Skip to content

Commit 12c24a8

Browse files
committed
chore: upgrade to lerna 3.x
1 parent 47e9369 commit 12c24a8

9 files changed

+108
-58
lines changed

bin/build-docs-site.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ rm -rf sandbox/loopback.io/
2828
git clone --depth 1 https://github.com/strongloop/loopback.io.git sandbox/loopback.io
2929

3030
# Bootstrap the `loopback.io` package
31-
lerna bootstrap --scope loopback.io-workflow-scripts
31+
lerna bootstrap --no-ci --scope loopback.io-workflow-scripts
3232

3333
pushd $REPO_ROOT/sandbox/loopback.io/ >/dev/null
3434

bin/config-lerna-scopes.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright IBM Corp. 2018. All Rights Reserved.
2+
// Node module: loopback-next
3+
// This file is licensed under the MIT License.
4+
// License text available at https://opensource.org/licenses/MIT
5+
6+
/**
7+
* This is an internal script to list lerna packages for loopback-next.
8+
* See https://github.com/marionebl/commitlint/pull/406
9+
*/
10+
'use strict';
11+
12+
const getPackages = require('@lerna/project').getPackages;
13+
module.exports = {
14+
rules: {
15+
// https://github.com/marionebl/commitlint/blob/master/docs/reference-rules.md
16+
'scope-enum': async ctx => [2, 'always', await listPackages(ctx)],
17+
},
18+
};
19+
20+
async function listPackages(context) {
21+
const ctx = context || {};
22+
const cwd = ctx.cwd || process.cwd();
23+
// List all lerna packages
24+
const packages = await getPackages(cwd);
25+
26+
// Get a list of names. Npm scopes will be removed, for example,
27+
// @loopback/core -> core
28+
return packages
29+
.map(pkg => pkg.name)
30+
.map(name => (name.charAt(0) === '@' ? name.split('/')[1] : name));
31+
}

bin/run-lerna.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,17 @@
1111
'use strict';
1212

1313
const path = require('path');
14-
const lerna = require('lerna');
14+
const Project = require('@lerna/project');
1515
const build = require('../packages/build');
1616

