@vltpkg/dep-id 1.0.0-rc.3 → 1.0.0-rc.31

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 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;;x@1.2.3
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;vlt;y@latest
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;github:a/b;branch
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;github:a/b;branch', 'x') // x@github:a/b#branch
47
+ const spec = hydrate('git~github:a/b~branch', 'x') // x@github:a/b#branch
48
48
  ```
49
49
 
50
50
  ### Note
@@ -2,28 +2,28 @@ import { Spec } from '@vltpkg/spec/browser';
2
2
  import type { SpecOptions } from '@vltpkg/spec/browser';
3
3
  import type { Manifest } from '@vltpkg/types';
4
4
  export declare const delimiter: Delimiter;
5
- export type Delimiter = '·';
5
+ export type Delimiter = '~';
6
6
  /**
7
7
  * Dependency IDs are a URI-encoded set of strings, separated
8
- * by the {@link Delimiter} character (`'·'`).
8
+ * by the {@link Delimiter} character (`'~'`).
9
9
  *
10
10
  * The first entry is always the specifier type. The rest depend on the
11
11
  * type. `git`, `registry`, and `workspace` entries have 3 fields, the rest
12
12
  * have 2.
13
13
  *
14
- * - `registry`: `'registry·<registry>·name@specifier'`
14
+ * - `registry`: `'registry~<registry>~name@specifier'`
15
15
  * The `<registry>` portion can be a known named registry name, or a
16
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>'`
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
27
  *
28
28
  * Lastly, the final portion can contain arbitrary string data, and is
29
29
  * used to store peer dep resolutions to maintain the peerDep contract.
@@ -85,9 +85,22 @@ export declare const isPackageNameConfused: (spec?: Spec, name?: string) => bool
85
85
  * specifier, so at least there's something to use later.
86
86
  */
87
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
+ };
88
102
  /**
89
103
  * Reset internal caches. This should be used when options change since
90
104
  * they're not take into account in the memoization keys.
91
105
  */
92
106
  export declare const resetCaches: () => void;
93
- //# sourceMappingURL=browser.d.ts.map
@@ -1,6 +1,7 @@
1
1
  import { error } from '@vltpkg/error-cause';
2
- import { Spec } from '@vltpkg/spec/browser';
3
- export const delimiter = '·';
2
+ import { currentDefaultRegistryName, defaultRegistryName, Spec, } from '@vltpkg/spec/browser';
3
+ export const delimiter = '~';
4
+ const EXTRA_PEER_SET_DELIMITER = 'peer.';
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,23 +22,159 @@ 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:
28
29
  return `${type}${delimiter}${f}${second ? `${delimiter}${encode(second)}` : ''}`;
29
30
  }
30
31
  };
