Skip to content

Commit f1fe2e5

Browse files
committed
chore: add run-lerna script to run lerna with repo root
The script sets `LERNA_ROOT_PATH` to the root directory of loopback-next monorepo and run `lerna` commands. It also detects VSCode and disables parallel mode.
1 parent e770208 commit f1fe2e5

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

bin/run-lerna.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env node
2+
// Copyright IBM Corp. 2017,2018. All Rights Reserved.
3+
// Node module: @loopback/cli
4+
// This file is licensed under the MIT License.
5+
// License text available at https://opensource.org/licenses/MIT
6+
7+
/**
8+
* This is an internal script to run `lerna` command with enviornment variable
9+
* `LERNA_ROOT_PATH` set to the root directory of `loopback-next` monorepo
10+
*/
11+
'use strict';
12+
13+
const path = require('path');
14+
const lerna = require('lerna');
15+
const build = require('../packages/build');
16+
17+
/**
18+
* Check if the script is running within Visual Studio Code
19+
*/
20+
function isVSCode() {
21+
return Object.keys(process.env).some(k => k.indexOf('VSCODE') === 0);
22+
}
23+
24+
function run(argv, options) {
25+
const ls = new lerna.LsCommand(
26+
null,
27+
{json: true, loglevel: 'silent'},
28+
path.join(__dirname, '..'),
29+
);
30+
const rootPath = ls.repository.rootPath;
31+
32+
process.env.LERNA_ROOT_PATH = rootPath;
33+
let args = argv.slice(2);
34+
35+
// Force lerna command runs in non-parallel mode for VSCode builds
36+
if (isVSCode()) {
37+
args = args.filter(arg => arg !== '--parallel');
38+
}
39+
return build.runCLI('lerna/bin/lerna', args, options);
40+
}
41+
42+
module.exports = run;
43+
if (require.main === module) run(process.argv);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
"prettier:fix": "npm run prettier:cli -- --write",
3737
"clean": "lerna run clean --loglevel=silent --parallel && node packages/build/bin/run-clean \"packages/*/dist*\"",
3838
"clean:lerna": "lerna clean --yes --parallel --loglevel=silent",
39-
"build": "lerna run build --parallel --loglevel=silent",
39+
"build": "node bin/run-lerna run build --parallel --loglevel=silent",
4040
"build:full": "npm run clean:lerna && npm run bootstrap && npm test",
4141
"pretest": "npm run clean && npm run build",
4242
"test": "node packages/build/bin/run-nyc npm run mocha --scripts-prepend-node-path",

packages/build/bin/compile-package.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,10 @@ function run(argv, options) {
100100

101101
const args = [];
102102

103+
const cwd = process.env.LERNA_ROOT_PATH || process.cwd();
103104
if (tsConfigFile) {
104-
args.push('-p', tsConfigFile);
105+
// Make the config file relative the current directory
106+
args.push('-p', path.relative(cwd, tsConfigFile));
105107
}
106108

107109
if (outDir) {
@@ -114,7 +116,12 @@ function run(argv, options) {
114116

115117
args.push(...compilerOpts);
116118

117-
return utils.runCLI('typescript/lib/tsc', args, options);
119+
if (options === true) {
120+
options = {dryRun: true};
121+
} else {
122+
options = options || {};
123+
}
124+
return utils.runCLI('typescript/lib/tsc', args, {cwd, ...options});
118125
}
119126

120127
module.exports = run;

0 commit comments

Comments
 (0)