@vltpkg/dep-id 0.0.0-2 → 0.0.0-21
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 +9 -10
- package/dist/esm/browser.d.ts +25 -0
- package/dist/esm/browser.d.ts.map +1 -1
- package/dist/esm/browser.js +110 -9
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/index.d.ts +6 -69
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +14 -144
- package/dist/esm/index.js.map +1 -1
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
# @vltpkg/dep-id
|
|
4
4
|
|
|
5
|
-
A library for serializing dependencies into terse string identifiers,
|
|
5
|
+
A library for serializing dependencies into terse string identifiers,
|
|
6
|
+
and turning those serialized identifiers back into `Spec` objects.
|
|
6
7
|
|
|
7
|
-
**[Usage](#usage)**
|
|
8
|
-
·
|
|
9
|
-
**[Note](#note)**
|
|
8
|
+
**[Usage](#usage)** · **[Note](#note)**
|
|
10
9
|
|
|
11
10
|
## Usage
|
|
12
11
|
|
|
@@ -50,12 +49,12 @@ const spec = hydrate('git;github:a/b;branch', 'x') // x@github:a/b#branch
|
|
|
50
49
|
|
|
51
50
|
### Note
|
|
52
51
|
|
|
53
|
-
multiple different spec/manifest combinations _can_ result
|
|
54
|
-
|
|
55
|
-
`
|
|
56
|
-
|
|
57
|
-
store once.
|
|
52
|
+
multiple different spec/manifest combinations _can_ result in the same
|
|
53
|
+
identifier. For example, the specifiers `x@npm:y@latest` and
|
|
54
|
+
`asdf@npm:y@1.x` might both ultimately resolve to the same package, so
|
|
55
|
+
they only need to appear in the store once.
|
|
58
56
|
|
|
59
57
|
## BROWSER API
|
|
60
58
|
|
|
61
|
-
An isomorphic API `@vltpkg/dep-id/browser` is provided for use in the
|
|
59
|
+
An isomorphic API `@vltpkg/dep-id/browser` is provided for use in the
|
|
60
|
+
browser.
|
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,23 @@ 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;
|
|
63
88
|
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,WA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H,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"}
|
package/dist/esm/browser.js
CHANGED
|
@@ -29,10 +29,15 @@ export const joinDepIDTuple = (list) => {
|
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
// allow @, but otherwise, escape everything urls do
|
|
32
|
-
const encode = (s) =>
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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;
|
|
36
41
|
/**
|
|
37
42
|
* turn a {@link DepID} into a {@link DepIDTuple}
|
|
38
43
|
*/
|
|
@@ -51,17 +56,14 @@ export const splitDepID = (id) => {
|
|
|
51
56
|
type || 'registry',
|
|
52
57
|
f,
|
|
53
58
|
decodeURIComponent(second),
|
|
59
|
+
decode(extra),
|
|
54
60
|
];
|
|
55
|
-
if (extra)
|
|
56
|
-
t.push(decodeURIComponent(extra));
|
|
57
61
|
return t;
|
|
58
62
|
}
|
|
59
63
|
case 'file':
|
|
60
64
|
case 'remote':
|
|
61
65
|
case 'workspace': {
|
|
62
|
-
const t = [type, f];
|
|
63
|
-
if (second)
|
|
64
|
-
t.push(decodeURIComponent(second));
|
|
66
|
+
const t = [type, f, decode(second)];
|
|
65
67
|
return t;
|
|
66
68
|
}
|
|
67
69
|
default: {
|
|
@@ -72,6 +74,20 @@ export const splitDepID = (id) => {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
};
|
|
77
|
+
/**
|
|
78
|
+
* Retrieves the base {@link DepID} for a given depID,
|
|
79
|
+
* ignoring any extra information that may be present.
|
|
80
|
+
*/
|
|
81
|
+
export const baseDepID = (id) => {
|
|
82
|
+
const [type, first, second] = splitDepID(id);
|
|
83
|
+
switch (type) {
|
|
84
|
+
case 'git':
|
|
85
|
+
case 'registry':
|
|
86
|
+
return joinDepIDTuple([type, first, second]);
|
|
87
|
+
default:
|
|
88
|
+
return joinDepIDTuple([type, first]);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
75
91
|
/**
|
|
76
92
|
* Turn a {@link DepID} into a {@link Spec} object
|
|
77
93
|
*/
|
|
@@ -151,4 +167,89 @@ export const hydrateTuple = (tuple, name, options = {}) => {
|
|
|
151
167
|
}
|
|
152
168
|
}
|
|
153
169
|
};
|
|
170
|
+
// Strip out the default registry, there's no need to store that
|
|
171
|
+
const omitDefReg = (s) => (!s ||
|
|
172
|
+
s === 'https://registry.npmjs.org' ||
|
|
173
|
+
s === 'https://registry.npmjs.org/') ?
|
|
174
|
+
''
|
|
175
|
+
: s;
|
|
176
|
+
/**
|
|
177
|
+
* Get the {@link DepIDTuple} for a given {@link Spec} and {@link Manifest}.
|
|
178
|
+
* The Manifest is used to get the name and version, if possible. If not found
|
|
179
|
+
* in the manifest, registry ID types will use the name or bareSpec from the
|
|
180
|
+
* specifier, so at least there's something to use later.
|
|
181
|
+
*/
|
|
182
|
+
export const getTuple = (spec, mani, extra) => {
|
|
183
|
+
const f = spec.final;
|
|
184
|
+
switch (f.type) {
|
|
185
|
+
case 'registry': {
|
|
186
|
+
// try to shorten to a known name if we can.
|
|
187
|
+
const reg = omitDefReg(f.registry);
|
|
188
|
+
if (!f.namedRegistry && reg) {
|
|
189
|
+
for (const [alias, host] of Object.entries(spec.options.registries)) {
|
|
190
|
+
if (reg === host) {
|
|
191
|
+
f.namedRegistry = alias;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const version = mani.version ?
|
|
197
|
+
mani.version.startsWith('v') ?
|
|
198
|
+
mani.version.slice(1)
|
|
199
|
+
: mani.version
|
|
200
|
+
: f.bareSpec;
|
|
201
|
+
return [
|
|
202
|
+
f.type,
|
|
203
|
+
f.namedRegistry ?? reg,
|
|
204
|
+
`${isPackageNameConfused(spec, mani.name) ? spec.name : (mani.name ?? f.name)}@${version}`,
|
|
205
|
+
extra,
|
|
206
|
+
];
|
|
207
|
+
}
|
|
208
|
+
case 'git': {
|
|
209
|
+
const { namedGitHost, namedGitHostPath, gitRemote, gitSelector = '', } = f;
|
|
210
|
+
if (!gitRemote)
|
|
211
|
+
throw error('no host on git specifier', { spec });
|
|
212
|
+
if (namedGitHost) {
|
|
213
|
+
if (!namedGitHostPath) {
|
|
214
|
+
throw error('named git host without path portion', {
|
|
215
|
+
spec,
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return [
|
|
219
|
+
f.type,
|
|
220
|
+
`${namedGitHost}:${namedGitHostPath}`,
|
|
221
|
+
gitSelector,
|
|
222
|
+
extra,
|
|
223
|
+
];
|
|
224
|
+
}
|
|
225
|
+
else {
|
|
226
|
+
return [f.type, gitRemote, gitSelector, extra];
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
case 'remote': {
|
|
230
|
+
const { remoteURL } = f;
|
|
231
|
+
if (!remoteURL)
|
|
232
|
+
throw error('no URL on remote specifier', { spec });
|
|
233
|
+
return [f.type, remoteURL, extra];
|
|
234
|
+
}
|
|
235
|
+
case 'file':
|
|
236
|
+
case 'workspace':
|
|
237
|
+
throw error('Path-based dep ids are not supported', { spec });
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
/**
|
|
241
|
+
* Checks for a potentially manifest-confused package name.
|
|
242
|
+
* Returns `true` if the package name is confused, `false` otherwise.
|
|
243
|
+
*/
|
|
244
|
+
export const isPackageNameConfused = (spec, name) => !!spec?.name && // a nameless spec can't be checked
|
|
245
|
+
!spec.subspec && // it's not an aliased package or using a custom protocol
|
|
246
|
+
spec.type === 'registry' && // the defined spec is of type registry
|
|
247
|
+
spec.name !== name; // its name is not the same as the defined spec name
|
|
248
|
+
/**
|
|
249
|
+
* Get the {@link DepID} for a given {@link Spec} and {@link Manifest}. The
|
|
250
|
+
* Manifest is used to get the name and version, if possible. If not found in
|
|
251
|
+
* the manifest, registry ID types will use the name or bareSpec from the
|
|
252
|
+
* specifier, so at least there's something to use later.
|
|
253
|
+
*/
|
|
254
|
+
export const getId = (spec, mani, extra) => joinDepIDTuple(getTuple(spec, mani, extra));
|
|
154
255
|
//# 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,C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YACD,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,IAAI,WAAW,EACnB,KAAK,GAAG,GAAG,GAAG,MAAM,EACpB,OAAO,CACR,CAAA;QACH,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,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,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,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;AAC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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"]}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,78 +1,15 @@
|
|
|
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
|
|
11
|
+
* Turn a {@link DepIDTuple} into a {@link Spec} object using
|
|
12
|
+
* the Node.js-specific `Spec.parse` method.
|
|
62
13
|
*/
|
|
63
14
|
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.
|
|
69
|
-
*/
|
|
70
|
-
export declare const getTuple: (spec: Spec, mani: Manifest) => DepIDTuple;
|
|
71
|
-
/**
|
|
72
|
-
* Get the {@link DepID} for a given {@link Spec} and {@link Manifest}. The
|
|
73
|
-
* Manifest is used to get the name and version, if possible. If not found in
|
|
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.
|
|
76
|
-
*/
|
|
77
|
-
export declare const getId: (spec: Spec, mani: Manifest) => DepID;
|
|
78
15
|
//# 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,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAEnC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAQrD,cAAc,cAAc,CAAA;AAE5B;;;GAGG;AAEH,eAAO,MAAM,OAAO,OACd,KAAK,SACF,MAAM,YACJ,WAAW,KACnB,IAAmD,CAAA;AAEtD;;;GAGG;AAEH,eAAO,MAAM,YAAY,UAChB,UAAU,SACV,MAAM,YACJ,WAAW,wCAmFrB,CAAA"}
|
package/dist/esm/index.js
CHANGED
|
@@ -1,84 +1,24 @@
|
|
|
1
1
|
import { error } from '@vltpkg/error-cause';
|
|
2
2
|
import { Spec } from '@vltpkg/spec';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
found: str,
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
return str;
|
|
15
|
-
};
|
|
16
|
-
/**
|
|
17
|
-
* turn a {@link DepIDTuple} into a {@link DepID}
|
|
18
|
-
*/
|
|
19
|
-
export const joinDepIDTuple = (list) => {
|
|
20
|
-
const [type, first, second, extra] = list;
|
|
21
|
-
const f = encode(first);
|
|
22
|
-
switch (type) {
|
|
23
|
-
case 'registry':
|
|
24
|
-
return `${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`;
|
|
25
|
-
case 'git':
|
|
26
|
-
return `${type}${delimiter}${f}${delimiter}${encode(second)}${extra ? `${delimiter}${encode(extra)}` : ''}`;
|
|
27
|
-
default:
|
|
28
|
-
return `${type}${delimiter}${f}${second ? `${delimiter}${encode(second)}` : ''}`;
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
// allow @, but otherwise, escape everything urls do
|
|
32
|
-
const encode = (s) => encodeURIComponent(s)
|
|
33
|
-
.replaceAll('%40', '@')
|
|
34
|
-
.replaceAll('%2f', '§')
|
|
35
|
-
.replaceAll('%2F', '§');
|
|
36
|
-
/**
|
|
37
|
-
* turn a {@link DepID} into a {@link DepIDTuple}
|
|
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
|
-
};
|
|
3
|
+
import { 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";
|
|
75
11
|
/**
|
|
76
|
-
* Turn a {@link DepID} into a {@link Spec} object
|
|
12
|
+
* Turn a {@link DepID} into a {@link Spec} object using
|
|
13
|
+
* the Node.js-specific `Spec.parse` method.
|
|
77
14
|
*/
|
|
15
|
+
// eslint-disable-next-line import/export
|
|
78
16
|
export const hydrate = (id, name, options = {}) => hydrateTuple(splitDepID(id), name, options);
|
|
79
17
|
/**
|
|
80
|
-
* Turn a {@link DepIDTuple} into a {@link Spec} object
|
|
18
|
+
* Turn a {@link DepIDTuple} into a {@link Spec} object using
|
|
19
|
+
* the Node.js-specific `Spec.parse` method.
|
|
81
20
|
*/
|
|
21
|
+
// eslint-disable-next-line import/export
|
|
82
22
|
export const hydrateTuple = (tuple, name, options = {}) => {
|
|
83
23
|
const [type, first, second] = tuple;
|
|
84
24
|
switch (type) {
|
|
@@ -151,74 +91,4 @@ export const hydrateTuple = (tuple, name, options = {}) => {
|
|
|
151
91
|
}
|
|
152
92
|
}
|
|
153
93
|
};
|
|
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
|
-
/**
|
|
161
|
-
* Get the {@link DepIDTuple} for a given {@link Spec} and {@link Manifest}.
|
|
162
|
-
* The Manifest is used to get the name and version, if possible. If not found
|
|
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.
|
|
165
|
-
*/
|
|
166
|
-
export const getTuple = (spec, mani) => {
|
|
167
|
-
const f = spec.final;
|
|
168
|
-
switch (f.type) {
|
|
169
|
-
case 'registry': {
|
|
170
|
-
// try to shorten to a known name if we can.
|
|
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
|
-
return [
|
|
181
|
-
f.type,
|
|
182
|
-
f.namedRegistry ?? reg,
|
|
183
|
-
`${mani.name ?? spec.name}@${mani.version ?? spec.bareSpec}`,
|
|
184
|
-
];
|
|
185
|
-
}
|
|
186
|
-
case 'git': {
|
|
187
|
-
const { namedGitHost, namedGitHostPath, gitRemote, gitSelector = '', } = f;
|
|
188
|
-
if (!gitRemote)
|
|
189
|
-
throw error('no host on git specifier', { spec });
|
|
190
|
-
if (namedGitHost) {
|
|
191
|
-
if (!namedGitHostPath) {
|
|
192
|
-
throw error('named git host without path portion', {
|
|
193
|
-
spec,
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
return [
|
|
197
|
-
f.type,
|
|
198
|
-
`${namedGitHost}:${namedGitHostPath}`,
|
|
199
|
-
gitSelector,
|
|
200
|
-
];
|
|
201
|
-
}
|
|
202
|
-
else {
|
|
203
|
-
return [f.type, gitRemote, gitSelector];
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
case 'remote': {
|
|
207
|
-
const { remoteURL } = f;
|
|
208
|
-
if (!remoteURL)
|
|
209
|
-
throw error('no URL on remote specifier', { spec });
|
|
210
|
-
return [f.type, remoteURL];
|
|
211
|
-
}
|
|
212
|
-
case 'file':
|
|
213
|
-
case 'workspace':
|
|
214
|
-
throw error('Path-based dep ids are not supported', { spec });
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
/**
|
|
218
|
-
* Get the {@link DepID} for a given {@link Spec} and {@link Manifest}. The
|
|
219
|
-
* Manifest is used to get the name and version, if possible. If not found in
|
|
220
|
-
* the manifest, registry ID types will use the name or bareSpec from the
|
|
221
|
-
* specifier, so at least there's something to use later.
|
|
222
|
-
*/
|
|
223
|
-
export const getId = (spec, mani) => joinDepIDTuple(getTuple(spec, mani));
|
|
224
94
|
//# 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,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,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AAE,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 return [\n f.type,\n f.namedRegistry ?? reg,\n `${mani.name ?? spec.name}@${mani.version ?? spec.bareSpec}`,\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,EAAE,IAAI,EAAE,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,CAAC,IAAI,GAAG,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC;gBAC7C,CAAC,CAAC,CAAC,CAAA;QACP,CAAC;QACD,KAAK,KAAK,CAAC,CAAC,CAAC;YACX,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,MAAM,KAAK,CAAC,yBAAyB,EAAE;oBACrC,KAAK,EAAE,KAAK;iBACb,CAAC,CAAA;YACJ,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CACf,IAAI,IAAI,WAAW,EACnB,KAAK,GAAG,GAAG,GAAG,MAAM,EACpB,OAAO,CACR,CAAA;QACH,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,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'\nimport { splitDepID } 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\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 => hydrateTuple(splitDepID(id), name, options)\n\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) => {\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"]}
|
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-
|
|
4
|
+
"version": "0.0.0-21",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
@@ -20,21 +20,20 @@
|
|
|
20
20
|
}
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@vltpkg/
|
|
24
|
-
"@vltpkg/
|
|
25
|
-
"@vltpkg/types": "0.0.0-
|
|
23
|
+
"@vltpkg/spec": "0.0.0-21",
|
|
24
|
+
"@vltpkg/error-cause": "0.0.0-21",
|
|
25
|
+
"@vltpkg/types": "0.0.0-21"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@eslint/js": "^9.
|
|
29
|
-
"@types/
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"prettier": "^3.4.2",
|
|
28
|
+
"@eslint/js": "^9.28.0",
|
|
29
|
+
"@types/node": "^22.15.29",
|
|
30
|
+
"eslint": "^9.28.0",
|
|
31
|
+
"prettier": "^3.6.0",
|
|
33
32
|
"tap": "^21.1.0",
|
|
34
33
|
"tshy": "^3.0.2",
|
|
35
|
-
"typedoc": "0.27.
|
|
34
|
+
"typedoc": "~0.27.9",
|
|
36
35
|
"typescript": "5.7.3",
|
|
37
|
-
"typescript-eslint": "^8.
|
|
36
|
+
"typescript-eslint": "^8.33.1"
|
|
38
37
|
},
|
|
39
38
|
"license": "BSD-2-Clause-Patent",
|
|
40
39
|
"engines": {
|
|
@@ -72,6 +71,7 @@
|
|
|
72
71
|
"snap": "tap",
|
|
73
72
|
"test": "tap",
|
|
74
73
|
"posttest": "tsc --noEmit",
|
|
74
|
+
"tshy": "tshy",
|
|
75
75
|
"typecheck": "tsc --noEmit"
|
|
76
76
|
}
|
|
77
77
|
}
|