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(core): update yarn-parser to handle yarn v4 syntax for root workspace package #29452

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions packages/nx/src/plugins/js/lock-file/utils/package-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export type NormalizedPackageJson = Pick<
| 'peerDependencies'
| 'peerDependenciesMeta'
| 'optionalDependencies'
| 'packageManager'
>;

/**
Expand All @@ -42,6 +43,7 @@ export function normalizePackageJson(
peerDependencies,
peerDependenciesMeta,
optionalDependencies,
packageManager,
} = packageJson;

return {
Expand All @@ -53,5 +55,6 @@ export function normalizePackageJson(
peerDependencies,
peerDependenciesMeta,
optionalDependencies,
packageManager,
};
}
4 changes: 3 additions & 1 deletion packages/nx/src/plugins/js/lock-file/yarn-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2596,6 +2596,7 @@ __metadata:
dependencies: {
resolve: '^1.12.0',
},
packageManager: '[email protected]',
};

const hash = uniq('mock-hash');
Expand Down Expand Up @@ -2721,6 +2722,7 @@ __metadata:
dependencies: {
resolve: '^1.12.0',
},
packageManager: '[email protected]',
};

const hash = uniq('mock-hash');
Expand Down Expand Up @@ -2771,7 +2773,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@my-ns/example@workspace:."
dependencies:
resolve: ^1.12.0
resolve: "npm:^1.12.0"
languageName: unknown
linkType: soft

Expand Down
32 changes: 28 additions & 4 deletions packages/nx/src/plugins/js/lock-file/yarn-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -602,18 +602,42 @@ const BERRY_LOCK_FILE_DISCLAIMER = `# This file is generated by running "yarn in
function generateRootWorkspacePackage(
packageJson: NormalizedPackageJson
): YarnDependency {
let isVersion4 = false;
if (!!packageJson.packageManager) {
const [_, version] = packageJson.packageManager.split('@');
isVersion4 = !!version && satisfies(version, '>=4.0.0');
}

const reducer = (acc, [name, version]) => {
acc[name] = isVersion4 ? `npm:${version}` : version;
return acc;
};

return {
version: '0.0.0-use.local',
resolution: `${packageJson.name}@workspace:.`,
...(packageJson.dependencies && { dependencies: packageJson.dependencies }),
...(packageJson.dependencies && {
dependencies: Object.entries(packageJson.dependencies).reduce(
reducer,
{}
),
}),
...(packageJson.peerDependencies && {
peerDependencies: packageJson.peerDependencies,
peerDependencies: Object.entries(packageJson.peerDependencies).reduce(
reducer,
{}
),
}),
...(packageJson.devDependencies && {
devDependencies: packageJson.devDependencies,
devDependencies: Object.entries(packageJson.devDependencies).reduce(
reducer,
{}
),
}),
...(packageJson.optionalDependencies && {
optionalDependencies: packageJson.optionalDependencies,
optionalDependencies: Object.entries(
packageJson.optionalDependencies
).reduce(reducer, {}),
}),
languageName: 'unknown',
linkType: 'soft',
Expand Down
Loading