Skip to content

Commit

Permalink
Add support for install-args option
Browse files Browse the repository at this point in the history
  • Loading branch information
Anifacted committed Jul 9, 2019
1 parent 8cd557b commit 0d80987
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
7 changes: 7 additions & 0 deletions bin/lernaupdate
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const { input, flags } = meow(
--lazy Runs a single install command after updating package.json files, instead installing inside each individual package (Useful for workspaces)
--install-args Any additional arguments to pass to the NPM or Yarn during the installation (space-separated). See example.
Examples:
$ lernaupdate ./myproject --dedupe
Expand All @@ -33,6 +35,8 @@ const { input, flags } = meow(
$ lernaupdate ./myproject --packages "packages/*"
$ lernaupdate ./myproject --non-interactive --dependency "react@latest" --new-installs-mode dev
$ lernaupdate ./myproject --install-args="--verbose --prefer-offline"
`,
{
flags: {
Expand All @@ -55,6 +59,9 @@ const { input, flags } = meow(
lazy: {
type: "boolean",
},
installArgs: {
type: "string",
},
},
}
);
Expand Down
33 changes: 22 additions & 11 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const parseDependency = require("./utils/parseDependency");
const sanitizeGitBranchName = require("./utils/sanitizeGitBranchName");
const modifyPackageJson = require("./utils/modifyPackageJson");
const lines = require("./utils/lines");
const composeCommand = require("./utils/composeCommand");

inquirer.registerPrompt(
"autocomplete",
Expand Down Expand Up @@ -383,7 +384,7 @@ module.exports = async ({ input, flags }) => {

ui.log.write(chalk.green(`Using version ${targetVersionResolved} ✓\n`));

// PROMPT: Yarn workspaces lazy installation prompt
// PROMPT: Yarn workspaces lazy installation
if (workspaces && !flags.lazy && !flags.nonInteractive) {
ui.logBottom("");

Expand Down Expand Up @@ -497,15 +498,22 @@ module.exports = async ({ input, flags }) => {
chalk`{white.bold ${packageName}}: {green package.json updated ✓}\n`
);
} else {
const installCmd = (dependencyManager === "yarn"
? ["yarn", "add", sourceParam, `${targetDependency}@${targetVersion}`]
: [
"npm",
"install",
sourceParam,
`${targetDependency}@${targetVersion}`,
]
).join(" ");
const installCmd =
dependencyManager === "yarn"
? composeCommand(
"yarn",
"add",
sourceParam,
flags.installArgs,
`${targetDependency}@${targetVersion}`
)
: composeCommand(
"npm",
"install",
sourceParam,
flags.installArgs,
`${targetDependency}@${targetVersion}`
);

await runCommand(`cd ${packageDir} && ${installCmd}`, {
startMessage: `${chalk.white.bold(depName)}: ${installCmd}`,
Expand All @@ -520,7 +528,10 @@ module.exports = async ({ input, flags }) => {
if (flags.lazy) {
ui.log.write("");

const installCmd = dependencyManager === "yarn" ? "yarn" : "npm install";
const installCmd = composeCommand(
dependencyManager === "yarn" ? "yarn" : "npm install",
flags.installArgs
);

await runCommand(`cd ${projectDir} && ${installCmd}`, {
startMessage: `${chalk.white.bold(projectName)}: ${installCmd}`,
Expand Down
1 change: 1 addition & 0 deletions src/utils/composeCommand.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = (...args) => args.filter(Boolean).join(" ");
28 changes: 28 additions & 0 deletions src/utils/composeCommand.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const expect = require("unexpected");
const composeCommand = require("./composeCommand");

describe("composeCommand", () => {
it("composes single command", () => {
expect(composeCommand, "when called with", ["yarn"], "to equal", "yarn");
});

it("composes multiple commands", () => {
expect(
composeCommand,
"when called with",
["yarn", "add"],
"to equal",
"yarn add"
);
});

it("ignores empty inputs", () => {
expect(
composeCommand,
"when called with",
["yarn", undefined, "add", null, false],
"to equal",
"yarn add"
);
});
});

0 comments on commit 0d80987

Please sign in to comment.