Skip to content

Commit 22f0930

Browse files
committed
fix(config-lerna-scopes): remove deprecated @lerna/project dependency
BREAKING CHANGE: drop support for lerna < 7.1.0
1 parent 73f23f9 commit 22f0930

File tree

26 files changed

+1314
-1789
lines changed

26 files changed

+1314
-1789
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lerna": "4",
2+
"lerna": "8",
33
"version": "1.0.0",
44
"packages": ["packages/*"]
55
}

@commitlint/config-lerna-scopes/fixtures/basic/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "basic",
33
"version": "1.0.0",
44
"devDependencies": {
5-
"lerna": "^4.0.0",
6-
"@lerna/project": "^4.0.0"
5+
"lerna": "^8.1.9"
76
}
87
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "a",
2+
"name": "@commitlint-lerna-scopes/basic-a",
33
"version": "1.0.0"
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "b",
2+
"name": "@commitlint-lerna-scopes/basic-b",
33
"version": "1.0.0"
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lerna": "4",
2+
"lerna": "8",
33
"version": "1.0.0",
44
"packages": ["packages/*"]
55
}

@commitlint/config-lerna-scopes/fixtures/empty/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "empty",
33
"version": "1.0.0",
44
"devDependencies": {
5-
"lerna": "^4.0.0",
5+
"lerna": "^8.1.9",
66
"@lerna/project": "^4.0.0"
77
}
88
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lerna": "4",
2+
"lerna": "8",
33
"version": "1.0.0",
44
"packages": ["packages/*"]
55
}

@commitlint/config-lerna-scopes/fixtures/modules/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "basic",
33
"version": "1.0.0",
44
"devDependencies": {
5-
"lerna": "^4.0.0",
6-
"@lerna/project": "^4.0.0"
5+
"lerna": "^8.1.9"
76
}
87
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "a",
2+
"name": "@commitlint-lerna-scopes/modules-a",
33
"version": "1.0.0"
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "@packages/nested-a",
2+
"name": "@commitlint-lerna-scopes/nested-a",
33
"version": "1.0.0"
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "@packages/nested-b",
2+
"name": "@commitlint-lerna-scopes/nested-b",
33
"version": "1.0.0"
44
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"lerna": "8",
3+
"version": "1.0.0",
4+
"packages": ["packages/**"]
5+
}
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
{
22
"name": "nested-workspaces",
33
"version": "1.0.0",
4-
"workspaces": [
5-
"@packages/**"
6-
],
74
"devDependencies": {
8-
"lerna": "^4.0.0",
9-
"@lerna/project": "^4.0.0"
5+
"lerna": "^8.1.9"
106
}
117
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "@packages/a",
2+
"name": "@commitlint-lerna-scopes/scoped-a",
33
"version": "1.0.0"
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"name": "@packages/b",
2+
"name": "@commitlint-lerna-scopes/scoped-b",
33
"version": "1.0.0"
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"lerna": "4",
2+
"lerna": "8",
33
"version": "1.0.0",
44
"packages": ["@packages/*"]
55
}

@commitlint/config-lerna-scopes/fixtures/scoped/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"name": "scoped",
33
"version": "1.0.0",
44
"devDependencies": {
5-
"lerna": "^4.0.0",
6-
"@lerna/project": "^4.0.0"
5+
"lerna": "^8.1.9"
76
}
87
}

@commitlint/config-lerna-scopes/fixtures/yarn/@packages/a/package.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

@commitlint/config-lerna-scopes/fixtures/yarn/@packages/b/package.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

@commitlint/config-lerna-scopes/fixtures/yarn/package.json

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 18 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,31 @@
1-
import {createRequire} from 'module';
2-
import Path from 'path';
3-
4-
import {globSync} from 'glob';
51
import importFrom from 'import-from';
6-
import semver from 'semver';
7-
8-
const require = createRequire(import.meta.url);
92

103
export default {
11-
utils: {getPackages},
4+
utils: {
5+
getPackages,
6+
},
127
rules: {
138
'scope-enum': (ctx) =>
149
getPackages(ctx).then((packages) => [2, 'always', packages]),
1510
},
1611
};
1712

