@storm-software/config-tools 1.6.1 → 1.7.1
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 +14 -0
- package/README.md +1 -1
- package/declarations.d.ts +22 -2
- package/index.cjs +91 -14
- package/index.js +86 -11
- package/meta.cjs.json +1 -1
- package/meta.esm.json +1 -1
- package/package.json +1 -1
- package/utilities/find-workspace-root.cjs +89 -22
- package/utilities/find-workspace-root.js +86 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
# [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
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **config-tools:** Added the `findWorkspaceRootSync` and `findWorkspaceRootSafeSync` functions ([59e0ee4](https://github.com/storm-software/storm-ops/commit/59e0ee4779a15752fb035d235b929bb3e8ecc974))
|
|
7
|
+
|
|
8
|
+
## [1.6.1](https://github.com/storm-software/storm-ops/compare/config-tools-v1.6.0...config-tools-v1.6.1) (2023-12-21)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **config-tools:** Remove unused dependencies ([ef00034](https://github.com/storm-software/storm-ops/commit/ef00034e8a79b81147056ee32a12eaa991a0d4f3))
|
|
14
|
+
|
|
1
15
|
# [1.6.0](https://github.com/storm-software/storm-ops/compare/config-tools-v1.5.14...config-tools-v1.6.0) (2023-12-21)
|
|
2
16
|
|
|
3
17
|
|
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ This package is part of the <b>⚡Storm-Ops</b> monorepo. The Storm-Ops packages
|
|
|
16
16
|
|
|
17
17
|
<h3 align="center">💻 Visit <a href="https://stormsoftware.org" target="_blank">stormsoftware.org</a> to stay up to date with this developer</h3><br />
|
|
18
18
|
|
|
19
|
-
[](https://prettier.io/)
|
|
20
20
|
[](http://nx.dev/) [](https://nextjs.org/) [](http://commitizen.github.io/cz-cli/)  [](https://docusaurus.io/) 
|
|
21
21
|
|
|
22
22
|
<h3 align="center" bold="true">⚠️ <b>Attention</b> ⚠️ This repository, and the apps, libraries, and tools contained within, is still in it's initial development phase. As a result, bugs and issues are expected with it's usage. When the main development phase completes, a proper release will be performed, the packages will be availible through NPM (and other distributions), and this message will be removed. However, in the meantime, please feel free to report any issues you may come across.</h3><br />
|
package/declarations.d.ts
CHANGED
|
@@ -22,7 +22,9 @@ export { StormConfig };
|
|
|
22
22
|
*
|
|
23
23
|
* @param pathInsideMonorepo - The path inside the monorepo
|
|
24
24
|
*/
|
|
25
|
-
declare function findWorkspaceRoot(
|
|
25
|
+
declare function findWorkspaceRoot(
|
|
26
|
+
pathInsideMonorepo?: string
|
|
27
|
+
): Promise<string>;
|
|
26
28
|
export { findWorkspaceRoot };
|
|
27
29
|
|
|
28
30
|
/**
|
|
@@ -32,9 +34,27 @@ export { findWorkspaceRoot };
|
|
|
32
34
|
*/
|
|
33
35
|
declare function findWorkspaceRootSafe(
|
|
34
36
|
pathInsideMonorepo?: string
|
|
35
|
-
): string | undefined
|
|
37
|
+
): Promise<string | undefined>;
|
|
36
38
|
export { findWorkspaceRootSafe };
|
|
37
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;
|
|
46
|
+
export { findWorkspaceRootSync };
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Find the root of the current monorepo safely (do not throw an error if it cannot be found)
|
|
50
|
+
*
|
|
51
|
+
* @param pathInsideMonorepo - The path inside the monorepo
|
|
52
|
+
*/
|
|
53
|
+
declare function findWorkspaceRootSafeSync(
|
|
54
|
+
pathInsideMonorepo?: string
|
|
55
|
+
): string | undefined;
|
|
56
|
+
export { findWorkspaceRootSafeSync };
|
|
57
|
+
|
|
38
58
|
/**
|
|
39
59
|
* Type-check to determine if `obj` is a `StormError` object
|
|
40
60
|
*
|
package/index.cjs
CHANGED
|
@@ -40,6 +40,8 @@ __export(src_exports, {
|
|
|
40
40
|
createStormConfig: () => createStormConfig,
|
|
41
41
|
findWorkspaceRoot: () => findWorkspaceRoot,
|
|
42
42
|
findWorkspaceRootSafe: () => findWorkspaceRootSafe,
|
|
43
|
+
findWorkspaceRootSafeSync: () => findWorkspaceRootSafeSync,
|
|
44
|
+
findWorkspaceRootSync: () => findWorkspaceRootSync,
|
|
43
45
|
getConfigEnv: () => getConfigEnv,
|
|
44
46
|
getConfigFile: () => getConfigFile,
|
|
45
47
|
getDefaultConfig: () => getDefaultConfig,
|
|
@@ -110,16 +112,62 @@ var LogLevelLabel = {
|
|
|
110
112
|
|
|
111
113
|
// packages/config-tools/src/utilities/find-up.ts
|
|
112
114
|
var import_locate_path = require("locate-path");
|
|
113
|
-
var
|
|
115
|
+
var import_path = require("path");
|
|
114
116
|
var import_url = require("url");
|
|
115
117
|
var findUpStop = Symbol("findUpStop");
|
|
116
118
|
function toPath(urlOrPath) {
|
|
117
119
|
return urlOrPath instanceof URL ? (0, import_url.fileURLToPath)(urlOrPath) : urlOrPath;
|
|
118
120
|
}
|
|
121
|
+
async function findUpMultiple(names, options = { limit: Number.POSITIVE_INFINITY, type: "file" }) {
|
|
122
|
+
let directory = (0, import_path.resolve)(toPath(options.cwd) ?? "");
|
|
123
|
+
const { root } = (0, import_path.parse)(directory);
|
|
124
|
+
const stopAt = (0, import_path.resolve)(directory, toPath(options.stopAt ?? root));
|
|
125
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
126
|
+
if (typeof names === "function") {
|
|
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
|
+
}
|
|
119
167
|
function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
120
|
-
let directory =
|
|
121
|
-
const { root } =
|
|
122
|
-
const stopAt =
|
|
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);
|
|
123
171
|
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
124
172
|
if (typeof names === "function") {
|
|
125
173
|
const foundPath = names(options.cwd);
|
|
@@ -141,16 +189,20 @@ function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
|
141
189
|
while (true) {
|
|
142
190
|
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
143
191
|
if (foundPath) {
|
|
144
|
-
matches.push(
|
|
192
|
+
matches.push((0, import_path.resolve)(directory, foundPath));
|
|
145
193
|
}
|
|
146
194
|
if (directory === stopAt || matches.length >= limit) {
|
|
147
195
|
break;
|
|
148
196
|
}
|
|
149
|
-
directory =
|
|
197
|
+
directory = (0, import_path.dirname)(directory);
|
|
150
198
|
}
|
|
151
199
|
return matches;
|
|
152
200
|
};
|
|
153
|
-
return (names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name)).flat();
|
|
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];
|
|
154
206
|
}
|
|
155
207
|
function findUpSync(names, options = { limit: 1, type: "file" }) {
|
|
156
208
|
const matches = findUpMultipleSync(names, options);
|
|
@@ -182,15 +234,38 @@ var rootFiles = [
|
|
|
182
234
|
"pnpm-lock.yml",
|
|
183
235
|
"bun.lockb"
|
|
184
236
|
];
|
|
185
|
-
function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
237
|
+
async function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
238
|
+
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
239
|
+
return process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH;
|
|
240
|
+
}
|
|
241
|
+
return await findUp(rootFiles, {
|
|
242
|
+
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
243
|
+
type: "file",
|
|
244
|
+
limit: 1
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
function findWorkspaceRootSafeSync(pathInsideMonorepo) {
|
|
186
248
|
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, {
|
|
187
249
|
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
188
250
|
type: "file",
|
|
189
251
|
limit: 1
|
|
190
252
|
});
|
|
191
253
|
}
|
|
192
|
-
function findWorkspaceRoot(pathInsideMonorepo) {
|
|
193
|
-
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
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);
|
|
194
269
|
if (!result) {
|
|
195
270
|
throw new Error(
|
|
196
271
|
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
@@ -205,7 +280,7 @@ Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
|
205
280
|
|
|
206
281
|
// packages/config-tools/src/utilities/get-default-config.ts
|
|
207
282
|
var import_fs = require("fs");
|
|
208
|
-
var
|
|
283
|
+
var import_path2 = require("path");
|
|
209
284
|
|
|
210
285
|
// packages/config-tools/src/schema.ts
|
|
211
286
|
var z = __toESM(require("zod"), 1);
|
|
@@ -295,9 +370,9 @@ var getDefaultConfig = (config = {}, root) => {
|
|
|
295
370
|
let repository = "https://github.com/storm-software/storm-stack";
|
|
296
371
|
let license = DefaultStormConfig.license;
|
|
297
372
|
let homepage = DefaultStormConfig.homepage;
|
|
298
|
-
const workspaceRoot =
|
|
299
|
-
if ((0, import_fs.existsSync)((0,
|
|
300
|
-
const file = (0, import_fs.readFileSync)((0,
|
|
373
|
+
const workspaceRoot = findWorkspaceRootSync(root);
|
|
374
|
+
if ((0, import_fs.existsSync)((0, import_path2.join)(workspaceRoot, "package.json"))) {
|
|
375
|
+
const file = (0, import_fs.readFileSync)((0, import_path2.join)(workspaceRoot, "package.json"), {
|
|
301
376
|
encoding: "utf-8"
|
|
302
377
|
});
|
|
303
378
|
if (file) {
|
|
@@ -552,6 +627,8 @@ var setConfigEnv = (config) => {
|
|
|
552
627
|
createStormConfig,
|
|
553
628
|
findWorkspaceRoot,
|
|
554
629
|
findWorkspaceRootSafe,
|
|
630
|
+
findWorkspaceRootSafeSync,
|
|
631
|
+
findWorkspaceRootSync,
|
|
555
632
|
getConfigEnv,
|
|
556
633
|
getConfigFile,
|
|
557
634
|
getDefaultConfig,
|
package/index.js
CHANGED
|
@@ -57,16 +57,62 @@ var LogLevelLabel = {
|
|
|
57
57
|
|
|
58
58
|
// packages/config-tools/src/utilities/find-up.ts
|
|
59
59
|
import { locatePath, locatePathSync } from "locate-path";
|
|
60
|
-
import
|
|
60
|
+
import { dirname, parse, resolve } from "path";
|
|
61
61
|
import { fileURLToPath } from "url";
|
|
62
62
|
var findUpStop = Symbol("findUpStop");
|
|
63
63
|
function toPath(urlOrPath) {
|
|
64
64
|
return urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
65
65
|
}
|
|
66
|
+
async function findUpMultiple(names, options = { limit: Number.POSITIVE_INFINITY, type: "file" }) {
|
|
67
|
+
let directory = resolve(toPath(options.cwd) ?? "");
|
|
68
|
+
const { root } = parse(directory);
|
|
69
|
+
const stopAt = resolve(directory, toPath(options.stopAt ?? root));
|
|
70
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
71
|
+
if (typeof names === "function") {
|
|
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
|
+
}
|
|
66
112
|
function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
67
|
-
let directory =
|
|
68
|
-
const { root } =
|
|
69
|
-
const stopAt =
|
|
113
|
+
let directory = resolve(toPath(options.cwd) ?? "");
|
|
114
|
+
const { root } = parse(directory);
|
|
115
|
+
const stopAt = resolve(directory, toPath(options.stopAt) ?? root);
|
|
70
116
|
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
71
117
|
if (typeof names === "function") {
|
|
72
118
|
const foundPath = names(options.cwd);
|
|
@@ -88,16 +134,20 @@ function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
|
88
134
|
while (true) {
|
|
89
135
|
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
90
136
|
if (foundPath) {
|
|
91
|
-
matches.push(
|
|
137
|
+
matches.push(resolve(directory, foundPath));
|
|
92
138
|
}
|
|
93
139
|
if (directory === stopAt || matches.length >= limit) {
|
|
94
140
|
break;
|
|
95
141
|
}
|
|
96
|
-
directory =
|
|
142
|
+
directory = dirname(directory);
|
|
97
143
|
}
|
|
98
144
|
return matches;
|
|
99
145
|
};
|
|
100
|
-
return (names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name)).flat();
|
|
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];
|
|
101
151
|
}
|
|
102
152
|
function findUpSync(names, options = { limit: 1, type: "file" }) {
|
|
103
153
|
const matches = findUpMultipleSync(names, options);
|
|
@@ -129,15 +179,38 @@ var rootFiles = [
|
|
|
129
179
|
"pnpm-lock.yml",
|
|
130
180
|
"bun.lockb"
|
|
131
181
|
];
|
|
132
|
-
function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
182
|
+
async function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
183
|
+
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
184
|
+
return process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH;
|
|
185
|
+
}
|
|
186
|
+
return await findUp(rootFiles, {
|
|
187
|
+
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
188
|
+
type: "file",
|
|
189
|
+
limit: 1
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function findWorkspaceRootSafeSync(pathInsideMonorepo) {
|
|
133
193
|
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, {
|
|
134
194
|
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
135
195
|
type: "file",
|
|
136
196
|
limit: 1
|
|
137
197
|
});
|
|
138
198
|
}
|
|
139
|
-
function findWorkspaceRoot(pathInsideMonorepo) {
|
|
140
|
-
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
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);
|
|
141
214
|
if (!result) {
|
|
142
215
|
throw new Error(
|
|
143
216
|
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
@@ -242,7 +315,7 @@ var getDefaultConfig = (config = {}, root) => {
|
|
|
242
315
|
let repository = "https://github.com/storm-software/storm-stack";
|
|
243
316
|
let license = DefaultStormConfig.license;
|
|
244
317
|
let homepage = DefaultStormConfig.homepage;
|
|
245
|
-
const workspaceRoot =
|
|
318
|
+
const workspaceRoot = findWorkspaceRootSync(root);
|
|
246
319
|
if (existsSync(join(workspaceRoot, "package.json"))) {
|
|
247
320
|
const file = readFileSync(join(workspaceRoot, "package.json"), {
|
|
248
321
|
encoding: "utf-8"
|
|
@@ -498,6 +571,8 @@ export {
|
|
|
498
571
|
createStormConfig,
|
|
499
572
|
findWorkspaceRoot,
|
|
500
573
|
findWorkspaceRootSafe,
|
|
574
|
+
findWorkspaceRootSafeSync,
|
|
575
|
+
findWorkspaceRootSync,
|
|
501
576
|
getConfigEnv,
|
|
502
577
|
getConfigFile,
|
|
503
578
|
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":4531,"imports":[{"path":"locate-path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"url","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytes":3052,"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":5736,"imports":[{"path":"zod","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/get-default-config.ts":{"bytes":2608,"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":"locate-path","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"url","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":1015},"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":3846},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytesInOutput":1900},"packages/config-tools/src/utilities/index.ts":{"bytesInOutput":0},"packages/config-tools/src/utilities/get-default-config.ts":{"bytesInOutput":2042},"packages/config-tools/src/schema.ts":{"bytesInOutput":4454},"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":26338},"dist/packages/config-tools/utilities/find-workspace-root.cjs":{"imports":[{"path":"locate-path","kind":"require-call","external":true},{"path":"path","kind":"require-call","external":true},{"path":"url","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":2257},"packages/config-tools/src/utilities/find-up.ts":{"bytesInOutput":3846}},"bytes":7255}}}
|
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":4531,"imports":[{"path":"locate-path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"url","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytes":3052,"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":5736,"imports":[{"path":"zod","kind":"import-statement","external":true}],"format":"esm"},"packages/config-tools/src/utilities/get-default-config.ts":{"bytes":2608,"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":"locate-path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"url","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","findWorkspaceRootSafeSync","findWorkspaceRootSync","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":3542},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytesInOutput":1900},"packages/config-tools/src/utilities/index.ts":{"bytesInOutput":0},"packages/config-tools/src/utilities/get-default-config.ts":{"bytesInOutput":1985},"packages/config-tools/src/schema.ts":{"bytesInOutput":4444},"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":23421},"dist/packages/config-tools/utilities/find-workspace-root.js":{"imports":[{"path":"locate-path","kind":"import-statement","external":true},{"path":"path","kind":"import-statement","external":true},{"path":"url","kind":"import-statement","external":true}],"exports":["findWorkspaceRoot","findWorkspaceRootSafe","findWorkspaceRootSafeSync","findWorkspaceRootSync"],"entryPoint":"packages/config-tools/src/utilities/find-workspace-root.ts","inputs":{"packages/config-tools/src/utilities/find-up.ts":{"bytesInOutput":3542},"packages/config-tools/src/utilities/find-workspace-root.ts":{"bytesInOutput":1900}},"bytes":5666}}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storm-software/config-tools",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.7.1",
|
|
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": {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
6
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
5
|
var __export = (target, all) => {
|
|
8
6
|
for (var name in all)
|
|
@@ -16,36 +14,76 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
16
14
|
}
|
|
17
15
|
return to;
|
|
18
16
|
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
-
mod
|
|
26
|
-
));
|
|
27
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
18
|
|
|
29
19
|
// packages/config-tools/src/utilities/find-workspace-root.ts
|
|
30
20
|
var find_workspace_root_exports = {};
|
|
31
21
|
__export(find_workspace_root_exports, {
|
|
32
22
|
findWorkspaceRoot: () => findWorkspaceRoot,
|
|
33
|
-
findWorkspaceRootSafe: () => findWorkspaceRootSafe
|
|
23
|
+
findWorkspaceRootSafe: () => findWorkspaceRootSafe,
|
|
24
|
+
findWorkspaceRootSafeSync: () => findWorkspaceRootSafeSync,
|
|
25
|
+
findWorkspaceRootSync: () => findWorkspaceRootSync
|
|
34
26
|
});
|
|
35
27
|
module.exports = __toCommonJS(find_workspace_root_exports);
|
|
36
28
|
|
|
37
29
|
// packages/config-tools/src/utilities/find-up.ts
|
|
38
30
|
var import_locate_path = require("locate-path");
|
|
39
|
-
var
|
|
31
|
+
var import_path = require("path");
|
|
40
32
|
var import_url = require("url");
|
|
41
33
|
var findUpStop = Symbol("findUpStop");
|
|
42
34
|
function toPath(urlOrPath) {
|
|
43
35
|
return urlOrPath instanceof URL ? (0, import_url.fileURLToPath)(urlOrPath) : urlOrPath;
|
|
44
36
|
}
|
|
37
|
+
async function findUpMultiple(names, options = { limit: Number.POSITIVE_INFINITY, type: "file" }) {
|
|
38
|
+
let directory = (0, import_path.resolve)(toPath(options.cwd) ?? "");
|
|
39
|
+
const { root } = (0, import_path.parse)(directory);
|
|
40
|
+
const stopAt = (0, import_path.resolve)(directory, toPath(options.stopAt ?? root));
|
|
41
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
42
|
+
if (typeof names === "function") {
|
|
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
|
+
}
|
|
45
83
|
function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
46
|
-
let directory =
|
|
47
|
-
const { root } =
|
|
48
|
-
const stopAt =
|
|
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);
|
|
49
87
|
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
50
88
|
if (typeof names === "function") {
|
|
51
89
|
const foundPath = names(options.cwd);
|
|
@@ -67,16 +105,20 @@ function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
|
67
105
|
while (true) {
|
|
68
106
|
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
69
107
|
if (foundPath) {
|
|
70
|
-
matches.push(
|
|
108
|
+
matches.push((0, import_path.resolve)(directory, foundPath));
|
|
71
109
|
}
|
|
72
110
|
if (directory === stopAt || matches.length >= limit) {
|
|
73
111
|
break;
|
|
74
112
|
}
|
|
75
|
-
directory =
|
|
113
|
+
directory = (0, import_path.dirname)(directory);
|
|
76
114
|
}
|
|
77
115
|
return matches;
|
|
78
116
|
};
|
|
79
|
-
return (names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name)).flat();
|
|
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];
|
|
80
122
|
}
|
|
81
123
|
function findUpSync(names, options = { limit: 1, type: "file" }) {
|
|
82
124
|
const matches = findUpMultipleSync(names, options);
|
|
@@ -108,15 +150,38 @@ var rootFiles = [
|
|
|
108
150
|
"pnpm-lock.yml",
|
|
109
151
|
"bun.lockb"
|
|
110
152
|
];
|
|
111
|
-
function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
153
|
+
async function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
154
|
+
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
155
|
+
return process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH;
|
|
156
|
+
}
|
|
157
|
+
return await findUp(rootFiles, {
|
|
158
|
+
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
159
|
+
type: "file",
|
|
160
|
+
limit: 1
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function findWorkspaceRootSafeSync(pathInsideMonorepo) {
|
|
112
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, {
|
|
113
165
|
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
114
166
|
type: "file",
|
|
115
167
|
limit: 1
|
|
116
168
|
});
|
|
117
169
|
}
|
|
118
|
-
function findWorkspaceRoot(pathInsideMonorepo) {
|
|
119
|
-
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
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;
|
|
182
|
+
}
|
|
183
|
+
function findWorkspaceRootSync(pathInsideMonorepo) {
|
|
184
|
+
const result = findWorkspaceRootSafeSync(pathInsideMonorepo);
|
|
120
185
|
if (!result) {
|
|
121
186
|
throw new Error(
|
|
122
187
|
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
@@ -131,5 +196,7 @@ Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
|
131
196
|
// Annotate the CommonJS export names for ESM import in node:
|
|
132
197
|
0 && (module.exports = {
|
|
133
198
|
findWorkspaceRoot,
|
|
134
|
-
findWorkspaceRootSafe
|
|
199
|
+
findWorkspaceRootSafe,
|
|
200
|
+
findWorkspaceRootSafeSync,
|
|
201
|
+
findWorkspaceRootSync
|
|
135
202
|
});
|
|
@@ -1,15 +1,61 @@
|
|
|
1
1
|
// packages/config-tools/src/utilities/find-up.ts
|
|
2
2
|
import { locatePath, locatePathSync } from "locate-path";
|
|
3
|
-
import
|
|
3
|
+
import { dirname, parse, resolve } from "path";
|
|
4
4
|
import { fileURLToPath } from "url";
|
|
5
5
|
var findUpStop = Symbol("findUpStop");
|
|
6
6
|
function toPath(urlOrPath) {
|
|
7
7
|
return urlOrPath instanceof URL ? fileURLToPath(urlOrPath) : urlOrPath;
|
|
8
8
|
}
|
|
9
|
+
async function findUpMultiple(names, options = { limit: Number.POSITIVE_INFINITY, type: "file" }) {
|
|
10
|
+
let directory = resolve(toPath(options.cwd) ?? "");
|
|
11
|
+
const { root } = parse(directory);
|
|
12
|
+
const stopAt = resolve(directory, toPath(options.stopAt ?? root));
|
|
13
|
+
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
14
|
+
if (typeof names === "function") {
|
|
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
|
+
}
|
|
9
55
|
function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
10
|
-
let directory =
|
|
11
|
-
const { root } =
|
|
12
|
-
const stopAt =
|
|
56
|
+
let directory = resolve(toPath(options.cwd) ?? "");
|
|
57
|
+
const { root } = parse(directory);
|
|
58
|
+
const stopAt = resolve(directory, toPath(options.stopAt) ?? root);
|
|
13
59
|
const limit = options.limit ?? Number.POSITIVE_INFINITY;
|
|
14
60
|
if (typeof names === "function") {
|
|
15
61
|
const foundPath = names(options.cwd);
|
|
@@ -31,16 +77,20 @@ function findUpMultipleSync(names, options = { limit: 1, type: "file" }) {
|
|
|
31
77
|
while (true) {
|
|
32
78
|
const foundPath = runMatcher({ ...options, cwd: directory });
|
|
33
79
|
if (foundPath) {
|
|
34
|
-
matches.push(
|
|
80
|
+
matches.push(resolve(directory, foundPath));
|
|
35
81
|
}
|
|
36
82
|
if (directory === stopAt || matches.length >= limit) {
|
|
37
83
|
break;
|
|
38
84
|
}
|
|
39
|
-
directory =
|
|
85
|
+
directory = dirname(directory);
|
|
40
86
|
}
|
|
41
87
|
return matches;
|
|
42
88
|
};
|
|
43
|
-
return (names && Array.isArray(names) ? names : [names]).map((name) => runNameMatcher(name)).flat();
|
|
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];
|
|
44
94
|
}
|
|
45
95
|
function findUpSync(names, options = { limit: 1, type: "file" }) {
|
|
46
96
|
const matches = findUpMultipleSync(names, options);
|
|
@@ -72,15 +122,38 @@ var rootFiles = [
|
|
|
72
122
|
"pnpm-lock.yml",
|
|
73
123
|
"bun.lockb"
|
|
74
124
|
];
|
|
75
|
-
function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
125
|
+
async function findWorkspaceRootSafe(pathInsideMonorepo) {
|
|
126
|
+
if (process.env.STORM_WORKSPACE_ROOT || process.env.NX_WORKSPACE_ROOT_PATH) {
|
|
127
|
+
return process.env.STORM_WORKSPACE_ROOT ?? process.env.NX_WORKSPACE_ROOT_PATH;
|
|
128
|
+
}
|
|
129
|
+
return await findUp(rootFiles, {
|
|
130
|
+
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
131
|
+
type: "file",
|
|
132
|
+
limit: 1
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
function findWorkspaceRootSafeSync(pathInsideMonorepo) {
|
|
76
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, {
|
|
77
137
|
cwd: pathInsideMonorepo ?? process.cwd(),
|
|
78
138
|
type: "file",
|
|
79
139
|
limit: 1
|
|
80
140
|
});
|
|
81
141
|
}
|
|
82
|
-
function findWorkspaceRoot(pathInsideMonorepo) {
|
|
83
|
-
const result = findWorkspaceRootSafe(pathInsideMonorepo);
|
|
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;
|
|
154
|
+
}
|
|
155
|
+
function findWorkspaceRootSync(pathInsideMonorepo) {
|
|
156
|
+
const result = findWorkspaceRootSafeSync(pathInsideMonorepo);
|
|
84
157
|
if (!result) {
|
|
85
158
|
throw new Error(
|
|
86
159
|
`Cannot find workspace root upwards from known path. Files search list includes:
|
|
@@ -94,5 +167,7 @@ Path: ${pathInsideMonorepo ? pathInsideMonorepo : process.cwd()}`
|
|
|
94
167
|
}
|
|
95
168
|
export {
|
|
96
169
|
findWorkspaceRoot,
|
|
97
|
-
findWorkspaceRootSafe
|
|
170
|
+
findWorkspaceRootSafe,
|
|
171
|
+
findWorkspaceRootSafeSync,
|
|
172
|
+
findWorkspaceRootSync
|
|
98
173
|
};
|