@storm-software/config-tools 1.7.1 → 1.8.0
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/CHANGELOG.md +7 -0
- package/declarations.d.ts +2 -22
- package/index.cjs +24 -131
- package/index.js +26 -131
- package/meta.cjs.json +1 -1
- package/meta.esm.json +1 -1
- package/package.json +1 -1
- package/utilities/find-workspace-root.cjs +18 -128
- package/utilities/find-workspace-root.js +18 -126
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.7.1](https://github.com/storm-software/storm-ops/compare/config-tools-v1.7.0...config-tools-v1.7.1) (2023-12-22)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **config-tools:** Resolved issues with returned values in `findWorkspaceRoot` functions ([c790e15](https://github.com/storm-software/storm-ops/commit/c790e151ec130b4a72d17b965092c402c685d824))
|
|
7
|
+
|
|
1
8
|
# [1.7.0](https://github.com/storm-software/storm-ops/compare/config-tools-v1.6.1...config-tools-v1.7.0) (2023-12-21)
|
|
2
9
|
|
|
3
10
|
|
package/declarations.d.ts
CHANGED
|
@@ -22,27 +22,7 @@ export { StormConfig };
|
|
|
22
22
|
*
|
|
23
23
|
* @param pathInsideMonorepo - The path inside the monorepo
|
|
24
24
|
*/
|
|
25
|
-
declare function findWorkspaceRoot(
|
|
26
|
-
pathInsideMonorepo?: string
|
|
27
|
-
): Promise<string>;
|
|
28
|
-
export { findWorkspaceRoot };
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Find the root of the current monorepo safely (do not throw an error if it cannot be found)
|
|
32
|
-
*
|
|
33
|
-
* @param pathInsideMonorepo - The path inside the monorepo
|
|
34
|
-
*/
|
|
35
|
-
declare function findWorkspaceRootSafe(
|
|
36
|
-
pathInsideMonorepo?: string
|
|
37
|
-
): Promise<string | undefined>;
|
|
38
|
-
export { findWorkspaceRootSafe };
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Find the root of the current monorepo
|
|
42
|
-
*
|
|
43
|
-
* @param pathInsideMonorepo - The path inside the monorepo
|
|
44
|
-
*/
|
|
45
|
-
declare function findWorkspaceRootSync(pathInsideMonorepo?: string): string;
|
|
25
|
+
declare function findWorkspaceRoot(pathInsideMonorepo?: string): string;
|
|
46
26
|
export { findWorkspaceRootSync };
|
|
47
27
|
|
|
48
28
|
/**
|
|
@@ -50,7 +30,7 @@ export { findWorkspaceRootSync };
|
|
|
50
30
|
*
|
|
51
31
|
* @param pathInsideMonorepo - The path inside the monorepo
|
|
52
32
|
*/
|
|
53
|
-
declare function
|
|
33
|
+
declare function findWorkspaceRootSafe(
|
|
54
34
|
pathInsideMonorepo?: string
|
|
55
35
|
): string | undefined;
|
|
56
36
|
export { findWorkspaceRootSafeSync };
|
package/index.cjs
CHANGED
|
@@ -40,8 +40,6 @@ __export(src_exports, {
|
|
|
40
40
|
createStormConfig: () => createStormConfig,
|
|
41
41
|
findWorkspaceRoot: () => findWorkspaceRoot,
|
|
42
42
|
findWorkspaceRootSafe: () => findWorkspaceRootSafe,
|
|
43
|
-
findWorkspaceRootSafeSync: () => findWorkspaceRootSafeSync,
|
|
44
|
-
findWorkspaceRootSync: () => findWorkspaceRootSync,
|
|
45
43
|
getConfigEnv: () => getConfigEnv,
|
|
46
44
|
getConfigFile: () => getConfigFile,
|
|
47
45
|
getDefaultConfig: () => getDefaultConfig,
|
|
@@ -111,102 +109,20 @@ var LogLevelLabel = {
|
|
|
111
109
|
};
|
|
112
110
|
|
|
113
111
|
// packages/config-tools/src/utilities/find-up.ts
|
|
114
|
-
var
|
|
112
|
+
var import_fs = require("fs");
|
|
115
113
|
var import_path = require("path");
|
|
116
|
-
var
|
|
117
|
-
var
|
|
118
|
-
function
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const foundPath = names(options.cwd);
|
|
128
|
-
return (0, import_locate_path.locatePathSync)([foundPath], { ...options, cwd: directory });
|
|
129
|
-
}
|
|
130
|
-
const runNameMatcher = async (name) => {
|
|
131
|
-
const paths = [name].flat();
|
|
132
|
-
const runMatcher = async (locateOptions) => {
|
|
133
|
-
if (typeof name !== "function") {
|
|
134
|
-
return (0, import_locate_path.locatePath)(paths, locateOptions);
|
|
135
|
-
}
|
|
136
|
-
const foundPath = await name(locateOptions.cwd);
|
|
137
|
-
if (typeof foundPath === "string") {
|
|
138
|
-
return (0, import_locate_path.locatePath)([foundPath], locateOptions);
|
|
139
|
-
}
|
|
140
|
-
return foundPath;
|
|
141
|
-
};
|
|
142
|
-
const matches = [];
|
|
143
|
-
while (true) {
|
|
144
|
-
console.debug(
|
|
145
|
-
`Searching for workspace root files in ${directory}
|
|
146
|
-
Options: ${JSON.stringify(
|
|
147
|
-
options
|
|
148
|
-
)}`
|
|
149
|
-
);
|
|
150
|
-
const foundPath = await runMatcher({ ...options, cwd: directory });
|
|
151
|
-
console.debug(`Found path specified at ${foundPath}`);
|
|
152
|
-
if (foundPath) {
|
|
153
|
-
matches.push((0, import_path.resolve)(directory, foundPath));
|
|
154
|
-
}
|
|
155
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
directory = (0, import_path.dirname)(directory);
|
|
159
|
-
}
|
|
160
|
-
return matches;
|
|
161
|
-
};
|
|
162
|
-
const promises = Promise.all(
|
|
163
|
-
(names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name))
|
|
164
|
-
);
|
|
165
|
-
return (await promises).flat().map((path) => path ? path : "");
|
|
166
|
-
}
|
|
167
|
-
function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
168
|
-
let directory = (0, import_path.resolve)(toPath(options.cwd) ?? "");
|
|
169
|
-
const { root } = (0, import_path.parse)(directory);
|
|
170
|
-
const stopAt = (0, import_path.resolve)(directory, toPath(options.stopAt) ?? root);
|
|
171
|
-
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
172
|
-
if (typeof names === "function") {
|
|
173
|
-
const foundPath = names(options.cwd);
|
|
174
|
-
return (0, import_locate_path.locatePathSync)([foundPath], options);
|
|
114
|
+
var MAX_PATH_SEARCH_DEPTH = 30;
|
|
115
|
+
var depth = 0;
|
|
116
|
+
function findFolderUp(startPath, endFileNames) {
|
|
117
|
+
startPath = startPath ?? process.cwd();
|
|
118
|
+
if (endFileNames.some((endFileName) => (0, import_fs.existsSync)((0, import_path.join)(startPath, endFileName)))) {
|
|
119
|
+
return startPath;
|
|
120
|
+
} else if (startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
|
|
121
|
+
const parent = (0, import_path.join)(startPath, "..");
|
|
122
|
+
return findFolderUp(parent, endFileNames);
|
|
123
|
+
} else {
|
|
124
|
+
return void 0;
|
|
175
125
|
}
|
|
176
|
-
const runNameMatcher = (name) => {
|
|
177
|
-
const paths = [name].flat();
|
|
178
|
-
const runMatcher = (locateOptions) => {
|
|
179
|
-
if (typeof name !== "function") {
|
|
180
|
-
return (0, import_locate_path.locatePathSync)(paths, locateOptions);
|
|
181
|
-
}
|
|
182
|
-
const foundPath = name(locateOptions.cwd);
|
|
183
|
-
if (typeof foundPath === "string") {
|
|
184
|
-
return (0, import_locate_path.locatePathSync)([foundPath], locateOptions);
|
|
185
|
-
}
|
|
186
|
-
return foundPath;
|
|
187
|
-
};
|
|
188
|
-
const matches = [];
|
|
189
|
-
while (true) {
|
|
190
|
-
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
191
|
-
if (foundPath) {
|
|
192
|
-
matches.push((0, import_path.resolve)(directory, foundPath));
|
|
193
|
-
}
|
|
194
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
195
|
-
break;
|
|
196
|
-
}
|
|
197
|
-
directory = (0, import_path.dirname)(directory);
|
|
198
|
-
}
|
|
199
|
-
return matches;
|
|
200
|
-
};
|
|
201
|
-
return (names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name)).flat().map((path) => path ? path : "");
|
|
202
|
-
}
|
|
203
|
-
async function findUp(names, options = { limit: 1, type: "file" }) {
|
|
204
|
-
const matches = await findUpMultiple(names, options);
|
|
205
|
-
return matches[0];
|
|
206
|
-
}
|
|
207
|
-
function findUpSync(names, options = { limit: 1, type: "file" }) {
|
|
208
|
-
const matches = findUpMultipleSync(names, options);
|
|
209
|
-
return matches[0];
|
|
210
126
|
}
|
|
211
127
|
|
|
212
128
|
// packages/config-tools/src/utilities/find-workspace-root.ts
|
|
@@ -234,38 +150,14 @@ var rootFiles = [
|
|
|
234
150
|
"pnpm-lock.yml",
|
|
235
151
|
"bun.lockb"
|
|
236
152
|
];
|
|
237
|
-
|
|
153
|
+
function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
238
154
|
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
239
155
|
return process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH;
|
|
240
156
|
}
|
|
241
|
-
return
|
|
242
|
-
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
243
|
-
type: "file",
|
|
244
|
-
limit: 1
|
|
245
|
-
});
|
|
157
|
+
return findFolderUp(pathInsideMonorepo ?? process.cwd(), rootFiles);
|
|
246
158
|
}
|
|
247
|
-
function
|
|
248
|
-
|
|
249
|
-
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
250
|
-
type: "file",
|
|
251
|
-
limit: 1
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
async function findWorkspaceRoot(pathInsideMonorepo) {
|
|
255
|
-
const result = await findWorkspaceRootSafe(pathInsideMonorepo);
|
|
256
|
-
if (!result) {
|
|
257
|
-
throw new Error(
|
|
258
|
-
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
259
|
-
${rootFiles.join(
|
|
260
|
-
"\n"
|
|
261
|
-
)}
|
|
262
|
-
Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
return result;
|
|
266
|
-
}
|
|
267
|
-
function findWorkspaceRootSync(pathInsideMonorepo) {
|
|
268
|
-
const result = findWorkspaceRootSafeSync(pathInsideMonorepo);
|
|
159
|
+
function findWorkspaceRoot(pathInsideMonorepo) {
|
|
160
|
+
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
269
161
|
if (!result) {
|
|
270
162
|
throw new Error(
|
|
271
163
|
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
@@ -279,7 +171,7 @@ Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
|
279
171
|
}
|
|
280
172
|
|
|
281
173
|
// packages/config-tools/src/utilities/get-default-config.ts
|
|
282
|
-
var
|
|
174
|
+
var import_fs2 = require("fs");
|
|
283
175
|
var import_path2 = require("path");
|
|
284
176
|
|
|
285
177
|
// packages/config-tools/src/schema.ts
|
|
@@ -319,6 +211,7 @@ var StormConfigSchema = z.object({
|
|
|
319
211
|
runtimeVersion: z.string().trim().regex(
|
|
320
212
|
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
|
|
321
213
|
).default("1.0.0").describe("The global version of the Storm runtime"),
|
|
214
|
+
packageManager: z.enum(["npm", "yarn", "pnpm", "bun"]).default("npm").describe("The package manager used by the repository"),
|
|
322
215
|
timezone: z.string().trim().default("America/New_York").describe("The default timezone of the workspace"),
|
|
323
216
|
locale: z.string().trim().default("en-US").describe("The default locale of the workspace"),
|
|
324
217
|
logLevel: z.enum(["silent", "fatal", "error", "warn", "info", "debug", "trace"]).optional().describe(
|
|
@@ -346,6 +239,7 @@ var DefaultColorConfig = {
|
|
|
346
239
|
fatal: "#7d1a1a"
|
|
347
240
|
};
|
|
348
241
|
var DefaultStormConfig = {
|
|
242
|
+
name: "storm-workspace",
|
|
349
243
|
namespace: "storm-software",
|
|
350
244
|
license: "Apache License 2.0",
|
|
351
245
|
homepage: "https://stormsoftware.org",
|
|
@@ -353,6 +247,7 @@ var DefaultStormConfig = {
|
|
|
353
247
|
owner: "@storm-software/development",
|
|
354
248
|
worker: "stormie-bot",
|
|
355
249
|
runtimeDirectory: "node_modules/.storm",
|
|
250
|
+
packageManager: "npm",
|
|
356
251
|
timezone: "America/New_York",
|
|
357
252
|
locale: "en-US",
|
|
358
253
|
env: "production",
|
|
@@ -367,12 +262,12 @@ var DefaultStormConfig = {
|
|
|
367
262
|
var getDefaultConfig = (config = {}, root) => {
|
|
368
263
|
let name = "storm-workspace";
|
|
369
264
|
let namespace = "storm-software";
|
|
370
|
-
let repository = "https://github.com/storm-software/storm-
|
|
265
|
+
let repository = "https://github.com/storm-software/storm-ops";
|
|
371
266
|
let license = DefaultStormConfig.license;
|
|
372
267
|
let homepage = DefaultStormConfig.homepage;
|
|
373
|
-
const workspaceRoot =
|
|
374
|
-
if ((0,
|
|
375
|
-
const file = (0,
|
|
268
|
+
const workspaceRoot = findWorkspaceRoot(root);
|
|
269
|
+
if ((0, import_fs2.existsSync)((0, import_path2.join)(workspaceRoot, "package.json"))) {
|
|
270
|
+
const file = (0, import_fs2.readFileSync)((0, import_path2.join)(workspaceRoot, "package.json"), {
|
|
376
271
|
encoding: "utf-8"
|
|
377
272
|
});
|
|
378
273
|
if (file) {
|
|
@@ -627,8 +522,6 @@ var setConfigEnv = (config) => {
|
|
|
627
522
|
createStormConfig,
|
|
628
523
|
findWorkspaceRoot,
|
|
629
524
|
findWorkspaceRootSafe,
|
|
630
|
-
findWorkspaceRootSafeSync,
|
|
631
|
-
findWorkspaceRootSync,
|
|
632
525
|
getConfigEnv,
|
|
633
526
|
getConfigFile,
|
|
634
527
|
getDefaultConfig,
|
package/index.js
CHANGED
|
@@ -56,102 +56,20 @@ var LogLevelLabel = {
|
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
// packages/config-tools/src/utilities/find-up.ts
|
|
59
|
-
import {
|
|
60
|
-
import {
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const foundPath = names(options.cwd);
|
|
73
|
-
return locatePathSync([foundPath], { ...options, cwd: directory });
|
|
74
|
-
}
|
|
75
|
-
const runNameMatcher = async (name) => {
|
|
76
|
-
const paths = [name].flat();
|
|
77
|
-
const runMatcher = async (locateOptions) => {
|
|
78
|
-
if (typeof name !== "function") {
|
|
79
|
-
return locatePath(paths, locateOptions);
|
|
80
|
-
}
|
|
81
|
-
const foundPath = await name(locateOptions.cwd);
|
|
82
|
-
if (typeof foundPath === "string") {
|
|
83
|
-
return locatePath([foundPath], locateOptions);
|
|
84
|
-
}
|
|
85
|
-
return foundPath;
|
|
86
|
-
};
|
|
87
|
-
const matches = [];
|
|
88
|
-
while (true) {
|
|
89
|
-
console.debug(
|
|
90
|
-
`Searching for workspace root files in ${directory}
|
|
91
|
-
Options: ${JSON.stringify(
|
|
92
|
-
options
|
|
93
|
-
)}`
|
|
94
|
-
);
|
|
95
|
-
const foundPath = await runMatcher({ ...options, cwd: directory });
|
|
96
|
-
console.debug(`Found path specified at ${foundPath}`);
|
|
97
|
-
if (foundPath) {
|
|
98
|
-
matches.push(resolve(directory, foundPath));
|
|
99
|
-
}
|
|
100
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
101
|
-
break;
|
|
102
|
-
}
|
|
103
|
-
directory = dirname(directory);
|
|
104
|
-
}
|
|
105
|
-
return matches;
|
|
106
|
-
};
|
|
107
|
-
const promises = Promise.all(
|
|
108
|
-
(names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name))
|
|
109
|
-
);
|
|
110
|
-
return (await promises).flat().map((path) => path ? path : "");
|
|
111
|
-
}
|
|
112
|
-
function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
113
|
-
let directory = resolve(toPath(options.cwd) ?? "");
|
|
114
|
-
const { root } = parse(directory);
|
|
115
|
-
const stopAt = resolve(directory, toPath(options.stopAt) ?? root);
|
|
116
|
-
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
117
|
-
if (typeof names === "function") {
|
|
118
|
-
const foundPath = names(options.cwd);
|
|
119
|
-
return locatePathSync([foundPath], options);
|
|
59
|
+
import { existsSync } from "fs";
|
|
60
|
+
import { join } from "path";
|
|
61
|
+
var MAX_PATH_SEARCH_DEPTH = 30;
|
|
62
|
+
var depth = 0;
|
|
63
|
+
function findFolderUp(startPath, endFileNames) {
|
|
64
|
+
startPath = startPath ?? process.cwd();
|
|
65
|
+
if (endFileNames.some((endFileName) => existsSync(join(startPath, endFileName)))) {
|
|
66
|
+
return startPath;
|
|
67
|
+
} else if (startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
|
|
68
|
+
const parent = join(startPath, "..");
|
|
69
|
+
return findFolderUp(parent, endFileNames);
|
|
70
|
+
} else {
|
|
71
|
+
return void 0;
|
|
120
72
|
}
|
|
121
|
-
const runNameMatcher = (name) => {
|
|
122
|
-
const paths = [name].flat();
|
|
123
|
-
const runMatcher = (locateOptions) => {
|
|
124
|
-
if (typeof name !== "function") {
|
|
125
|
-
return locatePathSync(paths, locateOptions);
|
|
126
|
-
}
|
|
127
|
-
const foundPath = name(locateOptions.cwd);
|
|
128
|
-
if (typeof foundPath === "string") {
|
|
129
|
-
return locatePathSync([foundPath], locateOptions);
|
|
130
|
-
}
|
|
131
|
-
return foundPath;
|
|
132
|
-
};
|
|
133
|
-
const matches = [];
|
|
134
|
-
while (true) {
|
|
135
|
-
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
136
|
-
if (foundPath) {
|
|
137
|
-
matches.push(resolve(directory, foundPath));
|
|
138
|
-
}
|
|
139
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
140
|
-
break;
|
|
141
|
-
}
|
|
142
|
-
directory = dirname(directory);
|
|
143
|
-
}
|
|
144
|
-
return matches;
|
|
145
|
-
};
|
|
146
|
-
return (names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name)).flat().map((path) => path ? path : "");
|
|
147
|
-
}
|
|
148
|
-
async function findUp(names, options = { limit: 1, type: "file" }) {
|
|
149
|
-
const matches = await findUpMultiple(names, options);
|
|
150
|
-
return matches[0];
|
|
151
|
-
}
|
|
152
|
-
function findUpSync(names, options = { limit: 1, type: "file" }) {
|
|
153
|
-
const matches = findUpMultipleSync(names, options);
|
|
154
|
-
return matches[0];
|
|
155
73
|
}
|
|
156
74
|
|
|
157
75
|
// packages/config-tools/src/utilities/find-workspace-root.ts
|
|
@@ -179,38 +97,14 @@ var rootFiles = [
|
|
|
179
97
|
"pnpm-lock.yml",
|
|
180
98
|
"bun.lockb"
|
|
181
99
|
];
|
|
182
|
-
|
|
100
|
+
function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
183
101
|
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
184
102
|
return process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH;
|
|
185
103
|
}
|
|
186
|
-
return
|
|
187
|
-
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
188
|
-
type: "file",
|
|
189
|
-
limit: 1
|
|
190
|
-
});
|
|
104
|
+
return findFolderUp(pathInsideMonorepo ?? process.cwd(), rootFiles);
|
|
191
105
|
}
|
|
192
|
-
function
|
|
193
|
-
|
|
194
|
-
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
195
|
-
type: "file",
|
|
196
|
-
limit: 1
|
|
197
|
-
});
|
|
198
|
-
}
|
|
199
|
-
async function findWorkspaceRoot(pathInsideMonorepo) {
|
|
200
|
-
const result = await findWorkspaceRootSafe(pathInsideMonorepo);
|
|
201
|
-
if (!result) {
|
|
202
|
-
throw new Error(
|
|
203
|
-
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
204
|
-
${rootFiles.join(
|
|
205
|
-
"\n"
|
|
206
|
-
)}
|
|
207
|
-
Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
208
|
-
);
|
|
209
|
-
}
|
|
210
|
-
return result;
|
|
211
|
-
}
|
|
212
|
-
function findWorkspaceRootSync(pathInsideMonorepo) {
|
|
213
|
-
const result = findWorkspaceRootSafeSync(pathInsideMonorepo);
|
|
106
|
+
function findWorkspaceRoot(pathInsideMonorepo) {
|
|
107
|
+
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
214
108
|
if (!result) {
|
|
215
109
|
throw new Error(
|
|
216
110
|
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
@@ -224,8 +118,8 @@ Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
|
224
118
|
}
|
|
225
119
|
|
|
226
120
|
// packages/config-tools/src/utilities/get-default-config.ts
|
|
227
|
-
import { existsSync, readFileSync } from "fs";
|
|
228
|
-
import { join } from "path";
|
|
121
|
+
import { existsSync as existsSync2, readFileSync } from "fs";
|
|
122
|
+
import { join as join2 } from "path";
|
|
229
123
|
|
|
230
124
|
// packages/config-tools/src/schema.ts
|
|
231
125
|
import * as z from "zod";
|
|
@@ -264,6 +158,7 @@ var StormConfigSchema = z.object({
|
|
|
264
158
|
runtimeVersion: z.string().trim().regex(
|
|
265
159
|
/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/
|
|
266
160
|
).default("1.0.0").describe("The global version of the Storm runtime"),
|
|
161
|
+
packageManager: z.enum(["npm", "yarn", "pnpm", "bun"]).default("npm").describe("The package manager used by the repository"),
|
|
267
162
|
timezone: z.string().trim().default("America/New_York").describe("The default timezone of the workspace"),
|
|
268
163
|
locale: z.string().trim().default("en-US").describe("The default locale of the workspace"),
|
|
269
164
|
logLevel: z.enum(["silent", "fatal", "error", "warn", "info", "debug", "trace"]).optional().describe(
|
|
@@ -291,6 +186,7 @@ var DefaultColorConfig = {
|
|
|
291
186
|
fatal: "#7d1a1a"
|
|
292
187
|
};
|
|
293
188
|
var DefaultStormConfig = {
|
|
189
|
+
name: "storm-workspace",
|
|
294
190
|
namespace: "storm-software",
|
|
295
191
|
license: "Apache License 2.0",
|
|
296
192
|
homepage: "https://stormsoftware.org",
|
|
@@ -298,6 +194,7 @@ var DefaultStormConfig = {
|
|
|
298
194
|
owner: "@storm-software/development",
|
|
299
195
|
worker: "stormie-bot",
|
|
300
196
|
runtimeDirectory: "node_modules/.storm",
|
|
197
|
+
packageManager: "npm",
|
|
301
198
|
timezone: "America/New_York",
|
|
302
199
|
locale: "en-US",
|
|
303
200
|
env: "production",
|
|
@@ -312,12 +209,12 @@ var DefaultStormConfig = {
|
|
|
312
209
|
var getDefaultConfig = (config = {}, root) => {
|
|
313
210
|
let name = "storm-workspace";
|
|
314
211
|
let namespace = "storm-software";
|
|
315
|
-
let repository = "https://github.com/storm-software/storm-
|
|
212
|
+
let repository = "https://github.com/storm-software/storm-ops";
|
|
316
213
|
let license = DefaultStormConfig.license;
|
|
317
214
|
let homepage = DefaultStormConfig.homepage;
|
|
318
|
-
const workspaceRoot =
|
|
319
|
-
if (
|
|
320
|
-
const file = readFileSync(
|
|
215
|
+
const workspaceRoot = findWorkspaceRoot(root);
|
|
216
|
+
if (existsSync2(join2(workspaceRoot, "package.json"))) {
|
|
217
|
+
const file = readFileSync(join2(workspaceRoot, "package.json"), {
|
|
321
218
|
encoding: "utf-8"
|
|
322
219
|
});
|
|
323
220
|
if (file) {
|
|
@@ -571,8 +468,6 @@ export {
|
|
|
571
468
|
createStormConfig,
|
|
572
469
|
findWorkspaceRoot,
|
|
573
470
|
findWorkspaceRootSafe,
|
|
574
|
-
findWorkspaceRootSafeSync,
|
|
575
|
-
findWorkspaceRootSync,
|
|
576
471
|
getConfigEnv,
|
|
577
472
|
getConfigFile,
|
|
578
473
|
getDefaultConfig,
|
package/meta.cjs.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/config-tools/src/config-file/get-config-file.ts":{"bytes":1987,"imports":[{"path":"cosmiconfig","kind":"import-statement","external":true},{"path":"../types","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/config-file/index.ts":{"bytes":35,"imports":[{"path":"packages/config-tools/src/config-file/get-config-file.ts","kind":"import-statement","original":"./get-config-file"}],"format":"esm"},"packages/config-tools/src/types.ts":{"bytes":1405,"imports":[{"path":"zod","kind":"import-statement","external":true},{"path":"./schema","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/find-up.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/config-tools/src/config-file/get-config-file.ts":{"bytes":1987,"imports":[{"path":"cosmiconfig","kind":"import-statement","external":true},{"path":"../types","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/config-file/index.ts":{"bytes":35,"imports":[{"path":"packages/config-tools/src/config-file/get-config-file.ts","kind":"import-statement","original":"./get-config-file"}],"format":"esm"},"packages/config-tools/src/types.ts":{"bytes":1405,"imports":[{"path":"zod","kind":"import-statement","external":true},{"path":"./schema","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/find-up.ts":{"bytes":648,"imports":[{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytes":1755,"imports":[{"path":"packages/config-tools/src/utilities/find-up.ts","kind":"import-statement","original":"./find-up"}],"format":"esm"},"packages/config-tools/src/schema.ts":{"bytes":5887,"imports":[{"path":"zod","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/get-default-config.ts":{"bytes":2636,"imports":[{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"packages/config-tools/src/schema.ts","kind":"import-statement","original":"../schema"},{"path":"../types","kind":"import-statement","external":true},{"path":"packages/config-tools/src/utilities/find-workspace-root.ts","kind":"import-statement","original":"./find-workspace-root"}],"format":"esm"},"packages/config-tools/src/utilities/get-log-level.ts":{"bytes":1409,"imports":[{"path":"packages/config-tools/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/config-tools/src/utilities/index.ts":{"bytes":110,"imports":[{"path":"packages/config-tools/src/utilities/find-workspace-root.ts","kind":"import-statement","original":"./find-workspace-root"},{"path":"packages/config-tools/src/utilities/get-default-config.ts","kind":"import-statement","original":"./get-default-config"},{"path":"packages/config-tools/src/utilities/get-log-level.ts","kind":"import-statement","original":"./get-log-level"}],"format":"esm"},"packages/config-tools/src/env/get-env.ts":{"bytes":4137,"imports":[{"path":"packages/config-tools/src/types.ts","kind":"import-statement","original":"../types"},{"path":"packages/config-tools/src/utilities/index.ts","kind":"import-statement","original":"../utilities"}],"format":"esm"},"packages/config-tools/src/create-storm-config.ts":{"bytes":2905,"imports":[{"path":"zod","kind":"import-statement","external":true},{"path":"packages/config-tools/src/env/get-env.ts","kind":"import-statement","original":"./env/get-env"},{"path":"packages/config-tools/src/schema.ts","kind":"import-statement","original":"./schema"},{"path":"./types","kind":"import-statement","external":true},{"path":"packages/config-tools/src/utilities/get-default-config.ts","kind":"import-statement","original":"./utilities/get-default-config"}],"format":"esm"},"packages/config-tools/src/env/set-env.ts":{"bytes":4309,"imports":[{"path":"packages/config-tools/src/types.ts","kind":"import-statement","original":"../types"},{"path":"packages/config-tools/src/utilities/get-log-level.ts","kind":"import-statement","original":"../utilities/get-log-level"}],"format":"esm"},"packages/config-tools/src/env/index.ts":{"bytes":54,"imports":[{"path":"packages/config-tools/src/env/get-env.ts","kind":"import-statement","original":"./get-env"},{"path":"packages/config-tools/src/env/set-env.ts","kind":"import-statement","original":"./set-env"}],"format":"esm"},"packages/config-tools/src/index.ts":{"bytes":399,"imports":[{"path":"packages/config-tools/src/config-file/index.ts","kind":"import-statement","original":"./config-file"},{"path":"packages/config-tools/src/create-storm-config.ts","kind":"import-statement","original":"./create-storm-config"},{"path":"packages/config-tools/src/env/index.ts","kind":"import-statement","original":"./env"},{"path":"packages/config-tools/src/schema.ts","kind":"import-statement","original":"./schema"},{"path":"packages/config-tools/src/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/config-tools/src/utilities/index.ts","kind":"import-statement","original":"./utilities"}],"format":"esm"}},"outputs":{"dist/packages/config-tools/index.cjs":{"imports":[{"path":"cosmiconfig","kind":"require-call","external":true},{"path":"fs","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"fs","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"zod","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/config-tools/src/index.ts","inputs":{"packages/config-tools/src/index.ts":{"bytesInOutput":899},"packages/config-tools/src/config-file/get-config-file.ts":{"bytesInOutput":1594},"packages/config-tools/src/config-file/index.ts":{"bytesInOutput":0},"packages/config-tools/src/types.ts":{"bytesInOutput":256},"packages/config-tools/src/utilities/find-up.ts":{"bytesInOutput":555},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytesInOutput":1137},"packages/config-tools/src/utilities/index.ts":{"bytesInOutput":0},"packages/config-tools/src/utilities/get-default-config.ts":{"bytesInOutput":2091},"packages/config-tools/src/schema.ts":{"bytesInOutput":4582},"packages/config-tools/src/utilities/get-log-level.ts":{"bytesInOutput":1029},"packages/config-tools/src/env/get-env.ts":{"bytesInOutput":3060},"packages/config-tools/src/create-storm-config.ts":{"bytesInOutput":1106},"packages/config-tools/src/env/index.ts":{"bytesInOutput":0},"packages/config-tools/src/env/set-env.ts":{"bytesInOutput":3528}},"bytes":22291},"dist/packages/config-tools/utilities/find-workspace-root.cjs":{"imports":[{"path":"fs","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true}],"exports":[],"entryPoint":"packages/config-tools/src/utilities/find-workspace-root.ts","inputs":{"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytesInOutput":1378},"packages/config-tools/src/utilities/find-up.ts":{"bytesInOutput":555}},"bytes":3031}}}
|
package/meta.esm.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"packages/config-tools/src/config-file/get-config-file.ts":{"bytes":1987,"imports":[{"path":"cosmiconfig","kind":"import-statement","external":true},{"path":"../types","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/config-file/index.ts":{"bytes":35,"imports":[{"path":"packages/config-tools/src/config-file/get-config-file.ts","kind":"import-statement","original":"./get-config-file"}],"format":"esm"},"packages/config-tools/src/types.ts":{"bytes":1405,"imports":[{"path":"zod","kind":"import-statement","external":true},{"path":"./schema","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/find-up.ts":{"bytes":
|
|
1
|
+
{"inputs":{"packages/config-tools/src/config-file/get-config-file.ts":{"bytes":1987,"imports":[{"path":"cosmiconfig","kind":"import-statement","external":true},{"path":"../types","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/config-file/index.ts":{"bytes":35,"imports":[{"path":"packages/config-tools/src/config-file/get-config-file.ts","kind":"import-statement","original":"./get-config-file"}],"format":"esm"},"packages/config-tools/src/types.ts":{"bytes":1405,"imports":[{"path":"zod","kind":"import-statement","external":true},{"path":"./schema","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/find-up.ts":{"bytes":648,"imports":[{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytes":1755,"imports":[{"path":"packages/config-tools/src/utilities/find-up.ts","kind":"import-statement","original":"./find-up"}],"format":"esm"},"packages/config-tools/src/schema.ts":{"bytes":5887,"imports":[{"path":"zod","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/get-default-config.ts":{"bytes":2636,"imports":[{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"packages/config-tools/src/schema.ts","kind":"import-statement","original":"../schema"},{"path":"../types","kind":"import-statement","external":true},{"path":"packages/config-tools/src/utilities/find-workspace-root.ts","kind":"import-statement","original":"./find-workspace-root"}],"format":"esm"},"packages/config-tools/src/utilities/get-log-level.ts":{"bytes":1409,"imports":[{"path":"packages/config-tools/src/types.ts","kind":"import-statement","original":"../types"}],"format":"esm"},"packages/config-tools/src/utilities/index.ts":{"bytes":110,"imports":[{"path":"packages/config-tools/src/utilities/find-workspace-root.ts","kind":"import-statement","original":"./find-workspace-root"},{"path":"packages/config-tools/src/utilities/get-default-config.ts","kind":"import-statement","original":"./get-default-config"},{"path":"packages/config-tools/src/utilities/get-log-level.ts","kind":"import-statement","original":"./get-log-level"}],"format":"esm"},"packages/config-tools/src/env/get-env.ts":{"bytes":4137,"imports":[{"path":"packages/config-tools/src/types.ts","kind":"import-statement","original":"../types"},{"path":"packages/config-tools/src/utilities/index.ts","kind":"import-statement","original":"../utilities"}],"format":"esm"},"packages/config-tools/src/create-storm-config.ts":{"bytes":2905,"imports":[{"path":"zod","kind":"import-statement","external":true},{"path":"packages/config-tools/src/env/get-env.ts","kind":"import-statement","original":"./env/get-env"},{"path":"packages/config-tools/src/schema.ts","kind":"import-statement","original":"./schema"},{"path":"./types","kind":"import-statement","external":true},{"path":"packages/config-tools/src/utilities/get-default-config.ts","kind":"import-statement","original":"./utilities/get-default-config"}],"format":"esm"},"packages/config-tools/src/env/set-env.ts":{"bytes":4309,"imports":[{"path":"packages/config-tools/src/types.ts","kind":"import-statement","original":"../types"},{"path":"packages/config-tools/src/utilities/get-log-level.ts","kind":"import-statement","original":"../utilities/get-log-level"}],"format":"esm"},"packages/config-tools/src/env/index.ts":{"bytes":54,"imports":[{"path":"packages/config-tools/src/env/get-env.ts","kind":"import-statement","original":"./get-env"},{"path":"packages/config-tools/src/env/set-env.ts","kind":"import-statement","original":"./set-env"}],"format":"esm"},"packages/config-tools/src/index.ts":{"bytes":399,"imports":[{"path":"packages/config-tools/src/config-file/index.ts","kind":"import-statement","original":"./config-file"},{"path":"packages/config-tools/src/create-storm-config.ts","kind":"import-statement","original":"./create-storm-config"},{"path":"packages/config-tools/src/env/index.ts","kind":"import-statement","original":"./env"},{"path":"packages/config-tools/src/schema.ts","kind":"import-statement","original":"./schema"},{"path":"packages/config-tools/src/types.ts","kind":"import-statement","original":"./types"},{"path":"packages/config-tools/src/utilities/index.ts","kind":"import-statement","original":"./utilities"}],"format":"esm"}},"outputs":{"dist/packages/config-tools/index.js":{"imports":[{"path":"cosmiconfig","kind":"import-statement","external":true},{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"zod","kind":"import-statement","external":true}],"exports":["ColorConfigSchema","DefaultColorConfig","DefaultStormConfig","LogLevel","LogLevelLabel","StormConfigSchema","createConfig","createConfigExtension","createStormConfig","findWorkspaceRoot","findWorkspaceRootSafe","getConfigEnv","getConfigFile","getDefaultConfig","getExtensionEnv","getLogLevel","getLogLevelLabel","setConfigEnv","setExtensionEnv"],"entryPoint":"packages/config-tools/src/index.ts","inputs":{"packages/config-tools/src/config-file/get-config-file.ts":{"bytesInOutput":1564},"packages/config-tools/src/config-file/index.ts":{"bytesInOutput":0},"packages/config-tools/src/index.ts":{"bytesInOutput":0},"packages/config-tools/src/types.ts":{"bytesInOutput":256},"packages/config-tools/src/utilities/find-up.ts":{"bytesInOutput":502},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytesInOutput":1137},"packages/config-tools/src/utilities/index.ts":{"bytesInOutput":0},"packages/config-tools/src/utilities/get-default-config.ts":{"bytesInOutput":2058},"packages/config-tools/src/schema.ts":{"bytesInOutput":4572},"packages/config-tools/src/utilities/get-log-level.ts":{"bytesInOutput":1029},"packages/config-tools/src/env/get-env.ts":{"bytesInOutput":3060},"packages/config-tools/src/create-storm-config.ts":{"bytesInOutput":1106},"packages/config-tools/src/env/index.ts":{"bytesInOutput":0},"packages/config-tools/src/env/set-env.ts":{"bytesInOutput":3528}},"bytes":19765},"dist/packages/config-tools/utilities/find-workspace-root.js":{"imports":[{"path":"fs","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true}],"exports":["findWorkspaceRoot","findWorkspaceRootSafe"],"entryPoint":"packages/config-tools/src/utilities/find-workspace-root.ts","inputs":{"packages/config-tools/src/utilities/find-up.ts":{"bytesInOutput":502},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytesInOutput":1137}},"bytes":1809}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storm-software/config-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "⚡The Storm-Ops monorepo contains utility applications, tools, and various libraries to create modern and scalable web applications.",
|
|
6
6
|
"repository": {
|
|
@@ -20,109 +20,25 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
var find_workspace_root_exports = {};
|
|
21
21
|
__export(find_workspace_root_exports, {
|
|
22
22
|
findWorkspaceRoot: () => findWorkspaceRoot,
|
|
23
|
-
findWorkspaceRootSafe: () => findWorkspaceRootSafe
|
|
24
|
-
findWorkspaceRootSafeSync: () => findWorkspaceRootSafeSync,
|
|
25
|
-
findWorkspaceRootSync: () => findWorkspaceRootSync
|
|
23
|
+
findWorkspaceRootSafe: () => findWorkspaceRootSafe
|
|
26
24
|
});
|
|
27
25
|
module.exports = __toCommonJS(find_workspace_root_exports);
|
|
28
26
|
|
|
29
27
|
// packages/config-tools/src/utilities/find-up.ts
|
|
30
|
-
var
|
|
28
|
+
var import_fs = require("fs");
|
|
31
29
|
var import_path = require("path");
|
|
32
|
-
var
|
|
33
|
-
var
|
|
34
|
-
function
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const foundPath = names(options.cwd);
|
|
44
|
-
return (0, import_locate_path.locatePathSync)([foundPath], { ...options, cwd: directory });
|
|
45
|
-
}
|
|
46
|
-
const runNameMatcher = async (name) => {
|
|
47
|
-
const paths = [name].flat();
|
|
48
|
-
const runMatcher = async (locateOptions) => {
|
|
49
|
-
if (typeof name !== "function") {
|
|
50
|
-
return (0, import_locate_path.locatePath)(paths, locateOptions);
|
|
51
|
-
}
|
|
52
|
-
const foundPath = await name(locateOptions.cwd);
|
|
53
|
-
if (typeof foundPath === "string") {
|
|
54
|
-
return (0, import_locate_path.locatePath)([foundPath], locateOptions);
|
|
55
|
-
}
|
|
56
|
-
return foundPath;
|
|
57
|
-
};
|
|
58
|
-
const matches = [];
|
|
59
|
-
while (true) {
|
|
60
|
-
console.debug(
|
|
61
|
-
`Searching for workspace root files in ${directory}
|
|
62
|
-
Options: ${JSON.stringify(
|
|
63
|
-
options
|
|
64
|
-
)}`
|
|
65
|
-
);
|
|
66
|
-
const foundPath = await runMatcher({ ...options, cwd: directory });
|
|
67
|
-
console.debug(`Found path specified at ${foundPath}`);
|
|
68
|
-
if (foundPath) {
|
|
69
|
-
matches.push((0, import_path.resolve)(directory, foundPath));
|
|
70
|
-
}
|
|
71
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
directory = (0, import_path.dirname)(directory);
|
|
75
|
-
}
|
|
76
|
-
return matches;
|
|
77
|
-
};
|
|
78
|
-
const promises = Promise.all(
|
|
79
|
-
(names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name))
|
|
80
|
-
);
|
|
81
|
-
return (await promises).flat().map((path) => path ? path : "");
|
|
82
|
-
}
|
|
83
|
-
function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
84
|
-
let directory = (0, import_path.resolve)(toPath(options.cwd) ?? "");
|
|
85
|
-
const { root } = (0, import_path.parse)(directory);
|
|
86
|
-
const stopAt = (0, import_path.resolve)(directory, toPath(options.stopAt) ?? root);
|
|
87
|
-
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
88
|
-
if (typeof names === "function") {
|
|
89
|
-
const foundPath = names(options.cwd);
|
|
90
|
-
return (0, import_locate_path.locatePathSync)([foundPath], options);
|
|
30
|
+
var MAX_PATH_SEARCH_DEPTH = 30;
|
|
31
|
+
var depth = 0;
|
|
32
|
+
function findFolderUp(startPath, endFileNames) {
|
|
33
|
+
startPath = startPath ?? process.cwd();
|
|
34
|
+
if (endFileNames.some((endFileName) => (0, import_fs.existsSync)((0, import_path.join)(startPath, endFileName)))) {
|
|
35
|
+
return startPath;
|
|
36
|
+
} else if (startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
|
|
37
|
+
const parent = (0, import_path.join)(startPath, "..");
|
|
38
|
+
return findFolderUp(parent, endFileNames);
|
|
39
|
+
} else {
|
|
40
|
+
return void 0;
|
|
91
41
|
}
|
|
92
|
-
const runNameMatcher = (name) => {
|
|
93
|
-
const paths = [name].flat();
|
|
94
|
-
const runMatcher = (locateOptions) => {
|
|
95
|
-
if (typeof name !== "function") {
|
|
96
|
-
return (0, import_locate_path.locatePathSync)(paths, locateOptions);
|
|
97
|
-
}
|
|
98
|
-
const foundPath = name(locateOptions.cwd);
|
|
99
|
-
if (typeof foundPath === "string") {
|
|
100
|
-
return (0, import_locate_path.locatePathSync)([foundPath], locateOptions);
|
|
101
|
-
}
|
|
102
|
-
return foundPath;
|
|
103
|
-
};
|
|
104
|
-
const matches = [];
|
|
105
|
-
while (true) {
|
|
106
|
-
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
107
|
-
if (foundPath) {
|
|
108
|
-
matches.push((0, import_path.resolve)(directory, foundPath));
|
|
109
|
-
}
|
|
110
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
directory = (0, import_path.dirname)(directory);
|
|
114
|
-
}
|
|
115
|
-
return matches;
|
|
116
|
-
};
|
|
117
|
-
return (names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name)).flat().map((path) => path ? path : "");
|
|
118
|
-
}
|
|
119
|
-
async function findUp(names, options = { limit: 1, type: "file" }) {
|
|
120
|
-
const matches = await findUpMultiple(names, options);
|
|
121
|
-
return matches[0];
|
|
122
|
-
}
|
|
123
|
-
function findUpSync(names, options = { limit: 1, type: "file" }) {
|
|
124
|
-
const matches = findUpMultipleSync(names, options);
|
|
125
|
-
return matches[0];
|
|
126
42
|
}
|
|
127
43
|
|
|
128
44
|
// packages/config-tools/src/utilities/find-workspace-root.ts
|
|
@@ -150,38 +66,14 @@ var rootFiles = [
|
|
|
150
66
|
"pnpm-lock.yml",
|
|
151
67
|
"bun.lockb"
|
|
152
68
|
];
|
|
153
|
-
|
|
69
|
+
function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
154
70
|
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
155
71
|
return process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH;
|
|
156
72
|
}
|
|
157
|
-
return
|
|
158
|
-
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
159
|
-
type: "file",
|
|
160
|
-
limit: 1
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
function findWorkspaceRootSafeSync(pathInsideMonorepo) {
|
|
164
|
-
return process.env.STORM_WORKSPACE_ROOT ? process.env.STORM_WORKSPACE_ROOT : process.env.NX_WORKSPACE_ROOT_PATH ? process.env.NX_WORKSPACE_ROOT_PATH : findUpSync(rootFiles, {
|
|
165
|
-
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
166
|
-
type: "file",
|
|
167
|
-
limit: 1
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
async function findWorkspaceRoot(pathInsideMonorepo) {
|
|
171
|
-
const result = await findWorkspaceRootSafe(pathInsideMonorepo);
|
|
172
|
-
if (!result) {
|
|
173
|
-
throw new Error(
|
|
174
|
-
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
175
|
-
${rootFiles.join(
|
|
176
|
-
"\n"
|
|
177
|
-
)}
|
|
178
|
-
Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
return result;
|
|
73
|
+
return findFolderUp(pathInsideMonorepo ?? process.cwd(), rootFiles);
|
|
182
74
|
}
|
|
183
|
-
function
|
|
184
|
-
const result =
|
|
75
|
+
function findWorkspaceRoot(pathInsideMonorepo) {
|
|
76
|
+
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
185
77
|
if (!result) {
|
|
186
78
|
throw new Error(
|
|
187
79
|
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
@@ -196,7 +88,5 @@ Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
|
196
88
|
// Annotate the CommonJS export names for ESM import in node:
|
|
197
89
|
0 && (module.exports = {
|
|
198
90
|
findWorkspaceRoot,
|
|
199
|
-
findWorkspaceRootSafe
|
|
200
|
-
findWorkspaceRootSafeSync,
|
|
201
|
-
findWorkspaceRootSync
|
|
91
|
+
findWorkspaceRootSafe
|
|
202
92
|
});
|
|
@@ -1,100 +1,18 @@
|
|
|
1
1
|
// packages/config-tools/src/utilities/find-up.ts
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
var
|
|
6
|
-
function
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const foundPath = names(options.cwd);
|
|
16
|
-
return locatePathSync([foundPath], { ...options, cwd: directory });
|
|
17
|
-
}
|
|
18
|
-
const runNameMatcher = async (name) => {
|
|
19
|
-
const paths = [name].flat();
|
|
20
|
-
const runMatcher = async (locateOptions) => {
|
|
21
|
-
if (typeof name !== "function") {
|
|
22
|
-
return locatePath(paths, locateOptions);
|
|
23
|
-
}
|
|
24
|
-
const foundPath = await name(locateOptions.cwd);
|
|
25
|
-
if (typeof foundPath === "string") {
|
|
26
|
-
return locatePath([foundPath], locateOptions);
|
|
27
|
-
}
|
|
28
|
-
return foundPath;
|
|
29
|
-
};
|
|
30
|
-
const matches = [];
|
|
31
|
-
while (true) {
|
|
32
|
-
console.debug(
|
|
33
|
-
`Searching for workspace root files in ${directory}
|
|
34
|
-
Options: ${JSON.stringify(
|
|
35
|
-
options
|
|
36
|
-
)}`
|
|
37
|
-
);
|
|
38
|
-
const foundPath = await runMatcher({ ...options, cwd: directory });
|
|
39
|
-
console.debug(`Found path specified at ${foundPath}`);
|
|
40
|
-
if (foundPath) {
|
|
41
|
-
matches.push(resolve(directory, foundPath));
|
|
42
|
-
}
|
|
43
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
44
|
-
break;
|
|
45
|
-
}
|
|
46
|
-
directory = dirname(directory);
|
|
47
|
-
}
|
|
48
|
-
return matches;
|
|
49
|
-
};
|
|
50
|
-
const promises = Promise.all(
|
|
51
|
-
(names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name))
|
|
52
|
-
);
|
|
53
|
-
return (await promises).flat().map((path) => path ? path : "");
|
|
54
|
-
}
|
|
55
|
-
function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
56
|
-
let directory = resolve(toPath(options.cwd) ?? "");
|
|
57
|
-
const { root } = parse(directory);
|
|
58
|
-
const stopAt = resolve(directory, toPath(options.stopAt) ?? root);
|
|
59
|
-
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
60
|
-
if (typeof names === "function") {
|
|
61
|
-
const foundPath = names(options.cwd);
|
|
62
|
-
return locatePathSync([foundPath], options);
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { join } from "path";
|
|
4
|
+
var MAX_PATH_SEARCH_DEPTH = 30;
|
|
5
|
+
var depth = 0;
|
|
6
|
+
function findFolderUp(startPath, endFileNames) {
|
|
7
|
+
startPath = startPath ?? process.cwd();
|
|
8
|
+
if (endFileNames.some((endFileName) => existsSync(join(startPath, endFileName)))) {
|
|
9
|
+
return startPath;
|
|
10
|
+
} else if (startPath !== "/" && depth++ < MAX_PATH_SEARCH_DEPTH) {
|
|
11
|
+
const parent = join(startPath, "..");
|
|
12
|
+
return findFolderUp(parent, endFileNames);
|
|
13
|
+
} else {
|
|
14
|
+
return void 0;
|
|
63
15
|
}
|
|
64
|
-
const runNameMatcher = (name) => {
|
|
65
|
-
const paths = [name].flat();
|
|
66
|
-
const runMatcher = (locateOptions) => {
|
|
67
|
-
if (typeof name !== "function") {
|
|
68
|
-
return locatePathSync(paths, locateOptions);
|
|
69
|
-
}
|
|
70
|
-
const foundPath = name(locateOptions.cwd);
|
|
71
|
-
if (typeof foundPath === "string") {
|
|
72
|
-
return locatePathSync([foundPath], locateOptions);
|
|
73
|
-
}
|
|
74
|
-
return foundPath;
|
|
75
|
-
};
|
|
76
|
-
const matches = [];
|
|
77
|
-
while (true) {
|
|
78
|
-
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
79
|
-
if (foundPath) {
|
|
80
|
-
matches.push(resolve(directory, foundPath));
|
|
81
|
-
}
|
|
82
|
-
if (directory === stopAt || matches.length >= limit) {
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
directory = dirname(directory);
|
|
86
|
-
}
|
|
87
|
-
return matches;
|
|
88
|
-
};
|
|
89
|
-
return (names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name)).flat().map((path) => path ? path : "");
|
|
90
|
-
}
|
|
91
|
-
async function findUp(names, options = { limit: 1, type: "file" }) {
|
|
92
|
-
const matches = await findUpMultiple(names, options);
|
|
93
|
-
return matches[0];
|
|
94
|
-
}
|
|
95
|
-
function findUpSync(names, options = { limit: 1, type: "file" }) {
|
|
96
|
-
const matches = findUpMultipleSync(names, options);
|
|
97
|
-
return matches[0];
|
|
98
16
|
}
|
|
99
17
|
|
|
100
18
|
// packages/config-tools/src/utilities/find-workspace-root.ts
|
|
@@ -122,38 +40,14 @@ var rootFiles = [
|
|
|
122
40
|
"pnpm-lock.yml",
|
|
123
41
|
"bun.lockb"
|
|
124
42
|
];
|
|
125
|
-
|
|
43
|
+
function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
126
44
|
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
127
45
|
return process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH;
|
|
128
46
|
}
|
|
129
|
-
return
|
|
130
|
-
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
131
|
-
type: "file",
|
|
132
|
-
limit: 1
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
function findWorkspaceRootSafeSync(pathInsideMonorepo) {
|
|
136
|
-
return process.env.STORM_WORKSPACE_ROOT ? process.env.STORM_WORKSPACE_ROOT : process.env.NX_WORKSPACE_ROOT_PATH ? process.env.NX_WORKSPACE_ROOT_PATH : findUpSync(rootFiles, {
|
|
137
|
-
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
138
|
-
type: "file",
|
|
139
|
-
limit: 1
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
async function findWorkspaceRoot(pathInsideMonorepo) {
|
|
143
|
-
const result = await findWorkspaceRootSafe(pathInsideMonorepo);
|
|
144
|
-
if (!result) {
|
|
145
|
-
throw new Error(
|
|
146
|
-
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
147
|
-
${rootFiles.join(
|
|
148
|
-
"\n"
|
|
149
|
-
)}
|
|
150
|
-
Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
return result;
|
|
47
|
+
return findFolderUp(pathInsideMonorepo ?? process.cwd(), rootFiles);
|
|
154
48
|
}
|
|
155
|
-
function
|
|
156
|
-
const result =
|
|
49
|
+
function findWorkspaceRoot(pathInsideMonorepo) {
|
|
50
|
+
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
157
51
|
if (!result) {
|
|
158
52
|
throw new Error(
|
|
159
53
|
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
@@ -167,7 +61,5 @@ Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
|
167
61
|
}
|
|
168
62
|
export {
|
|
169
63
|
findWorkspaceRoot,
|
|
170
|
-
findWorkspaceRootSafe
|
|
171
|
-
findWorkspaceRootSafeSync,
|
|
172
|
-
findWorkspaceRootSync
|
|
64
|
+
findWorkspaceRootSafe
|
|
173
65
|
};
|