From 0a147789265aa84859a1a8232b6c8e912af1ef4b Mon Sep 17 00:00:00 2001 From: Joel Denning Date: Fri, 13 Mar 2020 21:43:28 -0600 Subject: [PATCH] Add support for --frozen-lockfile flag. Resolves #17 --- lib/narn-lib.js | 11 ++++++++++- test/install.test.js | 13 +++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/narn-lib.js b/lib/narn-lib.js index b145e1d..b9e67a4 100644 --- a/lib/narn-lib.js +++ b/lib/narn-lib.js @@ -40,7 +40,9 @@ exports.detectNpm = function detectNpm(args) { exports.getYarnArgs = narnArgs => narnArgs; exports.getNpmArgs = (narnArgs, isPnpm = false) => { - const yarnArgs = minimist(narnArgs, { boolean: ["dev", "D", "--latest"] }); + const yarnArgs = minimist(narnArgs, { + boolean: ["dev", "D", "latest", "frozen-lockfile"] + }); const yarnCommands = yarnArgs._; const yarnTarget = yarnCommands.length > 0 ? yarnCommands[0] : "install"; const yarnSubCommands = yarnCommands.slice(1); @@ -51,6 +53,13 @@ exports.getNpmArgs = (narnArgs, isPnpm = false) => { case "install": npmTarget = "install"; npmArgs = []; + if (yarnArgs["frozen-lockfile"]) { + if (isPnpm) { + npmArgs.push("--frozen-lockfile"); + } else { + npmTarget = "ci"; + } + } break; case "add": npmTarget = "install"; diff --git a/test/install.test.js b/test/install.test.js index d380f5d..a0b746c 100644 --- a/test/install.test.js +++ b/test/install.test.js @@ -8,4 +8,17 @@ describe("narn install", () => { it("works when install is specified", () => { expect(getNpmArgs(["install"])).toEqual(["install"]); }); + + describe("--frozen-lockfile", () => { + it("works with npm", () => { + expect(getNpmArgs(["install", "--frozen-lockfile"])).toEqual(["ci"]); + }); + + it("works with pnpm", () => { + expect(getNpmArgs(["install", "--frozen-lockfile"], true)).toEqual([ + "install", + "--frozen-lockfile" + ]); + }); + }); });