Skip to content

Commit

Permalink
Disallow self referencing deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Keir committed Oct 23, 2024
1 parent 031b5da commit a67978f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .yarn/versions/1157e53a.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
releases:
"@yarnpkg/builder": patch
"@yarnpkg/cli": patch
"@yarnpkg/core": patch
"@yarnpkg/doctor": patch
"@yarnpkg/extensions": patch
"@yarnpkg/nm": patch
"@yarnpkg/plugin-compat": patch
"@yarnpkg/plugin-constraints": patch
"@yarnpkg/plugin-dlx": patch
"@yarnpkg/plugin-essentials": patch
"@yarnpkg/plugin-exec": patch
"@yarnpkg/plugin-file": patch
"@yarnpkg/plugin-git": patch
"@yarnpkg/plugin-github": patch
"@yarnpkg/plugin-http": patch
"@yarnpkg/plugin-init": patch
"@yarnpkg/plugin-interactive-tools": patch
"@yarnpkg/plugin-link": patch
"@yarnpkg/plugin-nm": patch
"@yarnpkg/plugin-npm": patch
"@yarnpkg/plugin-npm-cli": patch
"@yarnpkg/plugin-pack": patch
"@yarnpkg/plugin-patch": patch
"@yarnpkg/plugin-pnp": patch
"@yarnpkg/plugin-pnpm": patch
"@yarnpkg/plugin-stage": patch
"@yarnpkg/plugin-typescript": patch
"@yarnpkg/plugin-version": patch
"@yarnpkg/plugin-workspace-tools": patch
"@yarnpkg/pnpify": patch
"@yarnpkg/sdks": patch
9 changes: 9 additions & 0 deletions packages/yarnpkg-core/sources/Manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,9 @@ export class Manifest {
data.dependencies = Object.assign({}, ...structUtils.sortDescriptors(regularDependencies).map(dependency => {
return {[structUtils.stringifyIdent(dependency)]: dependency.range};
}));
if (data.name && data.dependencies[data.name]) {
delete data.dependencies[data.name];
}
} else {
delete data.dependencies;
}
Expand All @@ -887,6 +890,9 @@ export class Manifest {
data.devDependencies = Object.assign({}, ...structUtils.sortDescriptors(this.devDependencies.values()).map(dependency => {
return {[structUtils.stringifyIdent(dependency)]: dependency.range};
}));
if (data.name && data.devDependencies[data.name]) {
delete data.devDependencies[data.name];
}
} else {
delete data.devDependencies;
}
Expand All @@ -895,6 +901,9 @@ export class Manifest {
data.peerDependencies = Object.assign({}, ...structUtils.sortDescriptors(this.peerDependencies.values()).map(dependency => {
return {[structUtils.stringifyIdent(dependency)]: dependency.range};
}));
if (data.name && data.peerDependencies[data.name]) {
delete data.peerDependencies[data.name];
}
} else {
delete data.peerDependencies;
}
Expand Down
11 changes: 11 additions & 0 deletions packages/yarnpkg-core/tests/Manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,16 @@ describe(`Manifest`, () => {
const manifest = Manifest.fromText(`{ "name": "name", "bin": { "bin1": " ", "bin2": "./bin2.js" } }`);
expect(manifest.exportTo({}).bin).toEqual({bin2: `./bin2.js`});
});

it(`should remove dependency if referencing itself`, () => {
const deps = `{ "bar": "^1.0.0", "foo": "^1.2.0" }`;
const manifest = Manifest.fromText(`
{ "name": "foo", "dependencies": ${deps}, "devDependencies": ${deps}, "peerDependencies": ${deps} }
`);
const exportedManifest = manifest.exportTo({});
expect(exportedManifest.dependencies).toEqual({bar: `^1.0.0`});
expect(exportedManifest.devDependencies).toEqual({bar: `^1.0.0`});
expect(exportedManifest.peerDependencies).toEqual({bar: `^1.0.0`});
});
});
});

0 comments on commit a67978f

Please sign in to comment.