@dbx-tools/core 0.6.88 → 0.6.89
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/README.md +9 -14
- package/index.ts +1 -2
- package/lib/index.d.ts +1 -2
- package/lib/index.js +2 -2
- package/lib/src/config.d.ts +26 -51
- package/lib/src/config.js +123 -274
- package/lib/src/project.d.ts +1 -1
- package/lib/src/project.js +8 -8
- package/package.json +2 -11
- package/src/config.ts +149 -279
- package/src/project.ts +8 -8
package/src/project.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { spawnSync } from "node:child_process";
|
|
|
2
2
|
import { Stats, readFileSync } from "node:fs";
|
|
3
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
4
4
|
import { context, json, net, string } from "@dbx-tools/shared-core";
|
|
5
|
-
import { statSync as
|
|
5
|
+
import { statSync as fileStatSync } from "./file.ts";
|
|
6
6
|
|
|
7
7
|
const ROOT_MARKERS = [
|
|
8
8
|
".projenrc.ts",
|
|
@@ -18,7 +18,7 @@ export interface ProjectContext {
|
|
|
18
18
|
readonly output: string;
|
|
19
19
|
/** `output` when it names something on disk. */
|
|
20
20
|
readonly path?: string;
|
|
21
|
-
/** `
|
|
21
|
+
/** `file.statSync` of {@link path}, when it exists. */
|
|
22
22
|
readonly pathStats?: Stats;
|
|
23
23
|
/**
|
|
24
24
|
* `output` parsed into a chainable {@link net.UrlBuilder}, when it is a real
|
|
@@ -40,7 +40,7 @@ function projectContextCommandOutput(command: string, args: string[], cwd: strin
|
|
|
40
40
|
const result = spawnSync(command, args, { cwd, stdio: ["ignore", "pipe", "ignore"] });
|
|
41
41
|
const output = result?.stdout?.toString()?.trim();
|
|
42
42
|
if (result.status === 0 && output) {
|
|
43
|
-
const pathStats =
|
|
43
|
+
const pathStats = fileStatSync(output);
|
|
44
44
|
// Only an EXPLICIT `scheme://...` counts as a URL. `urlBuilder` otherwise
|
|
45
45
|
// synthesizes one (a bare `example.com` -> `https://…`, an absolute path ->
|
|
46
46
|
// `http://localhost/…`), which would mislabel directory outputs and bare
|
|
@@ -83,7 +83,7 @@ function gitRoot(cwd?: string): string | undefined {
|
|
|
83
83
|
export function root(cwd: string = process.cwd()): string | undefined {
|
|
84
84
|
let current = resolve(cwd);
|
|
85
85
|
|
|
86
|
-
if (!
|
|
86
|
+
if (!fileStatSync(current)?.isDirectory()) {
|
|
87
87
|
current = dirname(current);
|
|
88
88
|
}
|
|
89
89
|
const boundaries = new Set(
|
|
@@ -95,7 +95,7 @@ export function root(cwd: string = process.cwd()): string | undefined {
|
|
|
95
95
|
let best: { dir: string; priority: number } | undefined;
|
|
96
96
|
while (true) {
|
|
97
97
|
for (const [priority, marker] of ROOT_MARKERS.entries()) {
|
|
98
|
-
if (
|
|
98
|
+
if (fileStatSync(join(current, marker))?.isFile()) {
|
|
99
99
|
if (
|
|
100
100
|
best === undefined ||
|
|
101
101
|
priority < best.priority ||
|
|
@@ -160,7 +160,7 @@ export function* resolveProjectRoots(cwd: string = process.cwd()): Generator<str
|
|
|
160
160
|
const dir = resolve(candidate);
|
|
161
161
|
if (seen.has(dir)) continue;
|
|
162
162
|
seen.add(dir);
|
|
163
|
-
if (
|
|
163
|
+
if (fileStatSync(dir)?.isDirectory()) yield dir;
|
|
164
164
|
}
|
|
165
165
|
if (!seen.has(base)) yield base;
|
|
166
166
|
}
|
|
@@ -169,7 +169,7 @@ export function* resolveProjectRoots(cwd: string = process.cwd()): Generator<str
|
|
|
169
169
|
function workspaceRoot(cwd: string = process.cwd()): string {
|
|
170
170
|
let last: string | undefined;
|
|
171
171
|
for (const dir of resolveProjectRoots(cwd)) {
|
|
172
|
-
if (
|
|
172
|
+
if (fileStatSync(resolve(dir, "package.json"))?.isFile()) return dir;
|
|
173
173
|
last = dir;
|
|
174
174
|
}
|
|
175
175
|
return last ?? resolve(cwd);
|
|
@@ -311,7 +311,7 @@ export function npmRegistry(
|
|
|
311
311
|
}
|
|
312
312
|
|
|
313
313
|
function readPackageName(pkgPath: string): string | undefined {
|
|
314
|
-
if (!
|
|
314
|
+
if (!fileStatSync(pkgPath)?.isFile()) return undefined;
|
|
315
315
|
return string.trimToNull(json.parseRecord(readFileSync(pkgPath, "utf8"))?.name) ?? undefined;
|
|
316
316
|
}
|
|
317
317
|
|