@dbx-tools/core 0.9.154 → 0.9.157
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/index.ts +12 -6
- package/lib/index.d.ts +12 -6
- package/lib/index.js +13 -6
- package/lib/src/bin.js +3 -4
- package/lib/src/brand-files.d.ts +1 -101
- package/lib/src/brand-files.js +4 -14
- package/lib/src/bundle.js +10 -10
- package/lib/src/config-utils.d.ts +0 -5
- package/lib/src/config-utils.js +34 -49
- package/lib/src/dependency-resolver.js +12 -12
- package/lib/src/exec.js +4 -4
- package/lib/src/file-lock.js +12 -18
- package/lib/src/process-lock.js +8 -9
- package/lib/src/project-utils.d.ts +3 -3
- package/lib/src/project-utils.js +14 -14
- package/package.json +3 -91
- package/src/bin.ts +2 -3
- package/src/brand-files.ts +3 -18
- package/src/bundle.ts +9 -12
- package/src/config-utils.ts +50 -62
- package/src/dependency-resolver.ts +11 -11
- package/src/exec.ts +3 -3
- package/src/file-lock.ts +20 -17
- package/src/process-lock.ts +7 -8
- package/src/project-utils.ts +25 -19
package/src/project-utils.ts
CHANGED
|
@@ -12,7 +12,13 @@ import { spawnSync } from "node:child_process";
|
|
|
12
12
|
import { Stats, readFileSync } from "node:fs";
|
|
13
13
|
import { homedir } from "node:os";
|
|
14
14
|
import { basename, dirname, join, resolve } from "node:path";
|
|
15
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
parseRecord,
|
|
17
|
+
type UrlBuilder,
|
|
18
|
+
urlBuilder,
|
|
19
|
+
isRecord,
|
|
20
|
+
trimToNull,
|
|
21
|
+
} from "@dbx-tools/shared-core";
|
|
16
22
|
import { parse as parseYaml } from "yaml";
|
|
17
23
|
import { cachedRecord, statSync as fileStatSync } from "./file.ts";
|
|
18
24
|
|
|
@@ -26,7 +32,7 @@ const ROOT_MARKERS = [
|
|
|
26
32
|
|
|
27
33
|
/** Resolve a blank, null, omitted, relative, or absolute cwd to an absolute path. */
|
|
28
34
|
export function resolveWorkingDirectory(cwd?: string | null): string {
|
|
29
|
-
return resolve(
|
|
35
|
+
return resolve(trimToNull(cwd) ?? process.cwd());
|
|
30
36
|
}
|
|
31
37
|
|
|
32
38
|
/** A command's stdout, classified as a filesystem path and/or a URL. */
|
|
@@ -43,7 +49,7 @@ export interface ProjectContext {
|
|
|
43
49
|
* network URL - a non-blank scheme (not `file:`) AND a non-blank hostname.
|
|
44
50
|
* Bare paths, scp-like `git@host:...` remotes, and `file:` URLs stay unset.
|
|
45
51
|
*/
|
|
46
|
-
readonly url?:
|
|
52
|
+
readonly url?: UrlBuilder;
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
/**
|
|
@@ -77,7 +83,7 @@ function projectContextCommandOutput(
|
|
|
77
83
|
// synthesizes one (a bare `example.com` -> `https://…`, an absolute path ->
|
|
78
84
|
// `http://localhost/…`), which would mislabel directory outputs and bare
|
|
79
85
|
// tokens - so gate on the raw output already carrying a scheme + authority.
|
|
80
|
-
const url = /^[a-z][a-z0-9+.-]*:\/\//i.test(output) ?
|
|
86
|
+
const url = /^[a-z][a-z0-9+.-]*:\/\//i.test(output) ? urlBuilder(output) : undefined;
|
|
81
87
|
return { output, path: pathStats ? output : undefined, pathStats, success: true, url };
|
|
82
88
|
}
|
|
83
89
|
return { output, success: result.status === 0 };
|
|
@@ -109,7 +115,7 @@ function projectCommand(command: string) {
|
|
|
109
115
|
return {
|
|
110
116
|
context,
|
|
111
117
|
output(args: string[], cwd?: string, options?: ProjectCommandOptions): string | undefined {
|
|
112
|
-
return
|
|
118
|
+
return trimToNull(context(args, cwd, options).output) ?? undefined;
|
|
113
119
|
},
|
|
114
120
|
root(args: string[], cwd: string): string | undefined {
|
|
115
121
|
const parsed = context(args, cwd);
|
|
@@ -151,7 +157,7 @@ function npmRoot(cwd?: string): string | undefined {
|
|
|
151
157
|
}
|
|
152
158
|
|
|
153
159
|
function envDirectory(value: string | undefined): string | undefined {
|
|
154
|
-
const path =
|
|
160
|
+
const path = trimToNull(value);
|
|
155
161
|
if (!path) return undefined;
|
|
156
162
|
const resolved = resolve(path);
|
|
157
163
|
return fileStatSync(resolved)?.isDirectory() ? resolved : undefined;
|
|
@@ -300,7 +306,7 @@ function repositoryUrlFromGh(cwd?: string): string | undefined {
|
|
|
300
306
|
account.root,
|
|
301
307
|
{ cache: true, env: account.env },
|
|
302
308
|
);
|
|
303
|
-
return
|
|
309
|
+
return trimToNull(parseRecord(out)?.url) ?? undefined;
|
|
304
310
|
}
|
|
305
311
|
|
|
306
312
|
/** Resolve an ssh host alias (`~/.ssh/config`) to its effective `hostname` via `ssh -G`. */
|
|
@@ -373,7 +379,7 @@ export function resolveProjectGhAccount(
|
|
|
373
379
|
options: ResolveProjectGhAccountOptions = {},
|
|
374
380
|
): ProjectGhAccount | undefined {
|
|
375
381
|
const root = resolveWorkingDirectory(cwd);
|
|
376
|
-
const remoteName =
|
|
382
|
+
const remoteName = trimToNull(options.remote) ?? "origin";
|
|
377
383
|
const key = JSON.stringify([root, remoteName, homedir(), process.env.GH_CONFIG_DIR ?? ""]);
|
|
378
384
|
if (!options.refresh && projectGhAccountCache.has(key)) {
|
|
379
385
|
return projectGhAccountCache.get(key) ?? undefined;
|
|
@@ -468,7 +474,7 @@ function repositoryUrlFromGit(cwd?: string): string | undefined {
|
|
|
468
474
|
if (scp) https = `https://${scp[1]}/${scp[2]}`;
|
|
469
475
|
https = https.replace(/^(ssh|git):\/\//, "https://");
|
|
470
476
|
|
|
471
|
-
let builder =
|
|
477
|
+
let builder = urlBuilder(https);
|
|
472
478
|
if (!builder) return undefined;
|
|
473
479
|
// Drop any embedded `user[:pass]@` credentials.
|
|
474
480
|
if (builder.username || builder.password) {
|
|
@@ -516,7 +522,7 @@ export type NpmRegistryOptions = {
|
|
|
516
522
|
envVars?: boolean;
|
|
517
523
|
};
|
|
518
524
|
|
|
519
|
-
const npmRegistryCache = new Map<string,
|
|
525
|
+
const npmRegistryCache = new Map<string, UrlBuilder | undefined>();
|
|
520
526
|
|
|
521
527
|
/**
|
|
522
528
|
* The active npm registry as a chainable {@link net.UrlBuilder}.
|
|
@@ -529,7 +535,7 @@ const npmRegistryCache = new Map<string, net.UrlBuilder | undefined>();
|
|
|
529
535
|
export function npmRegistry(
|
|
530
536
|
cwd?: string | null,
|
|
531
537
|
options?: NpmRegistryOptions,
|
|
532
|
-
):
|
|
538
|
+
): UrlBuilder | undefined {
|
|
533
539
|
const resolved = resolveWorkingDirectory(cwd);
|
|
534
540
|
const envVars = options?.envVars !== false;
|
|
535
541
|
const overrideOnly = Boolean(options?.overrideOnly);
|
|
@@ -554,7 +560,7 @@ export function npmRegistry(
|
|
|
554
560
|
function resolveNpmRegistry(
|
|
555
561
|
cwd: string,
|
|
556
562
|
options: { overrideOnly: boolean; envVars: boolean },
|
|
557
|
-
):
|
|
563
|
+
): UrlBuilder | undefined {
|
|
558
564
|
for (const candidate of npmRegistryCandidates(cwd, options.envVars)) {
|
|
559
565
|
const url = toRegistryUrl(candidate, options.overrideOnly);
|
|
560
566
|
if (url) return url;
|
|
@@ -588,16 +594,16 @@ function* npmRegistryCandidates(cwd: string, envVars: boolean): Generator<string
|
|
|
588
594
|
function toRegistryUrl(
|
|
589
595
|
candidate: string | undefined,
|
|
590
596
|
overrideOnly: boolean,
|
|
591
|
-
):
|
|
592
|
-
const trimmed =
|
|
597
|
+
): UrlBuilder | undefined {
|
|
598
|
+
const trimmed = trimToNull(candidate);
|
|
593
599
|
if (!trimmed) return undefined;
|
|
594
|
-
const url =
|
|
600
|
+
const url = urlBuilder(trimmed);
|
|
595
601
|
if (!url) return undefined;
|
|
596
602
|
if (overrideOnly && isPublicNpmRegistry(url)) return undefined;
|
|
597
603
|
return url;
|
|
598
604
|
}
|
|
599
605
|
|
|
600
|
-
function isPublicNpmRegistry(url:
|
|
606
|
+
function isPublicNpmRegistry(url: UrlBuilder): boolean {
|
|
601
607
|
return url.hostname === "registry.npmjs.org";
|
|
602
608
|
}
|
|
603
609
|
|
|
@@ -650,7 +656,7 @@ function readYamlRegistry(path: string): string | undefined {
|
|
|
650
656
|
const text = readTextFile(path);
|
|
651
657
|
if (!text) return undefined;
|
|
652
658
|
const parsed = parseYaml(text);
|
|
653
|
-
if (!
|
|
659
|
+
if (!isRecord(parsed)) return undefined;
|
|
654
660
|
const registry = yamlRegistry(parsed);
|
|
655
661
|
return registry ? { registry } : undefined;
|
|
656
662
|
})?.registry;
|
|
@@ -702,7 +708,7 @@ function parseBunfigRegistry(text: string): string | undefined {
|
|
|
702
708
|
function yamlRegistry(data: Record<string, unknown>): string | undefined {
|
|
703
709
|
if (typeof data.registry === "string") return data.registry;
|
|
704
710
|
const registries = data.registries;
|
|
705
|
-
if (
|
|
711
|
+
if (isRecord(registries) && typeof registries.default === "string") {
|
|
706
712
|
return registries.default;
|
|
707
713
|
}
|
|
708
714
|
return undefined;
|
|
@@ -725,5 +731,5 @@ function stripTomlComment(line: string): string {
|
|
|
725
731
|
|
|
726
732
|
function readPackageName(pkgPath: string): string | undefined {
|
|
727
733
|
if (!fileStatSync(pkgPath)?.isFile()) return undefined;
|
|
728
|
-
return
|
|
734
|
+
return trimToNull(parseRecord(readFileSync(pkgPath, "utf8"))?.name) ?? undefined;
|
|
729
735
|
}
|