Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Adds support for Yarn 2 #757

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,17 @@ function selectYarnDependencies(deps: YarnDependency[], packagedDependencies: st
}

async function getYarnProductionDependencies(cwd: string, packagedDependencies?: string[]): Promise<YarnDependency[]> {
const versionString = await new Promise<string>((c, e) =>
cp.exec(
'yarn --version',
{ cwd, encoding: 'utf8', env: { ...process.env }, maxBuffer: 5000 * 1024 },
(err, stdout) => (err ? e(err) : c(stdout))
)
);
const yarnCommand = versionString[0] !== 1 ? "yarn info --recursive --dependents --json" : 'yarn list --prod --json'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const yarnCommand = versionString[0] !== 1 ? "yarn info --recursive --dependents --json" : 'yarn list --prod --json'
const yarnCommand = versionString[0] !== "1" ? "yarn info --recursive --dependents --json" : 'yarn list --prod --json'

The versionString[0] !== 1 part causes a compilation error:

src/npm.ts:165:22 - error TS2367: This condition will always return 'true' since the types 'string' and 'number' have no overlap.

const raw = await new Promise<string>((c, e) =>
cp.exec(
'yarn list --prod --json',
yarnCommand,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 176 (where it says Could not parse result of […]) should be updated with yarnCommand as well; otherwise the error message is going to be misleading.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure that yarn info --recursive --dependents --json is a compatible drop-in replacement for yarn list --prod --json, anyway?

On Yarn v3.3.1, the former prints a list of JSON objects, for example:

{"value":"yallist@npm:4.0.0","children":{"Version":"4.0.0","Dependents":["lru-cache@npm:6.0.0","minipass@npm:3.3.6","minipass@npm:4.0.0","minizlib@npm:2.1.2","tar@npm:6.1.13"]}}

At least on Yarn 3.3.1, none of those lines seem to contain anything like "type":"tree". However, the code that follows seems to rely on just that. Consequently, vsce package now errors out for me in line 176, saying:

Could not parse result of `yarn list --json`

{ cwd, encoding: 'utf8', env: { ...process.env }, maxBuffer: 5000 * 1024 },
(err, stdout) => (err ? e(err) : c(stdout))
)
Expand Down