@vltpkg/which 1.0.0-rc.18 → 1.0.0-rc.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,13 +1,16 @@
1
1
  {
2
2
  "name": "@vltpkg/which",
3
3
  "description": "Find the first executable in the path (TS port of 'which')",
4
- "version": "1.0.0-rc.18",
4
+ "version": "1.0.0-rc.22",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/vltpkg/vltpkg.git",
8
8
  "directory": "src/which"
9
9
  },
10
- "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
10
+ "author": {
11
+ "name": "vlt technology inc.",
12
+ "email": "support@vlt.sh"
13
+ },
11
14
  "dependencies": {
12
15
  "isexe": "^3.1.1"
13
16
  },
@@ -23,33 +26,34 @@
23
26
  },
24
27
  "license": "ISC",
25
28
  "engines": {
26
- "node": ">=22.9.0"
29
+ "node": ">=22.22.0"
30
+ },
31
+ "scripts": {
32
+ "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
33
+ "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
34
+ "lint": "eslint . --fix",
35
+ "lint:check": "eslint .",
36
+ "prepack": "tsc -p tsconfig.publish.json && ../../scripts/update-dist-exports.ts",
37
+ "snap": "tap",
38
+ "test": "tap",
39
+ "posttest": "tsc --noEmit",
40
+ "typecheck": "tsc --noEmit"
27
41
  },
28
42
  "tap": {
29
43
  "extends": "../../tap-config.yaml"
30
44
  },
31
45
  "prettier": "../../.prettierrc.js",
32
- "module": "./dist/index.js",
46
+ "module": "./src/index.ts",
33
47
  "type": "module",
34
48
  "exports": {
35
49
  "./package.json": "./package.json",
36
50
  ".": {
37
51
  "import": {
38
- "default": "./dist/index.js"
52
+ "default": "./src/index.ts"
39
53
  }
40
54
  }
41
55
  },
