Skip to content

Commit e6c2823

Browse files
committed
chore: upgrade to lerna 3.x
1 parent 5a8c5d6 commit e6c2823

File tree

7 files changed

+98
-57
lines changed

7 files changed

+98
-57
lines changed

bin/config-lerna-scopes.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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/blob/master/%40commitlint/config-lerna-scopes/index.js
9+
*/
10+
'use strict';
11+
12+
const getPackages = require('@lerna/project').getPackages;
13+
module.exports = {
14+
rules: {
15+
'scope-enum': ctx => [2, 'always', listPackages(ctx)],
16+
},
17+
};
18+
19+
async function listPackages(context) {
20+
const ctx = context || {};
21+
const cwd = ctx.cwd || process.cwd();
22+
const packages = await getPackages(cwd);
23+
24+
return packages
25+
.map(pkg => pkg.name)
26+
.map(name => (name.charAt(0) === '@' ? name.split('/')[1] : name));
27+
}

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/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: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,7 @@
44
// License text available at https://opensource.org/licenses/MIT
55

66
module.exports = {
7-
extends: [
8-
'@commitlint/config-conventional',
9-
'@commitlint/config-lerna-scopes',
10-
],
7+
extends: ['@commitlint/config-conventional', './bin/config-lerna-scopes'],
118
rules: {
129
'header-max-length': [2, 'always', 100],
1310
'body-leading-blank': [2, 'always'],

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.1",
33
"packages": [
44
"benchmark",
55
"docs",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"coveralls": "^3.0.0",
1919
"cz-conventional-changelog": "^2.1.0",
2020
"husky": "^0.14.3",
21-
"lerna": "^2.9.1"
21+
"lerna": "^3.1.1"
2222
},
2323
"scripts": {
2424
"postinstall": "lerna bootstrap",

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

Lines changed: 5 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,11 @@ 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+
_: [],
7374
scope: scope,
7475
loglevel: 'silent',
7576
});
76-
return cmd.run();
77+
await cmd;
7778
}

0 commit comments

Comments
 (0)