Skip to content

Commit

Permalink
Ignoring node_modules folders inside nested workspaces as Lerna scopes (
Browse files Browse the repository at this point in the history
#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
  • Loading branch information
emredoganm committed Feb 14, 2022
1 parent b273403 commit e597735
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -12,3 +12,6 @@ package.json.lerna_backup
/*.iml
tsconfig.tsbuildinfo
coverage

# For testing nested workspaces does not have the package's dependencies name in the scope
!**/config-lerna-scopes/fixtures/nested-workspaces/**/node_modules

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,4 @@
{
"name": "@packages/nested-a",
"version": "1.0.0"
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

@@ -0,0 +1,4 @@
{
"name": "@packages/nested-b",
"version": "1.0.0"
}
@@ -0,0 +1,11 @@
{
"name": "nested-workspaces",
"version": "1.0.0",
"workspaces": [
"@packages/**"
],
"devDependencies": {
"lerna": "^4.0.0",
"@lerna/project": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion @commitlint/config-lerna-scopes/index.js
Expand Up @@ -25,7 +25,7 @@ function getPackages(context) {
workspaces.map((ws) => {
return Path.posix.join(ws, 'package.json');
}),
{cwd}
{cwd, ignore: ['**/node_modules/**']}
).then((pJsons = []) => {
return pJsons.map((pJson) => require(Path.join(cwd, pJson)));
});
Expand Down
11 changes: 11 additions & 0 deletions @commitlint/config-lerna-scopes/index.test.js
Expand Up @@ -82,3 +82,14 @@ test('returns expected value for yarn workspaces', async () => {
const [, , value] = await fn({cwd});
expect(value.sort()).toEqual(['a', 'b']);
});

test('returns expected value for yarn workspaces has nested packages', async () => {
const {'scope-enum': fn} = config.rules;
const cwd = await npm.bootstrap('fixtures/nested-workspaces', __dirname);

const [, , value] = await fn({cwd});
expect(value).toEqual(expect.arrayContaining(['nested-a', 'nested-b']));
expect(value).toEqual(
expect.not.arrayContaining(['dependency-a', 'dependency-b'])
);
});

0 comments on commit e597735

Please sign in to comment.