File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ describe('package-manifest', () => {
6666 a : '1.0.0' ,
6767 b : '^2.0.0' ,
6868 c : '~4.3.0' ,
69+ d : 'workspace:^' ,
6970 } ,
7071 } ;
7172 const validated = {
@@ -77,6 +78,7 @@ describe('package-manifest', () => {
7778 a : '1.0.0' ,
7879 b : '^2.0.0' ,
7980 c : '~4.3.0' ,
81+ d : 'workspace:^' ,
8082 } ,
8183 peerDependencies : { } ,
8284 } ;
@@ -100,6 +102,7 @@ describe('package-manifest', () => {
100102 a : '1.0.0' ,
101103 b : '^2.0.0' ,
102104 c : '~4.3.0' ,
105+ d : 'workspace:^' ,
103106 } ,
104107 } ;
105108 const validated = {
@@ -112,6 +115,7 @@ describe('package-manifest', () => {
112115 a : '1.0.0' ,
113116 b : '^2.0.0' ,
114117 c : '~4.3.0' ,
118+ d : 'workspace:^' ,
115119 } ,
116120 } ;
117121 await fs . promises . writeFile ( manifestPath , JSON . stringify ( unvalidated ) ) ;
Original file line number Diff line number Diff line change @@ -142,6 +142,24 @@ function isValidPackageManifestVersionField(
142142 return isTruthyString ( version ) && semver . validRange ( version ) !== null ;
143143}
144144
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+
145163/**
146164 * Retrieves and validates the "version" field within the package manifest
147165 * object.
@@ -285,7 +303,8 @@ function isValidPackageManifestDependenciesField(
285303 ( isPlainObject ( depsValue ) &&
286304 Object . entries ( depsValue ) . every ( ( [ pkgName , version ] ) => {
287305 return (
288- isTruthyString ( pkgName ) && isValidPackageManifestVersionField ( version )
306+ isTruthyString ( pkgName ) &&
307+ isValidPackageManifestDependencyValue ( version )
289308 ) ;
290309 } ) )
291310 ) ;
You can’t perform that action at this time.
0 commit comments