@vltpkg/satisfies 0.0.0-0.1730239248325
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/LICENSE +15 -0
- package/README.md +17 -0
- package/dist/esm/index.d.ts +10 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +116 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/package.json +65 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
Copyright (c) vlt technology, Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
|
4
|
+
|
|
5
|
+
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
|
6
|
+
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
|
7
|
+
Subject to the terms and conditions of this license, each copyright holder and contributor hereby grants to those receiving rights under this license a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except for failure to satisfy the conditions of this license) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer this software, where such license applies only to those patent claims, already acquired or hereafter acquired, licensable by such copyright holder or contributor that are necessarily infringed by:
|
|
8
|
+
|
|
9
|
+
(a) their Contribution(s) (the licensed copyrights of copyright holders and non-copyrightable additions of contributors, in source or binary form) alone; or
|
|
10
|
+
(b) combination of their Contribution(s) with the work of authorship to which such Contribution(s) was added by such copyright holder or contributor, if, at the time the Contribution is added, such addition causes such combination to be necessarily infringed. The patent license shall not apply to any other combinations which include the Contribution.
|
|
11
|
+
Except as expressly stated above, no rights or licenses from any copyright holder or contributor is granted under this license, whether expressly, by implication, estoppel or otherwise.
|
|
12
|
+
|
|
13
|
+
DISCLAIMER
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# `@vltpkg/satisfies`
|
|
2
|
+
|
|
3
|
+
Give it a DepID and a Spec, and it'll tell you whether that dep
|
|
4
|
+
satisfies the spec.
|
|
5
|
+
|
|
6
|
+
Note that this method knows nothing about Nodes, Edges, or
|
|
7
|
+
dependency types, it's just doing simple string comparisons.
|
|
8
|
+
|
|
9
|
+
## USAGE
|
|
10
|
+
|
|
11
|
+
```js
|
|
12
|
+
import { Spec } from '@vltpkg/spec'
|
|
13
|
+
import { satisfies } from '@vltpkg/satisfies'
|
|
14
|
+
const id = ';;glob@11.0.1'
|
|
15
|
+
const spec = Spec.parse('foo@npm:glob@11.x')
|
|
16
|
+
console.log(satisfies(id, spec)) // true
|
|
17
|
+
```
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { DepID, DepIDTuple } from '@vltpkg/dep-id';
|
|
2
|
+
import { Spec } from '@vltpkg/spec';
|
|
3
|
+
import { Monorepo } from '@vltpkg/workspaces';
|
|
4
|
+
/**
|
|
5
|
+
* Return true if the node referenced by this DepID would satisfy the
|
|
6
|
+
* supplied Spec object.
|
|
7
|
+
*/
|
|
8
|
+
export declare const satisfies: (id: DepID | undefined, spec: Spec, fromLocation?: string, projectRoot?: string, monorepo?: Monorepo) => boolean;
|
|
9
|
+
export declare const satisfiesTuple: (tuple: DepIDTuple, spec: Spec, fromLocation?: string, projectRoot?: string, monorepo?: Monorepo) => boolean;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAc,MAAM,gBAAgB,CAAA;AAG9D,OAAO,EAAqB,IAAI,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAG7C;;;GAGG;AACH,eAAO,MAAM,SAAS,OAChB,KAAK,GAAG,SAAS,QACf,IAAI,0DAGC,QAAQ,KAClB,OAQA,CAAA;AAEH,eAAO,MAAM,cAAc,UAClB,UAAU,QACX,IAAI,0DAGC,QAAQ,KAClB,OAkGF,CAAA"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { splitDepID } from '@vltpkg/dep-id';
|
|
2
|
+
import { error } from '@vltpkg/error-cause';
|
|
3
|
+
import { parse, Version } from '@vltpkg/semver';
|
|
4
|
+
import { Spec } from '@vltpkg/spec';
|
|
5
|
+
import { Monorepo } from '@vltpkg/workspaces';
|
|
6
|
+
import { relative, resolve } from 'path';
|
|
7
|
+
/**
|
|
8
|
+
* Return true if the node referenced by this DepID would satisfy the
|
|
9
|
+
* supplied Spec object.
|
|
10
|
+
*/
|
|
11
|
+
export const satisfies = (id, spec, fromLocation = process.cwd(), projectRoot = process.cwd(), monorepo) => !!id &&
|
|
12
|
+
satisfiesTuple(splitDepID(id), spec, fromLocation, projectRoot, monorepo);
|
|
13
|
+
export const satisfiesTuple = (tuple, spec, fromLocation = process.cwd(), projectRoot = process.cwd(), monorepo) => {
|
|
14
|
+
const { options } = spec;
|
|
15
|
+
spec = spec.final;
|
|
16
|
+
const [type, first, second] = tuple;
|
|
17
|
+
if (spec.type !== type)
|
|
18
|
+
return false;
|
|
19
|
+
switch (spec.type) {
|
|
20
|
+
case 'registry': {
|
|
21
|
+
if (!first) {
|
|
22
|
+
// must be from the default registry
|
|
23
|
+
if (spec.registry !== options.registry) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const namedRegistry = options.registries[first];
|
|
29
|
+
if (namedRegistry && namedRegistry !== spec.registry) {
|
|
30
|
+
// we know the name, and it's not the registry being used
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
else if (!namedRegistry && first !== spec.registry) {
|
|
34
|
+
// an explicit registry URL, but does not match
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/* c8 ignore next */
|
|
39
|
+
if (!second)
|
|
40
|
+
throw error('Invalid DepID', { found: tuple });
|
|
41
|
+
const [name, version] = parseNameVer(second);
|
|
42
|
+
return (
|
|
43
|
+
// mismatched name always invalid
|
|
44
|
+
name !== spec.name || !version ? false
|
|
45
|
+
// if just a dist-tag, assume valid
|
|
46
|
+
: !spec.range ? true
|
|
47
|
+
: spec.range.test(Version.parse(version)));
|
|
48
|
+
}
|
|
49
|
+
case 'file': {
|
|
50
|
+
/* c8 ignore next - should be impossible */
|
|
51
|
+
if (spec.file === undefined)
|
|
52
|
+
return false;
|
|
53
|
+
const resolvedSpec = resolve(projectRoot, fromLocation, spec.file);
|
|
54
|
+
const resolvedId = resolve(projectRoot, first);
|
|
55
|
+
// valid if the relative path is '', refers to the same path
|
|
56
|
+
return !relative(resolvedSpec, resolvedId);
|
|
57
|
+
}
|
|
58
|
+
case 'workspace': {
|
|
59
|
+
monorepo ??= Monorepo.load(projectRoot);
|
|
60
|
+
/* c8 ignore next */
|
|
61
|
+
if (!spec.workspace)
|
|
62
|
+
return false;
|
|
63
|
+
const fromID = monorepo.get(first);
|
|
64
|
+
const fromSpec = monorepo.get(spec.workspace);
|
|
65
|
+
if (fromID !== fromSpec || !fromSpec || !fromID)
|
|
66
|
+
return false;
|
|
67
|
+
if (!spec.range)
|
|
68
|
+
return true;
|
|
69
|
+
const v = parse(fromID.manifest.version ?? '');
|
|
70
|
+
return !!v && spec.range.test(v);
|
|
71
|
+
}
|
|
72
|
+
case 'remote': {
|
|
73
|
+
return spec.remoteURL === first;
|
|
74
|
+
}
|
|
75
|
+
case 'git': {
|
|
76
|
+
const { gitRemote, gitSelectorParsed = {}, gitSelector, gitCommittish, namedGitHost, namedGitHostPath, } = spec;
|
|
77
|
+
if (gitRemote !== first) {
|
|
78
|
+
if (namedGitHost && namedGitHostPath) {
|
|
79
|
+
const ngh = `${namedGitHost}:`;
|
|
80
|
+
if (first.startsWith(ngh)) {
|
|
81
|
+
if (first !== ngh + namedGitHostPath)
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
else
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
else
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (gitSelector && !second)
|
|
91
|
+
return false;
|
|
92
|
+
/* c8 ignore next - always set to something, even if empty */
|
|
93
|
+
const [parsed, committish] = Spec.parseGitSelector(second ?? '');
|
|
94
|
+
if (gitCommittish && committish)
|
|
95
|
+
return !!committish.startsWith(gitCommittish);
|
|
96
|
+
for (const [k, v] of Object.entries(gitSelectorParsed)) {
|
|
97
|
+
if (parsed[k] !== v)
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
/* c8 ignore start */
|
|
103
|
+
default: {
|
|
104
|
+
throw error('Invalid spec type', { spec });
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
/* c8 ignore stop */
|
|
108
|
+
};
|
|
109
|
+
const parseNameVer = (nv) => {
|
|
110
|
+
const at = nv.lastIndexOf('@');
|
|
111
|
+
// if it's 0, means @scoped without a version
|
|
112
|
+
return at <= 0 ?
|
|
113
|
+
[nv, '']
|
|
114
|
+
: [nv.substring(0, at), nv.substring(at + 1)];
|
|
115
|
+
};
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC/C,OAAO,EAAqB,IAAI,EAAE,MAAM,cAAc,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAC7C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAExC;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,EAAqB,EACrB,IAAU,EACV,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE,EAC5B,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,EAC3B,QAAmB,EACV,EAAE,CACX,CAAC,CAAC,EAAE;IACJ,cAAc,CACZ,UAAU,CAAC,EAAE,CAAC,EACd,IAAI,EACJ,YAAY,EACZ,WAAW,EACX,QAAQ,CACT,CAAA;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAC5B,KAAiB,EACjB,IAAU,EACV,YAAY,GAAG,OAAO,CAAC,GAAG,EAAE,EAC5B,WAAW,GAAG,OAAO,CAAC,GAAG,EAAE,EAC3B,QAAmB,EACV,EAAE;IACX,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAA;IACxB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;IACjB,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,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CAAC,EAAE,EAAE,EAAE,CAAC;QACV,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAA;AACjD,CAAC,CAAA","sourcesContent":["import { DepID, DepIDTuple, splitDepID } from '@vltpkg/dep-id'\nimport { error } from '@vltpkg/error-cause'\nimport { parse, Version } from '@vltpkg/semver'\nimport { GitSelectorParsed, Spec } from '@vltpkg/spec'\nimport { Monorepo } from '@vltpkg/workspaces'\nimport { relative, resolve } from 'path'\n\n/**\n * Return true if the node referenced by this DepID would satisfy the\n * supplied Spec object.\n */\nexport const satisfies = (\n id: DepID | undefined,\n spec: Spec,\n fromLocation = process.cwd(),\n projectRoot = process.cwd(),\n monorepo?: Monorepo,\n): boolean =>\n !!id &&\n satisfiesTuple(\n splitDepID(id),\n spec,\n fromLocation,\n projectRoot,\n monorepo,\n )\n\nexport const satisfiesTuple = (\n tuple: DepIDTuple,\n spec: Spec,\n fromLocation = process.cwd(),\n projectRoot = process.cwd(),\n monorepo?: Monorepo,\n): boolean => {\n const { options } = spec\n spec = spec.final\n const [type, first, second] = tuple\n if (spec.type !== type) return false\n\n switch (spec.type) {\n case 'registry': {\n if (!first) {\n // must be from the default registry\n if (spec.registry !== options.registry) {\n return false\n }\n } else {\n const namedRegistry = options.registries[first]\n if (namedRegistry && namedRegistry !== spec.registry) {\n // we know the name, and it's not the registry being used\n return false\n } else if (!namedRegistry && first !== spec.registry) {\n // an explicit registry URL, but does not match\n return false\n }\n }\n /* c8 ignore next */\n if (!second) throw error('Invalid DepID', { found: tuple })\n const [name, version] = parseNameVer(second)\n return (\n // mismatched name always invalid\n name !== spec.name || !version ? false\n // if just a dist-tag, assume valid\n : !spec.range ? true\n : spec.range.test(Version.parse(version))\n )\n }\n\n case 'file': {\n /* c8 ignore next - should be impossible */\n if (spec.file === undefined) return false\n const resolvedSpec = resolve(\n projectRoot,\n fromLocation,\n spec.file,\n )\n const resolvedId = resolve(projectRoot, first)\n // valid if the relative path is '', refers to the same path\n return !relative(resolvedSpec, resolvedId)\n }\n\n case 'workspace': {\n monorepo ??= Monorepo.load(projectRoot)\n /* c8 ignore next */\n if (!spec.workspace) return false\n const fromID = monorepo.get(first)\n const fromSpec = monorepo.get(spec.workspace)\n if (fromID !== fromSpec || !fromSpec || !fromID) return false\n if (!spec.range) return true\n const v = parse(fromID.manifest.version ?? '')\n return !!v && spec.range.test(v)\n }\n\n case 'remote': {\n return spec.remoteURL === first\n }\n\n case 'git': {\n const {\n gitRemote,\n gitSelectorParsed = {},\n gitSelector,\n gitCommittish,\n namedGitHost,\n namedGitHostPath,\n } = spec\n if (gitRemote !== first) {\n if (namedGitHost && namedGitHostPath) {\n const ngh = `${namedGitHost}:`\n if (first.startsWith(ngh)) {\n if (first !== ngh + namedGitHostPath) return false\n } else return false\n } else return false\n }\n if (gitSelector && !second) return false\n /* c8 ignore next - always set to something, even if empty */\n const [parsed, committish] = Spec.parseGitSelector(second ?? '')\n if (gitCommittish && committish)\n return !!committish.startsWith(gitCommittish)\n for (const [k, v] of Object.entries(gitSelectorParsed)) {\n if (parsed[k as keyof GitSelectorParsed] !== v) return false\n }\n return true\n }\n\n /* c8 ignore start */\n default: {\n throw error('Invalid spec type', { spec })\n }\n }\n /* c8 ignore stop */\n}\n\nconst parseNameVer = (nv: string): [string, string] => {\n const at = nv.lastIndexOf('@')\n // if it's 0, means @scoped without a version\n return at <= 0 ?\n [nv, '']\n : [nv.substring(0, at), nv.substring(at + 1)]\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vltpkg/satisfies",
|
|
3
|
+
"description": "method for determining if a DepID satisfies a Spec",
|
|
4
|
+
"version": "0.0.0-0.1730239248325",
|
|
5
|
+
"tshy": {
|
|
6
|
+
"selfLink": false,
|
|
7
|
+
"dialects": [
|
|
8
|
+
"esm"
|
|
9
|
+
],
|
|
10
|
+
"exports": {
|
|
11
|
+
"./package.json": "./package.json",
|
|
12
|
+
".": "./src/index.ts"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@vltpkg/dep-id": "0.0.0-0.1730239248325",
|
|
17
|
+
"@vltpkg/error-cause": "0.0.0-0.1730239248325",
|
|
18
|
+
"@vltpkg/spec": "0.0.0-0.1730239248325",
|
|
19
|
+
"@vltpkg/semver": "0.0.0-0.1730239248325",
|
|
20
|
+
"@vltpkg/workspaces": "0.0.0-0.1730239248325"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@eslint/js": "^9.8.0",
|
|
24
|
+
"@types/eslint__js": "^8.42.3",
|
|
25
|
+
"@types/node": "^22.4.1",
|
|
26
|
+
"eslint": "^9.8.0",
|
|
27
|
+
"prettier": "^3.3.2",
|
|
28
|
+
"tap": "^21.0.1",
|
|
29
|
+
"tshy": "^3.0.2",
|
|
30
|
+
"typescript": "^5.5.4",
|
|
31
|
+
"typescript-eslint": "^8.0.1"
|
|
32
|
+
},
|
|
33
|
+
"license": "BSD-2-Clause-Patent",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": "20 || >=22"
|
|
36
|
+
},
|
|
37
|
+
"tap": {
|
|
38
|
+
"extends": "../../tap-config.yaml"
|
|
39
|
+
},
|
|
40
|
+
"prettier": "../../.prettierrc.js",
|
|
41
|
+
"module": "./dist/esm/index.js",
|
|
42
|
+
"type": "module",
|
|
43
|
+
"exports": {
|
|
44
|
+
"./package.json": "./package.json",
|
|
45
|
+
".": {
|
|
46
|
+
"import": {
|
|
47
|
+
"types": "./dist/esm/index.d.ts",
|
|
48
|
+
"default": "./dist/esm/index.js"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"files": [
|
|
53
|
+
"dist"
|
|
54
|
+
],
|
|
55
|
+
"scripts": {
|
|
56
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
57
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
58
|
+
"lint": "eslint . --fix",
|
|
59
|
+
"lint:check": "eslint .",
|
|
60
|
+
"presnap": "tshy",
|
|
61
|
+
"snap": "tap",
|
|
62
|
+
"pretest": "tshy",
|
|
63
|
+
"test": "tap"
|
|
64
|
+
}
|
|
65
|
+
}
|