-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from ghiscoding/chore/lerna-cli
BREAKING CHANGE: use `lerna` CLI for all commands, fixes #28
- Loading branch information
Showing
87 changed files
with
2,378 additions
and
1,119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
"use strict"; | ||
|
||
const path = require("path"); | ||
const lernaCLI = require("../../packages/cli/src/lerna-cli"); | ||
|
||
module.exports = commandRunner; | ||
|
||
/** | ||
* A higher-order function to help with passing _actual_ yargs-parsed argv | ||
* into command constructors (instead of artificial direct parameters). | ||
* | ||
* @param {Object} commandModule The yargs command exports | ||
* @return {Function} with partially-applied yargs config | ||
*/ | ||
function commandRunner(commandModule) { | ||
/* eslint-disable import/no-dynamic-require, global-require */ | ||
const cmd = commandModule.command.split(" ")[0]; | ||
|
||
// prime the pump so slow-as-molasses CI doesn't fail with delayed require() | ||
require(path.resolve(require.main.filename, "../..")); | ||
|
||
return (cwd) => { | ||
// create a _new_ yargs instance every time cwd changes to avoid singleton pollution | ||
const cli = lernaCLI([], cwd) | ||
.exitProcess(false) | ||
.detectLocale(false) | ||
.showHelpOnFail(false) | ||
.wrap(null) | ||
.command(commandModule); | ||
|
||
return (...args) => { | ||
return new Promise((resolve, reject) => { | ||
const yargsMeta = {}; | ||
|
||
const context = { | ||
cwd, | ||
lernaVersion: "__TEST_VERSION__", | ||
loglevel: "silent", | ||
progress: false, | ||
onResolved: (result) => { | ||
// success resolves the result, if any, returned from execute() | ||
resolve(Object.assign({}, result, yargsMeta)); | ||
}, | ||
onRejected: (result) => { | ||
Object.assign(result, yargsMeta); | ||
// tests expect errors thrown to indicate failure, | ||
// _not_ just non-zero exitCode | ||
reject(result); | ||
}, | ||
}; | ||
|
||
const parseFn = (yargsError, parsedArgv, yargsOutput) => { | ||
// this is synchronous, before the async handlers resolve | ||
Object.assign(yargsMeta, { parsedArgv, yargsOutput }); | ||
}; | ||
|
||
cli | ||
.fail((msg, err) => { | ||
// since yargs 10.1.0, this is the only way to catch handler rejection | ||
// _and_ yargs validation exceptions when using async command handlers | ||
const actual = err || new Error(msg); | ||
// backfill exitCode for test convenience | ||
yargsMeta.exitCode = "exitCode" in actual ? actual.exitCode : 1; | ||
context.onRejected(actual); | ||
}) | ||
.parse([cmd, ...args], context, parseFn); | ||
}); | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"name": "@lerna-test/command-runner", | ||
"version": "0.0.0-test-only", | ||
"description": "A local test helper", | ||
"main": "index.js", | ||
"private": true, | ||
"license": "MIT", | ||
"dependencies": { | ||
"@lerna/cli": "file:../../core/cli" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,4 @@ | |
"runDryRun": false | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.