From c2fb639b7421aaf6a022fbb471ae3988226078f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Sun, 9 Jun 2019 20:47:20 +0200 Subject: [PATCH] fix(bootstrap): Respect `--force-local` option (#2104) 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_ --- .../bootstrap-command.test.js.snap | 18 +++++++++++++++--- .../__tests__/bootstrap-command.test.js | 18 ++++++++++++++++++ commands/bootstrap/index.js | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/commands/bootstrap/__tests__/__snapshots__/bootstrap-command.test.js.snap b/commands/bootstrap/__tests__/__snapshots__/bootstrap-command.test.js.snap index 2424dbf80d..51649aef7c 100644 --- a/commands/bootstrap/__tests__/__snapshots__/bootstrap-command.test.js.snap +++ b/commands/bootstrap/__tests__/__snapshots__/bootstrap-command.test.js.snap @@ -319,9 +319,6 @@ Object { "bar@^2.0.0", "foo@^1.0.0", ], - "packages/package-4": Array [ - "package-3@^1.0.0", - ], } `; @@ -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", + }, ] `; diff --git a/commands/bootstrap/__tests__/bootstrap-command.test.js b/commands/bootstrap/__tests__/bootstrap-command.test.js index 51ed93b7c9..c9c14c7e3a 100644 --- a/commands/bootstrap/__tests__/bootstrap-command.test.js +++ b/commands/bootstrap/__tests__/bootstrap-command.test.js @@ -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"); diff --git a/commands/bootstrap/index.js b/commands/bootstrap/index.js index 9fdd63695c..1690186aea 100644 --- a/commands/bootstrap/index.js +++ b/commands/bootstrap/index.js @@ -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