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

Prevents a workspace from depending on itself #6572

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
34 changes: 34 additions & 0 deletions .yarn/versions/f1299379.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
releases:
"@yarnpkg/cli": patch
"@yarnpkg/core": patch

declined:
- "@yarnpkg/plugin-compat"
- "@yarnpkg/plugin-constraints"
- "@yarnpkg/plugin-dlx"
- "@yarnpkg/plugin-essentials"
- "@yarnpkg/plugin-exec"
- "@yarnpkg/plugin-file"
- "@yarnpkg/plugin-git"
- "@yarnpkg/plugin-github"
- "@yarnpkg/plugin-http"
- "@yarnpkg/plugin-init"
- "@yarnpkg/plugin-interactive-tools"
- "@yarnpkg/plugin-link"
- "@yarnpkg/plugin-nm"
- "@yarnpkg/plugin-npm"
- "@yarnpkg/plugin-npm-cli"
- "@yarnpkg/plugin-pack"
- "@yarnpkg/plugin-patch"
- "@yarnpkg/plugin-pnp"
- "@yarnpkg/plugin-pnpm"
- "@yarnpkg/plugin-stage"
- "@yarnpkg/plugin-typescript"
- "@yarnpkg/plugin-version"
- "@yarnpkg/plugin-workspace-tools"
- "@yarnpkg/builder"
- "@yarnpkg/doctor"
- "@yarnpkg/extensions"
- "@yarnpkg/nm"
- "@yarnpkg/pnpify"
- "@yarnpkg/sdks"
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,8 @@ describe(`Commands`, () => {
await run(`add`, `no-deps`);

await expect(xfs.readJsonPromise(ppath.join(path, Filename.manifest))).resolves.toMatchObject({
dependencies: {
[`no-deps`]: `^2.0.0`,
},
// Note that Manifest.exportTo disallows depending on self
dependencies: {},
});
}),
);
Expand Down
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
18 changes: 18 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,23 @@ 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 = `{ "no-dep": "^1.0.0", "dep": "^1.2.0" }`;
const manifest = Manifest.fromText(`
{ "name": "no-dep", "dependencies": ${deps}, "devDependencies": ${deps}, "peerDependencies": ${deps} }
`);
expect(manifest.exportTo({})).toMatchObject({
dependencies: {
dep: `^1.2.0`,
},
devDependencies: {
dep: `^1.2.0`,
},
peerDependencies: {
dep: `^1.2.0`,
},
});
});
});
});
Loading