31
- // allow @, but otherwise, escape everything urls do
32
- const encode = (s) => s ?
33
- encodeURIComponent(s)
34
- .replaceAll('%40', '@')
35
- .replaceAll('%2f', '§')
36
- .replaceAll('%2F', '§')
37
- : s;
38
- const decode = (s) => s ?
39
- decodeURIComponent(s.replaceAll('@', '%40').replaceAll('§', '%2F'))
40
- : s;
32
+ // Escape chars unsafe for filesystems or reserved for DepID syntax
33
+ const ESCAPE = {
34
+ _: '__',
35
+ '+': '_p',
36
+ '\\': '_b',
37
+ ':': '_c',
38
+ '~': '_t',
39
+ '<': '_l',
40
+ '>': '_g',
41
+ '"': '_q',
42
+ '|': '_i',
43
+ '?': '_m',
44
+ '*': '_a',
45
+ ' ': '_s',
46
+ };
47
+ // Unescape map (includes trailing dot/space escapes)
48
+ const UNESCAPE = {
49
+ __: '_',
50
+ _p: '+',
51
+ _b: '\\',
52
+ _c: ':',
53
+ _t: '~',
54
+ _l: '<',
55
+ _g: '>',
56
+ _q: '"',
57
+ _i: '|',
58
+ _m: '?',
59
+ _a: '*',
60
+ _d: '.',
61
+ _s: ' ',
62
+ };
63
+ /**
64
+ * Checks if a character code represents a control character (0x00-0x1F).
65
+ * Control characters are non-printable ASCII characters that need special encoding.
66
+ */
67
+ const isControl = (code) => code >= 0x00 && code <= 0x1f;
68
+ /**
69
+ * Converts a character code to a 2-digit uppercase hexadecimal string.
70
+ * Used to encode control characters as _XX format (e.g., 0x0A becomes "0A").
71
+ */
72
+ const toHex2Upper = (code) => code.toString(16).toUpperCase().padStart(2, '0');
73
+ /**
74
+ * Checks if a character is a valid hexadecimal digit (0-9, A-F, a-f).
75
+ * Used during decoding to identify hex-encoded control characters (e.g., _0A, _1F).
76
+ */
77
+ const isHexDigit = (c) => (c >= '0' && c <= '9') ||
78
+ (c >= 'A' && c <= 'F') ||
79
+ (c >= 'a' && c <= 'f');
80
+ /**
81
+ * Encodes a string into a DepID format.
82
+ * Handles special characters, control characters, and trailing dots.
83
+ */
84
+ const encode = (s) => {
85
+ if (!s)
86
+ return s;
87
+ let out = '';
88
+ // Loop through each character in the string
89
+ for (const ch of s) {
90
+ /* c8 ignore next */
91
+ if (!ch)
92
+ continue;
93
+ // '/' becomes '+', and that '+' is NOT escaped
94
+ if (ch === '/') {
95
+ out += '+';
96
+ continue;
97
+ }
98
+ // Escape special characters with predefined mappings
99
+ const mapped = ESCAPE[ch];
100
+ if (mapped) {
101
+ // Found a special character that needs escaping, append the escaped version
102
+ out += mapped;
103
+ continue;
104
+ }
105
+ // Check if the character is a control character and encode it as _XX
106
+ const code = ch.charCodeAt(0);
107
+ if (isControl(code)) {
108
+ // Found a control character, encode it as _XX
109
+ out += '_' + toHex2Upper(code); // _00, _0A, _1F, etc.
110
+ continue;
111
+ }
112
+ // If no special characters or control characters were found, append the character as-is
113
+ out += ch;
114
+ }
115
+ // Escape trailing dot (Windows strips these)
116
+ if (out.endsWith('.'))
117
+ out = out.slice(0, -1) + '_d';
118
+ return out;
119
+ };
120
+ /**
121
+ * Decodes a DepID string back into its original form.
122
+ * Handles special characters, control characters, and trailing dots.
123
+ */
124
+ const decode = (s) => {
125
+ if (!s)
126
+ return s;
127
+ let out = '';
128
+ // Loop through each character in the string
129
+ for (let i = 0; i < s.length; i++) {
130
+ const ch = s[i];
131
+ /* c8 ignore next */
132
+ if (!ch)
133
+ continue;
134
+ if (ch === '+') {
135
+ out += '/';
136
+ continue;
137
+ }
138
+ if (ch !== '_') {
139
+ out += ch;
140
+ continue;
141
+ }
142
+ // Try to parse an escape sequence starting at '_'
143
+ const next = s[i + 1];
144
+ if (next === undefined) {
145
+ out += '_';
146
+ continue;
147
+ }
148
+ // "__" -> "_"
149
+ if (next === '_') {
150
+ out += '_';
151
+ i += 1;
152
+ continue;
153
+ }
154
+ // "_X" single-letter escapes
155
+ const two = s.slice(i, i + 2); // "_p", "_d", etc.
156
+ const mapped = UNESCAPE[two];
157
+ if (mapped) {
158
+ out += mapped;
159
+ i += 1;
160
+ continue;
161
+ }
162
+ // "_XX" hex escape for control chars, where first hex digit is 0 or 1
163
+ const h1 = s[i + 1];
164
+ const h2 = s[i + 2];
165
+ if ((h1 === '0' || h1 === '1') &&
166
+ h2 !== undefined &&
167
+ isHexDigit(h2)) {
168
+ const hex = s.slice(i + 1, i + 3); // "0A", "1F", etc.
169
+ out += String.fromCharCode(parseInt(hex, 16));
170
+ i += 2;
171
+ continue;
172
+ }
173
+ // Not a recognized escape; leave '_' as-is
174
+ out += '_';
175
+ }
176
+ return out;
177
+ };
41
178
  const seenSplitDepIDs = new Map();
