Add support for `workspace:` dependency pattern prefix
MODIFY
internal/codec-js-manifest/dependencies.test.md
internal/codec-js-manifest/dependencies.test.md
@@ -91,3 +91,9 @@ npm {
}
}
```
+
+## `can parse workspace patterns`
+
+```javascript
+workspace {path: "*"}
+```

MODIFY
internal/codec-js-manifest/dependencies.test.ts
internal/codec-js-manifest/dependencies.test.ts
@@ -44,3 +44,12 @@ test(
);
},
);
+
+test(
+ "can parse workspace patterns",
+ async (t) => {
+ t.snapshot(
+ parseDependencyPattern(consumeUnknown("workspace:*", "parse/json"), false),
+ );
+ },
+);

MODIFY
internal/codec-js-manifest/dependencies.ts
internal/codec-js-manifest/dependencies.ts
@@ -27,7 +27,8 @@ export type DependencyPattern =
| FilePattern
| TagPattern
| NpmPattern
- | LinkPattern;
+ | LinkPattern
+ | WorkspacePattern;
export type ManifestDependencies = Map<ManifestName, DependencyPattern>;
@@ -76,6 +77,9 @@ export function stringifyDependencyPattern(pattern: DependencyPattern): string {
case "link":
return `${LINK_PREFIX}${pattern.path.join()}`;
+
+ case "workspace":
+ return `${WORKSPACE_PREFIX}${pattern.path}`;
}
}
@@ -100,7 +104,7 @@ function removePrefix(prefix: string, value: string): string {
}
}
-//# GIST
+//# Gist
const GIST_PREFIX = "gist:";
@@ -116,7 +120,7 @@ function parseGist(pattern: string): GistPattern {
};
}
-//# HOSTED GIT
+//# Hosted Gist
export type HostedGitHost = "bitbucket" | "github" | "gitlab";
type IncompleteHostedGitPattern = {
@@ -196,7 +200,7 @@ export function getHostedGitURL(pattern: IncompleteHostedGitPattern): string {
}
}
-//# REGULAR GIT
+//# Regular Git
type GitPattern = UrlWithHash & {
type: "git";
};
@@ -216,7 +220,7 @@ function parseGit(pattern: string, consumer: Consumer): GitPattern {
};
}
-//# TARBALL
+//# HTTP Tarball
type HTTPTarballPattern = UrlWithHash & {
type: "http-tarball";
};
@@ -231,7 +235,7 @@ function parseHttpTarball(
};
}
-//# SEMVER
+//# Semver Range
type SemverPattern = {
type: "semver";
range: SemverRangeNode;
@@ -260,7 +264,7 @@ function parseSemver(
};
}
-//# FILE
+//# File
const FILE_PREFIX_REGEX = /^\.{1,2}\//;
type FilePattern = {
@@ -275,7 +279,7 @@ function parseFile(pattern: string): FilePattern {
};
}
-//# TAG
+//# Tag
// This regex will likely need to be refined, not sure what the allowable characters of a tag are
const TAG_REGEX = /^[a-z]+$/g;
@@ -292,7 +296,22 @@ function parseTag(pattern: string): TagPattern {
};
}
-//# LINK
+//# Workspace
+const WORKSPACE_PREFIX = "workspace:";
+
+type WorkspacePattern = {
+ type: "workspace";
+ path: string;
+};
+
+function parseWorkspace(pattern: string): WorkspacePattern {
+ return {
+ type: "workspace",
+ path: pattern.slice(WORKSPACE_PREFIX.length),
+ };
+}
+
+//# Link
const LINK_PREFIX = "link:";
type LinkPattern = {
@@ -307,7 +326,7 @@ function parseLink(pattern: string): LinkPattern {
};
}
-//# NPM
+//# Explicit npm
const NPM_PREFIX = "npm:";
type NpmPattern = {
@@ -436,6 +455,9 @@ export function parseGitDependencyPattern(
return undefined;
}
+// Check if we received something that looks like a pattern that we don't support
+const UNSUPPORTED_PATTERN = /^([a-z]+):/i;
+
export function parseDependencyPattern(
consumer: Consumer,
loose: boolean,
@@ -451,6 +473,10 @@ export function parseDependencyPattern(
return parseHttpTarball(pattern, consumer);
}
+ if (pattern.startsWith(WORKSPACE_PREFIX)) {
+ return parseWorkspace(pattern);
+ }
+
if (pattern.startsWith(GIST_PREFIX)) {
return parseGist(pattern);
}
@@ -475,6 +501,15 @@ export function parseDependencyPattern(
return parseTag(pattern);
}
+ const unsupportedMatch = pattern.match(UNSUPPORTED_PATTERN);
+ if (unsupportedMatch != null) {
+ throw consumer.unexpected(
+ descriptions.MANIFEST.UNSUPPORTED_DEPENDENCY_PATTERN_PREFIX(
+ unsupportedMatch[1],
+ ),
+ );
+ }
+
return parseSemver(pattern, consumer, loose);
}

MODIFY
internal/diagnostics/descriptions/manifest.ts
internal/diagnostics/descriptions/manifest.ts
@@ -37,4 +37,7 @@ export const manifest = createDiagnosticsCategory({
TYPO: (typoKey: string, correctKey: string) => ({
message: markup`${typoKey} is a typo of ${correctKey}`,
}),
+ UNSUPPORTED_DEPENDENCY_PATTERN_PREFIX: (prefix: string) => ({
+ message: markup`Unsupported dependency pattern prefix <emphasis>${prefix}</emphasis>`,
+ }),
});

Add support for `workspace:` dependency pattern prefix (#1127)