@dbx-tools/core 0.9.153 → 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.
@@ -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 { json, net, object, stringUtils } from "@dbx-tools/shared-core";
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(stringUtils.trimToNull(cwd) ?? process.cwd());
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?: net.UrlBuilder;
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) ? net.urlBuilder(output) : undefined;
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 stringUtils.trimToNull(context(args, cwd, options).output) ?? undefined;
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 = stringUtils.trimToNull(value);
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 stringUtils.trimToNull(json.parseRecord(out)?.url) ?? undefined;
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 = stringUtils.trimToNull(options.remote) ?? "origin";
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 = net.urlBuilder(https);
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, net.UrlBuilder | undefined>();
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
- ): net.UrlBuilder | undefined {
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
- ): net.UrlBuilder | undefined {
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
- ): net.UrlBuilder | undefined {
592
- const trimmed = stringUtils.trimToNull(candidate);
597
+ ): UrlBuilder | undefined {
598
+ const trimmed = trimToNull(candidate);
593
599
  if (!trimmed) return undefined;
594
- const url = net.urlBuilder(trimmed);
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: net.UrlBuilder): boolean {
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 (!object.isRecord(parsed)) return undefined;
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 (object.isRecord(registries) && typeof registries.default === "string") {
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 stringUtils.trimToNull(json.parseRecord(readFileSync(pkgPath, "utf8"))?.name) ?? undefined;
734
+ return trimToNull(parseRecord(readFileSync(pkgPath, "utf8"))?.name) ?? undefined;
729
735
  }