diff --git a/@commitlint/config-lerna-scopes/fixtures/modules/lerna.json b/@commitlint/config-lerna-scopes/fixtures/modules/lerna.json new file mode 100644 index 0000000000..41c31e2033 --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/modules/lerna.json @@ -0,0 +1,5 @@ +{ + "lerna": "4", + "version": "1.0.0", + "packages": ["packages/*"] +} diff --git a/@commitlint/config-lerna-scopes/fixtures/modules/package.json b/@commitlint/config-lerna-scopes/fixtures/modules/package.json new file mode 100644 index 0000000000..06aff06a63 --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/modules/package.json @@ -0,0 +1,7 @@ +{ + "name": "basic", + "version": "1.0.0", + "devDependencies": { + "lerna": "^4.0.0" + } +} diff --git a/@commitlint/config-lerna-scopes/fixtures/modules/packages/a/package.json b/@commitlint/config-lerna-scopes/fixtures/modules/packages/a/package.json new file mode 100644 index 0000000000..9113c2528e --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/modules/packages/a/package.json @@ -0,0 +1,4 @@ +{ + "name": "a", + "version": "1.0.0" +} diff --git a/@commitlint/config-lerna-scopes/fixtures/modules/packages/module/package.json b/@commitlint/config-lerna-scopes/fixtures/modules/packages/module/package.json new file mode 100644 index 0000000000..3dbc1ca591 --- /dev/null +++ b/@commitlint/config-lerna-scopes/fixtures/modules/packages/module/package.json @@ -0,0 +1,3 @@ +{ + "type": "module" +} diff --git a/@commitlint/config-lerna-scopes/index.js b/@commitlint/config-lerna-scopes/index.js index daad6a6e9b..73fec444df 100644 --- a/@commitlint/config-lerna-scopes/index.js +++ b/@commitlint/config-lerna-scopes/index.js @@ -49,6 +49,7 @@ function getPackages(context) { .then((packages) => { return packages .map((pkg) => pkg.name) + .filter(Boolean) .map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name)); }); } diff --git a/@commitlint/config-lerna-scopes/index.test.js b/@commitlint/config-lerna-scopes/index.test.js index c1214327b5..052260ef5c 100644 --- a/@commitlint/config-lerna-scopes/index.test.js +++ b/@commitlint/config-lerna-scopes/index.test.js @@ -60,6 +60,14 @@ test('returns expected value for basic lerna repository', async () => { expect(value).toEqual(['a', 'b']); }); +test('returns expected value for lerna repository containing modules', async () => { + const {'scope-enum': fn} = config.rules; + const cwd = await lerna.bootstrap('modules', __dirname); + + const [, , value] = await fn({cwd}); + expect(value).toEqual(['a']); +}); + test('returns expected value for scoped lerna repository', async () => { const {'scope-enum': fn} = config.rules; const cwd = await lerna.bootstrap('scoped', __dirname);