@vltpkg/spec 1.4.0 → 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.
Files changed (2) hide show
  1. package/dist/browser.js +39 -13
  2. package/package.json +3 -3
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,
@@ -320,22 +321,28 @@ export class Spec {
320
321
  }
321
322
  if (this.bareSpec.startsWith('catalog:')) {
322
323
  this.catalog = this.bareSpec.substring('catalog:'.length);
324
+ const { catalog: defaultCatalog, catalogs = {} } = this.options;
323
325
  const catalog = this.catalog ?
324
- this.options.catalogs?.[this.catalog]
325
- : this.options.catalog;
326
+ Object.hasOwn(catalogs, this.catalog) ?
327
+ catalogs[this.catalog]
328
+ : undefined
329
+ : Object.keys(defaultCatalog).length ? defaultCatalog
330
+ : undefined;
326
331
  if (!catalog) {
327
- throw this.#error('Named catalog not found', {
328
- name: this.catalog,
329
- validOptions: this.options.catalogs &&
330
- Object.keys(this.options.catalogs),
331
- });
332
+ throw this.#catalogError(this.catalog ?
333
+ `Catalog "${this.catalog}" not found for ${this.spec}`
334
+ : `Default catalog not found for ${this.spec}`);
332
335
  }
333
- 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;
334
340
  if (!sub) {
335
- throw this.#error('Name not found in catalog', {
336
- name: this.name,
337
- validOptions: Object.keys(catalog),
338
- });
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 });
339
346
  }
340
347
  this.subspec = Spec.parse(this.name, sub, this.options);
341
348
  this.type = 'catalog';
@@ -684,6 +691,25 @@ export class Spec {
684
691
  ].map(p => `${p}:`),
685
692
  });
686
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
+ }
687
713
  #error(message, extra = {}) {
688
714
  return error(message, { spec: this.spec, ...extra }, this.#error);
689
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.4.0",
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.4.0",
17
- "@vltpkg/semver": "1.4.0"
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",