Skip to content

Commit e597735

Browse files
authored
Ignoring node_modules folders inside nested workspaces as Lerna scopes (conventional-changelog#3025)
* fix(config-lerna-scopes): fix the problem for not ignoring node modules for nested workspaces * test(config-lerna-scopes): add tests for ignoring node modules works for nested workspaces scopes
1 parent b273403 commit e597735

File tree

8 files changed

+42
-1
lines changed

8 files changed

+42
-1
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ package.json.lerna_backup
1212
/*.iml
1313
tsconfig.tsbuildinfo
1414
coverage
15+
16+
# For testing nested workspaces does not have the package's dependencies name in the scope
17+
!**/config-lerna-scopes/fixtures/nested-workspaces/**/node_modules

@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/node_modules/dependency-a/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@packages/nested-a",
3+
"version": "1.0.0"
4+
}

@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/node_modules/dependency-b/package.json

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "@packages/nested-b",
3+
"version": "1.0.0"
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "nested-workspaces",
3+
"version": "1.0.0",
4+
"workspaces": [
5+
"@packages/**"
6+
],
7+
"devDependencies": {
8+
"lerna": "^4.0.0",
9+
"@lerna/project": "^4.0.0"
10+
}
11+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function getPackages(context) {
2525
workspaces.map((ws) => {
2626
return Path.posix.join(ws, 'package.json');
2727
}),
28-
{cwd}
28+
{cwd, ignore: ['**/node_modules/**']}
2929
).then((pJsons = []) => {
3030
return pJsons.map((pJson) => require(Path.join(cwd, pJson)));
3131
});

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

+11
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,14 @@ test('returns expected value for yarn workspaces', async () => {
8282
const [, , value] = await fn({cwd});
8383
expect(value.sort()).toEqual(['a', 'b']);
8484
});
85+
86+
test('returns expected value for yarn workspaces has nested packages', async () => {
87+
const {'scope-enum': fn} = config.rules;
88+
const cwd = await npm.bootstrap('fixtures/nested-workspaces', __dirname);
89+
90+
const [, , value] = await fn({cwd});
91+
expect(value).toEqual(expect.arrayContaining(['nested-a', 'nested-b']));
92+
expect(value).toEqual(
93+
expect.not.arrayContaining(['dependency-a', 'dependency-b'])
94+
);
95+
});

0 commit comments

Comments
 (0)