From 79b6e07d36722f380b1c52fdaa4f1ad28957221b Mon Sep 17 00:00:00 2001 From: dishuostec Date: Fri, 24 Jul 2020 14:30:18 +0800 Subject: [PATCH] pnpm use add command and NODE_ENV should not equal "production" when add development dependency in workspace. --- packages/core/package-manager/src/Pnpm.js | 29 +++++++++++++++++-- .../src/utils/installPackage.js | 2 +- packages/core/parcel/src/cli.js | 4 ++- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/packages/core/package-manager/src/Pnpm.js b/packages/core/package-manager/src/Pnpm.js index 2be779d369b8..39c890ef9845 100644 --- a/packages/core/package-manager/src/Pnpm.js +++ b/packages/core/package-manager/src/Pnpm.js @@ -21,18 +21,23 @@ export class Pnpm implements PackageInstaller { cwd, saveDev = true, }: InstallerOptions): Promise { - let args = ['install', '--reporter ndjson', saveDev ? '--dev' : ''].concat( + let args = ['add', '--reporter', 'ndjson', saveDev ? '-D' : ''].concat( modules.map(npmSpecifierFromModuleRequest), ); + console.log({cwd, args}); let addedCount = 0; let removedCount = 0; - let installProcess = spawn(PNPM_CMD, args, {cwd}); + let installProcess = spawn(PNPM_CMD, args, { + cwd, + env: {...process.env, NODE_ENV: 'development'}, + }); installProcess.stdout .pipe(split()) .pipe(new JSONParseStream()) .on('error', e => { + console.log('[ERROR]', e); logger.warn({ origin: '@parcel/package-manager', message: e.chunk, @@ -40,6 +45,15 @@ export class Pnpm implements PackageInstaller { }); }) .on('data', (json: PNPMResults) => { + console.log('[stdout]', json); + if (json.level === 'error') { + logger.error({ + origin: '@parcel/package-manager', + message: json.err.message, + stack: json.err.stack, + }); + return; + } if (json.level === 'info' && typeof json.message === 'string') { logger.info({ origin: '@parcel/package-manager', @@ -95,9 +109,11 @@ export class Pnpm implements PackageInstaller { let stderr = []; installProcess.stderr .on('data', str => { + console.log('[sdterr]', str.toString()); stderr.push(str.toString()); }) .on('error', e => { + console.log('[ERROR] install', e); logger.warn({ origin: '@parcel/package-manager', message: e.message, @@ -137,6 +153,14 @@ export class Pnpm implements PackageInstaller { type LogLevel = 'error' | 'warn' | 'info' | 'debug'; +type ErrorLog = {| + err: {| + message: string, + code: string, + stack: string, + |}, +|}; + type PNPMLog = | {| +name: 'pnpm:progress', @@ -168,6 +192,7 @@ type PNPMResults = {| level: LogLevel, prefix?: string, message?: string, + ...ErrorLog, ...PNPMLog, |}; diff --git a/packages/core/parcel-bundler/src/utils/installPackage.js b/packages/core/parcel-bundler/src/utils/installPackage.js index 7443b803571e..abc52e822a24 100644 --- a/packages/core/parcel-bundler/src/utils/installPackage.js +++ b/packages/core/parcel-bundler/src/utils/installPackage.js @@ -26,7 +26,7 @@ async function install(modules, filepath, options = {}) { packageManager = await determinePackageManager(filepath); } - let commandToUse = packageManager === 'yarn' ? 'add' : 'install'; + let commandToUse = packageManager === 'npm' ? 'install' : 'add'; let args = [commandToUse, ...modules]; if (saveDev) { args.push('-D'); diff --git a/packages/core/parcel/src/cli.js b/packages/core/parcel/src/cli.js index 67f987c1cb9a..e124405ed477 100755 --- a/packages/core/parcel/src/cli.js +++ b/packages/core/parcel/src/cli.js @@ -313,7 +313,7 @@ async function normalizeOptions(command): Promise { } let mode = command.name() === 'build' ? 'production' : 'development'; - return { + let newVar = { disableCache: command.cache === false, cacheDir: command.cacheDir, mode, @@ -334,4 +334,6 @@ async function normalizeOptions(command): Promise { NODE_ENV: nodeEnv, }, }; + console.log('[options]', newVar); + return newVar; }