42
179
  /**
43
180
  * turn a {@link DepID} into a {@link DepIDTuple}
@@ -48,20 +185,19 @@ export const splitDepID = (id) => {
48
185
  if (seen)
49
186
  return seen;
50
187
  let res;
51
- const [type, first = '', second, extra] = id
52
- .replaceAll('§', '/')
53
- .split(delimiter, 4);
54
- const f = decodeURIComponent(first);
188
+ const [type, first = '', second, extra] = id.split(delimiter, 4);
189
+ const f = decode(first) || ''; // decode handles + -> / internally
55
190
  switch (type) {
56
191
  case 'git':
57
192
  case '': {
58
193
  if (second === undefined) {
59
194
  throw error(`invalid ${type} id`, { found: id });
60
195
  }
196
+ const decodedSecond = decode(second) || '';
61
197
  res = [
62
198
  type || 'registry',
63
- f,
64
- decodeURIComponent(second),
199
+ f || defaultRegistryName,
200
+ decodedSecond,
65
201
  decode(extra),
66
202
  ];
67
203
  break;
@@ -117,7 +253,7 @@ const seenHydratedTuples = new Map();
117
253
  export const hydrateTuple = (tuple, name, options = {}) => {
118
254
  const [type, first, second] = tuple;
119
255
  // memoized entries return early
120
- const cacheKey = (name ?? '') + type + first + (second ?? '');
256
+ const cacheKey = (name ?? '') + ',' + type + ',' + first + ',' + (second ?? '');
121
257
  const seen = seenHydratedTuples.get(cacheKey);
122
258
  if (seen)
123
259
  return seen;
@@ -151,33 +287,43 @@ export const hydrateTuple = (tuple, name, options = {}) => {
151
287
  found: tuple,
152
288
  });
153
289
  }
154
- if (!first) {
155
- // just a normal name@version on the default registry
156
- const s = Spec.parseArgs(second, options);
157
- if (name && s.name !== name) {
158
- res = Spec.parse(name, `npm:${second}`, options);
159
- }
160
- else {
161
- res = s;
162
- }
290
+ const defaultName = options.registry &&
291
+ currentDefaultRegistryName(options.registry, options);
292
+ const defaultRegistryURL = options.registry ?
293
+ options.registry.endsWith('/') ?
294
+ options.registry
295
+ : options.registry + '/'
296
+ : undefined;
297
+ const firstURL = first.endsWith('/') ? first : first + '/';
298
+ const hasScope = second.startsWith('@');
299
+ const hasAtVersion = second.includes('@', hasScope ? 1 : 0);
300
+ const name_ = (hasAtVersion && hasScope ?
301
+ `@${second.split('@')[1]}`
302
+ : second.split('@')[0]) /* c8 ignore next */ || '(unknown)';
303
+ const usesDefaultRegistry = !first ||
304
+ first === defaultName ||
305
+ firstURL === defaultRegistryURL;
306
+ const noAliasedNameUsed = !name || name === name_;
307
+ if (usesDefaultRegistry && noAliasedNameUsed) {
308
+ const version = (hasAtVersion &&
309
+ second.split('@')[hasScope ? 2 : 1]) /* c8 ignore next */ ||
310
+ second;
311
+ res = Spec.parse(name || name_, version, options);
163
312
  break;
164
313
  }
