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

feat(link): Use publishConfig.directory as symlink source if it exists to allow linking sub-directories #2274

Merged
merged 16 commits into from Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion commands/link/README.md
Expand Up @@ -10,7 +10,7 @@ Install [lerna](https://www.npmjs.com/package/lerna) for access to the `lerna` C
$ lerna link
```

Symlink together all Lerna `packages` that are dependencies of each other in the current Lerna repo.
Symlink together all Lerna `packages` that are dependencies of each other in the current Lerna repo. When using `publishConfig.directory`, that will be the source directory of the link (e.g. `package-1/dist => node_modules/package-1`).
kamranayub marked this conversation as resolved.
Show resolved Hide resolved

## Options

Expand Down
3 changes: 3 additions & 0 deletions commands/link/__tests__/__fixtures__/with-contents/lerna.json
@@ -0,0 +1,3 @@
{
"version": "1.0.0"
}
@@ -0,0 +1,3 @@
{
"name": "independent"
}
@@ -0,0 +1,7 @@
{
"name": "@test/package-1",
"version": "1.0.0",
"publishConfig": {
"directory": "dist"
evocateur marked this conversation as resolved.
Show resolved Hide resolved
}
}
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log("Hello, world!");
@@ -0,0 +1,11 @@
{
"name": "@test/package-2",
"version": "1.0.0",
"publishConfig": {
"directory": "dist"
},
"bin": "cli.js",
"dependencies": {
"@test/package-1": "^1.0.0"
}
}
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log("Hello, world!");
kamranayub marked this conversation as resolved.
Show resolved Hide resolved
@@ -0,0 +1,2 @@
#!/usr/bin/env node
console.log("Hello, world!");
@@ -0,0 +1,15 @@
{
"name": "package-3",
"version": "1.0.0",
"publishConfig": {
"directory": "dist"
},
"bin": {
"package3cli1": "cli1.js",
"package3cli2": "cli2.js"
},
"devDependencies": {
"@test/package-1": "^1.0.0",
"@test/package-2": "^1.0.0"
}
}
@@ -0,0 +1,11 @@
{
"name": "package-4",
"version": "1.0.0",
"publishConfig": {
"directory": "dist"
},
"dependencies": {
"@test/package-1": "^0.0.0",
"package-3": "^1.0.0"
}
}
47 changes: 47 additions & 0 deletions commands/link/__tests__/link-command.test.js
Expand Up @@ -87,6 +87,53 @@ Array [
});
});

describe("with contents", () => {
it("should symlink sub-directory of package folders and bin directories", async () => {
const testDir = await initFixture("with-contents");
await lernaLink(testDir)();

expect(symlinkedDirectories(testDir)).toMatchInlineSnapshot(`
Array [
Object {
"_src": "packages/package-1/dist",
"dest": "packages/package-2/node_modules/@test/package-1",
"type": "junction",
},
Object {
"_src": "packages/package-1/dist",
"dest": "packages/package-3/node_modules/@test/package-1",
"type": "junction",
},
Object {
"_src": "packages/package-2/dist",
"dest": "packages/package-3/node_modules/@test/package-2",
"type": "junction",
},
Object {
"_src": "packages/package-2/dist/cli.js",
"dest": "packages/package-3/node_modules/.bin/package-2",
"type": "exec",
},
Object {
"_src": "packages/package-3/dist",
"dest": "packages/package-4/node_modules/package-3",
"type": "junction",
},
Object {
"_src": "packages/package-3/dist/cli1.js",
"dest": "packages/package-4/node_modules/.bin/package3cli1",
"type": "exec",
},
Object {
"_src": "packages/package-3/dist/cli2.js",
"dest": "packages/package-4/node_modules/.bin/package3cli2",
"type": "exec",
},
]
`);
});
});

describe("with --force-local", () => {
it("should force symlink of all packages", async () => {
const testDir = await initFixture("force-local");
Expand Down
2 changes: 1 addition & 1 deletion commands/publish/README.md
Expand Up @@ -303,7 +303,7 @@ You can customize the dist-tag on a per-package basis by setting [`tag`](https:/

### `publishConfig.directory`

This _non-standard_ field allows you to customize the published subdirectory just like [`--contents`](#--contents-dir), but on a per-package basis. All other caveats of `--contents` still apply.
This _non-standard_ field allows you to customize the published subdirectory just like [`--contents`](#--contents-dir), but on a per-package basis. All other caveats of `--contents` still apply. When symlinking using `lerna link` or `lerna bootstrap`, this will be the _source_ directory of the symlink, just like how the published package would be consumed.
kamranayub marked this conversation as resolved.
Show resolved Hide resolved

```json
"publishConfig": {
Expand Down
5 changes: 4 additions & 1 deletion utils/symlink-binary/symlink-binary.js
Expand Up @@ -19,7 +19,10 @@ function symlinkBinary(srcPackageRef, destPackageRef) {
return Promise.all([Package.lazy(srcPackageRef), Package.lazy(destPackageRef)]).then(
([srcPackage, destPackage]) => {
const actions = Object.keys(srcPackage.bin).map(name => {
const src = path.join(srcPackage.location, srcPackage.bin[name]);
const srcLocation = srcPackage.contents
? path.resolve(srcPackage.location, srcPackage.contents)
: srcPackage.location;
const src = path.join(srcLocation, srcPackage.bin[name]);
const dst = path.join(destPackage.binLocation, name);

// Symlink all declared binaries, even if they don't exist (yet). We will
Expand Down
5 changes: 4 additions & 1 deletion utils/symlink-dependencies/symlink-dependencies.js
Expand Up @@ -77,7 +77,10 @@ function symlinkDependencies(packages, packageGraph, tracker) {
});

// create package symlink
chain = chain.then(() => createSymlink(dependencyNode.location, targetDirectory, "junction"));
const dependencyLocation = dependencyNode.pkg.contents
? path.resolve(dependencyNode.location, dependencyNode.pkg.contents)
: dependencyNode.location;
chain = chain.then(() => createSymlink(dependencyLocation, targetDirectory, "junction"));

// TODO: pass PackageGraphNodes directly instead of Packages
chain = chain.then(() => symlinkBinary(dependencyNode.pkg, currentNode.pkg));
Expand Down