18-
function getPackages(context) {
19-
return Promise.resolve()
20-
.then(() => {
21-
const ctx = context || {};
22-
const cwd = ctx.cwd || process.cwd();
23-
24-
const {workspaces} = require(Path.join(cwd, 'package.json'));
25-
if (Array.isArray(workspaces) && workspaces.length) {
26-
// use yarn workspaces
13+
async function getPackages(context) {
14+
const ctx = context || {};
15+
const cwd = ctx.cwd || process.cwd();
2716

28-
const wsGlobs = workspaces.flatMap((ws) => {
29-
const path = Path.posix.join(ws, 'package.json');
30-
return globSync(path, {cwd, ignore: ['**/node_modules/**']});
31-
});
17+
// https://lerna.js.org/docs/api-reference/utilities#detectprojects
18+
const {detectProjects} = importFrom(cwd, 'lerna/utils');
19+
// https://github.com/lerna/lerna/blob/main/libs/core/src/lib/project-graph-with-packages.ts#L14
20+
const projectGraph = await detectProjects(cwd);
21+
const packages = Object.values(projectGraph.nodes)
22+
.map((node) => node.package)
23+
.filter(Boolean);
3224

33-
return wsGlobs.map((pJson) => require(Path.join(cwd, pJson)));
34-
}
35-
36-
const lernaVersion = getLernaVersion(cwd);
37-
if (semver.lt(lernaVersion, '3.0.0')) {
38-
const Repository = importFrom(cwd, 'lerna/lib/Repository');
39-
const PackageUtilities = importFrom(cwd, 'lerna/lib/PackageUtilities');
40-
41-
const repository = new Repository(cwd);
42-
return PackageUtilities.getPackages({
43-
packageConfigs: repository.packageConfigs,
44-
rootPath: cwd,
45-
});
46-
}
47-
48-
const {getPackages} = importFrom(cwd, '@lerna/project');
49-
return getPackages(cwd);
50-
})
51-
.then((packages) => {
52-
return packages
53-
.map((pkg) => pkg.name)
54-
.filter(Boolean)
55-
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
56-
});
57-
}
25+
console.log('>>>>>> PACKAGES', packages);
5826

59-
function getLernaVersion(cwd) {
60-
const moduleEntrypoint = require.resolve('lerna', {
61-
paths: [cwd],
62-
});
63-
const moduleDir = Path.join(
64-
moduleEntrypoint.slice(0, moduleEntrypoint.lastIndexOf('node_modules')),
65-
'node_modules',
66-
'lerna'
67-
);
68-
const modulePackageJson = Path.join(moduleDir, 'package.json');
69-
return require(modulePackageJson).version;
27+
return packages
28+
.map((pkg) => pkg.name)
29+
.filter(Boolean)
30+
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
7031
}

@commitlint/config-lerna-scopes/index.test.js

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ test('returns empty value for empty lerna repository', async () => {
5858
expect(value).toEqual([]);
5959
});
6060

61-
test('returns expected value for basic lerna repository', async () => {
61+
test.only('returns expected value for basic lerna repository', async () => {
6262
const {'scope-enum': fn} = config.rules;
6363
const cwd = await npm.bootstrap('fixtures/basic', __dirname);
6464

6565
const [, , value] = await fn({cwd});
66-
expect(value).toEqual(['a', 'b']);
66+
expect(value).toEqual(['a', 'b', 'c']);
6767
});
6868

6969
test('returns expected value for lerna repository containing modules', async () => {
@@ -81,21 +81,3 @@ test('returns expected value for scoped lerna repository', async () => {
8181
const [, , value] = await fn({cwd});
8282
expect(value).toEqual(['a', 'b']);
8383
});
84-
85-
test('returns expected value for yarn workspaces', async () => {
86-
const {'scope-enum': fn} = config.rules;
87-
const cwd = path.join(__dirname, 'fixtures', 'yarn');
88-
const [, , value] = await fn({cwd});
89-
expect(value.sort()).toEqual(['a', 'b']);
90-
});
91-
92-
test('returns expected value for yarn workspaces has nested packages', async () => {
93-
const {'scope-enum': fn} = config.rules;
94-
const cwd = await npm.bootstrap('fixtures/nested-workspaces', __dirname);
95-
96-
const [, , value] = await fn({cwd});
97-
expect(value).toEqual(expect.arrayContaining(['nested-a', 'nested-b']));
98-
expect(value).toEqual(
99-
expect.not.arrayContaining(['dependency-a', 'dependency-b'])
100-
);
101-
});

@commitlint/config-lerna-scopes/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
"lerna"
2424
],
2525
"author": "Mario Nebl <[email protected]>",
26+
"contributors": [
27+
"Jan Biasi (https://github.com/janbiasi)"
28+
],
2629
"license": "MIT",
2730
"bugs": {
2831
"url": "https://github.com/conventional-changelog/commitlint/issues"
2932
},
3033
"homepage": "https://commitlint.js.org/",
3134
"peerDependencies": {
32-
"lerna": ">=5 <9"
35+
"lerna": ">=7.1.0"
3336
},
3437
"peerDependenciesMeta": {
3538
"lerna": {
@@ -40,15 +43,13 @@
4043
"node": ">=v18"
4144
},
4245
"dependencies": {
43-
"@lerna/project": "^6.0.0",
44-
"glob": "^10.3.10",
4546
"import-from": "^4.0.0",
4647
"semver": "^7.6.0"
4748
},
4849
"devDependencies": {
4950
"@commitlint/test": "^19.5.0",
5051
"@commitlint/utils": "^19.5.0",
51-
"@types/glob": "^8.1.0"
52+
"lerna": "^8.1.9"
5253
},
5354
"gitHead": "70f7f4688b51774e7ac5e40e896cdaa3f132b2bc"
5455
}

lerna.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"lerna": "4",
2+
"lerna": "8",
33
"npmClient": "yarn",
4-
"useWorkspaces": true,
54
"version": "19.7.1"
65
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
"eslint-plugin-jest": "^28.8.2",
101101
"globals": "^15.13.0",
102102
"husky": "^9.1.5",
103-
"lerna": "^6.0.0",
103+
"lerna": "^8.1.9",
104104
"lint-staged": "15.4.3",
105105
"prettier": "^2.8.8",
106106
"typescript": "^5.2.2",

0 commit comments

Comments
 (0)