File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ describe('package-manifest', () => {
66
66
a : '1.0.0' ,
67
67
b : '^2.0.0' ,
68
68
c : '~4.3.0' ,
69
+ d : 'workspace:^' ,
69
70
} ,
70
71
} ;
71
72
const validated = {
@@ -77,6 +78,7 @@ describe('package-manifest', () => {
77
78
a : '1.0.0' ,
78
79
b : '^2.0.0' ,
79
80
c : '~4.3.0' ,
81
+ d : 'workspace:^' ,
80
82
} ,
81
83
peerDependencies : { } ,
82
84
} ;
@@ -100,6 +102,7 @@ describe('package-manifest', () => {
100
102
a : '1.0.0' ,
101
103
b : '^2.0.0' ,
102
104
c : '~4.3.0' ,
105
+ d : 'workspace:^' ,
103
106
} ,
104
107
} ;
105
108
const validated = {
@@ -112,6 +115,7 @@ describe('package-manifest', () => {
112
115
a : '1.0.0' ,
113
116
b : '^2.0.0' ,
114
117
c : '~4.3.0' ,
118
+ d : 'workspace:^' ,
115
119
} ,
116
120
} ;
117
121
await fs . promises . writeFile ( manifestPath , JSON . stringify ( unvalidated ) ) ;
Original file line number Diff line number Diff line change @@ -142,6 +142,24 @@ function isValidPackageManifestVersionField(
142
142
return isTruthyString ( version ) && semver . validRange ( version ) !== null ;
143
143
}
144
144
145
+ /**
146
+ * Type guard to ensure that the provided version value is a valid dependency version
147
+ * specifier for a package manifest. This function validates both semantic versioning
148
+ * ranges and the special 'workspace:^' notation.
149
+ *
150
+ * @param version - The value to check.
151
+ * @returns `true` if the version is a valid string that either
152
+ * represents a semantic versioning range or is exactly 'workspace:^'.
153
+ * Otherwise, it returns `false`.
154
+ */
155
+ function isValidPackageManifestDependencyValue (
156
+ version : unknown ,
157
+ ) : version is string {
158
+ return (
159
+ isValidPackageManifestVersionField ( version ) || version === 'workspace:^'
160
+ ) ;
161
+ }
162
+
145
163
/**
146
164
* Retrieves and validates the "version" field within the package manifest
147
165
* object.
@@ -285,7 +303,8 @@ function isValidPackageManifestDependenciesField(
285
303
( isPlainObject ( depsValue ) &&
286
304
Object . entries ( depsValue ) . every ( ( [ pkgName , version ] ) => {
287
305
return (
288
- isTruthyString ( pkgName ) && isValidPackageManifestVersionField ( version )
306
+ isTruthyString ( pkgName ) &&
307
+ isValidPackageManifestDependencyValue ( version )
289
308
) ;
290
309
} ) )
291
310
) ;
You can’t perform that action at this time.
0 commit comments