17-
function run(argv, options) {
18-
const ls = new lerna.LsCommand(
19-
null,
20-
{json: true, loglevel: 'silent'},
21-
path.join(__dirname, '..'),
22-
);
23-
const rootPath = ls.repository.rootPath;
17+
async function run(argv, options) {
18+
const project = new Project(path.join(__dirname, '..'));
19+
const rootPath = project.rootPath;
2420

2521
process.env.LERNA_ROOT_PATH = rootPath;
2622
let args = argv.slice(2);
2723

28-
return build.runCLI('lerna/bin/lerna', args, options);
24+
return build.runCLI('lerna/cli', args, options);
2925
}
3026

3127
module.exports = run;

bin/travis.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -e
44
# Running Code Linter -- Requires @loopback/build so it's bootstrapped
55
if [ $TASK = "code-lint" ]; then
66
echo "TASK => LINTING CODE"
7-
lerna bootstrap --scope @loopback/build
7+
lerna bootstrap --no-ci --scope @loopback/build
88
npm run lint
99

1010
# Commit Message Linter

bin/update-template-deps.js

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -12,51 +12,71 @@
1212

1313
const path = require('path');
1414
const fs = require('fs');
15-
const lerna = require('lerna');
16-
const ls = new lerna.LsCommand(null, {json: true, loglevel: 'silent'});
17-
18-
// We don't have to run the command as the preparations will collect packages
19-
ls.configureLogging();
20-
ls.runValidations();
21-
ls.runPreparations();
22-
23-
const pkgs = ls.filteredPackages.filter(pkg => !pkg.isPrivate()).map(pkg => ({
24-
name: pkg.name,
25-
version: pkg.version,
26-
}));
27-
28-
const lbModules = {};
29-
for (const p of pkgs) {
30-
lbModules[p.name] = '^' + p.version;
15+
16+
const Command = require('@lerna/command');
17+
18+
/**
19+
* A dummy command to get filtered packages
20+
*/
21+
class NopCommand extends Command {
22+
get requiresGit() {
23+
return false;
24+
}
25+
26+
initialize() {
27+
// No-op
28+
}
29+
30+
execute() {
31+
// No-op
32+
}
3133
}
3234

33-
const rootPath = ls.repository.rootPath;
35+
async function updateTemplateDeps() {
36+
const cmd = new NopCommand({_: [], loglevel: 'silent'});
3437

35-
// Load dependencies from `packages/build/package.json`
36-
const buildDeps = require(path.join(rootPath, 'packages/build/package.json'))
37-
.dependencies;
38+
await cmd; // Execute the command
3839

39-
// Load dependencies from `packages/cli/package.json`
40-
const cliPackageJson = path.join(rootPath, 'packages/cli/package.json');
40+
const pkgs = cmd.filteredPackages.filter(pkg => !pkg.private).map(pkg => ({
41+
name: pkg.name,
42+
version: pkg.version,
43+
}));
4144

42-
// Loading existing dependencies from `packages/cli/package.json`
43-
const cliPkg = require(cliPackageJson);
44-
cliPkg.config = cliPkg.config || {};
45-
const currentDeps = cliPkg.config.templateDependencies || {};
45+
const lbModules = {};
46+
for (const p of pkgs) {
47+
lbModules[p.name] = '^' + p.version;
48+
}
4649

47-
// Merge all entries
48-
const deps = Object.assign({}, currentDeps, buildDeps, lbModules);
50+
const rootPath = cmd.project.rootPath;
4951

50-
cliPkg.config.templateDependencies = deps;
52+
// Load dependencies from `packages/build/package.json`
53+
const buildDeps = require(path.join(rootPath, 'packages/build/package.json'))
54+
.dependencies;
5155

52-
// Convert to JSON
53-
const json = JSON.stringify(cliPkg, null, 2);
56+
// Load dependencies from `packages/cli/package.json`
57+
const cliPackageJson = path.join(rootPath, 'packages/cli/package.json');
5458

55-
if (process.argv[2] === '-f') {
56-
// Using `-f` to overwrite packages/cli/lib/dependencies.json
57-
fs.writeFileSync(cliPackageJson, json + '\n', {encoding: 'utf-8'});
58-
console.log('%s has been updated.', cliPackageJson);
59-
} else {
60-
// Otherwise write to console
61-
console.log(json);
59+
// Loading existing dependencies from `packages/cli/package.json`
60+
const cliPkg = require(cliPackageJson);
61+
cliPkg.config = cliPkg.config || {};
62+
const currentDeps = cliPkg.config.templateDependencies || {};
63+
64+
// Merge all entries
65+
const deps = Object.assign({}, currentDeps, buildDeps, lbModules);
66+
67+
cliPkg.config.templateDependencies = deps;
68+
69+
// Convert to JSON
70+
const json = JSON.stringify(cliPkg, null, 2);
71+
72+
if (process.argv[2] === '-f') {
73+
// Using `-f` to overwrite packages/cli/lib/dependencies.json
74+
fs.writeFileSync(cliPackageJson, json + '\n', {encoding: 'utf-8'});
75+
console.log('%s has been updated.', cliPackageJson);
76+
} else {
77+
// Otherwise write to console
78+
console.log(json);
79+
}
6280
}
81+
82+
if (require.main === module) updateTemplateDeps();

commitlint.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
module.exports = {
77
extends: [
88
'@commitlint/config-conventional',
9-
'@commitlint/config-lerna-scopes',
9+
// https://github.com/marionebl/commitlint/pull/406
10+
// '@commitlint/config-lerna-scopes',
11+
'./bin/config-lerna-scopes',
1012
],
1113
rules: {
1214
'header-max-length': [2, 'always', 100],

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lerna": "2.9.1",
2+
"lerna": "3.1.2",
33
"packages": [
44
"benchmark",
55
"docs",

package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212
"devDependencies": {
1313
"@commitlint/cli": "^7.0.0",
1414
"@commitlint/config-conventional": "^7.0.0",
15-
"@commitlint/config-lerna-scopes": "^7.0.0",
1615
"@commitlint/travis-cli": "^7.0.0",
1716
"@types/mocha": "^5.0.0",
1817
"coveralls": "^3.0.0",
1918
"cz-conventional-changelog": "^2.1.0",
2019
"husky": "^0.14.3",
21-
"lerna": "^2.9.1"
20+
"lerna": "^3.1.2"
2221
},
2322
"scripts": {
24-
"postinstall": "lerna bootstrap",
23+
"postinstall": "lerna bootstrap --no-ci",
2524
"prerelease": "npm run build:full && npm run mocha && npm run lint",
2625
"release": "lerna publish",
2726
"update-template-deps": "node bin/update-template-deps -f",

packages/cli/test/acceptance/app-run.acceptance.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
const path = require('path');
99
const assert = require('yeoman-assert');
1010
const helpers = require('yeoman-test');
11-
const lerna = require('lerna');
11+
const bootstrapCommandFactory = require('@lerna/bootstrap');
1212
const build = require('@loopback/build');
1313

1414
describe('app-generator (SLOW)', function() {
@@ -68,10 +68,12 @@ describe('app-generator (SLOW)', function() {
6868
});
6969
});
7070

71-
function lernaBootstrap(scope) {
72-
const cmd = new lerna.BootstrapCommand('', {
71+
async function lernaBootstrap(scope) {
72+
const cmd = bootstrapCommandFactory({
73+
_: [],
74+
ci: false,
7375
scope: scope,
7476
loglevel: 'silent',
7577
});
76-
return cmd.run();
78+
await cmd;
7779
}

0 commit comments

Comments
 (0)