165
314
  if (!/^https?:\/\//.test(first)) {
166
315
  const reg = options.registries?.[first];
167
- if (first !== 'npm' && !reg) {
316
+ const jsrReg = options['jsr-registries']?.[first];
317
+ if (first !== defaultRegistryName && !reg && !jsrReg) {
168
318
  throw error('named registry not found in options', {
169
319
  name: first,
170
320
  found: tuple,
171
321
  });
172
322
  }
173
- res = Spec.parse(name ?? '(unknown)', `${first}:${second}`, options);
323
+ res = Spec.parse(name || name_, `${first}:${second}`, options);
174
324
  break;
175
325
  }
176
- const s = Spec.parse(name ?? '(unknown)', `registry:${first}#${second}`, options);
177
- res =
178
- name && s.final.name !== name ?
179
- Spec.parse(s.final.name, s.bareSpec, options)
180
- : s;
326
+ res = Spec.parse(name || name_, `registry:${first}#${second}`, options);
181
327
  break;
182
328
  }
183
329
  case 'git': {
@@ -203,12 +349,32 @@ export const hydrateTuple = (tuple, name, options = {}) => {
203
349
  seenHydratedTuples.set(cacheKey, res);
204
350
  return res;
205
351
  };
206
- // Strip out the default registry, there's no need to store that
207
- const omitDefReg = (s) => (!s ||
208
- s === 'https://registry.npmjs.org' ||
209
- s === 'https://registry.npmjs.org/') ?
210
- ''
211
- : s;
352
+ const matchRegistryURL = (registry, registries) => {
353
+ // iterate on known registries to check if any known value
354
+ // matches the current default registry of this Spec value
355
+ for (const [alias, url] of Object.entries(registries)) {
356
+ // normalize trailing slash for comparison
357
+ const specRegURL = registry.endsWith('/') ? registry : registry + '/';
358
+ const knownRegURL = url.endsWith('/') ? url : url + '/';
359
+ if (specRegURL === knownRegURL) {
360
+ return alias;
361
+ }
362
+ }
363
+ };
364
+ /**
365
+ * Convert a Spec's registry URL to a known short registry name, if possible.
366
+ */
367
+ const convertToKnownShortRegistryName = (s, registry) => {
368
+ if (!s.registry)
369
+ return;
370
+ const reg = registry ?? s.registry;
371
+ const namedRegistry = matchRegistryURL(reg, s.options.registries);
372
+ if (namedRegistry)
373
+ return namedRegistry;
374
+ const namedJSRRegistry = matchRegistryURL(reg, s.options['jsr-registries']);
375
+ if (namedJSRRegistry)
376
+ return namedJSRRegistry;
377
+ };
212
378
  const seenTuples = new Map();
213
379
  /**
214
380
  * Get the {@link DepIDTuple} for a given {@link Spec} and {@link Manifest}.
@@ -219,6 +385,7 @@ const seenTuples = new Map();
219
385
  export const getTuple = (spec, mani, extra) => {
220
386
  // memoized entries return early
221
387
  const cacheKey = String(spec) +
388
+ (spec.registry ?? '') +
222
389
  (mani.name ?? '') +
223
390
  (mani.version ?? '') +
224
391
  (extra ?? '');
@@ -229,16 +396,6 @@ export const getTuple = (spec, mani, extra) => {
229
396
  const f = spec.final;
230
397
  switch (f.type) {
231
398
  case 'registry': {
232
- // try to shorten to a known name if we can.
233
- const reg = omitDefReg(f.registry);
234
- if (!f.namedRegistry && reg) {
235
- for (const [alias, host] of Object.entries(spec.options.registries)) {
236
- if (reg === host) {
237
- f.namedRegistry = alias;
238
- break;
239
- }
240
- }
241
- }
242
399
  const version = mani.version ?
243
400
  mani.version.startsWith('v') ?
244
401
  mani.version.slice(1)
@@ -246,7 +403,11 @@ export const getTuple = (spec, mani, extra) => {
246
403
  : f.bareSpec;
247
404
  res = [
248
405
  f.type,
249
- f.namedRegistry ?? reg,
406
+ f.namedRegistry ||
407
+ convertToKnownShortRegistryName(f, f.scopeRegistry) ||
408
+ f.scopeRegistry ||
409
+ f.registry ||
410
+ defaultRegistryName,
250
411
  `${isPackageNameConfused(spec, mani.name) ? spec.name : (mani.name ?? f.name)}@${version}`,
251
412
  extra,
252
413
  ];
@@ -304,6 +465,39 @@ export const isPackageNameConfused = (spec, name) => !!spec?.name && // a namele
304
465
  * specifier, so at least there's something to use later.
305
466
  */
306
467
  export const getId = (spec, mani, extra) => joinDepIDTuple(getTuple(spec, mani, extra));
468
+ /**
469
+ * Join a modifier and a peer set hash into a single "extra" string.
470
+ */
471
+ export function joinExtra({ modifier, peerSetHash, }) {
472
+ if (!modifier && !peerSetHash)
473
+ return;
474
+ if (modifier && peerSetHash)
475
+ return `${modifier}${peerSetHash}`;
476
+ if (modifier)
477
+ return modifier;
478
+ return peerSetHash;
479
+ }
480
+ /**
481
+ * Split an "extra" string into a modifier and a peerSetHash.
482
+ */
483
+ export function splitExtra(extra) {
484
+ if (!extra)
485
+ return {};
486
+ // only peerSetHash is present, return it
487
+ if (extra.startsWith(EXTRA_PEER_SET_DELIMITER)) {
488
+ return { peerSetHash: extra };
489
+ }
490
+ // only modifier is present, return its value
491
+ const idx = extra.indexOf(EXTRA_PEER_SET_DELIMITER);
492
+ if (idx === -1) {
493
+ return { modifier: extra };
494
+ }
495
+ // Both modifier and peerSetHash are present
496
+ return {
497
+ modifier: extra.slice(0, idx),
498
+ peerSetHash: extra.slice(idx),
499
+ };
500
+ }
307
501
  /**
308
502
  * Reset internal caches. This should be used when options change since
309
503
  * they're not take into account in the memoization keys.
@@ -314,4 +508,3 @@ export const resetCaches = () => {
314
508
  seenSplitDepIDs.clear();
315
509
  seenTuples.clear();
316
510
  };
317
- //# sourceMappingURL=browser.js.map
@@ -17,4 +17,3 @@ export declare const hydrateTuple: (tuple: DepIDTuple, name?: string, options?:
17
17
  * they're not take into account in the memoization keys.
18
18
  */
19
19
  export declare const resetCaches: () => void;
20
- //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,5 @@
1
1
  import { error } from '@vltpkg/error-cause';
2
- import { Spec } from '@vltpkg/spec';
2
+ import { currentDefaultRegistryName, defaultRegistryName, Spec, } from '@vltpkg/spec';
3
3
  import { resetCaches as browserResetCaches, splitDepID, } from "./browser.js";
4
4
  // Here we re-export the browser-specific parts of the implementation
5
5
  // we disable the eslint rules for import/export since we are intentionally
@@ -33,7 +33,7 @@ const seenHydratedTuples = new Map();
33
33
  export const hydrateTuple = (tuple, name, options = {}) => {
34
34
  const [type, first, second] = tuple;
35
35
  // memoized entries return early
36
- const cacheKey = (name ?? '') + type + first + (second ?? '');
36
+ const cacheKey = (name ?? '') + ',' + type + ',' + first + ',' + (second ?? '');
37
37
  const seen = seenHydratedTuples.get(cacheKey);
38
38
  if (seen)
39
39
  return seen;
@@ -44,7 +44,7 @@ export const hydrateTuple = (tuple, name, options = {}) => {
44
44
  throw error('no remoteURL found on remote id', {
45
45
  found: tuple,
46
46
  });
47
- res = Spec.parse(name ?? '(unknown)', first);
47
+ res = Spec.parse(name ?? '(unknown)', first, options);
48
48
  break;
49
49
  }
50
50
  case 'file': {
@@ -67,33 +67,43 @@ export const hydrateTuple = (tuple, name, options = {}) => {
67
67
  found: tuple,
68
68
  });
69
69
  }
70
- if (!first) {
71
- // just a normal name@version on the default registry
72
- const s = Spec.parse(second);
73
- if (name && s.name !== name) {
74
- res = Spec.parse(`${name}@npm:${second}`);
75
- }
76
- else {
77
- res = s;
78
- }
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);
79
92
  break;
80
93
  }
