@vltpkg/dep-id 0.0.0-9 → 1.0.0-rc.10
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/README.md +4 -4
- package/dist/esm/browser.d.ts +44 -0
- package/dist/esm/browser.d.ts.map +1 -1
- package/dist/esm/browser.js +259 -37
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/index.d.ts +10 -68
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +81 -168
- package/dist/esm/index.js.map +1 -1
- package/package.json +15 -14
package/README.md
CHANGED
|
@@ -24,7 +24,7 @@ import { manifest } from '@vltpkg/package-info'
|
|
|
24
24
|
// default registry
|
|
25
25
|
const spec = Spec.parse('x@latest')
|
|
26
26
|
const mani = await manifest(spec)
|
|
27
|
-
const id = getId(spec, mani) // registry
|
|
27
|
+
const id = getId(spec, mani) // registry··x@1.2.3
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
{
|
|
@@ -33,18 +33,18 @@ import { manifest } from '@vltpkg/package-info'
|
|
|
33
33
|
registries: { vlt: 'http://vlt.sh' },
|
|
34
34
|
})
|
|
35
35
|
const mani = await manifest(spec)
|
|
36
|
-
const id = getId(spec, mani) // registry
|
|
36
|
+
const id = getId(spec, mani) // registry·vlt·y@latest
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
{
|
|
40
40
|
// git, hosted
|
|
41
41
|
const spec = Spec.parse('x@github:a/b#branch')
|
|
42
42
|
const mani = await manifest(spec)
|
|
43
|
-
const id = getId(spec, mani) // git
|
|
43
|
+
const id = getId(spec, mani) // git·github:a/b·branch
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// Hydrate by providing a name, and options for the spec creation
|
|
47
|
-
const spec = hydrate('git
|
|
47
|
+
const spec = hydrate('git·github:a/b·branch', 'x') // x@github:a/b#branch
|
|
48
48
|
```
|
|
49
49
|
|
|
50
50
|
### Note
|
package/dist/esm/browser.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Spec } from '@vltpkg/spec/browser';
|
|
2
2
|
import type { SpecOptions } from '@vltpkg/spec/browser';
|
|
3
|
+
import type { Manifest } from '@vltpkg/types';
|
|
3
4
|
export declare const delimiter: Delimiter;
|
|
4
5
|
export type Delimiter = '·';
|
|
5
6
|
/**
|
|
@@ -52,6 +53,11 @@ export declare const joinDepIDTuple: (list: DepIDTuple) => DepID;
|
|
|
52
53
|
* turn a {@link DepID} into a {@link DepIDTuple}
|
|
53
54
|
*/
|
|
54
55
|
export declare const splitDepID: (id: string) => DepIDTuple;
|
|
56
|
+
/**
|
|
57
|
+
* Retrieves the base {@link DepID} for a given depID,
|
|
58
|
+
* ignoring any extra information that may be present.
|
|
59
|
+
*/
|
|
60
|
+
export declare const baseDepID: (id: string) => DepID;
|
|
55
61
|
/**
|
|
56
62
|
* Turn a {@link DepID} into a {@link Spec} object
|
|
57
63
|
*/
|
|
@@ -60,4 +66,42 @@ export declare const hydrate: (id: DepID, name?: string, options?: SpecOptions)
|
|
|
60
66
|
* Turn a {@link DepIDTuple} into a {@link Spec} object
|
|
61
67
|
*/
|
|
62
68
|
export declare const hydrateTuple: (tuple: DepIDTuple, name?: string, options?: SpecOptions) => Spec;
|
|
69
|
+
/**
|
|
70
|
+
* Get the {@link DepIDTuple} for a given {@link Spec} and {@link Manifest}.
|
|
71
|
+
* The Manifest is used to get the name and version, if possible. If not found
|
|
72
|
+
* in the manifest, registry ID types will use the name or bareSpec from the
|
|
73
|
+
* specifier, so at least there's something to use later.
|
|
74
|
+
*/
|
|
75
|
+
export declare const getTuple: (spec: Spec, mani: Pick<Manifest, "name" | "version">, extra?: string) => DepIDTuple;
|
|
76
|
+
/**
|
|
77
|
+
* Checks for a potentially manifest-confused package name.
|
|
78
|
+
* Returns `true` if the package name is confused, `false` otherwise.
|
|
79
|
+
*/
|
|
80
|
+
export declare const isPackageNameConfused: (spec?: Spec, name?: string) => boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Get the {@link DepID} for a given {@link Spec} and {@link Manifest}. The
|
|
83
|
+
* Manifest is used to get the name and version, if possible. If not found in
|
|
84
|
+
* the manifest, registry ID types will use the name or bareSpec from the
|
|
85
|
+
* specifier, so at least there's something to use later.
|
|
86
|
+
*/
|
|
87
|
+
export declare const getId: (spec: Spec, mani: Pick<Manifest, "name" | "version">, extra?: string) => DepID;
|
|
88
|
+
/**
|
|
89
|
+
* Join a modifier and a peer set hash into a single "extra" string.
|
|
90
|
+
*/
|
|
91
|
+
export declare function joinExtra({ modifier, peerSetHash, }: {
|
|
92
|
+
modifier?: string;
|
|
93
|
+
peerSetHash?: string;
|
|
94
|
+
}): string | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* Split an "extra" string into a modifier and a peerSetHash.
|
|
97
|
+
*/
|
|
98
|
+
export declare function splitExtra(extra: string): {
|
|
99
|
+
modifier?: string;
|
|
100
|
+
peerSetHash?: string;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Reset internal caches. This should be used when options change since
|
|
104
|
+
* they're not take into account in the memoization keys.
|
|
105
|
+
*/
|
|
106
|
+
export declare const resetCaches: () => void;
|
|
63
107
|
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,IAAI,EACL,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C,eAAO,MAAM,SAAS,EAAE,SAAe,CAAA;AACvC,MAAM,MAAM,SAAS,GAAG,GAAG,CAAA;AAG3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;A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,MAAM,KAAG,KAStC,CAAA;AAGD;;GAEG;AACH,eAAO,MAAM,OAAO,OACd,KAAK,SACF,MAAM,YACJ,WAAW,KACnB,IASF,CAAA;AAGD;;GAEG;AACH,eAAO,MAAM,YAAY,UAChB,UAAU,SACV,MAAM,YACJ,WAAW,KACnB,IAmHF,CAAA;AAuCD;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,SACb,IAAI,QACJ,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC,UAChC,MAAM,KACb,UAyEF,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,qBAAqB,UAAW,IAAI,SAAS,MAAM,YAI5C,CAAA;AAEpB;;;;;GAKG;AACH,eAAO,MAAM,KAAK,SACV,IAAI,QACJ,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAC,UAChC,MAAM,KACb,KAAoD,CAAA;AAEvD;;GAEG;AACH,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,WAAW,GACZ,EAAE;IACD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,GAAG,MAAM,GAAG,SAAS,CAKrB;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAmBA;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,YAKvB,CAAA"}
|
package/dist/esm/browser.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
import { Spec } from '@vltpkg/spec/browser';
|
|
2
|
+
import { currentDefaultRegistryName, defaultRegistryName, Spec, } from '@vltpkg/spec/browser';
|
|
3
3
|
export const delimiter = '·';
|
|
4
|
+
const EXTRA_PEER_SET_DELIMITER = 'ṗ:';
|
|
4
5
|
const depIDRegExp = new RegExp(`^((git)?${delimiter}[^${delimiter}]*${delimiter}[^${delimiter}]*(${delimiter}[^${delimiter}]*)?$` +
|
|
5
6
|
`|` +
|
|
6
7
|
`^(file|remote|workspace)${delimiter}[^${delimiter}]*)(${delimiter}[^${delimiter}]*)?$`);
|
|
@@ -21,7 +22,7 @@ export const joinDepIDTuple = (list) => {
|
|
|
21
22
|
const f = encode(first);
|
|
22
23
|
switch (type) {
|
|
23
24
|
case 'registry':
|
|
24
|
-
return `${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`;
|
|
25
|
+
return `${delimiter}${f || defaultRegistryName}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`;
|
|
25
26
|
case 'git':
|
|
26
27
|
return `${type}${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`;
|
|
27
28
|
default:
|
|
@@ -29,14 +30,25 @@ export const joinDepIDTuple = (list) => {
|
|
|
29
30
|
}
|
|
30
31
|
};
|
|
31
32
|
// allow @, but otherwise, escape everything urls do
|
|
32
|
-
const encode = (s) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
const encode = (s) => s ?
|
|
34
|
+
encodeURIComponent(s)
|
|
35
|
+
.replaceAll('%40', '@')
|
|
36
|
+
.replaceAll('%2f', '§')
|
|
37
|
+
.replaceAll('%2F', '§')
|
|
38
|
+
: s;
|
|
39
|
+
const decode = (s) => s ?
|
|
40
|
+
decodeURIComponent(s.replaceAll('@', '%40').replaceAll('§', '%2F'))
|
|
41
|
+
: s;
|
|
42
|
+
const seenSplitDepIDs = new Map();
|
|
36
43
|
/**
|
|
37
44
|
* turn a {@link DepID} into a {@link DepIDTuple}
|
|
38
45
|
*/
|
|
39
46
|
export const splitDepID = (id) => {
|
|
47
|
+
// memoized entries return early
|
|
48
|
+
const seen = seenSplitDepIDs.get(id);
|
|
49
|
+
if (seen)
|
|
50
|
+
return seen;
|
|
51
|
+
let res;
|
|
40
52
|
const [type, first = '', second, extra] = id
|
|
41
53
|
.replaceAll('§', '/')
|
|
42
54
|
.split(delimiter, 4);
|
|
@@ -47,22 +59,19 @@ export const splitDepID = (id) => {
|
|
|
47
59
|
if (second === undefined) {
|
|
48
60
|
throw error(`invalid ${type} id`, { found: id });
|
|
49
61
|
}
|
|
50
|
-
|
|
62
|
+
res = [
|
|
51
63
|
type || 'registry',
|
|
52
|
-
f,
|
|
64
|
+
f || defaultRegistryName,
|
|
53
65
|
decodeURIComponent(second),
|
|
66
|
+
decode(extra),
|
|
54
67
|
];
|
|
55
|
-
|
|
56
|
-
t.push(decodeURIComponent(extra));
|
|
57
|
-
return t;
|
|
68
|
+
break;
|
|
58
69
|
}
|
|
59
70
|
case 'file':
|
|
60
71
|
case 'remote':
|
|
61
72
|
case 'workspace': {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
t.push(decodeURIComponent(second));
|
|
65
|
-
return t;
|
|
73
|
+
res = [type, f, decode(second)];
|
|
74
|
+
break;
|
|
66
75
|
}
|
|
67
76
|
default: {
|
|
68
77
|
throw error('invalid DepID type', {
|
|
@@ -71,23 +80,57 @@ export const splitDepID = (id) => {
|
|
|
71
80
|
});
|
|
72
81
|
}
|
|
73
82
|
}
|
|
83
|
+
seenSplitDepIDs.set(id, res);
|
|
84
|
+
return res;
|
|
74
85
|
};
|
|
86
|
+
/**
|
|
87
|
+
* Retrieves the base {@link DepID} for a given depID,
|
|
88
|
+
* ignoring any extra information that may be present.
|
|
89
|
+
*/
|
|
90
|
+
export const baseDepID = (id) => {
|
|
91
|
+
const [type, first, second] = splitDepID(id);
|
|
92
|
+
switch (type) {
|
|
93
|
+
case 'git':
|
|
94
|
+
case 'registry':
|
|
95
|
+
return joinDepIDTuple([type, first, second]);
|
|
96
|
+
default:
|
|
97
|
+
return joinDepIDTuple([type, first]);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const seenHydrated = new Map();
|
|
75
101
|
/**
|
|
76
102
|
* Turn a {@link DepID} into a {@link Spec} object
|
|
77
103
|
*/
|
|
78
|
-
export const hydrate = (id, name, options = {}) =>
|
|
104
|
+
export const hydrate = (id, name, options = {}) => {
|
|
105
|
+
// memozied entries return early
|
|
106
|
+
const cacheKey = (name ?? '') + id;
|
|
107
|
+
const seen = seenHydrated.get(cacheKey);
|
|
108
|
+
if (seen)
|
|
109
|
+
return seen;
|
|
110
|
+
const res = hydrateTuple(splitDepID(id), name, options);
|
|
111
|
+
seenHydrated.set(cacheKey, res);
|
|
112
|
+
return res;
|
|
113
|
+
};
|
|
114
|
+
const seenHydratedTuples = new Map();
|
|
79
115
|
/**
|
|
80
116
|
* Turn a {@link DepIDTuple} into a {@link Spec} object
|
|
81
117
|
*/
|
|
82
118
|
export const hydrateTuple = (tuple, name, options = {}) => {
|
|
83
119
|
const [type, first, second] = tuple;
|
|
120
|
+
// memoized entries return early
|
|
121
|
+
const cacheKey = (name ?? '') + ',' + type + ',' + first + ',' + (second ?? '');
|
|
122
|
+
const seen = seenHydratedTuples.get(cacheKey);
|
|
123
|
+
if (seen)
|
|
124
|
+
return seen;
|
|
125
|
+
let res;
|
|
84
126
|
switch (type) {
|
|
85
127
|
case 'remote': {
|
|
86
128
|
if (!first)
|
|
87
129
|
throw error('no remoteURL found on remote id', {
|
|
88
130
|
found: tuple,
|
|
89
131
|
});
|
|
90
|
-
|
|
132
|
+
res = Spec.parse(name ?? '(unknown)', first, options);
|
|
133
|
+
break;
|
|
91
134
|
}
|
|
92
135
|
case 'file': {
|
|
93
136
|
if (!first) {
|
|
@@ -95,7 +138,8 @@ export const hydrateTuple = (tuple, name, options = {}) => {
|
|
|
95
138
|
found: tuple,
|
|
96
139
|
});
|
|
97
140
|
}
|
|
98
|
-
|
|
141
|
+
res = Spec.parse(name ?? '(unknown)', `file:${first}`, options);
|
|
142
|
+
break;
|
|
99
143
|
}
|
|
100
144
|
case 'registry': {
|
|
101
145
|
if (typeof first !== 'string') {
|
|
@@ -108,30 +152,44 @@ export const hydrateTuple = (tuple, name, options = {}) => {
|
|
|
108
152
|
found: tuple,
|
|
109
153
|
});
|
|
110
154
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
155
|
+
const defaultName = options.registry &&
|
|
156
|
+
currentDefaultRegistryName(options.registry, options);
|
|
157
|
+
const defaultRegistryURL = options.registry ?
|
|
158
|
+
options.registry.endsWith('/') ?
|
|
159
|
+
options.registry
|
|
160
|
+
: options.registry + '/'
|
|
161
|
+
: undefined;
|
|
162
|
+
const firstURL = first.endsWith('/') ? first : first + '/';
|
|
163
|
+
const hasScope = second.startsWith('@');
|
|
164
|
+
const hasAtVersion = second.includes('@', hasScope ? 1 : 0);
|
|
165
|
+
const name_ = (hasAtVersion && hasScope ?
|
|
166
|
+
`@${second.split('@')[1]}`
|
|
167
|
+
: second.split('@')[0]) /* c8 ignore next */ || '(unknown)';
|
|
168
|
+
const usesDefaultRegistry = !first ||
|
|
169
|
+
first === defaultName ||
|
|
170
|
+
firstURL === defaultRegistryURL;
|
|
171
|
+
const noAliasedNameUsed = !name || name === name_;
|
|
172
|
+
if (usesDefaultRegistry && noAliasedNameUsed) {
|
|
173
|
+
const version = (hasAtVersion &&
|
|
174
|
+
second.split('@')[hasScope ? 2 : 1]) /* c8 ignore next */ ||
|
|
175
|
+
second;
|
|
176
|
+
res = Spec.parse(name || name_, version, options);
|
|
177
|
+
break;
|
|
120
178
|
}
|
|
121
179
|
if (!/^https?:\/\//.test(first)) {
|
|
122
180
|
const reg = options.registries?.[first];
|
|
123
|
-
|
|
181
|
+
const jsrReg = options['jsr-registries']?.[first];
|
|
182
|
+
if (first !== defaultRegistryName && !reg && !jsrReg) {
|
|
124
183
|
throw error('named registry not found in options', {
|
|
125
184
|
name: first,
|
|
126
185
|
found: tuple,
|
|
127
186
|
});
|
|
128
187
|
}
|
|
129
|
-
|
|
188
|
+
res = Spec.parse(name || name_, `${first}:${second}`, options);
|
|
189
|
+
break;
|
|
130
190
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
Spec.parse(s.final.name + '@' + s.bareSpec)
|
|
134
|
-
: s;
|
|
191
|
+
res = Spec.parse(name || name_, `registry:${first}#${second}`, options);
|
|
192
|
+
break;
|
|
135
193
|
}
|
|
136
194
|
case 'git': {
|
|
137
195
|
if (!first) {
|
|
@@ -139,16 +197,180 @@ export const hydrateTuple = (tuple, name, options = {}) => {
|
|
|
139
197
|
found: tuple,
|
|
140
198
|
});
|
|
141
199
|
}
|
|
142
|
-
|
|
200
|
+
res = Spec.parse(name ?? '(unknown)', first + '#' + second, options);
|
|
201
|
+
break;
|
|
143
202
|
}
|
|
144
203
|
case 'workspace': {
|
|
145
204
|
if (!first) {
|
|
146
205
|
throw error('no name/path on workspace id', { found: tuple });
|
|
147
206
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
207
|
+
res =
|
|
208
|
+
name && name !== first ?
|
|
209
|
+
Spec.parse(name, `workspace:${first}@*`, options)
|
|
210
|
+
: Spec.parse(first, `workspace:*`, options);
|
|
211
|
+
break;
|
|
151
212
|
}
|
|
152
213
|
}
|
|
214
|
+
seenHydratedTuples.set(cacheKey, res);
|
|
215
|
+
return res;
|
|
216
|
+
};
|
|
217
|
+
const matchRegistryURL = (registry, registries) => {
|
|
218
|
+
// iterate on known registries to check if any known value
|
|
219
|
+
// matches the current default registry of this Spec value
|
|
220
|
+
for (const [alias, url] of Object.entries(registries)) {
|
|
221
|
+
// normalize trailing slash for comparison
|
|
222
|
+
const specRegURL = registry.endsWith('/') ? registry : registry + '/';
|
|
223
|
+
const knownRegURL = url.endsWith('/') ? url : url + '/';
|
|
224
|
+
if (specRegURL === knownRegURL) {
|
|
225
|
+
return alias;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
/**
|
|
230
|
+
* Convert a Spec's registry URL to a known short registry name, if possible.
|
|
231
|
+
*/
|
|
232
|
+
const convertToKnownShortRegistryName = (s, registry) => {
|
|
233
|
+
if (!s.registry)
|
|
234
|
+
return;
|
|
235
|
+
const reg = registry ?? s.registry;
|
|
236
|
+
const namedRegistry = matchRegistryURL(reg, s.options.registries);
|
|
237
|
+
if (namedRegistry)
|
|
238
|
+
return namedRegistry;
|
|
239
|
+
const namedJSRRegistry = matchRegistryURL(reg, s.options['jsr-registries']);
|
|
240
|
+
if (namedJSRRegistry)
|
|
241
|
+
return namedJSRRegistry;
|
|
242
|
+
};
|
|
243
|
+
const seenTuples = new Map();
|
|
244
|
+
/**
|
|
245
|
+
* Get the {@link DepIDTuple} for a given {@link Spec} and {@link Manifest}.
|
|
246
|
+
* The Manifest is used to get the name and version, if possible. If not found
|
|
247
|
+
* in the manifest, registry ID types will use the name or bareSpec from the
|
|
248
|
+
* specifier, so at least there's something to use later.
|
|
249
|
+
*/
|
|
250
|
+
export const getTuple = (spec, mani, extra) => {
|
|
251
|
+
// memoized entries return early
|
|
252
|
+
const cacheKey = String(spec) +
|
|
253
|
+
(spec.registry ?? '') +
|
|
254
|
+
(mani.name ?? '') +
|
|
255
|
+
(mani.version ?? '') +
|
|
256
|
+
(extra ?? '');
|
|
257
|
+
const seen = seenTuples.get(cacheKey);
|
|
258
|
+
if (seen)
|
|
259
|
+
return seen;
|
|
260
|
+
let res;
|
|
261
|
+
const f = spec.final;
|
|
262
|
+
switch (f.type) {
|
|
263
|
+
case 'registry': {
|
|
264
|
+
const version = mani.version ?
|
|
265
|
+
mani.version.startsWith('v') ?
|
|
266
|
+
mani.version.slice(1)
|
|
267
|
+
: mani.version
|
|
268
|
+
: f.bareSpec;
|
|
269
|
+
res = [
|
|
270
|
+
f.type,
|
|
271
|
+
f.namedRegistry ||
|
|
272
|
+
convertToKnownShortRegistryName(f, f.scopeRegistry) ||
|
|
273
|
+
f.scopeRegistry ||
|
|
274
|
+
f.registry ||
|
|
275
|
+
defaultRegistryName,
|
|
276
|
+
`${isPackageNameConfused(spec, mani.name) ? spec.name : (mani.name ?? f.name)}@${version}`,
|
|
277
|
+
extra,
|
|
278
|
+
];
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
case 'git': {
|
|
282
|
+
const { namedGitHost, namedGitHostPath, gitRemote, gitSelector = '', } = f;
|
|
283
|
+
if (!gitRemote)
|
|
284
|
+
throw error('no host on git specifier', { spec });
|
|
285
|
+
if (namedGitHost) {
|
|
286
|
+
if (!namedGitHostPath) {
|
|
287
|
+
throw error('named git host without path portion', {
|
|
288
|
+
spec,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
res = [
|
|
292
|
+
f.type,
|
|
293
|
+
`${namedGitHost}:${namedGitHostPath}`,
|
|
294
|
+
gitSelector,
|
|
295
|
+
extra,
|
|
296
|
+
];
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
else {
|
|
300
|
+
res = [f.type, gitRemote, gitSelector, extra];
|
|
301
|
+
}
|
|
302
|
+
break;
|
|
303
|
+
}
|
|
304
|
+
case 'remote': {
|
|
305
|
+
const { remoteURL } = f;
|
|
306
|
+
if (!remoteURL)
|
|
307
|
+
throw error('no URL on remote specifier', { spec });
|
|
308
|
+
res = [f.type, remoteURL, extra];
|
|
309
|
+
break;
|
|
310
|
+
}
|
|
311
|
+
case 'file':
|
|
312
|
+
case 'workspace':
|
|
313
|
+
throw error('Path-based dep ids are not supported', { spec });
|
|
314
|
+
}
|
|
315
|
+
seenTuples.set(cacheKey, res);
|
|
316
|
+
return res;
|
|
317
|
+
};
|
|
318
|
+
/**
|
|
319
|
+
* Checks for a potentially manifest-confused package name.
|
|
320
|
+
* Returns `true` if the package name is confused, `false` otherwise.
|
|
321
|
+
*/
|
|
322
|
+
export const isPackageNameConfused = (spec, name) => !!spec?.name && // a nameless spec can't be checked
|
|
323
|
+
!spec.subspec && // it's not an aliased package or using a custom protocol
|
|
324
|
+
spec.type === 'registry' && // the defined spec is of type registry
|
|
325
|
+
spec.name !== name; // its name is not the same as the defined spec name
|
|
326
|
+
/**
|
|
327
|
+
* Get the {@link DepID} for a given {@link Spec} and {@link Manifest}. The
|
|
328
|
+
* Manifest is used to get the name and version, if possible. If not found in
|
|
329
|
+
* the manifest, registry ID types will use the name or bareSpec from the
|
|
330
|
+
* specifier, so at least there's something to use later.
|
|
331
|
+
*/
|
|
332
|
+
export const getId = (spec, mani, extra) => joinDepIDTuple(getTuple(spec, mani, extra));
|
|
333
|
+
/**
|
|
334
|
+
* Join a modifier and a peer set hash into a single "extra" string.
|
|
335
|
+
*/
|
|
336
|
+
export function joinExtra({ modifier, peerSetHash, }) {
|
|
337
|
+
if (!modifier && !peerSetHash)
|
|
338
|
+
return;
|
|
339
|
+
if (modifier && peerSetHash)
|
|
340
|
+
return `${modifier}${peerSetHash}`;
|
|
341
|
+
if (modifier)
|
|
342
|
+
return modifier;
|
|
343
|
+
return peerSetHash;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Split an "extra" string into a modifier and a peerSetHash.
|
|
347
|
+
*/
|
|
348
|
+
export function splitExtra(extra) {
|
|
349
|
+
if (!extra)
|
|
350
|
+
return {};
|
|
351
|
+
// only peerSetHash is present, return it
|
|
352
|
+
if (extra.startsWith(EXTRA_PEER_SET_DELIMITER)) {
|
|
353
|
+
return { peerSetHash: extra };
|
|
354
|
+
}
|
|
355
|
+
// only modifier is present, return its value
|
|
356
|
+
const idx = extra.indexOf(EXTRA_PEER_SET_DELIMITER);
|
|
357
|
+
if (idx === -1) {
|
|
358
|
+
return { modifier: extra };
|
|
359
|
+
}
|
|
360
|
+
// Both modifier and peerSetHash are present
|
|
361
|
+
return {
|
|
362
|
+
modifier: extra.slice(0, idx),
|
|
363
|
+
peerSetHash: extra.slice(idx),
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Reset internal caches. This should be used when options change since
|
|
368
|
+
* they're not take into account in the memoization keys.
|
|
369
|
+
*/
|
|
370
|
+
export const resetCaches = () => {
|
|
371
|
+
seenHydrated.clear();
|
|
372
|
+
seenHydratedTuples.clear();
|
|
373
|
+
seenSplitDepIDs.clear();
|
|
374
|
+
seenTuples.clear();
|
|
153
375
|
};
|
|
154
376
|
//# sourceMappingURL=browser.js.map
|
package/dist/esm/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAG3C,MAAM,CAAC,MAAM,SAAS,GAAc,GAAG,CAAA;AAsDvC,MAAM,WAAW,GAAG,IAAI,MAAM,CAC5B,WAAW,SAAS,KAAK,SAAS,KAAK,SAAS,KAAK,SAAS,MAC5D,SACF,KAAK,SAAS,OAAO;IACnB,GAAG;IACH,2BAA2B,SAAS,KAClC,SACF,OAAO,SAAS,KAAK,SAAS,OAAO,CACxC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAY,EAAgB,EAAE,CACpD,OAAO,GAAG,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAElD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAS,EAAE;IAC5C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,KAAK,CAAC,iBAAiB,EAAE;YAC7B,KAAK,EAAE,GAAG;SACX,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAgB,EAAS,EAAE;IACxD,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAA;IACzC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;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AAE,CAAC,CAAA;YAC/D,CAAC;YACD,OAAO,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC;gBAC3B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,EAAE,OAAO,CAAC;gBACnD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,CAAA;QAC/C,CAAC;IACH,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { Spec } from '@vltpkg/spec/browser'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\n\nexport const delimiter: Delimiter = '·'\nexport type Delimiter = '·'\n\n/**\n * Dependency IDs are a URI-encoded set of strings, separated\n * by the {@link Delimiter} character (`'·'`).\n *\n * The first entry is always the specifier type. The rest depend on the\n * type. `git`, `registry`, and `workspace` entries have 3 fields, the rest\n * have 2.\n *\n * - `registry`: `'registry·<registry>·name@specifier'`\n * The `<registry>` portion can be a known named registry name, or a\n * url to a registry. If empty, it is the default registry. Examples:\n * - `··some-package@2.0.1`\n * - `·npm·whatever@1.2.3`\n * - `·http%3A%2F%2Fvlt.sh%2F·x@1.2.3`\n * - `git`: `'git·<git remote>·<git selector>'`. For example:\n * - `git·github:user/project·branchname`\n * - `git·git%2Bssh%3A%2F%2Fuser%40host%3Aproject.git·semver:1.x`\n * - `workspace`: `'workspace·<path>'`. For example:\n * - `workspace·src/mything`\n * - `remote`: `'remote·<url>'`\n * - `file`: `'file·<path>'`\n *\n * Lastly, the final portion can contain arbitrary string data, and is\n * used to store peer dep resolutions to maintain the peerDep contract.\n */\nexport type DepID =\n | `${'' | 'git'}${Delimiter}${string}${Delimiter}${string}${Delimiter}${string}`\n | `${'' | 'git'}${Delimiter}${string}${Delimiter}${string}`\n | `${'file' | 'remote' | 'workspace'}${Delimiter}${string}${Delimiter}${string}`\n | `${'file' | 'remote' | 'workspace'}${Delimiter}${string}`\n\n/**\n * A {@link DepID}, split apart and URI-decoded\n */\nexport type DepIDTuple =\n | [\n type: 'git',\n gitRemote: string,\n gitSelector: string,\n extra?: string,\n ]\n | [\n type: 'registry',\n registry: string,\n registrySpec: string,\n extra?: string,\n ]\n | [type: 'file', path: string, extra?: string]\n | [type: 'remote', url: string, extra?: string]\n | [type: 'workspace', workspace: string, extra?: string]\n\nconst depIDRegExp = new RegExp(\n `^((git)?${delimiter}[^${delimiter}]*${delimiter}[^${delimiter}]*(${\n delimiter\n }[^${delimiter}]*)?$` +\n `|` +\n `^(file|remote|workspace)${delimiter}[^${\n delimiter\n }]*)(${delimiter}[^${delimiter}]*)?$`,\n)\n\nexport const isDepID = (str: unknown): str is DepID =>\n typeof str === 'string' && depIDRegExp.test(str)\n\nexport const asDepID = (str: string): DepID => {\n if (!isDepID(str)) {\n throw error('Expected dep id', {\n found: str,\n })\n }\n return str\n}\n\n/**\n * turn a {@link DepIDTuple} into a {@link DepID}\n */\nexport const joinDepIDTuple = (list: DepIDTuple): DepID => {\n const [type, first, second, extra] = list\n const f = encode(first)\n switch (type) {\n case 'registry':\n return `${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`\n case 'git':\n return `${type}${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`\n default:\n return `${type}${delimiter}${f}${second ? `${delimiter}${encode(second)}` : ''}`\n }\n}\n\n// allow @, but otherwise, escape everything urls do\nconst encode = (s: string): string =>\n encodeURIComponent(s)\n .replaceAll('%40', '@')\n .replaceAll('%2f', '§')\n .replaceAll('%2F', '§')\n\n/**\n * turn a {@link DepID} into a {@link DepIDTuple}\n */\nexport const splitDepID = (id: string): DepIDTuple => {\n const [type, first = '', second, extra] = id\n .replaceAll('§', '/')\n .split(delimiter, 4)\n const f = decodeURIComponent(first)\n switch (type) {\n case 'git':\n case '': {\n if (second === undefined) {\n throw error(`invalid ${type} id`, { found: id })\n }\n const t: DepIDTuple = [\n type || 'registry',\n f,\n decodeURIComponent(second),\n ]\n if (extra) t.push(decodeURIComponent(extra))\n return t\n }\n case 'file':\n case 'remote':\n case 'workspace': {\n const t: DepIDTuple = [type, f]\n if (second) t.push(decodeURIComponent(second))\n return t\n }\n default: {\n throw error('invalid DepID type', {\n found: type,\n validOptions: ['git', 'file', 'workspace', 'remote', ''],\n })\n }\n }\n}\n\n/**\n * Turn a {@link DepID} into a {@link Spec} object\n */\nexport const hydrate = (\n id: DepID,\n name?: string,\n options: SpecOptions = {},\n): Spec => hydrateTuple(splitDepID(id), name, options)\n\n/**\n * Turn a {@link DepIDTuple} into a {@link Spec} object\n */\nexport const hydrateTuple = (\n tuple: DepIDTuple,\n name?: string,\n options: SpecOptions = {},\n) => {\n const [type, first, second] = tuple\n switch (type) {\n case 'remote': {\n if (!first)\n throw error('no remoteURL found on remote id', {\n found: tuple,\n })\n return Spec.parse(name ?? '(unknown)', first)\n }\n case 'file': {\n if (!first) {\n throw error('no file path found on remote id', {\n found: tuple,\n })\n }\n return Spec.parse(name ?? '(unknown)', `file:${first}`, options)\n }\n case 'registry': {\n if (typeof first !== 'string') {\n throw error('no registry url or name in registry ID', {\n found: tuple,\n })\n }\n if (!second) {\n throw error('no name/specifier in registry ID', {\n found: tuple,\n })\n }\n if (!first) {\n // just a normal name@version on the default registry\n const s = Spec.parse(second)\n if (name && s.name !== name) {\n return Spec.parse(`${name}@npm:${second}`)\n } else {\n return s\n }\n }\n if (!/^https?:\\/\\//.test(first)) {\n const reg = options.registries?.[first]\n if (first !== 'npm' && !reg) {\n throw error('named registry not found in options', {\n name: first,\n found: tuple,\n })\n }\n return Spec.parse(\n name ?? '(unknown)',\n `${first}:${second}`,\n options,\n )\n }\n const s = Spec.parse(\n name ?? '(unknown)',\n `registry:${first}#${second}`,\n options,\n )\n return name && s.final.name !== name ?\n Spec.parse(s.final.name + '@' + s.bareSpec)\n : s\n }\n case 'git': {\n if (!first) {\n throw error('no git remote in git ID', {\n found: tuple,\n })\n }\n return Spec.parse(\n name ?? '(unknown)',\n first + '#' + second,\n options,\n )\n }\n case 'workspace': {\n if (!first) {\n throw error('no name/path on workspace id', { found: tuple })\n }\n return name && name !== first ?\n Spec.parse(name, `workspace:${first}@*`, options)\n : Spec.parse(first, `workspace:*`, options)\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,IAAI,GACL,MAAM,sBAAsB,CAAA;AAI7B,MAAM,CAAC,MAAM,SAAS,GAAc,GAAG,CAAA;AAEvC,MAAM,wBAAwB,GAAG,IAAI,CAAA;AAqDrC,MAAM,WAAW,GAAG,IAAI,MAAM,CAC5B,WAAW,SAAS,KAAK,SAAS,KAAK,SAAS,KAAK,SAAS,MAC5D,SACF,KAAK,SAAS,OAAO;IACnB,GAAG;IACH,2BAA2B,SAAS,KAClC,SACF,OAAO,SAAS,KAAK,SAAS,OAAO,CACxC,CAAA;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAY,EAAgB,EAAE,CACpD,OAAO,GAAG,KAAK,QAAQ,IAAI,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAElD,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAW,EAAS,EAAE;IAC5C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAClB,MAAM,KAAK,CAAC,iBAAiB,EAAE;YAC7B,KAAK,EAAE,GAAG;SACX,CAAC,CAAA;IACJ,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAgB,EAAS,EAAE;IACxD,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,GAAG,IAAI,CAAA;IACzC,MAAM,CAAC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AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IAItC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,CAAA;IAErB,yCAAyC;IACzC,IAAI,KAAK,CAAC,UAAU,CAAC,wBAAwB,CAAC,EAAE,CAAC;QAC/C,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAA;IAC/B,CAAC;IAED,6CAA6C;IAC7C,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAA;IACnD,IAAI,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC;QACf,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAA;IAC5B,CAAC;IAED,4CAA4C;IAC5C,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC;QAC7B,WAAW,EAAE,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;KAC9B,CAAA;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,YAAY,CAAC,KAAK,EAAE,CAAA;IACpB,kBAAkB,CAAC,KAAK,EAAE,CAAA;IAC1B,eAAe,CAAC,KAAK,EAAE,CAAA;IACvB,UAAU,CAAC,KAAK,EAAE,CAAA;AACpB,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport {\n currentDefaultRegistryName,\n defaultRegistryName,\n Spec,\n} from '@vltpkg/spec/browser'\nimport type { SpecOptions } from '@vltpkg/spec/browser'\nimport type { Manifest } from '@vltpkg/types'\n\nexport const delimiter: Delimiter = '·'\nexport type Delimiter = '·'\nconst EXTRA_PEER_SET_DELIMITER = 'ṗ:'\n\n/**\n * Dependency IDs are a URI-encoded set of strings, separated\n * by the {@link Delimiter} character (`'·'`).\n *\n * The first entry is always the specifier type. The rest depend on the\n * type. `git`, `registry`, and `workspace` entries have 3 fields, the rest\n * have 2.\n *\n * - `registry`: `'registry·<registry>·name@specifier'`\n * The `<registry>` portion can be a known named registry name, or a\n * url to a registry. If empty, it is the default registry. Examples:\n * - `··some-package@2.0.1`\n * - `·npm·whatever@1.2.3`\n * - `·http%3A%2F%2Fvlt.sh%2F·x@1.2.3`\n * - `git`: `'git·<git remote>·<git selector>'`. For example:\n * - `git·github:user/project·branchname`\n * - `git·git%2Bssh%3A%2F%2Fuser%40host%3Aproject.git·semver:1.x`\n * - `workspace`: `'workspace·<path>'`. For example:\n * - `workspace·src/mything`\n * - `remote`: `'remote·<url>'`\n * - `file`: `'file·<path>'`\n *\n * Lastly, the final portion can contain arbitrary string data, and is\n * used to store peer dep resolutions to maintain the peerDep contract.\n */\nexport type DepID =\n | `${'' | 'git'}${Delimiter}${string}${Delimiter}${string}${Delimiter}${string}`\n | `${'' | 'git'}${Delimiter}${string}${Delimiter}${string}`\n | `${'file' | 'remote' | 'workspace'}${Delimiter}${string}${Delimiter}${string}`\n | `${'file' | 'remote' | 'workspace'}${Delimiter}${string}`\n\n/**\n * A {@link DepID}, split apart and URI-decoded\n */\nexport type DepIDTuple =\n | [\n type: 'git',\n gitRemote: string,\n gitSelector: string,\n extra?: string,\n ]\n | [\n type: 'registry',\n registry: string,\n registrySpec: string,\n extra?: string,\n ]\n | [type: 'file', path: string, extra?: string]\n | [type: 'remote', url: string, extra?: string]\n | [type: 'workspace', workspace: string, extra?: string]\n\nconst depIDRegExp = new RegExp(\n `^((git)?${delimiter}[^${delimiter}]*${delimiter}[^${delimiter}]*(${\n delimiter\n }[^${delimiter}]*)?$` +\n `|` +\n `^(file|remote|workspace)${delimiter}[^${\n delimiter\n }]*)(${delimiter}[^${delimiter}]*)?$`,\n)\n\nexport const isDepID = (str: unknown): str is DepID =>\n typeof str === 'string' && depIDRegExp.test(str)\n\nexport const asDepID = (str: string): DepID => {\n if (!isDepID(str)) {\n throw error('Expected dep id', {\n found: str,\n })\n }\n return str\n}\n\n/**\n * turn a {@link DepIDTuple} into a {@link DepID}\n */\nexport const joinDepIDTuple = (list: DepIDTuple): DepID => {\n const [type, first, second, extra] = list\n const f = encode(first)\n switch (type) {\n case 'registry':\n return `${delimiter}${f || defaultRegistryName}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`\n case 'git':\n return `${type}${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`\n default:\n return `${type}${delimiter}${f}${second ? `${delimiter}${encode(second)}` : ''}`\n }\n}\n\n// allow @, but otherwise, escape everything urls do\nconst encode = (s?: string) =>\n s ?\n encodeURIComponent(s)\n .replaceAll('%40', '@')\n .replaceAll('%2f', '§')\n .replaceAll('%2F', '§')\n : s\n\nconst decode = (s?: string) =>\n s ?\n decodeURIComponent(\n s.replaceAll('@', '%40').replaceAll('§', '%2F'),\n )\n : s\n\nconst seenSplitDepIDs = new Map<string, DepIDTuple>()\n/**\n * turn a {@link DepID} into a {@link DepIDTuple}\n */\nexport const splitDepID = (id: string): DepIDTuple => {\n // memoized entries return early\n const seen = seenSplitDepIDs.get(id)\n if (seen) return seen\n\n let res: DepIDTuple\n const [type, first = '', second, extra] = id\n .replaceAll('§', '/')\n .split(delimiter, 4)\n const f = decodeURIComponent(first)\n switch (type) {\n case 'git':\n case '': {\n if (second === undefined) {\n throw error(`invalid ${type} id`, { found: id })\n }\n res = [\n type || 'registry',\n f || defaultRegistryName,\n decodeURIComponent(second),\n decode(extra),\n ]\n break\n }\n case 'file':\n case 'remote':\n case 'workspace': {\n res = [type, f, decode(second)]\n break\n }\n default: {\n throw error('invalid DepID type', {\n found: type,\n validOptions: ['git', 'file', 'workspace', 'remote', ''],\n })\n }\n }\n seenSplitDepIDs.set(id, res)\n return res\n}\n\n/**\n * Retrieves the base {@link DepID} for a given depID,\n * ignoring any extra information that may be present.\n */\nexport const baseDepID = (id: string): DepID => {\n const [type, first, second] = splitDepID(id)\n switch (type) {\n case 'git':\n case 'registry':\n return joinDepIDTuple([type, first, second])\n default:\n return joinDepIDTuple([type, first])\n }\n}\n\nconst seenHydrated = new Map<string, Spec>()\n/**\n * Turn a {@link DepID} into a {@link Spec} object\n */\nexport const hydrate = (\n id: DepID,\n name?: string,\n options: SpecOptions = {},\n): Spec => {\n // memozied entries return early\n const cacheKey = (name ?? '') + id\n const seen = seenHydrated.get(cacheKey)\n if (seen) return seen\n\n const res = hydrateTuple(splitDepID(id), name, options)\n seenHydrated.set(cacheKey, res)\n return res\n}\n\nconst seenHydratedTuples = new Map<string, Spec>()\n/**\n * Turn a {@link DepIDTuple} into a {@link Spec} object\n */\nexport const hydrateTuple = (\n tuple: DepIDTuple,\n name?: string,\n options: SpecOptions = {},\n): Spec => {\n const [type, first, second] = tuple\n\n // memoized entries return early\n const cacheKey =\n (name ?? '') + ',' + type + ',' + first + ',' + (second ?? '')\n const seen = seenHydratedTuples.get(cacheKey)\n if (seen) return seen\n\n let res: Spec\n switch (type) {\n case 'remote': {\n if (!first)\n throw error('no remoteURL found on remote id', {\n found: tuple,\n })\n res = Spec.parse(name ?? '(unknown)', first, options)\n break\n }\n case 'file': {\n if (!first) {\n throw error('no file path found on remote id', {\n found: tuple,\n })\n }\n res = Spec.parse(name ?? '(unknown)', `file:${first}`, options)\n break\n }\n case 'registry': {\n if (typeof first !== 'string') {\n throw error('no registry url or name in registry ID', {\n found: tuple,\n })\n }\n if (!second) {\n throw error('no name/specifier in registry ID', {\n found: tuple,\n })\n }\n const defaultName =\n options.registry &&\n currentDefaultRegistryName(options.registry, options)\n const defaultRegistryURL =\n options.registry ?\n options.registry.endsWith('/') ?\n options.registry\n : options.registry + '/'\n : undefined\n const firstURL = first.endsWith('/') ? first : first + '/'\n const hasScope = second.startsWith('@')\n const hasAtVersion = second.includes('@', hasScope ? 1 : 0)\n const name_ =\n (hasAtVersion && hasScope ?\n `@${second.split('@')[1]}`\n : second.split('@')[0]) /* c8 ignore next */ || '(unknown)'\n const usesDefaultRegistry =\n !first ||\n first === defaultName ||\n firstURL === defaultRegistryURL\n const noAliasedNameUsed = !name || name === name_\n if (usesDefaultRegistry && noAliasedNameUsed) {\n const version =\n (hasAtVersion &&\n second.split('@')[\n hasScope ? 2 : 1\n ]) /* c8 ignore next */ ||\n second\n res = Spec.parse(name || name_, version, options)\n break\n }\n if (!/^https?:\\/\\//.test(first)) {\n const reg = options.registries?.[first]\n const jsrReg = options['jsr-registries']?.[first]\n if (first !== defaultRegistryName && !reg && !jsrReg) {\n throw error('named registry not found in options', {\n name: first,\n found: tuple,\n })\n }\n res = Spec.parse(name || name_, `${first}:${second}`, options)\n break\n }\n res = Spec.parse(\n name || name_,\n `registry:${first}#${second}`,\n options,\n )\n break\n }\n case 'git': {\n if (!first) {\n throw error('no git remote in git ID', {\n found: tuple,\n })\n }\n res = Spec.parse(\n name ?? '(unknown)',\n first + '#' + second,\n options,\n )\n break\n }\n case 'workspace': {\n if (!first) {\n throw error('no name/path on workspace id', { found: tuple })\n }\n res =\n name && name !== first ?\n Spec.parse(name, `workspace:${first}@*`, options)\n : Spec.parse(first, `workspace:*`, options)\n break\n }\n }\n seenHydratedTuples.set(cacheKey, res)\n return res\n}\n\nconst matchRegistryURL = (\n registry: string,\n registries: Record<string, string>,\n): string | undefined => {\n // iterate on known registries to check if any known value\n // matches the current default registry of this Spec value\n for (const [alias, url] of Object.entries(registries)) {\n // normalize trailing slash for comparison\n const specRegURL =\n registry.endsWith('/') ? registry : registry + '/'\n const knownRegURL = url.endsWith('/') ? url : url + '/'\n if (specRegURL === knownRegURL) {\n return alias\n }\n }\n}\n\n/**\n * Convert a Spec's registry URL to a known short registry name, if possible.\n */\nconst convertToKnownShortRegistryName = (\n s: Spec,\n registry?: string,\n): string | undefined => {\n if (!s.registry) return\n const reg = registry ?? s.registry\n const namedRegistry = matchRegistryURL(reg, s.options.registries)\n if (namedRegistry) return namedRegistry\n\n const namedJSRRegistry = matchRegistryURL(\n reg,\n s.options['jsr-registries'],\n )\n if (namedJSRRegistry) return namedJSRRegistry\n}\n\nconst seenTuples = new Map<string, DepIDTuple>()\n/**\n * Get the {@link DepIDTuple} for a given {@link Spec} and {@link Manifest}.\n * The Manifest is used to get the name and version, if possible. If not found\n * in the manifest, registry ID types will use the name or bareSpec from the\n * specifier, so at least there's something to use later.\n */\nexport const getTuple = (\n spec: Spec,\n mani: Pick<Manifest, 'name' | 'version'>,\n extra?: string,\n): DepIDTuple => {\n // memoized entries return early\n const cacheKey =\n String(spec) +\n (spec.registry ?? '') +\n (mani.name ?? '') +\n (mani.version ?? '') +\n (extra ?? '')\n const seen = seenTuples.get(cacheKey)\n if (seen) return seen\n\n let res: DepIDTuple\n const f = spec.final\n switch (f.type) {\n case 'registry': {\n const version =\n mani.version ?\n mani.version.startsWith('v') ?\n mani.version.slice(1)\n : mani.version\n : f.bareSpec\n res = [\n f.type,\n f.namedRegistry ||\n convertToKnownShortRegistryName(f, f.scopeRegistry) ||\n f.scopeRegistry ||\n f.registry ||\n defaultRegistryName,\n `${isPackageNameConfused(spec, mani.name) ? spec.name : (mani.name ?? f.name)}@${version}`,\n extra,\n ]\n break\n }\n case 'git': {\n const {\n namedGitHost,\n namedGitHostPath,\n gitRemote,\n gitSelector = '',\n } = f\n if (!gitRemote)\n throw error('no host on git specifier', { spec })\n if (namedGitHost) {\n if (!namedGitHostPath) {\n throw error('named git host without path portion', {\n spec,\n })\n }\n res = [\n f.type,\n `${namedGitHost}:${namedGitHostPath}`,\n gitSelector,\n extra,\n ]\n break\n } else {\n res = [f.type, gitRemote, gitSelector, extra]\n }\n break\n }\n case 'remote': {\n const { remoteURL } = f\n if (!remoteURL)\n throw error('no URL on remote specifier', { spec })\n res = [f.type, remoteURL, extra]\n break\n }\n case 'file':\n case 'workspace':\n throw error('Path-based dep ids are not supported', { spec })\n }\n seenTuples.set(cacheKey, res)\n return res\n}\n\n/**\n * Checks for a potentially manifest-confused package name.\n * Returns `true` if the package name is confused, `false` otherwise.\n */\nexport const isPackageNameConfused = (spec?: Spec, name?: string) =>\n !!spec?.name && // a nameless spec can't be checked\n !spec.subspec && // it's not an aliased package or using a custom protocol\n spec.type === 'registry' && // the defined spec is of type registry\n spec.name !== name // its name is not the same as the defined spec name\n\n/**\n * Get the {@link DepID} for a given {@link Spec} and {@link Manifest}. The\n * Manifest is used to get the name and version, if possible. If not found in\n * the manifest, registry ID types will use the name or bareSpec from the\n * specifier, so at least there's something to use later.\n */\nexport const getId = (\n spec: Spec,\n mani: Pick<Manifest, 'name' | 'version'>,\n extra?: string,\n): DepID => joinDepIDTuple(getTuple(spec, mani, extra))\n\n/**\n * Join a modifier and a peer set hash into a single \"extra\" string.\n */\nexport function joinExtra({\n modifier,\n peerSetHash,\n}: {\n modifier?: string\n peerSetHash?: string\n}): string | undefined {\n if (!modifier && !peerSetHash) return\n if (modifier && peerSetHash) return `${modifier}${peerSetHash}`\n if (modifier) return modifier\n return peerSetHash\n}\n\n/**\n * Split an \"extra\" string into a modifier and a peerSetHash.\n */\nexport function splitExtra(extra: string): {\n modifier?: string\n peerSetHash?: string\n} {\n if (!extra) return {}\n\n // only peerSetHash is present, return it\n if (extra.startsWith(EXTRA_PEER_SET_DELIMITER)) {\n return { peerSetHash: extra }\n }\n\n // only modifier is present, return its value\n const idx = extra.indexOf(EXTRA_PEER_SET_DELIMITER)\n if (idx === -1) {\n return { modifier: extra }\n }\n\n // Both modifier and peerSetHash are present\n return {\n modifier: extra.slice(0, idx),\n peerSetHash: extra.slice(idx),\n }\n}\n\n/**\n * Reset internal caches. This should be used when options change since\n * they're not take into account in the memoization keys.\n */\nexport const resetCaches = () => {\n seenHydrated.clear()\n seenHydratedTuples.clear()\n seenSplitDepIDs.clear()\n seenTuples.clear()\n}\n"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,78 +1,20 @@
|
|
|
1
1
|
import { Spec } from '@vltpkg/spec';
|
|
2
2
|
import type { SpecOptions } from '@vltpkg/spec';
|
|
3
|
-
import type {
|
|
4
|
-
export
|
|
5
|
-
export type Delimiter = '·';
|
|
3
|
+
import type { DepID, DepIDTuple } from './browser.ts';
|
|
4
|
+
export * from './browser.ts';
|
|
6
5
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* The first entry is always the specifier type. The rest depend on the
|
|
11
|
-
* type. `git`, `registry`, and `workspace` entries have 3 fields, the rest
|
|
12
|
-
* have 2.
|
|
13
|
-
*
|
|
14
|
-
* - `registry`: `'registry·<registry>·name@specifier'`
|
|
15
|
-
* The `<registry>` portion can be a known named registry name, or a
|
|
16
|
-
* url to a registry. If empty, it is the default registry. Examples:
|
|
17
|
-
* - `··some-package@2.0.1`
|
|
18
|
-
* - `·npm·whatever@1.2.3`
|
|
19
|
-
* - `·http%3A%2F%2Fvlt.sh%2F·x@1.2.3`
|
|
20
|
-
* - `git`: `'git·<git remote>·<git selector>'`. For example:
|
|
21
|
-
* - `git·github:user/project·branchname`
|
|
22
|
-
* - `git·git%2Bssh%3A%2F%2Fuser%40host%3Aproject.git·semver:1.x`
|
|
23
|
-
* - `workspace`: `'workspace·<path>'`. For example:
|
|
24
|
-
* - `workspace·src/mything`
|
|
25
|
-
* - `remote`: `'remote·<url>'`
|
|
26
|
-
* - `file`: `'file·<path>'`
|
|
27
|
-
*
|
|
28
|
-
* Lastly, the final portion can contain arbitrary string data, and is
|
|
29
|
-
* used to store peer dep resolutions to maintain the peerDep contract.
|
|
30
|
-
*/
|
|
31
|
-
export type DepID = `${'' | 'git'}${Delimiter}${string}${Delimiter}${string}${Delimiter}${string}` | `${'' | 'git'}${Delimiter}${string}${Delimiter}${string}` | `${'file' | 'remote' | 'workspace'}${Delimiter}${string}${Delimiter}${string}` | `${'file' | 'remote' | 'workspace'}${Delimiter}${string}`;
|
|
32
|
-
/**
|
|
33
|
-
* A {@link DepID}, split apart and URI-decoded
|
|
34
|
-
*/
|
|
35
|
-
export type DepIDTuple = [
|
|
36
|
-
type: 'git',
|
|
37
|
-
gitRemote: string,
|
|
38
|
-
gitSelector: string,
|
|
39
|
-
extra?: string
|
|
40
|
-
] | [
|
|
41
|
-
type: 'registry',
|
|
42
|
-
registry: string,
|
|
43
|
-
registrySpec: string,
|
|
44
|
-
extra?: string
|
|
45
|
-
] | [type: 'file', path: string, extra?: string] | [type: 'remote', url: string, extra?: string] | [type: 'workspace', workspace: string, extra?: string];
|
|
46
|
-
export declare const isDepID: (str: unknown) => str is DepID;
|
|
47
|
-
export declare const asDepID: (str: string) => DepID;
|
|
48
|
-
/**
|
|
49
|
-
* turn a {@link DepIDTuple} into a {@link DepID}
|
|
50
|
-
*/
|
|
51
|
-
export declare const joinDepIDTuple: (list: DepIDTuple) => DepID;
|
|
52
|
-
/**
|
|
53
|
-
* turn a {@link DepID} into a {@link DepIDTuple}
|
|
54
|
-
*/
|
|
55
|
-
export declare const splitDepID: (id: string) => DepIDTuple;
|
|
56
|
-
/**
|
|
57
|
-
* Turn a {@link DepID} into a {@link Spec} object
|
|
6
|
+
* Turn a {@link DepID} into a {@link Spec} object using
|
|
7
|
+
* the Node.js-specific `Spec.parse` method.
|
|
58
8
|
*/
|
|
59
9
|
export declare const hydrate: (id: DepID, name?: string, options?: SpecOptions) => Spec;
|
|
60
10
|
/**
|
|
61
|
-
* Turn a {@link DepIDTuple} into a {@link Spec} object
|
|
62
|
-
|
|
63
|
-
export declare const hydrateTuple: (tuple: DepIDTuple, name?: string, options?: SpecOptions) => import("@vltpkg/spec/browser").Spec;
|
|
64
|
-
/**
|
|
65
|
-
* Get the {@link DepIDTuple} for a given {@link Spec} and {@link Manifest}.
|
|
66
|
-
* The Manifest is used to get the name and version, if possible. If not found
|
|
67
|
-
* in the manifest, registry ID types will use the name or bareSpec from the
|
|
68
|
-
* specifier, so at least there's something to use later.
|
|
11
|
+
* Turn a {@link DepIDTuple} into a {@link Spec} object using
|
|
12
|
+
* the Node.js-specific `Spec.parse` method.
|
|
69
13
|
*/
|
|
70
|
-
export declare const
|
|
14
|
+
export declare const hydrateTuple: (tuple: DepIDTuple, name?: string, options?: SpecOptions) => Spec;
|
|
71
15
|
/**
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
* the manifest, registry ID types will use the name or bareSpec from the
|
|
75
|
-
* specifier, so at least there's something to use later.
|
|
16
|
+
* Reset internal caches. This should be used when options change since
|
|
17
|
+
* they're not take into account in the memoization keys.
|
|
76
18
|
*/
|
|
77
|
-
export declare const
|
|
19
|
+
export declare const resetCaches: () => void;
|
|
78
20
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/esm/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAGL,IAAI,EACL,MAAM,cAAc,CAAA;AAKrB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAQrD,cAAc,cAAc,CAAA;AAG5B;;;GAGG;AAEH,eAAO,MAAM,OAAO,OACd,KAAK,SACF,MAAM,YACJ,WAAW,KACnB,IAQF,CAAA;AAGD;;;GAGG;AAEH,eAAO,MAAM,YAAY,UAChB,UAAU,SACV,MAAM,YACJ,WAAW,KACnB,IAmHF,CAAA;AAED;;;GAGG;AAEH,eAAO,MAAM,WAAW,YAIvB,CAAA"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,93 +1,51 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
|
-
import { Spec } from '@vltpkg/spec';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return str;
|
|
15
|
-
};
|
|
2
|
+
import { currentDefaultRegistryName, defaultRegistryName, Spec, } from '@vltpkg/spec';
|
|
3
|
+
import { resetCaches as browserResetCaches, splitDepID, } from "./browser.js";
|
|
4
|
+
// Here we re-export the browser-specific parts of the implementation
|
|
5
|
+
// we disable the eslint rules for import/export since we are intentionally
|
|
6
|
+
// re-exporting the `hydrate` and `hydrateTuple` functions to make sure they
|
|
7
|
+
// use the Node.js-specific `Spec.parse` method that relies on internal node
|
|
8
|
+
// modules like `util` and `path` that are not isomorphic.
|
|
9
|
+
// eslint-disable-next-line import/export
|
|
10
|
+
export * from "./browser.js";
|
|
11
|
+
const seenHydrated = new Map();
|
|
16
12
|
/**
|
|
17
|
-
*
|
|
13
|
+
* Turn a {@link DepID} into a {@link Spec} object using
|
|
14
|
+
* the Node.js-specific `Spec.parse` method.
|
|
18
15
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
16
|
+
// eslint-disable-next-line import/export
|
|
17
|
+
export const hydrate = (id, name, options = {}) => {
|
|
18
|
+
// memoized entries return early
|
|
19
|
+
const cacheKey = (name ?? '') + id;
|
|
20
|
+
const seen = seenHydrated.get(cacheKey);
|
|
21
|
+
if (seen)
|
|
22
|
+
return seen;
|
|
23
|
+
const res = hydrateTuple(splitDepID(id), name, options);
|
|
24
|
+
seenHydrated.set(cacheKey, res);
|
|
25
|
+
return res;
|
|
30
26
|
};
|
|
31
|
-
|
|
32
|
-
const encode = (s) => encodeURIComponent(s)
|
|
33
|
-
.replaceAll('%40', '@')
|
|
34
|
-
.replaceAll('%2f', '§')
|
|
35
|
-
.replaceAll('%2F', '§');
|
|
27
|
+
const seenHydratedTuples = new Map();
|
|
36
28
|
/**
|
|
37
|
-
*
|
|
38
|
-
|
|
39
|
-
export const splitDepID = (id) => {
|
|
40
|
-
const [type, first = '', second, extra] = id
|
|
41
|
-
.replaceAll('§', '/')
|
|
42
|
-
.split(delimiter, 4);
|
|
43
|
-
const f = decodeURIComponent(first);
|
|
44
|
-
switch (type) {
|
|
45
|
-
case 'git':
|
|
46
|
-
case '': {
|
|
47
|
-
if (second === undefined) {
|
|
48
|
-
throw error(`invalid ${type} id`, { found: id });
|
|
49
|
-
}
|
|
50
|
-
const t = [
|
|
51
|
-
type || 'registry',
|
|
52
|
-
f,
|
|
53
|
-
decodeURIComponent(second),
|
|
54
|
-
];
|
|
55
|
-
if (extra)
|
|
56
|
-
t.push(decodeURIComponent(extra));
|
|
57
|
-
return t;
|
|
58
|
-
}
|
|
59
|
-
case 'file':
|
|
60
|
-
case 'remote':
|
|
61
|
-
case 'workspace': {
|
|
62
|
-
const t = [type, f];
|
|
63
|
-
if (second)
|
|
64
|
-
t.push(decodeURIComponent(second));
|
|
65
|
-
return t;
|
|
66
|
-
}
|
|
67
|
-
default: {
|
|
68
|
-
throw error('invalid DepID type', {
|
|
69
|
-
found: type,
|
|
70
|
-
validOptions: ['git', 'file', 'workspace', 'remote', ''],
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
/**
|
|
76
|
-
* Turn a {@link DepID} into a {@link Spec} object
|
|
77
|
-
*/
|
|
78
|
-
export const hydrate = (id, name, options = {}) => hydrateTuple(splitDepID(id), name, options);
|
|
79
|
-
/**
|
|
80
|
-
* Turn a {@link DepIDTuple} into a {@link Spec} object
|
|
29
|
+
* Turn a {@link DepIDTuple} into a {@link Spec} object using
|
|
30
|
+
* the Node.js-specific `Spec.parse` method.
|
|
81
31
|
*/
|
|
32
|
+
// eslint-disable-next-line import/export
|
|
82
33
|
export const hydrateTuple = (tuple, name, options = {}) => {
|
|
83
34
|
const [type, first, second] = tuple;
|
|
35
|
+
// memoized entries return early
|
|
36
|
+
const cacheKey = (name ?? '') + ',' + type + ',' + first + ',' + (second ?? '');
|
|
37
|
+
const seen = seenHydratedTuples.get(cacheKey);
|
|
38
|
+
if (seen)
|
|
39
|
+
return seen;
|
|
40
|
+
let res;
|
|
84
41
|
switch (type) {
|
|
85
42
|
case 'remote': {
|
|
86
43
|
if (!first)
|
|
87
44
|
throw error('no remoteURL found on remote id', {
|
|
88
45
|
found: tuple,
|
|
89
46
|
});
|
|
90
|
-
|
|
47
|
+
res = Spec.parse(name ?? '(unknown)', first, options);
|
|
48
|
+
break;
|
|
91
49
|
}
|
|
92
50
|
case 'file': {
|
|
93
51
|
if (!first) {
|
|
@@ -95,7 +53,8 @@ export const hydrateTuple = (tuple, name, options = {}) => {
|
|
|
95
53
|
found: tuple,
|
|
96
54
|
});
|
|
97
55
|
}
|
|
98
|
-
|
|
56
|
+
res = Spec.parse(name ?? '(unknown)', `file:${first}`, options);
|
|
57
|
+
break;
|
|
99
58
|
}
|
|
100
59
|
case 'registry': {
|
|
101
60
|
if (typeof first !== 'string') {
|
|
@@ -108,30 +67,44 @@ export const hydrateTuple = (tuple, name, options = {}) => {
|
|
|
108
67
|
found: tuple,
|
|
109
68
|
});
|
|
110
69
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
70
|
+
const defaultName = options.registry &&
|
|
71
|
+
currentDefaultRegistryName(options.registry, options);
|
|
72
|
+
const defaultRegistryURL = options.registry ?
|
|
73
|
+
options.registry.endsWith('/') ?
|
|
74
|
+
options.registry
|
|
75
|
+
: options.registry + '/'
|
|
76
|
+
: undefined;
|
|
77
|
+
const firstURL = first.endsWith('/') ? first : first + '/';
|
|
78
|
+
const hasScope = second.startsWith('@');
|
|
79
|
+
const hasAtVersion = second.includes('@', hasScope ? 1 : 0);
|
|
80
|
+
const name_ = (hasAtVersion && hasScope ?
|
|
81
|
+
`@${second.split('@')[1]}`
|
|
82
|
+
: second.split('@')[0]) /* c8 ignore next */ || '(unknown)';
|
|
83
|
+
const usesDefaultRegistry = !first ||
|
|
84
|
+
first === defaultName ||
|
|
85
|
+
firstURL === defaultRegistryURL;
|
|
86
|
+
const noAliasedNameUsed = !name || name === name_;
|
|
87
|
+
if (usesDefaultRegistry && noAliasedNameUsed) {
|
|
88
|
+
const version = (hasAtVersion &&
|
|
89
|
+
second.split('@')[hasScope ? 2 : 1]) /* c8 ignore next */ ||
|
|
90
|
+
second;
|
|
91
|
+
res = Spec.parse(name || name_, version, options);
|
|
92
|
+
break;
|
|
120
93
|
}
|
|
121
94
|
if (!/^https?:\/\//.test(first)) {
|
|
122
95
|
const reg = options.registries?.[first];
|
|
123
|
-
|
|
96
|
+
const jsrReg = options['jsr-registries']?.[first];
|
|
97
|
+
if (first !== defaultRegistryName && !reg && !jsrReg) {
|
|
124
98
|
throw error('named registry not found in options', {
|
|
125
99
|
name: first,
|
|
126
100
|
found: tuple,
|
|
127
101
|
});
|
|
128
102
|
}
|
|
129
|
-
|
|
103
|
+
res = Spec.parse(name || name_, `${first}:${second}`, options);
|
|
104
|
+
break;
|
|
130
105
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
Spec.parse(s.final.name + '@' + s.bareSpec)
|
|
134
|
-
: s;
|
|
106
|
+
res = Spec.parse(name || name_, `registry:${first}#${second}`, options);
|
|
107
|
+
break;
|
|
135
108
|
}
|
|
136
109
|
case 'git': {
|
|
137
110
|
if (!first) {
|
|
@@ -139,91 +112,31 @@ export const hydrateTuple = (tuple, name, options = {}) => {
|
|
|
139
112
|
found: tuple,
|
|
140
113
|
});
|
|
141
114
|
}
|
|
142
|
-
|
|
115
|
+
res = Spec.parse(name ?? '(unknown)', first + '#' + second, options);
|
|
116
|
+
break;
|
|
143
117
|
}
|
|
144
118
|
case 'workspace': {
|
|
145
119
|
if (!first) {
|
|
146
120
|
throw error('no name/path on workspace id', { found: tuple });
|
|
147
121
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
122
|
+
res =
|
|
123
|
+
name && name !== first ?
|
|
124
|
+
Spec.parse(name, `workspace:${first}@*`, options)
|
|
125
|
+
: Spec.parse(first, `workspace:*`, options);
|
|
126
|
+
break;
|
|
151
127
|
}
|
|
152
128
|
}
|
|
129
|
+
seenHydratedTuples.set(cacheKey, res);
|
|
130
|
+
return res;
|
|
153
131
|
};
|
|
154
|
-
// Strip out the default registry, there's no need to store that
|
|
155
|
-
const omitDefReg = (s) => (!s ||
|
|
156
|
-
s === 'https://registry.npmjs.org' ||
|
|
157
|
-
s === 'https://registry.npmjs.org/') ?
|
|
158
|
-
''
|
|
159
|
-
: s;
|
|
160
132
|
/**
|
|
161
|
-
*
|
|
162
|
-
*
|
|
163
|
-
* in the manifest, registry ID types will use the name or bareSpec from the
|
|
164
|
-
* specifier, so at least there's something to use later.
|
|
133
|
+
* Reset internal caches. This should be used when options change since
|
|
134
|
+
* they're not take into account in the memoization keys.
|
|
165
135
|
*/
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const reg = omitDefReg(f.registry);
|
|
172
|
-
if (!f.namedRegistry && reg) {
|
|
173
|
-
for (const [alias, host] of Object.entries(spec.options.registries)) {
|
|
174
|
-
if (reg === host) {
|
|
175
|
-
f.namedRegistry = alias;
|
|
176
|
-
break;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
const version = mani.version ?
|
|
181
|
-
mani.version.startsWith('v') ?
|
|
182
|
-
mani.version.slice(1)
|
|
183
|
-
: mani.version
|
|
184
|
-
: f.bareSpec;
|
|
185
|
-
return [
|
|
186
|
-
f.type,
|
|
187
|
-
f.namedRegistry ?? reg,
|
|
188
|
-
`${mani.name ?? f.name}@${version}`,
|
|
189
|
-
];
|
|
190
|
-
}
|
|
191
|
-
case 'git': {
|
|
192
|
-
const { namedGitHost, namedGitHostPath, gitRemote, gitSelector = '', } = f;
|
|
193
|
-
if (!gitRemote)
|
|
194
|
-
throw error('no host on git specifier', { spec });
|
|
195
|
-
if (namedGitHost) {
|
|
196
|
-
if (!namedGitHostPath) {
|
|
197
|
-
throw error('named git host without path portion', {
|
|
198
|
-
spec,
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
|
-
return [
|
|
202
|
-
f.type,
|
|
203
|
-
`${namedGitHost}:${namedGitHostPath}`,
|
|
204
|
-
gitSelector,
|
|
205
|
-
];
|
|
206
|
-
}
|
|
207
|
-
else {
|
|
208
|
-
return [f.type, gitRemote, gitSelector];
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
case 'remote': {
|
|
212
|
-
const { remoteURL } = f;
|
|
213
|
-
if (!remoteURL)
|
|
214
|
-
throw error('no URL on remote specifier', { spec });
|
|
215
|
-
return [f.type, remoteURL];
|
|
216
|
-
}
|
|
217
|
-
case 'file':
|
|
218
|
-
case 'workspace':
|
|
219
|
-
throw error('Path-based dep ids are not supported', { spec });
|
|
220
|
-
}
|
|
136
|
+
// eslint-disable-next-line import/export
|
|
137
|
+
export const resetCaches = () => {
|
|
138
|
+
seenHydrated.clear();
|
|
139
|
+
seenHydratedTuples.clear();
|
|
140
|
+
browserResetCaches();
|
|
221
141
|
};
|
|
222
|
-
/**
|
|
223
|
-
* Get the {@link DepID} for a given {@link Spec} and {@link Manifest}. The
|
|
224
|
-
* Manifest is used to get the name and version, if possible. If not found in
|
|
225
|
-
* the manifest, registry ID types will use the name or bareSpec from the
|
|
226
|
-
* specifier, so at least there's something to use later.
|
|
227
|
-
*/
|
|
228
|
-
export const getId = (spec, mani) => joinDepIDTuple(getTuple(spec, mani));
|
|
229
142
|
//# sourceMappingURL=index.js.map
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAInC,MAAM,CAAC,MAAM,SAAS,GAAc,GAAG,CAAA;AAsDvC,MAAM,WAAW,GAAG,IAAI,MAAM,CAC5B,WAAW,SAAS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A0B,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;YACnD,IAAI,YAAY,EAAE,CAAC;gBACjB,IAAI,CAAC,gBAAgB,EAAE,CAAC;oBACtB,MAAM,KAAK,CAAC,qCAAqC,EAAE;wBACjD,IAAI;qBACL,CAAC,CAAA;gBACJ,CAAC;gBACD,OAAO;oBACL,CAAC,CAAC,IAAI;oBACN,GAAG,YAAY,IAAI,gBAAgB,EAAE;oBACrC,WAAW;iBACZ,CAAA;YACH,CAAC;iBAAM,CAAC;gBACN,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,CAAC,CAAA;YACzC,CAAC;QACH,CAAC;QACD,KAAK,QAAQ,CAAC,CAAC,CAAC;YACd,MAAM,EAAE,SAAS,EAAE,GAAG,CAAC,CAAA;YACvB,IAAI,CAAC,SAAS;gBACZ,MAAM,KAAK,CAAC,4BAA4B,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;YACrD,OAAO,CAAC,CAAC,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;QAC5B,CAAC;QACD,KAAK,MAAM,CAAC;QACZ,KAAK,WAAW;YACd,MAAM,KAAK,CAAC,sCAAsC,EAAE,EAAE,IAAI,EAAE,CAAC,CAAA;IACjE,CAAC;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAU,EAAE,IAAc,EAAS,EAAE,CACzD,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { Spec } from '@vltpkg/spec'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { Manifest } from '@vltpkg/types'\n\nexport const delimiter: Delimiter = '·'\nexport type Delimiter = '·'\n\n/**\n * Dependency IDs are a URI-encoded set of strings, separated\n * by the {@link Delimiter} character (`'·'`).\n *\n * The first entry is always the specifier type. The rest depend on the\n * type. `git`, `registry`, and `workspace` entries have 3 fields, the rest\n * have 2.\n *\n * - `registry`: `'registry·<registry>·name@specifier'`\n * The `<registry>` portion can be a known named registry name, or a\n * url to a registry. If empty, it is the default registry. Examples:\n * - `··some-package@2.0.1`\n * - `·npm·whatever@1.2.3`\n * - `·http%3A%2F%2Fvlt.sh%2F·x@1.2.3`\n * - `git`: `'git·<git remote>·<git selector>'`. For example:\n * - `git·github:user/project·branchname`\n * - `git·git%2Bssh%3A%2F%2Fuser%40host%3Aproject.git·semver:1.x`\n * - `workspace`: `'workspace·<path>'`. For example:\n * - `workspace·src/mything`\n * - `remote`: `'remote·<url>'`\n * - `file`: `'file·<path>'`\n *\n * Lastly, the final portion can contain arbitrary string data, and is\n * used to store peer dep resolutions to maintain the peerDep contract.\n */\nexport type DepID =\n | `${'' | 'git'}${Delimiter}${string}${Delimiter}${string}${Delimiter}${string}`\n | `${'' | 'git'}${Delimiter}${string}${Delimiter}${string}`\n | `${'file' | 'remote' | 'workspace'}${Delimiter}${string}${Delimiter}${string}`\n | `${'file' | 'remote' | 'workspace'}${Delimiter}${string}`\n\n/**\n * A {@link DepID}, split apart and URI-decoded\n */\nexport type DepIDTuple =\n | [\n type: 'git',\n gitRemote: string,\n gitSelector: string,\n extra?: string,\n ]\n | [\n type: 'registry',\n registry: string,\n registrySpec: string,\n extra?: string,\n ]\n | [type: 'file', path: string, extra?: string]\n | [type: 'remote', url: string, extra?: string]\n | [type: 'workspace', workspace: string, extra?: string]\n\nconst depIDRegExp = new RegExp(\n `^((git)?${delimiter}[^${delimiter}]*${delimiter}[^${delimiter}]*(${\n delimiter\n }[^${delimiter}]*)?$` +\n `|` +\n `^(file|remote|workspace)${delimiter}[^${\n delimiter\n }]*)(${delimiter}[^${delimiter}]*)?$`,\n)\n\nexport const isDepID = (str: unknown): str is DepID =>\n typeof str === 'string' && depIDRegExp.test(str)\n\nexport const asDepID = (str: string): DepID => {\n if (!isDepID(str)) {\n throw error('Expected dep id', {\n found: str,\n })\n }\n return str\n}\n\n/**\n * turn a {@link DepIDTuple} into a {@link DepID}\n */\nexport const joinDepIDTuple = (list: DepIDTuple): DepID => {\n const [type, first, second, extra] = list\n const f = encode(first)\n switch (type) {\n case 'registry':\n return `${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`\n case 'git':\n return `${type}${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`\n default:\n return `${type}${delimiter}${f}${second ? `${delimiter}${encode(second)}` : ''}`\n }\n}\n\n// allow @, but otherwise, escape everything urls do\nconst encode = (s: string): string =>\n encodeURIComponent(s)\n .replaceAll('%40', '@')\n .replaceAll('%2f', '§')\n .replaceAll('%2F', '§')\n\n/**\n * turn a {@link DepID} into a {@link DepIDTuple}\n */\nexport const splitDepID = (id: string): DepIDTuple => {\n const [type, first = '', second, extra] = id\n .replaceAll('§', '/')\n .split(delimiter, 4)\n const f = decodeURIComponent(first)\n switch (type) {\n case 'git':\n case '': {\n if (second === undefined) {\n throw error(`invalid ${type} id`, { found: id })\n }\n const t: DepIDTuple = [\n type || 'registry',\n f,\n decodeURIComponent(second),\n ]\n if (extra) t.push(decodeURIComponent(extra))\n return t\n }\n case 'file':\n case 'remote':\n case 'workspace': {\n const t: DepIDTuple = [type, f]\n if (second) t.push(decodeURIComponent(second))\n return t\n }\n default: {\n throw error('invalid DepID type', {\n found: type,\n validOptions: ['git', 'file', 'workspace', 'remote', ''],\n })\n }\n }\n}\n\n/**\n * Turn a {@link DepID} into a {@link Spec} object\n */\nexport const hydrate = (\n id: DepID,\n name?: string,\n options: SpecOptions = {},\n): Spec => hydrateTuple(splitDepID(id), name, options)\n\n/**\n * Turn a {@link DepIDTuple} into a {@link Spec} object\n */\nexport const hydrateTuple = (\n tuple: DepIDTuple,\n name?: string,\n options: SpecOptions = {},\n) => {\n const [type, first, second] = tuple\n switch (type) {\n case 'remote': {\n if (!first)\n throw error('no remoteURL found on remote id', {\n found: tuple,\n })\n return Spec.parse(name ?? '(unknown)', first)\n }\n case 'file': {\n if (!first) {\n throw error('no file path found on remote id', {\n found: tuple,\n })\n }\n return Spec.parse(name ?? '(unknown)', `file:${first}`, options)\n }\n case 'registry': {\n if (typeof first !== 'string') {\n throw error('no registry url or name in registry ID', {\n found: tuple,\n })\n }\n if (!second) {\n throw error('no name/specifier in registry ID', {\n found: tuple,\n })\n }\n if (!first) {\n // just a normal name@version on the default registry\n const s = Spec.parse(second)\n if (name && s.name !== name) {\n return Spec.parse(`${name}@npm:${second}`)\n } else {\n return s\n }\n }\n if (!/^https?:\\/\\//.test(first)) {\n const reg = options.registries?.[first]\n if (first !== 'npm' && !reg) {\n throw error('named registry not found in options', {\n name: first,\n found: tuple,\n })\n }\n return Spec.parse(\n name ?? '(unknown)',\n `${first}:${second}`,\n options,\n )\n }\n const s = Spec.parse(\n name ?? '(unknown)',\n `registry:${first}#${second}`,\n options,\n )\n return name && s.final.name !== name ?\n Spec.parse(s.final.name + '@' + s.bareSpec)\n : s\n }\n case 'git': {\n if (!first) {\n throw error('no git remote in git ID', {\n found: tuple,\n })\n }\n return Spec.parse(\n name ?? '(unknown)',\n first + '#' + second,\n options,\n )\n }\n case 'workspace': {\n if (!first) {\n throw error('no name/path on workspace id', { found: tuple })\n }\n return name && name !== first ?\n Spec.parse(name, `workspace:${first}@*`, options)\n : Spec.parse(first, `workspace:*`, options)\n }\n }\n}\n\n// Strip out the default registry, there's no need to store that\nconst omitDefReg = (s?: string): string =>\n (\n !s ||\n s === 'https://registry.npmjs.org' ||\n s === 'https://registry.npmjs.org/'\n ) ?\n ''\n : s\n\n/**\n * Get the {@link DepIDTuple} for a given {@link Spec} and {@link Manifest}.\n * The Manifest is used to get the name and version, if possible. If not found\n * in the manifest, registry ID types will use the name or bareSpec from the\n * specifier, so at least there's something to use later.\n */\nexport const getTuple = (spec: Spec, mani: Manifest): DepIDTuple => {\n const f = spec.final\n switch (f.type) {\n case 'registry': {\n // try to shorten to a known name if we can.\n const reg = omitDefReg(f.registry)\n if (!f.namedRegistry && reg) {\n for (const [alias, host] of Object.entries(\n spec.options.registries,\n )) {\n if (reg === host) {\n f.namedRegistry = alias\n break\n }\n }\n }\n const version =\n mani.version ?\n mani.version.startsWith('v') ?\n mani.version.slice(1)\n : mani.version\n : f.bareSpec\n return [\n f.type,\n f.namedRegistry ?? reg,\n `${mani.name ?? f.name}@${version}`,\n ]\n }\n case 'git': {\n const {\n namedGitHost,\n namedGitHostPath,\n gitRemote,\n gitSelector = '',\n } = f\n if (!gitRemote)\n throw error('no host on git specifier', { spec })\n if (namedGitHost) {\n if (!namedGitHostPath) {\n throw error('named git host without path portion', {\n spec,\n })\n }\n return [\n f.type,\n `${namedGitHost}:${namedGitHostPath}`,\n gitSelector,\n ]\n } else {\n return [f.type, gitRemote, gitSelector]\n }\n }\n case 'remote': {\n const { remoteURL } = f\n if (!remoteURL)\n throw error('no URL on remote specifier', { spec })\n return [f.type, remoteURL]\n }\n case 'file':\n case 'workspace':\n throw error('Path-based dep ids are not supported', { spec })\n }\n}\n\n/**\n * Get the {@link DepID} for a given {@link Spec} and {@link Manifest}. The\n * Manifest is used to get the name and version, if possible. If not found in\n * the manifest, registry ID types will use the name or bareSpec from the\n * specifier, so at least there's something to use later.\n */\nexport const getId = (spec: Spec, mani: Manifest): DepID =>\n joinDepIDTuple(getTuple(spec, mani))\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EACL,0BAA0B,EAC1B,mBAAmB,EACnB,IAAI,GACL,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,WAAW,IAAI,kBAAkB,EACjC,UAAU,GACX,MAAM,cAAc,CAAA;AAIrB,qEAAqE;AACrE,2EAA2E;AAC3E,4EAA4E;AAC5E,4EAA4E;AAC5E,0DAA0D;AAC1D,yCAAyC;AACzC,cAAc,cAAc,CAAA;AAE5B,MAAM,YAAY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AA;IACrC,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;;GAGG;AACH,yCAAyC;AACzC,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,EAAE;IAC9B,YAAY,CAAC,KAAK,EAAE,CAAA;IACpB,kBAAkB,CAAC,KAAK,EAAE,CAAA;IAC1B,kBAAkB,EAAE,CAAA;AACtB,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport {\n currentDefaultRegistryName,\n defaultRegistryName,\n Spec,\n} from '@vltpkg/spec'\nimport {\n resetCaches as browserResetCaches,\n splitDepID,\n} from './browser.ts'\nimport type { SpecOptions } from '@vltpkg/spec'\nimport type { DepID, DepIDTuple } from './browser.ts'\n\n// Here we re-export the browser-specific parts of the implementation\n// we disable the eslint rules for import/export since we are intentionally\n// re-exporting the `hydrate` and `hydrateTuple` functions to make sure they\n// use the Node.js-specific `Spec.parse` method that relies on internal node\n// modules like `util` and `path` that are not isomorphic.\n// eslint-disable-next-line import/export\nexport * from './browser.ts'\n\nconst seenHydrated = new Map<string, Spec>()\n/**\n * Turn a {@link DepID} into a {@link Spec} object using\n * the Node.js-specific `Spec.parse` method.\n */\n// eslint-disable-next-line import/export\nexport const hydrate = (\n id: DepID,\n name?: string,\n options: SpecOptions = {},\n): Spec => {\n // memoized entries return early\n const cacheKey = (name ?? '') + id\n const seen = seenHydrated.get(cacheKey)\n if (seen) return seen\n const res = hydrateTuple(splitDepID(id), name, options)\n seenHydrated.set(cacheKey, res)\n return res\n}\n\nconst seenHydratedTuples = new Map<string, Spec>()\n/**\n * Turn a {@link DepIDTuple} into a {@link Spec} object using\n * the Node.js-specific `Spec.parse` method.\n */\n// eslint-disable-next-line import/export\nexport const hydrateTuple = (\n tuple: DepIDTuple,\n name?: string,\n options: SpecOptions = {},\n): Spec => {\n const [type, first, second] = tuple\n\n // memoized entries return early\n const cacheKey =\n (name ?? '') + ',' + type + ',' + first + ',' + (second ?? '')\n const seen = seenHydratedTuples.get(cacheKey)\n if (seen) return seen\n\n let res: Spec\n switch (type) {\n case 'remote': {\n if (!first)\n throw error('no remoteURL found on remote id', {\n found: tuple,\n })\n res = Spec.parse(name ?? '(unknown)', first, options)\n break\n }\n case 'file': {\n if (!first) {\n throw error('no file path found on remote id', {\n found: tuple,\n })\n }\n res = Spec.parse(name ?? '(unknown)', `file:${first}`, options)\n break\n }\n case 'registry': {\n if (typeof first !== 'string') {\n throw error('no registry url or name in registry ID', {\n found: tuple,\n })\n }\n if (!second) {\n throw error('no name/specifier in registry ID', {\n found: tuple,\n })\n }\n const defaultName =\n options.registry &&\n currentDefaultRegistryName(options.registry, options)\n const defaultRegistryURL =\n options.registry ?\n options.registry.endsWith('/') ?\n options.registry\n : options.registry + '/'\n : undefined\n const firstURL = first.endsWith('/') ? first : first + '/'\n const hasScope = second.startsWith('@')\n const hasAtVersion = second.includes('@', hasScope ? 1 : 0)\n const name_ =\n (hasAtVersion && hasScope ?\n `@${second.split('@')[1]}`\n : second.split('@')[0]) /* c8 ignore next */ || '(unknown)'\n const usesDefaultRegistry =\n !first ||\n first === defaultName ||\n firstURL === defaultRegistryURL\n const noAliasedNameUsed = !name || name === name_\n if (usesDefaultRegistry && noAliasedNameUsed) {\n const version =\n (hasAtVersion &&\n second.split('@')[\n hasScope ? 2 : 1\n ]) /* c8 ignore next */ ||\n second\n res = Spec.parse(name || name_, version, options)\n break\n }\n if (!/^https?:\\/\\//.test(first)) {\n const reg = options.registries?.[first]\n const jsrReg = options['jsr-registries']?.[first]\n if (first !== defaultRegistryName && !reg && !jsrReg) {\n throw error('named registry not found in options', {\n name: first,\n found: tuple,\n })\n }\n res = Spec.parse(name || name_, `${first}:${second}`, options)\n break\n }\n res = Spec.parse(\n name || name_,\n `registry:${first}#${second}`,\n options,\n )\n break\n }\n case 'git': {\n if (!first) {\n throw error('no git remote in git ID', {\n found: tuple,\n })\n }\n res = Spec.parse(\n name ?? '(unknown)',\n first + '#' + second,\n options,\n )\n break\n }\n case 'workspace': {\n if (!first) {\n throw error('no name/path on workspace id', { found: tuple })\n }\n res =\n name && name !== first ?\n Spec.parse(name, `workspace:${first}@*`, options)\n : Spec.parse(first, `workspace:*`, options)\n break\n }\n }\n seenHydratedTuples.set(cacheKey, res)\n return res\n}\n\n/**\n * Reset internal caches. This should be used when options change since\n * they're not take into account in the memoization keys.\n */\n// eslint-disable-next-line import/export\nexport const resetCaches = () => {\n seenHydrated.clear()\n seenHydratedTuples.clear()\n browserResetCaches()\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/dep-id",
|
|
3
3
|
"description": "create and hydrate dependency IDs",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "1.0.0-rc.10",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
8
8
|
"directory": "src/dep-id"
|
|
9
9
|
},
|
|
10
|
+
"author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
|
|
10
11
|
"tshy": {
|
|
11
12
|
"selfLink": false,
|
|
12
13
|
"liveDev": true,
|
|
@@ -20,25 +21,24 @@
|
|
|
20
21
|
}
|
|
21
22
|
},
|
|
22
23
|
"dependencies": {
|
|
23
|
-
"@vltpkg/error-cause": "
|
|
24
|
-
"@vltpkg/types": "
|
|
25
|
-
"@vltpkg/spec": "
|
|
24
|
+
"@vltpkg/error-cause": "1.0.0-rc.10",
|
|
25
|
+
"@vltpkg/types": "1.0.0-rc.10",
|
|
26
|
+
"@vltpkg/spec": "1.0.0-rc.10"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@eslint/js": "^9.
|
|
29
|
-
"@types/
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"typedoc": "0.27.6",
|
|
29
|
+
"@eslint/js": "^9.39.1",
|
|
30
|
+
"@types/node": "^22.19.2",
|
|
31
|
+
"eslint": "^9.39.1",
|
|
32
|
+
"prettier": "^3.7.4",
|
|
33
|
+
"tap": "^21.5.0",
|
|
34
|
+
"tshy": "^3.1.0",
|
|
35
|
+
"typedoc": "~0.27.9",
|
|
36
36
|
"typescript": "5.7.3",
|
|
37
|
-
"typescript-eslint": "^8.
|
|
37
|
+
"typescript-eslint": "^8.49.0"
|
|
38
38
|
},
|
|
39
39
|
"license": "BSD-2-Clause-Patent",
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=22"
|
|
41
|
+
"node": ">=22.9.0"
|
|
42
42
|
},
|
|
43
43
|
"tap": {
|
|
44
44
|
"extends": "../../tap-config.yaml"
|
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
"snap": "tap",
|
|
73
73
|
"test": "tap",
|
|
74
74
|
"posttest": "tsc --noEmit",
|
|
75
|
+
"tshy": "tshy",
|
|
75
76
|
"typecheck": "tsc --noEmit"
|
|
76
77
|
}
|
|
77
78
|
}
|