Skip to content

Commit

Permalink
fix(publish): work around yarn "link:" intransigency
Browse files Browse the repository at this point in the history
  • Loading branch information
evocateur committed Mar 8, 2018
1 parent f1816d0 commit ddfb517
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
1 change: 1 addition & 0 deletions commands/__fixtures__/yarn-link-spec/.yarnrc
@@ -0,0 +1 @@
workspaces-experimental true
5 changes: 5 additions & 0 deletions commands/__fixtures__/yarn-link-spec/lerna.json
@@ -0,0 +1,5 @@
{
"version": "1.0.0",
"npmClient": "yarn",
"useWorkspaces": true
}
7 changes: 7 additions & 0 deletions commands/__fixtures__/yarn-link-spec/package.json
@@ -0,0 +1,7 @@
{
"name": "yarn-link-spec",
"private": true,
"workspaces": [
"workspaces/*"
]
}
@@ -0,0 +1,4 @@
{
"name": "package-1",
"version": "1.0.0"
}
@@ -0,0 +1,7 @@
{
"name": "package-2",
"version": "1.0.0",
"dependencies": {
"package-1": "link:../package-1"
}
}
10 changes: 10 additions & 0 deletions commands/publish/__tests__/publish-command.test.js
Expand Up @@ -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", () => {
Expand Down
6 changes: 5 additions & 1 deletion core/package-graph/index.js
Expand Up @@ -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
Expand Down

0 comments on commit ddfb517

Please sign in to comment.