@vltpkg/vlx 0.0.0-10
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 +78 -0
- package/dist/esm/add-to-path.d.ts +2 -0
- package/dist/esm/add-to-path.d.ts.map +1 -0
- package/dist/esm/add-to-path.js +9 -0
- package/dist/esm/add-to-path.js.map +1 -0
- package/dist/esm/delete.d.ts +4 -0
- package/dist/esm/delete.d.ts.map +1 -0
- package/dist/esm/delete.js +35 -0
- package/dist/esm/delete.js.map +1 -0
- package/dist/esm/dir-exists.d.ts +2 -0
- package/dist/esm/dir-exists.d.ts.map +1 -0
- package/dist/esm/dir-exists.js +3 -0
- package/dist/esm/dir-exists.js.map +1 -0
- package/dist/esm/do-prompt.d.ts +4 -0
- package/dist/esm/do-prompt.d.ts.map +1 -0
- package/dist/esm/do-prompt.js +9 -0
- package/dist/esm/do-prompt.js.map +1 -0
- package/dist/esm/find-executable.d.ts +8 -0
- package/dist/esm/find-executable.d.ts.map +1 -0
- package/dist/esm/find-executable.js +19 -0
- package/dist/esm/find-executable.js.map +1 -0
- package/dist/esm/find-package.d.ts +10 -0
- package/dist/esm/find-package.d.ts.map +1 -0
- package/dist/esm/find-package.js +41 -0
- package/dist/esm/find-package.js.map +1 -0
- package/dist/esm/index.d.ts +48 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/infer-default-executable.d.ts +8 -0
- package/dist/esm/infer-default-executable.d.ts.map +1 -0
- package/dist/esm/infer-default-executable.js +20 -0
- package/dist/esm/infer-default-executable.js.map +1 -0
- package/dist/esm/info.d.ts +4 -0
- package/dist/esm/info.d.ts.map +1 -0
- package/dist/esm/info.js +36 -0
- package/dist/esm/info.js.map +1 -0
- package/dist/esm/install.d.ts +8 -0
- package/dist/esm/install.d.ts.map +1 -0
- package/dist/esm/install.js +63 -0
- package/dist/esm/install.js.map +1 -0
- package/dist/esm/list.d.ts +2 -0
- package/dist/esm/list.d.ts.map +1 -0
- package/dist/esm/list.js +11 -0
- package/dist/esm/list.js.map +1 -0
- package/dist/esm/mount-path.d.ts +6 -0
- package/dist/esm/mount-path.d.ts.map +1 -0
- package/dist/esm/mount-path.js +11 -0
- package/dist/esm/mount-path.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/resolve.d.ts +9 -0
- package/dist/esm/resolve.d.ts.map +1 -0
- package/dist/esm/resolve.js +84 -0
- package/dist/esm/resolve.js.map +1 -0
- package/package.json +78 -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,78 @@
|
|
|
1
|
+
# @vltpkg/vlx
|
|
2
|
+
|
|
3
|
+
Executable management for `vlt exec`.
|
|
4
|
+
|
|
5
|
+
**[Usage](#usage)**
|
|
6
|
+
|
|
7
|
+
## Overview
|
|
8
|
+
|
|
9
|
+
This is a tool that provides the global installs used by `vlt exec`
|
|
10
|
+
(that is, when it's not a local installed dependency).
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```ts
|
|
15
|
+
import * as vlx from '@vltpkg/vlx'
|
|
16
|
+
|
|
17
|
+
// get the options and arguments in the normal ways
|
|
18
|
+
const conf: LoadedConfig = blahblahblah()
|
|
19
|
+
|
|
20
|
+
const { positionals, options } = conf
|
|
21
|
+
|
|
22
|
+
// Provide a promptFn which is `()=>Promise<string>` if you want
|
|
23
|
+
// to confirm before installing things. If it returns a string
|
|
24
|
+
// that does not start with the letter 'y', then operation will
|
|
25
|
+
// be aborted. If not provided, consent is assumed.
|
|
26
|
+
const promptFn = async (pkgSpec: Spec, path: string) => {
|
|
27
|
+
const result = await createInterface(
|
|
28
|
+
process.stdin,
|
|
29
|
+
process.stdout,
|
|
30
|
+
).question(`Installing ${pkgSpec} in ${path}, is this ok? (y)`)
|
|
31
|
+
process.stdin.pause()
|
|
32
|
+
return result
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// figure out the correct executable, adding it to the user's
|
|
36
|
+
// XDG.data directory if appropriate, based on the positional
|
|
37
|
+
// args and the package option. Other options are used
|
|
38
|
+
// appropriately for installation, resolution, etc.
|
|
39
|
+
const arg0 = await vlx.resolve(positionals, options, promptFn)
|
|
40
|
+
|
|
41
|
+
// now one of the following is true:
|
|
42
|
+
// - arg0 refers to a locally installed package bin
|
|
43
|
+
// - arg0 refers to a package bin in the XDG.data directory
|
|
44
|
+
// - arg0 is undefined, and an interactive shell can be executed
|
|
45
|
+
// - an error was thrown, because it couijld not be determined
|
|
46
|
+
if (arg0 === undefined) {
|
|
47
|
+
doInteractiveShellOrWhatever()
|
|
48
|
+
} else {
|
|
49
|
+
runTheCommandOrWhatever([arg0, ...positionals.slice(2)])
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// some other stuff this can do:
|
|
53
|
+
|
|
54
|
+
// explicitly add a package install to the XDG.data dir, if
|
|
55
|
+
// not already present. Returns the key used to reference
|
|
56
|
+
// the install for removal or inspection.
|
|
57
|
+
const info = await vlx.install('somepkg@somespec', options)
|
|
58
|
+
|
|
59
|
+
// remove an installed instance, if present
|
|
60
|
+
// returns a list of paths that were removed
|
|
61
|
+
const removed = await vlx.delete(['somepkg'], remover, options)
|
|
62
|
+
const removed = await vlx.delete(['somepkg'], remover, options)
|
|
63
|
+
|
|
64
|
+
// list the paths for all installs in the XDG.data directory
|
|
65
|
+
const installPaths = await vlx.list()
|
|
66
|
+
|
|
67
|
+
// get information about a given install, or undefined missing
|
|
68
|
+
const {
|
|
69
|
+
// the manifest of the synthetic vlx project depending on that package
|
|
70
|
+
manifest,
|
|
71
|
+
// path to the synthetic vlx project
|
|
72
|
+
path,
|
|
73
|
+
// the resolved package dependency, if it came from the vlx cache
|
|
74
|
+
resolved,
|
|
75
|
+
// the inferred default binary, if one could be determined.
|
|
76
|
+
arg0,
|
|
77
|
+
} = await vlx.info(path, options)
|
|
78
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-to-path.d.ts","sourceRoot":"","sources":["../../src/add-to-path.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,YAAa,MAAM,SAUxC,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { delimiter } from 'node:path';
|
|
2
|
+
export const addToPATH = (newPath) => {
|
|
3
|
+
process.env.PATH = [
|
|
4
|
+
...new Set(`${newPath}${delimiter}${process.env.PATH ?? ''}`.split(delimiter)),
|
|
5
|
+
]
|
|
6
|
+
.filter(p => !!p)
|
|
7
|
+
.join(delimiter);
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=add-to-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"add-to-path.js","sourceRoot":"","sources":["../../src/add-to-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAErC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAe,EAAE,EAAE;IAC3C,OAAO,CAAC,GAAG,CAAC,IAAI,GAAG;QACjB,GAAG,IAAI,GAAG,CACR,GAAG,OAAO,GAAG,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,EAAE,EAAE,CAAC,KAAK,CACrD,SAAS,CACV,CACF;KACF;SACE,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;SAChB,IAAI,CAAC,SAAS,CAAC,CAAA;AACpB,CAAC,CAAA","sourcesContent":["import { delimiter } from 'node:path'\n\nexport const addToPATH = (newPath: string) => {\n process.env.PATH = [\n ...new Set(\n `${newPath}${delimiter}${process.env.PATH ?? ''}`.split(\n delimiter,\n ),\n ),\n ]\n .filter(p => !!p)\n .join(delimiter)\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../src/delete.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AAE7D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAY5C,eAAO,MAAM,SAAS,SACd,MAAM,EAAE,WACL,cAAc,WACd,UAAU,sBAqBpB,CAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { basename } from 'node:path';
|
|
2
|
+
import { vlxInfo } from "./info.js";
|
|
3
|
+
import { vlxList } from "./list.js";
|
|
4
|
+
const keyMatch = (keys, path) => {
|
|
5
|
+
if (!keys.length)
|
|
6
|
+
return true;
|
|
7
|
+
for (const k of keys) {
|
|
8
|
+
if (path.includes(k))
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
};
|
|
13
|
+
export const vlxDelete = async (keys, remover, options) => {
|
|
14
|
+
const removed = [];
|
|
15
|
+
const promises = [];
|
|
16
|
+
for await (const p of vlxList()) {
|
|
17
|
+
// if the request for info fails, delete it
|
|
18
|
+
const key = basename(p);
|
|
19
|
+
try {
|
|
20
|
+
vlxInfo(p, options);
|
|
21
|
+
if (keyMatch(keys, key)) {
|
|
22
|
+
promises.push(remover.rm(p));
|
|
23
|
+
removed.push(key);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
// delete if no good
|
|
28
|
+
promises.push(remover.rm(p));
|
|
29
|
+
removed.push(key);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
await Promise.all(promises);
|
|
33
|
+
return removed;
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../src/delete.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,QAAQ,GAAG,CAAC,IAAc,EAAE,IAAY,EAAW,EAAE;IACzD,IAAI,CAAC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAC7B,KAAK,MAAM,CAAC,IAAI,IAAI,EAAE,CAAC;QACrB,IAAI,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;YAAE,OAAO,IAAI,CAAA;IACnC,CAAC;IACD,OAAO,KAAK,CAAA;AACd,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAC5B,IAAc,EACd,OAAuB,EACvB,OAAmB,EACnB,EAAE;IACF,MAAM,OAAO,GAAa,EAAE,CAAA;IAC5B,MAAM,QAAQ,GAAoB,EAAE,CAAA;IACpC,IAAI,KAAK,EAAE,MAAM,CAAC,IAAI,OAAO,EAAE,EAAE,CAAC;QAChC,2CAA2C;QAC3C,MAAM,GAAG,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;QACvB,IAAI,CAAC;YACH,OAAO,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;YACnB,IAAI,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;gBACxB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC5B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;YACnB,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,oBAAoB;YACpB,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;YAC5B,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;QACnB,CAAC;IACH,CAAC;IACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IAC3B,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA","sourcesContent":["import type { RollbackRemove } from '@vltpkg/rollback-remove'\nimport { basename } from 'node:path'\nimport type { VlxOptions } from './index.ts'\nimport { vlxInfo } from './info.ts'\nimport { vlxList } from './list.ts'\n\nconst keyMatch = (keys: string[], path: string): boolean => {\n if (!keys.length) return true\n for (const k of keys) {\n if (path.includes(k)) return true\n }\n return false\n}\n\nexport const vlxDelete = async (\n keys: string[],\n remover: RollbackRemove,\n options: VlxOptions,\n) => {\n const removed: string[] = []\n const promises: Promise<void>[] = []\n for await (const p of vlxList()) {\n // if the request for info fails, delete it\n const key = basename(p)\n try {\n vlxInfo(p, options)\n if (keyMatch(keys, key)) {\n promises.push(remover.rm(p))\n removed.push(key)\n }\n } catch {\n // delete if no good\n promises.push(remover.rm(p))\n removed.push(key)\n }\n }\n await Promise.all(promises)\n return removed\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dir-exists.d.ts","sourceRoot":"","sources":["../../src/dir-exists.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,SAAgB,MAAM,KAAG,OAAO,CAAC,OAAO,CAI3D,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dir-exists.js","sourceRoot":"","sources":["../../src/dir-exists.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAA;AAEvC,MAAM,CAAC,MAAM,SAAS,GAAG,KAAK,EAAE,IAAY,EAAoB,EAAE,CAChE,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CACb,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,WAAW,EAAE,EACtB,GAAG,EAAE,CAAC,KAAK,CACZ,CAAA","sourcesContent":["import { stat } from 'node:fs/promises'\n\nexport const dirExists = async (path: string): Promise<boolean> =>\n stat(path).then(\n st => st.isDirectory(),\n () => false,\n )\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do-prompt.d.ts","sourceRoot":"","sources":["../../src/do-prompt.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACxC,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAE1C,eAAO,MAAM,QAAQ,SACb,IAAI,OACL,MAAM,cACC,MAAM,OACb,QAAQ,KACZ,OAAO,CAAC,OAAO,CAMjB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"do-prompt.js","sourceRoot":"","sources":["../../src/do-prompt.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,MAAM,QAAQ,GAAG,KAAK,EAC3B,IAAU,EACV,GAAW,EACX,UAAkB,EAClB,EAAa,EACK,EAAE;IACpB,IAAI,CAAC,EAAE;QAAE,OAAO,IAAI,CAAA;IACpB,MAAM,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;SAC7C,IAAI,EAAE;SACN,WAAW,EAAE,CAAA;IAChB,OAAO,CAAC,MAAM,IAAI,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;AAC1C,CAAC,CAAA","sourcesContent":["import type { Spec } from '@vltpkg/spec'\nimport type { PromptFn } from './index.ts'\n\nexport const doPrompt = async (\n spec: Spec,\n dir: string,\n resolution: string,\n fn?: PromptFn,\n): Promise<boolean> => {\n if (!fn) return true\n const result = (await fn(spec, dir, resolution))\n .trim()\n .toLowerCase()\n return !result || result.startsWith('y')\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Find the executable in a node_modules/.bin folder between the cwd
|
|
3
|
+
* and the projectRoot.
|
|
4
|
+
*
|
|
5
|
+
* Returns `[executable, target]` showing the package origin.
|
|
6
|
+
*/
|
|
7
|
+
export declare const findExecutable: (arg0: string, projectRoot: string) => Promise<string | undefined>;
|
|
8
|
+
//# sourceMappingURL=find-executable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-executable.d.ts","sourceRoot":"","sources":["../../src/find-executable.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,eAAO,MAAM,cAAc,SACnB,MAAM,eACC,MAAM,gCASpB,CAAA"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { findCmdShimIfExists } from '@vltpkg/cmd-shim';
|
|
2
|
+
import { relative, resolve } from 'node:path';
|
|
3
|
+
import { walkUp } from 'walk-up-path';
|
|
4
|
+
/**
|
|
5
|
+
* Find the executable in a node_modules/.bin folder between the cwd
|
|
6
|
+
* and the projectRoot.
|
|
7
|
+
*
|
|
8
|
+
* Returns `[executable, target]` showing the package origin.
|
|
9
|
+
*/
|
|
10
|
+
export const findExecutable = async (arg0, projectRoot) => {
|
|
11
|
+
for (const path of walkUp(process.cwd())) {
|
|
12
|
+
const bin = await findCmdShimIfExists(resolve(path, 'node_modules/.bin', arg0));
|
|
13
|
+
if (bin)
|
|
14
|
+
return bin[0];
|
|
15
|
+
if (relative(path, projectRoot) === '')
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=find-executable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-executable.js","sourceRoot":"","sources":["../../src/find-executable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,KAAK,EACjC,IAAY,EACZ,WAAmB,EACnB,EAAE;IACF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACzC,MAAM,GAAG,GAAG,MAAM,mBAAmB,CACnC,OAAO,CAAC,IAAI,EAAE,mBAAmB,EAAE,IAAI,CAAC,CACzC,CAAA;QACD,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC,CAAC,CAAC,CAAA;QACtB,IAAI,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,EAAE;YAAE,MAAK;IAC/C,CAAC;AACH,CAAC,CAAA","sourcesContent":["import { findCmdShimIfExists } from '@vltpkg/cmd-shim'\nimport { relative, resolve } from 'node:path'\nimport { walkUp } from 'walk-up-path'\n\n/**\n * Find the executable in a node_modules/.bin folder between the cwd\n * and the projectRoot.\n *\n * Returns `[executable, target]` showing the package origin.\n */\nexport const findExecutable = async (\n arg0: string,\n projectRoot: string,\n) => {\n for (const path of walkUp(process.cwd())) {\n const bin = await findCmdShimIfExists(\n resolve(path, 'node_modules/.bin', arg0),\n )\n if (bin) return bin[0]\n if (relative(path, projectRoot) === '') break\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { PackageJson } from '@vltpkg/package-json';
|
|
2
|
+
import type { VlxInfo } from './index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Find the nearest package in a node_modules folder between the cwd
|
|
5
|
+
* and the projectRoot. This should only be used to look for local packages.
|
|
6
|
+
* Note that the `resolved` value in the VlxInfo object is a bit useless,
|
|
7
|
+
* as we didn't install anything and so don't need to do a full resolution.
|
|
8
|
+
*/
|
|
9
|
+
export declare const findPackage: (name: string, projectRoot: string, packageJson: PackageJson) => Promise<undefined | VlxInfo>;
|
|
10
|
+
//# sourceMappingURL=find-package.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-package.d.ts","sourceRoot":"","sources":["../../src/find-package.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAIvD,OAAO,KAAK,EAAE,OAAO,EAAe,MAAM,YAAY,CAAA;AAWtD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,SAChB,MAAM,eACC,MAAM,eACN,WAAW,KACvB,OAAO,CAAC,SAAS,GAAG,OAAO,CAmB7B,CAAA"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { relative, resolve } from 'node:path';
|
|
2
|
+
import { pathToFileURL } from 'node:url';
|
|
3
|
+
import { walkUp } from 'walk-up-path';
|
|
4
|
+
import { inferDefaultExecutable } from "./infer-default-executable.js";
|
|
5
|
+
const maybeManifest = (p, packageJson) => {
|
|
6
|
+
try {
|
|
7
|
+
return packageJson.read(p);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Find the nearest package in a node_modules folder between the cwd
|
|
15
|
+
* and the projectRoot. This should only be used to look for local packages.
|
|
16
|
+
* Note that the `resolved` value in the VlxInfo object is a bit useless,
|
|
17
|
+
* as we didn't install anything and so don't need to do a full resolution.
|
|
18
|
+
*/
|
|
19
|
+
export const findPackage = async (name, projectRoot, packageJson) => {
|
|
20
|
+
for (const path of walkUp(process.cwd())) {
|
|
21
|
+
const p = resolve(path, 'node_modules', name);
|
|
22
|
+
const manifest = maybeManifest(path, packageJson);
|
|
23
|
+
try {
|
|
24
|
+
const m = packageJson.read(p, { reload: true });
|
|
25
|
+
const bin = inferDefaultExecutable(m);
|
|
26
|
+
const { vlx = {} } = manifest;
|
|
27
|
+
return {
|
|
28
|
+
path,
|
|
29
|
+
name,
|
|
30
|
+
version: m.version,
|
|
31
|
+
resolved: String(pathToFileURL(p)),
|
|
32
|
+
arg0: bin?.[0],
|
|
33
|
+
...vlx,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
catch { }
|
|
37
|
+
if (relative(path, projectRoot) === '')
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=find-package.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-package.js","sourceRoot":"","sources":["../../src/find-package.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAErC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAEtE,MAAM,aAAa,GAAG,CAAC,CAAS,EAAE,WAAwB,EAAE,EAAE;IAC5D,IAAI,CAAC;QACH,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAA;IAC5B,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAA;IACX,CAAC;AACH,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC9B,IAAY,EACZ,WAAmB,EACnB,WAAwB,EACM,EAAE;IAChC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACzC,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,CAAA;QAC7C,MAAM,QAAQ,GAAG,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QACjD,IAAI,CAAC;YACH,MAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;YAC/C,MAAM,GAAG,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAA;YACrC,MAAM,EAAE,GAAG,GAAG,EAAE,EAAE,GAAG,QAAuB,CAAA;YAC5C,OAAO;gBACL,IAAI;gBACJ,IAAI;gBACJ,OAAO,EAAE,CAAC,CAAC,OAAO;gBAClB,QAAQ,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;gBAClC,IAAI,EAAE,GAAG,EAAE,CAAC,CAAC,CAAC;gBACd,GAAG,GAAG;aACP,CAAA;QACH,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;QACV,IAAI,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC,KAAK,EAAE;YAAE,MAAK;IAC/C,CAAC;AACH,CAAC,CAAA","sourcesContent":["import type { PackageJson } from '@vltpkg/package-json'\nimport { relative, resolve } from 'node:path'\nimport { pathToFileURL } from 'node:url'\nimport { walkUp } from 'walk-up-path'\nimport type { VlxInfo, VlxManifest } from './index.ts'\nimport { inferDefaultExecutable } from './infer-default-executable.ts'\n\nconst maybeManifest = (p: string, packageJson: PackageJson) => {\n try {\n return packageJson.read(p)\n } catch {\n return {}\n }\n}\n\n/**\n * Find the nearest package in a node_modules folder between the cwd\n * and the projectRoot. This should only be used to look for local packages.\n * Note that the `resolved` value in the VlxInfo object is a bit useless,\n * as we didn't install anything and so don't need to do a full resolution.\n */\nexport const findPackage = async (\n name: string,\n projectRoot: string,\n packageJson: PackageJson,\n): Promise<undefined | VlxInfo> => {\n for (const path of walkUp(process.cwd())) {\n const p = resolve(path, 'node_modules', name)\n const manifest = maybeManifest(path, packageJson)\n try {\n const m = packageJson.read(p, { reload: true })\n const bin = inferDefaultExecutable(m)\n const { vlx = {} } = manifest as VlxManifest\n return {\n path,\n name,\n version: m.version,\n resolved: String(pathToFileURL(p)),\n arg0: bin?.[0],\n ...vlx,\n }\n } catch {}\n if (relative(path, projectRoot) === '') break\n }\n}\n"]}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { InstallOptions } from '@vltpkg/graph';
|
|
2
|
+
import type { PackageInfoClientOptions, PackageInfoClientRequestOptions, Resolution } from '@vltpkg/package-info';
|
|
3
|
+
import type { Spec, SpecOptions } from '@vltpkg/spec';
|
|
4
|
+
import type { Integrity, Manifest } from '@vltpkg/types';
|
|
5
|
+
export type VlxManifest = Manifest & {
|
|
6
|
+
vlx?: {
|
|
7
|
+
integrity?: Integrity;
|
|
8
|
+
signatures?: Resolution['signatures'];
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Provide a promptFn which is `()=>Promise<string>` if you want to confirm
|
|
13
|
+
* before installing things. If it returns a string that does not start with
|
|
14
|
+
* the letter 'y', then operation will be aborted. If not provided, consent is
|
|
15
|
+
* assumed.
|
|
16
|
+
*/
|
|
17
|
+
export type PromptFn = (pkgSpec: Spec, path: string, resolution: string) => Promise<string>;
|
|
18
|
+
/** The info about a given vlx installation */
|
|
19
|
+
export type VlxInfo = VlxManifest['vlx'] & {
|
|
20
|
+
/** name of the package that is being run */
|
|
21
|
+
name: string;
|
|
22
|
+
/** version of the package being run */
|
|
23
|
+
version?: string;
|
|
24
|
+
/**
|
|
25
|
+
* path to the synthetic project for non-local installs, or to the
|
|
26
|
+
* current projectRoot if the resolution is local.
|
|
27
|
+
*/
|
|
28
|
+
path: string;
|
|
29
|
+
/**
|
|
30
|
+
* resolution of the package installed, for non-local installs,
|
|
31
|
+
* or a file URL into the node_modules for project local installs.
|
|
32
|
+
*/
|
|
33
|
+
resolved: string;
|
|
34
|
+
/**
|
|
35
|
+
* Full path to the inferred default binary for the dependency if it exists.
|
|
36
|
+
*/
|
|
37
|
+
arg0?: string;
|
|
38
|
+
};
|
|
39
|
+
export type VlxOptions = SpecOptions & PackageInfoClientOptions & PackageInfoClientRequestOptions & InstallOptions & {
|
|
40
|
+
package?: string;
|
|
41
|
+
yes?: boolean;
|
|
42
|
+
};
|
|
43
|
+
export { vlxDelete as delete } from './delete.ts';
|
|
44
|
+
export { vlxInfo as info } from './info.ts';
|
|
45
|
+
export { vlxInstall as install } from './install.ts';
|
|
46
|
+
export { vlxList as list } from './list.ts';
|
|
47
|
+
export { vlxResolve as resolve } from './resolve.ts';
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AACnD,OAAO,KAAK,EACV,wBAAwB,EACxB,+BAA+B,EAC/B,UAAU,EACX,MAAM,sBAAsB,CAAA;AAC7B,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAExD,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG;IACnC,GAAG,CAAC,EAAE;QACJ,SAAS,CAAC,EAAE,SAAS,CAAA;QACrB,UAAU,CAAC,EAAE,UAAU,CAAC,YAAY,CAAC,CAAA;KACtC,CAAA;CACF,CAAA;AAED;;;;;GAKG;AACH,MAAM,MAAM,QAAQ,GAAG,CACrB,OAAO,EAAE,IAAI,EACb,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,KACf,OAAO,CAAC,MAAM,CAAC,CAAA;AAEpB,8CAA8C;AAC9C,MAAM,MAAM,OAAO,GAAG,WAAW,CAAC,KAAK,CAAC,GAAG;IACzC,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAA;IAEZ,uCAAuC;IACvC,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAA;IAEZ;;;OAGG;IACH,QAAQ,EAAE,MAAM,CAAA;IAEhB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAED,MAAM,MAAM,UAAU,GAAG,WAAW,GAClC,wBAAwB,GACxB,+BAA+B,GAC/B,cAAc,GAAG;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,CAAA;AAEH,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { vlxDelete as delete } from "./delete.js";
|
|
2
|
+
export { vlxInfo as info } from "./info.js";
|
|
3
|
+
export { vlxInstall as install } from "./install.js";
|
|
4
|
+
export { vlxList as list } from "./list.js";
|
|
5
|
+
export { vlxResolve as resolve } from "./resolve.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA8DA,OAAO,EAAE,SAAS,IAAI,MAAM,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,EAAE,OAAO,IAAI,IAAI,EAAE,MAAM,WAAW,CAAA;AAC3C,OAAO,EAAE,UAAU,IAAI,OAAO,EAAE,MAAM,cAAc,CAAA","sourcesContent":["import type { InstallOptions } from '@vltpkg/graph'\nimport type {\n PackageInfoClientOptions,\n PackageInfoClientRequestOptions,\n Resolution,\n} from '@vltpkg/package-info'\nimport type { Spec, SpecOptions } from '@vltpkg/spec'\nimport type { Integrity, Manifest } from '@vltpkg/types'\n\nexport type VlxManifest = Manifest & {\n vlx?: {\n integrity?: Integrity\n signatures?: Resolution['signatures']\n }\n}\n\n/**\n * Provide a promptFn which is `()=>Promise<string>` if you want to confirm\n * before installing things. If it returns a string that does not start with\n * the letter 'y', then operation will be aborted. If not provided, consent is\n * assumed.\n */\nexport type PromptFn = (\n pkgSpec: Spec,\n path: string,\n resolution: string,\n) => Promise<string>\n\n/** The info about a given vlx installation */\nexport type VlxInfo = VlxManifest['vlx'] & {\n /** name of the package that is being run */\n name: string\n\n /** version of the package being run */\n version?: string\n\n /**\n * path to the synthetic project for non-local installs, or to the\n * current projectRoot if the resolution is local.\n */\n path: string\n\n /**\n * resolution of the package installed, for non-local installs,\n * or a file URL into the node_modules for project local installs.\n */\n resolved: string\n\n /**\n * Full path to the inferred default binary for the dependency if it exists.\n */\n arg0?: string\n}\n\nexport type VlxOptions = SpecOptions &\n PackageInfoClientOptions &\n PackageInfoClientRequestOptions &\n InstallOptions & {\n package?: string\n yes?: boolean\n }\n\nexport { vlxDelete as delete } from './delete.ts'\nexport { vlxInfo as info } from './info.ts'\nexport { vlxInstall as install } from './install.ts'\nexport { vlxList as list } from './list.ts'\nexport { vlxResolve as resolve } from './resolve.ts'\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Manifest } from '@vltpkg/types';
|
|
2
|
+
/**
|
|
3
|
+
* Infer the default binary from a package.
|
|
4
|
+
*
|
|
5
|
+
* Returns `undefined` if it couldn't be determined
|
|
6
|
+
*/
|
|
7
|
+
export declare const inferDefaultExecutable: ({ name, bin, }: Manifest) => undefined | [string, string];
|
|
8
|
+
//# sourceMappingURL=infer-default-executable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-default-executable.d.ts","sourceRoot":"","sources":["../../src/infer-default-executable.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAE7C;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,mBAGhC,QAAQ,KAAG,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,CAcxC,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Infer the default binary from a package.
|
|
3
|
+
*
|
|
4
|
+
* Returns `undefined` if it couldn't be determined
|
|
5
|
+
*/
|
|
6
|
+
export const inferDefaultExecutable = ({ name, bin, }) => {
|
|
7
|
+
if (!bin)
|
|
8
|
+
return undefined;
|
|
9
|
+
const binName = name?.startsWith('@') ? name.split('/')[1] : name;
|
|
10
|
+
if (!binName)
|
|
11
|
+
return undefined;
|
|
12
|
+
if (typeof bin === 'string') {
|
|
13
|
+
return [binName, bin];
|
|
14
|
+
}
|
|
15
|
+
bin = bin[binName];
|
|
16
|
+
if (!bin)
|
|
17
|
+
return undefined;
|
|
18
|
+
return [binName, bin];
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=infer-default-executable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infer-default-executable.js","sourceRoot":"","sources":["../../src/infer-default-executable.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,EACrC,IAAI,EACJ,GAAG,GACM,EAAgC,EAAE;IAC3C,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAA;IAE1B,MAAM,OAAO,GAAG,IAAI,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACjE,IAAI,CAAC,OAAO;QAAE,OAAO,SAAS,CAAA;IAE9B,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;IACvB,CAAC;IAED,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,CAAA;IAClB,IAAI,CAAC,GAAG;QAAE,OAAO,SAAS,CAAA;IAE1B,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;AACvB,CAAC,CAAA","sourcesContent":["import type { Manifest } from '@vltpkg/types'\n\n/**\n * Infer the default binary from a package.\n *\n * Returns `undefined` if it couldn't be determined\n */\nexport const inferDefaultExecutable = ({\n name,\n bin,\n}: Manifest): undefined | [string, string] => {\n if (!bin) return undefined\n\n const binName = name?.startsWith('@') ? name.split('/')[1] : name\n if (!binName) return undefined\n\n if (typeof bin === 'string') {\n return [binName, bin]\n }\n\n bin = bin[binName]\n if (!bin) return undefined\n\n return [binName, bin]\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"info.d.ts","sourceRoot":"","sources":["../../src/info.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAA;AAG7C,OAAO,KAAK,EAAE,OAAO,EAAe,UAAU,EAAE,MAAM,YAAY,CAAA;AAKlE,eAAO,MAAM,OAAO,SACZ,MAAM,WACH,UAAU,aACR,QAAQ,KAClB,OA8BF,CAAA"}
|
package/dist/esm/info.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { XDG } from '@vltpkg/xdg';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { inferDefaultExecutable } from "./infer-default-executable.js";
|
|
5
|
+
import { mountPath } from "./mount-path.js";
|
|
6
|
+
export const vlxInfo = (path, options, manifest) => {
|
|
7
|
+
const root = new XDG('vlt/vlx').data();
|
|
8
|
+
path = mountPath(root, path);
|
|
9
|
+
try {
|
|
10
|
+
// do not allow it to traverse up or read arbitrary paths
|
|
11
|
+
const { packageJson } = options;
|
|
12
|
+
manifest ??= packageJson.read(path);
|
|
13
|
+
const { dependencies = {} } = manifest;
|
|
14
|
+
// every one of these has exactly one dep, on the resolved url
|
|
15
|
+
for (const [name, resolved] of Object.entries(dependencies)) {
|
|
16
|
+
const p = resolve(path, 'node_modules', name);
|
|
17
|
+
const pj = packageJson.read(p, { reload: true });
|
|
18
|
+
const def = inferDefaultExecutable(pj);
|
|
19
|
+
const arg0 = def?.[0];
|
|
20
|
+
const { vlx } = manifest;
|
|
21
|
+
return {
|
|
22
|
+
path,
|
|
23
|
+
name,
|
|
24
|
+
version: pj.version,
|
|
25
|
+
resolved,
|
|
26
|
+
arg0,
|
|
27
|
+
...vlx,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (er) {
|
|
32
|
+
throw error('Could not get vlx information', er);
|
|
33
|
+
}
|
|
34
|
+
throw error('Could not get vlx information');
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"info.js","sourceRoot":"","sources":["../../src/info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAE3C,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAA;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAE3C,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,IAAY,EACZ,OAAmB,EACnB,QAAmB,EACV,EAAE;IACX,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAA;IACtC,IAAI,GAAG,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,CAAA;IAE5B,IAAI,CAAC;QACH,yDAAyD;QACzD,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;QAC/B,QAAQ,KAAK,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACnC,MAAM,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,QAAQ,CAAA;QAEtC,8DAA8D;QAC9D,KAAK,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YAC5D,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,cAAc,EAAE,IAAI,CAAC,CAAA;YAC7C,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAA;YAChD,MAAM,GAAG,GAAG,sBAAsB,CAAC,EAAE,CAAC,CAAA;YACtC,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,CAAC,CAAC,CAAA;YACrB,MAAM,EAAE,GAAG,EAAE,GAAG,QAAuB,CAAA;YACvC,OAAO;gBACL,IAAI;gBACJ,IAAI;gBACJ,OAAO,EAAE,EAAE,CAAC,OAAO;gBACnB,QAAQ;gBACR,IAAI;gBACJ,GAAG,GAAG;aACP,CAAA;QACH,CAAC;IACH,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,MAAM,KAAK,CAAC,+BAA+B,EAAE,EAAW,CAAC,CAAA;IAC3D,CAAC;IACD,MAAM,KAAK,CAAC,+BAA+B,CAAC,CAAA;AAC9C,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport type { Manifest } from '@vltpkg/types'\nimport { XDG } from '@vltpkg/xdg'\nimport { resolve } from 'node:path'\nimport type { VlxInfo, VlxManifest, VlxOptions } from './index.ts'\nimport { inferDefaultExecutable } from './infer-default-executable.ts'\n\nimport { mountPath } from './mount-path.ts'\n\nexport const vlxInfo = (\n path: string,\n options: VlxOptions,\n manifest?: Manifest,\n): VlxInfo => {\n const root = new XDG('vlt/vlx').data()\n path = mountPath(root, path)\n\n try {\n // do not allow it to traverse up or read arbitrary paths\n const { packageJson } = options\n manifest ??= packageJson.read(path)\n const { dependencies = {} } = manifest\n\n // every one of these has exactly one dep, on the resolved url\n for (const [name, resolved] of Object.entries(dependencies)) {\n const p = resolve(path, 'node_modules', name)\n const pj = packageJson.read(p, { reload: true })\n const def = inferDefaultExecutable(pj)\n const arg0 = def?.[0]\n const { vlx } = manifest as VlxManifest\n return {\n path,\n name,\n version: pj.version,\n resolved,\n arg0,\n ...vlx,\n }\n }\n } catch (er) {\n throw error('Could not get vlx information', er as Error)\n }\n throw error('Could not get vlx information')\n}\n"]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Spec } from '@vltpkg/spec';
|
|
2
|
+
import type { PromptFn, VlxInfo, VlxOptions } from './index.ts';
|
|
3
|
+
/**
|
|
4
|
+
* Install a given package spec in the appropriate folder, if it's not
|
|
5
|
+
* already present.
|
|
6
|
+
*/
|
|
7
|
+
export declare const vlxInstall: (spec: Spec | string, options: VlxOptions, promptFn?: PromptFn) => Promise<VlxInfo>;
|
|
8
|
+
//# sourceMappingURL=install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../src/install.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AAQnC,OAAO,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AAG/D;;;GAGG;AACH,eAAO,MAAM,UAAU,SACf,IAAI,GAAG,MAAM,WACV,UAAU,aACR,QAAQ,KAClB,OAAO,CAAC,OAAO,CAyDjB,CAAA"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { install } from '@vltpkg/graph';
|
|
3
|
+
import { PackageInfoClient } from '@vltpkg/package-info';
|
|
4
|
+
import { Spec } from '@vltpkg/spec';
|
|
5
|
+
import { XDG } from '@vltpkg/xdg';
|
|
6
|
+
import { createHash } from 'node:crypto';
|
|
7
|
+
import { mkdir, writeFile } from 'node:fs/promises';
|
|
8
|
+
import { resolve } from 'node:path';
|
|
9
|
+
import { PathScurry } from 'path-scurry';
|
|
10
|
+
import { dirExists } from "./dir-exists.js";
|
|
11
|
+
import { doPrompt } from "./do-prompt.js";
|
|
12
|
+
import { vlxInfo } from "./info.js";
|
|
13
|
+
/**
|
|
14
|
+
* Install a given package spec in the appropriate folder, if it's not
|
|
15
|
+
* already present.
|
|
16
|
+
*/
|
|
17
|
+
export const vlxInstall = async (spec, options, promptFn) => {
|
|
18
|
+
const pkgSpec = typeof spec === 'string' ? Spec.parseArgs(spec) : spec;
|
|
19
|
+
const { name } = pkgSpec.final;
|
|
20
|
+
// We always use the cache as much as possible, to prevent unnecessarily
|
|
21
|
+
// waiting to run a command while installing something. The one we used
|
|
22
|
+
// last time is almost certainly fine.
|
|
23
|
+
options = {
|
|
24
|
+
...options,
|
|
25
|
+
['stale-while-revalidate-factor']: Infinity,
|
|
26
|
+
};
|
|
27
|
+
const packageInfo = (options.packageInfo = new PackageInfoClient(options));
|
|
28
|
+
const resolution = await packageInfo.resolve(pkgSpec, options);
|
|
29
|
+
const hash = createHash('sha512')
|
|
30
|
+
.update(resolution.resolved)
|
|
31
|
+
.digest('hex')
|
|
32
|
+
.substring(0, 8);
|
|
33
|
+
const xdg = new XDG('vlt/vlx');
|
|
34
|
+
const dir = xdg.data(pkgSpec.name.replace('/', '§') + '-' + hash);
|
|
35
|
+
if (await dirExists(dir)) {
|
|
36
|
+
return vlxInfo(dir, options);
|
|
37
|
+
}
|
|
38
|
+
const ok = options.yes ||
|
|
39
|
+
(await doPrompt(pkgSpec, dir, resolution.resolved, promptFn));
|
|
40
|
+
if (!ok)
|
|
41
|
+
throw error('Operation aborted');
|
|
42
|
+
await mkdir(resolve(dir, 'node_modules/.vlt'), { recursive: true });
|
|
43
|
+
const manifest = {
|
|
44
|
+
name: 'vlx',
|
|
45
|
+
dependencies: {
|
|
46
|
+
[name]: resolution.resolved,
|
|
47
|
+
},
|
|
48
|
+
vlx: {
|
|
49
|
+
integrity: resolution.integrity,
|
|
50
|
+
signatures: resolution.signatures,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
await writeFile(resolve(dir, 'package.json'), JSON.stringify(manifest, null, 2) + '\n');
|
|
54
|
+
await install({
|
|
55
|
+
...options,
|
|
56
|
+
packageInfo,
|
|
57
|
+
projectRoot: dir,
|
|
58
|
+
monorepo: undefined,
|
|
59
|
+
scurry: new PathScurry(dir),
|
|
60
|
+
});
|
|
61
|
+
return vlxInfo(dir, options, manifest);
|
|
62
|
+
};
|
|
63
|
+
//# sourceMappingURL=install.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../src/install.ts"],"names":[],"mappings":"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","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { install } from '@vltpkg/graph'\nimport { PackageInfoClient } from '@vltpkg/package-info'\nimport { Spec } from '@vltpkg/spec'\nimport { XDG } from '@vltpkg/xdg'\nimport { createHash } from 'node:crypto'\nimport { mkdir, writeFile } from 'node:fs/promises'\nimport { resolve } from 'node:path'\nimport { PathScurry } from 'path-scurry'\nimport { dirExists } from './dir-exists.ts'\nimport { doPrompt } from './do-prompt.ts'\nimport type { PromptFn, VlxInfo, VlxOptions } from './index.ts'\nimport { vlxInfo } from './info.ts'\n\n/**\n * Install a given package spec in the appropriate folder, if it's not\n * already present.\n */\nexport const vlxInstall = async (\n spec: Spec | string,\n options: VlxOptions,\n promptFn?: PromptFn,\n): Promise<VlxInfo> => {\n const pkgSpec =\n typeof spec === 'string' ? Spec.parseArgs(spec) : spec\n const { name } = pkgSpec.final\n // We always use the cache as much as possible, to prevent unnecessarily\n // waiting to run a command while installing something. The one we used\n // last time is almost certainly fine.\n options = {\n ...options,\n ['stale-while-revalidate-factor']: Infinity,\n }\n const packageInfo = (options.packageInfo = new PackageInfoClient(\n options,\n ))\n const resolution = await packageInfo.resolve(pkgSpec, options)\n const hash = createHash('sha512')\n .update(resolution.resolved)\n .digest('hex')\n .substring(0, 8)\n const xdg = new XDG('vlt/vlx')\n const dir = xdg.data(pkgSpec.name.replace('/', '§') + '-' + hash)\n if (await dirExists(dir)) {\n return vlxInfo(dir, options)\n }\n\n const ok =\n options.yes ||\n (await doPrompt(pkgSpec, dir, resolution.resolved, promptFn))\n if (!ok) throw error('Operation aborted')\n\n await mkdir(resolve(dir, 'node_modules/.vlt'), { recursive: true })\n\n const manifest = {\n name: 'vlx',\n dependencies: {\n [name]: resolution.resolved,\n },\n vlx: {\n integrity: resolution.integrity,\n signatures: resolution.signatures,\n },\n }\n\n await writeFile(\n resolve(dir, 'package.json'),\n JSON.stringify(manifest, null, 2) + '\\n',\n )\n\n await install({\n ...options,\n packageInfo,\n projectRoot: dir,\n monorepo: undefined,\n scurry: new PathScurry(dir),\n })\n\n return vlxInfo(dir, options, manifest)\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/list.ts"],"names":[],"mappings":"AAIA,wBAAuB,OAAO,0CAM7B"}
|
package/dist/esm/list.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { XDG } from '@vltpkg/xdg';
|
|
2
|
+
import { opendir } from 'node:fs/promises';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
export async function* vlxList() {
|
|
5
|
+
const path = new XDG('vlt/vlx').data();
|
|
6
|
+
const dir = await opendir(path);
|
|
7
|
+
for await (const dirent of dir) {
|
|
8
|
+
yield resolve(path, dirent.name);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=list.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"list.js","sourceRoot":"","sources":["../../src/list.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAA;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAEnC,MAAM,CAAC,KAAK,SAAS,CAAC,CAAC,OAAO;IAC5B,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAA;IACtC,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/B,IAAI,KAAK,EAAE,MAAM,MAAM,IAAI,GAAG,EAAE,CAAC;QAC/B,MAAM,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;AACH,CAAC","sourcesContent":["import { XDG } from '@vltpkg/xdg'\nimport { opendir } from 'node:fs/promises'\nimport { resolve } from 'node:path'\n\nexport async function* vlxList() {\n const path = new XDG('vlt/vlx').data()\n const dir = await opendir(path)\n for await (const dirent of dir) {\n yield resolve(path, dirent.name)\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount-path.d.ts","sourceRoot":"","sources":["../../src/mount-path.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,eAAO,MAAM,SAAS,SAAU,MAAM,QAAQ,MAAM,KAAG,MAItD,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
/**
|
|
3
|
+
* Prevent `vlx exec-cache info/delete/ls` from reaching out of its
|
|
4
|
+
* safe little sandbox.
|
|
5
|
+
*/
|
|
6
|
+
export const mountPath = (root, path) => {
|
|
7
|
+
path = join(path);
|
|
8
|
+
path = path.startsWith(root) ? path.substring(root.length) : path;
|
|
9
|
+
return join(root, join('/', path));
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=mount-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mount-path.js","sourceRoot":"","sources":["../../src/mount-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEhC;;;GAGG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE;IAC9D,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;IACjB,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IACjE,OAAO,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC,CAAA;AACpC,CAAC,CAAA","sourcesContent":["import { join } from 'node:path'\n\n/**\n * Prevent `vlx exec-cache info/delete/ls` from reaching out of its\n * safe little sandbox.\n */\nexport const mountPath = (root: string, path: string): string => {\n path = join(path)\n path = path.startsWith(root) ? path.substring(root.length) : path\n return join(root, join('/', path))\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { PromptFn, VlxOptions } from './index.ts';
|
|
2
|
+
/**
|
|
3
|
+
* Figure out the `arg0` to use for an exec command.
|
|
4
|
+
*
|
|
5
|
+
* If `undefined` is returned, then the caller should spawn an interactive
|
|
6
|
+
* shell, or in multi-workspace mode, raise an error.
|
|
7
|
+
*/
|
|
8
|
+
export declare const vlxResolve: (positionals: string[], options: VlxOptions, promptFn?: PromptFn) => Promise<undefined | string>;
|
|
9
|
+
//# sourceMappingURL=resolve.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/resolve.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,QAAQ,EAAW,UAAU,EAAE,MAAM,YAAY,CAAA;AAG/D;;;;;GAKG;AACH,eAAO,MAAM,UAAU,gBACR,MAAM,EAAE,WACZ,UAAU,aACR,QAAQ,KAClB,OAAO,CAAC,SAAS,GAAG,MAAM,CA6E5B,CAAA"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { error } from '@vltpkg/error-cause';
|
|
2
|
+
import { Spec } from '@vltpkg/spec';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
import { addToPATH } from "./add-to-path.js";
|
|
5
|
+
import { findExecutable } from "./find-executable.js";
|
|
6
|
+
import { findPackage } from "./find-package.js";
|
|
7
|
+
import { vlxInstall } from "./install.js";
|
|
8
|
+
/**
|
|
9
|
+
* Figure out the `arg0` to use for an exec command.
|
|
10
|
+
*
|
|
11
|
+
* If `undefined` is returned, then the caller should spawn an interactive
|
|
12
|
+
* shell, or in multi-workspace mode, raise an error.
|
|
13
|
+
*/
|
|
14
|
+
export const vlxResolve = async (positionals, options, promptFn) => {
|
|
15
|
+
const noArgs = positionals.length === 0;
|
|
16
|
+
let arg0 = positionals[0];
|
|
17
|
+
let pkgOption = options.package;
|
|
18
|
+
const { projectRoot, packageJson } = options;
|
|
19
|
+
if (!pkgOption) {
|
|
20
|
+
// can come from any package
|
|
21
|
+
if (!arg0) {
|
|
22
|
+
// caller will run interactive shell
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
const found = await findExecutable(arg0, projectRoot);
|
|
26
|
+
// if found locally, then that's the bin, whatever the package is
|
|
27
|
+
// since no package option was provided anyway.
|
|
28
|
+
if (found)
|
|
29
|
+
return found;
|
|
30
|
+
// ok, not local, might have to install something.
|
|
31
|
+
// treat the arg0 as a package specifier
|
|
32
|
+
pkgOption = arg0;
|
|
33
|
+
arg0 = undefined;
|
|
34
|
+
}
|
|
35
|
+
let pkgTarget = undefined;
|
|
36
|
+
if (pkgOption) {
|
|
37
|
+
// check for local option, otherwise install in data dir we can
|
|
38
|
+
// ONLY do the local option if the spec is a simple name. otherwise
|
|
39
|
+
// it's too complicated to know if it's a match, especially in this
|
|
40
|
+
// world of multiple registries and such, and it's easy enough to
|
|
41
|
+
// just install it externally.
|
|
42
|
+
const pkgSpec = Spec.parseArgs(pkgOption, options);
|
|
43
|
+
const { name, bareSpec } = pkgSpec.final;
|
|
44
|
+
// if it's just a name, we can use the local version
|
|
45
|
+
if (!bareSpec) {
|
|
46
|
+
pkgTarget = await findPackage(name, projectRoot, packageJson);
|
|
47
|
+
}
|
|
48
|
+
pkgTarget ??= await vlxInstall(pkgSpec, options, promptFn);
|
|
49
|
+
}
|
|
50
|
+
if (pkgTarget) {
|
|
51
|
+
addToPATH(resolve(pkgTarget.path, 'node_modules/.bin'));
|
|
52
|
+
// if we now have a pkgTarget, and we did not have any arguments, then
|
|
53
|
+
// the user did something like `vlx --package=foo`, but didn't give us
|
|
54
|
+
// a command. In that case, we add the relevant exec-cache .bin folder to
|
|
55
|
+
// the PATH env, and let the caller invoke an interactive shell.
|
|
56
|
+
if (noArgs)
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
// now if we had a package option, then pkgTarget is set
|
|
60
|
+
// if arg0 isn't set, then we need to infer from the manifest
|
|
61
|
+
// This is like doing `vlx foo@version`, where we treat arg0
|
|
62
|
+
// as the package option. A default exec *must* be inferred then.
|
|
63
|
+
if (!arg0) {
|
|
64
|
+
/* c8 ignore start - impossible, case already handled */
|
|
65
|
+
if (!pkgTarget) {
|
|
66
|
+
throw error('Must supply a --package option and/or arguments', {
|
|
67
|
+
code: 'EUSAGE',
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
/* c8 ignore stop */
|
|
71
|
+
// infer arg0 from the manifst found at pkgTarget[1]
|
|
72
|
+
arg0 = pkgTarget.arg0;
|
|
73
|
+
if (!arg0) {
|
|
74
|
+
const { name, version, bin } = packageJson.read(resolve(pkgTarget.path, 'node_modules', pkgTarget.name));
|
|
75
|
+
throw error('Package executable could not be inferred', {
|
|
76
|
+
name,
|
|
77
|
+
version,
|
|
78
|
+
found: bin,
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return arg0;
|
|
83
|
+
};
|
|
84
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAA;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,WAAqB,EACrB,OAAmB,EACnB,QAAmB,EACU,EAAE;IAC/B,MAAM,MAAM,GAAG,WAAW,CAAC,MAAM,KAAK,CAAC,CAAA;IACvC,IAAI,IAAI,GAAG,WAAW,CAAC,CAAC,CAAC,CAAA;IACzB,IAAI,SAAS,GAAG,OAAO,CAAC,OAAO,CAAA;IAC/B,MAAM,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,OAAO,CAAA;IAE5C,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,4BAA4B;QAC5B,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,oCAAoC;YACpC,OAAO,SAAS,CAAA;QAClB,CAAC;QAED,MAAM,KAAK,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,WAAW,CAAC,CAAA;QACrD,iEAAiE;QACjE,+CAA+C;QAC/C,IAAI,KAAK;YAAE,OAAO,KAAK,CAAA;QACvB,kDAAkD;QAClD,wCAAwC;QACxC,SAAS,GAAG,IAAI,CAAA;QAChB,IAAI,GAAG,SAAS,CAAA;IAClB,CAAC;IAED,IAAI,SAAS,GAAwB,SAAS,CAAA;IAE9C,IAAI,SAAS,EAAE,CAAC;QACd,+DAA+D;QAC/D,mEAAmE;QACnE,mEAAmE;QACnE,iEAAiE;QACjE,8BAA8B;QAC9B,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAClD,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,OAAO,CAAC,KAAK,CAAA;QACxC,oDAAoD;QACpD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,SAAS,GAAG,MAAM,WAAW,CAAC,IAAI,EAAE,WAAW,EAAE,WAAW,CAAC,CAAA;QAC/D,CAAC;QACD,SAAS,KAAK,MAAM,UAAU,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAC5D,CAAC;IAED,IAAI,SAAS,EAAE,CAAC;QACd,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,mBAAmB,CAAC,CAAC,CAAA;QACvD,sEAAsE;QACtE,sEAAsE;QACtE,yEAAyE;QACzE,gEAAgE;QAChE,IAAI,MAAM;YAAE,OAAO,SAAS,CAAA;IAC9B,CAAC;IAED,wDAAwD;IACxD,6DAA6D;IAC7D,4DAA4D;IAC5D,iEAAiE;IACjE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,wDAAwD;QACxD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,KAAK,CAAC,iDAAiD,EAAE;gBAC7D,IAAI,EAAE,QAAQ;aACf,CAAC,CAAA;QACJ,CAAC;QACD,oBAAoB;QAEpB,oDAAoD;QACpD,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;QACrB,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,WAAW,CAAC,IAAI,CAC7C,OAAO,CAAC,SAAS,CAAC,IAAI,EAAE,cAAc,EAAE,SAAS,CAAC,IAAI,CAAC,CACxD,CAAA;YACD,MAAM,KAAK,CAAC,0CAA0C,EAAE;gBACtD,IAAI;gBACJ,OAAO;gBACP,KAAK,EAAE,GAAG;aACX,CAAC,CAAA;QACJ,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC,CAAA","sourcesContent":["import { error } from '@vltpkg/error-cause'\nimport { Spec } from '@vltpkg/spec'\nimport { resolve } from 'node:path'\nimport { addToPATH } from './add-to-path.ts'\nimport { findExecutable } from './find-executable.ts'\nimport { findPackage } from './find-package.ts'\nimport type { PromptFn, VlxInfo, VlxOptions } from './index.ts'\nimport { vlxInstall } from './install.ts'\n\n/**\n * Figure out the `arg0` to use for an exec command.\n *\n * If `undefined` is returned, then the caller should spawn an interactive\n * shell, or in multi-workspace mode, raise an error.\n */\nexport const vlxResolve = async (\n positionals: string[],\n options: VlxOptions,\n promptFn?: PromptFn,\n): Promise<undefined | string> => {\n const noArgs = positionals.length === 0\n let arg0 = positionals[0]\n let pkgOption = options.package\n const { projectRoot, packageJson } = options\n\n if (!pkgOption) {\n // can come from any package\n if (!arg0) {\n // caller will run interactive shell\n return undefined\n }\n\n const found = await findExecutable(arg0, projectRoot)\n // if found locally, then that's the bin, whatever the package is\n // since no package option was provided anyway.\n if (found) return found\n // ok, not local, might have to install something.\n // treat the arg0 as a package specifier\n pkgOption = arg0\n arg0 = undefined\n }\n\n let pkgTarget: undefined | VlxInfo = undefined\n\n if (pkgOption) {\n // check for local option, otherwise install in data dir we can\n // ONLY do the local option if the spec is a simple name. otherwise\n // it's too complicated to know if it's a match, especially in this\n // world of multiple registries and such, and it's easy enough to\n // just install it externally.\n const pkgSpec = Spec.parseArgs(pkgOption, options)\n const { name, bareSpec } = pkgSpec.final\n // if it's just a name, we can use the local version\n if (!bareSpec) {\n pkgTarget = await findPackage(name, projectRoot, packageJson)\n }\n pkgTarget ??= await vlxInstall(pkgSpec, options, promptFn)\n }\n\n if (pkgTarget) {\n addToPATH(resolve(pkgTarget.path, 'node_modules/.bin'))\n // if we now have a pkgTarget, and we did not have any arguments, then\n // the user did something like `vlx --package=foo`, but didn't give us\n // a command. In that case, we add the relevant exec-cache .bin folder to\n // the PATH env, and let the caller invoke an interactive shell.\n if (noArgs) return undefined\n }\n\n // now if we had a package option, then pkgTarget is set\n // if arg0 isn't set, then we need to infer from the manifest\n // This is like doing `vlx foo@version`, where we treat arg0\n // as the package option. A default exec *must* be inferred then.\n if (!arg0) {\n /* c8 ignore start - impossible, case already handled */\n if (!pkgTarget) {\n throw error('Must supply a --package option and/or arguments', {\n code: 'EUSAGE',\n })\n }\n /* c8 ignore stop */\n\n // infer arg0 from the manifst found at pkgTarget[1]\n arg0 = pkgTarget.arg0\n if (!arg0) {\n const { name, version, bin } = packageJson.read(\n resolve(pkgTarget.path, 'node_modules', pkgTarget.name),\n )\n throw error('Package executable could not be inferred', {\n name,\n version,\n found: bin,\n })\n }\n }\n\n return arg0\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vltpkg/vlx",
|
|
3
|
+
"description": "vlt exec management",
|
|
4
|
+
"version": "0.0.0-10",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/vltpkg/vltpkg.git",
|
|
8
|
+
"directory": "src/vlx"
|
|
9
|
+
},
|
|
10
|
+
"tshy": {
|
|
11
|
+
"selfLink": false,
|
|
12
|
+
"liveDev": true,
|
|
13
|
+
"dialects": [
|
|
14
|
+
"esm"
|
|
15
|
+
],
|
|
16
|
+
"exports": {
|
|
17
|
+
"./package.json": "./package.json",
|
|
18
|
+
".": "./src/index.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"dependencies": {
|
|
22
|
+
"path-scurry": "^2.0.0",
|
|
23
|
+
"walk-up-path": "^4.0.0",
|
|
24
|
+
"@vltpkg/cmd-shim": "0.0.0-10",
|
|
25
|
+
"@vltpkg/error-cause": "0.0.0-10",
|
|
26
|
+
"@vltpkg/graph": "0.0.0-10",
|
|
27
|
+
"@vltpkg/package-info": "0.0.0-10",
|
|
28
|
+
"@vltpkg/package-json": "0.0.0-10",
|
|
29
|
+
"@vltpkg/spec": "0.0.0-10",
|
|
30
|
+
"@vltpkg/rollback-remove": "0.0.0-10",
|
|
31
|
+
"@vltpkg/types": "0.0.0-10",
|
|
32
|
+
"@vltpkg/run": "0.0.0-10",
|
|
33
|
+
"@vltpkg/xdg": "0.0.0-10"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@eslint/js": "^9.25.0",
|
|
37
|
+
"@types/node": "^22.14.1",
|
|
38
|
+
"eslint": "^9.25.0",
|
|
39
|
+
"prettier": "^3.5.3",
|
|
40
|
+
"tap": "^21.1.0",
|
|
41
|
+
"tshy": "^3.0.2",
|
|
42
|
+
"typedoc": "~0.27.6",
|
|
43
|
+
"typescript": "5.7.3",
|
|
44
|
+
"typescript-eslint": "^8.30.1"
|
|
45
|
+
},
|
|
46
|
+
"license": "BSD-2-Clause-Patent",
|
|
47
|
+
"engines": {
|
|
48
|
+
"node": ">=22"
|
|
49
|
+
},
|
|
50
|
+
"tap": {
|
|
51
|
+
"extends": "../../tap-config.yaml"
|
|
52
|
+
},
|
|
53
|
+
"prettier": "../../.prettierrc.js",
|
|
54
|
+
"module": "./dist/esm/index.js",
|
|
55
|
+
"type": "module",
|
|
56
|
+
"exports": {
|
|
57
|
+
"./package.json": "./package.json",
|
|
58
|
+
".": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/esm/index.d.ts",
|
|
61
|
+
"default": "./dist/esm/index.js"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"files": [
|
|
66
|
+
"dist"
|
|
67
|
+
],
|
|
68
|
+
"scripts": {
|
|
69
|
+
"format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
|
|
70
|
+
"format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
|
|
71
|
+
"lint": "eslint . --fix",
|
|
72
|
+
"lint:check": "eslint .",
|
|
73
|
+
"snap": "tap",
|
|
74
|
+
"test": "tap",
|
|
75
|
+
"posttest": "tsc --noEmit",
|
|
76
|
+
"typecheck": "tsc --noEmit"
|
|
77
|
+
}
|
|
78
|
+
}
|