Skip to content

Commit 4a005e1

Browse files
authored
fix: allow workspace prefix for local package (#520)
1 parent 01647bb commit 4a005e1

File tree

11 files changed

+106
-9
lines changed

11 files changed

+106
-9
lines changed

lib/dependency-versions.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,15 +154,19 @@ export function calculateMismatchingVersions(
154154
const localPackageVersions = versionObjectsForDep
155155
.filter((versionObject) => versionObject.isLocalPackageVersion)
156156
.map((versionObject) => versionObject.version);
157-
157+
const allVersionsHaveWorkspacePrefix = versions.every((version) =>
158+
version.startsWith('workspace:')
159+
);
160+
const hasIncompatibilityWithLocalPackageVersion = versions.some(
161+
(version) => !semver.satisfies(localPackageVersions[0], version)
162+
);
158163
if (
159164
localPackageVersions.length === 1 &&
160-
versions.some(
161-
(uniqueVersion) =>
162-
!semver.satisfies(localPackageVersions[0], uniqueVersion)
163-
)
165+
!allVersionsHaveWorkspacePrefix &&
166+
hasIncompatibilityWithLocalPackageVersion
164167
) {
165168
// If we saw a version for this dependency that isn't compatible with its actual local package version, add the local package version to the list of versions seen.
169+
// Note that using the `workspace:` prefix to refer to the local package version is allowed.
166170
versions = [...versions, ...localPackageVersions];
167171
}
168172

test/fixtures/all-version-types/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
"git6": "mochajs/mocha#4727d357ea",
2525
"git7": "user/repo#feature\/branch",
2626
"star": "*",
27-
"workspace1": "workspace:^",
28-
"workspace2": "workspace:*",
27+
"workspace1": "workspace:*",
28+
"workspace2": "workspace:^",
29+
"workspace3": "workspace:~",
30+
"workspace4": "workspace:^1.2.3",
31+
"workspace5": "workspace:path/to/baz",
2932
"latest": "latest",
3033
"//": "some comment",
3134
"blank": "",

test/fixtures/all-version-types/package1/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222
"git6": "mochajs/mocha#4727d357ea",
2323
"git7": "user/repo#feature\/branch",
2424
"star": "*",
25-
"workspace1": "workspace:^",
26-
"workspace2": "workspace:*",
25+
"workspace1": "workspace:*",
26+
"workspace2": "workspace:^",
27+
"workspace3": "workspace:~",
28+
"workspace4": "workspace:^1.2.3",
29+
"workspace5": "workspace:path/to/baz",
2730
"latest": "latest",
2831
"//": "some comment",
2932
"blank": "",
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"workspaces": [
3+
"*"
4+
],
5+
"dependencies": {
6+
"package1": "workspace:*"
7+
}
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "package1",
3+
"version": "1.0.0"
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"package1": "workspace:^"
4+
}
5+
}

test/fixtures/index.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,13 @@ export const FIXTURE_PATH_ALL_VERSION_TYPES = join(
6666
FIXTURE_PATH,
6767
'all-version-types'
6868
);
69+
70+
export const FIXTURE_PATH_VALID_WITH_WORKSPACE_PREFIX = join(
71+
FIXTURE_PATH,
72+
'valid-with-workspace-prefix'
73+
);
74+
75+
export const FIXTURE_PATH_INCONSISTENT_WITH_WORKSPACE_PREFIX = join(
76+
FIXTURE_PATH,
77+
'inconsistent-with-workspace-prefix'
78+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"workspaces": [
3+
"*"
4+
],
5+
"dependencies": {
6+
"package1": "workspace:*"
7+
}
8+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "package1",
3+
"version": "1.0.0"
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"dependencies": {
3+
"package1": "workspace:*"
4+
}
5+
}

0 commit comments

Comments
 (0)