@dbx-tools/core 0.3.21 → 0.3.22
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/package.json +2 -2
- package/src/brand.ts +6 -3
- package/src/exec.ts +16 -21
- package/src/project.ts +11 -9
package/package.json
CHANGED
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"yaml": "^2.9.0",
|
|
15
|
-
"@dbx-tools/shared-core": "0.3.
|
|
15
|
+
"@dbx-tools/shared-core": "0.3.22"
|
|
16
16
|
},
|
|
17
17
|
"main": "index.ts",
|
|
18
18
|
"license": "UNLICENSED",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
-
"version": "0.3.
|
|
22
|
+
"version": "0.3.22",
|
|
23
23
|
"types": "index.ts",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"exports": {
|
package/src/brand.ts
CHANGED
|
@@ -39,11 +39,14 @@ export async function loadBrandContextFile(path: string): Promise<BrandContext>
|
|
|
39
39
|
const extension = extname(path).toLowerCase();
|
|
40
40
|
let input: unknown;
|
|
41
41
|
|
|
42
|
-
if (extension === ".json")
|
|
43
|
-
|
|
42
|
+
if (extension === ".json") {
|
|
43
|
+
input = JSON.parse(source) as unknown;
|
|
44
|
+
} else if (extension === ".yaml" || extension === ".yml") {
|
|
44
45
|
const { parse } = await import("yaml");
|
|
45
46
|
input = parse(source) as unknown;
|
|
46
|
-
} else
|
|
47
|
+
} else {
|
|
48
|
+
throw new Error(`Unsupported brand context format: ${extension || "no extension"}`);
|
|
49
|
+
}
|
|
47
50
|
|
|
48
51
|
return sharedBrand.parseBrandContext(input);
|
|
49
52
|
}
|
package/src/exec.ts
CHANGED
|
@@ -39,7 +39,12 @@
|
|
|
39
39
|
*
|
|
40
40
|
* @module
|
|
41
41
|
*/
|
|
42
|
-
import {
|
|
42
|
+
import {
|
|
43
|
+
type ChildProcess,
|
|
44
|
+
type SpawnOptions,
|
|
45
|
+
spawn as nodeSpawn,
|
|
46
|
+
spawnSync as nodeSpawnSync,
|
|
47
|
+
} from "node:child_process";
|
|
43
48
|
import * as readline from "node:readline";
|
|
44
49
|
import { Readable } from "node:stream";
|
|
45
50
|
|
|
@@ -136,14 +141,12 @@ export type SpawnArgs<T extends SpawnOptions> =
|
|
|
136
141
|
| [command: string, args: readonly string[], options: T]
|
|
137
142
|
| [command: string, ...argsAndOptions: [...string[], T]];
|
|
138
143
|
|
|
139
|
-
|
|
140
144
|
interface ParsedSpawnArgs<T extends SpawnOptions> {
|
|
141
145
|
command: string;
|
|
142
146
|
commandArgs: string[];
|
|
143
147
|
options?: T;
|
|
144
148
|
}
|
|
145
149
|
|
|
146
|
-
|
|
147
150
|
function parseSpawnArgs<T extends SpawnOptions>(input: SpawnArgs<T>): ParsedSpawnArgs<T> {
|
|
148
151
|
let [value, ...values] = input;
|
|
149
152
|
const [command, ...commandArgs] = shlex(value);
|
|
@@ -155,17 +158,13 @@ function parseSpawnArgs<T extends SpawnOptions>(input: SpawnArgs<T>): ParsedSpaw
|
|
|
155
158
|
}
|
|
156
159
|
|
|
157
160
|
const last = values.at(-1);
|
|
158
|
-
const options =
|
|
159
|
-
last !== null &&
|
|
160
|
-
typeof last === "object" &&
|
|
161
|
-
!Array.isArray(last)
|
|
162
|
-
) ? last : undefined;
|
|
161
|
+
const options =
|
|
162
|
+
last !== null && typeof last === "object" && !Array.isArray(last) ? last : undefined;
|
|
163
163
|
const argumentValues = options ? values.slice(0, -1) : values;
|
|
164
|
-
const valueArgs: string[] =
|
|
165
|
-
argumentValues.length === 1 &&
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
164
|
+
const valueArgs: string[] =
|
|
165
|
+
argumentValues.length === 1 && Array.isArray(argumentValues[0])
|
|
166
|
+
? [...argumentValues[0]]
|
|
167
|
+
: argumentValues;
|
|
169
168
|
|
|
170
169
|
return {
|
|
171
170
|
command,
|
|
@@ -481,11 +480,9 @@ function linesFromCapturedOutput(output: string): string[] {
|
|
|
481
480
|
* @returns Exit code, captured line arrays, and trimmed `stdout` / `stderr` getters
|
|
482
481
|
* @throws When spawn fails, line reads fail, or `check` is true and exit code is non-zero
|
|
483
482
|
*/
|
|
484
|
-
export async function spawn(
|
|
485
|
-
...args: SpawnArgs<ExecOptions>
|
|
486
|
-
): Promise<ExecResult> {
|
|
483
|
+
export async function spawn(...args: SpawnArgs<ExecOptions>): Promise<ExecResult> {
|
|
487
484
|
const { command, commandArgs, options = {} } = parseSpawnArgs(args);
|
|
488
|
-
const { stdin, stdout, stderr, check, trim, ...spawnOpts } = options
|
|
485
|
+
const { stdin, stdout, stderr, check, trim, ...spawnOpts } = options;
|
|
489
486
|
const stdoutLines: string[] = [];
|
|
490
487
|
const stderrLines: string[] = [];
|
|
491
488
|
const stdoutHandler = resolveStdio(stdout, stdoutLines);
|
|
@@ -529,9 +526,7 @@ export async function spawn(
|
|
|
529
526
|
* @returns Exit code, captured line arrays, and trimmed `stdout` / `stderr` getters
|
|
530
527
|
* @throws When spawn fails or `check` is true and exit code is non-zero
|
|
531
528
|
*/
|
|
532
|
-
export function spawnSync(
|
|
533
|
-
...args: SpawnArgs<SyncExecOptions>
|
|
534
|
-
): ExecResult {
|
|
529
|
+
export function spawnSync(...args: SpawnArgs<SyncExecOptions>): ExecResult {
|
|
535
530
|
const { command, commandArgs, options = {} } = parseSpawnArgs(args);
|
|
536
531
|
const { stdin, stdout, stderr, check, trim, ...spawnOpts } = options;
|
|
537
532
|
const stdinMode: ExecStdio = typeof stdin === "string" ? "pipe" : (stdin ?? "inherit");
|
|
@@ -642,4 +637,4 @@ export function shlex(command: string): string[] {
|
|
|
642
637
|
push();
|
|
643
638
|
|
|
644
639
|
return args.length ? args : [command];
|
|
645
|
-
}
|
|
640
|
+
}
|
package/src/project.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { Stats } from "node:fs";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
2
|
+
import { Stats, readFileSync } from "node:fs";
|
|
4
3
|
import { basename, dirname, join, resolve } from "node:path";
|
|
5
4
|
import { hash, net } from "@dbx-tools/shared-core";
|
|
6
5
|
import { statSync as stat } from "./file";
|
|
7
6
|
|
|
8
|
-
|
|
9
7
|
const ROOT_MARKERS = [
|
|
10
8
|
".projenrc.ts",
|
|
11
9
|
".projenrc.js",
|
|
@@ -17,7 +15,7 @@ const ROOT_MARKERS = [
|
|
|
17
15
|
/** A command's stdout, classified as a filesystem path and/or a URL. */
|
|
18
16
|
export interface ProjectContext {
|
|
19
17
|
readonly cwd: string;
|
|
20
|
-
readonly output: string
|
|
18
|
+
readonly output: string;
|
|
21
19
|
/** `output` when it names something on disk. */
|
|
22
20
|
readonly path?: string;
|
|
23
21
|
/** `fs.stat` of {@link path}, when it exists. */
|
|
@@ -30,7 +28,6 @@ export interface ProjectContext {
|
|
|
30
28
|
readonly url?: net.UrlBuilder;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
|
|
34
31
|
/**
|
|
35
32
|
* because this is crucial do not use exec.spawnSync
|
|
36
33
|
*
|
|
@@ -64,7 +61,7 @@ const parsedCommandCache = new Map<string, ProjectContext>();
|
|
|
64
61
|
|
|
65
62
|
function projectContextCommand(command: string, args: string[], cwd?: string): ProjectContext {
|
|
66
63
|
const processCwd = resolve(process.cwd());
|
|
67
|
-
let cacheEnabled: boolean
|
|
64
|
+
let cacheEnabled: boolean;
|
|
68
65
|
if (!cwd) {
|
|
69
66
|
cwd = processCwd;
|
|
70
67
|
cacheEnabled = true;
|
|
@@ -78,7 +75,9 @@ function projectContextCommand(command: string, args: string[], cwd?: string): P
|
|
|
78
75
|
}
|
|
79
76
|
const cacheKey = cacheEnabled ? hash.fnvHash(command, args) : undefined;
|
|
80
77
|
const cacheHit = cacheKey ? parsedCommandCache.get(cacheKey) : undefined;
|
|
81
|
-
if (cacheHit?.cwd === cwd) {
|
|
78
|
+
if (cacheHit?.cwd === cwd) {
|
|
79
|
+
return cacheHit;
|
|
80
|
+
}
|
|
82
81
|
const result = projectContextCommandOutput(command, args, cwd);
|
|
83
82
|
if (cacheKey) {
|
|
84
83
|
parsedCommandCache.set(cacheKey, result);
|
|
@@ -136,7 +135,6 @@ export function root(cwd: string = process.cwd()): string | undefined {
|
|
|
136
135
|
}
|
|
137
136
|
}
|
|
138
137
|
|
|
139
|
-
|
|
140
138
|
/**
|
|
141
139
|
* Parse a git remote URL (`https://...`, `git@host:owner/repo.git`, etc.) and
|
|
142
140
|
* return the repo segment, stripping any `.git` suffix. Returns `undefined` for
|
|
@@ -203,7 +201,11 @@ export function name(cwd: string = process.cwd()): string {
|
|
|
203
201
|
const fromPackage = readPackageName(resolve(rootDir, "package.json"));
|
|
204
202
|
if (fromPackage) return fromPackage;
|
|
205
203
|
|
|
206
|
-
const remote = projectContextCommand(
|
|
204
|
+
const remote = projectContextCommand(
|
|
205
|
+
"git",
|
|
206
|
+
["-C", rootDir, "remote", "get-url", "origin"],
|
|
207
|
+
rootDir,
|
|
208
|
+
).output;
|
|
207
209
|
const fromGit = remote ? parseGitRemote(remote) : undefined;
|
|
208
210
|
if (fromGit) return fromGit;
|
|
209
211
|
|