From e597735a763206abb493229ab51655c77b969832 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emre=20Do=C4=9Fan?= Date: Mon, 14 Feb 2022 05:01:11 +0300 Subject: [PATCH] Ignoring node_modules folders inside nested workspaces as Lerna scopes (#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 --- .gitignore | 3 +++ .../a/nested-a/node_modules/dependency-a/package.json | 4 ++++ .../@packages/a/nested-a/package.json | 4 ++++ .../b/nested-b/node_modules/dependency-b/package.json | 4 ++++ .../@packages/b/nested-b/package.json | 4 ++++ .../fixtures/nested-workspaces/package.json | 11 +++++++++++ @commitlint/config-lerna-scopes/index.js | 2 +- @commitlint/config-lerna-scopes/index.test.js | 11 +++++++++++ 8 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 @commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/node_modules/dependency-a/package.json create mode 100644 @commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/package.json create mode 100644 @commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/node_modules/dependency-b/package.json create mode 100644 @commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/package.json create mode 100644 @commitlint/config-lerna-scopes/fixtures/nested-workspaces/package.json diff --git a/.gitignore b/.gitignore index c9d515cd7d..c74ceef1f1 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/node_modules/dependency-a/package.json b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/node_modules/dependency-a/package.json new file mode 100644 index 0000000000..2d821efc58 --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/node_modules/dependency-a/package.json @@ -0,0 +1,4 @@ +{ + "name": "@packages/dependency-a", + "version": "1.0.0" +} diff --git a/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/package.json b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/package.json new file mode 100644 index 0000000000..d22626edd3 --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/a/nested-a/package.json @@ -0,0 +1,4 @@ +{ + "name": "@packages/nested-a", + "version": "1.0.0" +} diff --git a/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/node_modules/dependency-b/package.json b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/node_modules/dependency-b/package.json new file mode 100644 index 0000000000..f3a1a9b5e9 --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/node_modules/dependency-b/package.json @@ -0,0 +1,4 @@ +{ + "name": "@packages/dependency-b", + "version": "1.0.0" +} diff --git a/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/package.json b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/package.json new file mode 100644 index 0000000000..a2006192a7 --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/@packages/b/nested-b/package.json @@ -0,0 +1,4 @@ +{ + "name": "@packages/nested-b", + "version": "1.0.0" +} diff --git a/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/package.json b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/package.json new file mode 100644 index 0000000000..628cdcdbe0 --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/nested-workspaces/package.json @@ -0,0 +1,11 @@ +{ + "name": "nested-workspaces", + "version": "1.0.0", + "workspaces": [ + "@packages/**" + ], + "devDependencies": { + "lerna": "^4.0.0", + "@lerna/project": "^4.0.0" + } +} diff --git a/@commitlint/config-lerna-scopes/index.js b/@commitlint/config-lerna-scopes/index.js index 73fec444df..b82ce0922c 100644 --- a/@commitlint/config-lerna-scopes/index.js +++ b/@commitlint/config-lerna-scopes/index.js @@ -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))); }); diff --git a/@commitlint/config-lerna-scopes/index.test.js b/@commitlint/config-lerna-scopes/index.test.js index 2028fc6f8c..7c44257f51 100644 --- a/@commitlint/config-lerna-scopes/index.test.js +++ b/@commitlint/config-lerna-scopes/index.test.js @@ -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']) + ); +});