@arcgis/node-toolkit 5.2.0-next.100
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.md +19 -0
- package/README.md +12 -0
- package/dist/file.d.ts +37 -0
- package/dist/file.js +49 -0
- package/dist/glob.d.ts +28 -0
- package/dist/glob.js +28 -0
- package/dist/packageJson.d.ts +104 -0
- package/dist/packageJson.js +58 -0
- package/dist/path.d.ts +60 -0
- package/dist/path.js +48 -0
- package/dist/shell.d.ts +115 -0
- package/dist/shell.js +160 -0
- package/dist/vite/externalizeDependenciesPlugin.d.ts +96 -0
- package/dist/vite/externalizeDependenciesPlugin.js +104 -0
- package/dist/vite/installPlaywright.d.ts +3 -0
- package/dist/vite/installPlaywright.js +87 -0
- package/dist/vite/presetPlugin.d.ts +21 -0
- package/dist/vite/presetPlugin.js +76 -0
- package/dist/vite/simpleTypesEmit.d.ts +19 -0
- package/dist/vite/simpleTypesEmit.js +76 -0
- package/dist/vite/typeScript.d.ts +21 -0
- package/dist/vite/typeScript.js +40 -0
- package/dist/workspace.d.ts +62 -0
- package/dist/workspace.js +78 -0
- package/package.json +32 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Licensing
|
|
2
|
+
|
|
3
|
+
COPYRIGHT Esri
|
|
4
|
+
|
|
5
|
+
All rights reserved under the copyright laws of the United States and applicable international laws, treaties, and conventions.
|
|
6
|
+
|
|
7
|
+
This material is licensed for use under the Esri Master License Agreement (MLA), and is bound by the terms of that agreement.
|
|
8
|
+
You may redistribute and use this code without modification, provided you adhere to the terms of the MLA and include this copyright notice.
|
|
9
|
+
|
|
10
|
+
See use restrictions at https://www.esri.com/content/dam/esrisites/en-us/media/legal/ma-full/ma-full.pdf.
|
|
11
|
+
|
|
12
|
+
For additional information, contact:
|
|
13
|
+
Environmental Systems Research Institute, Inc.
|
|
14
|
+
Attn: Contracts and Legal Services Department
|
|
15
|
+
380 New York Street
|
|
16
|
+
Redlands, California, USA 92373
|
|
17
|
+
USA
|
|
18
|
+
|
|
19
|
+
email: legal@esri.com
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# ArcGIS Maps SDK for JavaScript - Node Utils
|
|
2
|
+
|
|
3
|
+
**No Esri Technical Support included.**
|
|
4
|
+
|
|
5
|
+
Package that is part of the [ArcGIS Maps SDK for JavaScript](https://developers.arcgis.com/javascript).
|
|
6
|
+
|
|
7
|
+
It is not intended to be used directly, but rather used as a dependency by other packages in the SDK.
|
|
8
|
+
|
|
9
|
+
## License
|
|
10
|
+
|
|
11
|
+
This package is licensed under the terms described in the `LICENSE.md` file, located in the root of the package, and at https://js.arcgis.com/5.2/LICENSE.txt.
|
|
12
|
+
For third party notices, see https://js.arcgis.com/5.2/third-party-notices.txt.
|
package/dist/file.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously check if a file or directory exists.
|
|
3
|
+
* Using un-promisified version because promises version creates exceptions
|
|
4
|
+
* which interferes with debugging when "Pause on caught exceptions" is enabled
|
|
5
|
+
*
|
|
6
|
+
* @public
|
|
7
|
+
* @param file
|
|
8
|
+
*/
|
|
9
|
+
export declare const existsAsync: (file: string) => Promise<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Create a file with the specified content if it does not already exist.
|
|
12
|
+
*
|
|
13
|
+
* @public
|
|
14
|
+
* @param filePath
|
|
15
|
+
* @param content
|
|
16
|
+
*/
|
|
17
|
+
export declare function createFileIfNotExists(filePath: string, content: string): Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Climb the directory tree upward, until it founds a directory that contains the
|
|
20
|
+
* target file, and return resulting full path.
|
|
21
|
+
* Returns `undefined` if the file is not found.
|
|
22
|
+
*
|
|
23
|
+
* @public
|
|
24
|
+
* @param target
|
|
25
|
+
* @param startDirectory
|
|
26
|
+
*/
|
|
27
|
+
export declare function findPath(target: string, startDirectory?: string): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Asynchronously climb the directory tree upward, until it founds a directory that contains the
|
|
30
|
+
* target file, and return resulting full path.
|
|
31
|
+
* Returns `undefined` if the file is not found.
|
|
32
|
+
*
|
|
33
|
+
* @public
|
|
34
|
+
* @param target
|
|
35
|
+
* @param startDirectory
|
|
36
|
+
*/
|
|
37
|
+
export declare function asyncFindPath(target: string, startDirectory?: string): Promise<string | undefined>;
|
package/dist/file.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { access, existsSync } from "node:fs";
|
|
2
|
+
import { constants, mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import { dirname, resolve, sep, join } from "path";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
const existsAsync = async (file) => (
|
|
6
|
+
//#endregion existsAsync
|
|
7
|
+
await new Promise((resolve2) => access(file, constants.F_OK, (error) => resolve2(!error)))
|
|
8
|
+
);
|
|
9
|
+
async function createFileIfNotExists(filePath, content) {
|
|
10
|
+
await mkdir(dirname(filePath), { recursive: true });
|
|
11
|
+
if (!await existsAsync(filePath)) {
|
|
12
|
+
await writeFile(filePath, content, { encoding: "utf8" });
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function* getSearchCandidates(target, startDirectory) {
|
|
16
|
+
const resolvedStartDirectory = startDirectory.startsWith("file:///") ? dirname(fileURLToPath(startDirectory)) : resolve(startDirectory);
|
|
17
|
+
const parentPath = resolvedStartDirectory.split(sep);
|
|
18
|
+
while (parentPath.length > searchStopIndex) {
|
|
19
|
+
yield join(
|
|
20
|
+
...sep === "/" ? ["/"] : [],
|
|
21
|
+
...parentPath,
|
|
22
|
+
target
|
|
23
|
+
);
|
|
24
|
+
parentPath.pop();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function findPath(target, startDirectory = process.cwd()) {
|
|
28
|
+
for (const fullPath of getSearchCandidates(target, startDirectory)) {
|
|
29
|
+
if (existsSync(fullPath)) {
|
|
30
|
+
return fullPath;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
const searchStopIndex = 0;
|
|
36
|
+
async function asyncFindPath(target, startDirectory = process.cwd()) {
|
|
37
|
+
for (const fullPath of getSearchCandidates(target, startDirectory)) {
|
|
38
|
+
if (await existsAsync(fullPath)) {
|
|
39
|
+
return fullPath;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return void 0;
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
asyncFindPath,
|
|
46
|
+
createFileIfNotExists,
|
|
47
|
+
existsAsync,
|
|
48
|
+
findPath
|
|
49
|
+
};
|
package/dist/glob.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Read `.gitignore` files and convert it to globs that are accepted by ESLint
|
|
3
|
+
*
|
|
4
|
+
* @public
|
|
5
|
+
* @param filePath
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* // eslint.config.js
|
|
9
|
+
* import { gitIgnoreFileToGlobs } from "@arcgis/node-toolkit/glob";
|
|
10
|
+
* import { globalIgnores } from "eslint/config";
|
|
11
|
+
*
|
|
12
|
+
* export default [
|
|
13
|
+
* globalIgnores([
|
|
14
|
+
* ...gitIgnoreFileToGlobs(import.meta.dirname + "/.gitignore"),
|
|
15
|
+
* ...gitIgnoreFileToGlobs(import.meta.dirname + "/.prettierignore"),
|
|
16
|
+
* ]),
|
|
17
|
+
* // ...
|
|
18
|
+
* ];
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare function gitIgnoreFileToGlobs(filePath: string): string[];
|
|
22
|
+
/**
|
|
23
|
+
* @public
|
|
24
|
+
* @param pattern
|
|
25
|
+
* @deprecated Use gitIgnoreFileToGlobs from "@arcgis/node-toolkit/glob"
|
|
26
|
+
* instead
|
|
27
|
+
*/
|
|
28
|
+
export declare const gitIgnoreToGlob: (pattern: string) => string;
|
package/dist/glob.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
function gitIgnoreFileToGlobs(filePath) {
|
|
3
|
+
return readFileSync(filePath, "utf8").split("\n").filter((line) => line.trim().length > 0 && !line.trim().startsWith("#")).map(gitIgnoreToGlob);
|
|
4
|
+
}
|
|
5
|
+
const gitIgnoreToGlob = (pattern) => fixAbsoluteSyntax(fixMatchFilesSyntax(pattern.trim()));
|
|
6
|
+
function fixAbsoluteSyntax(pattern) {
|
|
7
|
+
if (pattern.startsWith("/")) {
|
|
8
|
+
return pattern.slice(1);
|
|
9
|
+
}
|
|
10
|
+
if (pattern.startsWith("!/")) {
|
|
11
|
+
return `!${pattern.slice(2)}`;
|
|
12
|
+
}
|
|
13
|
+
const isAlreadyCorrect = pattern.startsWith("**") || pattern.startsWith("!**");
|
|
14
|
+
const basePattern = pattern.startsWith("!") ? pattern.slice(1) : pattern;
|
|
15
|
+
return isAlreadyCorrect ? pattern : `${pattern.startsWith("!") ? "!" : ""}**/${basePattern}`;
|
|
16
|
+
}
|
|
17
|
+
function fixMatchFilesSyntax(pattern) {
|
|
18
|
+
const base = pattern.split("/").at(-1);
|
|
19
|
+
const isAlreadyCorrect = pattern.endsWith("**") || pattern.includes("{") || base?.includes(".");
|
|
20
|
+
if (isAlreadyCorrect) {
|
|
21
|
+
return pattern;
|
|
22
|
+
}
|
|
23
|
+
return pattern.endsWith("/*") ? `${pattern}*` : pattern.endsWith("/") ? `${pattern}**` : `${pattern}/**`;
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
gitIgnoreFileToGlobs,
|
|
27
|
+
gitIgnoreToGlob
|
|
28
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A subset of the package.json typing.
|
|
3
|
+
* Useful for the majority of cases where you just need to read the name, version, and dependencies of a package.json file.
|
|
4
|
+
*
|
|
5
|
+
* The full package.json type is insanely large (20k lines):
|
|
6
|
+
* https://github.com/ffflorian/schemastore-updater/blob/main/schemas/package/index.d.ts#L20067
|
|
7
|
+
*
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export type PackageJson = {
|
|
11
|
+
/** @public */
|
|
12
|
+
"name": string;
|
|
13
|
+
/** @public */
|
|
14
|
+
"version": string;
|
|
15
|
+
/** @public */
|
|
16
|
+
"private"?: boolean;
|
|
17
|
+
/** @public */
|
|
18
|
+
"type"?: "commonjs" | "module";
|
|
19
|
+
/** @public */
|
|
20
|
+
"main"?: string;
|
|
21
|
+
/** @public */
|
|
22
|
+
"module"?: string;
|
|
23
|
+
/** @public */
|
|
24
|
+
"types"?: string;
|
|
25
|
+
/** @public */
|
|
26
|
+
"files"?: string[];
|
|
27
|
+
/** @public */
|
|
28
|
+
"bin"?: Record<string, string> | string;
|
|
29
|
+
/** @public */
|
|
30
|
+
"man"?: string[] | string;
|
|
31
|
+
/**
|
|
32
|
+
* @public
|
|
33
|
+
* @see https://pnpm.io/package_json#publishconfigdirectory
|
|
34
|
+
*/
|
|
35
|
+
"publishConfig"?: {
|
|
36
|
+
directory?: string;
|
|
37
|
+
linkDirectory?: boolean;
|
|
38
|
+
};
|
|
39
|
+
/** @public */
|
|
40
|
+
"dependencies"?: Record<string, string>;
|
|
41
|
+
/** @public */
|
|
42
|
+
"devDependencies"?: Record<string, string>;
|
|
43
|
+
/** @public */
|
|
44
|
+
"peerDependencies"?: Record<string, string>;
|
|
45
|
+
/** @public */
|
|
46
|
+
"peerDependenciesMeta"?: Record<string, {
|
|
47
|
+
optional?: boolean;
|
|
48
|
+
}>;
|
|
49
|
+
/** @public */
|
|
50
|
+
"optionalDependencies"?: Record<string, string>;
|
|
51
|
+
/** @public */
|
|
52
|
+
"css.customData"?: string[];
|
|
53
|
+
/** @public */
|
|
54
|
+
"customElements"?: string;
|
|
55
|
+
/** @public */
|
|
56
|
+
"html.customData"?: string[];
|
|
57
|
+
/** @public */
|
|
58
|
+
"web-types"?: string;
|
|
59
|
+
/** @public */
|
|
60
|
+
"exports"?: Record<string, Record<string, string> | string>;
|
|
61
|
+
/** @public */
|
|
62
|
+
"engines"?: {
|
|
63
|
+
node?: string;
|
|
64
|
+
};
|
|
65
|
+
/** @public */
|
|
66
|
+
"scripts"?: Record<string, string>;
|
|
67
|
+
/** @public */
|
|
68
|
+
"packageManager"?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Synchronously retrieves the package.json file for the current project or a specified location.
|
|
72
|
+
* If the location is not specified, it will search for the package.json file starting from the current working directory.
|
|
73
|
+
* This function caches the package.json file for future calls to avoid unnecessary file system reads.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
* @param location
|
|
77
|
+
*/
|
|
78
|
+
export declare function retrievePackageJson(location?: string): PackageJson;
|
|
79
|
+
/**
|
|
80
|
+
* Asynchronously retrieves the package.json file for the current project or a specified location.
|
|
81
|
+
* If the location is not specified, it will search for the package.json file starting from the current working directory.
|
|
82
|
+
* This function caches the package.json file for future calls to avoid unnecessary file system reads.
|
|
83
|
+
*
|
|
84
|
+
* @public
|
|
85
|
+
* @param location
|
|
86
|
+
*/
|
|
87
|
+
export declare function asyncRetrievePackageJson(location?: string): Promise<PackageJson>;
|
|
88
|
+
/**
|
|
89
|
+
* Returns an absolute path to the root of a package in node_modules, without
|
|
90
|
+
* trailing slash.
|
|
91
|
+
*
|
|
92
|
+
* @public
|
|
93
|
+
* @param packageName
|
|
94
|
+
* @param cwd
|
|
95
|
+
*/
|
|
96
|
+
export declare function fetchPackageLocation(packageName: string, cwd?: string): Promise<string>;
|
|
97
|
+
/**
|
|
98
|
+
* Find the package.json for a given package name in node_modules, and return the parsed JSON.
|
|
99
|
+
* Returns undefined if the package.json cannot be found.
|
|
100
|
+
*
|
|
101
|
+
* @public
|
|
102
|
+
* @param packageName
|
|
103
|
+
*/
|
|
104
|
+
export declare function findPackageJson(packageName: string): PackageJson | undefined;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
import { path } from "./path.js";
|
|
3
|
+
import { asyncFindPath, findPath } from "./file.js";
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
const cachedPackageJson = {};
|
|
6
|
+
const cachedPackageJsonPromises = {};
|
|
7
|
+
let rootPackageJsonLocation;
|
|
8
|
+
function retrievePackageJson(location) {
|
|
9
|
+
const packageJsonPath = getPackageJsonPath(location);
|
|
10
|
+
cachedPackageJson[packageJsonPath] ??= JSON.parse(readFileSync(packageJsonPath, "utf-8"));
|
|
11
|
+
return cachedPackageJson[packageJsonPath];
|
|
12
|
+
}
|
|
13
|
+
async function asyncRetrievePackageJson(location) {
|
|
14
|
+
const packageJsonPath = getPackageJsonPath(location);
|
|
15
|
+
if (packageJsonPath in cachedPackageJson) {
|
|
16
|
+
return cachedPackageJson[packageJsonPath];
|
|
17
|
+
}
|
|
18
|
+
cachedPackageJsonPromises[packageJsonPath] ??= asyncReadPackageJson(packageJsonPath);
|
|
19
|
+
const result = await cachedPackageJsonPromises[packageJsonPath];
|
|
20
|
+
cachedPackageJson[packageJsonPath] ??= result;
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
const getPackageJsonPath = (location) => location ? path.resolve(location, "package.json") : rootPackageJsonLocation ??= findPath("package.json");
|
|
24
|
+
const asyncReadPackageJson = async (location) => JSON.parse(await readFile(location, "utf-8"));
|
|
25
|
+
const cachedPackageLocation = {};
|
|
26
|
+
const cachedPackageLocationPromises = {};
|
|
27
|
+
async function fetchPackageLocation(packageName, cwd) {
|
|
28
|
+
if (packageName in cachedPackageLocation) {
|
|
29
|
+
return cachedPackageLocation[packageName];
|
|
30
|
+
}
|
|
31
|
+
cachedPackageLocationPromises[packageName] ??= asyncFindPath(
|
|
32
|
+
path.join("node_modules", packageName, "package.json"),
|
|
33
|
+
cwd
|
|
34
|
+
).then((packageJsonLocation) => {
|
|
35
|
+
if (packageJsonLocation === void 0) {
|
|
36
|
+
throw Error(
|
|
37
|
+
`@arcgis/node-toolkit: Unable to resolve package.json location for "${packageName}" package. Current working directory: ${process.cwd()}`
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return path.dirname(packageJsonLocation);
|
|
41
|
+
});
|
|
42
|
+
const result = await cachedPackageLocationPromises[packageName];
|
|
43
|
+
cachedPackageLocation[packageName] ??= result;
|
|
44
|
+
return cachedPackageLocation[packageName];
|
|
45
|
+
}
|
|
46
|
+
function findPackageJson(packageName) {
|
|
47
|
+
const path2 = findPath(`node_modules/${packageName}/`);
|
|
48
|
+
if (!path2) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
return retrievePackageJson(path2);
|
|
52
|
+
}
|
|
53
|
+
export {
|
|
54
|
+
asyncRetrievePackageJson,
|
|
55
|
+
fetchPackageLocation,
|
|
56
|
+
findPackageJson,
|
|
57
|
+
retrievePackageJson
|
|
58
|
+
};
|
package/dist/path.d.ts
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* See ../path.md for details about our path handling.
|
|
3
|
+
*
|
|
4
|
+
* DOCS: publish to webgis reference docs for this package, and the ./path.md file
|
|
5
|
+
*/
|
|
6
|
+
import { posix } from "path";
|
|
7
|
+
/**
|
|
8
|
+
* Determines if the current environment is POSIX (e.g., macOS, Linux) or not.
|
|
9
|
+
* This is called "isPosix" rather than "isNotWindows" because even if we are
|
|
10
|
+
* on Windows, we could be running in a POSIX environment (e.g. WSL2)
|
|
11
|
+
*
|
|
12
|
+
* @public
|
|
13
|
+
*/
|
|
14
|
+
export declare const isPosix: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Converts a Windows-style path to a POSIX-style path.
|
|
17
|
+
*
|
|
18
|
+
* @public
|
|
19
|
+
* @param relativePath The path to convert to POSIX-style separators.
|
|
20
|
+
*/
|
|
21
|
+
export declare const toPosixPathSeparators: (relativePath: string) => string;
|
|
22
|
+
/**
|
|
23
|
+
* Normalizes the path separators for the current runtime environment.
|
|
24
|
+
* On POSIX systems, this function returns the path unchanged.
|
|
25
|
+
* On Windows systems, it converts all `\` separators to `/`.
|
|
26
|
+
*
|
|
27
|
+
* @public
|
|
28
|
+
* @param path The path to normalize.
|
|
29
|
+
*/
|
|
30
|
+
export declare const normalizePath: (relativePath: string) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a POSIX-style path to a Windows-style path.
|
|
33
|
+
* On Windows, replace all `/` in the path back with `\\`. Do this only if you
|
|
34
|
+
* wish to output the path in the console or error message.
|
|
35
|
+
* On POSIX system (macOS, Linux, ...), this does not change the path (because
|
|
36
|
+
* inside the compiler we use `/` everywhere).
|
|
37
|
+
*
|
|
38
|
+
* @public
|
|
39
|
+
* @param relativePath
|
|
40
|
+
*/
|
|
41
|
+
export declare const toSystemPathSeparators: (relativePath: string) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Like `process.cwd()`, but always returns a POSIX-style path
|
|
44
|
+
* (with `/` as separator).
|
|
45
|
+
*
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
export declare const getCwd: () => string;
|
|
49
|
+
/**
|
|
50
|
+
* A wrapper for Node.js's `path` module that always uses POSIX-style paths
|
|
51
|
+
* (with `/` as separator).
|
|
52
|
+
*
|
|
53
|
+
* @public
|
|
54
|
+
*/
|
|
55
|
+
export declare const path: typeof posix & {
|
|
56
|
+
sep: "/";
|
|
57
|
+
};
|
|
58
|
+
export declare const exportsForTests: {
|
|
59
|
+
toWin32PathSeparators: (relativePath: string) => string;
|
|
60
|
+
};
|
package/dist/path.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { sep, posix, win32 } from "path";
|
|
2
|
+
const isPosix = sep === posix.sep;
|
|
3
|
+
const toPosixPathSeparators = (relativePath) => (
|
|
4
|
+
//#endregion toPosixPathSeparators
|
|
5
|
+
relativePath.includes(win32.sep) ? relativePath.replaceAll(win32.sep, posix.sep) : relativePath
|
|
6
|
+
);
|
|
7
|
+
const normalizePath = isPosix ? (path2) => path2 : toPosixPathSeparators;
|
|
8
|
+
const toWin32PathSeparators = (relativePath) => relativePath.includes(posix.sep) ? relativePath.replaceAll(posix.sep, win32.sep) : relativePath;
|
|
9
|
+
const toSystemPathSeparators = isPosix ? (relativePath) => relativePath : toWin32PathSeparators;
|
|
10
|
+
const getCwd = isPosix ? process.cwd : () => toPosixPathSeparators(process.cwd());
|
|
11
|
+
const path = isPosix ? posix : {
|
|
12
|
+
...win32,
|
|
13
|
+
sep: posix.sep,
|
|
14
|
+
join(...paths) {
|
|
15
|
+
const result = win32.join(...paths);
|
|
16
|
+
return toPosixPathSeparators(result);
|
|
17
|
+
},
|
|
18
|
+
normalize(path2) {
|
|
19
|
+
const result = win32.normalize(path2);
|
|
20
|
+
return toPosixPathSeparators(result);
|
|
21
|
+
},
|
|
22
|
+
relative(from, to) {
|
|
23
|
+
const result = win32.relative(from, to);
|
|
24
|
+
return toPosixPathSeparators(result);
|
|
25
|
+
},
|
|
26
|
+
dirname(path2) {
|
|
27
|
+
const result = win32.dirname(path2);
|
|
28
|
+
return toPosixPathSeparators(result);
|
|
29
|
+
},
|
|
30
|
+
resolve(...paths) {
|
|
31
|
+
const result = win32.resolve(...paths);
|
|
32
|
+
return toPosixPathSeparators(result);
|
|
33
|
+
},
|
|
34
|
+
toNamespacedPath(path2) {
|
|
35
|
+
const result = win32.toNamespacedPath(path2);
|
|
36
|
+
return toPosixPathSeparators(result);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const exportsForTests = { toWin32PathSeparators };
|
|
40
|
+
export {
|
|
41
|
+
exportsForTests,
|
|
42
|
+
getCwd,
|
|
43
|
+
isPosix,
|
|
44
|
+
normalizePath,
|
|
45
|
+
path,
|
|
46
|
+
toPosixPathSeparators,
|
|
47
|
+
toSystemPathSeparators
|
|
48
|
+
};
|
package/dist/shell.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { type ExecOptionsWithStringEncoding, type ExecSyncOptionsWithStringEncoding, type SpawnSyncOptionsWithStringEncoding, type SpawnOptions } from "node:child_process";
|
|
2
|
+
/** @public */
|
|
3
|
+
type SyncProcessOptions = Omit<SpawnSyncOptionsWithStringEncoding, "stdio">;
|
|
4
|
+
/** @public */
|
|
5
|
+
type CollectOutputSyncOptions = SyncProcessOptions & {
|
|
6
|
+
/** @public */
|
|
7
|
+
stderr?: "ignore" | "inherit";
|
|
8
|
+
};
|
|
9
|
+
/** @public */
|
|
10
|
+
type AsyncProcessOptions = SpawnOptions & {
|
|
11
|
+
/** @public */
|
|
12
|
+
input?: NonNullable<SpawnSyncOptionsWithStringEncoding["input"]>;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Synchronously execute a shell command and return the output.
|
|
16
|
+
*
|
|
17
|
+
* Prefer {@link shell!runCommandSync} for command-only execution, or {@link shell!collectOutputSync}
|
|
18
|
+
* when you need to capture stdout. {@link shell!sh} goes through a shell, which
|
|
19
|
+
* requires careful escaping and can mis-handle dynamic input with spaces or
|
|
20
|
+
* shell metacharacters.
|
|
21
|
+
*
|
|
22
|
+
* Use {@link shell!sh} only when shell features are intentionally required, such as
|
|
23
|
+
* pipes, redirects, `&&`, or command substitution.
|
|
24
|
+
*
|
|
25
|
+
* Example (shell features required):
|
|
26
|
+
* `sh("pnpm list | grep @arcgis/core")`
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
* @param command
|
|
30
|
+
* @param options
|
|
31
|
+
*/
|
|
32
|
+
export declare function sh(command: string, options?: Partial<ExecSyncOptionsWithStringEncoding>): string;
|
|
33
|
+
/**
|
|
34
|
+
* Asynchronously execute a shell command and return the output.
|
|
35
|
+
*
|
|
36
|
+
* Prefer {@link shell!runCommand} for command-only execution, or {@link shell!collectOutput}
|
|
37
|
+
* when you need to capture stdout. {@link shell!asyncSh} executes through a shell,
|
|
38
|
+
* so callers must handle shell escaping and quoting correctly.
|
|
39
|
+
*
|
|
40
|
+
* Use {@link shell!asyncSh} only when shell syntax is intentionally needed.
|
|
41
|
+
*
|
|
42
|
+
* Example (shell features required):
|
|
43
|
+
* `await asyncSh("pnpm list | grep @arcgis/core")`
|
|
44
|
+
*
|
|
45
|
+
* @param command
|
|
46
|
+
* @param options
|
|
47
|
+
*/
|
|
48
|
+
export declare function asyncSh(command: string, options?: Partial<ExecOptionsWithStringEncoding>): Promise<string>;
|
|
49
|
+
/**
|
|
50
|
+
* Synchronously execute a command without shell interpolation and return the output.
|
|
51
|
+
*
|
|
52
|
+
* This is usually safer than {@link shell!sh} because arguments are passed as
|
|
53
|
+
* discrete tokens, which avoids most shell escaping issues and command
|
|
54
|
+
* injection pitfalls.
|
|
55
|
+
*
|
|
56
|
+
* Example:
|
|
57
|
+
* `sp("git", ["show", `${baseRef}:pnpm-workspace.yaml`])`
|
|
58
|
+
*
|
|
59
|
+
* Avoid {@link shell!sp} only when you explicitly need shell features.
|
|
60
|
+
* @public
|
|
61
|
+
* @deprecated Use {@link shell!collectOutputSync} or {@link shell!runCommandSync} instead.
|
|
62
|
+
* @param command
|
|
63
|
+
* @param args
|
|
64
|
+
* @param options
|
|
65
|
+
*/
|
|
66
|
+
export declare function sp(command: string, args: string[], options?: Partial<SpawnSyncOptionsWithStringEncoding>): string;
|
|
67
|
+
/**
|
|
68
|
+
* Synchronously execute a command and stream output to the current process.
|
|
69
|
+
* Note 1:
|
|
70
|
+
* `pnpm` command will be automatically invoked with `shell: process.platform === "win32"`
|
|
71
|
+
* if the `shell` option is not explicitly provided.
|
|
72
|
+
* Note 2:
|
|
73
|
+
* If the `input` option is provided, it will be piped to the child process's stdin.
|
|
74
|
+
*
|
|
75
|
+
* @public
|
|
76
|
+
* @param command
|
|
77
|
+
* @param args
|
|
78
|
+
* @param options
|
|
79
|
+
*/
|
|
80
|
+
export declare function runCommandSync(command: string, args: string[], options?: Partial<SyncProcessOptions>): void;
|
|
81
|
+
/**
|
|
82
|
+
* Asynchronously execute a command and stream output to the current process.
|
|
83
|
+
* Note 1:
|
|
84
|
+
* `pnpm` command will be automatically invoked with `shell: process.platform === "win32"`
|
|
85
|
+
* if the `shell` option is not explicitly provided.
|
|
86
|
+
* Note 2:
|
|
87
|
+
* If the `input` option is provided, it will be piped to the child process's stdin.
|
|
88
|
+
*
|
|
89
|
+
* @public
|
|
90
|
+
* @param command
|
|
91
|
+
* @param args
|
|
92
|
+
* @param options
|
|
93
|
+
*/
|
|
94
|
+
export declare function runCommand(command: string, args: string[], options?: Partial<AsyncProcessOptions>): Promise<void>;
|
|
95
|
+
/**
|
|
96
|
+
* Synchronously execute a command and collect stdout while streaming stderr.
|
|
97
|
+
* Note that `pnpm` command will be automatically invoked with `shell: process.platform === "win32"`.
|
|
98
|
+
*
|
|
99
|
+
* @public
|
|
100
|
+
* @param command
|
|
101
|
+
* @param args
|
|
102
|
+
* @param options
|
|
103
|
+
*/
|
|
104
|
+
export declare function collectOutputSync(command: string, args: string[], options?: Partial<CollectOutputSyncOptions>): string;
|
|
105
|
+
/**
|
|
106
|
+
* Asynchronously execute a command and collect stdout while streaming stderr.
|
|
107
|
+
* Note that `pnpm` command will be automatically invoked with `shell: process.platform === "win32"`.
|
|
108
|
+
*
|
|
109
|
+
* @public
|
|
110
|
+
* @param command
|
|
111
|
+
* @param args
|
|
112
|
+
* @param options
|
|
113
|
+
*/
|
|
114
|
+
export declare function collectOutput(command: string, args: string[], options?: Partial<AsyncProcessOptions>): Promise<string>;
|
|
115
|
+
export {};
|