Skip to content

Commit

Permalink
pnpm use add command and NODE_ENV should not equal "production" when …
Browse files Browse the repository at this point in the history
…add development dependency in workspace.
  • Loading branch information
dishuostec committed Jul 24, 2020
1 parent a45b5dc commit 79b6e07
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
29 changes: 27 additions & 2 deletions packages/core/package-manager/src/Pnpm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,39 @@ export class Pnpm implements PackageInstaller {
cwd,
saveDev = true,
}: InstallerOptions): Promise<void> {
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,
stack: e.stack,
});
})
.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',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -168,6 +192,7 @@ type PNPMResults = {|
level: LogLevel,
prefix?: string,
message?: string,
...ErrorLog,
...PNPMLog,
|};

Expand Down
2 changes: 1 addition & 1 deletion packages/core/parcel-bundler/src/utils/installPackage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
4 changes: 3 additions & 1 deletion packages/core/parcel/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ async function normalizeOptions(command): Promise<InitialParcelOptions> {
}

let mode = command.name() === 'build' ? 'production' : 'development';
return {
let newVar = {
disableCache: command.cache === false,
cacheDir: command.cacheDir,
mode,
Expand All @@ -334,4 +334,6 @@ async function normalizeOptions(command): Promise<InitialParcelOptions> {
NODE_ENV: nodeEnv,
},
};
console.log('[options]', newVar);
return newVar;
}

0 comments on commit 79b6e07

Please sign in to comment.