81
94
  if (!/^https?:\/\//.test(first)) {
82
95
  const reg = options.registries?.[first];
83
- if (first !== 'npm' && !reg) {
96
+ const jsrReg = options['jsr-registries']?.[first];
97
+ if (first !== defaultRegistryName && !reg && !jsrReg) {
84
98
  throw error('named registry not found in options', {
85
99
  name: first,
86
100
  found: tuple,
87
101
  });
88
102
  }
89
- res = Spec.parse(name ?? '(unknown)', `${first}:${second}`, options);
103
+ res = Spec.parse(name || name_, `${first}:${second}`, options);
90
104
  break;
91
105
  }
92
- const s = Spec.parse(name ?? '(unknown)', `registry:${first}#${second}`, options);
93
- res =
94
- name && s.final.name !== name ?
95
- Spec.parse(s.final.name + '@' + s.bareSpec)
96
- : s;
106
+ res = Spec.parse(name || name_, `registry:${first}#${second}`, options);
97
107
  break;
98
108
  }
99
109
  case 'git': {
@@ -129,4 +139,3 @@ export const resetCaches = () => {
129
139
  seenHydratedTuples.clear();
130
140
  browserResetCaches();
131
141
  };
132
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,78 +1,67 @@
1
1
  {
2
2
  "name": "@vltpkg/dep-id",
3
3
  "description": "create and hydrate dependency IDs",
4
- "version": "1.0.0-rc.3",
4
+ "version": "1.0.0-rc.31",
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)",
11
- "tshy": {
12
- "selfLink": false,
13
- "liveDev": true,
14
- "dialects": [
15
- "esm"
16
- ],
17
- "exports": {
18
- "./package.json": "./package.json",
19
- ".": "./src/index.ts",
20
- "./browser": "./src/browser.ts"
21
- }
10
+ "author": {
11
+ "name": "vlt technology inc.",
12
+ "email": "support@vlt.sh",
13
+ "url": "http://vlt.sh"
22
14
  },
23
15
  "dependencies": {
24
- "@vltpkg/error-cause": "1.0.0-rc.3",
25
- "@vltpkg/spec": "1.0.0-rc.3",
26
- "@vltpkg/types": "1.0.0-rc.3"
16
+ "@vltpkg/error-cause": "1.0.0-rc.31",
17
+ "@vltpkg/spec": "1.0.0-rc.31",
18
+ "@vltpkg/types": "1.0.0-rc.31"
27
19
  },
28
20
  "devDependencies": {
29
- "@eslint/js": "^9.34.0",
30
- "@types/node": "^22.17.2",
31
- "eslint": "^9.34.0",
32
- "prettier": "^3.6.2",
33
- "tap": "^21.1.0",
34
- "tshy": "^3.0.2",
21
+ "@eslint/js": "^9.39.1",
22
+ "@types/node": "^22.19.2",
23
+ "eslint": "^9.39.1",
24
+ "prettier": "^3.7.4",
25
+ "tap": "^21.5.0",
35
26
  "typedoc": "~0.27.9",
36
27
  "typescript": "5.7.3",
37
- "typescript-eslint": "^8.40.0"
28
+ "typescript-eslint": "^8.49.0"
38
29
  },
39
30
  "license": "BSD-2-Clause-Patent",
40
31
  "engines": {
41
- "node": ">=22"
32
+ "node": ">=22.22.0"
33
+ },
34
+ "scripts": {
35
+ "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
36
+ "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
37
+ "lint": "eslint . --fix",
38
+ "lint:check": "eslint .",
39
+ "prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
40
+ "snap": "tap",
41
+ "test": "tap",
42
+ "posttest": "tsc --noEmit",
43
+ "typecheck": "tsc --noEmit"
42
44
  },
43
45
  "tap": {
44
46
  "extends": "../../tap-config.yaml"
45
47
  },
46
48
  "prettier": "../../.prettierrc.js",
47
- "module": "./dist/esm/index.js",
49
+ "module": "./dist/index.js",
48
50
  "type": "module",
49
51
  "exports": {
50
52
  "./package.json": "./package.json",
51
53
  ".": {
52
54
  "import": {
53
- "types": "./dist/esm/index.d.ts",
54
- "default": "./dist/esm/index.js"
55
+ "default": "./dist/index.js"
55
56
  }
56
57
  },
57
58
  "./browser": {
58
59
  "import": {
59
- "types": "./dist/esm/browser.d.ts",
60
- "default": "./dist/esm/browser.js"
60
+ "default": "./dist/browser.js"
61
61
  }
62
62
  }
63
63
  },
64
64
  "files": [
65
65
  "dist"
66
- ],
67
- "scripts": {
68
- "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
69
- "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
70
- "lint": "eslint . --fix",
71
- "lint:check": "eslint .",
72
- "snap": "tap",
73
- "test": "tap",
74
- "posttest": "tsc --noEmit",
75
- "tshy": "tshy",
76
- "typecheck": "tsc --noEmit"
77
- }
78
- }
66
+ ]
67
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAA;AAC3C,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;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,MAAM,KAAK,GACb,GAAG,EAAE,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GAC9E,GAAG,EAAE,GAAG,KAAK,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GACzD,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,EAAE,GAC9E,GAAG,MAAM,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,EAAE,CAAA;AAE7D;;GAEG;A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C,CAAA;IAC7B,OAAO,GAAG,CAAA;AACZ,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,IAAW,EAAE,IAAa,EAAE,EAAE,CAClE,CAAC,CAAC,IAAI,EAAE,IAAI,IAAI,mCAAmC;IACnD,CAAC,IAAI,CAAC,OAAO,IAAI,yDAAyD;IAC1E,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,uCAAuC;IACnE,IAAI,CAAC,IAAI,KAAK,IAAI,CAAA,CAAC,oDAAoD;AAEzE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,IAAU,EACV,IAAwC,EACxC,KAAc,EACP,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAA;AAEvD;;;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 { Spec } 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 = '·'\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) =>\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,\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) => {\n const [type, first, second] = tuple\n\n // memoized entries return early\n const cacheKey = (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 if (!first) {\n // just a normal name@version on the default registry\n const s = Spec.parseArgs(second, options)\n if (name && s.name !== name) {\n res = Spec.parse(name, `npm:${second}`, options)\n } else {\n res = s\n }\n break\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 res = Spec.parse(\n name ?? '(unknown)',\n `${first}:${second}`,\n options,\n )\n break\n }\n const s = Spec.parse(\n name ?? '(unknown)',\n `registry:${first}#${second}`,\n options,\n )\n res =\n name && s.final.name !== name ?\n Spec.parse(s.final.name, s.bareSpec, options)\n : s\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// 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\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 (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 // 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 res = [\n f.type,\n f.namedRegistry ?? reg,\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 * 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"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAKnC,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,I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BAAyB,EAAE;oBACrC,KAAK,EAAE,KAAK;iBACb,CAAC,CAAA;YACJ,CAAC;YACD,GAAG,GAAG,IAAI,CAAC,KAAK,CACd,IAAI,IAAI,WAAW,EACnB,KAAK,GAAG,GAAG,GAAG,MAAM,EACpB,OAAO,CACR,CAAA;YACD,MAAK;QACP,CAAC;QACD,KAAK,WAAW,CAAC,CAAC,CAAC;YACjB,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,KAAK,CAAC,8BAA8B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAA;YAC/D,CAAC;YACD,GAAG;gBACD,IAAI,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC;oBACtB,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,EAAE,OAAO,CAAC;oBACnD,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,aAAa,EAAE,OAAO,CAAC,CAAA;YAC7C,MAAK;QACP,CAAC;IACH,CAAC;IACD,kBAAkB,CAAC,GAAG,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAA;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 { Spec } 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 = (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)\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 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 res = Spec.parse(`${name}@npm:${second}`)\n } else {\n res = s\n }\n break\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 res = Spec.parse(\n name ?? '(unknown)',\n `${first}:${second}`,\n options,\n )\n break\n }\n const s = Spec.parse(\n name ?? '(unknown)',\n `registry:${first}#${second}`,\n options,\n )\n res =\n name && s.final.name !== name ?\n Spec.parse(s.final.name + '@' + s.bareSpec)\n : s\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"]}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }