Skip to content

Commit

Permalink
Merge branch 'v2' into bump-swc
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Mar 25, 2023
2 parents b727e49 + 379e02c commit 09cae43
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 10 deletions.
28 changes: 23 additions & 5 deletions packages/core/package-manager/src/Pnpm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

import type {PackageInstaller, InstallerOptions} from './types';

import path from 'path';
import fs from 'fs';
import commandExists from 'command-exists';
import spawn from 'cross-spawn';
import logger from '@parcel/logger';
import split from 'split2';
import JSONParseStream from './JSONParseStream';
import promiseFromProcess from './promiseFromProcess';
import {registerSerializableClass} from '@parcel/core';
import {npmSpecifierFromModuleRequest} from './utils';
import {exec, npmSpecifierFromModuleRequest} from './utils';

// $FlowFixMe
import pkg from '../package.json';
Expand Down Expand Up @@ -62,6 +64,8 @@ type PNPMResults = {|
|};

let hasPnpm: ?boolean;
let pnpmVersion: ?number;

export class Pnpm implements PackageInstaller {
static async exists(): Promise<boolean> {
if (hasPnpm != null) {
Expand All @@ -82,9 +86,23 @@ export class Pnpm implements PackageInstaller {
cwd,
saveDev = true,
}: InstallerOptions): Promise<void> {
if (pnpmVersion == null) {
let version = await exec('pnpm --version');
pnpmVersion = parseInt(version.stdout, 10);
}

let args = ['add', '--reporter', 'ndjson'];
if (saveDev) {
args.push('-D', '-W');
args.push('-D');
}
if (pnpmVersion >= 7) {
if (fs.existsSync(path.join(cwd, 'pnpm-workspace.yaml'))) {
// installs in workspace root (regardless of cwd)
args.push('-w');
}
} else {
// ignores workspace root check
args.push('-W');
}
args = args.concat(modules.map(npmSpecifierFromModuleRequest));

Expand Down Expand Up @@ -148,9 +166,9 @@ export class Pnpm implements PackageInstaller {
if (addedCount > 0 || removedCount > 0) {
logger.log({
origin: '@parcel/package-manager',
message: `Added ${addedCount} and ${
removedCount > 0 ? `removed ${removedCount}` : ''
} packages via pnpm`,
message: `Added ${addedCount} ${
removedCount > 0 ? `and removed ${removedCount} ` : ''
}packages via pnpm`,
});
}

Expand Down
5 changes: 1 addition & 4 deletions packages/core/package-manager/src/Yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@ import type {PackageInstaller, InstallerOptions} from './types';

import commandExists from 'command-exists';
import spawn from 'cross-spawn';
import {exec as _exec} from 'child_process';
import {promisify} from 'util';
import logger from '@parcel/logger';
import split from 'split2';
import JSONParseStream from './JSONParseStream';
import promiseFromProcess from './promiseFromProcess';
import {registerSerializableClass} from '@parcel/core';
import {npmSpecifierFromModuleRequest} from './utils';
import {exec, npmSpecifierFromModuleRequest} from './utils';

// $FlowFixMe
import pkg from '../package.json';

const YARN_CMD = 'yarn';
const exec = promisify(_exec);

type YarnStdOutMessage =
| {|
Expand Down
8 changes: 8 additions & 0 deletions packages/core/package-manager/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import type {FileSystem} from '@parcel/fs';
import invariant from 'assert';
import ThrowableDiagnostic from '@parcel/diagnostic';
import {resolveConfig} from '@parcel/utils';
import {exec as _exec} from 'child_process';
import {promisify} from 'util';

export const exec: (
command: string,
options?: child_process$execOpts,
) => Promise<{|stdout: string | Buffer, stderr: string | Buffer|}> =
promisify(_exec);

export function npmSpecifierFromModuleRequest(
moduleRequest: ModuleRequest,
Expand Down
5 changes: 4 additions & 1 deletion packages/transformers/elm/src/ElmTransformer.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ function elmCompileErrorToParcelDiagnostics(error) {
}

function formatElmError(problem, relativePath) {
const padLength = 80 - 5 - problem.title.length - relativePath.length;
const padLength = Math.max(
80 - 5 - problem.title.length - relativePath.length,
1,
);
const dashes = '-'.repeat(padLength);
const message = [
'',
Expand Down
3 changes: 3 additions & 0 deletions packages/utils/node-resolver-core/src/Wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,9 @@ export default class NodeResolver {
},
);

// Need to clear the resolver caches after installing the package
this.resolversByEnv.clear();

// Re-resolve
return this.resolve({
...options,
Expand Down

0 comments on commit 09cae43

Please sign in to comment.