From d0c677fc3df5c5ee636ba736a8dd857e8a5515d6 Mon Sep 17 00:00:00 2001 From: Daniel Stockman Date: Tue, 18 Dec 2018 16:34:06 -0800 Subject: [PATCH] refactor(pack-directory): Use figgy-pudding to wrap options, snapshot conf in test --- commands/publish/index.js | 2 +- package-lock.json | 1 + .../__tests__/pack-directory.test.js | 2 +- utils/pack-directory/lib/pack-directory.js | 15 ++++++++++++--- utils/pack-directory/package.json | 1 + 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/commands/publish/index.js b/commands/publish/index.js index 58bbd1906d..64b934acd7 100644 --- a/commands/publish/index.js +++ b/commands/publish/index.js @@ -81,7 +81,7 @@ class PublishCommand extends Command { this.logger.verbose("user-agent", userAgent); this.conf = npmConf({ - command: "publish", + lernaCommand: "publish", log: this.logger, npmSession, npmVersion: userAgent, diff --git a/package-lock.json b/package-lock.json index aabecc63e5..02dd9855f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -603,6 +603,7 @@ "requires": { "@lerna/get-packed": "file:utils/get-packed", "@lerna/run-lifecycle": "file:utils/run-lifecycle", + "figgy-pudding": "^3.5.1", "npm-packlist": "^1.1.12", "tar": "^4.4.8", "temp-write": "^3.4.0" diff --git a/utils/pack-directory/__tests__/pack-directory.test.js b/utils/pack-directory/__tests__/pack-directory.test.js index 48c49de35f..5dc3b482d8 100644 --- a/utils/pack-directory/__tests__/pack-directory.test.js +++ b/utils/pack-directory/__tests__/pack-directory.test.js @@ -72,7 +72,7 @@ describe("pack-directory", () => { jest.spyOn(fs, "move"); const cwd = await initFixture("lerna-bootstrap"); - const conf = npmConf({ prefix: cwd }); + const conf = npmConf({ prefix: cwd }).snapshot; const pkgs = await getPackages(cwd); // choose first and last package since the middle two are repetitive diff --git a/utils/pack-directory/lib/pack-directory.js b/utils/pack-directory/lib/pack-directory.js index 40dd7b8006..e867dd69a8 100644 --- a/utils/pack-directory/lib/pack-directory.js +++ b/utils/pack-directory/lib/pack-directory.js @@ -1,5 +1,6 @@ "use strict"; +const figgyPudding = require("figgy-pudding"); const packlist = require("npm-packlist"); const tar = require("tar"); const tempWrite = require("temp-write"); @@ -8,7 +9,15 @@ const runLifecycle = require("@lerna/run-lifecycle"); module.exports = packDirectory; -function packDirectory(pkg, opts) { +const PackConfig = figgyPudding({ + "lerna-command": { default: "pack" }, + lernaCommand: "lerna-command", + "ignore-prepublish": {}, + ignorePrepublish: "ignore-prepublish", +}); + +function packDirectory(pkg, _opts) { + const opts = PackConfig(_opts); const dir = pkg.location; const name = pkg.name[0] === "@" @@ -19,13 +28,13 @@ function packDirectory(pkg, opts) { let chain = Promise.resolve(); - if (opts.get("ignore-prepublish") !== false) { + if (opts.ignorePrepublish !== false) { chain = chain.then(() => runLifecycle(pkg, "prepublish", opts)); } chain = chain.then(() => runLifecycle(pkg, "prepare", opts)); - if (opts.get("command") === "publish") { + if (opts.lernaCommand === "publish") { chain = chain.then(() => pkg.refresh()); chain = chain.then(() => runLifecycle(pkg, "prepublishOnly", opts)); chain = chain.then(() => pkg.refresh()); diff --git a/utils/pack-directory/package.json b/utils/pack-directory/package.json index 6d2c8db02b..a91446082b 100644 --- a/utils/pack-directory/package.json +++ b/utils/pack-directory/package.json @@ -28,6 +28,7 @@ "dependencies": { "@lerna/get-packed": "file:../get-packed", "@lerna/run-lifecycle": "file:../run-lifecycle", + "figgy-pudding": "^3.5.1", "npm-packlist": "^1.1.12", "tar": "^4.4.8", "temp-write": "^3.4.0"