@orkestrel/scaffold 0.0.46 → 0.0.48

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.
@@ -908,7 +908,7 @@ export declare class Materializer implements MaterializerInterface {
908
908
  */
909
909
  catalog(entries: readonly CatalogEntry[], target: string): MaterializeResult;
910
910
  /**
911
- * Rewrite the `@orkestrel/*` range set in the target's manifest.
911
+ * Rewrite the declared dependency ranges the caller names in the target's manifest.
912
912
  *
913
913
  * @param dependencies - The names and ranges the manifest must declare.
914
914
  * @param target - The directory to write into.
@@ -1062,7 +1062,7 @@ export declare class Materializer implements MaterializerInterface {
1062
1062
  */
1063
1063
  catalog(entries: readonly CatalogEntry[], target: string): MaterializeResult;
1064
1064
  /**
1065
- * Rewrite the `@orkestrel/*` range set in the target's manifest.
1065
+ * Rewrite the declared dependency ranges the caller names in the target's manifest.
1066
1066
  *
1067
1067
  * @param dependencies - The names and ranges the manifest must declare.
1068
1068
  * @param target - The directory to write into.
@@ -1630,7 +1630,7 @@ export declare class Materializer implements MaterializerInterface {
1630
1630
  /** The upstream reader's observation channel. */
1631
1631
  get emitter(): EmitterInterface<UpstreamEventMap>;
1632
1632
  /**
1633
- * Look up the registry's latest release for each declared dependency.
1633
+ * Look up the newest release each declared range admits.
1634
1634
  *
1635
1635
  * @param dependencies - The declared dependencies to look up.
1636
1636
  * @returns One release verdict per dependency, in input order.
@@ -1639,10 +1639,11 @@ export declare class Materializer implements MaterializerInterface {
1639
1639
  * torn down before or during the call.
1640
1640
  *
1641
1641
  * @remarks
1642
- * Whether the declared range already admits the reported version is not
1643
- * decided here and is not stored on the verdict: it is a function of the
1644
- * `range` and `latest` sitting beside each other, and one centralized helper
1645
- * answers it for every caller.
1642
+ * The reader selects across the packument's stable version map before any
1643
+ * collection bound can truncate it. It falls back to `dist-tags.latest` only
1644
+ * when that version satisfies the declared range. `*` requests the newest
1645
+ * stable version outright. The verdict's `major` field carries the stable
1646
+ * major from the latest tag when that tag can be read.
1646
1647
  *
1647
1648
  * @example
1648
1649
  * ```ts
@@ -1760,7 +1761,7 @@ export declare class Materializer implements MaterializerInterface {
1760
1761
  export declare interface UpstreamInterface {
1761
1762
  readonly emitter: EmitterInterface<UpstreamEventMap>;
1762
1763
  /**
1763
- * Look up the registry's latest release for each declared dependency.
1764
+ * Look up the newest release each declared range admits.
1764
1765
  *
1765
1766
  * @param dependencies - The declared dependencies to look up.
1766
1767
  * @returns One release verdict per dependency, in input order.
@@ -908,7 +908,7 @@ export declare class Materializer implements MaterializerInterface {
908
908
  */
909
909
  catalog(entries: readonly CatalogEntry[], target: string): MaterializeResult;
910
910
  /**
911
- * Rewrite the `@orkestrel/*` range set in the target's manifest.
911
+ * Rewrite the declared dependency ranges the caller names in the target's manifest.
912
912
  *
913
913
  * @param dependencies - The names and ranges the manifest must declare.
914
914
  * @param target - The directory to write into.
@@ -1062,7 +1062,7 @@ export declare class Materializer implements MaterializerInterface {
1062
1062
  */
1063
1063
  catalog(entries: readonly CatalogEntry[], target: string): MaterializeResult;
1064
1064
  /**
1065
- * Rewrite the `@orkestrel/*` range set in the target's manifest.
1065
+ * Rewrite the declared dependency ranges the caller names in the target's manifest.
1066
1066
  *
1067
1067
  * @param dependencies - The names and ranges the manifest must declare.
1068
1068
  * @param target - The directory to write into.
@@ -1630,7 +1630,7 @@ export declare class Materializer implements MaterializerInterface {
1630
1630
  /** The upstream reader's observation channel. */
1631
1631
  get emitter(): EmitterInterface<UpstreamEventMap>;
1632
1632
  /**
1633
- * Look up the registry's latest release for each declared dependency.
1633
+ * Look up the newest release each declared range admits.
1634
1634
  *
1635
1635
  * @param dependencies - The declared dependencies to look up.
1636
1636
  * @returns One release verdict per dependency, in input order.
@@ -1639,10 +1639,11 @@ export declare class Materializer implements MaterializerInterface {
1639
1639
  * torn down before or during the call.
1640
1640
  *
1641
1641
  * @remarks
1642
- * Whether the declared range already admits the reported version is not
1643
- * decided here and is not stored on the verdict: it is a function of the
1644
- * `range` and `latest` sitting beside each other, and one centralized helper
1645
- * answers it for every caller.
1642
+ * The reader selects across the packument's stable version map before any
1643
+ * collection bound can truncate it. It falls back to `dist-tags.latest` only
1644
+ * when that version satisfies the declared range. `*` requests the newest
1645
+ * stable version outright. The verdict's `major` field carries the stable
1646
+ * major from the latest tag when that tag can be read.
1646
1647
  *
1647
1648
  * @example
1648
1649
  * ```ts
@@ -1760,7 +1761,7 @@ export declare class Materializer implements MaterializerInterface {
1760
1761
  export declare interface UpstreamInterface {
1761
1762
  readonly emitter: EmitterInterface<UpstreamEventMap>;
1762
1763
  /**
1763
- * Look up the registry's latest release for each declared dependency.
1764
+ * Look up the newest release each declared range admits.
1764
1765
  *
1765
1766
  * @param dependencies - The declared dependencies to look up.
1766
1767
  * @returns One release verdict per dependency, in input order.
@@ -1,5 +1,5 @@
1
1
  import { andOf, arrayOf, attempt, boundsOf, holds, isArray, isBoolean, isError, isFunction, isInteger, isRecord, isString, parseJSON, parseJSONAs, parseStringField, recordOf, stringOf } from "@orkestrel/contract";
2
- import { CATALOG_AGENT_PATH, CONTROL_CHARACTER_PATTERN, EXECUTABLE_PATHS, HOST_PATHS, MAX_ARTIFACT_BYTES, MAX_COLLECTION_ITEMS, MAX_DEPENDENCY_NAME_LENGTH, MAX_MANIFEST_BYTES, MAX_PATH_LENGTH, MAX_RANGE_LENGTH, MAX_TOTAL_ARTIFACT_BYTES, ScaffoldError, WORKSPACE_OWNED_PATHS, bytesToHex, catalogToLayers, cloneValue, computeBytes, contentToHex, inferGroup, isAudit, isCatalogEntry, isCollection, isDependency, isDependencyName, isMirror, isPath, isPlan, isSnapshot, matchesDriftReachability, nameToGuide, planToFindings } from "../core/index.js";
2
+ import { CATALOG_AGENT_PATH, CONTROL_CHARACTER_PATTERN, EXECUTABLE_PATHS, HOST_PATHS, MAX_ARTIFACT_BYTES, MAX_COLLECTION_ITEMS, MAX_DEPENDENCY_NAME_LENGTH, MAX_MANIFEST_BYTES, MAX_PATH_LENGTH, MAX_RANGE_LENGTH, MAX_REGISTRY_BYTES, MAX_TOTAL_ARTIFACT_BYTES, MAX_TOTAL_REGISTRY_BYTES, ScaffoldError, WORKSPACE_OWNED_PATHS, bytesToHex, catalogToLayers, cloneValue, compareVersions, computeBytes, contentToHex, extractRangeMajor, extractVersion, inferGroup, isAudit, isCatalogEntry, isCollection, isDependency, isDependencyName, isMirror, isPath, isPlan, isSnapshot, matchesDriftReachability, matchesRange, nameToGuide, planToFindings, replaceManifestRanges } from "../core/index.js";
3
3
  import { createHash, randomUUID } from "node:crypto";
4
4
  import { chmodSync, closeSync, constants, copyFileSync, fstatSync, linkSync, lstatSync, mkdirSync, openSync, opendirSync, readSync, readdirSync, readlinkSync, realpathSync, renameSync, rmSync, rmdirSync, writeFileSync } from "node:fs";
5
5
  import { basename, dirname, join, parse, relative, resolve, sep } from "node:path";
@@ -2425,7 +2425,7 @@ var Materializer = class Materializer {
2425
2425
  return this.#rewrite(directory, CATALOG_AGENT_PATH, MAX_ARTIFACT_BYTES, this.#recatalog(accepted));
2426
2426
  }
2427
2427
  /**
2428
- * Rewrite the `@orkestrel/*` range set in the target's manifest.
2428
+ * Rewrite the declared dependency ranges the caller names in the target's manifest.
2429
2429
  *
2430
2430
  * @param dependencies - The names and ranges the manifest must declare.
2431
2431
  * @param target - The directory to write into.
@@ -2924,45 +2924,12 @@ var Materializer = class Materializer {
2924
2924
  }
2925
2925
  #redeclare(dependencies) {
2926
2926
  return (text) => {
2927
- let manifest = text;
2928
- for (const dependency of dependencies) {
2929
- const key = JSON.stringify(dependency.name);
2930
- const range = JSON.stringify(dependency.range);
2931
- let index = manifest.indexOf(key);
2932
- let declared = false;
2933
- while (index >= 0) {
2934
- const span = this.#span(manifest, index + key.length);
2935
- if (span === void 0) {
2936
- index = manifest.indexOf(key, index + key.length);
2937
- continue;
2938
- }
2939
- manifest = manifest.slice(0, span[0]) + range + manifest.slice(span[1]);
2940
- declared = true;
2941
- index = manifest.indexOf(key, span[0] + range.length);
2942
- }
2943
- if (!declared) throw this.#error("INVALID", `The manifest does not declare ${dependency.name}, so its range cannot be rewritten.`, { name: dependency.name });
2944
- }
2945
- return manifest;
2927
+ const manifest = replaceManifestRanges(text, dependencies);
2928
+ if (manifest !== void 0) return manifest;
2929
+ const missing = dependencies.find((dependency) => !text.includes(JSON.stringify(dependency.name)));
2930
+ throw this.#error("INVALID", `The manifest does not declare ${missing?.name ?? "a requested package"}, so its range cannot be rewritten.`, missing === void 0 ? void 0 : { name: missing.name });
2946
2931
  };
2947
2932
  }
2948
- #span(text, from) {
2949
- let index = from;
2950
- while (index < text.length && /\s/u.test(text.charAt(index))) index += 1;
2951
- if (text.charAt(index) !== ":") return void 0;
2952
- index += 1;
2953
- while (index < text.length && /\s/u.test(text.charAt(index))) index += 1;
2954
- if (text.charAt(index) !== "\"") return void 0;
2955
- const start = index;
2956
- index += 1;
2957
- while (index < text.length) {
2958
- if (text.charAt(index) === "\\") {
2959
- index += 2;
2960
- continue;
2961
- }
2962
- if (text.charAt(index) === "\"") return [start, index + 1];
2963
- index += 1;
2964
- }
2965
- }
2966
2933
  #finish(result) {
2967
2934
  this.#emitter.emit("finish", result);
2968
2935
  return result;
@@ -3027,7 +2994,6 @@ var Upstream = class Upstream {
3027
2994
  static #defaultTimeout = 1e4;
3028
2995
  static #defaultConcurrency = 6;
3029
2996
  static #defaultRetries = 0;
3030
- static #defaultBudget = 16777216;
3031
2997
  static #scope = "orkestrel";
3032
2998
  static #unreadable = "the answer carries no readable latest version";
3033
2999
  static #packument = "application/vnd.npm.install-v1+json";
@@ -3075,15 +3041,15 @@ var Upstream = class Upstream {
3075
3041
  this.#registryTimeout = options?.registry?.timeout ?? Upstream.#defaultTimeout;
3076
3042
  this.#concurrency = options?.concurrency ?? Upstream.#defaultConcurrency;
3077
3043
  this.#retries = options?.retries ?? Upstream.#defaultRetries;
3078
- this.#limit = options?.limit ?? MAX_ARTIFACT_BYTES;
3079
- this.#budget = options?.budget ?? Upstream.#defaultBudget;
3044
+ this.#limit = options?.limit ?? MAX_REGISTRY_BYTES;
3045
+ this.#budget = options?.budget ?? MAX_TOTAL_REGISTRY_BYTES;
3080
3046
  }
3081
3047
  /** The upstream reader's observation channel. */
3082
3048
  get emitter() {
3083
3049
  return this.#emitter;
3084
3050
  }
3085
3051
  /**
3086
- * Look up the registry's latest release for each declared dependency.
3052
+ * Look up the newest release each declared range admits.
3087
3053
  *
3088
3054
  * @param dependencies - The declared dependencies to look up.
3089
3055
  * @returns One release verdict per dependency, in input order.
@@ -3092,10 +3058,11 @@ var Upstream = class Upstream {
3092
3058
  * torn down before or during the call.
3093
3059
  *
3094
3060
  * @remarks
3095
- * Whether the declared range already admits the reported version is not
3096
- * decided here and is not stored on the verdict: it is a function of the
3097
- * `range` and `latest` sitting beside each other, and one centralized helper
3098
- * answers it for every caller.
3061
+ * The reader selects across the packument's stable version map before any
3062
+ * collection bound can truncate it. It falls back to `dist-tags.latest` only
3063
+ * when that version satisfies the declared range. `*` requests the newest
3064
+ * stable version outright. The verdict's `major` field carries the stable
3065
+ * major from the latest tag when that tag can be read.
3099
3066
  *
3100
3067
  * @example
3101
3068
  * ```ts
@@ -3224,17 +3191,21 @@ var Upstream = class Upstream {
3224
3191
  }
3225
3192
  async #release(dependency, allowance) {
3226
3193
  const outcome = await this.#read(this.#registryURL(dependency.name), this.#registryTimeout, allowance, Upstream.#packument);
3227
- const latest = outcome.lookup === "found" ? this.#latest(outcome.content) : void 0;
3194
+ const latest = outcome.lookup === "found" ? this.#releaseVersion(outcome.content, dependency.range) : void 0;
3195
+ const tagged = outcome.lookup === "found" ? this.#latest(outcome.content) : void 0;
3196
+ const major = tagged === void 0 ? void 0 : extractVersion(tagged)?.[0];
3228
3197
  const release = latest === void 0 ? {
3229
3198
  name: dependency.name,
3230
3199
  range: dependency.range,
3231
3200
  lookup: outcome.lookup === "missing" ? "missing" : "failed",
3232
- note: outcome.lookup === "found" ? Upstream.#unreadable : outcome.note
3201
+ note: outcome.lookup === "found" ? Upstream.#unreadable : outcome.note,
3202
+ ...major === void 0 ? {} : { major }
3233
3203
  } : {
3234
3204
  name: dependency.name,
3235
3205
  range: dependency.range,
3236
3206
  lookup: "found",
3237
- latest
3207
+ latest,
3208
+ ...major === void 0 ? {} : { major }
3238
3209
  };
3239
3210
  this.#emitter.emit("release", release);
3240
3211
  return release;
@@ -3319,6 +3290,27 @@ var Upstream = class Upstream {
3319
3290
  if (latest === void 0 || latest.length === 0 || latest.length > MAX_RANGE_LENGTH) return;
3320
3291
  return CONTROL_CHARACTER_PATTERN.test(latest) ? void 0 : latest;
3321
3292
  }
3293
+ #releaseVersion(content, range) {
3294
+ const parsed = parseJSON(content);
3295
+ if (!isRecord(parsed)) return void 0;
3296
+ const versions = parsed.versions;
3297
+ let selected;
3298
+ if (isRecord(versions)) for (const version of Object.keys(versions)) {
3299
+ if (!this.#admits(range, version)) continue;
3300
+ if (selected === void 0 || compareVersions(version, selected) > 0) selected = version;
3301
+ }
3302
+ if (selected !== void 0) return selected;
3303
+ const latest = this.#latest(content);
3304
+ return latest !== void 0 && this.#admits(range, latest) ? latest : void 0;
3305
+ }
3306
+ #admits(range, version) {
3307
+ const extracted = extractVersion(version);
3308
+ if (extracted === void 0) return false;
3309
+ if (range === "*") return true;
3310
+ const major = extractRangeMajor(range);
3311
+ if (major !== void 0 && range === `^${String(major)}`) return extracted[0] === major;
3312
+ return matchesRange(range, version);
3313
+ }
3322
3314
  #registryURL(name) {
3323
3315
  return `${this.#registryBase}/${encodeURIComponent(name).replaceAll("%40", "@")}`;
3324
3316
  }