@vltpkg/spec 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +52 -1
- package/package.json +3 -3
package/dist/browser.js
CHANGED
|
@@ -67,6 +67,37 @@ export const getOptions = (options) => ({
|
|
|
67
67
|
}
|
|
68
68
|
: defaultGitHostArchives,
|
|
69
69
|
});
|
|
70
|
+
// RFC3986 scheme chars minus `.`, min 2 chars. Excludes windows drive
|
|
71
|
+
// letters (`C:/x`) and hostnames (`notgithub.com:user/repo`).
|
|
72
|
+
const protocolRE = /^([a-zA-Z][a-zA-Z0-9+-]+):/;
|
|
73
|
+
const builtinProtocols = new Set([
|
|
74
|
+
'catalog',
|
|
75
|
+
'workspace',
|
|
76
|
+
'registry',
|
|
77
|
+
'file',
|
|
78
|
+
'http',
|
|
79
|
+
'https',
|
|
80
|
+
'git',
|
|
81
|
+
'git+ssh',
|
|
82
|
+
'git+http',
|
|
83
|
+
'git+https',
|
|
84
|
+
'git+file',
|
|
85
|
+
]);
|
|
86
|
+
/**
|
|
87
|
+
* Return the scheme if `str` starts with a protocol that is neither
|
|
88
|
+
* built-in nor configured, otherwise `undefined`.
|
|
89
|
+
*/
|
|
90
|
+
const unknownProtocol = (str, options) => {
|
|
91
|
+
const p = protocolRE.exec(str)?.[1];
|
|
92
|
+
return (p === undefined ||
|
|
93
|
+
builtinProtocols.has(p) ||
|
|
94
|
+
p === options['default-registry-alias'] ||
|
|
95
|
+
options.registries[p] !== undefined ||
|
|
96
|
+
options['git-hosts'][p] !== undefined ||
|
|
97
|
+
options['jsr-registries'][p] !== undefined) ?
|
|
98
|
+
undefined
|
|
99
|
+
: p;
|
|
100
|
+
};
|
|
70
101
|
/**
|
|
71
102
|
* Various nameless scenarios that are handled in the
|
|
72
103
|
* standard spec parsing and should return an unknown name.
|
|
@@ -98,7 +129,8 @@ const startsWithSpecIdentifier = (spec, options) => spec.startsWith('/') ||
|
|
|
98
129
|
...Object.keys(options['git-hosts']),
|
|
99
130
|
...Object.keys(options.registries),
|
|
100
131
|
...Object.keys(options['jsr-registries']),
|
|
101
|
-
].some(key => spec.startsWith(`${key}:`))
|
|
132
|
+
].some(key => spec.startsWith(`${key}:`)) ||
|
|
133
|
+
unknownProtocol(spec, options) !== undefined;
|
|
102
134
|
/**
|
|
103
135
|
* Returns the location in which the first `@` value is found in a given
|
|
104
136
|
* string, also takes into account that a string starting with @ is
|
|
@@ -254,6 +286,7 @@ export class Spec {
|
|
|
254
286
|
}
|
|
255
287
|
else {
|
|
256
288
|
this.spec = spec;
|
|
289
|
+
this.#assertKnownProtocol(spec);
|
|
257
290
|
// Check if this spec starts with a known registry identifier
|
|
258
291
|
// but exclude git specs like 'git@github:a/b'
|
|
259
292
|
if (!spec.startsWith('git@') &&
|
|
@@ -470,6 +503,7 @@ export class Spec {
|
|
|
470
503
|
this.spec = `${this.name}@${this.bareSpec}`;
|
|
471
504
|
return;
|
|
472
505
|
}
|
|
506
|
+
this.#assertKnownProtocol(this.bareSpec);
|
|
473
507
|
// legacy! once upon a time, `user/project` was a shorthand for pulling
|
|
474
508
|
// packages from github, instead of the more verbose and explicit
|
|
475
509
|
// `github:user/project`.
|
|
@@ -632,6 +666,23 @@ export class Spec {
|
|
|
632
666
|
this.spec = this.name + '@' + this.bareSpec;
|
|
633
667
|
return this.subspec;
|
|
634
668
|
}
|
|
669
|
+
#assertKnownProtocol(str) {
|
|
670
|
+
const proto = unknownProtocol(str, this.options);
|
|
671
|
+
if (proto === undefined)
|
|
672
|
+
return;
|
|
673
|
+
throw this.#error(`Protocol ${proto}: is not defined`, {
|
|
674
|
+
found: `${proto}:`,
|
|
675
|
+
validOptions: [
|
|
676
|
+
...new Set([
|
|
677
|
+
...builtinProtocols,
|
|
678
|
+
this.options['default-registry-alias'],
|
|
679
|
+
...Object.keys(this.options.registries),
|
|
680
|
+
...Object.keys(this.options['git-hosts']),
|
|
681
|
+
...Object.keys(this.options['jsr-registries']),
|
|
682
|
+
]),
|
|
683
|
+
].map(p => `${p}:`),
|
|
684
|
+
});
|
|
685
|
+
}
|
|
635
686
|
#error(message, extra = {}) {
|
|
636
687
|
return error(message, { spec: this.spec, ...extra }, this.#error);
|
|
637
688
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/spec",
|
|
3
3
|
"description": "Package specifier library",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.5",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"url": "http://vlt.sh"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@vltpkg/error-cause": "1.0.
|
|
17
|
-
"@vltpkg/semver": "1.0.
|
|
16
|
+
"@vltpkg/error-cause": "1.0.5",
|
|
17
|
+
"@vltpkg/semver": "1.0.5"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@eslint/js": "^9.39.1",
|