Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pnpm workspace root package should not require name #590

Merged
merged 1 commit into from
May 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Package {
}

get name() {
if (this.packageJson.workspaces && !this.packageJson.name) {
if (this.workspacePatterns.length > 0 && !this.packageJson.name) {
return '(Root)';
}
if (!this.packageJson.name) {
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ export const FIXTURE_PATH_PACKAGE_MISSING_NAME = join(
FIXTURE_PATH,
'package-missing-name'
);
export const FIXTURE_PATH_WORKSPACE_PNPM_MISSING_NAME = join(
FIXTURE_PATH,
'workspace-pnpm-missing-name'
);
export const FIXTURE_PATH_INCONSISTENT_LOCAL_PACKAGE_VERSION = join(
FIXTURE_PATH,
'inconsistent-local-package-version'
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/workspace-pnpm-missing-name/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "package1"
}
2 changes: 2 additions & 0 deletions test/fixtures/workspace-pnpm-missing-name/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
packages:
- packages
21 changes: 20 additions & 1 deletion test/lib/package-test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Package } from '../../lib/package.js';
import { FIXTURE_PATH_PACKAGE_MISSING_NAME } from '../fixtures/index.js';
import {
FIXTURE_PATH_PACKAGE_MISSING_NAME,
FIXTURE_PATH_WORKSPACE_PNPM_MISSING_NAME,
} from '../fixtures/index.js';
import { join } from 'node:path';

describe('Utils | Package', function () {
Expand All @@ -16,4 +19,20 @@ describe('Utils | Package', function () {
)} missing \`name\``
);
});

it('uses (Root) with name-less workspace root package', function () {
const package_ = new Package(
FIXTURE_PATH_PACKAGE_MISSING_NAME,
FIXTURE_PATH_PACKAGE_MISSING_NAME
);
expect(package_.name).toStrictEqual('(Root)');
});

it('uses (Root) with name-less workspace root package (pnpm)', function () {
const package_ = new Package(
FIXTURE_PATH_WORKSPACE_PNPM_MISSING_NAME,
FIXTURE_PATH_WORKSPACE_PNPM_MISSING_NAME
);
expect(package_.name).toStrictEqual('(Root)');
});
});