diff --git a/package-lock.json b/package-lock.json index 6e8f46a5ab..47bc4f0849 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14072,7 +14072,6 @@ "license": "MIT", "dependencies": { "@lerna/npm-conf": "file:../npm-conf", - "figgy-pudding": "^3.5.1", "npm-lifecycle": "^3.1.2", "npmlog": "^4.1.2" }, @@ -15586,7 +15585,6 @@ "version": "file:utils/run-lifecycle", "requires": { "@lerna/npm-conf": "file:../npm-conf", - "figgy-pudding": "^3.5.1", "npm-lifecycle": "^3.1.2", "npmlog": "^4.1.2" } diff --git a/utils/run-lifecycle/__tests__/run-lifecycle.test.js b/utils/run-lifecycle/__tests__/run-lifecycle.test.js index 1908b099fc..0989e0f0c1 100644 --- a/utils/run-lifecycle/__tests__/run-lifecycle.test.js +++ b/utils/run-lifecycle/__tests__/run-lifecycle.test.js @@ -86,14 +86,14 @@ describe("runLifecycle()", () => { }; const dir = pkg.location; const stage = "dashed-options"; - const opts = new Map([ - ["ignore-prepublish", true], - ["ignore-scripts", false], - ["node-options", "--a-thing"], - ["script-shell", "fish"], - ["scripts-prepend-node-path", true], - ["unsafe-perm", false], - ]); + const opts = { + "ignore-prepublish": true, + "ignore-scripts": false, + "node-options": "--a-thing", + "script-shell": "fish", + "scripts-prepend-node-path": true, + "unsafe-perm": false, + }; await runLifecycle(pkg, stage, opts); @@ -120,7 +120,9 @@ describe("runLifecycle()", () => { }, }; const stage = "prepublish"; - const opts = new Map().set("ignore-prepublish", true); + const opts = { + "ignore-prepublish": true, + }; await runLifecycle(pkg, stage, opts); @@ -135,7 +137,9 @@ describe("runLifecycle()", () => { }, }; const stage = "ignored"; - const opts = new Map().set("ignore-scripts", true); + const opts = { + "ignore-scripts": true, + }; await runLifecycle(pkg, stage, opts); @@ -152,7 +156,7 @@ describe("runLifecycle()", () => { }, }; const stage = "prepack"; - const opts = new Map(); + const opts = {}; await runLifecycle(pkg, stage, opts); diff --git a/utils/run-lifecycle/package.json b/utils/run-lifecycle/package.json index a38538a862..563f68436c 100644 --- a/utils/run-lifecycle/package.json +++ b/utils/run-lifecycle/package.json @@ -32,7 +32,6 @@ }, "dependencies": { "@lerna/npm-conf": "file:../npm-conf", - "figgy-pudding": "^3.5.1", "npm-lifecycle": "^3.1.2", "npmlog": "^4.1.2" } diff --git a/utils/run-lifecycle/run-lifecycle.js b/utils/run-lifecycle/run-lifecycle.js index e313cf4f29..0a27200b55 100644 --- a/utils/run-lifecycle/run-lifecycle.js +++ b/utils/run-lifecycle/run-lifecycle.js @@ -2,49 +2,58 @@ const log = require("npmlog"); const runScript = require("npm-lifecycle"); -const figgyPudding = require("figgy-pudding"); const npmConf = require("@lerna/npm-conf"); module.exports = runLifecycle; module.exports.createRunner = createRunner; -const LifecycleConfig = figgyPudding( - { - log: { default: log }, - // provide aliases for some dash-cased props - "ignore-prepublish": {}, - ignorePrepublish: "ignore-prepublish", - "ignore-scripts": {}, - ignoreScripts: "ignore-scripts", - "node-options": {}, - nodeOptions: "node-options", - "script-shell": {}, - scriptShell: "script-shell", - "scripts-prepend-node-path": {}, - scriptsPrependNodePath: "scripts-prepend-node-path", - "unsafe-perm": { - // when running scripts explicitly, assume that they're trusted - default: true, - }, - unsafePerm: "unsafe-perm", - }, - { - other() { - // open up the pudding - return true; - }, - } -); +/** + * @typedef {object} LifecycleConfig + * @property {typeof log} [log] + * @property {boolean} [ignorePrepublish] + * @property {boolean} [ignoreScripts] + * @property {string} [nodeOptions] + * @property {string} [scriptShell] + * @property {boolean} [scriptsPrependNodePath] + * @property {boolean} [unsafePerm=true] + */ + +/** + * Alias dash-cased npmConf to camelCase + * @param {LifecycleConfig} obj + * @returns {LifecycleConfig} + */ +function flattenOptions(obj) { + return { + ignorePrepublish: obj["ignore-prepublish"], + ignoreScripts: obj["ignore-scripts"], + nodeOptions: obj["node-options"], + scriptShell: obj["script-shell"], + scriptsPrependNodePath: obj["scripts-prepend-node-path"], + unsafePerm: obj["unsafe-perm"], + ...obj, + }; +} -function runLifecycle(pkg, stage, _opts) { +/** + * Run a lifecycle script for a package. + * @param {import("@lerna/package")} pkg + * @param {string} stage + * @param {LifecycleConfig} options + */ +function runLifecycle(pkg, stage, options) { // back-compat for @lerna/npm-conf instances // https://github.com/isaacs/proto-list/blob/27764cd/proto-list.js#L14 - if ("root" in _opts) { + if ("root" in options) { // eslint-disable-next-line no-param-reassign - _opts = _opts.snapshot; + options = options.snapshot; } - const opts = LifecycleConfig(_opts); + const opts = { + log, + unsafePerm: true, + ...flattenOptions(options), + }; const dir = pkg.location; const config = {}; @@ -67,7 +76,7 @@ function runLifecycle(pkg, stage, _opts) { } // https://github.com/zkat/figgy-pudding/blob/7d68bd3/index.js#L42-L64 - for (const [key, val] of opts) { + for (const [key, val] of Object.entries(opts)) { // omit falsy values and circular objects if (val != null && key !== "log" && key !== "logstream") { config[key] = val;