@orkestrel/guide 0.0.19 → 0.0.21

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.
@@ -1,4 +1,4 @@
1
- import { arrayOf, isArray, isEmptyString, isFunction, isNonEmptyArray, isNonEmptyString, isObject, isRecord, isString, literalOf, parseJSON, recordOf, unionOf } from "@orkestrel/contract";
1
+ import { arrayOf, isArray, isEmptyString, isError, isFiniteNumber, isFunction, isInstance, isNonEmptyArray, isNonEmptyString, isObject, isRecord, isString, literalOf, parseEnum, parseJSONAs, recordOf, unionOf } from "@orkestrel/contract";
2
2
  import { resolve } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { globSync, writeFileSync } from "node:fs";
@@ -68,7 +68,7 @@ function matchesGuideResult(result) {
68
68
  * ```
69
69
  */
70
70
  function resolveGuideRoot(root) {
71
- return resolve(root instanceof URL ? fileURLToPath(root) : root);
71
+ return resolve(isInstance(root, URL) ? fileURLToPath(root) : root);
72
72
  }
73
73
  /**
74
74
  * Selects the indexed guide matching a package's bare name.
@@ -102,8 +102,7 @@ function selectGuidePitch(entries, name) {
102
102
  */
103
103
  function parseGuideDirection(args) {
104
104
  if (args.length !== 2 || args[0] !== "--to") return void 0;
105
- const direction = args[1];
106
- return direction === "guide" || direction === "source" ? direction : void 0;
105
+ return parseEnum(args[1], ["guide", "source"]);
107
106
  }
108
107
  /**
109
108
  * Reads the bare package name from package manifest JSON.
@@ -117,10 +116,10 @@ function parseGuideDirection(args) {
117
116
  * ```
118
117
  */
119
118
  function parsePackageName(manifest) {
120
- const parsed = parseJSON(manifest);
121
- if (!isRecord(parsed)) return void 0;
119
+ const parsed = parseJSONAs(manifest, isRecord);
120
+ if (parsed === void 0) return void 0;
122
121
  const name = parsed.name;
123
- if (typeof name !== "string" || name.length === 0) return void 0;
122
+ if (!isNonEmptyString(name)) return void 0;
124
123
  return name.slice(name.lastIndexOf("/") + 1);
125
124
  }
126
125
  //#endregion
@@ -773,7 +772,7 @@ function hasCanonicalSegments(key) {
773
772
  function normalizeDirectories(module) {
774
773
  const directories = [];
775
774
  const seen = /* @__PURE__ */ new Set();
776
- for (const value of typeof module === "string" ? [module] : module) {
775
+ for (const value of isString(module) ? [module] : module) {
777
776
  const directory = resolvePath(".", value);
778
777
  if (seen.has(directory)) continue;
779
778
  seen.add(directory);
@@ -3712,7 +3711,7 @@ var GuideCommand = class {
3712
3711
  try {
3713
3712
  await this.#executeNative();
3714
3713
  } catch (error) {
3715
- process.stderr.write(`${error instanceof Error ? error.message : String(error)}\n`);
3714
+ process.stderr.write(`${isError(error) ? error.message : String(error)}\n`);
3716
3715
  this.#raise(1);
3717
3716
  }
3718
3717
  }
@@ -3824,8 +3823,8 @@ var GuideCommand = class {
3824
3823
  }
3825
3824
  #raise(code) {
3826
3825
  const current = process.exitCode;
3827
- const numeric = typeof current === "string" ? Number.parseInt(current, 10) : current;
3828
- if (typeof numeric !== "number" || !Number.isFinite(numeric) || numeric < code) process.exitCode = code;
3826
+ const numeric = isString(current) ? Number.parseInt(current, 10) : current;
3827
+ if (!isFiniteNumber(numeric) || numeric < code) process.exitCode = code;
3829
3828
  }
3830
3829
  };
3831
3830
  //#endregion