42
56
  "files": [
43
57
  "dist"
44
- ],
45
- "scripts": {
46
- "format": "prettier --write . --log-level warn --ignore-path ../../.prettierignore --cache",
47
- "format:check": "prettier --check . --ignore-path ../../.prettierignore --cache",
48
- "lint": "eslint . --fix",
49
- "lint:check": "eslint .",
50
- "snap": "tap",
51
- "test": "tap",
52
- "posttest": "tsc --noEmit",
53
- "typecheck": "tsc --noEmit"
54
- }
55
- }
58
+ ]
59
+ }
package/dist/index.d.ts DELETED
@@ -1,42 +0,0 @@
1
- export type WhichOptions = {
2
- all?: boolean;
3
- path?: string;
4
- pathExt?: string;
5
- nothrow?: boolean;
6
- delimiter?: string;
7
- };
8
- export type WhichOptionsFindAll = WhichOptions & {
9
- all: true;
10
- };
11
- export type WhichOptionsFindOne = WhichOptions & {
12
- all?: false;
13
- };
14
- export type WhichOptionsNoThrow = WhichOptions & {
15
- nothrow: true;
16
- };
17
- export type WhichOptionsThrow = WhichOptions & {
18
- nothrow?: false;
19
- };
20
- export type WhichOptionsFindOneThrow = WhichOptionsFindOne & WhichOptionsThrow;
21
- export type WhichOptionsFindOneNoThrow = WhichOptionsFindOne & WhichOptionsNoThrow;
22
- export type WhichOptionsFindAllNoThrow = WhichOptionsFindAll & WhichOptionsNoThrow;
23
- export type WhichOptionsFindAllThrow = WhichOptionsFindAll & WhichOptionsThrow;
24
- export declare function which(cmd: string): Promise<string>;
25
- export declare function which(cmd: string, opt: WhichOptionsFindAllNoThrow): Promise<string[] | null>;
26
- export declare function which(cmd: string, opt: WhichOptionsFindOneNoThrow): Promise<string | null>;
27
- export declare function which(cmd: string, opt: WhichOptionsFindAllThrow): Promise<string[]>;
28
- export declare function which(cmd: string, opt: WhichOptionsFindOneThrow): Promise<string>;
29
- export declare function which(cmd: string, opt: WhichOptionsFindOne): Promise<string | null>;
30
- export declare function which(cmd: string, opt: WhichOptionsNoThrow): Promise<string[] | string | null>;
31
- export declare function which(cmd: string, opt: WhichOptionsFindAll): Promise<string[] | null>;
32
- export declare function which(cmd: string, opt: WhichOptions): Promise<string[] | string | null>;
33
- export declare function whichSync(cmd: string): string;
34
- export declare function whichSync(cmd: string, opt: WhichOptionsFindAllNoThrow): string[] | null;
35
- export declare function whichSync(cmd: string, opt: WhichOptionsFindOneNoThrow): string | null;
36
- export declare function whichSync(cmd: string, opt: WhichOptionsFindAllThrow): string[];
37
- export declare function whichSync(cmd: string, opt: WhichOptionsFindOneThrow): string;
38
- export declare function whichSync(cmd: string, opt: WhichOptionsFindOne): string | null;
39
- export declare function whichSync(cmd: string, opt: WhichOptionsNoThrow): string[] | string | null;
40
- export declare function whichSync(cmd: string, opt: WhichOptionsFindAll): string[] | null;
41
- export declare function whichSync(cmd: string, opt?: WhichOptions): string[] | string | null;
42
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAgEA,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG;IAAE,GAAG,EAAE,IAAI,CAAA;CAAE,CAAA;AAC9D,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAA;CAAE,CAAA;AAEhE,MAAM,MAAM,mBAAmB,GAAG,YAAY,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAAA;AAClE,MAAM,MAAM,iBAAiB,GAAG,YAAY,GAAG;IAAE,OAAO,CAAC,EAAE,KAAK,CAAA;CAAE,CAAA;AAElE,MAAM,MAAM,wBAAwB,GAAG,mBAAmB,GACxD,iBAAiB,CAAA;AACnB,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,GAC1D,mBAAmB,CAAA;AAErB,MAAM,MAAM,0BAA0B,GAAG,mBAAmB,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vB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,0BAA0B,GAC9B,MAAM,EAAE,GAAG,IAAI,CAAA;AAClB,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,0BAA0B,GAC9B,MAAM,GAAG,IAAI,CAAA;AAChB,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,wBAAwB,GAC5B,MAAM,EAAE,CAAA;AACX,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,wBAAwB,GAC5B,MAAM,CAAA;AACT,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,mBAAmB,GACvB,MAAM,GAAG,IAAI,CAAA;AAChB,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,mBAAmB,GACvB,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAAA;AAC3B,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,EAAE,mBAAmB,GACvB,MAAM,EAAE,GAAG,IAAI,CAAA;AAClB,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,EACX,GAAG,CAAC,EAAE,YAAY,GACjB,MAAM,EAAE,GAAG,MAAM,GAAG,IAAI,CAAA"}
package/dist/index.js DELETED
@@ -1,99 +0,0 @@
1
- import { isexe, sync as isexeSync } from 'isexe';
2
- import { delimiter, join, sep } from 'node:path';
3
- const isWindows = process.platform === 'win32';
4
- // used to check for slashed in commands passed in. always checks for the posix
5
- // separator on all platforms, and checks for the current separator when not on
6
- // a posix platform. don't use the isWindows check for this since that is
7
- // mocked in tests but we still need the code to actually work when called.
8
- // that is also why it is ignored from coverage.
9
- /* c8 ignore next */
10
- const rSlash = sep === '/' ? /\// : /[\\/]/;
11
- const rRel = new RegExp(`^\\.${rSlash.source}`);
12
- // Simulate a NodeJS.ErrnoException
13
- const getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' });
14
- const getPathInfo = (cmd, { path: optPath = process.env.PATH, pathExt: optPathExt = process.env.PATHEXT, delimiter: optDelimiter = delimiter, }) => {
15
- // If it has a slash, then we don't bother searching the pathenv.
16
- // just check the file itself, and that's it.
17
- const pathEnv = cmd.match(rSlash) ?
18
- ['']
19
- : [
20
- // windows always checks the cwd first
21
- /* c8 ignore next - platform-specific */
22
- ...(isWindows ? [process.cwd()] : []),
23
- ...(optPath ?? /* c8 ignore next - very unusual */ '').split(optDelimiter),
24
- ];
25
- if (isWindows) {
26
- const pathExtExe = optPathExt ||
27
- ['.EXE', '.CMD', '.BAT', '.COM'].join(optDelimiter);
28
- const pathExt = pathExtExe
29
- .split(optDelimiter)
30
- .flatMap(item => [item, item.toLowerCase()]);
31
- if (cmd.includes('.') && pathExt[0] !== '') {
32
- pathExt.unshift('');
33
- }
34
- return { pathEnv, pathExt, pathExtExe };
35
- /* c8 ignore start - not reachable on windows */
36
- }
37
- return { pathEnv, pathExt: [''] };
38
- };
39
- /* c8 ignore stop */
40
- const getPathPart = (raw, cmd) => {
41
- const pathPart = /^".*"$/.test(raw) ? raw.slice(1, -1) : raw;
42
- const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : '';
43
- return prefix + join(pathPart, cmd);
44
- };
45
- export async function which(cmd, opt = {}) {
46
- const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
47
- const found = [];
48
- for (const envPart of pathEnv) {
49
- const p = getPathPart(envPart, cmd);
50
- for (const ext of pathExt) {
51
- const withExt = p + ext;
52
- const is = await isexe(withExt, {
53
- pathExt: pathExtExe,
54
- ignoreErrors: true,
55
- });
56
- if (is) {
57
- if (!opt.all) {
58
- return withExt;
59
- }
60
- found.push(withExt);
61
- }
62
- }
63
- }
64
- if (opt.all && found.length) {
65
- return found;
66
- }
67
- if (opt.nothrow) {
68
- return null;
69
- }
70
- throw getNotFoundError(cmd);
71
- }
72
- export function whichSync(cmd, opt = {}) {
73
- const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
74
- const found = [];
75
- for (const pathEnvPart of pathEnv) {
76
- const p = getPathPart(pathEnvPart, cmd);
77
- for (const ext of pathExt) {
78
- const withExt = p + ext;
79
- const is = isexeSync(withExt, {
80
- pathExt: pathExtExe,
81
- ignoreErrors: true,
82
- });
83
- if (is) {
84
- if (!opt.all) {
85
- return withExt;
86
- }
87
- found.push(withExt);
88
- }
89
- }
90
- }
91
- if (opt.all && found.length) {
92
- return found;
93
- }
94
- if (opt.nothrow) {
95
- return null;
96
- }
97
- throw getNotFoundError(cmd);
98
- }
99
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,IAAI,SAAS,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,EAAE,MAAM,WAAW,CAAA;AAEhD,MAAM,SAAS,GAAG,OAAO,CAAC,QAAQ,KAAK,OAAO,CAAA;AAE9C,+EAA+E;AAC/E,+EAA+E;AAC/E,yEAAyE;AACzE,2EAA2E;AAC3E,gDAAgD;AAChD,oBAAoB;AACpB,MAAM,MAAM,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAA;AAC3C,MAAM,IAAI,GAAG,IAAI,MAAM,CAAC,OAAO,MAAM,CAAC,MAAM,EAAE,CAAC,CAAA;AAE/C,mCAAmC;AACnC,MAAM,gBAAgB,GAAG,CAAC,GAAW,EAAE,EAAE,CACvC,MAAM,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,cAAc,GAAG,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAA;AAEnE,MAAM,WAAW,GAAG,CAClB,GAAW,EACX,EACE,IAAI,EAAE,OAA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= process.platform === 'win32'\n\n// used to check for slashed in commands passed in. always checks for the posix\n// separator on all platforms, and checks for the current separator when not on\n// a posix platform. don't use the isWindows check for this since that is\n// mocked in tests but we still need the code to actually work when called.\n// that is also why it is ignored from coverage.\n/* c8 ignore next */\nconst rSlash = sep === '/' ? /\\// : /[\\\\/]/\nconst rRel = new RegExp(`^\\\\.${rSlash.source}`)\n\n// Simulate a NodeJS.ErrnoException\nconst getNotFoundError = (cmd: string) =>\n Object.assign(new Error(`not found: ${cmd}`), { code: 'ENOENT' })\n\nconst getPathInfo = (\n cmd: string,\n {\n path: optPath = process.env.PATH,\n pathExt: optPathExt = process.env.PATHEXT,\n delimiter: optDelimiter = delimiter,\n }: WhichOptions,\n) => {\n // If it has a slash, then we don't bother searching the pathenv.\n // just check the file itself, and that's it.\n const pathEnv =\n cmd.match(rSlash) ?\n ['']\n : [\n // windows always checks the cwd first\n /* c8 ignore next - platform-specific */\n ...(isWindows ? [process.cwd()] : []),\n ...(optPath ?? /* c8 ignore next - very unusual */ '').split(\n optDelimiter,\n ),\n ]\n\n if (isWindows) {\n const pathExtExe =\n optPathExt ||\n ['.EXE', '.CMD', '.BAT', '.COM'].join(optDelimiter)\n const pathExt = pathExtExe\n .split(optDelimiter)\n .flatMap(item => [item, item.toLowerCase()])\n if (cmd.includes('.') && pathExt[0] !== '') {\n pathExt.unshift('')\n }\n return { pathEnv, pathExt, pathExtExe }\n /* c8 ignore start - not reachable on windows */\n }\n\n return { pathEnv, pathExt: [''] }\n}\n/* c8 ignore stop */\n\nconst getPathPart = (raw: string, cmd: string) => {\n const pathPart = /^\".*\"$/.test(raw) ? raw.slice(1, -1) : raw\n const prefix = !pathPart && rRel.test(cmd) ? cmd.slice(0, 2) : ''\n return prefix + join(pathPart, cmd)\n}\n\nexport type WhichOptions = {\n all?: boolean\n path?: string\n pathExt?: string\n nothrow?: boolean\n delimiter?: string\n}\n\nexport type WhichOptionsFindAll = WhichOptions & { all: true }\nexport type WhichOptionsFindOne = WhichOptions & { all?: false }\n\nexport type WhichOptionsNoThrow = WhichOptions & { nothrow: true }\nexport type WhichOptionsThrow = WhichOptions & { nothrow?: false }\n\nexport type WhichOptionsFindOneThrow = WhichOptionsFindOne &\n WhichOptionsThrow\nexport type WhichOptionsFindOneNoThrow = WhichOptionsFindOne &\n WhichOptionsNoThrow\n\nexport type WhichOptionsFindAllNoThrow = WhichOptionsFindAll &\n WhichOptionsNoThrow\nexport type WhichOptionsFindAllThrow = WhichOptionsFindAll &\n WhichOptionsThrow\n\nexport async function which(cmd: string): Promise<string>\nexport async function which(\n cmd: string,\n opt: WhichOptionsFindAllNoThrow,\n): Promise<string[] | null>\nexport async function which(\n cmd: string,\n opt: WhichOptionsFindOneNoThrow,\n): Promise<string | null>\nexport async function which(\n cmd: string,\n opt: WhichOptionsFindAllThrow,\n): Promise<string[]>\nexport async function which(\n cmd: string,\n opt: WhichOptionsFindOneThrow,\n): Promise<string>\nexport async function which(\n cmd: string,\n opt: WhichOptionsFindOne,\n): Promise<string | null>\nexport async function which(\n cmd: string,\n opt: WhichOptionsNoThrow,\n): Promise<string[] | string | null>\nexport async function which(\n cmd: string,\n opt: WhichOptionsFindAll,\n): Promise<string[] | null>\nexport async function which(\n cmd: string,\n opt: WhichOptions,\n): Promise<string[] | string | null>\nexport async function which(cmd: string, opt: WhichOptions = {}) {\n const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)\n const found = []\n\n for (const envPart of pathEnv) {\n const p = getPathPart(envPart, cmd)\n\n for (const ext of pathExt) {\n const withExt = p + ext\n const is = await isexe(withExt, {\n pathExt: pathExtExe,\n ignoreErrors: true,\n })\n if (is) {\n if (!opt.all) {\n return withExt\n }\n found.push(withExt)\n }\n }\n }\n\n if (opt.all && found.length) {\n return found\n }\n\n if (opt.nothrow) {\n return null\n }\n\n throw getNotFoundError(cmd)\n}\n\nexport function whichSync(cmd: string): string\nexport function whichSync(\n cmd: string,\n opt: WhichOptionsFindAllNoThrow,\n): string[] | null\nexport function whichSync(\n cmd: string,\n opt: WhichOptionsFindOneNoThrow,\n): string | null\nexport function whichSync(\n cmd: string,\n opt: WhichOptionsFindAllThrow,\n): string[]\nexport function whichSync(\n cmd: string,\n opt: WhichOptionsFindOneThrow,\n): string\nexport function whichSync(\n cmd: string,\n opt: WhichOptionsFindOne,\n): string | null\nexport function whichSync(\n cmd: string,\n opt: WhichOptionsNoThrow,\n): string[] | string | null\nexport function whichSync(\n cmd: string,\n opt: WhichOptionsFindAll,\n): string[] | null\nexport function whichSync(\n cmd: string,\n opt?: WhichOptions,\n): string[] | string | null\nexport function whichSync(cmd: string, opt: WhichOptions = {}) {\n const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt)\n const found = []\n\n for (const pathEnvPart of pathEnv) {\n const p = getPathPart(pathEnvPart, cmd)\n\n for (const ext of pathExt) {\n const withExt = p + ext\n const is = isexeSync(withExt, {\n pathExt: pathExtExe,\n ignoreErrors: true,\n })\n if (is) {\n if (!opt.all) {\n return withExt\n }\n found.push(withExt)\n }\n }\n }\n\n if (opt.all && found.length) {\n return found\n }\n\n if (opt.nothrow) {\n return null\n }\n\n throw getNotFoundError(cmd)\n}\n"]}