Skip to content

Commit 238bd2d

Browse files
authored
pnpm workspace root package should not require name (#590)
1 parent 93d8f8e commit 238bd2d

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

lib/package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Package {
3434
}
3535

3636
get name() {
37-
if (this.packageJson.workspaces && !this.packageJson.name) {
37+
if (this.workspacePatterns.length > 0 && !this.packageJson.name) {
3838
return '(Root)';
3939
}
4040
if (!this.packageJson.name) {

test/fixtures/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ export const FIXTURE_PATH_PACKAGE_MISSING_NAME = join(
4040
FIXTURE_PATH,
4141
'package-missing-name'
4242
);
43+
export const FIXTURE_PATH_WORKSPACE_PNPM_MISSING_NAME = join(
44+
FIXTURE_PATH,
45+
'workspace-pnpm-missing-name'
46+
);
4347
export const FIXTURE_PATH_INCONSISTENT_LOCAL_PACKAGE_VERSION = join(
4448
FIXTURE_PATH,
4549
'inconsistent-local-package-version'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"name": "package1"
3+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages:
2+
- packages

test/lib/package-test.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { Package } from '../../lib/package.js';
2-
import { FIXTURE_PATH_PACKAGE_MISSING_NAME } from '../fixtures/index.js';
2+
import {
3+
FIXTURE_PATH_PACKAGE_MISSING_NAME,
4+
FIXTURE_PATH_WORKSPACE_PNPM_MISSING_NAME,
5+
} from '../fixtures/index.js';
36
import { join } from 'node:path';
47

58
describe('Utils | Package', function () {
@@ -16,4 +19,20 @@ describe('Utils | Package', function () {
1619
)} missing \`name\``
1720
);
1821
});
22+
23+
it('uses (Root) with name-less workspace root package', function () {
24+
const package_ = new Package(
25+
FIXTURE_PATH_PACKAGE_MISSING_NAME,
26+
FIXTURE_PATH_PACKAGE_MISSING_NAME
27+
);
28+
expect(package_.name).toStrictEqual('(Root)');
29+
});
30+
31+
it('uses (Root) with name-less workspace root package (pnpm)', function () {
32+
const package_ = new Package(
33+
FIXTURE_PATH_WORKSPACE_PNPM_MISSING_NAME,
34+
FIXTURE_PATH_WORKSPACE_PNPM_MISSING_NAME
35+
);
36+
expect(package_.name).toStrictEqual('(Root)');
37+
});
1938
});

0 commit comments

Comments
 (0)