diff --git a/commands/__fixtures__/yarn-link-spec/.yarnrc b/commands/__fixtures__/yarn-link-spec/.yarnrc new file mode 100644 index 0000000000..19daacaa08 --- /dev/null +++ b/commands/__fixtures__/yarn-link-spec/.yarnrc @@ -0,0 +1 @@ +workspaces-experimental true diff --git a/commands/__fixtures__/yarn-link-spec/lerna.json b/commands/__fixtures__/yarn-link-spec/lerna.json new file mode 100644 index 0000000000..cbf807a53b --- /dev/null +++ b/commands/__fixtures__/yarn-link-spec/lerna.json @@ -0,0 +1,5 @@ +{ + "version": "1.0.0", + "npmClient": "yarn", + "useWorkspaces": true +} diff --git a/commands/__fixtures__/yarn-link-spec/package.json b/commands/__fixtures__/yarn-link-spec/package.json new file mode 100644 index 0000000000..707937abe8 --- /dev/null +++ b/commands/__fixtures__/yarn-link-spec/package.json @@ -0,0 +1,7 @@ +{ + "name": "yarn-link-spec", + "private": true, + "workspaces": [ + "workspaces/*" + ] +} diff --git a/commands/__fixtures__/yarn-link-spec/workspaces/package-1/package.json b/commands/__fixtures__/yarn-link-spec/workspaces/package-1/package.json new file mode 100644 index 0000000000..8eb2fba205 --- /dev/null +++ b/commands/__fixtures__/yarn-link-spec/workspaces/package-1/package.json @@ -0,0 +1,4 @@ +{ + "name": "package-1", + "version": "1.0.0" +} diff --git a/commands/__fixtures__/yarn-link-spec/workspaces/package-2/package.json b/commands/__fixtures__/yarn-link-spec/workspaces/package-2/package.json new file mode 100644 index 0000000000..0e6aefb940 --- /dev/null +++ b/commands/__fixtures__/yarn-link-spec/workspaces/package-2/package.json @@ -0,0 +1,7 @@ +{ + "name": "package-2", + "version": "1.0.0", + "dependencies": { + "package-1": "link:../package-1" + } +} diff --git a/commands/publish/__tests__/publish-command.test.js b/commands/publish/__tests__/publish-command.test.js index b49cc69941..1b71033928 100644 --- a/commands/publish/__tests__/publish-command.test.js +++ b/commands/publish/__tests__/publish-command.test.js @@ -1204,6 +1204,16 @@ describe("PublishCommand", () => { "package-6": "6.0.0", }); }); + + it("works around npm-incompatible link: specifiers", async () => { + const testDir = await initFixture("yarn-link-spec"); + + await lernaPublish(testDir)("--cd-version", "major", "--yes"); + + expect(updatedPackageJSON("package-2").dependencies).toMatchObject({ + "package-1": "^2.0.0", + }); + }); }); describe("in a cyclical repo", () => { diff --git a/core/package-graph/index.js b/core/package-graph/index.js index 589338bb7e..1250837568 100644 --- a/core/package-graph/index.js +++ b/core/package-graph/index.js @@ -70,7 +70,11 @@ class PackageGraph extends Map { Object.keys(graphDependencies).forEach(depName => { const depNode = this.get(depName); - const resolved = npa.resolve(depName, graphDependencies[depName], currentNode.location); + // Yarn decided to ignore https://github.com/npm/npm/pull/15900 and implemented "link:" + // As they apparently have no intention of being compatible, we have to do it for them. + // @see https://github.com/yarnpkg/yarn/issues/4212 + const spec = graphDependencies[depName].replace(/^link:/, "file:"); + const resolved = npa.resolve(depName, spec, currentNode.location); if (!depNode) { // it's an external dependency, store the resolution and bail