Skip to content

Commit

Permalink
fix(core): update yarn-parser to handle yarn v4 syntax for root works…
Browse files Browse the repository at this point in the history
…pace package
  • Loading branch information
a88zach committed Dec 20, 2024
1 parent d7ffba8 commit 50ce2fe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 5 deletions.
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: 'yarn@3.0.0',
};

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

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

0 comments on commit 50ce2fe

Please sign in to comment.