@vltpkg/dep-id 0.0.0-20 → 0.0.0-22

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.
@@ -103,7 +103,7 @@ export const hydrateTuple = (tuple, name, options = {}) => {
103
103
  throw error('no remoteURL found on remote id', {
104
104
  found: tuple,
105
105
  });
106
- return Spec.parse(name ?? '(unknown)', first);
106
+ return Spec.parse(name ?? '(unknown)', first, options);
107
107
  }
108
108
  case 'file': {
109
109
  if (!first) {
@@ -126,9 +126,9 @@ export const hydrateTuple = (tuple, name, options = {}) => {
126
126
  }
127
127
  if (!first) {
128
128
  // just a normal name@version on the default registry
129
- const s = Spec.parse(second);
129
+ const s = Spec.parseArgs(second, options);
130
130
  if (name && s.name !== name) {
131
- return Spec.parse(`${name}@npm:${second}`);
131
+ return Spec.parse(name, `npm:${second}`, options);
132
132
  }
133
133
  else {
134
134
  return s;
@@ -146,7 +146,7 @@ export const hydrateTuple = (tuple, name, options = {}) => {
146
146
  }
147
147
  const s = Spec.parse(name ?? '(unknown)', `registry:${first}#${second}`, options);
148
148
  return name && s.final.name !== name ?
149
- Spec.parse(s.final.name + '@' + s.bareSpec)
149
+ Spec.parse(s.final.name, s.bareSpec, options)
150
150
  : s;
151
151
  }
152
152
  case 'git': {
@@ -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;AAI3C,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,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AAK,CAAC,CAAA;QACnC,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;;;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","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\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 decode(extra),\n ]\n return t\n }\n case 'file':\n case 'remote':\n case 'workspace': {\n const t: DepIDTuple = [type, f, decode(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 * 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\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 = (\n spec: Spec,\n mani: Pick<Manifest, 'name' | 'version'>,\n extra?: string,\n): 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 `${isPackageNameConfused(spec, mani.name) ? spec.name : (mani.name ?? f.name)}@${version}`,\n extra,\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 extra,\n ]\n } else {\n return [f.type, gitRemote, gitSelector, extra]\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, extra]\n }\n case 'file':\n case 'workspace':\n throw error('Path-based dep ids are not supported', { spec })\n }\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"]}
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,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CAAC,IAAI,EAAE,SAAS,EAAE,WAAW,EAAE,KAAK,CAAC,CAAA;YAChD,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,EAAE,KAAK,CAAC,CAAA;QACnC,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;;;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","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\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 decode(extra),\n ]\n return t\n }\n case 'file':\n case 'remote':\n case 'workspace': {\n const t: DepIDTuple = [type, f, decode(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 * 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\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, options)\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.parseArgs(second, options)\n if (name && s.name !== name) {\n return Spec.parse(name, `npm:${second}`, options)\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, options)\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 = (\n spec: Spec,\n mani: Pick<Manifest, 'name' | 'version'>,\n extra?: string,\n): 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 `${isPackageNameConfused(spec, mani.name) ? spec.name : (mani.name ?? f.name)}@${version}`,\n extra,\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 extra,\n ]\n } else {\n return [f.type, gitRemote, gitSelector, extra]\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, extra]\n }\n case 'file':\n case 'workspace':\n throw error('Path-based dep ids are not supported', { spec })\n }\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"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@vltpkg/dep-id",
3
3
  "description": "create and hydrate dependency IDs",
4
- "version": "0.0.0-20",
4
+ "version": "0.0.0-22",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
@@ -20,9 +20,9 @@
20
20
  }
21
21
  },
22
22
  "dependencies": {
23
- "@vltpkg/error-cause": "0.0.0-20",
24
- "@vltpkg/spec": "0.0.0-20",
25
- "@vltpkg/types": "0.0.0-20"
23
+ "@vltpkg/spec": "0.0.0-22",
24
+ "@vltpkg/types": "0.0.0-22",
25
+ "@vltpkg/error-cause": "0.0.0-22"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@eslint/js": "^9.28.0",