Skip to content

Commit

Permalink
fix(bootstrap): Respect --force-local option (#2104)
Browse files Browse the repository at this point in the history
Before this change, `--force-local` option was not respected and monorepo-local packages outside of the defined --scope were still installed from the npm registry.

This commit fixes the code handling `--force-local` logic, so that:
- Local packages are resolved as links within the monorepo
- The following warning IS NOT printed anymore:
  _Installing local packages that do not match filters from registry_
  • Loading branch information
bajtos authored and evocateur committed Jun 9, 2019
1 parent 4f15361 commit c2fb639
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
Expand Up @@ -319,9 +319,6 @@ Object {
"bar@^2.0.0",
"foo@^1.0.0",
],
"packages/package-4": Array [
"package-3@^1.0.0",
],
}
`;

Expand All @@ -332,6 +329,21 @@ Array [
"dest": "packages/package-4/node_modules/@test/package-1",
"type": "junction",
},
Object {
"_src": "packages/package-3",
"dest": "packages/package-4/node_modules/package-3",
"type": "junction",
},
Object {
"_src": "packages/package-3/cli1.js",
"dest": "packages/package-4/node_modules/.bin/package3cli1",
"type": "exec",
},
Object {
"_src": "packages/package-3/cli2.js",
"dest": "packages/package-4/node_modules/.bin/package3cli2",
"type": "exec",
},
]
`;

Expand Down
18 changes: 18 additions & 0 deletions commands/bootstrap/__tests__/bootstrap-command.test.js
Expand Up @@ -313,6 +313,24 @@ describe("BootstrapCommand", () => {
expect(symlinkedDirectories(testDir)).toMatchSnapshot();
});

it("should respect --force-local when a single package is in scope", async () => {
const testDir = await initFixture("basic");

await lernaBootstrap(testDir)("--scope", "package-4", "--force-local");

// no packages were installed from the registry
const installed = installedPackagesInDirectories(testDir);
expect(installed["packages/package-4"] || []).toEqual([]);

// package-3 was resolved as a local symlink
const symlinked = symlinkedDirectories(testDir);
expect(symlinked).toContainEqual({
_src: "packages/package-3",
dest: "packages/package-4/node_modules/package-3",
type: "junction",
});
});

it("should not update package.json when filtering", async () => {
const testDir = await initFixture("basic");

Expand Down
2 changes: 1 addition & 1 deletion commands/bootstrap/index.js
Expand Up @@ -161,7 +161,7 @@ class BootstrapCommand extends Command {
chain = chain.then(filteredPackages => {
this.filteredPackages = filteredPackages;

if (filteredPackages.length !== this.targetGraph.size) {
if (filteredPackages.length !== this.targetGraph.size && !this.options.forceLocal) {
this.logger.warn("bootstrap", "Installing local packages that do not match filters from registry");

// an explicit --scope, --ignore, or --since should only symlink the targeted packages, no others
Expand Down

0 comments on commit c2fb639

Please sign in to comment.