@arcgis/components-build-utils 4.31.0-next.112

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 ADDED
@@ -0,0 +1,13 @@
1
+ # Licensing
2
+
3
+ COPYRIGHT © 2024 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. You may redistribute and use this code without modification, provided you adhere to the terms of the MLA and include this copyright notice.
8
+
9
+ See use restrictions at http://www.esri.com/legal/pdfs/mla_e204_e300/english
10
+
11
+ For additional information, contact: Environmental Systems Research Institute, Inc. Attn: Contracts and Legal Services Department 380 New York Street Redlands, California, USA 92373 USA
12
+
13
+ email: contracts@esri.com
package/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # ArcGIS Maps SDK for JavaScript - Components Build Utilities
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
+ COPYRIGHT © 2024 Esri
12
+
13
+ All rights reserved under the copyright laws of the United States and applicable international laws, treaties, and conventions.
14
+
15
+ This material is licensed for use under the Esri Master License Agreement (MLA), and is bound by the terms of that agreement. You may redistribute and use this code without modification, provided you adhere to the terms of the MLA and include this copyright notice.
16
+
17
+ See use restrictions at <http://www.esri.com/legal/pdfs/mla_e204_e300/english>
18
+
19
+ For additional information, contact: Environmental Systems Research Institute, Inc. Attn: Contracts and Legal Services Department 380 New York Street Redlands, California, USA 92373 USA
20
+
21
+ email: contracts@esri.com
package/dist/index.cjs ADDED
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ asyncFindPath: () => asyncFindPath,
34
+ asyncRetrievePackageJson: () => asyncRetrievePackageJson,
35
+ createFileIfNotExists: () => createFileIfNotExists,
36
+ detectPackageManager: () => detectPackageManager,
37
+ existsAsync: () => existsAsync,
38
+ exportsForTests: () => exportsForTests,
39
+ fetchPackageLocation: () => fetchPackageLocation,
40
+ findPath: () => findPath,
41
+ getCwd: () => getCwd,
42
+ isPosix: () => isPosix,
43
+ path: () => path,
44
+ retrievePackageJson: () => retrievePackageJson,
45
+ sh: () => sh,
46
+ toPosixPathSeparators: () => toPosixPathSeparators,
47
+ toSystemPathSeparators: () => toSystemPathSeparators
48
+ });
49
+ module.exports = __toCommonJS(src_exports);
50
+ var import_node_fs3 = require("fs");
51
+ var import_node_path = require("path");
52
+
53
+ // src/file.ts
54
+ var import_node_fs = require("fs");
55
+ var import_promises = require("fs/promises");
56
+ var import_node_child_process = require("child_process");
57
+ var import_path = require("path");
58
+ var import_node_url = require("url");
59
+ var existsAsync = async (file) => await (0, import_promises.access)(file, import_promises.constants.F_OK).then(() => true).catch(() => false);
60
+ var sh = (command, cwd) => (0, import_node_child_process.execSync)(command.trim(), { encoding: "utf8", cwd }).trim();
61
+ async function createFileIfNotExists(filePath, content) {
62
+ await (0, import_promises.mkdir)((0, import_path.dirname)(filePath), { recursive: true });
63
+ if (!await existsAsync(filePath)) {
64
+ await (0, import_promises.writeFile)(filePath, content, { encoding: "utf8" });
65
+ }
66
+ }
67
+ function findPath(target, startDirectory = process.cwd()) {
68
+ const resolvedStartDirectory = startDirectory.startsWith("file:///") ? (0, import_path.dirname)((0, import_node_url.fileURLToPath)(startDirectory)) : (0, import_path.resolve)(startDirectory);
69
+ const parentPath = resolvedStartDirectory.split(import_path.sep);
70
+ while (parentPath.length > 2) {
71
+ const fullPath = (0, import_path.join)(
72
+ ...import_path.sep === "/" ? ["/"] : [],
73
+ ...parentPath,
74
+ target
75
+ );
76
+ if ((0, import_node_fs.existsSync)(fullPath)) {
77
+ return fullPath;
78
+ }
79
+ parentPath.pop();
80
+ }
81
+ return void 0;
82
+ }
83
+ async function asyncFindPath(target, startDirectory = process.cwd()) {
84
+ const resolvedStartDirectory = startDirectory.startsWith("file:///") ? (0, import_path.dirname)((0, import_node_url.fileURLToPath)(startDirectory)) : (0, import_path.resolve)(startDirectory);
85
+ const parentPath = resolvedStartDirectory.split(import_path.sep);
86
+ while (parentPath.length > 2) {
87
+ const fullPath = (0, import_path.join)(
88
+ ...import_path.sep === "/" ? ["/"] : [],
89
+ ...parentPath,
90
+ target
91
+ );
92
+ if (await existsAsync(fullPath)) {
93
+ return fullPath;
94
+ }
95
+ parentPath.pop();
96
+ }
97
+ return void 0;
98
+ }
99
+
100
+ // src/path.ts
101
+ var import_path2 = require("path");
102
+ var import_posix = __toESM(require("path/posix"), 1);
103
+ var import_win32 = __toESM(require("path/win32"), 1);
104
+ var isPosix = import_path2.sep === import_posix.default.sep;
105
+ var toPosixPathSeparators = (relativePath) => relativePath.includes(import_win32.default.sep) ? relativePath.replaceAll(import_win32.default.sep, import_posix.default.sep) : relativePath;
106
+ var toWin32PathSeparators = (relativePath) => relativePath.includes(import_posix.default.sep) ? relativePath.replaceAll(import_posix.default.sep, import_win32.default.sep) : relativePath;
107
+ var toSystemPathSeparators = isPosix ? (path2) => path2 : toWin32PathSeparators;
108
+ var getCwd = isPosix ? process.cwd : () => toPosixPathSeparators(process.cwd());
109
+ var path = isPosix ? import_posix.default : {
110
+ ...import_win32.default,
111
+ sep: import_posix.default.sep,
112
+ join(...paths) {
113
+ const result = import_win32.default.join(...paths);
114
+ return toPosixPathSeparators(result);
115
+ },
116
+ normalize(path2) {
117
+ const result = import_win32.default.normalize(path2);
118
+ return toPosixPathSeparators(result);
119
+ },
120
+ relative(from, to) {
121
+ const result = import_win32.default.relative(from, to);
122
+ return toPosixPathSeparators(result);
123
+ },
124
+ dirname(path2) {
125
+ const result = import_win32.default.dirname(path2);
126
+ return toPosixPathSeparators(result);
127
+ },
128
+ resolve(...paths) {
129
+ const result = import_win32.default.resolve(...paths);
130
+ return toPosixPathSeparators(result);
131
+ },
132
+ toNamespacedPath(path2) {
133
+ const result = import_win32.default.toNamespacedPath(path2);
134
+ return toPosixPathSeparators(result);
135
+ }
136
+ };
137
+ var exportsForTests = { toWin32PathSeparators };
138
+
139
+ // src/packageJson.ts
140
+ var import_node_fs2 = require("fs");
141
+ var import_promises2 = require("fs/promises");
142
+ var cachedPackageJson = {};
143
+ var cachedPackageJsonPromises = {};
144
+ var rootPackageJsonLocation;
145
+ function retrievePackageJson(location) {
146
+ const packageJsonPath = location ? path.resolve(location, "package.json") : rootPackageJsonLocation ??= findPath("package.json");
147
+ cachedPackageJson[packageJsonPath] ??= JSON.parse((0, import_node_fs2.readFileSync)(packageJsonPath, "utf-8"));
148
+ return cachedPackageJson[packageJsonPath];
149
+ }
150
+ async function asyncRetrievePackageJson(location = getCwd()) {
151
+ const packageJsonPath = path.resolve(location, "package.json");
152
+ if (packageJsonPath in cachedPackageJson) {
153
+ return cachedPackageJson[packageJsonPath];
154
+ }
155
+ cachedPackageJsonPromises[packageJsonPath] ??= asyncReadPackageJson(packageJsonPath);
156
+ const result = await cachedPackageJsonPromises[packageJsonPath];
157
+ cachedPackageJson[packageJsonPath] ??= result;
158
+ return result;
159
+ }
160
+ var asyncReadPackageJson = async (location) => JSON.parse(await (0, import_promises2.readFile)(location, "utf-8"));
161
+ var cachedPackageLocation = {};
162
+ var cachedPackageLocationPromises = {};
163
+ async function fetchPackageLocation(packageName, cwd) {
164
+ if (packageName in cachedPackageLocation) {
165
+ return cachedPackageLocation[packageName];
166
+ }
167
+ cachedPackageLocationPromises[packageName] ??= asyncFindPath(
168
+ path.join("node_modules", packageName, "package.json"),
169
+ cwd
170
+ ).then((packageJsonLocation) => {
171
+ if (packageJsonLocation === void 0) {
172
+ throw new Error(
173
+ `@arcgis/lumina-compiler: Unable to resolve package.json location for "${packageName}" package. Current working directory: ${process.cwd()}`
174
+ );
175
+ }
176
+ return path.dirname(packageJsonLocation);
177
+ });
178
+ const result = await cachedPackageLocationPromises[packageName];
179
+ cachedPackageLocation[packageName] ??= result;
180
+ return cachedPackageLocation[packageName];
181
+ }
182
+
183
+ // src/index.ts
184
+ function detectPackageManager(cwd = process.cwd()) {
185
+ let packageManager = void 0;
186
+ {
187
+ const pathParts = cwd.split(import_node_path.sep);
188
+ while (pathParts.length > 1) {
189
+ const packageJson = (0, import_node_path.join)(pathParts.join(import_node_path.sep), "package.json");
190
+ pathParts.pop();
191
+ if (!(0, import_node_fs3.existsSync)(packageJson)) {
192
+ continue;
193
+ }
194
+ const contents = JSON.parse((0, import_node_fs3.readFileSync)(packageJson, "utf8"));
195
+ if (typeof contents !== "object" || Array.isArray(contents)) {
196
+ continue;
197
+ }
198
+ if (typeof contents.packageManager === "string") {
199
+ packageManager ??= contents.packageManager.match(/\w+/u)?.[0] ?? packageManager;
200
+ }
201
+ }
202
+ }
203
+ packageManager ??= "npm";
204
+ return packageManager;
205
+ }
206
+ // Annotate the CommonJS export names for ESM import in node:
207
+ 0 && (module.exports = {
208
+ asyncFindPath,
209
+ asyncRetrievePackageJson,
210
+ createFileIfNotExists,
211
+ detectPackageManager,
212
+ existsAsync,
213
+ exportsForTests,
214
+ fetchPackageLocation,
215
+ findPath,
216
+ getCwd,
217
+ isPosix,
218
+ path,
219
+ retrievePackageJson,
220
+ sh,
221
+ toPosixPathSeparators,
222
+ toSystemPathSeparators
223
+ });
@@ -0,0 +1,69 @@
1
+ import posix from 'path/posix';
2
+
3
+ declare const existsAsync: (file: string) => Promise<boolean>;
4
+ /** Wrapper for execSync to execute shell commands */
5
+ declare const sh: (command: string, cwd?: string) => string;
6
+ declare function createFileIfNotExists(filePath: string, content: string): Promise<void>;
7
+ /**
8
+ * Climb the directory tree upward, until found a directory that contains the
9
+ * target file, and return resulting full path
10
+ */
11
+ declare function findPath(target: string, startDirectory?: string): string | undefined;
12
+ /**
13
+ * Climb the directory tree upward, until found a directory that contains the
14
+ * target file, and return resulting full path
15
+ */
16
+ declare function asyncFindPath(target: string, startDirectory?: string): Promise<string | undefined>;
17
+
18
+ /**
19
+ * This is called "isPosix" rather than "isNotWindows" because even if we are
20
+ * on Windows, we could be running in a POSIX environment (e.g. WSL2)
21
+ */
22
+ declare const isPosix: boolean;
23
+ declare const toPosixPathSeparators: (relativePath: string) => string;
24
+ /**
25
+ * On Windows, replace all `/` in the path back with `\\`. Do this only if you
26
+ * wish to output the path in the console or error message.
27
+ * On POSIX system (macOS, Linux, ...), this does not change the path (because
28
+ * inside the compiler we use `/` everywhere).
29
+ */
30
+ declare const toSystemPathSeparators: (relativePath: string) => string;
31
+ declare const getCwd: () => string;
32
+ declare const path: typeof posix & {
33
+ sep: "/";
34
+ };
35
+ declare const exportsForTests: {
36
+ toWin32PathSeparators: (relativePath: string) => string;
37
+ };
38
+
39
+ /**
40
+ * A subset of the package.json typing that is interesting to Lumina.
41
+ *
42
+ * The full package.json type is insanely large (20k lines):
43
+ * https://github.com/ffflorian/schemastore-updater/blob/main/schemas/package/index.d.ts#L20067
44
+ */
45
+ type MiniPackageJson = {
46
+ "name": string;
47
+ "version": string;
48
+ "dependencies"?: Record<string, string>;
49
+ "devDependencies"?: Record<string, string>;
50
+ "peerDependencies"?: Record<string, string>;
51
+ "css.customData"?: string[];
52
+ "customElements"?: string;
53
+ "html.customData"?: string[];
54
+ "web-types"?: string;
55
+ };
56
+ declare function retrievePackageJson(location?: string): MiniPackageJson;
57
+ declare function asyncRetrievePackageJson(location?: string): Promise<MiniPackageJson>;
58
+ /**
59
+ * Returns an absolute path to the root of a package in node_modules, without
60
+ * trailing slash.
61
+ */
62
+ declare function fetchPackageLocation(packageName: string, cwd?: string): Promise<string>;
63
+
64
+ /**
65
+ * Detect if current repository/monorepo uses npm, yarn or pnpm
66
+ */
67
+ declare function detectPackageManager(cwd?: string): string;
68
+
69
+ export { type MiniPackageJson, asyncFindPath, asyncRetrievePackageJson, createFileIfNotExists, detectPackageManager, existsAsync, exportsForTests, fetchPackageLocation, findPath, getCwd, isPosix, path, retrievePackageJson, sh, toPosixPathSeparators, toSystemPathSeparators };
@@ -0,0 +1,69 @@
1
+ import posix from 'path/posix';
2
+
3
+ declare const existsAsync: (file: string) => Promise<boolean>;
4
+ /** Wrapper for execSync to execute shell commands */
5
+ declare const sh: (command: string, cwd?: string) => string;
6
+ declare function createFileIfNotExists(filePath: string, content: string): Promise<void>;
7
+ /**
8
+ * Climb the directory tree upward, until found a directory that contains the
9
+ * target file, and return resulting full path
10
+ */
11
+ declare function findPath(target: string, startDirectory?: string): string | undefined;
12
+ /**
13
+ * Climb the directory tree upward, until found a directory that contains the
14
+ * target file, and return resulting full path
15
+ */
16
+ declare function asyncFindPath(target: string, startDirectory?: string): Promise<string | undefined>;
17
+
18
+ /**
19
+ * This is called "isPosix" rather than "isNotWindows" because even if we are
20
+ * on Windows, we could be running in a POSIX environment (e.g. WSL2)
21
+ */
22
+ declare const isPosix: boolean;
23
+ declare const toPosixPathSeparators: (relativePath: string) => string;
24
+ /**
25
+ * On Windows, replace all `/` in the path back with `\\`. Do this only if you
26
+ * wish to output the path in the console or error message.
27
+ * On POSIX system (macOS, Linux, ...), this does not change the path (because
28
+ * inside the compiler we use `/` everywhere).
29
+ */
30
+ declare const toSystemPathSeparators: (relativePath: string) => string;
31
+ declare const getCwd: () => string;
32
+ declare const path: typeof posix & {
33
+ sep: "/";
34
+ };
35
+ declare const exportsForTests: {
36
+ toWin32PathSeparators: (relativePath: string) => string;
37
+ };
38
+
39
+ /**
40
+ * A subset of the package.json typing that is interesting to Lumina.
41
+ *
42
+ * The full package.json type is insanely large (20k lines):
43
+ * https://github.com/ffflorian/schemastore-updater/blob/main/schemas/package/index.d.ts#L20067
44
+ */
45
+ type MiniPackageJson = {
46
+ "name": string;
47
+ "version": string;
48
+ "dependencies"?: Record<string, string>;
49
+ "devDependencies"?: Record<string, string>;
50
+ "peerDependencies"?: Record<string, string>;
51
+ "css.customData"?: string[];
52
+ "customElements"?: string;
53
+ "html.customData"?: string[];
54
+ "web-types"?: string;
55
+ };
56
+ declare function retrievePackageJson(location?: string): MiniPackageJson;
57
+ declare function asyncRetrievePackageJson(location?: string): Promise<MiniPackageJson>;
58
+ /**
59
+ * Returns an absolute path to the root of a package in node_modules, without
60
+ * trailing slash.
61
+ */
62
+ declare function fetchPackageLocation(packageName: string, cwd?: string): Promise<string>;
63
+
64
+ /**
65
+ * Detect if current repository/monorepo uses npm, yarn or pnpm
66
+ */
67
+ declare function detectPackageManager(cwd?: string): string;
68
+
69
+ export { type MiniPackageJson, asyncFindPath, asyncRetrievePackageJson, createFileIfNotExists, detectPackageManager, existsAsync, exportsForTests, fetchPackageLocation, findPath, getCwd, isPosix, path, retrievePackageJson, sh, toPosixPathSeparators, toSystemPathSeparators };
package/dist/index.js ADDED
@@ -0,0 +1,174 @@
1
+ // src/index.ts
2
+ import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
3
+ import { join as join2, sep as sep3 } from "node:path";
4
+
5
+ // src/file.ts
6
+ import { existsSync } from "node:fs";
7
+ import { access, constants, mkdir, writeFile } from "node:fs/promises";
8
+ import { execSync } from "node:child_process";
9
+ import { dirname, join, resolve, sep } from "path";
10
+ import { fileURLToPath } from "node:url";
11
+ var existsAsync = async (file) => await access(file, constants.F_OK).then(() => true).catch(() => false);
12
+ var sh = (command, cwd) => execSync(command.trim(), { encoding: "utf8", cwd }).trim();
13
+ async function createFileIfNotExists(filePath, content) {
14
+ await mkdir(dirname(filePath), { recursive: true });
15
+ if (!await existsAsync(filePath)) {
16
+ await writeFile(filePath, content, { encoding: "utf8" });
17
+ }
18
+ }
19
+ function findPath(target, startDirectory = process.cwd()) {
20
+ const resolvedStartDirectory = startDirectory.startsWith("file:///") ? dirname(fileURLToPath(startDirectory)) : resolve(startDirectory);
21
+ const parentPath = resolvedStartDirectory.split(sep);
22
+ while (parentPath.length > 2) {
23
+ const fullPath = join(
24
+ ...sep === "/" ? ["/"] : [],
25
+ ...parentPath,
26
+ target
27
+ );
28
+ if (existsSync(fullPath)) {
29
+ return fullPath;
30
+ }
31
+ parentPath.pop();
32
+ }
33
+ return void 0;
34
+ }
35
+ async function asyncFindPath(target, startDirectory = process.cwd()) {
36
+ const resolvedStartDirectory = startDirectory.startsWith("file:///") ? dirname(fileURLToPath(startDirectory)) : resolve(startDirectory);
37
+ const parentPath = resolvedStartDirectory.split(sep);
38
+ while (parentPath.length > 2) {
39
+ const fullPath = join(
40
+ ...sep === "/" ? ["/"] : [],
41
+ ...parentPath,
42
+ target
43
+ );
44
+ if (await existsAsync(fullPath)) {
45
+ return fullPath;
46
+ }
47
+ parentPath.pop();
48
+ }
49
+ return void 0;
50
+ }
51
+
52
+ // src/path.ts
53
+ import { sep as sep2 } from "path";
54
+ import posix from "path/posix";
55
+ import win32 from "path/win32";
56
+ var isPosix = sep2 === posix.sep;
57
+ var toPosixPathSeparators = (relativePath) => relativePath.includes(win32.sep) ? relativePath.replaceAll(win32.sep, posix.sep) : relativePath;
58
+ var toWin32PathSeparators = (relativePath) => relativePath.includes(posix.sep) ? relativePath.replaceAll(posix.sep, win32.sep) : relativePath;
59
+ var toSystemPathSeparators = isPosix ? (path2) => path2 : toWin32PathSeparators;
60
+ var getCwd = isPosix ? process.cwd : () => toPosixPathSeparators(process.cwd());
61
+ var path = isPosix ? posix : {
62
+ ...win32,
63
+ sep: posix.sep,
64
+ join(...paths) {
65
+ const result = win32.join(...paths);
66
+ return toPosixPathSeparators(result);
67
+ },
68
+ normalize(path2) {
69
+ const result = win32.normalize(path2);
70
+ return toPosixPathSeparators(result);
71
+ },
72
+ relative(from, to) {
73
+ const result = win32.relative(from, to);
74
+ return toPosixPathSeparators(result);
75
+ },
76
+ dirname(path2) {
77
+ const result = win32.dirname(path2);
78
+ return toPosixPathSeparators(result);
79
+ },
80
+ resolve(...paths) {
81
+ const result = win32.resolve(...paths);
82
+ return toPosixPathSeparators(result);
83
+ },
84
+ toNamespacedPath(path2) {
85
+ const result = win32.toNamespacedPath(path2);
86
+ return toPosixPathSeparators(result);
87
+ }
88
+ };
89
+ var exportsForTests = { toWin32PathSeparators };
90
+
91
+ // src/packageJson.ts
92
+ import { readFileSync } from "node:fs";
93
+ import { readFile } from "node:fs/promises";
94
+ var cachedPackageJson = {};
95
+ var cachedPackageJsonPromises = {};
96
+ var rootPackageJsonLocation;
97
+ function retrievePackageJson(location) {
98
+ const packageJsonPath = location ? path.resolve(location, "package.json") : rootPackageJsonLocation ??= findPath("package.json");
99
+ cachedPackageJson[packageJsonPath] ??= JSON.parse(readFileSync(packageJsonPath, "utf-8"));
100
+ return cachedPackageJson[packageJsonPath];
101
+ }
102
+ async function asyncRetrievePackageJson(location = getCwd()) {
103
+ const packageJsonPath = path.resolve(location, "package.json");
104
+ if (packageJsonPath in cachedPackageJson) {
105
+ return cachedPackageJson[packageJsonPath];
106
+ }
107
+ cachedPackageJsonPromises[packageJsonPath] ??= asyncReadPackageJson(packageJsonPath);
108
+ const result = await cachedPackageJsonPromises[packageJsonPath];
109
+ cachedPackageJson[packageJsonPath] ??= result;
110
+ return result;
111
+ }
112
+ var asyncReadPackageJson = async (location) => JSON.parse(await readFile(location, "utf-8"));
113
+ var cachedPackageLocation = {};
114
+ var cachedPackageLocationPromises = {};
115
+ async function fetchPackageLocation(packageName, cwd) {
116
+ if (packageName in cachedPackageLocation) {
117
+ return cachedPackageLocation[packageName];
118
+ }
119
+ cachedPackageLocationPromises[packageName] ??= asyncFindPath(
120
+ path.join("node_modules", packageName, "package.json"),
121
+ cwd
122
+ ).then((packageJsonLocation) => {
123
+ if (packageJsonLocation === void 0) {
124
+ throw new Error(
125
+ `@arcgis/lumina-compiler: Unable to resolve package.json location for "${packageName}" package. Current working directory: ${process.cwd()}`
126
+ );
127
+ }
128
+ return path.dirname(packageJsonLocation);
129
+ });
130
+ const result = await cachedPackageLocationPromises[packageName];
131
+ cachedPackageLocation[packageName] ??= result;
132
+ return cachedPackageLocation[packageName];
133
+ }
134
+
135
+ // src/index.ts
136
+ function detectPackageManager(cwd = process.cwd()) {
137
+ let packageManager = void 0;
138
+ {
139
+ const pathParts = cwd.split(sep3);
140
+ while (pathParts.length > 1) {
141
+ const packageJson = join2(pathParts.join(sep3), "package.json");
142
+ pathParts.pop();
143
+ if (!existsSync2(packageJson)) {
144
+ continue;
145
+ }
146
+ const contents = JSON.parse(readFileSync2(packageJson, "utf8"));
147
+ if (typeof contents !== "object" || Array.isArray(contents)) {
148
+ continue;
149
+ }
150
+ if (typeof contents.packageManager === "string") {
151
+ packageManager ??= contents.packageManager.match(/\w+/u)?.[0] ?? packageManager;
152
+ }
153
+ }
154
+ }
155
+ packageManager ??= "npm";
156
+ return packageManager;
157
+ }
158
+ export {
159
+ asyncFindPath,
160
+ asyncRetrievePackageJson,
161
+ createFileIfNotExists,
162
+ detectPackageManager,
163
+ existsAsync,
164
+ exportsForTests,
165
+ fetchPackageLocation,
166
+ findPath,
167
+ getCwd,
168
+ isPosix,
169
+ path,
170
+ retrievePackageJson,
171
+ sh,
172
+ toPosixPathSeparators,
173
+ toSystemPathSeparators
174
+ };
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "@arcgis/components-build-utils",
3
+ "version": "4.31.0-next.112",
4
+ "description": "Collection of common internal build-time patterns and utilities for ArcGIS Maps SDK for JavaScript components.",
5
+ "homepage": "https://developers.arcgis.com/javascript/latest/",
6
+ "type": "module",
7
+ "main": "dist/index.cjs",
8
+ "module": "dist/index.js",
9
+ "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.js",
14
+ "require": "./dist/index.cjs"
15
+ }
16
+ },
17
+ "files": [
18
+ "dist/"
19
+ ],
20
+ "bin": {
21
+ "awc": "src/commands/run-wrapper.js"
22
+ },
23
+ "publishConfig": {
24
+ "registry": "https://registry.npmjs.org/",
25
+ "access": "public"
26
+ },
27
+ "license": "SEE LICENSE IN LICENSE.md",
28
+ "scripts": {
29
+ "build": "tsup --silent",
30
+ "build:dev": "tsup --silent --sourcemap",
31
+ "watch": "yarn build:dev --watch --onSuccess 'yarn'",
32
+ "test": "vitest",
33
+ "test:watch": "vitest --watch",
34
+ "coverage": "vitest run --coverage",
35
+ "lint-test": "vitest related --run --passWithNoTests",
36
+ "clean": "rimraf ./dist ./turbo ./node_modules"
37
+ },
38
+ "dependencies": {
39
+ "tslib": "^2.7.0"
40
+ },
41
+ "devDependencies": {
42
+ "@arcgis/typescript-config": "4.31.0-next.112",
43
+ "@commander-js/extra-typings": "^11.1.0",
44
+ "commander": "^11.1.0",
45
+ "eslint": "^8.55.0",
46
+ "rimraf": "^5.0.0",
47
+ "tsup": "^8.2.4",
48
+ "typescript": "~5.4.0",
49
+ "vitest": "^2.1.1"
50
+ },
51
+ "gitHead": "388967aea3e36323fae8a2a117cb9c67e6197a66"
52
+ }
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const scriptPath = join(fileURLToPath(import.meta.url), "..", "run.ts");
7
+ const commandArguments = process.argv.slice(2);
8
+
9
+ const child = spawn("npx", ["tsx", scriptPath, ...commandArguments], {
10
+ stdio: "inherit",
11
+ shell: true,
12
+ });
13
+
14
+ // Forward the exit code
15
+ child.on("exit", function (code) {
16
+ process.exit(code);
17
+ });