@vltpkg/spec 1.3.8 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.d.ts CHANGED
@@ -40,6 +40,8 @@ export declare const defaultScopeRegistries: {
40
40
  '@jsr': string;
41
41
  };
42
42
  export declare const getOptions: (options?: SpecOptions) => SpecOptionsFilled;
43
+ /** Spec prefixes handled natively, not usable as alias names. */
44
+ export declare const builtinProtocols: ReadonlySet<string>;
43
45
  /**
44
46
  * Injects the Node.js dependencies into the Spec class.
45
47
  */
package/dist/browser.js CHANGED
@@ -39,9 +39,10 @@ export const defaultScopeRegistries = {
39
39
  '@jsr': 'https://npm.jsr.io/',
40
40
  };
41
41
  export const getOptions = (options) => ({
42
- catalog: {},
43
42
  catalogs: {},
44
43
  ...options,
44
+ // after spread: explicit `catalog: undefined` gets default too
45
+ catalog: options?.catalog ?? {},
45
46
  // built-in aliases are user/service-overridable: user config wins
46
47
  'jsr-registries': {
47
48
  ...defaultJsrRegistries,
@@ -70,7 +71,8 @@ export const getOptions = (options) => ({
70
71
  // RFC3986 scheme chars minus `.`, min 2 chars. Excludes windows drive
71
72
  // letters (`C:/x`) and hostnames (`notgithub.com:user/repo`).
72
73
  const protocolRE = /^([a-zA-Z][a-zA-Z0-9+-]+):/;
73
- const builtinProtocols = new Set([
74
+ /** Spec prefixes handled natively, not usable as alias names. */
75
+ export const builtinProtocols = new Set([
74
76
  'catalog',
75
77
  'workspace',
76
78
  'registry',
@@ -319,22 +321,28 @@ export class Spec {
319
321
  }
320
322
  if (this.bareSpec.startsWith('catalog:')) {
321
323
  this.catalog = this.bareSpec.substring('catalog:'.length);
324
+ const { catalog: defaultCatalog, catalogs = {} } = this.options;
322
325
  const catalog = this.catalog ?
323
- this.options.catalogs?.[this.catalog]
324
- : this.options.catalog;
326
+ Object.hasOwn(catalogs, this.catalog) ?
327
+ catalogs[this.catalog]
328
+ : undefined
329
+ : Object.keys(defaultCatalog).length ? defaultCatalog
330
+ : undefined;
325
331
  if (!catalog) {
326
- throw this.#error('Named catalog not found', {
327
- name: this.catalog,
328
- validOptions: this.options.catalogs &&
329
- Object.keys(this.options.catalogs),
330
- });
332
+ throw this.#catalogError(this.catalog ?
333
+ `Catalog "${this.catalog}" not found for ${this.spec}`
334
+ : `Default catalog not found for ${this.spec}`);
331
335
  }
332
- const sub = catalog[this.name];
336
+ const catalogName = this.catalog ? `catalog "${this.catalog}"` : 'default catalog';
337
+ const sub = Object.hasOwn(catalog, this.name) ?
338
+ catalog[this.name]
339
+ : undefined;
333
340
  if (!sub) {
334
- throw this.#error('Name not found in catalog', {
335
- name: this.name,
336
- validOptions: Object.keys(catalog),
337
- });
341
+ throw this.#catalogError(`Package "${this.name}" not found in ${catalogName}`);
342
+ }
343
+ // would recurse or resolve against another catalog
344
+ if (sub.startsWith('catalog:')) {
345
+ throw this.#error(`Catalog entry "${this.name}" in ${catalogName} cannot be a catalog: spec`, { code: 'ECONFIG', found: sub });
338
346
  }
339
347
  this.subspec = Spec.parse(this.name, sub, this.options);
340
348
  this.type = 'catalog';
@@ -683,6 +691,25 @@ export class Spec {
683
691
  ].map(p => `${p}:`),
684
692
  });
685
693
  }
694
+ /** ECONFIG error listing defined catalogs & ones defining this dep */
695
+ #catalogError(message) {
696
+ const { catalog, catalogs = {} } = this.options;
697
+ const defined = [
698
+ ...(Object.keys(catalog).length ?
699
+ [['', catalog]]
700
+ : []),
701
+ ...Object.entries(catalogs),
702
+ ];
703
+ const validOptions = defined.map(([n]) => `catalog:${n}`);
704
+ const wanted = defined
705
+ .filter(([, c]) => Object.hasOwn(c, this.name) && !!c[this.name])
706
+ .map(([n]) => `catalog:${n}`);
707
+ return this.#error(message, {
708
+ code: 'ECONFIG',
709
+ ...(validOptions.length ? { validOptions } : {}),
710
+ ...(wanted.length ? { wanted } : {}),
711
+ });
712
+ }
686
713
  #error(message, extra = {}) {
687
714
  return error(message, { spec: this.spec, ...extra }, this.#error);
688
715
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/spec",
3
3
  "description": "Package specifier library",
4
- "version": "1.3.8",
4
+ "version": "1.5.0",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -13,8 +13,8 @@
13
13
  "url": "http://vlt.sh"
14
14
  },
15
15
  "dependencies": {
16
- "@vltpkg/error-cause": "1.3.8",
17
- "@vltpkg/semver": "1.3.8"
16
+ "@vltpkg/error-cause": "1.5.0",
17
+ "@vltpkg/semver": "1.5.0"
18
18
  },
19
19
  "devDependencies": {
20
20
  "@eslint/js": "^9.39.1",