@packall/core 0.4.0 → 0.5.0
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/README.md +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -6
- package/dist/index.js.map +1 -1
- package/dist/node/index.d.ts +1 -0
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +9 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/platform.d.ts +13 -0
- package/dist/node/platform.d.ts.map +1 -0
- package/dist/platform.d.ts +0 -2
- package/dist/platform.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/src/node/index.ts +1 -0
- package/src/node/platform.ts +17 -0
- package/src/platform.ts +0 -6
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Layouts: ReadonlyArray<Layout>","out: Record<string, string>","out: Record<string, { optional: boolean }>","specs: Array<PackageSpec>","errors: Array<InvalidSpecError>","out: Array<PackageSpec>","UNSUPPORTED_PROTOCOLS: ReadonlyArray<readonly [string, string]>","allPlatforms: PlatformFilter","osByAlias: Readonly<Record<string, string | undefined>>","KNOWN_OS: ReadonlySet<string>","LIBC: ReadonlySet<string>","defaultScope: DependencyScope","defaultResolveOptions: ResolveOptions","defaultBundleOptions: Omit<BundleOptions, \"outDir\">","hashes: Array<IntegrityHash>","packages: ReadonlyArray<ManifestEntry>","edgesOf","tasks: Array<Task>","warnings: Array<ResolutionWarning>","frontier: ReadonlyArray<Task>","wave: Array<Task>","next: Array<Task>","Progress.emit","hasReason","roots: Array<RootResolution>","compareResolved","Progress.emit","warnings: Array<ResolutionWarning>","addWarning","rootResolutions: Array<RootResolution>","spec: PackageSpec","missing: Array<{ name: string; version: string; detail: string }>","queue: Array<{ key: PackageKey; reason: Reason }>","describeError","ROOT_KINDS","collectEntries","edgesOf","edges: Array<LockedEdge>","collectRoots","workspacePaths","ROOT_KINDS","edgesOf","edges: Array<LockedEdge>","collectRoots","root: unknown","parseYaml","describeError","edges: Array<LockedEdge>","defaultInputFileOptions: InputFileOptions","specs: Array<PackageSpec>","warnings: Array<string>","required: Array<string>","parsed: unknown","Progress.emit","unverified: Array<string>","Integrity.verify","preflight: Effect.Effect<void, BundlerError, Registry | Progress.Progress>","Progress.emit","emit","tarballs: ReadonlyArray<BundleArtifact>","artifacts: Array<BundleArtifact>","clashes: Array<string>"],"sources":["../src/enums/artifact-kind.ts","../src/enums/edge-kind.ts","../src/enums/input-file-kind.ts","../src/enums/layout.ts","../src/enums/lockfile-format.ts","../src/enums/phase.ts","../src/utils/is-record.ts","../src/schemas/lenient.ts","../src/spec.ts","../src/dependency-range.ts","../src/platform.ts","../src/options.ts","../src/registry.ts","../src/integrity.ts","../src/layout.ts","../src/manifest.ts","../src/resolve.ts","../src/locked-resolve.ts","../src/lockfile/json.ts","../src/lockfile/detect.ts","../src/lockfile/names.ts","../src/lockfile/tree-builder.ts","../src/lockfile/bun.ts","../src/lockfile/npm.ts","../src/lockfile/pnpm.ts","../src/lockfile/parse.ts","../src/schemas/package-json.ts","../src/input-file.ts","../src/download.ts","../src/bundle.ts"],"sourcesContent":["import type { ValueOf } from \"../types/value-of.js\";\n\n/** What a bundle run wrote to the output directory. */\nexport const ArtifactKind = {\n\tArchive: \"archive\",\n\tDirectory: \"directory\",\n\t/**\n\t * A loose file that is not an archive — the manifest and the import guide,\n\t * which `dir` and `flat` write beside the tarballs rather than sealing\n\t * inside one.\n\t */\n\tFile: \"file\",\n} as const;\n\nexport type ArtifactKind = ValueOf<typeof ArtifactKind>;\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/**\n * Why one package depends on another.\n *\n * `EdgeKind` and `LockedRootKind` are one concept in two parts, which is why\n * they share a file: `Dev` exists only at the top level, because lockfiles\n * record dev dependencies for the project alone — a transitive devDependency is\n * never installed, so it is never locked.\n */\nexport const EdgeKind = {\n\tProd: \"prod\",\n\tOptional: \"optional\",\n\tPeer: \"peer\",\n} as const;\n\nexport type EdgeKind = ValueOf<typeof EdgeKind>;\n\n/** The kind that only a direct dependency of the locked project can have. */\nexport const DirectOnlyKind = {\n\tDev: \"dev\",\n} as const;\n\nexport type DirectOnlyKind = ValueOf<typeof DirectOnlyKind>;\n\n/** Why a direct dependency of the locked project is a root. */\nexport const LockedRootKind = {\n\t...EdgeKind,\n\t...DirectOnlyKind,\n} as const;\n\nexport type LockedRootKind = ValueOf<typeof LockedRootKind>;\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/** Which of the three shapes a `--file` input turned out to be. */\nexport const InputFileKind = {\n\t/** Bundle everything a package.json depends on. */\n\tPackageJson: \"package.json\",\n\t/** Bundle the exact versions a lockfile pins. */\n\tLockfile: \"lockfile\",\n\t/** A newline-delimited list of specs. */\n\tList: \"list\",\n} as const;\n\nexport type InputFileKind = ValueOf<typeof InputFileKind>;\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/** How the resulting tarball(s) are shaped. */\nexport const Layout = {\n\t/**\n\t * One tarball per requested spec, each carrying its own complete dependency\n\t * closure. Shared dependencies repeat across tarballs, so the total is\n\t * larger — but each one imports, rolls back and hands off independently.\n\t */\n\tPerSpec: \"per-spec\",\n\t/**\n\t * One tarball for everything, with the union of all closures deduplicated.\n\t * Smallest output and a single import step; all-or-nothing to roll back.\n\t */\n\tSingle: \"single\",\n\t/**\n\t * No archive at all — just the npm-layout directory tree, ready for\n\t * `jf rt upload` or rsync.\n\t */\n\tDir: \"dir\",\n\t/**\n\t * Every tarball side by side in one directory — no archive, and no\n\t * `name/-/` nesting. For tooling that globs `*.tgz` out of one directory\n\t * rather than walking a registry tree.\n\t */\n\tFlat: \"flat\",\n} as const;\n\nexport type Layout = ValueOf<typeof Layout>;\n\nexport const Layouts: ReadonlyArray<Layout> = Object.values(Layout);\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/** Which package manager wrote a lockfile. */\nexport const LockfileFormat = {\n\tNpm: \"npm\",\n\tPnpm: \"pnpm\",\n\tBun: \"bun\",\n} as const;\n\nexport type LockfileFormat = ValueOf<typeof LockfileFormat>;\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/** The phases a bundle run moves through, in order. */\nexport const Phase = {\n\tPreflight: \"preflight\",\n\tResolve: \"resolve\",\n\tDownload: \"download\",\n\tArchive: \"archive\",\n\tDone: \"done\",\n} as const;\n\nexport type Phase = ValueOf<typeof Phase>;\n","/**\n * Narrows an unknown value to a plain object.\n *\n * The entry point for reading anything the tool does not control — lockfiles,\n * package.json files, registry responses — without reaching for a cast.\n */\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n","/**\n * Schemas for JSON nobody controls.\n *\n * Registry responses, lockfiles and hand-edited package.json files all arrive\n * as untyped JSON, and the rule at every one of those boundaries is the same:\n * drop what cannot be understood, keep the rest. A bundler that rejects a\n * packument because one published version carries a field it has never seen is\n * useless against exactly the private registries it exists to serve.\n *\n * Effect Schema does the narrowing, which is what keeps those boundaries free\n * of casts and hand-rolled `typeof` ladders. What this module adds on top of\n * the stock combinators is that tolerance: `Schema.Record(String, String)`\n * fails the whole record over one numeric value, where the wire format wants\n * that entry skipped and its neighbours kept.\n */\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport * as Getter from \"effect/SchemaGetter\";\n\nimport { isRecord } from \"../utils/is-record.js\";\n\n/**\n * An optional field that goes *absent* rather than failing when it is\n * malformed.\n *\n * This is the difference between \"we do not understand this field\" and \"we do\n * not understand this document\". An `os: \"linux\"` where an array was expected\n * costs the platform filter one signal; it should not cost the run the package.\n */\nexport const tolerant = <S extends Schema.Top>(schema: S) =>\n\tSchema.optional(\n\t\tSchema.UndefinedOr(schema).pipe(\n\t\t\tSchema.catchDecoding(() => Effect.succeed(Option.some(undefined))),\n\t\t),\n\t);\n\n/**\n * Keeps only the string-valued members of an untyped object.\n *\n * `{ \"lodash\": \"^4.0.0\", \"broken\": 3 }` decodes to `{ \"lodash\": \"^4.0.0\" }`.\n * Per-entry rather than whole-record tolerance, because one unreadable edge in\n * a dependency block is no reason to forget the others.\n */\nexport const StringRecordSchema = Schema.Record(Schema.String, Schema.Unknown).pipe(\n\tSchema.decodeTo(Schema.Record(Schema.String, Schema.String), {\n\t\tdecode: Getter.transform((raw: Record<string, unknown>) => {\n\t\t\tconst out: Record<string, string> = {};\n\t\t\tfor (const [key, value] of Object.entries(raw)) {\n\t\t\t\tif (typeof value === \"string\") out[key] = value;\n\t\t\t}\n\t\t\treturn out;\n\t\t}),\n\t\tencode: Getter.passthroughSubtype(),\n\t}),\n);\n\n/** The same per-entry tolerance for a list: `[\"linux\", 7]` decodes to `[\"linux\"]`. */\nexport const StringArraySchema = Schema.Array(Schema.Unknown).pipe(\n\tSchema.decodeTo(Schema.Array(Schema.String), {\n\t\tdecode: Getter.transform((raw: ReadonlyArray<unknown>) =>\n\t\t\traw.flatMap((entry) => (typeof entry === \"string\" ? entry : [])),\n\t\t),\n\t\tencode: Getter.passthroughSubtype(),\n\t}),\n);\n\n/**\n * `peerDependenciesMeta`, normalised.\n *\n * Only `optional` is read, and only its `true` is meaningful — npm writes the\n * flag as a boolean, a hand-edited file may carry anything, and every other\n * value means \"not optional\".\n */\nexport const OptionalFlagRecordSchema = Schema.Record(Schema.String, Schema.Unknown).pipe(\n\tSchema.decodeTo(Schema.Record(Schema.String, Schema.Struct({ optional: Schema.Boolean })), {\n\t\tdecode: Getter.transform((raw: Record<string, unknown>) => {\n\t\t\tconst out: Record<string, { optional: boolean }> = {};\n\t\t\tfor (const [key, value] of Object.entries(raw)) {\n\t\t\t\tif (isRecord(value)) out[key] = { optional: value[\"optional\"] === true };\n\t\t\t}\n\t\t\treturn out;\n\t\t}),\n\t\tencode: Getter.passthroughSubtype(),\n\t}),\n);\n\n/*\n * The `Optional…` variants below decode an empty result to `undefined`.\n *\n * Absent has to stay absent. `dependencies: {}` and no `dependencies` at all\n * read the same to the resolver, but the first one travels into a bundle\n * manifest claiming the registry published an empty block — a difference\n * somebody diffing two manifests has to explain.\n */\n\nconst absentWhenEmpty = <T extends Record<string, unknown>>(value: T): T | undefined =>\n\tObject.keys(value).length > 0 ? value : undefined;\n\nexport const OptionalStringRecordSchema = StringRecordSchema.pipe(\n\tSchema.decodeTo(Schema.UndefinedOr(Schema.Record(Schema.String, Schema.String)), {\n\t\tdecode: Getter.transform(absentWhenEmpty<Record<string, string>>),\n\t\tencode: Getter.transform((value: Record<string, string> | undefined) => value ?? {}),\n\t}),\n);\n\nexport const OptionalStringArraySchema = StringArraySchema.pipe(\n\tSchema.decodeTo(Schema.UndefinedOr(Schema.Array(Schema.String)), {\n\t\tdecode: Getter.transform((value: ReadonlyArray<string>) =>\n\t\t\tvalue.length > 0 ? value : undefined,\n\t\t),\n\t\tencode: Getter.transform((value: ReadonlyArray<string> | undefined) => value ?? []),\n\t}),\n);\n\nexport const OptionalFlagRecordOrAbsentSchema = OptionalFlagRecordSchema.pipe(\n\tSchema.decodeTo(\n\t\tSchema.UndefinedOr(\n\t\t\tSchema.Record(Schema.String, Schema.Struct({ optional: Schema.Boolean })),\n\t\t),\n\t\t{\n\t\t\tdecode: Getter.transform(\n\t\t\t\tabsentWhenEmpty<Record<string, { readonly optional: boolean }>>,\n\t\t\t),\n\t\t\tencode: Getter.transform(\n\t\t\t\t(value: Record<string, { readonly optional: boolean }> | undefined) => value ?? {},\n\t\t\t),\n\t\t},\n\t),\n);\n","/**\n * Parsing and validation of package specs — the `lodash`, `react@18.2.0`,\n * `@babel/core@^7`, `typescript@next` strings a user types.\n *\n * Deliberately dependency-light and synchronous: parsing must never touch the\n * network, so `--dry-run` and argument validation stay instant.\n */\nimport semver from \"semver\";\n\nimport { InvalidSpecError } from \"./errors.js\";\n\n/** How a spec narrows down which version(s) of a package we want. */\nexport type Selector =\n\t/** An exact, fully-qualified version: `react@18.2.0`. */\n\t| { readonly _tag: \"Exact\"; readonly version: string }\n\t/** A semver range: `react@^18`, `react@>=17 <19`, `react@*`. */\n\t| { readonly _tag: \"Range\"; readonly range: string }\n\t/** A dist-tag: `react@latest`, `typescript@next`. */\n\t| { readonly _tag: \"Tag\"; readonly tag: string };\n\n/** A parsed, validated package spec. */\nexport type PackageSpec = {\n\t/** The npm package name, including scope. */\n\treadonly name: string;\n\t/** What the user asked for after the `@`. */\n\treadonly selector: Selector;\n\t/** The original string, kept verbatim for error messages and the manifest. */\n\treadonly raw: string;\n};\n\nconst MAX_NAME_LENGTH = 214;\n\n// The registry accepts URL-safe characters plus `-`, `.` and `_`.\nconst SEGMENT_RE = /^[a-z0-9\\-._~]+$/;\n\nconst DIST_TAG_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;\n\n/** Renders a spec back into the canonical `name@selector` form. */\nexport const formatSpec = (spec: PackageSpec): string =>\n\t`${spec.name}@${formatSelector(spec.selector)}`;\n\n/** Human-readable form of just the selector part. */\nexport const formatSelector = (selector: Selector): string => {\n\tswitch (selector._tag) {\n\t\tcase \"Exact\":\n\t\t\treturn selector.version;\n\t\tcase \"Range\":\n\t\t\treturn selector.range;\n\t\tcase \"Tag\":\n\t\t\treturn selector.tag;\n\t}\n};\n\n/**\n * Validates an npm package name against the rules the registry actually\n * enforces. Returns `null` when valid, or the reason it is not.\n */\nexport const validatePackageName = (name: string): string | null => {\n\tif (name.length === 0) return \"name is empty\";\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\treturn `name is longer than ${MAX_NAME_LENGTH} characters`;\n\t}\n\tif (name.trim() !== name) return \"name has leading or trailing whitespace\";\n\tif (name.startsWith(\".\")) return \"name cannot start with a period\";\n\tif (name.startsWith(\"_\")) return \"name cannot start with an underscore\";\n\tif (name !== name.toLowerCase()) return \"name cannot contain capital letters\";\n\n\tif (name.startsWith(\"@\")) {\n\t\tconst slash = name.indexOf(\"/\");\n\t\tif (slash === -1) return \"scoped name is missing the '/name' part\";\n\t\tconst scope = name.slice(1, slash);\n\t\tconst rest = name.slice(slash + 1);\n\t\tif (scope.length === 0) return \"scope is empty\";\n\t\tif (rest.length === 0) return \"name after the scope is empty\";\n\t\tif (rest.includes(\"/\")) return \"name contains more than one '/'\";\n\t\tif (!SEGMENT_RE.test(scope)) return `scope \"${scope}\" contains illegal characters`;\n\t\tif (!SEGMENT_RE.test(rest)) return `name \"${rest}\" contains illegal characters`;\n\t\treturn null;\n\t}\n\n\tif (name.includes(\"/\")) return \"unscoped name cannot contain '/'\";\n\tif (!SEGMENT_RE.test(name)) return \"name contains illegal characters\";\n\treturn null;\n};\n\n/**\n * Parses a single spec string.\n *\n * Splitting on `@` is the fiddly part: a scoped name *starts* with `@`, so we\n * look for the last `@` that is not at index 0.\n */\nexport const parseSpec = (raw: string): PackageSpec => {\n\tconst input = raw.trim();\n\tif (input.length === 0) {\n\t\tthrow new InvalidSpecError(raw, \"spec is empty\");\n\t}\n\n\tconst at = input.lastIndexOf(\"@\");\n\tconst hasSelector = at > 0;\n\tconst name = hasSelector ? input.slice(0, at) : input;\n\tconst selectorText = hasSelector ? input.slice(at + 1) : \"\";\n\n\tconst nameProblem = validatePackageName(name);\n\tif (nameProblem !== null) {\n\t\tthrow new InvalidSpecError(raw, nameProblem);\n\t}\n\n\tif (!hasSelector || selectorText.length === 0) {\n\t\treturn { name, selector: { _tag: \"Tag\", tag: \"latest\" }, raw: input };\n\t}\n\n\treturn { name, selector: parseSelector(raw, selectorText), raw: input };\n};\n\n/** Classifies the part after the `@` as an exact version, a range, or a dist-tag. */\nexport const parseSelector = (raw: string, text: string): Selector => {\n\t// `semver.valid` only accepts a complete `x.y.z`, which is exactly the\n\t// \"pin me to this one version\" case.\n\tconst exact = semver.valid(text, { loose: false });\n\tif (exact !== null) {\n\t\treturn { _tag: \"Exact\", version: exact };\n\t}\n\n\tif (semver.validRange(text, { loose: false }) !== null) {\n\t\treturn { _tag: \"Range\", range: text };\n\t}\n\n\t// Anything left has to be a dist-tag. Tags may not look like versions and\n\t// may not contain characters that would break a registry URL.\n\tif (!DIST_TAG_RE.test(text)) {\n\t\tthrow new InvalidSpecError(\n\t\t\traw,\n\t\t\t`\"${text}\" is not a valid version, semver range, or dist-tag`,\n\t\t);\n\t}\n\treturn { _tag: \"Tag\", tag: text };\n};\n\n/**\n * Parses many specs, collecting *every* failure rather than stopping at the\n * first. Somebody bundling forty packages should be told about all four typos\n * in one go, not made to re-run four times.\n */\nexport const parseSpecs = (\n\tinputs: ReadonlyArray<string>,\n): {\n\treadonly specs: ReadonlyArray<PackageSpec>;\n\treadonly errors: ReadonlyArray<InvalidSpecError>;\n} => {\n\tconst specs: Array<PackageSpec> = [];\n\tconst errors: Array<InvalidSpecError> = [];\n\tfor (const input of inputs) {\n\t\ttry {\n\t\t\tspecs.push(parseSpec(input));\n\t\t} catch (error) {\n\t\t\tif (error instanceof InvalidSpecError) {\n\t\t\t\terrors.push(error);\n\t\t\t} else {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t}\n\treturn { specs, errors };\n};\n\n/**\n * Collapses duplicate specs, keeping the first occurrence.\n *\n * `npmb react react@latest` is a plausible thing to type and should not\n * download React twice.\n */\nexport const dedupeSpecs = (specs: ReadonlyArray<PackageSpec>): ReadonlyArray<PackageSpec> => {\n\tconst seen = new Set<string>();\n\tconst out: Array<PackageSpec> = [];\n\tfor (const spec of specs) {\n\t\tconst key = formatSpec(spec);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tout.push(spec);\n\t}\n\treturn out;\n};\n","/**\n * Classification of the right-hand side of a dependency entry.\n *\n * `\"dependencies\": { \"x\": \"^1.0.0\" }` is the easy case. Real package.json files\n * also contain aliases, git URLs, tarball URLs, `file:` links and\n * `workspace:` protocols — none of which can be fetched from a registry.\n *\n * Rather than crashing or silently producing a bundle that will not install,\n * we classify each edge and let the caller report precisely what was skipped\n * and why.\n */\nimport semver from \"semver\";\n\nimport type { Selector } from \"./spec.js\";\n\n/** What a dependency edge points at. */\nexport type DependencyTarget =\n\t/** A normal registry dependency. `name` may differ from the key under an alias. */\n\t| {\n\t\t\treadonly _tag: \"Registry\";\n\t\t\treadonly name: string;\n\t\t\treadonly selector: Selector;\n\t\t\t/** Set when the edge is an `npm:` alias, e.g. `\"lodash4\": \"npm:lodash@^4\"`. */\n\t\t\treadonly aliasOf?: string | undefined;\n\t }\n\t/** Something we cannot fetch from a registry. */\n\t| {\n\t\t\treadonly _tag: \"Unsupported\";\n\t\t\treadonly name: string;\n\t\t\treadonly raw: string;\n\t\t\treadonly reason: string;\n\t };\n\nconst UNSUPPORTED_PROTOCOLS: ReadonlyArray<readonly [string, string]> = [\n\t[\"file:\", \"local file path\"],\n\t[\"link:\", \"local link\"],\n\t[\"workspace:\", \"workspace protocol\"],\n\t[\"portal:\", \"portal protocol\"],\n\t[\"patch:\", \"patch protocol\"],\n\t[\"git:\", \"git dependency\"],\n\t[\"git+\", \"git dependency\"],\n\t[\"github:\", \"GitHub shorthand\"],\n\t[\"gitlab:\", \"GitLab shorthand\"],\n\t[\"bitbucket:\", \"Bitbucket shorthand\"],\n\t[\"http:\", \"remote tarball URL\"],\n\t[\"https:\", \"remote tarball URL\"],\n];\n\n/**\n * Classifies one `name -> range` entry.\n *\n * An empty range, `*`, and `latest` all mean \"any published version\"; npm\n * treats them interchangeably and so do we.\n */\nexport const parseDependencyTarget = (name: string, raw: string): DependencyTarget => {\n\tconst text = raw.trim();\n\n\tif (text.length === 0 || text === \"*\" || text === \"x\" || text === \"latest\") {\n\t\treturn { _tag: \"Registry\", name, selector: { _tag: \"Range\", range: \"*\" } };\n\t}\n\n\tif (text.startsWith(\"npm:\")) {\n\t\treturn parseAlias(name, text);\n\t}\n\n\tfor (const [prefix, reason] of UNSUPPORTED_PROTOCOLS) {\n\t\tif (text.startsWith(prefix)) {\n\t\t\treturn { _tag: \"Unsupported\", name, raw: text, reason };\n\t\t}\n\t}\n\n\t// Bare `owner/repo` is GitHub shorthand, but only when it is not a valid\n\t// range — `>=1.0.0/2` is not a thing, so this ordering is safe.\n\tif (semver.validRange(text, { loose: true }) === null && /^[\\w.-]+\\/[\\w.-]+/.test(text)) {\n\t\treturn { _tag: \"Unsupported\", name, raw: text, reason: \"git shorthand\" };\n\t}\n\n\tconst exact = semver.valid(text, { loose: true });\n\tif (exact !== null) {\n\t\treturn { _tag: \"Registry\", name, selector: { _tag: \"Exact\", version: exact } };\n\t}\n\n\tif (semver.validRange(text, { loose: true }) !== null) {\n\t\treturn { _tag: \"Registry\", name, selector: { _tag: \"Range\", range: text } };\n\t}\n\n\t// Whatever is left is most plausibly a dist-tag published by a private\n\t// registry, e.g. `\"@acme/sdk\": \"stable\"`.\n\tif (/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(text)) {\n\t\treturn { _tag: \"Registry\", name, selector: { _tag: \"Tag\", tag: text } };\n\t}\n\n\treturn { _tag: \"Unsupported\", name, raw: text, reason: \"unrecognised version specifier\" };\n};\n\n/**\n * Parses `npm:<name>[@<range>]`.\n *\n * The nested name may itself be scoped, so the `@` split has the same\n * \"not at index 0\" caveat as top-level spec parsing.\n */\nconst parseAlias = (key: string, text: string): DependencyTarget => {\n\tconst body = text.slice(\"npm:\".length);\n\tif (body.length === 0) {\n\t\treturn { _tag: \"Unsupported\", name: key, raw: text, reason: \"empty npm: alias\" };\n\t}\n\n\tconst at = body.lastIndexOf(\"@\");\n\tconst target = at > 0 ? body.slice(0, at) : body;\n\tconst rangeText = at > 0 ? body.slice(at + 1) : \"\";\n\n\tif (target.length === 0) {\n\t\treturn { _tag: \"Unsupported\", name: key, raw: text, reason: \"empty npm: alias target\" };\n\t}\n\n\tconst inner = parseDependencyTarget(target, rangeText);\n\tif (inner._tag === \"Unsupported\") {\n\t\treturn { ...inner, name: key, raw: text };\n\t}\n\treturn { _tag: \"Registry\", name: target, selector: inner.selector, aliasOf: key };\n};\n","/**\n * Platform matching for optional dependencies.\n *\n * The default is \"keep every platform\" and narrowing is opt-in — see\n * `notes/requirements.md` § FR-13 for the failure mode that decides it.\n *\n * The mechanics that decision rests on are here rather than there: a package\n * declares `os`, `cpu` and `libc` in its own manifest, and this module keeps a\n * package when the filter *could* install it, not when it matches exactly.\n */\n\n/** A target to keep, e.g. `linux-x64`, `linux-x64-musl`, or just `linux`. */\nexport type PlatformTarget = {\n\treadonly os: string;\n\t/** Undefined means \"every architecture for this OS\". */\n\treadonly cpu?: string | undefined;\n\t/** `glibc` / `musl`. Undefined means \"don't care\". */\n\treadonly libc?: string | undefined;\n};\n\n/**\n * Which platforms optional dependencies should be resolved for.\n *\n * - `All` — keep everything, regardless of `os`/`cpu`/`libc` (the default).\n * - `Targets` — keep only packages that could install on one of these.\n */\nexport type PlatformFilter =\n\t| { readonly _tag: \"All\" }\n\t| { readonly _tag: \"Targets\"; readonly targets: ReadonlyArray<PlatformTarget> };\n\n/** Constraints declared by a package, as they appear in its manifest. */\nexport type PlatformConstraints = {\n\treadonly os?: ReadonlyArray<string> | undefined;\n\treadonly cpu?: ReadonlyArray<string> | undefined;\n\treadonly libc?: ReadonlyArray<string> | undefined;\n};\n\nexport const allPlatforms: PlatformFilter = { _tag: \"All\" };\n\nexport const platformTargets = (targets: ReadonlyArray<PlatformTarget>): PlatformFilter => ({\n\t_tag: \"Targets\",\n\ttargets,\n});\n\n/** The machine we are currently running on. */\nexport const currentPlatform = (): PlatformTarget => ({\n\tos: process.platform,\n\tcpu: process.arch,\n});\n\n/**\n * npm's documented `os` values, plus the names people actually type.\n *\n * An OS on its own is a valid target, so a typo has to be caught here — the\n * whole failure mode this tool exists to prevent is a bundle that looks fine\n * and installs nothing. `--platform windows` silently matching no binding at\n * all would be precisely that, so it is corrected rather than accepted.\n */\nconst osByAlias: Readonly<Record<string, string | undefined>> = {\n\twin: \"win32\",\n\twindows: \"win32\",\n\tmac: \"darwin\",\n\tmacos: \"darwin\",\n\tosx: \"darwin\",\n};\n\nconst KNOWN_OS: ReadonlySet<string> = new Set([\n\t\"aix\",\n\t\"android\",\n\t\"cygwin\",\n\t\"darwin\",\n\t\"freebsd\",\n\t\"haiku\",\n\t\"linux\",\n\t\"netbsd\",\n\t\"openbsd\",\n\t\"sunos\",\n\t\"win32\",\n]);\n\nconst LIBC: ReadonlySet<string> = new Set([\"musl\", \"glibc\"]);\n\n/**\n * Parses `linux`, `linux-x64`, `darwin-arm64`, `win32-x64`, `linux-x64-musl`,\n * `linux-musl`.\n *\n * An OS on its own means every architecture for that OS, which is almost always\n * what you want: \"the Windows and Linux bindings\" is a far more natural way to\n * describe a target set than enumerating four `os-arch` pairs, and it keeps\n * working when a package adds an arm64 build.\n *\n * Returns `null` rather than throwing so the CLI can report every bad value at\n * once alongside the list of accepted forms.\n */\nexport const parsePlatformTarget = (input: string): PlatformTarget | null => {\n\tconst parts = input\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.split(\"-\")\n\t\t.filter((part) => part.length > 0);\n\tconst [rawOs, second, third] = parts;\n\tif (rawOs === undefined || parts.length > 3) return null;\n\n\tconst os = osByAlias[rawOs] ?? rawOs;\n\tif (!KNOWN_OS.has(os)) return null;\n\n\tif (second === undefined) return { os };\n\n\t// `linux-musl` is an OS plus a libc, not an OS plus an architecture.\n\tif (third === undefined) {\n\t\treturn LIBC.has(second) ? { os, libc: second } : { os, cpu: second };\n\t}\n\n\tif (!LIBC.has(third)) return null;\n\treturn { os, cpu: second, libc: third };\n};\n\n/**\n * npm's `os`/`cpu`/`libc` fields use a list of allowed values, where a leading\n * `!` negates. An empty or absent list means \"no constraint\".\n *\n * The semantics npm implements: if any negated entry matches, reject. Otherwise\n * if there are any positive entries, at least one must match.\n */\nconst listAllows = (list: ReadonlyArray<string> | undefined, value: string): boolean => {\n\tif (list === undefined || list.length === 0) return true;\n\n\tlet hasPositive = false;\n\tlet positiveMatched = false;\n\n\tfor (const entry of list) {\n\t\tconst normalized = entry.trim().toLowerCase();\n\t\tif (normalized.length === 0) continue;\n\t\tif (normalized === \"any\" || normalized === \"*\") return true;\n\n\t\tif (normalized.startsWith(\"!\")) {\n\t\t\tif (normalized.slice(1) === value) return false;\n\t\t} else {\n\t\t\thasPositive = true;\n\t\t\tif (normalized === value) positiveMatched = true;\n\t\t}\n\t}\n\n\treturn hasPositive ? positiveMatched : true;\n};\n\n/** Would this package install on this specific target? */\nexport const matchesTarget = (\n\tconstraints: PlatformConstraints,\n\ttarget: PlatformTarget,\n): boolean => {\n\tif (!listAllows(constraints.os, target.os)) return false;\n\t// An undefined cpu means the target is the whole OS, so any architecture the\n\t// package declares qualifies.\n\tif (target.cpu !== undefined && !listAllows(constraints.cpu, target.cpu)) return false;\n\tif (target.libc !== undefined && !listAllows(constraints.libc, target.libc)) return false;\n\treturn true;\n};\n\n/**\n * Should this package be included, given the active filter?\n *\n * Under `All` this is unconditionally `true` — that is the whole point.\n */\nexport const isIncluded = (constraints: PlatformConstraints, filter: PlatformFilter): boolean => {\n\tif (filter._tag === \"All\") return true;\n\treturn filter.targets.some((target) => matchesTarget(constraints, target));\n};\n\n/** Renders a filter for the manifest and for `--dry-run` output. */\nexport const formatPlatformFilter = (filter: PlatformFilter): string => {\n\tif (filter._tag === \"All\") return \"all\";\n\treturn filter.targets\n\t\t.map((target) =>\n\t\t\t[target.os, target.cpu, target.libc].filter((part) => part !== undefined).join(\"-\"),\n\t\t)\n\t\t.join(\",\");\n};\n","/**\n * Option types shared by the resolver and the bundler, plus their defaults.\n *\n * The rule the defaults below are derived from is stated once, beside the flags\n * that expose them — see `descriptors.ts` in `@packall/cli`, and\n * `notes/requirements.md` § FR-13.\n */\nimport { Layout } from \"./enums/layout.js\";\nimport type { PlatformFilter } from \"./platform.js\";\nimport { allPlatforms } from \"./platform.js\";\n\n/** Which dependency edges the resolver follows. */\nexport type DependencyScope = {\n\t/**\n\t * Follow `optionalDependencies`. On by default — this is where per-platform\n\t * native binaries live, and omitting them is the most common reason an\n\t * offline install fails on a machine other than the one that built it.\n\t */\n\treadonly optional: boolean;\n\t/**\n\t * Follow non-optional `peerDependencies`. On by default, because npm 7+\n\t * auto-installs peers and will reach for the network if they are absent.\n\t */\n\treadonly peer: boolean;\n\t/** Which platforms optional dependencies are kept for. */\n\treadonly platforms: PlatformFilter;\n};\n\nexport const defaultScope: DependencyScope = {\n\toptional: true,\n\tpeer: true,\n\tplatforms: allPlatforms,\n};\n\n/** Options governing version selection and the dependency walk. */\nexport type ResolveOptions = {\n\treadonly scope: DependencyScope;\n\t/**\n\t * When a root spec is a range, take *every* published version that satisfies\n\t * it rather than only the best match.\n\t *\n\t * `npmb react@^18` bundles one version; `npmb --all-versions react@^18`\n\t * bundles all of them.\n\t */\n\treadonly allVersions: boolean;\n\t/** With `allVersions`, keep at most this many (newest first). */\n\treadonly maxVersions?: number | undefined;\n\t/** Let prereleases satisfy ranges that would not normally admit them. */\n\treadonly includePrerelease: boolean;\n\t/** How many registry requests to have in flight at once. */\n\treadonly concurrency: number;\n};\n\nexport const defaultResolveOptions: ResolveOptions = {\n\tscope: defaultScope,\n\tallVersions: false,\n\tincludePrerelease: false,\n\tconcurrency: 10,\n};\n\n/** Options for a full bundle run. */\nexport type BundleOptions = ResolveOptions & {\n\treadonly layout: Layout;\n\t/** Directory the finished artifacts are written to. */\n\treadonly outDir: string;\n\t/** Base name for the archive in `single` layout. Defaults to `bundle`. */\n\treadonly archiveName?: string | undefined;\n\t/** Resolve and report, but download nothing and write nothing. */\n\treadonly dryRun: boolean;\n\t/**\n\t * Verify every tarball against the checksum the registry advertised.\n\t *\n\t * On by default and there is essentially no good reason to turn it off; the\n\t * escape hatch exists only for registries that serve broken metadata.\n\t */\n\treadonly verifyIntegrity: boolean;\n\t/** Overwrite existing files in `outDir` instead of refusing. */\n\treadonly force: boolean;\n\t/**\n\t * Planned output files to leave untouched, by file name.\n\t *\n\t * The engine never asks anything; deciding is the caller's job. The CLI's\n\t * `--force prompt` resolves its per-file answers into this set, so \"keep the\n\t * existing one\" means that artifact is simply not produced, and the rest of\n\t * the run continues.\n\t */\n\treadonly skipExisting?: ReadonlySet<string> | undefined;\n\t/**\n\t * Planned output files that may be replaced, by file name.\n\t *\n\t * A narrower `force`: `--force tsdown` says \"replace tsdown's bundle, and\n\t * still ask about anything else\".\n\t */\n\treadonly overwrite?: ReadonlySet<string> | undefined;\n};\n\nexport const defaultBundleOptions: Omit<BundleOptions, \"outDir\"> = {\n\t...defaultResolveOptions,\n\tlayout: Layout.PerSpec,\n\tdryRun: false,\n\tverifyIntegrity: true,\n\tforce: false,\n};\n","/**\n * The registry seam.\n *\n * This is the **only** place in the engine that knows a registry exists.\n * Everything downstream — range resolution, the dependency walk, layout,\n * archiving — is expressed against these three operations, so swapping npm for\n * something else means implementing this interface and nothing more.\n *\n * `@packall/registry-npm` provides the implementation that speaks the plain\n * npm registry protocol, which is what Artifactory, Nexus, Verdaccio, GitHub\n * Packages and registry.npmjs.org all serve.\n */\nimport * as Context from \"effect/Context\";\nimport type * as Effect from \"effect/Effect\";\n\nimport type { BundlerError } from \"./errors.js\";\n\n/** Where the tarball lives and how to prove it arrived intact. */\nexport type PackageDist = {\n\treadonly tarball: string;\n\t/** SRI string, e.g. `sha512-...`. Preferred over `shasum`. */\n\treadonly integrity?: string | undefined;\n\t/** Legacy hex sha1. Still the only checksum on very old versions. */\n\treadonly shasum?: string | undefined;\n\treadonly unpackedSize?: number | undefined;\n\treadonly fileCount?: number | undefined;\n};\n\n/**\n * A single published version, as the registry describes it.\n *\n * This is a narrowed view of a package.json — only the fields that affect what\n * has to be downloaded. Unknown fields are ignored rather than rejected,\n * because registries add metadata over time and a bundler that breaks on new\n * metadata is worse than useless.\n */\nexport type PackageManifest = {\n\treadonly name: string;\n\treadonly version: string;\n\n\treadonly dependencies?: Readonly<Record<string, string>> | undefined;\n\treadonly optionalDependencies?: Readonly<Record<string, string>> | undefined;\n\treadonly peerDependencies?: Readonly<Record<string, string>> | undefined;\n\treadonly peerDependenciesMeta?:\n\t\t| Readonly<Record<string, { readonly optional?: boolean | undefined }>>\n\t\t| undefined;\n\treadonly devDependencies?: Readonly<Record<string, string>> | undefined;\n\treadonly bundleDependencies?: ReadonlyArray<string> | undefined;\n\n\t/** Platform constraints, used when `--platform` narrows optional deps. */\n\treadonly os?: ReadonlyArray<string> | undefined;\n\treadonly cpu?: ReadonlyArray<string> | undefined;\n\treadonly libc?: ReadonlyArray<string> | undefined;\n\n\treadonly deprecated?: string | undefined;\n\n\treadonly dist: PackageDist;\n};\n\n/** Everything the registry knows about one package. */\nexport type Packument = {\n\treadonly name: string;\n\t/** `{ latest: \"1.2.3\", next: \"2.0.0-beta.1\" }` */\n\treadonly distTags: Readonly<Record<string, string>>;\n\t/** Every published version, keyed by version string. */\n\treadonly versions: Readonly<Record<string, PackageManifest>>;\n};\n\nexport declare namespace Registry {\n\t/** The set of operations a registry backend has to provide. */\n\texport type Service = {\n\t\t/** Short identifier for the manifest and for error messages, e.g. `\"npm\"`. */\n\t\treadonly kind: string;\n\n\t\t/**\n\t\t * The registry URL that will actually be used for a given package, after\n\t\t * per-scope configuration is applied. Used for reporting only.\n\t\t */\n\t\treadonly registryFor: (packageName: string) => string;\n\n\t\t/**\n\t\t * Cheap liveness check, run once before any real work.\n\t\t *\n\t\t * This is what turns \"hangs forever behind a dead VPN\" into a five-second\n\t\t * error naming the host we could not reach.\n\t\t */\n\t\treadonly preflight: Effect.Effect<void, BundlerError>;\n\n\t\t/**\n\t\t * Full metadata for a package. Implementations are expected to memoise:\n\t\t * the dependency walk asks for the same popular packages repeatedly.\n\t\t */\n\t\treadonly packument: (packageName: string) => Effect.Effect<Packument, BundlerError>;\n\n\t\t/** Fetches the tarball bytes for one published version. */\n\t\treadonly download: (manifest: PackageManifest) => Effect.Effect<Uint8Array, BundlerError>;\n\t};\n}\n\n/**\n * Service tag for the registry backend.\n *\n * @example\n * ```ts\n * import { Effect } from \"effect\"\n * import { Registry } from \"@packall/core\"\n *\n * const program = Effect.gen(function*() {\n * const registry = yield* Registry\n * return yield* registry.packument(\"lodash\")\n * })\n * ```\n */\nexport class Registry extends Context.Service<Registry, Registry.Service>()(\n\t\"@packall/core/Registry\",\n) {}\n","/**\n * Checksum verification for downloaded tarballs.\n *\n * A failed check discards the download rather than warning and carrying on —\n * see `notes/requirements.md` § FR-9 for why that strictness is a requirement\n * rather than a preference.\n *\n * Built on Effect's `Crypto` service rather than `node:crypto` directly. The\n * four digests `Crypto` offers — SHA-1, SHA-256, SHA-384, SHA-512 — are exactly\n * the four npm publishes, so nothing is given up, and the same verification\n * then runs unchanged against WebCrypto in a browser. Parsing stays here\n * because the subset of Subresource Integrity npm actually emits is small and\n * entirely mechanical; `ssri` would be a dependency for a regex.\n */\nimport * as Crypto from \"effect/Crypto\";\nimport * as Effect from \"effect/Effect\";\nimport * as Encoding from \"effect/Encoding\";\nimport type { PlatformError } from \"effect/PlatformError\";\n\n/**\n * The digests npm publishes, mapped to what `Crypto.digest` calls them.\n *\n * Doubles as the supported-algorithm list: an SRI token whose algorithm is not\n * a key here is one we cannot check, and is dropped during parsing.\n */\nconst digestAlgorithmByName = {\n\tsha512: \"SHA-512\",\n\tsha384: \"SHA-384\",\n\tsha256: \"SHA-256\",\n\tsha1: \"SHA-1\",\n} as const satisfies Record<string, Crypto.DigestAlgorithm>;\n\n/** An algorithm this module can verify against. */\nexport type IntegrityAlgorithm = keyof typeof digestAlgorithmByName;\n\nconst isSupported = (algorithm: string): algorithm is IntegrityAlgorithm =>\n\tObject.hasOwn(digestAlgorithmByName, algorithm);\n\n/** One parsed SRI hash. */\nexport type IntegrityHash = {\n\treadonly algorithm: IntegrityAlgorithm;\n\t/** Base64 digest, exactly as written in the SRI string. */\n\treadonly digest: string;\n};\n\n/**\n * Parses an SRI string such as `sha512-abc...==`.\n *\n * npm permits several space-separated hashes; we keep every one we can verify\n * and ignore algorithms we cannot.\n */\nexport const parseIntegrity = (integrity: string): ReadonlyArray<IntegrityHash> => {\n\tconst hashes: Array<IntegrityHash> = [];\n\tfor (const token of integrity.trim().split(/\\s+/)) {\n\t\tif (token.length === 0) continue;\n\t\tconst dash = token.indexOf(\"-\");\n\t\tif (dash <= 0) continue;\n\t\tconst algorithm = token.slice(0, dash).toLowerCase();\n\t\tconst digest = token.slice(dash + 1);\n\t\tif (!isSupported(algorithm) || digest.length === 0) continue;\n\t\thashes.push({ algorithm, digest });\n\t}\n\treturn hashes;\n};\n\nconst digestBytes = (\n\tdata: Uint8Array,\n\talgorithm: IntegrityAlgorithm,\n): Effect.Effect<Uint8Array, PlatformError, Crypto.Crypto> =>\n\tEffect.gen(function* () {\n\t\tconst crypto = yield* Crypto.Crypto;\n\t\treturn yield* crypto.digest(digestAlgorithmByName[algorithm], data);\n\t});\n\n/** Computes the base64 digest of some bytes under one algorithm. */\nexport const digestOf = (\n\tdata: Uint8Array,\n\talgorithm: IntegrityAlgorithm,\n): Effect.Effect<string, PlatformError, Crypto.Crypto> =>\n\tEffect.map(digestBytes(data, algorithm), Encoding.encodeBase64);\n\n/** Computes the hex digest of some bytes — the form legacy `shasum` uses. */\nexport const hexDigestOf = (\n\tdata: Uint8Array,\n\talgorithm: IntegrityAlgorithm,\n): Effect.Effect<string, PlatformError, Crypto.Crypto> =>\n\tEffect.map(digestBytes(data, algorithm), Encoding.encodeHex);\n\n/** Result of checking a download. */\nexport type VerificationResult =\n\t/** Verified against at least one checksum. */\n\t| { readonly _tag: \"Verified\"; readonly using: string }\n\t/** The registry advertised no checksum we could use. */\n\t| { readonly _tag: \"Unverifiable\"; readonly reason: string }\n\t/** A checksum was present and did not match. */\n\t| { readonly _tag: \"Mismatch\"; readonly expected: string; readonly actual: string };\n\n/**\n * Constant-time comparison of two digest strings.\n *\n * Written by hand rather than with `node:crypto`'s `timingSafeEqual`, which\n * needs `Buffer` and would pin this module to Node. Both digests here are\n * public knowledge, so the timing property is close to theatre — but it costs\n * four lines, and the alternative is explaining in a review why it was dropped.\n */\nconst digestsEqual = (a: string, b: string): boolean => {\n\tif (a.length !== b.length) return false;\n\tlet difference = 0;\n\tfor (let index = 0; index < a.length; index++) {\n\t\tdifference |= a.charCodeAt(index) ^ b.charCodeAt(index);\n\t}\n\treturn difference === 0;\n};\n\n/**\n * Checks bytes against whichever checksums the registry supplied.\n *\n * SRI is preferred; `shasum` is the fallback for versions published before\n * integrity strings existed. If the registry gave us neither, that is reported\n * as `Unverifiable` rather than silently treated as a pass — the caller decides\n * whether to tolerate it.\n */\nexport const verify = (\n\tdata: Uint8Array,\n\tdist: { readonly integrity?: string | undefined; readonly shasum?: string | undefined },\n): Effect.Effect<VerificationResult, PlatformError, Crypto.Crypto> =>\n\tEffect.gen(function* () {\n\t\tif (dist.integrity !== undefined && dist.integrity.length > 0) {\n\t\t\t// Strongest first, so a mismatch is reported against the best hash present.\n\t\t\tconst [best] = parseIntegrity(dist.integrity).toSorted(\n\t\t\t\t(a, b) => strengthByAlgorithm[b.algorithm] - strengthByAlgorithm[a.algorithm],\n\t\t\t);\n\t\t\tif (best === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\t_tag: \"Unverifiable\",\n\t\t\t\t\treason: `no supported algorithm in \"${dist.integrity}\"`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst actual = yield* digestOf(data, best.algorithm);\n\t\t\treturn digestsEqual(actual, best.digest)\n\t\t\t\t? { _tag: \"Verified\", using: best.algorithm }\n\t\t\t\t: {\n\t\t\t\t\t\t_tag: \"Mismatch\",\n\t\t\t\t\t\texpected: `${best.algorithm}-${best.digest}`,\n\t\t\t\t\t\tactual: `${best.algorithm}-${actual}`,\n\t\t\t\t\t};\n\t\t}\n\n\t\tif (dist.shasum !== undefined && dist.shasum.length > 0) {\n\t\t\tconst actual = yield* hexDigestOf(data, \"sha1\");\n\t\t\treturn digestsEqual(actual.toLowerCase(), dist.shasum.toLowerCase())\n\t\t\t\t? { _tag: \"Verified\", using: \"sha1\" }\n\t\t\t\t: { _tag: \"Mismatch\", expected: `sha1-${dist.shasum}`, actual: `sha1-${actual}` };\n\t\t}\n\n\t\treturn { _tag: \"Unverifiable\", reason: \"registry advertised no integrity or shasum\" };\n\t});\n\nconst strengthByAlgorithm = {\n\tsha512: 4,\n\tsha384: 3,\n\tsha256: 2,\n\tsha1: 1,\n} as const satisfies Record<IntegrityAlgorithm, number>;\n","/**\n * The on-disk shape of a bundle.\n *\n * Under every layout but `flat`, everything is laid out exactly the way a\n * registry serves it:\n *\n * lodash/-/lodash-4.17.21.tgz\n * @babel/core/-/core-7.24.0.tgz\n *\n * That is not an Artifactory convention — it is the path structure in every\n * `dist.tarball` URL npm publishes. See `notes/requirements.md` § FR-12 for\n * what that buys.\n *\n * The one shape worth noticing before editing anything here: a scoped\n * package's file name drops the scope, so `@babel/core` becomes\n * `core-7.24.0.tgz` under an `@babel/core/-/` directory.\n *\n * `flat` layout is the exception; `bundlePath` is where the two part company.\n */\n\nimport { Layout } from \"./enums/layout.js\";\n\n/** Splits `@scope/name` into its parts. `scope` is undefined when unscoped. */\nexport const splitName = (\n\tname: string,\n): { readonly scope: string | undefined; readonly bare: string } => {\n\tif (!name.startsWith(\"@\")) return { scope: undefined, bare: name };\n\tconst slash = name.indexOf(\"/\");\n\tif (slash === -1) return { scope: undefined, bare: name };\n\treturn { scope: name.slice(0, slash), bare: name.slice(slash + 1) };\n};\n\n/** `@babel/core` + `7.24.0` -> `core-7.24.0.tgz` */\nexport const tarballFileName = (name: string, version: string): string => {\n\tconst { bare } = splitName(name);\n\treturn `${bare}-${version}.tgz`;\n};\n\n/**\n * The path of one package tarball within a bundle, using `/` separators\n * regardless of host platform — these become tar entry names, and tar entries\n * are always POSIX.\n */\nexport const packagePath = (name: string, version: string): string =>\n\t`${name}/-/${tarballFileName(name, version)}`;\n\n/** File name of the manifest that ships inside every bundle. */\nexport const MANIFEST_FILE = \"bundle-manifest.json\";\n\n/** File name of the short import guide that ships inside every bundle. */\nexport const README_FILE = \"IMPORT.md\";\n\n/**\n * A flat, collision-free file name for one `name@version`.\n *\n * It is the spec, with the one character a file name cannot hold taken out:\n * `@types/react@19.2.18` becomes `@types-react@19.2.18.tgz`. So the name of the\n * file answers the question somebody has when they are looking at a directory\n * of them — which package, and which version — in the notation they would have\n * typed to ask for it.\n *\n * The version is joined with `@` rather than `-` for the same reason. A\n * hyphen made `foo-bar-1.0.0` ambiguous by eye: package `foo` at `bar-1.0.0`,\n * or `foo-bar` at `1.0.0`? npm's own syntax has no such problem, because a\n * package name may not contain `@` beyond its scope.\n *\n * **The scope's `@` stays**, and it is the difference between a correct bundle\n * and a quietly incomplete one.\n *\n * Dropping it — which this did, matching what `npm pack` produces — meant\n * `@something/somewhat` and `something-somewhat` were both\n * `something-somewhat-1.0.0.tgz`. Two different packages, one path: the second\n * landed on the first, and the run reported two artifacts for the one file that\n * survived. A bundle short a package, called complete, found at the far end of\n * an air gap.\n *\n * Keeping the `@` makes that impossible by construction rather than by a check,\n * because an unscoped npm name may not begin with one. It is also the more\n * honest name: the scope is part of what the package *is*, and a directory of\n * archives that has forgotten which ones were scoped is a directory somebody\n * has to cross-reference against a manifest.\n *\n * It does not make every collision impossible — `@a/b-c` and `@a-b/c` still\n * meet — so the run still checks before downloading anything. That pair is\n * pathological; the scoped-against-unscoped one is `@babel/core` beside\n * `babel-core`, which is a real migration somebody could be bundling.\n *\n * The leading `@` is safe here in a way it is not inside the archive: tar's\n * splice convention applies to the *file list* it is given, which is what\n * `archive.ts` guards with `./`. These are output paths, not entries.\n */\nexport const flatName = (name: string, version: string): string => {\n\tconst { scope, bare } = splitName(name);\n\tconst prefix = scope === undefined ? bare : `${scope}-${bare}`;\n\treturn `${prefix}@${version}.tgz`;\n};\n\n/**\n * Name of the archive produced for one root spec in `per-spec` layout.\n *\n * The same rule as {@link flatName}, which is where the reasoning lives — a\n * per-spec archive and a `flat` package tarball are both \"one file in a\n * directory, named for what is in it\", and there is no reason for a directory\n * of bundles and a directory of packages to be read differently.\n */\nexport const perSpecArchiveName = flatName;\n\n/**\n * The path of one package tarball within a bundle. The one place the two\n * shapes are chosen between, so a manifest and the tree it describes cannot\n * drift apart.\n *\n * `flat` keeps a file name and no directories, and uses {@link flatName}\n * rather than the registry file name: with the directories gone that name is\n * all there is to tell two packages apart, and the registry one drops the\n * scope, which would put `@types/node` and `node` on the same file. The name\n * is free to differ — `npm publish <tarball>` reads a package's name and\n * version from the `package.json` inside it, not from what the file is\n * called.\n */\nexport const bundlePath = (layout: Layout, name: string, version: string): string =>\n\tlayout === Layout.Flat ? flatName(name, version) : packagePath(name, version);\n\n/** Name of the archive produced in `single` layout. */\nexport const singleArchiveName = (base = \"bundle\"): string => `${base}.tgz`;\n\n/** Shared by both guides. */\ntype GuideOptions = {\n\treadonly packageCount: number;\n\treadonly createdAt: string;\n\treadonly toolVersion: string;\n\treadonly layout: Layout;\n};\n\n/**\n * The import guide written into each bundle.\n *\n * Kept short and copy-pasteable on purpose: whoever opens this is mid-task on a\n * restricted network and does not want prose.\n *\n * Layout-aware, because the instructions genuinely differ — a registry-layout\n * tree uploads into Artifactory as it stands and a flat directory does not, and\n * a guide that said otherwise would be discovered to be wrong by somebody who\n * can no longer look anything up.\n */\nexport const importGuide = (options: GuideOptions): string =>\n\toptions.layout === Layout.Flat ? flatGuide(options) : treeGuide(options);\n\nconst treeGuide = (options: GuideOptions): string =>\n\t`# Importing this bundle\n\n${options.packageCount} package tarball(s), laid out exactly as an npm registry serves them:\n\n <package-name>/-/<file>.tgz\n @<scope>/<name>/-/<file>.tgz\n\nCreated ${options.createdAt} by packall ${options.toolVersion}.\nSee ${MANIFEST_FILE} for the full list with checksums.\n\n## JFrog Artifactory\n\nUnpack, then upload the tree into a **local npm** repository. The layout already\nmatches what Artifactory expects, so no path rewriting is needed:\n\n tar -xzf <this-bundle>.tgz -C ./bundle\n jf rt upload \"bundle/(**)\" \"<npm-local-repo>/{1}\" --flat=false\n\n## Verdaccio / Nexus / any npm registry\n\nPublish each tarball individually:\n\n find ./bundle -name '*.tgz' -exec npm publish --registry <url> {} \\\\;\n\n## Verifying before import\n\n node -e \"const m=require('./bundle/${MANIFEST_FILE}');console.log(m.packages.length+' packages')\"\n\nEvery entry in ${MANIFEST_FILE} carries the integrity string the source registry\nadvertised, and each tarball was checked against it at download time.\n`;\n\nconst flatGuide = (options: GuideOptions): string =>\n\t`# Importing this bundle\n\n${options.packageCount} package tarball(s), side by side in this one directory:\n\n <name>@<version>.tgz\n @<scope>-<name>@<version>.tgz\n\nCreated ${options.createdAt} by packall ${options.toolVersion}.\nSee ${MANIFEST_FILE} for the full list with checksums.\n\n## Publishing into a registry\n\n\\`npm publish\\` reads each package's name and version from the \\`package.json\\`\ninside its tarball, so neither the file names nor the order matter:\n\n for f in *.tgz; do npm publish --registry <url> \"$f\"; done\n\nFor a tree that uploads into Artifactory as it stands, use --layout dir instead.\n\n## Verifying before import\n\n node -e \"const m=require('./${MANIFEST_FILE}');console.log(m.packages.length+' packages')\"\n\nEvery entry in ${MANIFEST_FILE} carries the integrity string the source registry\nadvertised, and each tarball was checked against it at download time.\n`;\n","/**\n * The manifest written into every bundle — the audit trail, answerable without\n * unpacking a single tarball. See `notes/requirements.md` § FR-10.\n */\nimport { bundlePath } from \"./layout.js\";\nimport type { BundleOptions } from \"./options.js\";\nimport { formatPlatformFilter } from \"./platform.js\";\nimport type { Resolution, ResolvedPackage } from \"./resolve.js\";\nimport { formatSpec } from \"./spec.js\";\n\n/** Schema version, bumped when the shape changes incompatibly. */\nexport const MANIFEST_VERSION = 1;\n\nexport type ManifestEntry = {\n\treadonly name: string;\n\treadonly version: string;\n\t/** Path of this tarball inside the bundle. */\n\treadonly path: string;\n\t/** The URL it was downloaded from. */\n\treadonly tarball: string;\n\t/** SRI integrity string as advertised by the source registry, when present. */\n\treadonly integrity?: string | undefined;\n\t/** Legacy sha1, present on older published versions. */\n\treadonly shasum?: string | undefined;\n\t/** Actual size on disk, in bytes. */\n\treadonly bytes?: number | undefined;\n\t/** Human-readable justifications: `root:react@18.2.0`, `prod:scheduler@0.23.0`. */\n\treadonly reasons: ReadonlyArray<string>;\n};\n\nexport type BundleManifest = {\n\treadonly manifestVersion: number;\n\treadonly tool: { readonly name: string; readonly version: string };\n\treadonly createdAt: string;\n\treadonly registry: { readonly kind: string; readonly url: string };\n\t/** What the user asked for, verbatim. */\n\treadonly requested: ReadonlyArray<string>;\n\t/** What each request expanded to. */\n\treadonly roots: ReadonlyArray<{\n\t\treadonly spec: string;\n\t\treadonly versions: ReadonlyArray<string>;\n\t\treadonly packageCount: number;\n\t}>;\n\treadonly options: {\n\t\treadonly layout: string;\n\t\treadonly optionalDependencies: boolean;\n\t\treadonly peerDependencies: boolean;\n\t\treadonly platforms: string;\n\t\treadonly allVersions: boolean;\n\t\treadonly includePrerelease: boolean;\n\t\treadonly integrityVerified: boolean;\n\t};\n\treadonly packages: ReadonlyArray<ManifestEntry>;\n\treadonly warnings: ReadonlyArray<string>;\n\treadonly totals: {\n\t\treadonly packages: number;\n\t\treadonly bytes: number;\n\t};\n};\n\n/** Renders a package's reasons into short, greppable strings. */\nexport const formatReasons = (pkg: ResolvedPackage): ReadonlyArray<string> =>\n\tpkg.reasons.map((reason) =>\n\t\treason._tag === \"Root\" ? `root:${reason.spec}` : `${reason.kind}:${reason.from}`,\n\t);\n\n/** Builds the manifest for a completed (or dry) run. */\nexport const buildManifest = (input: {\n\treadonly resolution: Resolution;\n\t/** Only the packages actually included in *this* archive. */\n\treadonly included: ReadonlyArray<ResolvedPackage>;\n\treadonly options: BundleOptions;\n\treadonly registry: { readonly kind: string; readonly url: string };\n\treadonly toolVersion: string;\n\treadonly sizes: ReadonlyMap<string, number>;\n\treadonly createdAt?: Date | undefined;\n}): BundleManifest => {\n\tconst includedNames = new Set(input.included.map((pkg) => `${pkg.name}@${pkg.version}`));\n\n\tconst packages: ReadonlyArray<ManifestEntry> = input.included.map((pkg) => {\n\t\tconst key = `${pkg.name}@${pkg.version}`;\n\t\treturn {\n\t\t\tname: pkg.name,\n\t\t\tversion: pkg.version,\n\t\t\tpath: bundlePath(input.options.layout, pkg.name, pkg.version),\n\t\t\ttarball: pkg.manifest.dist.tarball,\n\t\t\tintegrity: pkg.manifest.dist.integrity,\n\t\t\tshasum: pkg.manifest.dist.shasum,\n\t\t\tbytes: input.sizes.get(key),\n\t\t\treasons: formatReasons(pkg),\n\t\t};\n\t});\n\n\tconst totalBytes = packages.reduce((sum, entry) => sum + (entry.bytes ?? 0), 0);\n\n\treturn {\n\t\tmanifestVersion: MANIFEST_VERSION,\n\t\ttool: { name: \"packall\", version: input.toolVersion },\n\t\tcreatedAt: (input.createdAt ?? new Date()).toISOString(),\n\t\tregistry: input.registry,\n\t\trequested: input.resolution.roots.map((root) => formatSpec(root.spec)),\n\t\troots: input.resolution.roots.map((root) => ({\n\t\t\tspec: formatSpec(root.spec),\n\t\t\tversions: root.versions,\n\t\t\tpackageCount: root.closure.filter((key) => includedNames.has(key)).length,\n\t\t})),\n\t\toptions: {\n\t\t\tlayout: input.options.layout,\n\t\t\toptionalDependencies: input.options.scope.optional,\n\t\t\tpeerDependencies: input.options.scope.peer,\n\t\t\tplatforms: formatPlatformFilter(input.options.scope.platforms),\n\t\t\tallVersions: input.options.allVersions,\n\t\t\tincludePrerelease: input.options.includePrerelease,\n\t\t\tintegrityVerified: input.options.verifyIntegrity,\n\t\t},\n\t\tpackages,\n\t\twarnings: input.resolution.warnings.map((warning) =>\n\t\t\twarning.from === undefined ? warning.message : `${warning.from}: ${warning.message}`,\n\t\t),\n\t\ttotals: {\n\t\t\tpackages: packages.length,\n\t\t\tbytes: totalBytes,\n\t\t},\n\t};\n};\n\n/** Serialises a manifest with stable key order and a trailing newline. */\nexport const serializeManifest = (manifest: BundleManifest): string =>\n\t`${JSON.stringify(manifest, null, 2)}\\n`;\n","/**\n * Version selection and the dependency closure walk.\n *\n * This is the part that decides *what* ends up in a bundle. Its only side\n * effect is asking the `Registry` service for metadata, which makes the whole\n * of it testable against a fake registry with no network at all.\n *\n * The walk is breadth-first in waves: resolve the current frontier\n * concurrently, collect the newly discovered edges, repeat. Wave-based BFS\n * gives real parallelism without a dynamic worker pool, and because each wave\n * merges its results serially there is no shared mutable state being written\n * from more than one fiber.\n *\n * One subtlety worth calling out: metadata is cached across walks, but each\n * walk still traverses the full graph. That is what lets `per-spec` layout ask\n * \"what does *this* root version depend on\" many times over while the network\n * is touched exactly once per package.\n */\nimport * as Effect from \"effect/Effect\";\nimport semver from \"semver\";\n\nimport { parseDependencyTarget } from \"./dependency-range.js\";\nimport { EdgeKind } from \"./enums/edge-kind.js\";\nimport { Phase } from \"./enums/phase.js\";\nimport type { BundlerError } from \"./errors.js\";\nimport { NoMatchingVersionsError, VersionNotFoundError } from \"./errors.js\";\nimport type { ResolveOptions } from \"./options.js\";\nimport { isIncluded } from \"./platform.js\";\nimport * as Progress from \"./progress.js\";\nimport type { PackageManifest, Packument } from \"./registry.js\";\nimport { Registry } from \"./registry.js\";\nimport type { PackageSpec, Selector } from \"./spec.js\";\nimport { formatSelector, formatSpec } from \"./spec.js\";\n\n/** A single justification for including a package. */\nexport type Reason =\n\t| { readonly _tag: \"Root\"; readonly spec: string }\n\t| { readonly _tag: \"Edge\"; readonly from: string; readonly kind: EdgeKind };\n\n/** `name@version` — the identity of a resolved package throughout the engine. */\nexport type PackageKey = string;\n\n/** One package, pinned to one version, with every reason it was pulled in. */\nexport type ResolvedPackage = {\n\treadonly name: string;\n\treadonly version: string;\n\treadonly manifest: PackageManifest;\n\treadonly reasons: ReadonlyArray<Reason>;\n};\n\n/** Something we could not include, reported rather than thrown. */\nexport type ResolutionWarning = {\n\treadonly message: string;\n\t/** `name@version` of the package whose manifest contained the problem. */\n\treadonly from?: string | undefined;\n};\n\n/** What one requested spec expanded to. */\nexport type RootResolution = {\n\treadonly spec: PackageSpec;\n\t/** The concrete versions the spec selected — more than one under `--all-versions`. */\n\treadonly versions: ReadonlyArray<string>;\n\t/** Closure per selected version, keyed by version. Drives `per-spec` layout. */\n\treadonly closures: ReadonlyMap<string, ReadonlyArray<PackageKey>>;\n\t/** Union of every per-version closure. */\n\treadonly closure: ReadonlyArray<PackageKey>;\n};\n\n/** The complete result of resolving every requested spec. */\nexport type Resolution = {\n\treadonly roots: ReadonlyArray<RootResolution>;\n\t/** The deduplicated union of every closure, sorted by name then version. */\n\treadonly packages: ReadonlyArray<ResolvedPackage>;\n\treadonly warnings: ReadonlyArray<ResolutionWarning>;\n};\n\n/** One pending item on the BFS frontier. */\nexport type Task = {\n\treadonly name: string;\n\treadonly selector: Selector;\n\treadonly reason: Reason;\n\t/** Optional edges tolerate resolution failure; required ones do not. */\n\treadonly tolerateFailure: boolean;\n};\n\nexport const packageKey = (name: string, version: string): PackageKey => `${name}@${version}`;\n\n/** Index of a resolution by `name@version`, for lookups during bundling. */\nexport const indexPackages = (resolution: Resolution): ReadonlyMap<PackageKey, ResolvedPackage> =>\n\tnew Map(resolution.packages.map((pkg) => [packageKey(pkg.name, pkg.version), pkg]));\n\n/* -------------------------------------------------------------------------- */\n/* Version selection */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Turns a selector into the concrete version(s) it names.\n *\n * `all` controls whether a range collapses to its best match — npm's behaviour,\n * and what you always want for a transitive dependency — or expands to every\n * satisfying published version, which is what `--all-versions` is for.\n */\nexport const selectVersions = (\n\tpackument: Packument,\n\tselector: Selector,\n\toptions: {\n\t\treadonly all: boolean;\n\t\treadonly maxVersions?: number | undefined;\n\t\treadonly includePrerelease: boolean;\n\t},\n): ReadonlyArray<string> => {\n\tconst available = Object.keys(packument.versions);\n\n\tswitch (selector._tag) {\n\t\tcase \"Exact\": {\n\t\t\tif (!Object.hasOwn(packument.versions, selector.version)) {\n\t\t\t\tthrow new VersionNotFoundError(\n\t\t\t\t\tpackument.name,\n\t\t\t\t\tselector.version,\n\t\t\t\t\tsortVersions(available),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [selector.version];\n\t\t}\n\n\t\tcase \"Tag\": {\n\t\t\tconst version = packument.distTags[selector.tag];\n\t\t\tif (version === undefined || !Object.hasOwn(packument.versions, version)) {\n\t\t\t\tthrow new NoMatchingVersionsError(\n\t\t\t\t\tpackument.name,\n\t\t\t\t\tselector.tag,\n\t\t\t\t\tsortVersions(available),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [version];\n\t\t}\n\n\t\tcase \"Range\": {\n\t\t\tconst satisfying = available\n\t\t\t\t.filter((version) =>\n\t\t\t\t\tsemver.satisfies(version, selector.range, {\n\t\t\t\t\t\tloose: true,\n\t\t\t\t\t\tincludePrerelease: options.includePrerelease,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.toSorted(semver.rcompare);\n\n\t\t\tconst [best] = satisfying;\n\t\t\tif (best === undefined) {\n\t\t\t\tthrow new NoMatchingVersionsError(\n\t\t\t\t\tpackument.name,\n\t\t\t\t\tselector.range,\n\t\t\t\t\tsortVersions(available),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!options.all) return [best];\n\n\t\t\treturn options.maxVersions !== undefined && options.maxVersions > 0\n\t\t\t\t? satisfying.slice(0, options.maxVersions)\n\t\t\t\t: satisfying;\n\t\t}\n\t}\n};\n\nconst sortVersions = (versions: ReadonlyArray<string>): ReadonlyArray<string> =>\n\tversions.toSorted((a, b) =>\n\t\tsemver.valid(a) && semver.valid(b) ? semver.compare(a, b) : a.localeCompare(b),\n\t);\n\n/* -------------------------------------------------------------------------- */\n/* Walk state */\n/* -------------------------------------------------------------------------- */\n\n/**\n * State shared across every walk in a run.\n *\n * Caching packuments and expanded edges here is what makes repeated walks\n * cheap: the second walk over `react@18.2.0` costs no network at all.\n */\ntype WalkState = {\n\treadonly resolved: Map<PackageKey, ResolvedPackage>;\n\treadonly edges: Map<PackageKey, ReadonlyArray<Task>>;\n\treadonly packuments: Map<string, Packument>;\n\treadonly warnings: Array<ResolutionWarning>;\n\t/** Warnings are deduplicated — the same skipped edge appears in many walks. */\n\treadonly warningKeys: Set<string>;\n};\n\nconst makeWalkState = (): WalkState => ({\n\tresolved: new Map(),\n\tedges: new Map(),\n\tpackuments: new Map(),\n\twarnings: [],\n\twarningKeys: new Set(),\n});\n\nconst addWarning = (state: WalkState, warning: ResolutionWarning): void => {\n\tconst key = `${warning.from ?? \"\"}|${warning.message}`;\n\tif (state.warningKeys.has(key)) return;\n\tstate.warningKeys.add(key);\n\tstate.warnings.push(warning);\n};\n\n/**\n * Fetches a packument, reusing anything already seen in this run.\n *\n * Two fibers in the same wave can race here and both fetch. That is one\n * duplicated GET at worst, and de-racing it would cost more complexity than it\n * saves.\n */\nconst getPackument = (\n\tstate: WalkState,\n\tname: string,\n): Effect.Effect<Packument, BundlerError, Registry> =>\n\tEffect.gen(function* () {\n\t\tconst cached = state.packuments.get(name);\n\t\tif (cached !== undefined) return cached;\n\t\tconst registry = yield* Registry;\n\t\tconst packument = yield* registry.packument(name);\n\t\tstate.packuments.set(name, packument);\n\t\treturn packument;\n\t});\n\n/**\n * Re-fails a thrown selection error into the Effect error channel.\n *\n * `selectVersions` throws `BundlerError` subclasses and nothing else, so this\n * narrows rather than casting; anything unexpected is rethrown as a defect,\n * which is what an unexpected exception actually is.\n */\nconst asBundlerError = (error: unknown): BundlerError => {\n\tif (error instanceof VersionNotFoundError || error instanceof NoMatchingVersionsError) {\n\t\treturn error;\n\t}\n\tthrow error;\n};\n\n/* -------------------------------------------------------------------------- */\n/* Edge expansion */\n/* -------------------------------------------------------------------------- */\n\n/** Expands one resolved manifest into the edges that follow from it. */\nexport const edgesOf = (\n\tmanifest: PackageManifest,\n\toptions: ResolveOptions,\n): {\n\treadonly tasks: ReadonlyArray<Task>;\n\treadonly warnings: ReadonlyArray<ResolutionWarning>;\n} => {\n\tconst from = packageKey(manifest.name, manifest.version);\n\tconst tasks: Array<Task> = [];\n\tconst warnings: Array<ResolutionWarning> = [];\n\n\tconst add = (\n\t\tentries: Readonly<Record<string, string>> | undefined,\n\t\tkind: EdgeKind,\n\t\ttolerateFailure: boolean,\n\t\tskip?: (name: string) => boolean,\n\t): void => {\n\t\tif (entries === undefined) return;\n\t\tfor (const [name, raw] of Object.entries(entries)) {\n\t\t\tif (skip?.(name)) continue;\n\t\t\tconst target = parseDependencyTarget(name, raw);\n\t\t\tif (target._tag === \"Unsupported\") {\n\t\t\t\twarnings.push({\n\t\t\t\t\tfrom,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Skipped ${name}@${target.raw} (${target.reason}) — it cannot be fetched from a ` +\n\t\t\t\t\t\t`registry. Vendor it separately if the offline install needs it.`,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttasks.push({\n\t\t\t\tname: target.name,\n\t\t\t\tselector: target.selector,\n\t\t\t\treason: { _tag: \"Edge\", from, kind },\n\t\t\t\ttolerateFailure,\n\t\t\t});\n\t\t}\n\t};\n\n\t// Runtime dependencies are non-negotiable.\n\tadd(manifest.dependencies, EdgeKind.Prod, false);\n\n\t// Optional dependencies are allowed to be missing — npm tolerates a 404 here\n\t// and so must we, or one unpublished platform package fails the whole run.\n\tif (options.scope.optional) {\n\t\tadd(manifest.optionalDependencies, EdgeKind.Optional, true);\n\t}\n\n\tif (options.scope.peer) {\n\t\tconst meta = manifest.peerDependenciesMeta ?? {};\n\t\tadd(\n\t\t\tmanifest.peerDependencies,\n\t\t\tEdgeKind.Peer,\n\t\t\tfalse,\n\t\t\t(name) => meta[name]?.optional === true,\n\t\t);\n\t}\n\n\treturn { tasks, warnings };\n};\n\n/** Edges for a package, computed once and cached. */\nconst edgesFor = (\n\tstate: WalkState,\n\tmanifest: PackageManifest,\n\toptions: ResolveOptions,\n): ReadonlyArray<Task> => {\n\tconst key = packageKey(manifest.name, manifest.version);\n\tconst cached = state.edges.get(key);\n\tif (cached !== undefined) return cached;\n\n\tconst { tasks, warnings } = edgesOf(manifest, options);\n\tfor (const warning of warnings) addWarning(state, warning);\n\tstate.edges.set(key, tasks);\n\treturn tasks;\n};\n\n/* -------------------------------------------------------------------------- */\n/* The walk */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Resolves everything reachable from `seeds`, returning the closure.\n *\n * `state` is mutated with newly resolved packages and warnings; the returned\n * array is scoped to *this* walk, which is what makes per-root-version\n * closures possible.\n */\nconst walk = (\n\tstate: WalkState,\n\tseeds: ReadonlyArray<Task>,\n\toptions: ResolveOptions,\n): Effect.Effect<ReadonlyArray<PackageKey>, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tconst discovered = new Set<PackageKey>();\n\t\t// Guards against re-resolving the same (name, selector) pair. Large trees\n\t\t// ask for `tslib@^2` hundreds of times, and this is also what terminates\n\t\t// dependency cycles.\n\t\tconst attempted = new Set<string>();\n\t\tlet frontier: ReadonlyArray<Task> = seeds;\n\n\t\twhile (frontier.length > 0) {\n\t\t\tconst wave: Array<Task> = [];\n\t\t\tfor (const task of frontier) {\n\t\t\t\tconst id = `${task.name} ${formatSelector(task.selector)}`;\n\t\t\t\tif (attempted.has(id)) continue;\n\t\t\t\tattempted.add(id);\n\t\t\t\twave.push(task);\n\t\t\t}\n\t\t\tif (wave.length === 0) break;\n\n\t\t\tconst results = yield* Effect.forEach(\n\t\t\t\twave,\n\t\t\t\t(task) => resolveTask(state, task, options),\n\t\t\t\t{ concurrency: options.concurrency },\n\t\t\t);\n\n\t\t\tconst next: Array<Task> = [];\n\n\t\t\t// Merged serially: every mutation of `state` happens on one fiber.\n\t\t\tfor (const result of results) {\n\t\t\t\tif (result === null) continue;\n\n\t\t\t\tfor (const { manifest, reason } of result) {\n\t\t\t\t\tconst key = packageKey(manifest.name, manifest.version);\n\t\t\t\t\tconst existing = state.resolved.get(key);\n\n\t\t\t\t\tif (existing === undefined) {\n\t\t\t\t\t\tstate.resolved.set(key, {\n\t\t\t\t\t\t\tname: manifest.name,\n\t\t\t\t\t\t\tversion: manifest.version,\n\t\t\t\t\t\t\tmanifest,\n\t\t\t\t\t\t\treasons: [reason],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t\t\t_tag: \"PackageResolved\",\n\t\t\t\t\t\t\tname: manifest.name,\n\t\t\t\t\t\t\tversion: manifest.version,\n\t\t\t\t\t\t\tresolvedCount: state.resolved.size,\n\t\t\t\t\t\t\tpendingCount: next.length,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (manifest.deprecated !== undefined && manifest.deprecated !== \"\") {\n\t\t\t\t\t\t\taddWarning(state, {\n\t\t\t\t\t\t\t\tfrom: key,\n\t\t\t\t\t\t\t\tmessage: `${key} is deprecated: ${manifest.deprecated}`,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!hasReason(existing.reasons, reason)) {\n\t\t\t\t\t\tstate.resolved.set(key, {\n\t\t\t\t\t\t\t...existing,\n\t\t\t\t\t\t\treasons: [...existing.reasons, reason],\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// Expand regardless of whether the package is new. A package resolved\n\t\t\t\t\t// during an earlier walk still has to contribute its subtree to\n\t\t\t\t\t// *this* walk's closure; `attempted` stops that from looping.\n\t\t\t\t\tif (!discovered.has(key)) {\n\t\t\t\t\t\tdiscovered.add(key);\n\t\t\t\t\t\tnext.push(...edgesFor(state, manifest, options));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfrontier = next;\n\t\t}\n\n\t\treturn [...discovered];\n\t});\n\nconst hasReason = (reasons: ReadonlyArray<Reason>, candidate: Reason): boolean =>\n\treasons.some((reason) => {\n\t\tif (reason._tag === \"Root\" && candidate._tag === \"Root\")\n\t\t\treturn reason.spec === candidate.spec;\n\t\tif (reason._tag === \"Edge\" && candidate._tag === \"Edge\") {\n\t\t\treturn reason.from === candidate.from && reason.kind === candidate.kind;\n\t\t}\n\t\treturn false;\n\t});\n\n/**\n * Resolves one task to its manifest(s).\n *\n * Returns `null` when an optional edge could not be resolved — the caller\n * treats that as \"skip quietly\", which is what npm does for\n * `optionalDependencies`.\n */\nconst resolveTask = (\n\tstate: WalkState,\n\ttask: Task,\n\toptions: ResolveOptions,\n): Effect.Effect<\n\tReadonlyArray<{ readonly manifest: PackageManifest; readonly reason: Reason }> | null,\n\tBundlerError,\n\tRegistry\n> =>\n\tEffect.gen(function* () {\n\t\tconst packument = yield* getPackument(state, task.name);\n\n\t\t// Transitive edges always collapse to a single best match; only root specs\n\t\t// ever fan out, and those arrive here already pinned to an exact version.\n\t\tconst versions = yield* Effect.try({\n\t\t\ttry: () =>\n\t\t\t\tselectVersions(packument, task.selector, {\n\t\t\t\t\tall: false,\n\t\t\t\t\tincludePrerelease: options.includePrerelease,\n\t\t\t\t}),\n\t\t\tcatch: asBundlerError,\n\t\t});\n\n\t\treturn versions.flatMap((version) => {\n\t\t\tconst manifest = packument.versions[version];\n\t\t\tif (manifest === undefined) return [];\n\n\t\t\t// Platform narrowing only ever applies to optional edges. Filtering a\n\t\t\t// required dependency by platform would produce a bundle that cannot\n\t\t\t// install anywhere.\n\t\t\tif (\n\t\t\t\ttask.reason._tag === \"Edge\" &&\n\t\t\t\ttask.reason.kind === EdgeKind.Optional &&\n\t\t\t\t!isIncluded(manifest, options.scope.platforms)\n\t\t\t) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn { manifest, reason: task.reason };\n\t\t});\n\t}).pipe(\n\t\tEffect.catch((error) => {\n\t\t\t// A required edge that cannot be resolved is fatal. An optional one is\n\t\t\t// recorded and skipped, matching how npm treats `optionalDependencies`.\n\t\t\tif (!task.tolerateFailure) return Effect.fail(error);\n\t\t\treturn Effect.sync(() => {\n\t\t\t\taddWarning(state, {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Optional dependency ${task.name}@${formatSelector(task.selector)} could not be ` +\n\t\t\t\t\t\t`resolved and was skipped: ${error.message}`,\n\t\t\t\t});\n\t\t\t\treturn null;\n\t\t\t});\n\t\t}),\n\t);\n\n/* -------------------------------------------------------------------------- */\n/* Entry point */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Resolves every requested spec.\n *\n * Each selected root *version* is walked separately so `per-spec` layout has an\n * exact closure per tarball, while all walks share one cache, so a package\n * reached from twenty roots is fetched once.\n */\nexport const resolve = (\n\tspecs: ReadonlyArray<PackageSpec>,\n\toptions: ResolveOptions,\n): Effect.Effect<Resolution, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Resolve, total: specs.length });\n\n\t\tconst state = makeWalkState();\n\t\tconst roots: Array<RootResolution> = [];\n\n\t\tfor (const spec of specs) {\n\t\t\tconst packument = yield* getPackument(state, spec.name);\n\n\t\t\tconst versions = yield* Effect.try({\n\t\t\t\ttry: () =>\n\t\t\t\t\tselectVersions(packument, spec.selector, {\n\t\t\t\t\t\tall: options.allVersions,\n\t\t\t\t\t\tmaxVersions: options.maxVersions,\n\t\t\t\t\t\tincludePrerelease: options.includePrerelease,\n\t\t\t\t\t}),\n\t\t\t\tcatch: asBundlerError,\n\t\t\t});\n\n\t\t\tconst closures = new Map<string, ReadonlyArray<PackageKey>>();\n\t\t\tconst union = new Set<PackageKey>();\n\n\t\t\tfor (const version of versions) {\n\t\t\t\tconst closure = yield* walk(\n\t\t\t\t\tstate,\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: spec.name,\n\t\t\t\t\t\t\tselector: { _tag: \"Exact\", version },\n\t\t\t\t\t\t\treason: { _tag: \"Root\", spec: formatSpec(spec) },\n\t\t\t\t\t\t\ttolerateFailure: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\toptions,\n\t\t\t\t);\n\t\t\t\tclosures.set(version, closure);\n\t\t\t\tfor (const key of closure) union.add(key);\n\t\t\t}\n\n\t\t\troots.push({ spec, versions, closures, closure: [...union] });\n\t\t}\n\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Resolve });\n\n\t\treturn {\n\t\t\troots,\n\t\t\tpackages: [...state.resolved.values()].toSorted(compareResolved),\n\t\t\twarnings: state.warnings,\n\t\t};\n\t});\n\nconst compareResolved = (a: ResolvedPackage, b: ResolvedPackage): number => {\n\tif (a.name !== b.name) return a.name < b.name ? -1 : 1;\n\treturn semver.valid(a.version) && semver.valid(b.version)\n\t\t? semver.compare(a.version, b.version)\n\t\t: a.version.localeCompare(b.version);\n};\n","/**\n * Resolution driven by a lockfile instead of by semver.\n *\n * The distinction matters more than it first looks. Feeding a lockfile's\n * versions in as exact root specs and letting the ordinary walk run would still\n * produce the wrong bundle: every *transitive* edge is a range, and\n * `Resolve.walk` answers a range with whatever is newest today. Lock `tslib` at\n * 2.6.0 and let something depending on `tslib@^2` be re-resolved, and the\n * bundle grows a second copy at 2.8.1 that CI never installed.\n *\n * So the lockfile is treated as the graph, not as a set of hints. The package\n * set *is* what the file pins, and every edge is satisfied from inside it.\n * Nothing here calls `selectVersions`; the only thing the registry is asked for\n * is the metadata that a lockfile does not record — `dist`, and the `os`/`cpu`\n * constraints that `--platform` narrows on.\n *\n * The result is an ordinary `Resolution`, so layout, archiving, the manifest\n * and the summary cannot tell which path produced it.\n */\nimport * as Effect from \"effect/Effect\";\nimport semver from \"semver\";\n\nimport type { EdgeKind } from \"./enums/edge-kind.js\";\nimport { LockedRootKind } from \"./enums/edge-kind.js\";\nimport { Phase } from \"./enums/phase.js\";\nimport type { BundlerError } from \"./errors.js\";\nimport { LockfileIncompleteError, LockfileOutOfDateError } from \"./errors.js\";\nimport type { LockedRoot, LockedTree } from \"./lockfile/types.js\";\nimport type { ResolveOptions } from \"./options.js\";\nimport { isIncluded } from \"./platform.js\";\nimport * as Progress from \"./progress.js\";\nimport type { PackageManifest } from \"./registry.js\";\nimport { Registry } from \"./registry.js\";\nimport type {\n\tPackageKey,\n\tReason,\n\tResolution,\n\tResolutionWarning,\n\tResolvedPackage,\n\tRootResolution,\n} from \"./resolve.js\";\nimport { packageKey } from \"./resolve.js\";\nimport type { PackageSpec } from \"./spec.js\";\nimport { formatSpec } from \"./spec.js\";\n\n/** Options for a lockfile-pinned resolution. */\nexport type LockedResolveOptions = ResolveOptions & {\n\t/**\n\t * Include the project's `devDependencies`.\n\t *\n\t * Matches `--file package.json`: on by default, because a project without its\n\t * dev tooling does not build behind the firewall either.\n\t */\n\treadonly includeDev: boolean;\n\t/**\n\t * Direct dependency names declared by the accompanying package.json.\n\t *\n\t * When present, anything declared there but absent from the lockfile's roots\n\t * means the two have drifted — which is exactly the silent-mismatch case this\n\t * whole feature exists to catch, so it is reported rather than papered over.\n\t */\n\treadonly declared?: ReadonlyArray<string> | undefined;\n};\n\n/** Turns a parsed lockfile into a resolution, pinning every version. */\nexport const resolveLocked = (\n\tlock: LockedTree,\n\toptions: LockedResolveOptions,\n): Effect.Effect<Resolution, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tconst roots = selectRoots(lock, options);\n\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Resolve, total: roots.length });\n\n\t\tconst gap = findGaps(lock, roots, options.declared);\n\t\tif (gap !== null) return yield* Effect.fail(gap);\n\n\t\t// Everything the lockfile can reach, before the platform filter has had a\n\t\t// say. Cheap — no network at all — and it is what decides the fetch list.\n\t\tconst reachable = reachableKeys(lock, roots, options);\n\t\tconst manifests = yield* fetchManifests(lock, reachable, options);\n\n\t\tconst warnings: Array<ResolutionWarning> = lock.warnings.map((message) => ({ message }));\n\t\tconst resolved = new Map<PackageKey, ResolvedPackage>();\n\t\tconst seenWarnings = new Set<string>();\n\n\t\tconst addWarning = (warning: ResolutionWarning): void => {\n\t\t\tconst key = `${warning.from ?? \"\"}|${warning.message}`;\n\t\t\tif (seenWarnings.has(key)) return;\n\t\t\tseenWarnings.add(key);\n\t\t\twarnings.push(warning);\n\t\t};\n\n\t\tconst rootResolutions: Array<RootResolution> = [];\n\n\t\tfor (const root of roots) {\n\t\t\tconst key = packageKey(root.name, root.version);\n\t\t\tif (!manifests.has(key)) continue;\n\n\t\t\tconst spec: PackageSpec = {\n\t\t\t\tname: root.name,\n\t\t\t\tselector: { _tag: \"Exact\", version: root.version },\n\t\t\t\traw: `${root.name}@${root.version}`,\n\t\t\t};\n\n\t\t\t// Platform narrowing applies to optional roots for the same reason it\n\t\t\t// applies to optional edges: a native binding for another OS is exactly\n\t\t\t// what --platform is there to drop.\n\t\t\tif (root.kind === LockedRootKind.Optional && !platformAllows(manifests, key, options))\n\t\t\t\tcontinue;\n\n\t\t\tconst closure = walkLocked({\n\t\t\t\tlock,\n\t\t\t\tmanifests,\n\t\t\t\toptions,\n\t\t\t\tseed: key,\n\t\t\t\trootSpec: formatSpec(spec),\n\t\t\t\tresolved,\n\t\t\t\taddWarning,\n\t\t\t});\n\n\t\t\trootResolutions.push({\n\t\t\t\tspec,\n\t\t\t\tversions: [root.version],\n\t\t\t\tclosures: new Map([[root.version, closure]]),\n\t\t\t\tclosure,\n\t\t\t});\n\t\t}\n\n\t\tfor (const pkg of resolved.values()) {\n\t\t\tconst deprecated = pkg.manifest.deprecated;\n\t\t\tif (deprecated !== undefined && deprecated !== \"\") {\n\t\t\t\taddWarning({\n\t\t\t\t\tfrom: packageKey(pkg.name, pkg.version),\n\t\t\t\t\tmessage: `${packageKey(pkg.name, pkg.version)} is deprecated: ${deprecated}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Resolve });\n\n\t\treturn {\n\t\t\troots: rootResolutions,\n\t\t\tpackages: [...resolved.values()].toSorted(compareResolved),\n\t\t\twarnings,\n\t\t};\n\t});\n\n/* -------------------------------------------------------------------------- */\n/* Roots */\n/* -------------------------------------------------------------------------- */\n\n/** Which of the project's direct dependencies this run should bundle. */\nconst selectRoots = (lock: LockedTree, options: LockedResolveOptions): ReadonlyArray<LockedRoot> =>\n\tlock.roots\n\t\t.filter((root) => {\n\t\t\tif (root.kind === LockedRootKind.Dev) return options.includeDev;\n\t\t\tif (root.kind === LockedRootKind.Optional) return options.scope.optional;\n\t\t\tif (root.kind === LockedRootKind.Peer) return options.scope.peer;\n\t\t\treturn true;\n\t\t})\n\t\t// Sorted so the artifact order is a property of the dependency set rather\n\t\t// than of which manager wrote the file.\n\t\t.toSorted((a, b) => (a.name === b.name ? 0 : a.name < b.name ? -1 : 1));\n\n/**\n * The two ways a lockfile can be partial, checked before anything is fetched.\n *\n * Both mean the same thing to whoever is waiting on the bundle — a package they\n * expected will not be in it — and both are invisible unless something says so,\n * because the run otherwise succeeds and simply produces less.\n */\nconst findGaps = (\n\tlock: LockedTree,\n\troots: ReadonlyArray<LockedRoot>,\n\tdeclared: ReadonlyArray<string> | undefined,\n): LockfileIncompleteError | null => {\n\tconst remedy = `Run \\`${lock.format} install\\` to bring the lockfile up to date.`;\n\n\t// A dependency added to package.json without re-running the install. The\n\t// commonest way the two drift, and the cheapest to detect.\n\t//\n\t// Checked against everything the file pins rather than against its roots,\n\t// because the managers disagree about which blocks appear in the root entry —\n\t// pnpm's importers omit peers, npm's `packages[\"\"]` includes them — and a\n\t// package that is pinned somewhere will be in the bundle either way.\n\tif (declared !== undefined && declared.length > 0) {\n\t\tconst locked = new Set<string>();\n\t\tfor (const pkg of lock.packages.values()) locked.add(pkg.name);\n\t\tfor (const root of roots) locked.add(root.name);\n\n\t\tconst missing = declared.filter((name) => !locked.has(name));\n\t\tif (missing.length > 0) {\n\t\t\treturn new LockfileIncompleteError(\n\t\t\t\tlock.path,\n\t\t\t\tmissing,\n\t\t\t\t`the package.json declares ${missing.length} ` +\n\t\t\t\t\t`dependenc${missing.length === 1 ? \"y\" : \"ies\"} it does not pin`,\n\t\t\t\tremedy,\n\t\t\t);\n\t\t}\n\t}\n\n\t// A required edge inside the file pointing at nothing the file pins.\n\tif (lock.incomplete.length > 0) {\n\t\treturn new LockfileIncompleteError(\n\t\t\tlock.path,\n\t\t\tlock.incomplete,\n\t\t\t`${lock.incomplete.length} required ` +\n\t\t\t\t`dependenc${lock.incomplete.length === 1 ? \"y is\" : \"ies are\"} not pinned`,\n\t\t\tremedy,\n\t\t);\n\t}\n\n\treturn null;\n};\n\n/* -------------------------------------------------------------------------- */\n/* Reachability */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Every package the roots can reach through the locked edges.\n *\n * Scope filters apply here — `--no-optional` genuinely removes a subtree — but\n * the platform filter does not, because deciding it needs the `os`/`cpu` fields\n * that only the registry has.\n */\nconst reachableKeys = (\n\tlock: LockedTree,\n\troots: ReadonlyArray<LockedRoot>,\n\toptions: LockedResolveOptions,\n): ReadonlySet<PackageKey> => {\n\tconst seen = new Set<PackageKey>();\n\tconst queue = roots.map((root) => packageKey(root.name, root.version));\n\n\twhile (queue.length > 0) {\n\t\tconst key = queue.pop();\n\t\tif (key === undefined || seen.has(key)) continue;\n\t\tseen.add(key);\n\n\t\tfor (const edge of lock.packages.get(key)?.dependencies ?? []) {\n\t\t\tif (!followsEdge(edge.kind, options)) continue;\n\t\t\tqueue.push(packageKey(edge.name, edge.version));\n\t\t}\n\t}\n\n\treturn seen;\n};\n\nconst followsEdge = (kind: EdgeKind, options: LockedResolveOptions): boolean => {\n\tif (kind === LockedRootKind.Optional) return options.scope.optional;\n\tif (kind === LockedRootKind.Peer) return options.scope.peer;\n\treturn true;\n};\n\n/* -------------------------------------------------------------------------- */\n/* Metadata */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Fetches the published manifest for every pinned version.\n *\n * One packument per distinct *name*, not per version — a lockfile holding four\n * versions of `tslib` costs one request. Every pinned version that the registry\n * does not serve is collected and reported together, because \"refresh your\n * lockfile\" is a single action and finding out about the gaps one run at a time\n * would be miserable.\n */\nconst fetchManifests = (\n\tlock: LockedTree,\n\treachable: ReadonlySet<PackageKey>,\n\toptions: LockedResolveOptions,\n): Effect.Effect<\n\tReadonlyMap<PackageKey, PackageManifest>,\n\tBundlerError,\n\tRegistry | Progress.Progress\n> =>\n\tEffect.gen(function* () {\n\t\tconst registry = yield* Registry;\n\n\t\tconst wanted = new Map<string, Array<string>>();\n\t\tfor (const key of reachable) {\n\t\t\tconst pkg = lock.packages.get(key);\n\t\t\tif (pkg === undefined) continue;\n\t\t\tconst versions = wanted.get(pkg.name);\n\t\t\tif (versions === undefined) wanted.set(pkg.name, [pkg.version]);\n\t\t\telse versions.push(pkg.version);\n\t\t}\n\n\t\tconst manifests = new Map<PackageKey, PackageManifest>();\n\t\tconst missing: Array<{ name: string; version: string; detail: string }> = [];\n\n\t\tconst fetched = yield* Effect.forEach(\n\t\t\t[...wanted.entries()],\n\t\t\t([name, versions]) =>\n\t\t\t\tregistry.packument(name).pipe(\n\t\t\t\t\tEffect.map((packument) => ({ name, versions, packument })),\n\t\t\t\t\t// A package the registry has never heard of is the same problem as a\n\t\t\t\t\t// version it no longer serves, and belongs in the same report.\n\t\t\t\t\tEffect.catch((error) =>\n\t\t\t\t\t\terror._tag === \"PackageNotFoundError\"\n\t\t\t\t\t\t\t? Effect.succeed({ name, versions, packument: null })\n\t\t\t\t\t\t\t: Effect.fail(error),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t{ concurrency: options.concurrency },\n\t\t);\n\n\t\tfor (const { name, versions, packument } of fetched) {\n\t\t\tfor (const version of versions) {\n\t\t\t\tif (packument === null) {\n\t\t\t\t\tmissing.push({ name, version, detail: \"package not found\" });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst manifest = packument.versions[version];\n\t\t\t\tif (manifest === undefined) {\n\t\t\t\t\tmissing.push({\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t\tdetail: describeAvailable(Object.keys(packument.versions)),\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tmanifests.set(packageKey(name, version), manifest);\n\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t_tag: \"PackageResolved\",\n\t\t\t\t\tname,\n\t\t\t\t\tversion,\n\t\t\t\t\tresolvedCount: manifests.size,\n\t\t\t\t\tpendingCount: reachable.size - manifests.size,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (missing.length > 0) {\n\t\t\treturn yield* Effect.fail(\n\t\t\t\tnew LockfileOutOfDateError(\n\t\t\t\t\tlock.path,\n\t\t\t\t\tregistry.registryFor(missing[0]?.name ?? \"\"),\n\t\t\t\t\tmissing,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\treturn manifests;\n\t});\n\nconst describeAvailable = (available: ReadonlyArray<string>): string => {\n\tconst recent = available\n\t\t.toSorted((a, b) =>\n\t\t\tsemver.valid(a) && semver.valid(b) ? semver.compare(a, b) : a.localeCompare(b),\n\t\t)\n\t\t.slice(-3);\n\treturn recent.length === 0\n\t\t? \"no published versions\"\n\t\t: `no longer published (latest: ${recent.join(\", \")})`;\n};\n\n/* -------------------------------------------------------------------------- */\n/* The walk */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Collects one root's closure by following locked edges.\n *\n * Pure and synchronous — every manifest is already in hand — so a per-root\n * closure costs nothing beyond the traversal, which is what makes `per-spec`\n * layout as cheap here as it is for a range-resolved run.\n */\nconst walkLocked = (input: {\n\treadonly lock: LockedTree;\n\treadonly manifests: ReadonlyMap<PackageKey, PackageManifest>;\n\treadonly options: LockedResolveOptions;\n\treadonly seed: PackageKey;\n\treadonly rootSpec: string;\n\treadonly resolved: Map<PackageKey, ResolvedPackage>;\n\treadonly addWarning: (warning: ResolutionWarning) => void;\n}): ReadonlyArray<PackageKey> => {\n\tconst closure = new Set<PackageKey>();\n\tconst queue: Array<{ key: PackageKey; reason: Reason }> = [\n\t\t{ key: input.seed, reason: { _tag: \"Root\", spec: input.rootSpec } },\n\t];\n\n\twhile (queue.length > 0) {\n\t\tconst next = queue.pop();\n\t\tif (next === undefined) continue;\n\n\t\tconst manifest = input.manifests.get(next.key);\n\t\tconst locked = input.lock.packages.get(next.key);\n\t\tif (manifest === undefined || locked === undefined) continue;\n\n\t\trecord(input.resolved, next.key, manifest, locked, next.reason);\n\n\t\tif (closure.has(next.key)) continue;\n\t\tclosure.add(next.key);\n\n\t\tfor (const edge of locked.dependencies) {\n\t\t\tif (!followsEdge(edge.kind, input.options)) continue;\n\n\t\t\tconst target = packageKey(edge.name, edge.version);\n\t\t\tif (!input.manifests.has(target)) continue;\n\n\t\t\tif (\n\t\t\t\tedge.kind === LockedRootKind.Optional &&\n\t\t\t\t!platformAllows(input.manifests, target, input.options)\n\t\t\t) {\n\t\t\t\tinput.addWarning({\n\t\t\t\t\tfrom: next.key,\n\t\t\t\t\tmessage: `Skipped optional ${target} — it does not build for the selected platforms.`,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tqueue.push({ key: target, reason: { _tag: \"Edge\", from: next.key, kind: edge.kind } });\n\t\t}\n\t}\n\n\treturn [...closure];\n};\n\n/** Adds a package, or merges one more justification into an existing entry. */\nconst record = (\n\tresolved: Map<PackageKey, ResolvedPackage>,\n\tkey: PackageKey,\n\tmanifest: PackageManifest,\n\tlocked: { readonly name: string; readonly version: string },\n\treason: Reason,\n): void => {\n\tconst existing = resolved.get(key);\n\tif (existing === undefined) {\n\t\tresolved.set(key, {\n\t\t\tname: locked.name,\n\t\t\tversion: locked.version,\n\t\t\tmanifest,\n\t\t\treasons: [reason],\n\t\t});\n\t\treturn;\n\t}\n\tif (hasReason(existing.reasons, reason)) return;\n\tresolved.set(key, { ...existing, reasons: [...existing.reasons, reason] });\n};\n\nconst hasReason = (reasons: ReadonlyArray<Reason>, candidate: Reason): boolean =>\n\treasons.some((reason) => {\n\t\tif (reason._tag === \"Root\" && candidate._tag === \"Root\")\n\t\t\treturn reason.spec === candidate.spec;\n\t\tif (reason._tag === \"Edge\" && candidate._tag === \"Edge\") {\n\t\t\treturn reason.from === candidate.from && reason.kind === candidate.kind;\n\t\t}\n\t\treturn false;\n\t});\n\nconst platformAllows = (\n\tmanifests: ReadonlyMap<PackageKey, PackageManifest>,\n\tkey: PackageKey,\n\toptions: LockedResolveOptions,\n): boolean => {\n\tconst manifest = manifests.get(key);\n\tif (manifest === undefined) return false;\n\treturn isIncluded(manifest, options.scope.platforms);\n};\n\nconst compareResolved = (a: ResolvedPackage, b: ResolvedPackage): number => {\n\tif (a.name !== b.name) return a.name < b.name ? -1 : 1;\n\treturn semver.valid(a.version) && semver.valid(b.version)\n\t\t? semver.compare(a.version, b.version)\n\t\t: a.version.localeCompare(b.version);\n};\n","/**\n * Narrowing helpers for the untyped JSON and YAML a lockfile parses into.\n *\n * Everything here takes `unknown` and hands back something narrowed, which is\n * what keeps the parsers free of casts against files nobody controls. The\n * shape-level narrowing is Effect Schema — the same decoders the registry\n * response boundary uses — so \"tolerated\" means one thing across the codebase\n * rather than being re-decided per parser.\n */\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\n\nimport { LockfileError } from \"../errors.js\";\nimport { OptionalFlagRecordSchema, StringRecordSchema } from \"../schemas/lenient.js\";\nimport { isRecord } from \"../utils/is-record.js\";\n\nexport const stringOr = (value: unknown, fallback: string): string =>\n\ttypeof value === \"string\" ? value : fallback;\n\nconst decodeStringRecord = Schema.decodeUnknownOption(StringRecordSchema);\n\n/** Keeps only the string-valued members of an untyped object. */\nexport const stringRecord = (value: unknown): Readonly<Record<string, string>> =>\n\tOption.getOrElse(decodeStringRecord(value), (): Record<string, string> => ({}));\n\nconst decodeOptionalFlags = Schema.decodeUnknownOption(OptionalFlagRecordSchema);\n\n/** Names a package marked its peers optional with. */\nexport const optionalPeerNames = (value: unknown): ReadonlySet<string> => {\n\tconst flags = Option.getOrElse(\n\t\tdecodeOptionalFlags(value),\n\t\t(): Record<string, { readonly optional: boolean }> => ({}),\n\t);\n\treturn new Set(Object.entries(flags).flatMap(([name, meta]) => (meta.optional ? name : [])));\n};\n\nexport const parseJsonObject = (path: string, content: string): Record<string, unknown> => {\n\tconst parsed = tryParseJsonc(content);\n\tif (parsed === undefined) {\n\t\tthrow new LockfileError(path, \"not valid JSON\");\n\t}\n\tif (!isRecord(parsed)) {\n\t\tthrow new LockfileError(path, \"top level is not an object\");\n\t}\n\treturn parsed;\n};\n\n/**\n * Parses JSON, tolerating the comments and trailing commas bun writes.\n *\n * `bun.lock` is JSONC by design — bun puts explanatory comments in it — so\n * plain `JSON.parse` rejects real lockfiles. Returns `undefined` rather than\n * throwing so detection can use it as a probe.\n */\nexport const tryParseJsonc = (content: string): unknown => {\n\ttry {\n\t\treturn JSON.parse(content);\n\t} catch {\n\t\ttry {\n\t\t\treturn JSON.parse(stripJsonc(content));\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n};\n\n/**\n * Removes comments and trailing commas.\n *\n * String-aware, because a `//` inside a tarball URL is not a comment and an\n * escaped quote does not end a string. Both appear in every real lockfile.\n */\nexport const stripJsonc = (content: string): string => {\n\tlet out = \"\";\n\tlet index = 0;\n\tlet inString = false;\n\n\twhile (index < content.length) {\n\t\tconst char = content[index];\n\n\t\tif (inString) {\n\t\t\tout += char;\n\t\t\tif (char === \"\\\\\") {\n\t\t\t\tout += content[index + 1] ?? \"\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === '\"') inString = false;\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === '\"') {\n\t\t\tinString = true;\n\t\t\tout += char;\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && content[index + 1] === \"/\") {\n\t\t\tconst end = content.indexOf(\"\\n\", index);\n\t\t\tindex = end === -1 ? content.length : end;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && content[index + 1] === \"*\") {\n\t\t\tconst end = content.indexOf(\"*/\", index + 2);\n\t\t\tindex = end === -1 ? content.length : end + 2;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// A comma is trailing when the next thing that is not whitespace closes the\n\t\t// structure it sits in.\n\t\tif (char === \",\") {\n\t\t\tconst next = content.slice(index + 1).search(/\\S/);\n\t\t\tconst following = next === -1 ? \"\" : content[index + 1 + next];\n\t\t\tif (following === \"}\" || following === \"]\") {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tout += char;\n\t\tindex += 1;\n\t}\n\n\treturn out;\n};\n\nexport const describeError = (error: unknown): string =>\n\terror instanceof Error ? error.message : String(error);\n","/**\n * Working out which lockfile — if any — some content is.\n *\n * Detection is by content, matching how `--file` treats everything else: a\n * lockfile renamed to `deps.txt` still parses, and a `package-lock.json` that\n * is actually a package.json still gets read as one.\n */\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { isRecord } from \"../utils/is-record.js\";\nimport { tryParseJsonc } from \"./json.js\";\n\n/** What a blob of file content turned out to be. */\nexport type LockfileDetection =\n\t| { readonly _tag: \"Supported\"; readonly format: LockfileFormat }\n\t/**\n\t * Recognisably a lockfile, but not one we can read. Named explicitly so the\n\t * error says \"yarn.lock is not supported yet\" rather than leaving somebody to\n\t * work out why their file parsed as a spec list.\n\t */\n\t| { readonly _tag: \"Unsupported\"; readonly label: string; readonly hint: string }\n\t| { readonly _tag: \"NotALockfile\" };\n\n/**\n * Deliberately cheap and total: it never throws, so `--file` can try this\n * first and fall through to its other shapes when the answer is `NotALockfile`.\n */\nexport const detectLockfile = (content: string): LockfileDetection => {\n\tconst trimmed = content.trimStart();\n\n\t// bun's binary lockfile leads with its own magic string. Worth naming,\n\t// because `bun install` wrote this by default until 1.2 and the fix is one\n\t// command.\n\tif (trimmed.startsWith(\"bun-lockfile-format-v0\")) {\n\t\treturn {\n\t\t\t_tag: \"Unsupported\",\n\t\t\tlabel: \"a binary bun lockfile (bun.lockb)\",\n\t\t\thint: \"Run `bun install --save-text-lockfile` to produce a bun.lock, and pass that instead.\",\n\t\t};\n\t}\n\n\tif (/^__metadata:/m.test(trimmed) || /^# yarn lockfile v\\d/m.test(trimmed)) {\n\t\treturn {\n\t\t\t_tag: \"Unsupported\",\n\t\t\tlabel: \"a yarn lockfile\",\n\t\t\thint: \"yarn is not supported yet. Point --file at the package.json instead, or pass --lockfile off.\",\n\t\t};\n\t}\n\n\tif (trimmed.startsWith(\"{\")) return detectJsonLockfile(trimmed);\n\n\t// pnpm is the only YAML one, and it always declares its version first.\n\tif (/^lockfileVersion:/m.test(trimmed) || /^(importers|snapshots):/m.test(trimmed)) {\n\t\treturn { _tag: \"Supported\", format: LockfileFormat.Pnpm };\n\t}\n\n\treturn { _tag: \"NotALockfile\" };\n};\n\n/**\n * Separates the two JSON lockfiles from each other and from a package.json.\n *\n * Both npm and bun write a numeric `lockfileVersion`, so that field alone\n * cannot decide it. bun is the one that carries a `workspaces` map keyed by the\n * empty string; npm keeps the root project under `packages[\"\"]` instead.\n */\nconst detectJsonLockfile = (trimmed: string): LockfileDetection => {\n\tconst parsed = tryParseJsonc(trimmed);\n\tif (!isRecord(parsed)) return { _tag: \"NotALockfile\" };\n\n\tconst workspaces = parsed[\"workspaces\"];\n\tif (isRecord(workspaces) && Object.hasOwn(workspaces, \"\")) {\n\t\treturn { _tag: \"Supported\", format: LockfileFormat.Bun };\n\t}\n\n\tif (typeof parsed[\"lockfileVersion\"] === \"number\") {\n\t\treturn { _tag: \"Supported\", format: LockfileFormat.Npm };\n\t}\n\n\treturn { _tag: \"NotALockfile\" };\n};\n","import { LockfileFormat } from \"../enums/lockfile-format.js\";\n\n/**\n * The file name each supported manager writes, in detection order.\n *\n * Ordered: `package-lock.json` before `npm-shrinkwrap.json` before pnpm's and\n * bun's, so a directory holding several is searched the way npm itself would.\n */\nexport const formatByLockfileName = {\n\t\"package-lock.json\": LockfileFormat.Npm,\n\t\"npm-shrinkwrap.json\": LockfileFormat.Npm,\n\t\"pnpm-lock.yaml\": LockfileFormat.Pnpm,\n\t\"bun.lock\": LockfileFormat.Bun,\n} as const satisfies Record<string, LockfileFormat>;\n\n/** The names a given manager writes. */\nexport const lockfileNamesFor = (format: LockfileFormat): ReadonlyArray<string> =>\n\tObject.entries(formatByLockfileName).flatMap(([name, candidate]) =>\n\t\tcandidate === format ? name : [],\n\t);\n","/**\n * The bookkeeping every lockfile parser shares.\n *\n * Packages, edges and skip warnings accumulate here while a parser walks a\n * file, which is what lets each parser stay focused on its own encoding.\n */\nimport semver from \"semver\";\n\nimport { parseDependencyTarget } from \"../dependency-range.js\";\nimport { LockedRootKind } from \"../enums/edge-kind.js\";\nimport type { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { LockfileError } from \"../errors.js\";\nimport { packageKey } from \"../resolve.js\";\nimport type { LockedEdge, LockedPackage, LockedRoot, LockedTree } from \"./types.js\";\n\n/**\n * Which manifest block each root kind is declared in.\n *\n * The block names are the same across npm, pnpm and bun; only which of them a\n * given format writes differs, which is why each parser supplies its own order\n * rather than iterating this.\n */\nexport const fieldByRootKind = {\n\t[LockedRootKind.Prod]: \"dependencies\",\n\t[LockedRootKind.Optional]: \"optionalDependencies\",\n\t[LockedRootKind.Dev]: \"devDependencies\",\n\t[LockedRootKind.Peer]: \"peerDependencies\",\n} as const satisfies Record<LockedRootKind, string>;\n\nexport class TreeBuilder {\n\treadonly packages = new Map<string, LockedPackage>();\n\treadonly roots: Array<LockedRoot> = [];\n\treadonly warnings: Array<string> = [];\n\treadonly incomplete: Array<string> = [];\n\t/** Names dropped on purpose, so an edge into one is explained, not alarming. */\n\tprivate readonly skipped = new Set<string>();\n\tprivate readonly seenWarnings = new Set<string>();\n\n\tadd(pkg: LockedPackage): void {\n\t\tconst key = packageKey(pkg.name, pkg.version);\n\t\tconst existing = this.packages.get(key);\n\t\tif (existing === undefined) {\n\t\t\tthis.packages.set(key, pkg);\n\t\t\treturn;\n\t\t}\n\t\t// The same package at the same version can appear at several paths in a\n\t\t// nested layout. They are the same bytes; merge the edge sets so a copy\n\t\t// recorded with fewer dependencies does not lose any.\n\t\tthis.packages.set(key, {\n\t\t\t...existing,\n\t\t\tdependencies: mergeEdges(existing.dependencies, pkg.dependencies),\n\t\t});\n\t}\n\n\taddRoot(root: LockedRoot): void {\n\t\tif (this.roots.some((existing) => existing.name === root.name)) return;\n\t\tthis.roots.push(root);\n\t}\n\n\twarn(message: string): void {\n\t\tif (this.seenWarnings.has(message)) return;\n\t\tthis.seenWarnings.add(message);\n\t\tthis.warnings.push(message);\n\t}\n\n\t/** Notes an entry that is real but cannot come from a registry. */\n\tskip(name: string, spec: string, reason: string): void {\n\t\tthis.skipped.add(name);\n\t\tthis.warn(`skipped ${name}@${spec} (${reason}) — not fetchable from a registry`);\n\t}\n\n\t/**\n\t * Records a required edge that resolved to nothing.\n\t *\n\t * An edge into something skipped on purpose is expected — you cannot bundle a\n\t * `workspace:` sibling from a registry — so it stays a warning. Anything else\n\t * means the file does not pin what it claims to.\n\t */\n\tdangling(from: string, name: string): void {\n\t\tif (this.skipped.has(name)) {\n\t\t\tthis.warn(`${from} requires ${name}, which is not fetchable from a registry`);\n\t\t\treturn;\n\t\t}\n\t\tthis.incomplete.push(`${name} (required by ${from})`);\n\t}\n\n\tfinish(input: {\n\t\treadonly format: LockfileFormat;\n\t\treadonly lockfileVersion: string;\n\t\treadonly path: string;\n\t\treadonly importer?: string | undefined;\n\t}): LockedTree {\n\t\tif (this.packages.size === 0) {\n\t\t\tthrow new LockfileError(input.path, \"lockfile pins no packages that can be bundled\");\n\t\t}\n\t\treturn {\n\t\t\tformat: input.format,\n\t\t\tlockfileVersion: input.lockfileVersion,\n\t\t\tpath: input.path,\n\t\t\timporter: input.importer,\n\t\t\tpackages: this.packages,\n\t\t\troots: this.roots,\n\t\t\twarnings: this.warnings,\n\t\t\tincomplete: this.incomplete,\n\t\t};\n\t}\n}\n\nconst mergeEdges = (\n\ta: ReadonlyArray<LockedEdge>,\n\tb: ReadonlyArray<LockedEdge>,\n): ReadonlyArray<LockedEdge> => {\n\tconst merged = new Map<string, LockedEdge>();\n\tfor (const edge of [...a, ...b]) {\n\t\tmerged.set(`${edge.name}@${edge.version}|${edge.kind}`, edge);\n\t}\n\treturn [...merged.values()];\n};\n\n/**\n * Reads the right-hand side of a locked entry as an exact version.\n *\n * Returns the version when it is one, or the reason it is not — `file:../x`,\n * `workspace:*`, a git URL. `parseDependencyTarget` already classifies every\n * one of those for package.json parsing, so the vocabulary of skip reasons\n * stays identical between the two paths.\n */\nexport const asExactVersion = (\n\tname: string,\n\traw: string,\n):\n\t| { readonly _tag: \"Version\"; readonly version: string }\n\t| { readonly _tag: \"Unsupported\"; readonly reason: string } => {\n\tconst exact = semver.valid(raw, { loose: true });\n\tif (exact !== null) return { _tag: \"Version\", version: exact };\n\n\tconst target = parseDependencyTarget(name, raw);\n\tif (target._tag === \"Unsupported\") return { _tag: \"Unsupported\", reason: target.reason };\n\treturn { _tag: \"Unsupported\", reason: \"not an exact version\" };\n};\n\n/**\n * Raised when a lockfile found by walking up turns out not to cover the\n * package.json that went looking for it.\n *\n * Worth distinguishing from \"no lockfile at all\": the file exists and is\n * readable, it simply belongs to a different project, and bundling it would\n * produce someone else's dependency set.\n */\nexport const notCovered = (path: string, importer: string, known: ReadonlyArray<string>): never => {\n\tconst listed = known\n\t\t.slice(0, 8)\n\t\t.map((entry) => ` ${entry}`)\n\t\t.join(\"\\n\");\n\tthrow new LockfileError(\n\t\tpath,\n\t\t`it does not cover ${importer}.\\n` +\n\t\t\t(known.length === 0\n\t\t\t\t? \" It records no workspace members.\"\n\t\t\t\t: ` Workspace members it does record:\\n${listed}` +\n\t\t\t\t\t(known.length > 8 ? `\\n … and ${known.length - 8} more` : \"\")),\n\t);\n};\n\n/** `\"\"` is how npm and bun spell the project at the lockfile's own level. */\nexport const importerKey = (importer: string): string => (importer === \".\" ? \"\" : importer);\n","/**\n * `bun.lock`.\n *\n * Like npm, bun records ranges on its edges and resolves them through the\n * install-path nesting — but it nests with a plain `/`, and package names\n * contain `/` too, so the parent of a key can only be found by asking which\n * prefixes are themselves entries.\n */\nimport { EdgeKind, LockedRootKind } from \"../enums/edge-kind.js\";\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { isRecord } from \"../utils/is-record.js\";\nimport { optionalPeerNames, parseJsonObject, stringRecord } from \"./json.js\";\nimport {\n\tasExactVersion,\n\tfieldByRootKind,\n\timporterKey,\n\tnotCovered,\n\tTreeBuilder,\n} from \"./tree-builder.js\";\nimport type { LockedEdge, LockedTree } from \"./types.js\";\n\n/** One narrowed `packages` entry, keyed by its install path. */\ntype BunEntry = {\n\treadonly key: string;\n\treadonly name: string;\n\treadonly version: string;\n\treadonly dependencies: Readonly<Record<string, string>>;\n\treadonly optionalDependencies: Readonly<Record<string, string>>;\n\treadonly peerDependencies: Readonly<Record<string, string>>;\n\treadonly optionalPeers: ReadonlySet<string>;\n};\n\n/** Root blocks in bun's precedence order — the first mention of a name wins. */\nconst ROOT_KINDS = [\n\tLockedRootKind.Prod,\n\tLockedRootKind.Optional,\n\tLockedRootKind.Dev,\n\tLockedRootKind.Peer,\n] as const;\n\nexport const parseBunLockfile = (\n\tpath: string,\n\tcontent: string,\n\timporter: string | undefined,\n): LockedTree => {\n\tconst root = parseJsonObject(path, content);\n\tconst version = String(root[\"lockfileVersion\"] ?? \"?\");\n\tconst builder = new TreeBuilder();\n\n\tconst packages = root[\"packages\"];\n\tconst entries = isRecord(packages)\n\t\t? collectEntries(builder, packages)\n\t\t: new Map<string, BunEntry>();\n\n\tconst keys = new Set(entries.keys());\n\tfor (const entry of entries.values()) {\n\t\tbuilder.add({\n\t\t\tname: entry.name,\n\t\t\tversion: entry.version,\n\t\t\tdependencies: edgesOf(builder, entries, keys, entry),\n\t\t});\n\t}\n\n\tcollectRoots(builder, entries, keys, root[\"workspaces\"], path, importer);\n\n\treturn builder.finish({ format: LockfileFormat.Bun, lockfileVersion: version, path, importer });\n};\n\n/**\n * Narrows bun's tuple entries.\n *\n * The value is a positional array whose shape depends on where the package came\n * from. A registry package is `[id, registry, info, integrity]`; a workspace\n * member or a git dependency is shorter and its `id` carries the protocol.\n */\nconst collectEntries = (\n\tbuilder: TreeBuilder,\n\tpackages: Record<string, unknown>,\n): Map<string, BunEntry> => {\n\tconst entries = new Map<string, BunEntry>();\n\n\tfor (const [key, raw] of Object.entries(packages)) {\n\t\tif (!Array.isArray(raw)) continue;\n\n\t\tconst [id, , info] = raw;\n\t\tif (typeof id !== \"string\") continue;\n\n\t\tconst at = id.lastIndexOf(\"@\");\n\t\tif (at <= 0) continue;\n\t\tconst name = id.slice(0, at);\n\t\tconst spec = id.slice(at + 1);\n\n\t\tconst version = asExactVersion(name, spec);\n\t\tif (version._tag === \"Unsupported\") {\n\t\t\tbuilder.skip(name, spec, version.reason);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst details = isRecord(info) ? info : {};\n\n\t\tentries.set(key, {\n\t\t\tkey,\n\t\t\tname,\n\t\t\tversion: version.version,\n\t\t\tdependencies: stringRecord(details[\"dependencies\"]),\n\t\t\toptionalDependencies: stringRecord(details[\"optionalDependencies\"]),\n\t\t\tpeerDependencies: stringRecord(details[\"peerDependencies\"]),\n\t\t\toptionalPeers: collectOptionalPeers(details),\n\t\t});\n\t}\n\n\treturn entries;\n};\n\n/** bun lists optional peers as a name array rather than npm's metadata object. */\nconst collectOptionalPeers = (details: Record<string, unknown>): ReadonlySet<string> => {\n\tconst listed = details[\"optionalPeers\"];\n\tconst names = Array.isArray(listed)\n\t\t? listed.flatMap((entry) => (typeof entry === \"string\" ? entry : []))\n\t\t: [];\n\treturn new Set([...names, ...optionalPeerNames(details[\"peerDependenciesMeta\"])]);\n};\n\nconst edgesOf = (\n\tbuilder: TreeBuilder,\n\tentries: ReadonlyMap<string, BunEntry>,\n\tkeys: ReadonlySet<string>,\n\tentry: BunEntry,\n): ReadonlyArray<LockedEdge> => {\n\tconst edges: Array<LockedEdge> = [];\n\n\tconst add = (names: ReadonlyArray<string>, kind: EdgeKind): void => {\n\t\tfor (const name of names) {\n\t\t\tconst target = findEntry(entries, keys, entry.key, name);\n\t\t\tif (target === undefined) {\n\t\t\t\tif (kind === EdgeKind.Prod)\n\t\t\t\t\tbuilder.dangling(`${entry.name}@${entry.version}`, name);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tedges.push({ name: target.name, version: target.version, kind });\n\t\t}\n\t};\n\n\tadd(Object.keys(entry.dependencies), EdgeKind.Prod);\n\tadd(Object.keys(entry.optionalDependencies), EdgeKind.Optional);\n\tadd(\n\t\tObject.keys(entry.peerDependencies).filter((name) => !entry.optionalPeers.has(name)),\n\t\tEdgeKind.Peer,\n\t);\n\n\treturn edges;\n};\n\nconst collectRoots = (\n\tbuilder: TreeBuilder,\n\tentries: ReadonlyMap<string, BunEntry>,\n\tkeys: ReadonlySet<string>,\n\tworkspaces: unknown,\n\tpath: string,\n\tmember: string | undefined,\n): void => {\n\tif (!isRecord(workspaces)) return;\n\n\tconst selected =\n\t\tmember === undefined\n\t\t\t? Object.values(workspaces)\n\t\t\t: Object.hasOwn(workspaces, importerKey(member))\n\t\t\t\t? [workspaces[importerKey(member)]]\n\t\t\t\t: notCovered(path, member, workspacePaths(workspaces));\n\n\tfor (const workspace of selected) {\n\t\tif (!isRecord(workspace)) continue;\n\t\tfor (const kind of ROOT_KINDS) {\n\t\t\tconst declared = stringRecord(workspace[fieldByRootKind[kind]]);\n\t\t\tfor (const [name, specifier] of Object.entries(declared)) {\n\t\t\t\tconst target = findEntry(entries, keys, \"\", name);\n\t\t\t\tif (target === undefined) continue;\n\t\t\t\tbuilder.addRoot({ name: target.name, version: target.version, kind, specifier });\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst workspacePaths = (workspaces: Record<string, unknown>): ReadonlyArray<string> =>\n\tObject.keys(workspaces).map((key) => (key === \"\" ? \".\" : key));\n\n/**\n * bun nests with a plain `/`, and package names contain `/` too, so a parent\n * key cannot be found by string-splitting alone — `@babel/core` would split\n * into a scope that is not a key. `parentKey` only accepts a prefix that is\n * itself an entry, which resolves the ambiguity.\n */\nconst findEntry = (\n\tentries: ReadonlyMap<string, BunEntry>,\n\tkeys: ReadonlySet<string>,\n\tfromKey: string,\n\tname: string,\n): BunEntry | undefined => {\n\tlet scope = fromKey;\n\tfor (;;) {\n\t\tconst found = entries.get(scope === \"\" ? name : `${scope}/${name}`);\n\t\tif (found !== undefined) return found;\n\t\tif (scope === \"\") return undefined;\n\t\tscope = parentKey(keys, scope);\n\t}\n};\n\nconst parentKey = (keys: ReadonlySet<string>, key: string): string => {\n\tfor (let at = key.lastIndexOf(\"/\"); at > 0; at = key.lastIndexOf(\"/\", at - 1)) {\n\t\tconst prefix = key.slice(0, at);\n\t\tif (keys.has(prefix)) return prefix;\n\t}\n\treturn \"\";\n};\n","/**\n * `package-lock.json` / `npm-shrinkwrap.json`.\n *\n * npm records *ranges* on its edges and relies on the directory nesting to say\n * which copy of a package a range resolved to, so the node resolution walk-up —\n * look beside me, then in my parent, then my grandparent — is reimplemented\n * here.\n */\nimport { EdgeKind, LockedRootKind } from \"../enums/edge-kind.js\";\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { isRecord } from \"../utils/is-record.js\";\nimport { optionalPeerNames, parseJsonObject, stringOr, stringRecord } from \"./json.js\";\nimport {\n\tasExactVersion,\n\tfieldByRootKind,\n\timporterKey,\n\tnotCovered,\n\tTreeBuilder,\n} from \"./tree-builder.js\";\nimport type { LockedEdge, LockedTree } from \"./types.js\";\n\n/** One entry of the v2/v3 `packages` map, after narrowing. */\ntype NpmEntry = {\n\treadonly path: string;\n\treadonly version: string;\n\t/** Set when the install name differs from the real one — an `npm:` alias. */\n\treadonly realName: string;\n\treadonly dependencies: Readonly<Record<string, string>>;\n\treadonly optionalDependencies: Readonly<Record<string, string>>;\n\treadonly peerDependencies: Readonly<Record<string, string>>;\n\treadonly optionalPeers: ReadonlySet<string>;\n};\n\n/** Root blocks in npm's precedence order — the first mention of a name wins. */\nconst ROOT_KINDS = [\n\tLockedRootKind.Prod,\n\tLockedRootKind.Optional,\n\tLockedRootKind.Dev,\n\tLockedRootKind.Peer,\n] as const;\n\n/**\n * The node resolution walk-up, over a flat map of install paths.\n *\n * A package at `node_modules/a/node_modules/b` depending on `c` gets, in order,\n * `node_modules/a/node_modules/b/node_modules/c`, then\n * `node_modules/a/node_modules/c`, then `node_modules/c`. This is what makes a\n * range on an edge unambiguous: the nesting already recorded which copy won.\n */\nconst NESTING = \"/node_modules/\";\n\nexport const parseNpmLockfile = (\n\tpath: string,\n\tcontent: string,\n\timporter: string | undefined,\n): LockedTree => {\n\tconst root = parseJsonObject(path, content);\n\tconst version = String(root[\"lockfileVersion\"] ?? \"?\");\n\tconst builder = new TreeBuilder();\n\n\t// v2 carries both shapes for backwards compatibility; `packages` is the\n\t// accurate one, so it wins whenever it is there.\n\tconst packages = root[\"packages\"];\n\tconst entries = isRecord(packages)\n\t\t? collectEntries(builder, packages)\n\t\t: collectLegacyEntries(builder, root);\n\n\tfor (const entry of entries.values()) {\n\t\tbuilder.add({\n\t\t\tname: entry.realName,\n\t\t\tversion: entry.version,\n\t\t\tdependencies: edgesOf(builder, entries, entry),\n\t\t});\n\t}\n\n\tcollectRoots(builder, entries, isRecord(packages) ? packages : root, path, importer);\n\n\treturn builder.finish({ format: LockfileFormat.Npm, lockfileVersion: version, path, importer });\n};\n\n/** Narrows the v2/v3 `packages` map, dropping what cannot be bundled. */\nconst collectEntries = (\n\tbuilder: TreeBuilder,\n\tpackages: Record<string, unknown>,\n): Map<string, NpmEntry> => {\n\tconst entries = new Map<string, NpmEntry>();\n\n\tfor (const [entryPath, raw] of Object.entries(packages)) {\n\t\t// The root project itself, and workspace members, are not things to fetch.\n\t\tconst installName = installNameFromPath(entryPath);\n\t\tif (installName === null) continue;\n\t\tif (!isRecord(raw)) continue;\n\n\t\t// A symlinked workspace member. Nothing to fetch, but an edge into it has\n\t\t// to be explained rather than counted as a hole in the file.\n\t\tif (raw[\"link\"] === true) {\n\t\t\tbuilder.skip(installName, stringOr(raw[\"resolved\"], \"link\"), \"workspace link\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rawVersion = raw[\"version\"];\n\t\tif (typeof rawVersion !== \"string\") {\n\t\t\tbuilder.warn(\n\t\t\t\t`skipped ${installName} — its lockfile entry records no version, so there is nothing to pin`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst resolvedName = typeof raw[\"name\"] === \"string\" ? raw[\"name\"] : installName;\n\t\tconst version = asExactVersion(resolvedName, rawVersion);\n\t\tif (version._tag === \"Unsupported\") {\n\t\t\tbuilder.skip(resolvedName, rawVersion, version.reason);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// `resolved` names a git or tarball URL for anything not from a registry,\n\t\t// even when `version` looks ordinary.\n\t\tconst resolvedUrl = raw[\"resolved\"];\n\t\tif (typeof resolvedUrl === \"string\" && !isRegistryUrl(resolvedUrl)) {\n\t\t\tbuilder.skip(resolvedName, resolvedUrl, \"not a registry tarball\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tentries.set(entryPath, {\n\t\t\tpath: entryPath,\n\t\t\tversion: version.version,\n\t\t\trealName: resolvedName,\n\t\t\tdependencies: stringRecord(raw[\"dependencies\"]),\n\t\t\toptionalDependencies: stringRecord(raw[\"optionalDependencies\"]),\n\t\t\tpeerDependencies: stringRecord(raw[\"peerDependencies\"]),\n\t\t\toptionalPeers: optionalPeerNames(raw[\"peerDependenciesMeta\"]),\n\t\t});\n\t}\n\n\treturn entries;\n};\n\n/**\n * Flattens a v1 lockfile's nested `dependencies` tree into the same\n * path-keyed shape v2 uses.\n *\n * v1 is old — npm 6 — but it is exactly the vintage still pinned inside a lot\n * of the locked-down environments this tool exists for, so it is worth the\n * thirty lines rather than an error telling somebody to upgrade npm.\n */\nconst collectLegacyEntries = (\n\tbuilder: TreeBuilder,\n\troot: Record<string, unknown>,\n): Map<string, NpmEntry> => {\n\tconst entries = new Map<string, NpmEntry>();\n\n\tconst visit = (tree: unknown, prefix: string): void => {\n\t\tif (!isRecord(tree)) return;\n\t\tfor (const [name, raw] of Object.entries(tree)) {\n\t\t\tif (!isRecord(raw)) continue;\n\t\t\tconst entryPath =\n\t\t\t\tprefix === \"\" ? `node_modules/${name}` : `${prefix}/node_modules/${name}`;\n\n\t\t\tconst rawVersion = raw[\"version\"];\n\t\t\tif (typeof rawVersion === \"string\") {\n\t\t\t\tconst version = asExactVersion(name, rawVersion);\n\t\t\t\tif (version._tag === \"Unsupported\") {\n\t\t\t\t\tbuilder.skip(name, rawVersion, version.reason);\n\t\t\t\t} else {\n\t\t\t\t\tentries.set(entryPath, {\n\t\t\t\t\t\tpath: entryPath,\n\t\t\t\t\t\tversion: version.version,\n\t\t\t\t\t\trealName: name,\n\t\t\t\t\t\t// v1 calls the edge set `requires`.\n\t\t\t\t\t\tdependencies: stringRecord(raw[\"requires\"]),\n\t\t\t\t\t\toptionalDependencies: {},\n\t\t\t\t\t\tpeerDependencies: {},\n\t\t\t\t\t\toptionalPeers: new Set(),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvisit(raw[\"dependencies\"], entryPath);\n\t\t}\n\t};\n\n\tvisit(root[\"dependencies\"], \"\");\n\treturn entries;\n};\n\n/** Turns one entry's ranges into edges, resolved through the directory nesting. */\nconst edgesOf = (\n\tbuilder: TreeBuilder,\n\tentries: ReadonlyMap<string, NpmEntry>,\n\tentry: NpmEntry,\n): ReadonlyArray<LockedEdge> => {\n\tconst edges: Array<LockedEdge> = [];\n\n\tconst add = (names: ReadonlyArray<string>, kind: EdgeKind): void => {\n\t\tfor (const name of names) {\n\t\t\tconst targetPath = resolveNestedEdge(entries, entry.path, name);\n\t\t\tconst target = targetPath === null ? undefined : entries.get(targetPath);\n\t\t\tif (target === undefined) {\n\t\t\t\t// Only required edges are worth raising: an optional or peer edge that\n\t\t\t\t// resolves to nothing is how a lockfile records \"not installed here\",\n\t\t\t\t// which npm itself tolerates.\n\t\t\t\tif (kind === EdgeKind.Prod)\n\t\t\t\t\tbuilder.dangling(`${entry.realName}@${entry.version}`, name);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tedges.push({ name: target.realName, version: target.version, kind });\n\t\t}\n\t};\n\n\tconst optionalNames = Object.keys(entry.optionalDependencies);\n\tconst optional = new Set(optionalNames);\n\n\t// An entry listed in both is optional: that is how npm records \"wanted, but\n\t// the install may proceed without it\".\n\tadd(\n\t\tObject.keys(entry.dependencies).filter((name) => !optional.has(name)),\n\t\tEdgeKind.Prod,\n\t);\n\tadd(optionalNames, EdgeKind.Optional);\n\tadd(\n\t\tObject.keys(entry.peerDependencies).filter((name) => !entry.optionalPeers.has(name)),\n\t\tEdgeKind.Peer,\n\t);\n\n\treturn edges;\n};\n\n/**\n * Reads the root project's direct dependencies.\n *\n * The lockfile records these under `packages[\"\"]` for v2/v3. v1 has no such\n * entry, so every top-level `node_modules/x` is treated as direct — which\n * over-counts roots slightly on v1 and is the best that file can support.\n */\nconst collectRoots = (\n\tbuilder: TreeBuilder,\n\tentries: ReadonlyMap<string, NpmEntry>,\n\tsource: Record<string, unknown>,\n\tpath: string,\n\timporter: string | undefined,\n): void => {\n\t// Resolution starts from the member's own directory, so a dependency it\n\t// nests privately wins over the hoisted copy — the same rule node applies,\n\t// which is why the walk-up is shared with ordinary edges.\n\tconst collectFrom = (from: string, project: Record<string, unknown>): void => {\n\t\tfor (const kind of ROOT_KINDS) {\n\t\t\tconst field = fieldByRootKind[kind];\n\t\t\tfor (const [name, specifier] of Object.entries(stringRecord(project[field]))) {\n\t\t\t\tconst targetPath = resolveNestedEdge(entries, from, name);\n\t\t\t\tconst target = targetPath === null ? undefined : entries.get(targetPath);\n\t\t\t\tif (target === undefined) continue;\n\t\t\t\tbuilder.addRoot({\n\t\t\t\t\tname: target.realName,\n\t\t\t\t\tversion: target.version,\n\t\t\t\t\tkind,\n\t\t\t\t\tspecifier,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\n\tif (importer !== undefined) {\n\t\tconst key = importerKey(importer);\n\t\tconst project = source[key];\n\t\tif (!isRecord(project)) notCovered(path, importer, workspacePaths(source));\n\t\telse collectFrom(key, project);\n\t\treturn;\n\t}\n\n\t// No member named: every project the file records contributes, which is what\n\t// pointing --file straight at a monorepo's lockfile should mean.\n\tconst projects = Object.entries(source).flatMap(([key, value]) =>\n\t\tisRecord(value) && !key.includes(\"node_modules/\") ? [[key, value] as const] : [],\n\t);\n\n\tif (projects.length > 0) {\n\t\tfor (const [key, project] of projects) collectFrom(key, project);\n\t\treturn;\n\t}\n\n\t// v1 records no project entry at all, so every top-level install is direct.\n\tfor (const entry of entries.values()) {\n\t\tif (entry.path.includes(NESTING)) continue;\n\t\tbuilder.addRoot({\n\t\t\tname: entry.realName,\n\t\t\tversion: entry.version,\n\t\t\tkind: LockedRootKind.Prod,\n\t\t});\n\t}\n};\n\n/** The workspace paths a v2/v3 lockfile records, for a \"does not cover\" message. */\nconst workspacePaths = (source: Record<string, unknown>): ReadonlyArray<string> =>\n\tObject.keys(source).flatMap((key) =>\n\t\tkey === \"\" ? \".\" : key.includes(\"node_modules/\") ? [] : key,\n\t);\n\n/**\n * npm records non-registry sources as a URL in `resolved`. Registry tarballs\n * are ordinary http(s); anything with a `git+`, `file:` or bare path form is\n * something we cannot fetch.\n */\nconst isRegistryUrl = (url: string): boolean =>\n\turl.startsWith(\"http://\") || url.startsWith(\"https://\");\n\nconst resolveNestedEdge = (\n\tentries: ReadonlyMap<string, NpmEntry>,\n\tfromPath: string,\n\tname: string,\n): string | null => {\n\tlet scope = fromPath;\n\tfor (;;) {\n\t\tconst candidate = scope === \"\" ? `node_modules/${name}` : `${scope}${NESTING}${name}`;\n\t\tif (entries.has(candidate)) return candidate;\n\t\tif (scope === \"\") return null;\n\t\tconst at = scope.lastIndexOf(NESTING);\n\t\tscope = at === -1 ? \"\" : scope.slice(0, at);\n\t}\n};\n\n/** `node_modules/@babel/core` -> `@babel/core`; a workspace path -> `null`. */\nconst installNameFromPath = (entryPath: string): string | null => {\n\tconst marker = \"node_modules/\";\n\tconst at = entryPath.lastIndexOf(marker);\n\tif (at === -1) return null;\n\tconst name = entryPath.slice(at + marker.length);\n\treturn name.length === 0 ? null : name;\n};\n","/**\n * `pnpm-lock.yaml`.\n *\n * The easy one: pnpm's snapshots already name exact versions, so there is no\n * nesting walk-up to reimplement. The fiddly parts are the three package-key\n * encodings still in the wild and the parenthesised peer-resolution suffix.\n */\nimport semver from \"semver\";\nimport { parse as parseYaml } from \"yaml\";\n\nimport { parseDependencyTarget } from \"../dependency-range.js\";\nimport { EdgeKind, LockedRootKind } from \"../enums/edge-kind.js\";\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { LockfileError } from \"../errors.js\";\nimport { isRecord } from \"../utils/is-record.js\";\nimport { describeError } from \"./json.js\";\nimport { fieldByRootKind, notCovered, TreeBuilder } from \"./tree-builder.js\";\nimport type { LockedEdge, LockedTree } from \"./types.js\";\n\n/** `name@version`, as a snapshot or importer entry resolves to. */\ntype PnpmReference = {\n\treadonly name: string;\n\treadonly version: string;\n};\n\n/** pnpm never records peer dependencies against an importer. */\nconst ROOT_KINDS = [LockedRootKind.Prod, LockedRootKind.Optional, LockedRootKind.Dev] as const;\n\nexport const parsePnpmLockfile = (\n\tpath: string,\n\tcontent: string,\n\timporter: string | undefined,\n): LockedTree => {\n\tlet root: unknown;\n\ttry {\n\t\troot = parseYaml(content);\n\t} catch (error) {\n\t\tthrow new LockfileError(path, `not valid YAML — ${describeError(error)}`, { cause: error });\n\t}\n\tif (!isRecord(root)) {\n\t\tthrow new LockfileError(path, \"top level is not a mapping\");\n\t}\n\n\tconst version = String(root[\"lockfileVersion\"] ?? \"?\");\n\tconst builder = new TreeBuilder();\n\n\t// v9 split the graph in two: `packages` keeps resolution metadata, and\n\t// `snapshots` keeps the edges. Before that both lived in `packages`.\n\tconst packages = isRecord(root[\"packages\"]) ? root[\"packages\"] : {};\n\tconst snapshots = isRecord(root[\"snapshots\"]) ? root[\"snapshots\"] : packages;\n\n\tconst known = new Map<string, PnpmReference>();\n\tfor (const key of Object.keys(packages)) {\n\t\tconst parsed = parsePnpmKey(key);\n\t\tif (parsed === null) continue;\n\t\tknown.set(key, parsed);\n\t}\n\n\tfor (const [key, raw] of Object.entries(snapshots)) {\n\t\tconst parsed = parsePnpmKey(key) ?? known.get(key);\n\t\tif (parsed === undefined || parsed === null) {\n\t\t\tconst described = describeKey(key);\n\t\t\tif (described !== null) builder.skip(described.name, described.spec, described.reason);\n\t\t\tcontinue;\n\t\t}\n\t\tbuilder.add({\n\t\t\tname: parsed.name,\n\t\t\tversion: parsed.version,\n\t\t\tdependencies: edgesOf(builder, parsed, isRecord(raw) ? raw : {}),\n\t\t});\n\t}\n\n\tcollectRoots(builder, root, path, importer);\n\n\treturn builder.finish({\n\t\tformat: LockfileFormat.Pnpm,\n\t\tlockfileVersion: version,\n\t\tpath,\n\t\timporter,\n\t});\n};\n\nconst edgesOf = (\n\tbuilder: TreeBuilder,\n\tfrom: PnpmReference,\n\tsnapshot: Record<string, unknown>,\n): ReadonlyArray<LockedEdge> => {\n\tconst edges: Array<LockedEdge> = [];\n\n\tconst add = (field: string, kind: EdgeKind): void => {\n\t\tconst entries = snapshot[field];\n\t\tif (!isRecord(entries)) return;\n\t\tfor (const [name, raw] of Object.entries(entries)) {\n\t\t\tif (typeof raw !== \"string\") continue;\n\t\t\tconst target = parsePnpmReference(name, raw);\n\t\t\tif (target === null) {\n\t\t\t\tif (kind === EdgeKind.Prod) builder.dangling(`${from.name}@${from.version}`, name);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tedges.push({ ...target, kind });\n\t\t}\n\t};\n\n\tadd(fieldByRootKind[LockedRootKind.Prod], EdgeKind.Prod);\n\tadd(fieldByRootKind[LockedRootKind.Optional], EdgeKind.Optional);\n\tadd(fieldByRootKind[LockedRootKind.Peer], EdgeKind.Peer);\n\n\treturn edges;\n};\n\n/**\n * The importers' direct dependencies become the roots.\n *\n * pnpm is the format that makes this easy: `importers` is already keyed by the\n * path each package.json sits at, so scoping to one member is a lookup rather\n * than a reconstruction.\n */\nconst collectRoots = (\n\tbuilder: TreeBuilder,\n\troot: Record<string, unknown>,\n\tpath: string,\n\tmember: string | undefined,\n): void => {\n\t// A single-project lockfile has no `importers` block; its dependencies sit at\n\t// the top level, which is the same thing as an importer called \".\".\n\tconst importers = isRecord(root[\"importers\"]) ? root[\"importers\"] : { \".\": root };\n\n\tconst selected =\n\t\tmember === undefined\n\t\t\t? Object.values(importers)\n\t\t\t: Object.hasOwn(importers, member)\n\t\t\t\t? [importers[member]]\n\t\t\t\t: notCovered(path, member, Object.keys(importers));\n\n\tfor (const importer of selected) {\n\t\tif (!isRecord(importer)) continue;\n\t\tfor (const kind of ROOT_KINDS) {\n\t\t\tconst entries = importer[fieldByRootKind[kind]];\n\t\t\tif (!isRecord(entries)) continue;\n\n\t\t\tfor (const [name, raw] of Object.entries(entries)) {\n\t\t\t\t// v5 wrote a bare version string; v6 and v9 write\n\t\t\t\t// `{specifier, version}`.\n\t\t\t\tconst value =\n\t\t\t\t\ttypeof raw === \"string\" ? raw : isRecord(raw) ? raw[\"version\"] : undefined;\n\t\t\t\tif (typeof value !== \"string\") continue;\n\n\t\t\t\tconst target = parsePnpmReference(name, value);\n\t\t\t\tif (target === null) continue;\n\n\t\t\t\tconst specifier =\n\t\t\t\t\tisRecord(raw) && typeof raw[\"specifier\"] === \"string\"\n\t\t\t\t\t\t? raw[\"specifier\"]\n\t\t\t\t\t\t: undefined;\n\t\t\t\tbuilder.addRoot({ ...target, kind, specifier });\n\t\t\t}\n\t\t}\n\t}\n};\n\n/**\n * Reads a dependency value from a snapshot or importer.\n *\n * The value is either a bare version (`1.4.0`) or a full package key\n * (`/lodash@4.17.21`, used when the install name is an alias of another\n * package). Both may carry a peer-resolution suffix in parentheses.\n */\nconst parsePnpmReference = (name: string, raw: string): PnpmReference | null => {\n\tconst value = stripSuffix(raw);\n\n\tconst exact = semver.valid(value, { loose: true });\n\tif (exact !== null) return { name, version: exact };\n\n\treturn parsePnpmKey(raw);\n};\n\n/**\n * Splits a package key into name and version.\n *\n * Three encodings across the versions still in the wild:\n * v5 `/@babel/core/7.0.0`\n * v6 `/@babel/core@7.0.0`\n * v9 `@babel/core@7.0.0`\n *\n * plus an optional `(peer@1.0.0)` or `(patch_hash=…)` suffix on any of them.\n */\nexport const parsePnpmKey = (key: string): PnpmReference | null => {\n\tconst body = stripSuffix(key.startsWith(\"/\") ? key.slice(1) : key);\n\n\t// A scoped name's own `@` sits at index 0, so only a later one separates the\n\t// version. When there is none, this is the v5 form and the last `/` does it.\n\tconst at = body.lastIndexOf(\"@\");\n\tconst cut = at > 0 ? at : body.lastIndexOf(\"/\");\n\tif (cut <= 0) return null;\n\n\tconst name = body.slice(0, cut);\n\tconst version = semver.valid(body.slice(cut + 1), { loose: true });\n\tif (version === null || name.length === 0) return null;\n\n\treturn { name, version };\n};\n\n/** Describes a key we cannot pin, so the skip warning can say why. */\nconst describeKey = (\n\tkey: string,\n): { readonly name: string; readonly spec: string; readonly reason: string } | null => {\n\tconst body = key.startsWith(\"/\") ? key.slice(1) : key;\n\tconst at = body.lastIndexOf(\"@\");\n\tif (at <= 0) return null;\n\tconst name = body.slice(0, at);\n\tconst spec = body.slice(at + 1);\n\tconst target = parseDependencyTarget(name, spec);\n\treturn {\n\t\tname,\n\t\tspec,\n\t\treason: target._tag === \"Unsupported\" ? target.reason : \"not an exact version\",\n\t};\n};\n\n/**\n * Drops the parenthesised peer-resolution suffix.\n *\n * pnpm distinguishes the same version installed against different peers —\n * `react-dom@18.3.1(react@18.3.1)`. Those are the same published tarball, which\n * is all this tool downloads, so the suffix is noise here.\n */\nconst stripSuffix = (value: string): string => {\n\tconst open = value.indexOf(\"(\");\n\treturn open === -1 ? value : value.slice(0, open);\n};\n","/**\n * Lockfile parsing — npm, pnpm and bun.\n *\n * `--file package.json` reads *ranges*, and a range resolves to whatever is\n * newest at the moment the command runs. That is the right answer for \"bundle\n * me something installable\" and the wrong one for \"bundle exactly what CI\n * installed\" — which is what a lockfile records and what this module reads.\n *\n * Three formats, one output shape. Each parser's real job is the same: turn a\n * manager-specific encoding of \"package X at path P depends on Y\" into a flat\n * graph keyed by `name@version`, with every edge already pointing at a concrete\n * version. Once that is done, nothing downstream has to know which manager\n * wrote the file.\n */\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { LockfileError } from \"../errors.js\";\nimport { parseBunLockfile } from \"./bun.js\";\nimport { detectLockfile } from \"./detect.js\";\nimport { parseNpmLockfile } from \"./npm.js\";\nimport { parsePnpmLockfile } from \"./pnpm.js\";\nimport type { LockedTree, LockfileParseOptions } from \"./types.js\";\n\n/**\n * Parses lockfile content into a flat graph.\n *\n * Throws `LockfileError`; the caller is expected to be inside an `Effect.try`.\n */\nexport const parseLockfile = (\n\tpath: string,\n\tcontent: string,\n\tformat?: LockfileFormat,\n\toptions: LockfileParseOptions = {},\n): LockedTree => {\n\tconst resolved = format ?? resolveFormat(path, content);\n\tconst importer = options.importer;\n\tswitch (resolved) {\n\t\tcase LockfileFormat.Npm:\n\t\t\treturn parseNpmLockfile(path, content, importer);\n\t\tcase LockfileFormat.Pnpm:\n\t\t\treturn parsePnpmLockfile(path, content, importer);\n\t\tcase LockfileFormat.Bun:\n\t\t\treturn parseBunLockfile(path, content, importer);\n\t}\n};\n\nconst resolveFormat = (path: string, content: string): LockfileFormat => {\n\tconst detected = detectLockfile(content);\n\tif (detected._tag === \"Supported\") return detected.format;\n\tif (detected._tag === \"Unsupported\") {\n\t\tthrow new LockfileError(path, `${detected.label} — ${detected.hint}`);\n\t}\n\tthrow new LockfileError(\n\t\tpath,\n\t\t\"content does not look like a package-lock.json, pnpm-lock.yaml or bun.lock\",\n\t);\n};\n","/**\n * The package.json blocks `--file` reads, and what counts as readable.\n *\n * A narrow view on purpose: the only thing this tool wants from a package.json\n * is which packages it declares. Everything else — `scripts`, `exports`, the\n * half of the file that belongs to a bundler — is none of its business, and a\n * schema that insisted on understanding it would reject files that are fine.\n *\n * Every block is optional and every wrongly-typed one is simply absent, so a\n * hand-edited manifest produces a smaller spec list rather than a crash. That\n * is what `tolerant` buys: a `dependencies: \"all of them\"` loses one block, not\n * the file.\n */\nimport * as Schema from \"effect/Schema\";\n\nimport { OptionalFlagRecordSchema, StringRecordSchema, tolerant } from \"./lenient.js\";\n\nexport const PackageJsonSchema = Schema.Struct({\n\tdependencies: tolerant(StringRecordSchema),\n\tdevDependencies: tolerant(StringRecordSchema),\n\toptionalDependencies: tolerant(StringRecordSchema),\n\tpeerDependencies: tolerant(StringRecordSchema),\n\tpeerDependenciesMeta: tolerant(OptionalFlagRecordSchema),\n});\n\nexport type PackageJson = typeof PackageJsonSchema.Type;\n\nexport const decodePackageJson = Schema.decodeUnknownOption(PackageJsonSchema);\n","/**\n * `--file` handling.\n *\n * One flag, three accepted shapes, detected from the content rather than the\n * extension so that `--file deps.json` and `--file my-packages` both do the\n * obvious thing:\n *\n * - a **package.json** — bundle everything it depends on\n * - a **lockfile** — npm, pnpm or bun; bundle the exact versions it pins\n * - a **newline-delimited list** — one spec per line, `#` and `//` comments\n * allowed, blank lines ignored\n *\n * A lockfile is checked for first, because `package-lock.json` and\n * `package.json` are both JSON objects and only the content tells them apart.\n */\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\n\nimport { parseDependencyTarget } from \"./dependency-range.js\";\nimport { InputFileKind } from \"./enums/input-file-kind.js\";\nimport type { LockfileFormat } from \"./enums/lockfile-format.js\";\nimport type { InvalidSpecError, LockfileError } from \"./errors.js\";\nimport { InvalidInputFileError } from \"./errors.js\";\nimport { detectLockfile } from \"./lockfile/detect.js\";\nimport { parseLockfile } from \"./lockfile/parse.js\";\nimport type { LockedTree } from \"./lockfile/types.js\";\nimport type { PackageJson } from \"./schemas/package-json.js\";\nimport { decodePackageJson } from \"./schemas/package-json.js\";\nimport type { PackageSpec } from \"./spec.js\";\nimport { parseSpecs } from \"./spec.js\";\n\nexport type InputFileResult = {\n\treadonly kind: InputFileKind;\n\treadonly specs: ReadonlyArray<PackageSpec>;\n\t/** Entries that were recognised but cannot be bundled from a registry. */\n\treadonly warnings: ReadonlyArray<string>;\n\t/**\n\t * The pinned graph, set only for a lockfile.\n\t *\n\t * `specs` carries the same roots for display, but a lockfile run must resolve\n\t * from this — see `locked-resolve` for why re-resolving the roots' ranges\n\t * would quietly produce a different bundle.\n\t */\n\treadonly lockfile?: LockedTree | undefined;\n\t/**\n\t * Names from the blocks a package.json always installs — `dependencies` and,\n\t * unless `--prod`, `devDependencies`.\n\t *\n\t * Used to check a lockfile against the manifest beside it. Deliberately\n\t * excludes optional and peer entries: both are legitimately absent from a\n\t * lockfile (an optional dependency that failed to build, a peer the consumer\n\t * is expected to supply), so including them would turn a useful staleness\n\t * check into a false alarm.\n\t */\n\treadonly required?: ReadonlyArray<string> | undefined;\n};\n\n/** Which dependency blocks of a package.json become root specs. */\nexport type InputFileOptions = {\n\t/**\n\t * Include `devDependencies`.\n\t *\n\t * On by default: if you are pointing this tool at a package.json, you are\n\t * almost certainly trying to make that project installable behind the\n\t * firewall, and a project without its dev tooling does not build. `--prod`\n\t * turns it off.\n\t */\n\treadonly includeDev: boolean;\n\t/**\n\t * For a lockfile, which workspace member's dependencies are the roots.\n\t *\n\t * Set when a package.json found its lockfile by walking up: the file then\n\t * covers the whole repository, and only one member of it was asked for.\n\t */\n\treadonly importer?: string | undefined;\n};\n\nexport const defaultInputFileOptions: InputFileOptions = { includeDev: true };\n\n/** Reads and parses an input file. */\nexport const readInputFile = (\n\tfilePath: string,\n\toptions: InputFileOptions = defaultInputFileOptions,\n): Effect.Effect<InputFileResult, InvalidInputFileError | LockfileError, FileSystem.FileSystem> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\n\t\tconst exists = yield* fs\n\t\t\t.exists(filePath)\n\t\t\t.pipe(\n\t\t\t\tEffect.mapError(\n\t\t\t\t\t(cause) => new InvalidInputFileError(filePath, \"could not be read\", { cause }),\n\t\t\t\t),\n\t\t\t);\n\t\tif (!exists) {\n\t\t\treturn yield* Effect.fail(new InvalidInputFileError(filePath, \"file does not exist\"));\n\t\t}\n\n\t\tconst content = yield* fs\n\t\t\t.readFileString(filePath)\n\t\t\t.pipe(\n\t\t\t\tEffect.mapError(\n\t\t\t\t\t(cause) => new InvalidInputFileError(filePath, \"could not be read\", { cause }),\n\t\t\t\t),\n\t\t\t);\n\n\t\treturn yield* Effect.try({\n\t\t\ttry: () => parseInputFile(filePath, content, options),\n\t\t\tcatch: (error) =>\n\t\t\t\t// A LockfileError already names the file and says what is wrong with\n\t\t\t\t// it; wrapping it would only stutter.\n\t\t\t\terror instanceof InvalidInputFileError || isLockfileError(error)\n\t\t\t\t\t? error\n\t\t\t\t\t: new InvalidInputFileError(filePath, describeError(error), { cause: error }),\n\t\t});\n\t});\n\nconst isLockfileError = (error: unknown): error is LockfileError =>\n\terror instanceof Error && \"_tag\" in error && error._tag === \"LockfileError\";\n\n/**\n * Parses file content that has already been read.\n *\n * Split out from the IO so the whole of this logic is testable with plain\n * strings and no file system at all.\n */\nexport const parseInputFile = (\n\tfilePath: string,\n\tcontent: string,\n\toptions: InputFileOptions = defaultInputFileOptions,\n): InputFileResult => {\n\tconst trimmed = content.trim();\n\tif (trimmed.length === 0) {\n\t\tthrow new InvalidInputFileError(filePath, \"file is empty\");\n\t}\n\n\t// Checked first: a package-lock.json is also a JSON object whose top level\n\t// looks a lot like a package.json, and reading one as the other would produce\n\t// a bundle with none of the pinning that was asked for.\n\tconst detected = detectLockfile(trimmed);\n\tif (detected._tag === \"Unsupported\") {\n\t\tthrow new InvalidInputFileError(filePath, `${detected.label} — ${detected.hint}`);\n\t}\n\tif (detected._tag === \"Supported\") {\n\t\treturn fromLockfile(filePath, content, detected.format, options);\n\t}\n\n\treturn looksLikeJson(trimmed)\n\t\t? fromPackageJson(filePath, trimmed, options)\n\t\t: fromList(filePath, content);\n};\n\nconst looksLikeJson = (trimmed: string): boolean => trimmed.startsWith(\"{\");\n\n/* -------------------------------------------------------------------------- */\n/* Lockfile */\n/* -------------------------------------------------------------------------- */\n\nconst fromLockfile = (\n\tfilePath: string,\n\tcontent: string,\n\tformat: LockfileFormat,\n\toptions: InputFileOptions,\n): InputFileResult => {\n\tconst lockfile = parseLockfile(filePath, content, format, { importer: options.importer });\n\n\t// The same devDependency rule as a package.json, applied to the pinned roots\n\t// so that `specs` shows exactly what the run will bundle.\n\tconst roots = lockfile.roots.filter((root) => options.includeDev || root.kind !== \"dev\");\n\n\treturn {\n\t\tkind: InputFileKind.Lockfile,\n\t\tspecs: roots.map((root) => ({\n\t\t\tname: root.name,\n\t\t\tselector: { _tag: \"Exact\", version: root.version },\n\t\t\traw: `${root.name}@${root.version}`,\n\t\t})),\n\t\twarnings: lockfile.warnings,\n\t\tlockfile,\n\t};\n};\n\n/* -------------------------------------------------------------------------- */\n/* package.json */\n/* -------------------------------------------------------------------------- */\n\nconst fromPackageJson = (\n\tfilePath: string,\n\tcontent: string,\n\toptions: InputFileOptions,\n): InputFileResult => {\n\tconst parsed = parsePackageJson(filePath, content);\n\n\tconst specs: Array<PackageSpec> = [];\n\tconst warnings: Array<string> = [];\n\tconst required: Array<string> = [];\n\tconst seen = new Set<string>();\n\n\tconst collect = (\n\t\tentries: Record<string, string> | undefined,\n\t\tlabel: string,\n\t\tskip?: (name: string) => boolean,\n\t): void => {\n\t\tif (entries === undefined) return;\n\t\tfor (const [name, raw] of Object.entries(entries)) {\n\t\t\tif (skip?.(name)) continue;\n\t\t\tconst target = parseDependencyTarget(name, raw);\n\t\t\tif (target._tag === \"Unsupported\") {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`${label}: skipped ${name}@${target.raw} (${target.reason}) — not fetchable from a registry`,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// `target.name` rather than the key, so an `npm:` alias is recorded under\n\t\t\t// the name a lockfile would actually pin it as.\n\t\t\tif (label === \"dependencies\" || label === \"devDependencies\") required.push(target.name);\n\t\t\tconst key = `${target.name}|${JSON.stringify(target.selector)}`;\n\t\t\tif (seen.has(key)) continue;\n\t\t\tseen.add(key);\n\t\t\tspecs.push({\n\t\t\t\tname: target.name,\n\t\t\t\tselector: target.selector,\n\t\t\t\traw: `${target.name}@${raw}`,\n\t\t\t});\n\t\t}\n\t};\n\n\tcollect(parsed.dependencies, \"dependencies\");\n\tcollect(parsed.optionalDependencies, \"optionalDependencies\");\n\tif (options.includeDev) {\n\t\tcollect(parsed.devDependencies, \"devDependencies\");\n\t}\n\tconst meta = parsed.peerDependenciesMeta ?? {};\n\tcollect(parsed.peerDependencies, \"peerDependencies\", (name) => meta[name]?.optional === true);\n\n\tif (specs.length === 0) {\n\t\tthrow new InvalidInputFileError(\n\t\t\tfilePath,\n\t\t\toptions.includeDev\n\t\t\t\t? \"package.json declares no dependencies to bundle\"\n\t\t\t\t: \"package.json declares no non-dev dependencies to bundle (drop --prod to include devDependencies)\",\n\t\t);\n\t}\n\n\treturn { kind: InputFileKind.PackageJson, specs, warnings, required };\n};\n\n/**\n * Reads a package.json, or gives up on its contents rather than on the run.\n *\n * Invalid JSON is an error worth raising — somebody pointed `--file` at a\n * broken file. A well-formed JSON document this schema cannot recognise is\n * not: it decodes to no blocks, and the caller reports \"declares no\n * dependencies to bundle\", which is both true and more useful.\n */\nconst parsePackageJson = (filePath: string, content: string): PackageJson => {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(content);\n\t} catch (error) {\n\t\tthrow new InvalidInputFileError(filePath, `not valid JSON — ${describeError(error)}`, {\n\t\t\tcause: error,\n\t\t});\n\t}\n\n\treturn Option.getOrElse(decodePackageJson(parsed), (): PackageJson => ({}));\n};\n\n/* -------------------------------------------------------------------------- */\n/* Spec list */\n/* -------------------------------------------------------------------------- */\n\nconst fromList = (filePath: string, content: string): InputFileResult => {\n\tconst rawLines = content.split(/\\r?\\n/);\n\tconst lines = rawLines.flatMap((line) => {\n\t\tconst withoutComment = stripComment(line).trim();\n\t\treturn withoutComment.length === 0 ? [] : withoutComment;\n\t});\n\n\tif (lines.length === 0) {\n\t\tthrow new InvalidInputFileError(\n\t\t\tfilePath,\n\t\t\t\"no package specs found (only blank lines and comments)\",\n\t\t);\n\t}\n\n\tconst { specs, errors } = parseSpecs(lines);\n\tif (errors.length > 0) {\n\t\tthrow new InvalidInputFileError(filePath, formatSpecErrors(errors, rawLines));\n\t}\n\n\treturn { kind: InputFileKind.List, specs, warnings: [] };\n};\n\n/**\n * Strips `#` and `//` comments.\n *\n * `//` only counts when it is not part of a URL, so a future line containing\n * `https://…` does not get silently truncated.\n */\nconst stripComment = (line: string): string => {\n\tconst hash = line.indexOf(\"#\");\n\tconst result = hash === -1 ? line : line.slice(0, hash);\n\tconst slashes = result.indexOf(\"//\");\n\tif (slashes === 0) return \"\";\n\tif (slashes > 0 && result[slashes - 1] !== \":\") return result.slice(0, slashes);\n\treturn result;\n};\n\nconst formatSpecErrors = (\n\terrors: ReadonlyArray<InvalidSpecError>,\n\trawLines: ReadonlyArray<string>,\n): string => {\n\tconst details = errors.map((error) => {\n\t\tconst index = rawLines.findIndex((line) => stripComment(line).trim() === error.spec);\n\t\tconst where = index === -1 ? \"\" : ` (line ${index + 1})`;\n\t\treturn ` ${error.spec}${where}: ${error.reason}`;\n\t});\n\treturn `${errors.length} invalid spec(s):\\n${details.join(\"\\n\")}`;\n};\n\nconst describeError = (error: unknown): string =>\n\terror instanceof Error ? error.message : String(error);\n","/**\n * Fetching tarballs into the staging tree.\n *\n * Downloads run concurrently, every one is checksum-verified before it is\n * written, and the destination is always the scoped temp directory — nothing\n * lands next to the user's own files.\n */\nimport type * as Crypto from \"effect/Crypto\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport type { PlatformError } from \"effect/PlatformError\";\n\nimport { Phase } from \"./enums/phase.js\";\nimport type { BundlerError } from \"./errors.js\";\nimport { IntegrityError, OutputError } from \"./errors.js\";\nimport * as Integrity from \"./integrity.js\";\nimport { packagePath } from \"./layout.js\";\nimport * as Progress from \"./progress.js\";\nimport { Registry } from \"./registry.js\";\nimport type { ResolvedPackage } from \"./resolve.js\";\n\n/** What a completed download run produced. */\nexport type DownloadReport = {\n\t/** `name@version` -> bytes written. */\n\treadonly sizes: ReadonlyMap<string, number>;\n\t/** Packages the registry advertised no usable checksum for. */\n\treadonly unverified: ReadonlyArray<string>;\n\treadonly totalBytes: number;\n};\n\n/**\n * Downloads every package into `destDir`, laid out the way a registry serves\n * them.\n *\n * `verifyIntegrity` defaulting to on is deliberate: a corrupt tarball that\n * makes it into a corporate registry is far more expensive than a failed run.\n */\nexport const downloadAll = (\n\tpackages: ReadonlyArray<ResolvedPackage>,\n\tdestDir: string,\n\toptions: { readonly concurrency: number; readonly verifyIntegrity: boolean },\n): Effect.Effect<\n\tDownloadReport,\n\tBundlerError | PlatformError,\n\tRegistry | Progress.Progress | FileSystem.FileSystem | Path.Path | Crypto.Crypto\n> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\t\tconst registry = yield* Registry;\n\n\t\tyield* Progress.emit({\n\t\t\t_tag: \"PhaseStarted\",\n\t\t\tphase: Phase.Download,\n\t\t\ttotal: packages.length,\n\t\t});\n\n\t\tlet completed = 0;\n\t\tconst sizes = new Map<string, number>();\n\t\tconst unverified: Array<string> = [];\n\n\t\tconst results = yield* Effect.forEach(\n\t\t\tpackages,\n\t\t\t(pkg) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst key = `${pkg.name}@${pkg.version}`;\n\n\t\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t\t_tag: \"DownloadStarted\",\n\t\t\t\t\t\tname: pkg.name,\n\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst bytes = yield* registry.download(pkg.manifest);\n\n\t\t\t\t\tif (options.verifyIntegrity) {\n\t\t\t\t\t\tconst result = yield* Integrity.verify(bytes, pkg.manifest.dist);\n\t\t\t\t\t\tif (result._tag === \"Mismatch\") {\n\t\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\t\tnew IntegrityError(\n\t\t\t\t\t\t\t\t\tpkg.name,\n\t\t\t\t\t\t\t\t\tpkg.version,\n\t\t\t\t\t\t\t\t\tresult.expected,\n\t\t\t\t\t\t\t\t\tresult.actual,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (result._tag === \"Unverifiable\") {\n\t\t\t\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t\t\t\t_tag: \"Warning\",\n\t\t\t\t\t\t\t\tmessage: `${key} could not be verified (${result.reason})`,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst verifiable =\n\t\t\t\t\t\t(pkg.manifest.dist.integrity?.length ?? 0) > 0 ||\n\t\t\t\t\t\t(pkg.manifest.dist.shasum?.length ?? 0) > 0;\n\n\t\t\t\t\tconst relative = packagePath(pkg.name, pkg.version);\n\t\t\t\t\tconst target = path.join(destDir, ...relative.split(\"/\"));\n\n\t\t\t\t\tyield* fs\n\t\t\t\t\t\t.makeDirectory(path.dirname(target), { recursive: true })\n\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\tEffect.mapError(\n\t\t\t\t\t\t\t\t(cause) =>\n\t\t\t\t\t\t\t\t\tnew OutputError(\n\t\t\t\t\t\t\t\t\t\tpath.dirname(target),\n\t\t\t\t\t\t\t\t\t\t\"could not create directory\",\n\t\t\t\t\t\t\t\t\t\t{ cause },\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\tyield* fs\n\t\t\t\t\t\t.writeFile(target, bytes)\n\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\tEffect.mapError(\n\t\t\t\t\t\t\t\t(cause) =>\n\t\t\t\t\t\t\t\t\tnew OutputError(target, \"could not write tarball\", { cause }),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// Counting here rather than inside the concurrent body would be\n\t\t\t\t\t// wrong; each fiber increments as it finishes, which is what makes\n\t\t\t\t\t// the progress counter monotonic.\n\t\t\t\t\tcompleted += 1;\n\t\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t\t_tag: \"DownloadCompleted\",\n\t\t\t\t\t\tname: pkg.name,\n\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\tbytes: bytes.byteLength,\n\t\t\t\t\t\tcompletedCount: completed,\n\t\t\t\t\t\ttotalCount: packages.length,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn { key, bytes: bytes.byteLength, verifiable } as const;\n\t\t\t\t}),\n\t\t\t{ concurrency: options.concurrency },\n\t\t);\n\n\t\tfor (const result of results) {\n\t\t\tsizes.set(result.key, result.bytes);\n\t\t\tif (!result.verifiable) unverified.push(result.key);\n\t\t}\n\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Download });\n\n\t\treturn {\n\t\t\tsizes,\n\t\t\tunverified,\n\t\t\ttotalBytes: results.reduce((sum, result) => sum + result.bytes, 0),\n\t\t};\n\t});\n","/**\n * End-to-end orchestration: specs in, tarballs out.\n *\n * Two properties this module is responsible for — see `notes/requirements.md`\n * § FR-5 and § NFR-9 for why they are requirements, and the mechanisms below\n * for why the code reads as it does:\n *\n * 1. **Nothing is written outside the output directory.** Every intermediate\n * file lives in a scoped temp directory obtained from\n * `makeTempDirectoryScoped`, so the scope closing — on success, on failure,\n * or on Ctrl-C — takes the whole staging tree with it. The working\n * directory is never touched.\n *\n * 2. **Each package is downloaded exactly once**, no matter how many bundles\n * it ends up in. Per-spec archives are assembled by hard-linking out of one\n * shared download tree, so `per-spec` costs extra disk in the *output*, not\n * extra network.\n */\nimport type * as Crypto from \"effect/Crypto\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport type { PlatformError } from \"effect/PlatformError\";\nimport type { Scope } from \"effect/Scope\";\n\nimport type { Archiver } from \"./archive.js\";\nimport { createArchive } from \"./archive.js\";\nimport { downloadAll } from \"./download.js\";\nimport { ArtifactKind } from \"./enums/artifact-kind.js\";\nimport { Layout } from \"./enums/layout.js\";\nimport { Phase } from \"./enums/phase.js\";\nimport type { BundlerError } from \"./errors.js\";\nimport { OutputError } from \"./errors.js\";\nimport {\n\tflatName,\n\timportGuide,\n\tMANIFEST_FILE,\n\tpackagePath,\n\tperSpecArchiveName,\n\tREADME_FILE,\n\tsingleArchiveName,\n} from \"./layout.js\";\nimport type { LockedResolveOptions } from \"./locked-resolve.js\";\nimport { resolveLocked } from \"./locked-resolve.js\";\nimport type { LockedTree } from \"./lockfile/types.js\";\nimport { buildManifest, serializeManifest } from \"./manifest.js\";\nimport type { BundleOptions } from \"./options.js\";\nimport * as Progress from \"./progress.js\";\nimport { Registry } from \"./registry.js\";\nimport type { PackageKey, Resolution, ResolvedPackage, RootResolution } from \"./resolve.js\";\nimport { indexPackages, resolve } from \"./resolve.js\";\nimport type { PackageSpec } from \"./spec.js\";\nimport { formatSpec } from \"./spec.js\";\n\n/** One thing written to the output directory. */\nexport type BundleArtifact = {\n\treadonly kind: ArtifactKind;\n\treadonly path: string;\n\treadonly bytes: number;\n\treadonly packageCount: number;\n\t/** Which spec this artifact covers. Only `per-spec` sets it. */\n\treadonly spec?: string | undefined;\n\treadonly version?: string | undefined;\n};\n\n/** The outcome of a bundle run. */\nexport type BundleResult = {\n\treadonly resolution: Resolution;\n\treadonly artifacts: ReadonlyArray<BundleArtifact>;\n\t/** Total bytes downloaded from the registry. */\n\treadonly downloadedBytes: number;\n\t/** Packages the registry advertised no usable checksum for. */\n\treadonly unverified: ReadonlyArray<string>;\n\treadonly dryRun: boolean;\n};\n\n/** Everything `bundle` needs beyond the user-facing options. */\nexport type BundleContext = BundleOptions & {\n\t/** Recorded in the manifest so a bundle can be traced to the tool that built it. */\n\treadonly toolVersion: string;\n};\n\n/**\n * A summary of what a resolution would produce, for deciding whether the\n * chosen layout is still the right one.\n */\nexport type PlanSummary = {\n\t/** Distinct packages in the deduplicated union. */\n\treadonly uniquePackages: number;\n\t/** How many archives `per-spec` layout would emit. */\n\treadonly perSpecArchives: number;\n\t/**\n\t * Total package entries across all per-spec archives, counting shared\n\t * dependencies once per archive they appear in. The gap between this and\n\t * `uniquePackages` is exactly what `single` layout would save.\n\t */\n\treadonly perSpecEntries: number;\n};\n\n/**\n * The files a run will write, known before anything is downloaded.\n *\n * `dir` and `flat` are the odd ones: they merge a package tree into `outDir`\n * rather than writing an archive. Either way a package's path is derived from\n * its name and version, so the same package at the same version is the same\n * bytes at the same path — an overlap is idempotent rather than destructive.\n * Only the two summary files are genuinely replaced, and those are the ones\n * worth guarding.\n */\nexport type PlannedOutput = {\n\treadonly file: string;\n\t/** The root this file belongs to, when one file corresponds to one spec. */\n\treadonly name?: string | undefined;\n\treadonly version?: string | undefined;\n};\n\ntype BundleEnv =\n\t| Registry\n\t| Progress.Progress\n\t| FileSystem.FileSystem\n\t| Path.Path\n\t| Crypto.Crypto\n\t| Archiver;\n\ntype EmitInput = {\n\treadonly resolution: Resolution;\n\treadonly options: BundleContext;\n\treadonly packagesDir: string;\n\treadonly report: { readonly sizes: ReadonlyMap<string, number> };\n\treadonly registryInfo: { readonly kind: string; readonly url: string };\n};\n\n/** One archive `per-spec` layout will write: a root, at one of its versions. */\ntype PerSpecTarget = {\n\treadonly root: RootResolution;\n\treadonly version: string;\n};\n\n/**\n * The archives `per-spec` emits — one per distinct root package version.\n *\n * Roots are *specs*, and several specs can name one package: `react`,\n * `react@latest` and `react@19.2.8` are three ways of asking for the same\n * thing, and after resolution they are indistinguishable. Without this they\n * were three archives — the same bytes, under the same file name, written over\n * each other. The run then reported three artifacts and three times the size\n * for one file on disk, and the duplication ratio it computes to decide whether\n * to ask about the layout counted them too, so the tool would offer to\n * deduplicate a bundle it had duplicated itself.\n *\n * Keyed by name and version rather than by the archive's file name. A scoped\n * name is flattened to make a file name, so `@foo/bar` and `foo-bar` can spell\n * the same one — and those are two different packages, which should collide\n * loudly rather than being merged here.\n *\n * Roots only. The packages *inside* an archive were deduplicated by resolution\n * long before this, which is why the same closure fetched from twenty specs is\n * fetched once.\n */\nconst perSpecTargets = (resolution: Resolution): ReadonlyArray<PerSpecTarget> => {\n\tconst seen = new Set<string>();\n\n\treturn resolution.roots.flatMap((root) =>\n\t\troot.versions.flatMap((version) => {\n\t\t\tconst key = `${root.spec.name}@${version}`;\n\t\t\tif (seen.has(key)) return [];\n\n\t\t\tseen.add(key);\n\t\t\treturn { root, version };\n\t\t}),\n\t);\n};\n\n/** Computes the plan summary for a resolution. */\nexport const summarize = (resolution: Resolution): PlanSummary => {\n\tlet perSpecArchives = 0;\n\tlet perSpecEntries = 0;\n\tfor (const { root, version } of perSpecTargets(resolution)) {\n\t\tperSpecArchives += 1;\n\t\tperSpecEntries += (root.closures.get(version) ?? []).length;\n\t}\n\treturn {\n\t\tuniquePackages: resolution.packages.length,\n\t\tperSpecArchives,\n\t\tperSpecEntries,\n\t};\n};\n\n/** Replaces the layout on a set of options. */\nexport const withLayout = <T extends BundleOptions>(options: T, layout: Layout): T => ({\n\t...options,\n\tlayout,\n});\n\n/**\n * Checks the registry is reachable, then resolves every spec.\n *\n * Split out from `bundle` so a caller can inspect the plan — how many packages,\n * how many archives — and act on it before any bytes move. The CLI uses this to\n * offer a different layout when a run turns out to be much larger than\n * expected.\n */\nexport const plan = (\n\tspecs: ReadonlyArray<PackageSpec>,\n\toptions: BundleOptions,\n): Effect.Effect<Resolution, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tyield* preflight;\n\t\treturn yield* resolve(specs, options);\n\t});\n\n/**\n * The lockfile counterpart of `plan`.\n *\n * Same preflight, same `Resolution` out; the difference is entirely in how the\n * package set is arrived at. Kept as a separate entry point rather than an\n * option on `plan` because the two take genuinely different inputs — a set of\n * specs to satisfy versus a graph to reproduce — and blurring that is how a\n * \"pinned\" run quietly starts resolving ranges again.\n */\nexport const planLocked = (\n\tlockfile: LockedTree,\n\toptions: BundleOptions & LockedResolveOptions,\n): Effect.Effect<Resolution, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tyield* preflight;\n\t\treturn yield* resolveLocked(lockfile, options);\n\t});\n\nconst preflight: Effect.Effect<void, BundlerError, Registry | Progress.Progress> = Effect.gen(\n\tfunction* () {\n\t\tconst registry = yield* Registry;\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Preflight });\n\t\tyield* registry.preflight;\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Preflight });\n\t},\n);\n\n/**\n * Resolves, downloads and packages a set of specs.\n *\n * Under `dryRun` this stops after resolution and reports the plan — useful for\n * checking what a command *would* pull before committing to a multi-gigabyte\n * download over a slow VPN.\n */\nexport const bundle = (\n\tspecs: ReadonlyArray<PackageSpec>,\n\toptions: BundleContext,\n): Effect.Effect<BundleResult, BundlerError | PlatformError, BundleEnv> =>\n\tEffect.gen(function* () {\n\t\tconst resolution = yield* plan(specs, options);\n\t\treturn yield* bundleResolved(resolution, options);\n\t});\n\n/** `bundle`, pinned to a lockfile. */\nexport const bundleLocked = (\n\tlockfile: LockedTree,\n\toptions: BundleContext & LockedResolveOptions,\n): Effect.Effect<BundleResult, BundlerError | PlatformError, BundleEnv> =>\n\tEffect.gen(function* () {\n\t\tconst resolution = yield* planLocked(lockfile, options);\n\t\treturn yield* bundleResolved(resolution, options);\n\t});\n\n/**\n * Downloads and packages an already-computed resolution.\n *\n * Everything from here on touches the disk, and all of it happens inside\n * `Effect.scoped` — so the staging tree's lifetime is exactly this call,\n * including when it fails partway through or the user hits Ctrl-C.\n */\nexport const bundleResolved = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<BundleResult, BundlerError | PlatformError, BundleEnv> =>\n\tEffect.gen(function* () {\n\t\tif (options.dryRun) {\n\t\t\treturn {\n\t\t\t\tresolution,\n\t\t\t\tartifacts: [],\n\t\t\t\tdownloadedBytes: 0,\n\t\t\t\tunverified: [],\n\t\t\t\tdryRun: true,\n\t\t\t};\n\t\t}\n\t\treturn yield* Effect.scoped(runBundle(resolution, options));\n\t});\n\n/**\n * The files a run will write.\n *\n * Computed before anything is downloaded, so a collision is reported in the\n * first second rather than after a twenty-minute transfer.\n */\nexport const plannedOutputs = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): ReadonlyArray<PlannedOutput> => {\n\tif (options.layout === Layout.Dir || options.layout === Layout.Flat) {\n\t\treturn [{ file: MANIFEST_FILE }, { file: README_FILE }];\n\t}\n\tif (options.layout === Layout.Single) {\n\t\treturn [{ file: singleArchiveName(options.archiveName ?? \"bundle\") }];\n\t}\n\treturn perSpecTargets(resolution).map(({ root, version }) => ({\n\t\tfile: perSpecArchiveName(root.spec.name, version),\n\t\tname: root.spec.name,\n\t\tversion,\n\t}));\n};\n\nconst runBundle = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<BundleResult, BundlerError | PlatformError, BundleEnv | Scope> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\t\tconst registry = yield* Registry;\n\n\t\tyield* prepareOutputDir(resolution, options);\n\n\t\tconst staging = yield* fs.makeTempDirectoryScoped({ prefix: \"packall-\" });\n\t\tconst packagesDir = path.join(staging, \"packages\");\n\t\tyield* fs.makeDirectory(packagesDir, { recursive: true });\n\n\t\tconst report = yield* downloadAll(resolution.packages, packagesDir, {\n\t\t\tconcurrency: options.concurrency,\n\t\t\tverifyIntegrity: options.verifyIntegrity,\n\t\t});\n\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Archive });\n\n\t\tconst input: EmitInput = {\n\t\t\tresolution,\n\t\t\toptions,\n\t\t\tpackagesDir,\n\t\t\treport,\n\t\t\tregistryInfo: {\n\t\t\t\tkind: registry.kind,\n\t\t\t\turl: registry.registryFor(resolution.roots[0]?.spec.name ?? \"\"),\n\t\t\t},\n\t\t};\n\n\t\tconst artifacts = yield* emit(input, staging);\n\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Archive });\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Done });\n\n\t\treturn {\n\t\t\tresolution,\n\t\t\tartifacts,\n\t\t\tdownloadedBytes: report.totalBytes,\n\t\t\tunverified: report.unverified,\n\t\t\tdryRun: false,\n\t\t};\n\t});\n\n/* -------------------------------------------------------------------------- */\n/* Emitters */\n/* -------------------------------------------------------------------------- */\n\nconst emit = (\n\tinput: EmitInput,\n\tstaging: string,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path | Progress.Progress | Archiver\n> => {\n\tswitch (input.options.layout) {\n\t\tcase Layout.Single:\n\t\t\treturn emitSingle(input);\n\t\tcase Layout.Dir:\n\t\t\treturn emitDirectory(input);\n\t\tcase Layout.PerSpec:\n\t\t\treturn emitPerSpec(input, staging);\n\t\tcase Layout.Flat:\n\t\t\treturn emitFlat(input, staging);\n\t}\n};\n\n/** One tarball containing the deduplicated union of every closure. */\nconst emitSingle = (\n\tinput: EmitInput,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path | Progress.Progress | Archiver\n> =>\n\tEffect.gen(function* () {\n\t\tconst path = yield* Path.Path;\n\n\t\tconst archiveName = singleArchiveName(input.options.archiveName ?? \"bundle\");\n\t\t// Declined at the prompt, and it is the run's only output.\n\t\tif (input.options.skipExisting?.has(archiveName) === true) return [];\n\n\t\tyield* writeBundleMetadata({\n\t\t\tdir: input.packagesDir,\n\t\t\tresolution: input.resolution,\n\t\t\tincluded: input.resolution.packages,\n\t\t\toptions: input.options,\n\t\t\tregistryInfo: input.registryInfo,\n\t\t\tsizes: input.report.sizes,\n\t\t});\n\n\t\tconst outPath = path.join(input.options.outDir, archiveName);\n\n\t\tconst result = yield* createArchive({\n\t\t\tcwd: input.packagesDir,\n\t\t\tentries: yield* topLevelEntries(input.packagesDir),\n\t\t\toutPath,\n\t\t});\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: ArtifactKind.Archive,\n\t\t\t\tpath: result.path,\n\t\t\t\tbytes: result.bytes,\n\t\t\t\tpackageCount: input.resolution.packages.length,\n\t\t\t},\n\t\t];\n\t});\n\n/** The raw npm-layout tree, no archive. */\nconst emitDirectory = (\n\tinput: EmitInput,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path\n> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\n\t\tyield* writeBundleMetadata({\n\t\t\tdir: input.packagesDir,\n\t\t\tresolution: input.resolution,\n\t\t\tincluded: input.resolution.packages,\n\t\t\toptions: input.options,\n\t\t\tregistryInfo: input.registryInfo,\n\t\t\tsizes: input.report.sizes,\n\t\t});\n\n\t\t// The staging tree is about to be deleted with its scope, so this is a\n\t\t// real copy rather than a move — `copy` also works across devices, which\n\t\t// matters because the temp dir often lives on a different filesystem.\n\t\tyield* fs.copy(input.packagesDir, input.options.outDir, { overwrite: true }).pipe(\n\t\t\tEffect.mapError(\n\t\t\t\t(cause) =>\n\t\t\t\t\tnew OutputError(input.options.outDir, \"could not write output tree\", {\n\t\t\t\t\t\tcause,\n\t\t\t\t\t}),\n\t\t\t),\n\t\t);\n\n\t\tconst bytes = [...input.report.sizes.values()].reduce((a, b) => a + b, 0);\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: ArtifactKind.Directory,\n\t\t\t\tpath: input.options.outDir,\n\t\t\t\tbytes,\n\t\t\t\tpackageCount: input.resolution.packages.length,\n\t\t\t},\n\t\t];\n\t});\n\n/**\n * The flat directory: every tarball side by side, no archive, no nesting.\n *\n * The tarballs are the untouched registry ones — only their names are ours,\n * and `bundlePath` says why.\n */\nconst emitFlat = (\n\tinput: EmitInput,\n\tstaging: string,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path\n> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\n\t\t// Staged and then copied rather than written straight into `outDir`, so a\n\t\t// failure partway through leaves the output directory as it was.\n\t\tconst flatDir = path.join(staging, \"flat\");\n\t\tyield* fs.makeDirectory(flatDir, { recursive: true });\n\n\t\tfor (const pkg of input.resolution.packages) {\n\t\t\tconst parts = packagePath(pkg.name, pkg.version).split(\"/\");\n\t\t\tyield* linkOrCopy(\n\t\t\t\tpath.join(input.packagesDir, ...parts),\n\t\t\t\tpath.join(flatDir, flatName(pkg.name, pkg.version)),\n\t\t\t);\n\t\t}\n\n\t\tyield* writeBundleMetadata({\n\t\t\tdir: flatDir,\n\t\t\tresolution: input.resolution,\n\t\t\tincluded: input.resolution.packages,\n\t\t\toptions: input.options,\n\t\t\tregistryInfo: input.registryInfo,\n\t\t\tsizes: input.report.sizes,\n\t\t});\n\n\t\tyield* fs.copy(flatDir, input.options.outDir, { overwrite: true }).pipe(\n\t\t\tEffect.mapError(\n\t\t\t\t(cause) =>\n\t\t\t\t\tnew OutputError(input.options.outDir, \"could not write output tree\", {\n\t\t\t\t\t\tcause,\n\t\t\t\t\t}),\n\t\t\t),\n\t\t);\n\n\t\t// One artifact per file, not one for the directory.\n\t\t//\n\t\t// `dir` reports its tree as a single artifact because the tree is the\n\t\t// unit: the paths are what make it importable, so half of it is worth\n\t\t// nothing. Flat has no paths to preserve and every file stands on its\n\t\t// own — `npm publish` takes them one at a time, in any order. Reporting\n\t\t// one artifact there contradicted the directory it had just written, and\n\t\t// the run said \"1 artifact\" over 56 files.\n\t\t//\n\t\t// The manifest and the import guide are counted too: under this layout\n\t\t// they are loose files the run produced, and a count that omitted them\n\t\t// would not match what `ls` shows.\n\t\tconst tarballs: ReadonlyArray<BundleArtifact> = input.resolution.packages.map((pkg) => ({\n\t\t\tkind: ArtifactKind.Archive,\n\t\t\tpath: path.join(input.options.outDir, flatName(pkg.name, pkg.version)),\n\t\t\tbytes: input.report.sizes.get(`${pkg.name}@${pkg.version}`) ?? 0,\n\t\t\tpackageCount: 1,\n\t\t}));\n\n\t\tconst summaries = yield* Effect.forEach([MANIFEST_FILE, README_FILE], (file) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst info = yield* fs.stat(path.join(flatDir, file));\n\t\t\t\treturn {\n\t\t\t\t\tkind: ArtifactKind.File,\n\t\t\t\t\tpath: path.join(input.options.outDir, file),\n\t\t\t\t\tbytes: Number(info.size),\n\t\t\t\t\tpackageCount: 0,\n\t\t\t\t} satisfies BundleArtifact;\n\t\t\t}),\n\t\t);\n\n\t\treturn [...tarballs, ...summaries];\n\t});\n\n/**\n * One tarball per resolved root *version*.\n *\n * Under `--all-versions react@^18` this produces `react-18.0.0.tgz`,\n * `react-18.1.0.tgz` and so on, each independently importable — which is the\n * whole reason to prefer this layout.\n */\nconst emitPerSpec = (\n\tinput: EmitInput,\n\tstaging: string,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path | Progress.Progress | Archiver\n> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\t\tconst index = indexPackages(input.resolution);\n\t\tconst artifacts: Array<BundleArtifact> = [];\n\n\t\tlet counter = 0;\n\t\tfor (const { root, version } of perSpecTargets(input.resolution)) {\n\t\t\t// Declined at the prompt: the existing file stays, and this archive is\n\t\t\t// simply never built. Skipping the staging work too, not just the write.\n\t\t\tif (\n\t\t\t\tinput.options.skipExisting?.has(perSpecArchiveName(root.spec.name, version)) ===\n\t\t\t\ttrue\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst included = includedPackages(index, root.closures.get(version) ?? []);\n\n\t\t\tconst rootDir = path.join(staging, \"roots\", String(counter++));\n\t\t\tyield* fs.makeDirectory(rootDir, { recursive: true });\n\n\t\t\tfor (const pkg of included) {\n\t\t\t\tconst parts = packagePath(pkg.name, pkg.version).split(\"/\");\n\t\t\t\tconst source = path.join(input.packagesDir, ...parts);\n\t\t\t\tconst target = path.join(rootDir, ...parts);\n\t\t\t\tyield* fs.makeDirectory(path.dirname(target), { recursive: true });\n\t\t\t\tyield* linkOrCopy(source, target);\n\t\t\t}\n\n\t\t\tyield* writeBundleMetadata({\n\t\t\t\tdir: rootDir,\n\t\t\t\tresolution: {\n\t\t\t\t\t...input.resolution,\n\t\t\t\t\troots: [{ ...root, versions: [version] }],\n\t\t\t\t},\n\t\t\t\tincluded,\n\t\t\t\toptions: input.options,\n\t\t\t\tregistryInfo: input.registryInfo,\n\t\t\t\tsizes: input.report.sizes,\n\t\t\t});\n\n\t\t\tconst outPath = path.join(\n\t\t\t\tinput.options.outDir,\n\t\t\t\tperSpecArchiveName(root.spec.name, version),\n\t\t\t);\n\n\t\t\tconst result = yield* createArchive({\n\t\t\t\tcwd: rootDir,\n\t\t\t\tentries: yield* topLevelEntries(rootDir),\n\t\t\t\toutPath,\n\t\t\t});\n\n\t\t\tartifacts.push({\n\t\t\t\tkind: ArtifactKind.Archive,\n\t\t\t\tpath: result.path,\n\t\t\t\tbytes: result.bytes,\n\t\t\t\tpackageCount: included.length,\n\t\t\t\tspec: formatSpec(root.spec),\n\t\t\t\tversion,\n\t\t\t});\n\t\t}\n\n\t\treturn artifacts;\n\t});\n\n/* -------------------------------------------------------------------------- */\n/* Helpers */\n/* -------------------------------------------------------------------------- */\n\nconst includedPackages = (\n\tindex: ReadonlyMap<PackageKey, ResolvedPackage>,\n\tclosure: ReadonlyArray<PackageKey>,\n): ReadonlyArray<ResolvedPackage> => closure.flatMap((key) => index.get(key) ?? []);\n\n/**\n * Hard-links a file, falling back to a copy.\n *\n * Hard links make `per-spec` layout nearly free in the staging tree. They fail\n * across devices and on some Windows configurations, so the copy fallback is\n * not optional.\n */\nconst linkOrCopy = (\n\tsource: string,\n\ttarget: string,\n): Effect.Effect<void, PlatformError, FileSystem.FileSystem> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tyield* fs.link(source, target).pipe(Effect.catch(() => fs.copyFile(source, target)));\n\t});\n\n/** Writes the manifest and import guide into a staging directory. */\nconst writeBundleMetadata = (input: {\n\treadonly dir: string;\n\treadonly resolution: Resolution;\n\treadonly included: ReadonlyArray<ResolvedPackage>;\n\treadonly options: BundleContext;\n\treadonly registryInfo: { readonly kind: string; readonly url: string };\n\treadonly sizes: ReadonlyMap<string, number>;\n}): Effect.Effect<void, PlatformError, FileSystem.FileSystem | Path.Path> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\n\t\tconst createdAt = new Date();\n\t\tconst manifest = buildManifest({\n\t\t\tresolution: input.resolution,\n\t\t\tincluded: input.included,\n\t\t\toptions: input.options,\n\t\t\tregistry: input.registryInfo,\n\t\t\ttoolVersion: input.options.toolVersion,\n\t\t\tsizes: input.sizes,\n\t\t\tcreatedAt,\n\t\t});\n\n\t\tyield* fs.writeFileString(path.join(input.dir, MANIFEST_FILE), serializeManifest(manifest));\n\t\tyield* fs.writeFileString(\n\t\t\tpath.join(input.dir, README_FILE),\n\t\t\timportGuide({\n\t\t\t\tpackageCount: input.included.length,\n\t\t\t\tcreatedAt: createdAt.toISOString(),\n\t\t\t\ttoolVersion: input.options.toolVersion,\n\t\t\t\tlayout: input.options.layout,\n\t\t\t}),\n\t\t);\n\t});\n\n/** Sorted top-level entries of a directory, used as the tar entry list. */\nconst topLevelEntries = (\n\tdir: string,\n): Effect.Effect<ReadonlyArray<string>, PlatformError, FileSystem.FileSystem> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst entries = yield* fs.readDirectory(dir);\n\t\treturn entries.toSorted();\n\t});\n\n/**\n * `assertDistinctOutputs`, over package tarballs instead of archives.\n *\n * `flat` is the only layout with nothing but a file name to tell two packages\n * apart — everywhere else a tarball keeps its unique `name/-/` directory. What\n * is left to catch is the pathological pair, `@a/b-c` against `@a-b/c`; the\n * plausible one is impossible by construction, which is what `flatName` buys.\n */\nconst assertDistinctFlatNames = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<void, OutputError> =>\n\tEffect.gen(function* () {\n\t\tif (options.layout !== Layout.Flat) return;\n\n\t\tconst owners = new Map<string, Array<string>>();\n\t\tfor (const pkg of resolution.packages) {\n\t\t\tconst file = flatName(pkg.name, pkg.version);\n\t\t\tconst claimed = owners.get(file);\n\n\t\t\tif (claimed === undefined) owners.set(file, [`${pkg.name}@${pkg.version}`]);\n\t\t\telse claimed.push(`${pkg.name}@${pkg.version}`);\n\t\t}\n\n\t\tconst collisions = [...owners].filter(([, packages]) => packages.length > 1);\n\t\tif (collisions.length === 0) return;\n\n\t\tconst described = collisions\n\t\t\t.map(([file, packages]) => `${packages.join(\" and \")} would both be ${file}`)\n\t\t\t.join(\"; \");\n\n\t\treturn yield* Effect.fail(\n\t\t\tnew OutputError(\n\t\t\t\toptions.outDir,\n\t\t\t\t`two packages want the same file name — ${described}. \\`flat\\` layout has ` +\n\t\t\t\t\t`only the file name to tell them apart, and the \\`/\\` in a scope becomes ` +\n\t\t\t\t\t`a \\`-\\` to make one. Use --layout dir, which keeps each package in its ` +\n\t\t\t\t\t`own directory.`,\n\t\t\t),\n\t\t);\n\t});\n\n/**\n * Two different packages must not want the same file name.\n *\n * Most of what this used to catch is now impossible: an archive is named for\n * the spec, `@types-react@19.2.18.tgz`, and an unscoped npm name may not begin\n * with `@`, so it cannot spell a scoped one. What survives is **two scoped\n * packages whose scope boundary falls in a different place**, because that\n * boundary is the one character the file name drops:\n *\n * @a/b-c -> @a-b-c@1.0.0.tgz\n * @a-b/c -> @a-b-c@1.0.0.tgz\n *\n * Pathological rather than plausible — it needs somebody to hold the `@a-b`\n * scope as well as `@a`, and both packages in one run at one version. It is\n * kept anyway because of what it costs to be wrong: they are *different\n * packages*, so deduplicating them would be wrong, and writing both is worse —\n * the second lands on the first and the run reports two artifacts for the one\n * file that survived. A bundle short a package, called complete, found at the\n * far end of an air gap by somebody who cannot go and fetch the missing one.\n *\n * Nothing else would catch it. The overwrite check below compares this run's\n * planned files against what is *already on disk*, and both of these are new.\n *\n * So it refuses, and names both specs. Not silently renamed: an archive whose\n * name nobody chose is a file somebody has to identify later.\n *\n * Unconditional, unlike the overwrite check: `--force` is permission to replace\n * what was already in the directory, not to let one run overwrite itself.\n */\nconst assertDistinctOutputs = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<void, OutputError> =>\n\tEffect.gen(function* () {\n\t\tconst owners = new Map<string, Array<string>>();\n\n\t\t// Over `plannedOutputs` rather than the per-spec targets, so this asks\n\t\t// about the layout that is actually running. `single` writes one archive\n\t\t// and `dir` two summary files, neither of which can collide — and a check\n\t\t// that refused those would make its own advice impossible to take.\n\t\tfor (const planned of plannedOutputs(resolution, options)) {\n\t\t\tconst claimed = owners.get(planned.file);\n\t\t\tconst spec =\n\t\t\t\tplanned.name === undefined ? planned.file : `${planned.name}@${planned.version}`;\n\n\t\t\tif (claimed === undefined) owners.set(planned.file, [spec]);\n\t\t\telse claimed.push(spec);\n\t\t}\n\n\t\tconst collisions = [...owners].filter(([, specs]) => specs.length > 1);\n\t\tif (collisions.length === 0) return;\n\n\t\tconst described = collisions\n\t\t\t.map(([file, specs]) => `${specs.join(\" and \")} would both be ${file}`)\n\t\t\t.join(\"; \");\n\n\t\treturn yield* Effect.fail(\n\t\t\tnew OutputError(\n\t\t\t\toptions.outDir,\n\t\t\t\t`two packages want the same archive name — ${described}. The \\`/\\` in a ` +\n\t\t\t\t\t`scope becomes a \\`-\\` to make a file name, so \\`@a/b-c\\` and \\`@a-b/c\\` ` +\n\t\t\t\t\t`meet. Use --layout single, or bundle them into separate --out ` +\n\t\t\t\t\t`directories.`,\n\t\t\t),\n\t\t);\n\t});\n\n/**\n * Fails if the run would overwrite something, unless `--force`.\n *\n * The guard is on the *files this run writes*, not on whether the directory has\n * anything in it. An output directory accumulating bundles is the normal way to\n * use this — bundling `esbuild` into an `out/` that already holds `tsdown` is\n * not a conflict, and refusing it made `--out` a single-use directory and the\n * default `.` unusable.\n *\n * Checked before anything is downloaded. Discovering the collision *after* a\n * twenty-minute download would be a uniquely irritating way to fail — which is\n * also why `assertDistinctOutputs` runs from here rather than at emit time.\n */\nconst prepareOutputDir = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<void, OutputError | PlatformError, FileSystem.FileSystem | Path.Path> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\t\tconst outDir = options.outDir;\n\n\t\tyield* assertDistinctOutputs(resolution, options);\n\t\tyield* assertDistinctFlatNames(resolution, options);\n\n\t\tif (!options.force) {\n\t\t\tconst clashes: Array<string> = [];\n\t\t\tfor (const planned of plannedOutputs(resolution, options)) {\n\t\t\t\tif (options.skipExisting?.has(planned.file) === true) continue;\n\t\t\t\tif (options.overwrite?.has(planned.file) === true) continue;\n\t\t\t\tconst exists = yield* fs\n\t\t\t\t\t.exists(path.join(outDir, planned.file))\n\t\t\t\t\t.pipe(Effect.orElseSucceed(() => false));\n\t\t\t\tif (exists) clashes.push(planned.file);\n\t\t\t}\n\n\t\t\tif (clashes.length > 0) {\n\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\tnew OutputError(\n\t\t\t\t\t\toutDir,\n\t\t\t\t\t\t`would overwrite ${clashes.length} existing file${clashes.length === 1 ? \"\" : \"s\"} ` +\n\t\t\t\t\t\t\t`(${clashes.slice(0, 3).join(\", \")}${clashes.length > 3 ? \", …\" : \"\"}). ` +\n\t\t\t\t\t\t\t`Pass --force true to replace ${clashes.length === 1 ? \"it\" : \"them\"}, or choose a different --out.`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tyield* fs\n\t\t\t.makeDirectory(outDir, { recursive: true })\n\t\t\t.pipe(\n\t\t\t\tEffect.mapError(\n\t\t\t\t\t(cause) =>\n\t\t\t\t\t\tnew OutputError(outDir, \"could not create output directory\", { cause }),\n\t\t\t\t),\n\t\t\t);\n\t});\n"],"mappings":";;;;;;;;;;;;;;;AAGA,MAAa,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I,YACH,QAAQ,QACR,6CAA6C,UAAU,qKAIvD,CACD;EACA;;;;;;;;;;;;;;AAeH,MAAM,oBACL,YACA,YAEA,OAAO,IAAI,aAAa;CACvB,MAAM,KAAK,OAAO,WAAW;CAC7B,MAAM,OAAO,OAAO,KAAK;CACzB,MAAM,SAAS,QAAQ;AAEvB,QAAO,sBAAsB,YAAY,QAAQ;AACjD,QAAO,wBAAwB,YAAY,QAAQ;AAEnD,KAAI,CAAC,QAAQ,OAAO;EACnB,MAAMC,UAAyB,EAAE;AACjC,OAAK,MAAM,WAAW,eAAe,YAAY,QAAQ,EAAE;AAC1D,OAAI,QAAQ,cAAc,IAAI,QAAQ,KAAK,KAAK,KAAM;AACtD,OAAI,QAAQ,WAAW,IAAI,QAAQ,KAAK,KAAK,KAAM;AAInD,OAHe,OAAO,GACpB,OAAO,KAAK,KAAK,QAAQ,QAAQ,KAAK,CAAC,CACvC,KAAK,OAAO,oBAAoB,MAAM,CAAC,CAC7B,SAAQ,KAAK,QAAQ,KAAK;;AAGvC,MAAI,QAAQ,SAAS,EACpB,QAAO,OAAO,OAAO,KACpB,IAAI,YACH,QACA,mBAAmB,QAAQ,OAAO,gBAAgB,QAAQ,WAAW,IAAI,KAAK,IAAI,IAC7E,QAAQ,MAAM,GAAG,EAAE,CAAC,KAAK,KAAK,GAAG,QAAQ,SAAS,IAAI,QAAQ,GAAG,kCACrC,QAAQ,WAAW,IAAI,OAAO,OAAO,gCACtE,CACD;;AAIH,QAAO,GACL,cAAc,QAAQ,EAAE,WAAW,MAAM,CAAC,CAC1C,KACA,OAAO,UACL,UACA,IAAI,YAAY,QAAQ,qCAAqC,EAAE,OAAO,CAAC,CACxE,CACD;EACD"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["Layouts: ReadonlyArray<Layout>","out: Record<string, string>","out: Record<string, { optional: boolean }>","specs: Array<PackageSpec>","errors: Array<InvalidSpecError>","out: Array<PackageSpec>","UNSUPPORTED_PROTOCOLS: ReadonlyArray<readonly [string, string]>","allPlatforms: PlatformFilter","osByAlias: Readonly<Record<string, string | undefined>>","KNOWN_OS: ReadonlySet<string>","LIBC: ReadonlySet<string>","defaultScope: DependencyScope","defaultResolveOptions: ResolveOptions","defaultBundleOptions: Omit<BundleOptions, \"outDir\">","hashes: Array<IntegrityHash>","packages: ReadonlyArray<ManifestEntry>","edgesOf","tasks: Array<Task>","warnings: Array<ResolutionWarning>","frontier: ReadonlyArray<Task>","wave: Array<Task>","next: Array<Task>","Progress.emit","hasReason","roots: Array<RootResolution>","compareResolved","Progress.emit","warnings: Array<ResolutionWarning>","addWarning","rootResolutions: Array<RootResolution>","spec: PackageSpec","missing: Array<{ name: string; version: string; detail: string }>","queue: Array<{ key: PackageKey; reason: Reason }>","describeError","ROOT_KINDS","collectEntries","edgesOf","edges: Array<LockedEdge>","collectRoots","workspacePaths","ROOT_KINDS","edgesOf","edges: Array<LockedEdge>","collectRoots","root: unknown","parseYaml","describeError","edges: Array<LockedEdge>","defaultInputFileOptions: InputFileOptions","specs: Array<PackageSpec>","warnings: Array<string>","required: Array<string>","parsed: unknown","Progress.emit","unverified: Array<string>","Integrity.verify","preflight: Effect.Effect<void, BundlerError, Registry | Progress.Progress>","Progress.emit","emit","tarballs: ReadonlyArray<BundleArtifact>","artifacts: Array<BundleArtifact>","clashes: Array<string>"],"sources":["../src/enums/artifact-kind.ts","../src/enums/edge-kind.ts","../src/enums/input-file-kind.ts","../src/enums/layout.ts","../src/enums/lockfile-format.ts","../src/enums/phase.ts","../src/utils/is-record.ts","../src/schemas/lenient.ts","../src/spec.ts","../src/dependency-range.ts","../src/platform.ts","../src/options.ts","../src/registry.ts","../src/integrity.ts","../src/layout.ts","../src/manifest.ts","../src/resolve.ts","../src/locked-resolve.ts","../src/lockfile/json.ts","../src/lockfile/detect.ts","../src/lockfile/names.ts","../src/lockfile/tree-builder.ts","../src/lockfile/bun.ts","../src/lockfile/npm.ts","../src/lockfile/pnpm.ts","../src/lockfile/parse.ts","../src/schemas/package-json.ts","../src/input-file.ts","../src/download.ts","../src/bundle.ts"],"sourcesContent":["import type { ValueOf } from \"../types/value-of.js\";\n\n/** What a bundle run wrote to the output directory. */\nexport const ArtifactKind = {\n\tArchive: \"archive\",\n\tDirectory: \"directory\",\n\t/**\n\t * A loose file that is not an archive — the manifest and the import guide,\n\t * which `dir` and `flat` write beside the tarballs rather than sealing\n\t * inside one.\n\t */\n\tFile: \"file\",\n} as const;\n\nexport type ArtifactKind = ValueOf<typeof ArtifactKind>;\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/**\n * Why one package depends on another.\n *\n * `EdgeKind` and `LockedRootKind` are one concept in two parts, which is why\n * they share a file: `Dev` exists only at the top level, because lockfiles\n * record dev dependencies for the project alone — a transitive devDependency is\n * never installed, so it is never locked.\n */\nexport const EdgeKind = {\n\tProd: \"prod\",\n\tOptional: \"optional\",\n\tPeer: \"peer\",\n} as const;\n\nexport type EdgeKind = ValueOf<typeof EdgeKind>;\n\n/** The kind that only a direct dependency of the locked project can have. */\nexport const DirectOnlyKind = {\n\tDev: \"dev\",\n} as const;\n\nexport type DirectOnlyKind = ValueOf<typeof DirectOnlyKind>;\n\n/** Why a direct dependency of the locked project is a root. */\nexport const LockedRootKind = {\n\t...EdgeKind,\n\t...DirectOnlyKind,\n} as const;\n\nexport type LockedRootKind = ValueOf<typeof LockedRootKind>;\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/** Which of the three shapes a `--file` input turned out to be. */\nexport const InputFileKind = {\n\t/** Bundle everything a package.json depends on. */\n\tPackageJson: \"package.json\",\n\t/** Bundle the exact versions a lockfile pins. */\n\tLockfile: \"lockfile\",\n\t/** A newline-delimited list of specs. */\n\tList: \"list\",\n} as const;\n\nexport type InputFileKind = ValueOf<typeof InputFileKind>;\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/** How the resulting tarball(s) are shaped. */\nexport const Layout = {\n\t/**\n\t * One tarball per requested spec, each carrying its own complete dependency\n\t * closure. Shared dependencies repeat across tarballs, so the total is\n\t * larger — but each one imports, rolls back and hands off independently.\n\t */\n\tPerSpec: \"per-spec\",\n\t/**\n\t * One tarball for everything, with the union of all closures deduplicated.\n\t * Smallest output and a single import step; all-or-nothing to roll back.\n\t */\n\tSingle: \"single\",\n\t/**\n\t * No archive at all — just the npm-layout directory tree, ready for\n\t * `jf rt upload` or rsync.\n\t */\n\tDir: \"dir\",\n\t/**\n\t * Every tarball side by side in one directory — no archive, and no\n\t * `name/-/` nesting. For tooling that globs `*.tgz` out of one directory\n\t * rather than walking a registry tree.\n\t */\n\tFlat: \"flat\",\n} as const;\n\nexport type Layout = ValueOf<typeof Layout>;\n\nexport const Layouts: ReadonlyArray<Layout> = Object.values(Layout);\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/** Which package manager wrote a lockfile. */\nexport const LockfileFormat = {\n\tNpm: \"npm\",\n\tPnpm: \"pnpm\",\n\tBun: \"bun\",\n} as const;\n\nexport type LockfileFormat = ValueOf<typeof LockfileFormat>;\n","import type { ValueOf } from \"../types/value-of.js\";\n\n/** The phases a bundle run moves through, in order. */\nexport const Phase = {\n\tPreflight: \"preflight\",\n\tResolve: \"resolve\",\n\tDownload: \"download\",\n\tArchive: \"archive\",\n\tDone: \"done\",\n} as const;\n\nexport type Phase = ValueOf<typeof Phase>;\n","/**\n * Narrows an unknown value to a plain object.\n *\n * The entry point for reading anything the tool does not control — lockfiles,\n * package.json files, registry responses — without reaching for a cast.\n */\nexport const isRecord = (value: unknown): value is Record<string, unknown> =>\n\ttypeof value === \"object\" && value !== null && !Array.isArray(value);\n","/**\n * Schemas for JSON nobody controls.\n *\n * Registry responses, lockfiles and hand-edited package.json files all arrive\n * as untyped JSON, and the rule at every one of those boundaries is the same:\n * drop what cannot be understood, keep the rest. A bundler that rejects a\n * packument because one published version carries a field it has never seen is\n * useless against exactly the private registries it exists to serve.\n *\n * Effect Schema does the narrowing, which is what keeps those boundaries free\n * of casts and hand-rolled `typeof` ladders. What this module adds on top of\n * the stock combinators is that tolerance: `Schema.Record(String, String)`\n * fails the whole record over one numeric value, where the wire format wants\n * that entry skipped and its neighbours kept.\n */\nimport * as Effect from \"effect/Effect\";\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\nimport * as Getter from \"effect/SchemaGetter\";\n\nimport { isRecord } from \"../utils/is-record.js\";\n\n/**\n * An optional field that goes *absent* rather than failing when it is\n * malformed.\n *\n * This is the difference between \"we do not understand this field\" and \"we do\n * not understand this document\". An `os: \"linux\"` where an array was expected\n * costs the platform filter one signal; it should not cost the run the package.\n */\nexport const tolerant = <S extends Schema.Top>(schema: S) =>\n\tSchema.optional(\n\t\tSchema.UndefinedOr(schema).pipe(\n\t\t\tSchema.catchDecoding(() => Effect.succeed(Option.some(undefined))),\n\t\t),\n\t);\n\n/**\n * Keeps only the string-valued members of an untyped object.\n *\n * `{ \"lodash\": \"^4.0.0\", \"broken\": 3 }` decodes to `{ \"lodash\": \"^4.0.0\" }`.\n * Per-entry rather than whole-record tolerance, because one unreadable edge in\n * a dependency block is no reason to forget the others.\n */\nexport const StringRecordSchema = Schema.Record(Schema.String, Schema.Unknown).pipe(\n\tSchema.decodeTo(Schema.Record(Schema.String, Schema.String), {\n\t\tdecode: Getter.transform((raw: Record<string, unknown>) => {\n\t\t\tconst out: Record<string, string> = {};\n\t\t\tfor (const [key, value] of Object.entries(raw)) {\n\t\t\t\tif (typeof value === \"string\") out[key] = value;\n\t\t\t}\n\t\t\treturn out;\n\t\t}),\n\t\tencode: Getter.passthroughSubtype(),\n\t}),\n);\n\n/** The same per-entry tolerance for a list: `[\"linux\", 7]` decodes to `[\"linux\"]`. */\nexport const StringArraySchema = Schema.Array(Schema.Unknown).pipe(\n\tSchema.decodeTo(Schema.Array(Schema.String), {\n\t\tdecode: Getter.transform((raw: ReadonlyArray<unknown>) =>\n\t\t\traw.flatMap((entry) => (typeof entry === \"string\" ? entry : [])),\n\t\t),\n\t\tencode: Getter.passthroughSubtype(),\n\t}),\n);\n\n/**\n * `peerDependenciesMeta`, normalised.\n *\n * Only `optional` is read, and only its `true` is meaningful — npm writes the\n * flag as a boolean, a hand-edited file may carry anything, and every other\n * value means \"not optional\".\n */\nexport const OptionalFlagRecordSchema = Schema.Record(Schema.String, Schema.Unknown).pipe(\n\tSchema.decodeTo(Schema.Record(Schema.String, Schema.Struct({ optional: Schema.Boolean })), {\n\t\tdecode: Getter.transform((raw: Record<string, unknown>) => {\n\t\t\tconst out: Record<string, { optional: boolean }> = {};\n\t\t\tfor (const [key, value] of Object.entries(raw)) {\n\t\t\t\tif (isRecord(value)) out[key] = { optional: value[\"optional\"] === true };\n\t\t\t}\n\t\t\treturn out;\n\t\t}),\n\t\tencode: Getter.passthroughSubtype(),\n\t}),\n);\n\n/*\n * The `Optional…` variants below decode an empty result to `undefined`.\n *\n * Absent has to stay absent. `dependencies: {}` and no `dependencies` at all\n * read the same to the resolver, but the first one travels into a bundle\n * manifest claiming the registry published an empty block — a difference\n * somebody diffing two manifests has to explain.\n */\n\nconst absentWhenEmpty = <T extends Record<string, unknown>>(value: T): T | undefined =>\n\tObject.keys(value).length > 0 ? value : undefined;\n\nexport const OptionalStringRecordSchema = StringRecordSchema.pipe(\n\tSchema.decodeTo(Schema.UndefinedOr(Schema.Record(Schema.String, Schema.String)), {\n\t\tdecode: Getter.transform(absentWhenEmpty<Record<string, string>>),\n\t\tencode: Getter.transform((value: Record<string, string> | undefined) => value ?? {}),\n\t}),\n);\n\nexport const OptionalStringArraySchema = StringArraySchema.pipe(\n\tSchema.decodeTo(Schema.UndefinedOr(Schema.Array(Schema.String)), {\n\t\tdecode: Getter.transform((value: ReadonlyArray<string>) =>\n\t\t\tvalue.length > 0 ? value : undefined,\n\t\t),\n\t\tencode: Getter.transform((value: ReadonlyArray<string> | undefined) => value ?? []),\n\t}),\n);\n\nexport const OptionalFlagRecordOrAbsentSchema = OptionalFlagRecordSchema.pipe(\n\tSchema.decodeTo(\n\t\tSchema.UndefinedOr(\n\t\t\tSchema.Record(Schema.String, Schema.Struct({ optional: Schema.Boolean })),\n\t\t),\n\t\t{\n\t\t\tdecode: Getter.transform(\n\t\t\t\tabsentWhenEmpty<Record<string, { readonly optional: boolean }>>,\n\t\t\t),\n\t\t\tencode: Getter.transform(\n\t\t\t\t(value: Record<string, { readonly optional: boolean }> | undefined) => value ?? {},\n\t\t\t),\n\t\t},\n\t),\n);\n","/**\n * Parsing and validation of package specs — the `lodash`, `react@18.2.0`,\n * `@babel/core@^7`, `typescript@next` strings a user types.\n *\n * Deliberately dependency-light and synchronous: parsing must never touch the\n * network, so `--dry-run` and argument validation stay instant.\n */\nimport semver from \"semver\";\n\nimport { InvalidSpecError } from \"./errors.js\";\n\n/** How a spec narrows down which version(s) of a package we want. */\nexport type Selector =\n\t/** An exact, fully-qualified version: `react@18.2.0`. */\n\t| { readonly _tag: \"Exact\"; readonly version: string }\n\t/** A semver range: `react@^18`, `react@>=17 <19`, `react@*`. */\n\t| { readonly _tag: \"Range\"; readonly range: string }\n\t/** A dist-tag: `react@latest`, `typescript@next`. */\n\t| { readonly _tag: \"Tag\"; readonly tag: string };\n\n/** A parsed, validated package spec. */\nexport type PackageSpec = {\n\t/** The npm package name, including scope. */\n\treadonly name: string;\n\t/** What the user asked for after the `@`. */\n\treadonly selector: Selector;\n\t/** The original string, kept verbatim for error messages and the manifest. */\n\treadonly raw: string;\n};\n\nconst MAX_NAME_LENGTH = 214;\n\n// The registry accepts URL-safe characters plus `-`, `.` and `_`.\nconst SEGMENT_RE = /^[a-z0-9\\-._~]+$/;\n\nconst DIST_TAG_RE = /^[a-zA-Z0-9][a-zA-Z0-9._-]*$/;\n\n/** Renders a spec back into the canonical `name@selector` form. */\nexport const formatSpec = (spec: PackageSpec): string =>\n\t`${spec.name}@${formatSelector(spec.selector)}`;\n\n/** Human-readable form of just the selector part. */\nexport const formatSelector = (selector: Selector): string => {\n\tswitch (selector._tag) {\n\t\tcase \"Exact\":\n\t\t\treturn selector.version;\n\t\tcase \"Range\":\n\t\t\treturn selector.range;\n\t\tcase \"Tag\":\n\t\t\treturn selector.tag;\n\t}\n};\n\n/**\n * Validates an npm package name against the rules the registry actually\n * enforces. Returns `null` when valid, or the reason it is not.\n */\nexport const validatePackageName = (name: string): string | null => {\n\tif (name.length === 0) return \"name is empty\";\n\tif (name.length > MAX_NAME_LENGTH) {\n\t\treturn `name is longer than ${MAX_NAME_LENGTH} characters`;\n\t}\n\tif (name.trim() !== name) return \"name has leading or trailing whitespace\";\n\tif (name.startsWith(\".\")) return \"name cannot start with a period\";\n\tif (name.startsWith(\"_\")) return \"name cannot start with an underscore\";\n\tif (name !== name.toLowerCase()) return \"name cannot contain capital letters\";\n\n\tif (name.startsWith(\"@\")) {\n\t\tconst slash = name.indexOf(\"/\");\n\t\tif (slash === -1) return \"scoped name is missing the '/name' part\";\n\t\tconst scope = name.slice(1, slash);\n\t\tconst rest = name.slice(slash + 1);\n\t\tif (scope.length === 0) return \"scope is empty\";\n\t\tif (rest.length === 0) return \"name after the scope is empty\";\n\t\tif (rest.includes(\"/\")) return \"name contains more than one '/'\";\n\t\tif (!SEGMENT_RE.test(scope)) return `scope \"${scope}\" contains illegal characters`;\n\t\tif (!SEGMENT_RE.test(rest)) return `name \"${rest}\" contains illegal characters`;\n\t\treturn null;\n\t}\n\n\tif (name.includes(\"/\")) return \"unscoped name cannot contain '/'\";\n\tif (!SEGMENT_RE.test(name)) return \"name contains illegal characters\";\n\treturn null;\n};\n\n/**\n * Parses a single spec string.\n *\n * Splitting on `@` is the fiddly part: a scoped name *starts* with `@`, so we\n * look for the last `@` that is not at index 0.\n */\nexport const parseSpec = (raw: string): PackageSpec => {\n\tconst input = raw.trim();\n\tif (input.length === 0) {\n\t\tthrow new InvalidSpecError(raw, \"spec is empty\");\n\t}\n\n\tconst at = input.lastIndexOf(\"@\");\n\tconst hasSelector = at > 0;\n\tconst name = hasSelector ? input.slice(0, at) : input;\n\tconst selectorText = hasSelector ? input.slice(at + 1) : \"\";\n\n\tconst nameProblem = validatePackageName(name);\n\tif (nameProblem !== null) {\n\t\tthrow new InvalidSpecError(raw, nameProblem);\n\t}\n\n\tif (!hasSelector || selectorText.length === 0) {\n\t\treturn { name, selector: { _tag: \"Tag\", tag: \"latest\" }, raw: input };\n\t}\n\n\treturn { name, selector: parseSelector(raw, selectorText), raw: input };\n};\n\n/** Classifies the part after the `@` as an exact version, a range, or a dist-tag. */\nexport const parseSelector = (raw: string, text: string): Selector => {\n\t// `semver.valid` only accepts a complete `x.y.z`, which is exactly the\n\t// \"pin me to this one version\" case.\n\tconst exact = semver.valid(text, { loose: false });\n\tif (exact !== null) {\n\t\treturn { _tag: \"Exact\", version: exact };\n\t}\n\n\tif (semver.validRange(text, { loose: false }) !== null) {\n\t\treturn { _tag: \"Range\", range: text };\n\t}\n\n\t// Anything left has to be a dist-tag. Tags may not look like versions and\n\t// may not contain characters that would break a registry URL.\n\tif (!DIST_TAG_RE.test(text)) {\n\t\tthrow new InvalidSpecError(\n\t\t\traw,\n\t\t\t`\"${text}\" is not a valid version, semver range, or dist-tag`,\n\t\t);\n\t}\n\treturn { _tag: \"Tag\", tag: text };\n};\n\n/**\n * Parses many specs, collecting *every* failure rather than stopping at the\n * first. Somebody bundling forty packages should be told about all four typos\n * in one go, not made to re-run four times.\n */\nexport const parseSpecs = (\n\tinputs: ReadonlyArray<string>,\n): {\n\treadonly specs: ReadonlyArray<PackageSpec>;\n\treadonly errors: ReadonlyArray<InvalidSpecError>;\n} => {\n\tconst specs: Array<PackageSpec> = [];\n\tconst errors: Array<InvalidSpecError> = [];\n\tfor (const input of inputs) {\n\t\ttry {\n\t\t\tspecs.push(parseSpec(input));\n\t\t} catch (error) {\n\t\t\tif (error instanceof InvalidSpecError) {\n\t\t\t\terrors.push(error);\n\t\t\t} else {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t}\n\t}\n\treturn { specs, errors };\n};\n\n/**\n * Collapses duplicate specs, keeping the first occurrence.\n *\n * `npmb react react@latest` is a plausible thing to type and should not\n * download React twice.\n */\nexport const dedupeSpecs = (specs: ReadonlyArray<PackageSpec>): ReadonlyArray<PackageSpec> => {\n\tconst seen = new Set<string>();\n\tconst out: Array<PackageSpec> = [];\n\tfor (const spec of specs) {\n\t\tconst key = formatSpec(spec);\n\t\tif (seen.has(key)) continue;\n\t\tseen.add(key);\n\t\tout.push(spec);\n\t}\n\treturn out;\n};\n","/**\n * Classification of the right-hand side of a dependency entry.\n *\n * `\"dependencies\": { \"x\": \"^1.0.0\" }` is the easy case. Real package.json files\n * also contain aliases, git URLs, tarball URLs, `file:` links and\n * `workspace:` protocols — none of which can be fetched from a registry.\n *\n * Rather than crashing or silently producing a bundle that will not install,\n * we classify each edge and let the caller report precisely what was skipped\n * and why.\n */\nimport semver from \"semver\";\n\nimport type { Selector } from \"./spec.js\";\n\n/** What a dependency edge points at. */\nexport type DependencyTarget =\n\t/** A normal registry dependency. `name` may differ from the key under an alias. */\n\t| {\n\t\t\treadonly _tag: \"Registry\";\n\t\t\treadonly name: string;\n\t\t\treadonly selector: Selector;\n\t\t\t/** Set when the edge is an `npm:` alias, e.g. `\"lodash4\": \"npm:lodash@^4\"`. */\n\t\t\treadonly aliasOf?: string | undefined;\n\t }\n\t/** Something we cannot fetch from a registry. */\n\t| {\n\t\t\treadonly _tag: \"Unsupported\";\n\t\t\treadonly name: string;\n\t\t\treadonly raw: string;\n\t\t\treadonly reason: string;\n\t };\n\nconst UNSUPPORTED_PROTOCOLS: ReadonlyArray<readonly [string, string]> = [\n\t[\"file:\", \"local file path\"],\n\t[\"link:\", \"local link\"],\n\t[\"workspace:\", \"workspace protocol\"],\n\t[\"portal:\", \"portal protocol\"],\n\t[\"patch:\", \"patch protocol\"],\n\t[\"git:\", \"git dependency\"],\n\t[\"git+\", \"git dependency\"],\n\t[\"github:\", \"GitHub shorthand\"],\n\t[\"gitlab:\", \"GitLab shorthand\"],\n\t[\"bitbucket:\", \"Bitbucket shorthand\"],\n\t[\"http:\", \"remote tarball URL\"],\n\t[\"https:\", \"remote tarball URL\"],\n];\n\n/**\n * Classifies one `name -> range` entry.\n *\n * An empty range, `*`, and `latest` all mean \"any published version\"; npm\n * treats them interchangeably and so do we.\n */\nexport const parseDependencyTarget = (name: string, raw: string): DependencyTarget => {\n\tconst text = raw.trim();\n\n\tif (text.length === 0 || text === \"*\" || text === \"x\" || text === \"latest\") {\n\t\treturn { _tag: \"Registry\", name, selector: { _tag: \"Range\", range: \"*\" } };\n\t}\n\n\tif (text.startsWith(\"npm:\")) {\n\t\treturn parseAlias(name, text);\n\t}\n\n\tfor (const [prefix, reason] of UNSUPPORTED_PROTOCOLS) {\n\t\tif (text.startsWith(prefix)) {\n\t\t\treturn { _tag: \"Unsupported\", name, raw: text, reason };\n\t\t}\n\t}\n\n\t// Bare `owner/repo` is GitHub shorthand, but only when it is not a valid\n\t// range — `>=1.0.0/2` is not a thing, so this ordering is safe.\n\tif (semver.validRange(text, { loose: true }) === null && /^[\\w.-]+\\/[\\w.-]+/.test(text)) {\n\t\treturn { _tag: \"Unsupported\", name, raw: text, reason: \"git shorthand\" };\n\t}\n\n\tconst exact = semver.valid(text, { loose: true });\n\tif (exact !== null) {\n\t\treturn { _tag: \"Registry\", name, selector: { _tag: \"Exact\", version: exact } };\n\t}\n\n\tif (semver.validRange(text, { loose: true }) !== null) {\n\t\treturn { _tag: \"Registry\", name, selector: { _tag: \"Range\", range: text } };\n\t}\n\n\t// Whatever is left is most plausibly a dist-tag published by a private\n\t// registry, e.g. `\"@acme/sdk\": \"stable\"`.\n\tif (/^[a-zA-Z0-9][a-zA-Z0-9._-]*$/.test(text)) {\n\t\treturn { _tag: \"Registry\", name, selector: { _tag: \"Tag\", tag: text } };\n\t}\n\n\treturn { _tag: \"Unsupported\", name, raw: text, reason: \"unrecognised version specifier\" };\n};\n\n/**\n * Parses `npm:<name>[@<range>]`.\n *\n * The nested name may itself be scoped, so the `@` split has the same\n * \"not at index 0\" caveat as top-level spec parsing.\n */\nconst parseAlias = (key: string, text: string): DependencyTarget => {\n\tconst body = text.slice(\"npm:\".length);\n\tif (body.length === 0) {\n\t\treturn { _tag: \"Unsupported\", name: key, raw: text, reason: \"empty npm: alias\" };\n\t}\n\n\tconst at = body.lastIndexOf(\"@\");\n\tconst target = at > 0 ? body.slice(0, at) : body;\n\tconst rangeText = at > 0 ? body.slice(at + 1) : \"\";\n\n\tif (target.length === 0) {\n\t\treturn { _tag: \"Unsupported\", name: key, raw: text, reason: \"empty npm: alias target\" };\n\t}\n\n\tconst inner = parseDependencyTarget(target, rangeText);\n\tif (inner._tag === \"Unsupported\") {\n\t\treturn { ...inner, name: key, raw: text };\n\t}\n\treturn { _tag: \"Registry\", name: target, selector: inner.selector, aliasOf: key };\n};\n","/**\n * Platform matching for optional dependencies.\n *\n * The default is \"keep every platform\" and narrowing is opt-in — see\n * `notes/requirements.md` § FR-13 for the failure mode that decides it.\n *\n * The mechanics that decision rests on are here rather than there: a package\n * declares `os`, `cpu` and `libc` in its own manifest, and this module keeps a\n * package when the filter *could* install it, not when it matches exactly.\n */\n\n/** A target to keep, e.g. `linux-x64`, `linux-x64-musl`, or just `linux`. */\nexport type PlatformTarget = {\n\treadonly os: string;\n\t/** Undefined means \"every architecture for this OS\". */\n\treadonly cpu?: string | undefined;\n\t/** `glibc` / `musl`. Undefined means \"don't care\". */\n\treadonly libc?: string | undefined;\n};\n\n/**\n * Which platforms optional dependencies should be resolved for.\n *\n * - `All` — keep everything, regardless of `os`/`cpu`/`libc` (the default).\n * - `Targets` — keep only packages that could install on one of these.\n */\nexport type PlatformFilter =\n\t| { readonly _tag: \"All\" }\n\t| { readonly _tag: \"Targets\"; readonly targets: ReadonlyArray<PlatformTarget> };\n\n/** Constraints declared by a package, as they appear in its manifest. */\nexport type PlatformConstraints = {\n\treadonly os?: ReadonlyArray<string> | undefined;\n\treadonly cpu?: ReadonlyArray<string> | undefined;\n\treadonly libc?: ReadonlyArray<string> | undefined;\n};\n\nexport const allPlatforms: PlatformFilter = { _tag: \"All\" };\n\nexport const platformTargets = (targets: ReadonlyArray<PlatformTarget>): PlatformFilter => ({\n\t_tag: \"Targets\",\n\ttargets,\n});\n\n/**\n * npm's documented `os` values, plus the names people actually type.\n *\n * An OS on its own is a valid target, so a typo has to be caught here — the\n * whole failure mode this tool exists to prevent is a bundle that looks fine\n * and installs nothing. `--platform windows` silently matching no binding at\n * all would be precisely that, so it is corrected rather than accepted.\n */\nconst osByAlias: Readonly<Record<string, string | undefined>> = {\n\twin: \"win32\",\n\twindows: \"win32\",\n\tmac: \"darwin\",\n\tmacos: \"darwin\",\n\tosx: \"darwin\",\n};\n\nconst KNOWN_OS: ReadonlySet<string> = new Set([\n\t\"aix\",\n\t\"android\",\n\t\"cygwin\",\n\t\"darwin\",\n\t\"freebsd\",\n\t\"haiku\",\n\t\"linux\",\n\t\"netbsd\",\n\t\"openbsd\",\n\t\"sunos\",\n\t\"win32\",\n]);\n\nconst LIBC: ReadonlySet<string> = new Set([\"musl\", \"glibc\"]);\n\n/**\n * Parses `linux`, `linux-x64`, `darwin-arm64`, `win32-x64`, `linux-x64-musl`,\n * `linux-musl`.\n *\n * An OS on its own means every architecture for that OS, which is almost always\n * what you want: \"the Windows and Linux bindings\" is a far more natural way to\n * describe a target set than enumerating four `os-arch` pairs, and it keeps\n * working when a package adds an arm64 build.\n *\n * Returns `null` rather than throwing so the CLI can report every bad value at\n * once alongside the list of accepted forms.\n */\nexport const parsePlatformTarget = (input: string): PlatformTarget | null => {\n\tconst parts = input\n\t\t.trim()\n\t\t.toLowerCase()\n\t\t.split(\"-\")\n\t\t.filter((part) => part.length > 0);\n\tconst [rawOs, second, third] = parts;\n\tif (rawOs === undefined || parts.length > 3) return null;\n\n\tconst os = osByAlias[rawOs] ?? rawOs;\n\tif (!KNOWN_OS.has(os)) return null;\n\n\tif (second === undefined) return { os };\n\n\t// `linux-musl` is an OS plus a libc, not an OS plus an architecture.\n\tif (third === undefined) {\n\t\treturn LIBC.has(second) ? { os, libc: second } : { os, cpu: second };\n\t}\n\n\tif (!LIBC.has(third)) return null;\n\treturn { os, cpu: second, libc: third };\n};\n\n/**\n * npm's `os`/`cpu`/`libc` fields use a list of allowed values, where a leading\n * `!` negates. An empty or absent list means \"no constraint\".\n *\n * The semantics npm implements: if any negated entry matches, reject. Otherwise\n * if there are any positive entries, at least one must match.\n */\nconst listAllows = (list: ReadonlyArray<string> | undefined, value: string): boolean => {\n\tif (list === undefined || list.length === 0) return true;\n\n\tlet hasPositive = false;\n\tlet positiveMatched = false;\n\n\tfor (const entry of list) {\n\t\tconst normalized = entry.trim().toLowerCase();\n\t\tif (normalized.length === 0) continue;\n\t\tif (normalized === \"any\" || normalized === \"*\") return true;\n\n\t\tif (normalized.startsWith(\"!\")) {\n\t\t\tif (normalized.slice(1) === value) return false;\n\t\t} else {\n\t\t\thasPositive = true;\n\t\t\tif (normalized === value) positiveMatched = true;\n\t\t}\n\t}\n\n\treturn hasPositive ? positiveMatched : true;\n};\n\n/** Would this package install on this specific target? */\nexport const matchesTarget = (\n\tconstraints: PlatformConstraints,\n\ttarget: PlatformTarget,\n): boolean => {\n\tif (!listAllows(constraints.os, target.os)) return false;\n\t// An undefined cpu means the target is the whole OS, so any architecture the\n\t// package declares qualifies.\n\tif (target.cpu !== undefined && !listAllows(constraints.cpu, target.cpu)) return false;\n\tif (target.libc !== undefined && !listAllows(constraints.libc, target.libc)) return false;\n\treturn true;\n};\n\n/**\n * Should this package be included, given the active filter?\n *\n * Under `All` this is unconditionally `true` — that is the whole point.\n */\nexport const isIncluded = (constraints: PlatformConstraints, filter: PlatformFilter): boolean => {\n\tif (filter._tag === \"All\") return true;\n\treturn filter.targets.some((target) => matchesTarget(constraints, target));\n};\n\n/** Renders a filter for the manifest and for `--dry-run` output. */\nexport const formatPlatformFilter = (filter: PlatformFilter): string => {\n\tif (filter._tag === \"All\") return \"all\";\n\treturn filter.targets\n\t\t.map((target) =>\n\t\t\t[target.os, target.cpu, target.libc].filter((part) => part !== undefined).join(\"-\"),\n\t\t)\n\t\t.join(\",\");\n};\n","/**\n * Option types shared by the resolver and the bundler, plus their defaults.\n *\n * The rule the defaults below are derived from is stated once, beside the flags\n * that expose them — see `descriptors.ts` in `@packall/cli`, and\n * `notes/requirements.md` § FR-13.\n */\nimport { Layout } from \"./enums/layout.js\";\nimport type { PlatformFilter } from \"./platform.js\";\nimport { allPlatforms } from \"./platform.js\";\n\n/** Which dependency edges the resolver follows. */\nexport type DependencyScope = {\n\t/**\n\t * Follow `optionalDependencies`. On by default — this is where per-platform\n\t * native binaries live, and omitting them is the most common reason an\n\t * offline install fails on a machine other than the one that built it.\n\t */\n\treadonly optional: boolean;\n\t/**\n\t * Follow non-optional `peerDependencies`. On by default, because npm 7+\n\t * auto-installs peers and will reach for the network if they are absent.\n\t */\n\treadonly peer: boolean;\n\t/** Which platforms optional dependencies are kept for. */\n\treadonly platforms: PlatformFilter;\n};\n\nexport const defaultScope: DependencyScope = {\n\toptional: true,\n\tpeer: true,\n\tplatforms: allPlatforms,\n};\n\n/** Options governing version selection and the dependency walk. */\nexport type ResolveOptions = {\n\treadonly scope: DependencyScope;\n\t/**\n\t * When a root spec is a range, take *every* published version that satisfies\n\t * it rather than only the best match.\n\t *\n\t * `npmb react@^18` bundles one version; `npmb --all-versions react@^18`\n\t * bundles all of them.\n\t */\n\treadonly allVersions: boolean;\n\t/** With `allVersions`, keep at most this many (newest first). */\n\treadonly maxVersions?: number | undefined;\n\t/** Let prereleases satisfy ranges that would not normally admit them. */\n\treadonly includePrerelease: boolean;\n\t/** How many registry requests to have in flight at once. */\n\treadonly concurrency: number;\n};\n\nexport const defaultResolveOptions: ResolveOptions = {\n\tscope: defaultScope,\n\tallVersions: false,\n\tincludePrerelease: false,\n\tconcurrency: 10,\n};\n\n/** Options for a full bundle run. */\nexport type BundleOptions = ResolveOptions & {\n\treadonly layout: Layout;\n\t/** Directory the finished artifacts are written to. */\n\treadonly outDir: string;\n\t/** Base name for the archive in `single` layout. Defaults to `bundle`. */\n\treadonly archiveName?: string | undefined;\n\t/** Resolve and report, but download nothing and write nothing. */\n\treadonly dryRun: boolean;\n\t/**\n\t * Verify every tarball against the checksum the registry advertised.\n\t *\n\t * On by default and there is essentially no good reason to turn it off; the\n\t * escape hatch exists only for registries that serve broken metadata.\n\t */\n\treadonly verifyIntegrity: boolean;\n\t/** Overwrite existing files in `outDir` instead of refusing. */\n\treadonly force: boolean;\n\t/**\n\t * Planned output files to leave untouched, by file name.\n\t *\n\t * The engine never asks anything; deciding is the caller's job. The CLI's\n\t * `--force prompt` resolves its per-file answers into this set, so \"keep the\n\t * existing one\" means that artifact is simply not produced, and the rest of\n\t * the run continues.\n\t */\n\treadonly skipExisting?: ReadonlySet<string> | undefined;\n\t/**\n\t * Planned output files that may be replaced, by file name.\n\t *\n\t * A narrower `force`: `--force tsdown` says \"replace tsdown's bundle, and\n\t * still ask about anything else\".\n\t */\n\treadonly overwrite?: ReadonlySet<string> | undefined;\n};\n\nexport const defaultBundleOptions: Omit<BundleOptions, \"outDir\"> = {\n\t...defaultResolveOptions,\n\tlayout: Layout.PerSpec,\n\tdryRun: false,\n\tverifyIntegrity: true,\n\tforce: false,\n};\n","/**\n * The registry seam.\n *\n * This is the **only** place in the engine that knows a registry exists.\n * Everything downstream — range resolution, the dependency walk, layout,\n * archiving — is expressed against these three operations, so swapping npm for\n * something else means implementing this interface and nothing more.\n *\n * `@packall/registry-npm` provides the implementation that speaks the plain\n * npm registry protocol, which is what Artifactory, Nexus, Verdaccio, GitHub\n * Packages and registry.npmjs.org all serve.\n */\nimport * as Context from \"effect/Context\";\nimport type * as Effect from \"effect/Effect\";\n\nimport type { BundlerError } from \"./errors.js\";\n\n/** Where the tarball lives and how to prove it arrived intact. */\nexport type PackageDist = {\n\treadonly tarball: string;\n\t/** SRI string, e.g. `sha512-...`. Preferred over `shasum`. */\n\treadonly integrity?: string | undefined;\n\t/** Legacy hex sha1. Still the only checksum on very old versions. */\n\treadonly shasum?: string | undefined;\n\treadonly unpackedSize?: number | undefined;\n\treadonly fileCount?: number | undefined;\n};\n\n/**\n * A single published version, as the registry describes it.\n *\n * This is a narrowed view of a package.json — only the fields that affect what\n * has to be downloaded. Unknown fields are ignored rather than rejected,\n * because registries add metadata over time and a bundler that breaks on new\n * metadata is worse than useless.\n */\nexport type PackageManifest = {\n\treadonly name: string;\n\treadonly version: string;\n\n\treadonly dependencies?: Readonly<Record<string, string>> | undefined;\n\treadonly optionalDependencies?: Readonly<Record<string, string>> | undefined;\n\treadonly peerDependencies?: Readonly<Record<string, string>> | undefined;\n\treadonly peerDependenciesMeta?:\n\t\t| Readonly<Record<string, { readonly optional?: boolean | undefined }>>\n\t\t| undefined;\n\treadonly devDependencies?: Readonly<Record<string, string>> | undefined;\n\treadonly bundleDependencies?: ReadonlyArray<string> | undefined;\n\n\t/** Platform constraints, used when `--platform` narrows optional deps. */\n\treadonly os?: ReadonlyArray<string> | undefined;\n\treadonly cpu?: ReadonlyArray<string> | undefined;\n\treadonly libc?: ReadonlyArray<string> | undefined;\n\n\treadonly deprecated?: string | undefined;\n\n\treadonly dist: PackageDist;\n};\n\n/** Everything the registry knows about one package. */\nexport type Packument = {\n\treadonly name: string;\n\t/** `{ latest: \"1.2.3\", next: \"2.0.0-beta.1\" }` */\n\treadonly distTags: Readonly<Record<string, string>>;\n\t/** Every published version, keyed by version string. */\n\treadonly versions: Readonly<Record<string, PackageManifest>>;\n};\n\nexport declare namespace Registry {\n\t/** The set of operations a registry backend has to provide. */\n\texport type Service = {\n\t\t/** Short identifier for the manifest and for error messages, e.g. `\"npm\"`. */\n\t\treadonly kind: string;\n\n\t\t/**\n\t\t * The registry URL that will actually be used for a given package, after\n\t\t * per-scope configuration is applied. Used for reporting only.\n\t\t */\n\t\treadonly registryFor: (packageName: string) => string;\n\n\t\t/**\n\t\t * Cheap liveness check, run once before any real work.\n\t\t *\n\t\t * This is what turns \"hangs forever behind a dead VPN\" into a five-second\n\t\t * error naming the host we could not reach.\n\t\t */\n\t\treadonly preflight: Effect.Effect<void, BundlerError>;\n\n\t\t/**\n\t\t * Full metadata for a package. Implementations are expected to memoise:\n\t\t * the dependency walk asks for the same popular packages repeatedly.\n\t\t */\n\t\treadonly packument: (packageName: string) => Effect.Effect<Packument, BundlerError>;\n\n\t\t/** Fetches the tarball bytes for one published version. */\n\t\treadonly download: (manifest: PackageManifest) => Effect.Effect<Uint8Array, BundlerError>;\n\t};\n}\n\n/**\n * Service tag for the registry backend.\n *\n * @example\n * ```ts\n * import { Effect } from \"effect\"\n * import { Registry } from \"@packall/core\"\n *\n * const program = Effect.gen(function*() {\n * const registry = yield* Registry\n * return yield* registry.packument(\"lodash\")\n * })\n * ```\n */\nexport class Registry extends Context.Service<Registry, Registry.Service>()(\n\t\"@packall/core/Registry\",\n) {}\n","/**\n * Checksum verification for downloaded tarballs.\n *\n * A failed check discards the download rather than warning and carrying on —\n * see `notes/requirements.md` § FR-9 for why that strictness is a requirement\n * rather than a preference.\n *\n * Built on Effect's `Crypto` service rather than `node:crypto` directly. The\n * four digests `Crypto` offers — SHA-1, SHA-256, SHA-384, SHA-512 — are exactly\n * the four npm publishes, so nothing is given up, and the same verification\n * then runs unchanged against WebCrypto in a browser. Parsing stays here\n * because the subset of Subresource Integrity npm actually emits is small and\n * entirely mechanical; `ssri` would be a dependency for a regex.\n */\nimport * as Crypto from \"effect/Crypto\";\nimport * as Effect from \"effect/Effect\";\nimport * as Encoding from \"effect/Encoding\";\nimport type { PlatformError } from \"effect/PlatformError\";\n\n/**\n * The digests npm publishes, mapped to what `Crypto.digest` calls them.\n *\n * Doubles as the supported-algorithm list: an SRI token whose algorithm is not\n * a key here is one we cannot check, and is dropped during parsing.\n */\nconst digestAlgorithmByName = {\n\tsha512: \"SHA-512\",\n\tsha384: \"SHA-384\",\n\tsha256: \"SHA-256\",\n\tsha1: \"SHA-1\",\n} as const satisfies Record<string, Crypto.DigestAlgorithm>;\n\n/** An algorithm this module can verify against. */\nexport type IntegrityAlgorithm = keyof typeof digestAlgorithmByName;\n\nconst isSupported = (algorithm: string): algorithm is IntegrityAlgorithm =>\n\tObject.hasOwn(digestAlgorithmByName, algorithm);\n\n/** One parsed SRI hash. */\nexport type IntegrityHash = {\n\treadonly algorithm: IntegrityAlgorithm;\n\t/** Base64 digest, exactly as written in the SRI string. */\n\treadonly digest: string;\n};\n\n/**\n * Parses an SRI string such as `sha512-abc...==`.\n *\n * npm permits several space-separated hashes; we keep every one we can verify\n * and ignore algorithms we cannot.\n */\nexport const parseIntegrity = (integrity: string): ReadonlyArray<IntegrityHash> => {\n\tconst hashes: Array<IntegrityHash> = [];\n\tfor (const token of integrity.trim().split(/\\s+/)) {\n\t\tif (token.length === 0) continue;\n\t\tconst dash = token.indexOf(\"-\");\n\t\tif (dash <= 0) continue;\n\t\tconst algorithm = token.slice(0, dash).toLowerCase();\n\t\tconst digest = token.slice(dash + 1);\n\t\tif (!isSupported(algorithm) || digest.length === 0) continue;\n\t\thashes.push({ algorithm, digest });\n\t}\n\treturn hashes;\n};\n\nconst digestBytes = (\n\tdata: Uint8Array,\n\talgorithm: IntegrityAlgorithm,\n): Effect.Effect<Uint8Array, PlatformError, Crypto.Crypto> =>\n\tEffect.gen(function* () {\n\t\tconst crypto = yield* Crypto.Crypto;\n\t\treturn yield* crypto.digest(digestAlgorithmByName[algorithm], data);\n\t});\n\n/** Computes the base64 digest of some bytes under one algorithm. */\nexport const digestOf = (\n\tdata: Uint8Array,\n\talgorithm: IntegrityAlgorithm,\n): Effect.Effect<string, PlatformError, Crypto.Crypto> =>\n\tEffect.map(digestBytes(data, algorithm), Encoding.encodeBase64);\n\n/** Computes the hex digest of some bytes — the form legacy `shasum` uses. */\nexport const hexDigestOf = (\n\tdata: Uint8Array,\n\talgorithm: IntegrityAlgorithm,\n): Effect.Effect<string, PlatformError, Crypto.Crypto> =>\n\tEffect.map(digestBytes(data, algorithm), Encoding.encodeHex);\n\n/** Result of checking a download. */\nexport type VerificationResult =\n\t/** Verified against at least one checksum. */\n\t| { readonly _tag: \"Verified\"; readonly using: string }\n\t/** The registry advertised no checksum we could use. */\n\t| { readonly _tag: \"Unverifiable\"; readonly reason: string }\n\t/** A checksum was present and did not match. */\n\t| { readonly _tag: \"Mismatch\"; readonly expected: string; readonly actual: string };\n\n/**\n * Constant-time comparison of two digest strings.\n *\n * Written by hand rather than with `node:crypto`'s `timingSafeEqual`, which\n * needs `Buffer` and would pin this module to Node. Both digests here are\n * public knowledge, so the timing property is close to theatre — but it costs\n * four lines, and the alternative is explaining in a review why it was dropped.\n */\nconst digestsEqual = (a: string, b: string): boolean => {\n\tif (a.length !== b.length) return false;\n\tlet difference = 0;\n\tfor (let index = 0; index < a.length; index++) {\n\t\tdifference |= a.charCodeAt(index) ^ b.charCodeAt(index);\n\t}\n\treturn difference === 0;\n};\n\n/**\n * Checks bytes against whichever checksums the registry supplied.\n *\n * SRI is preferred; `shasum` is the fallback for versions published before\n * integrity strings existed. If the registry gave us neither, that is reported\n * as `Unverifiable` rather than silently treated as a pass — the caller decides\n * whether to tolerate it.\n */\nexport const verify = (\n\tdata: Uint8Array,\n\tdist: { readonly integrity?: string | undefined; readonly shasum?: string | undefined },\n): Effect.Effect<VerificationResult, PlatformError, Crypto.Crypto> =>\n\tEffect.gen(function* () {\n\t\tif (dist.integrity !== undefined && dist.integrity.length > 0) {\n\t\t\t// Strongest first, so a mismatch is reported against the best hash present.\n\t\t\tconst [best] = parseIntegrity(dist.integrity).toSorted(\n\t\t\t\t(a, b) => strengthByAlgorithm[b.algorithm] - strengthByAlgorithm[a.algorithm],\n\t\t\t);\n\t\t\tif (best === undefined) {\n\t\t\t\treturn {\n\t\t\t\t\t_tag: \"Unverifiable\",\n\t\t\t\t\treason: `no supported algorithm in \"${dist.integrity}\"`,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst actual = yield* digestOf(data, best.algorithm);\n\t\t\treturn digestsEqual(actual, best.digest)\n\t\t\t\t? { _tag: \"Verified\", using: best.algorithm }\n\t\t\t\t: {\n\t\t\t\t\t\t_tag: \"Mismatch\",\n\t\t\t\t\t\texpected: `${best.algorithm}-${best.digest}`,\n\t\t\t\t\t\tactual: `${best.algorithm}-${actual}`,\n\t\t\t\t\t};\n\t\t}\n\n\t\tif (dist.shasum !== undefined && dist.shasum.length > 0) {\n\t\t\tconst actual = yield* hexDigestOf(data, \"sha1\");\n\t\t\treturn digestsEqual(actual.toLowerCase(), dist.shasum.toLowerCase())\n\t\t\t\t? { _tag: \"Verified\", using: \"sha1\" }\n\t\t\t\t: { _tag: \"Mismatch\", expected: `sha1-${dist.shasum}`, actual: `sha1-${actual}` };\n\t\t}\n\n\t\treturn { _tag: \"Unverifiable\", reason: \"registry advertised no integrity or shasum\" };\n\t});\n\nconst strengthByAlgorithm = {\n\tsha512: 4,\n\tsha384: 3,\n\tsha256: 2,\n\tsha1: 1,\n} as const satisfies Record<IntegrityAlgorithm, number>;\n","/**\n * The on-disk shape of a bundle.\n *\n * Under every layout but `flat`, everything is laid out exactly the way a\n * registry serves it:\n *\n * lodash/-/lodash-4.17.21.tgz\n * @babel/core/-/core-7.24.0.tgz\n *\n * That is not an Artifactory convention — it is the path structure in every\n * `dist.tarball` URL npm publishes. See `notes/requirements.md` § FR-12 for\n * what that buys.\n *\n * The one shape worth noticing before editing anything here: a scoped\n * package's file name drops the scope, so `@babel/core` becomes\n * `core-7.24.0.tgz` under an `@babel/core/-/` directory.\n *\n * `flat` layout is the exception; `bundlePath` is where the two part company.\n */\n\nimport { Layout } from \"./enums/layout.js\";\n\n/** Splits `@scope/name` into its parts. `scope` is undefined when unscoped. */\nexport const splitName = (\n\tname: string,\n): { readonly scope: string | undefined; readonly bare: string } => {\n\tif (!name.startsWith(\"@\")) return { scope: undefined, bare: name };\n\tconst slash = name.indexOf(\"/\");\n\tif (slash === -1) return { scope: undefined, bare: name };\n\treturn { scope: name.slice(0, slash), bare: name.slice(slash + 1) };\n};\n\n/** `@babel/core` + `7.24.0` -> `core-7.24.0.tgz` */\nexport const tarballFileName = (name: string, version: string): string => {\n\tconst { bare } = splitName(name);\n\treturn `${bare}-${version}.tgz`;\n};\n\n/**\n * The path of one package tarball within a bundle, using `/` separators\n * regardless of host platform — these become tar entry names, and tar entries\n * are always POSIX.\n */\nexport const packagePath = (name: string, version: string): string =>\n\t`${name}/-/${tarballFileName(name, version)}`;\n\n/** File name of the manifest that ships inside every bundle. */\nexport const MANIFEST_FILE = \"bundle-manifest.json\";\n\n/** File name of the short import guide that ships inside every bundle. */\nexport const README_FILE = \"IMPORT.md\";\n\n/**\n * A flat, collision-free file name for one `name@version`.\n *\n * It is the spec, with the one character a file name cannot hold taken out:\n * `@types/react@19.2.18` becomes `@types-react@19.2.18.tgz`. So the name of the\n * file answers the question somebody has when they are looking at a directory\n * of them — which package, and which version — in the notation they would have\n * typed to ask for it.\n *\n * The version is joined with `@` rather than `-` for the same reason. A\n * hyphen made `foo-bar-1.0.0` ambiguous by eye: package `foo` at `bar-1.0.0`,\n * or `foo-bar` at `1.0.0`? npm's own syntax has no such problem, because a\n * package name may not contain `@` beyond its scope.\n *\n * **The scope's `@` stays**, and it is the difference between a correct bundle\n * and a quietly incomplete one.\n *\n * Dropping it — which this did, matching what `npm pack` produces — meant\n * `@something/somewhat` and `something-somewhat` were both\n * `something-somewhat-1.0.0.tgz`. Two different packages, one path: the second\n * landed on the first, and the run reported two artifacts for the one file that\n * survived. A bundle short a package, called complete, found at the far end of\n * an air gap.\n *\n * Keeping the `@` makes that impossible by construction rather than by a check,\n * because an unscoped npm name may not begin with one. It is also the more\n * honest name: the scope is part of what the package *is*, and a directory of\n * archives that has forgotten which ones were scoped is a directory somebody\n * has to cross-reference against a manifest.\n *\n * It does not make every collision impossible — `@a/b-c` and `@a-b/c` still\n * meet — so the run still checks before downloading anything. That pair is\n * pathological; the scoped-against-unscoped one is `@babel/core` beside\n * `babel-core`, which is a real migration somebody could be bundling.\n *\n * The leading `@` is safe here in a way it is not inside the archive: tar's\n * splice convention applies to the *file list* it is given, which is what\n * `archive.ts` guards with `./`. These are output paths, not entries.\n */\nexport const flatName = (name: string, version: string): string => {\n\tconst { scope, bare } = splitName(name);\n\tconst prefix = scope === undefined ? bare : `${scope}-${bare}`;\n\treturn `${prefix}@${version}.tgz`;\n};\n\n/**\n * Name of the archive produced for one root spec in `per-spec` layout.\n *\n * The same rule as {@link flatName}, which is where the reasoning lives — a\n * per-spec archive and a `flat` package tarball are both \"one file in a\n * directory, named for what is in it\", and there is no reason for a directory\n * of bundles and a directory of packages to be read differently.\n */\nexport const perSpecArchiveName = flatName;\n\n/**\n * The path of one package tarball within a bundle. The one place the two\n * shapes are chosen between, so a manifest and the tree it describes cannot\n * drift apart.\n *\n * `flat` keeps a file name and no directories, and uses {@link flatName}\n * rather than the registry file name: with the directories gone that name is\n * all there is to tell two packages apart, and the registry one drops the\n * scope, which would put `@types/node` and `node` on the same file. The name\n * is free to differ — `npm publish <tarball>` reads a package's name and\n * version from the `package.json` inside it, not from what the file is\n * called.\n */\nexport const bundlePath = (layout: Layout, name: string, version: string): string =>\n\tlayout === Layout.Flat ? flatName(name, version) : packagePath(name, version);\n\n/** Name of the archive produced in `single` layout. */\nexport const singleArchiveName = (base = \"bundle\"): string => `${base}.tgz`;\n\n/** Shared by both guides. */\ntype GuideOptions = {\n\treadonly packageCount: number;\n\treadonly createdAt: string;\n\treadonly toolVersion: string;\n\treadonly layout: Layout;\n};\n\n/**\n * The import guide written into each bundle.\n *\n * Kept short and copy-pasteable on purpose: whoever opens this is mid-task on a\n * restricted network and does not want prose.\n *\n * Layout-aware, because the instructions genuinely differ — a registry-layout\n * tree uploads into Artifactory as it stands and a flat directory does not, and\n * a guide that said otherwise would be discovered to be wrong by somebody who\n * can no longer look anything up.\n */\nexport const importGuide = (options: GuideOptions): string =>\n\toptions.layout === Layout.Flat ? flatGuide(options) : treeGuide(options);\n\nconst treeGuide = (options: GuideOptions): string =>\n\t`# Importing this bundle\n\n${options.packageCount} package tarball(s), laid out exactly as an npm registry serves them:\n\n <package-name>/-/<file>.tgz\n @<scope>/<name>/-/<file>.tgz\n\nCreated ${options.createdAt} by packall ${options.toolVersion}.\nSee ${MANIFEST_FILE} for the full list with checksums.\n\n## JFrog Artifactory\n\nUnpack, then upload the tree into a **local npm** repository. The layout already\nmatches what Artifactory expects, so no path rewriting is needed:\n\n tar -xzf <this-bundle>.tgz -C ./bundle\n jf rt upload \"bundle/(**)\" \"<npm-local-repo>/{1}\" --flat=false\n\n## Verdaccio / Nexus / any npm registry\n\nPublish each tarball individually:\n\n find ./bundle -name '*.tgz' -exec npm publish --registry <url> {} \\\\;\n\n## Verifying before import\n\n node -e \"const m=require('./bundle/${MANIFEST_FILE}');console.log(m.packages.length+' packages')\"\n\nEvery entry in ${MANIFEST_FILE} carries the integrity string the source registry\nadvertised, and each tarball was checked against it at download time.\n`;\n\nconst flatGuide = (options: GuideOptions): string =>\n\t`# Importing this bundle\n\n${options.packageCount} package tarball(s), side by side in this one directory:\n\n <name>@<version>.tgz\n @<scope>-<name>@<version>.tgz\n\nCreated ${options.createdAt} by packall ${options.toolVersion}.\nSee ${MANIFEST_FILE} for the full list with checksums.\n\n## Publishing into a registry\n\n\\`npm publish\\` reads each package's name and version from the \\`package.json\\`\ninside its tarball, so neither the file names nor the order matter:\n\n for f in *.tgz; do npm publish --registry <url> \"$f\"; done\n\nFor a tree that uploads into Artifactory as it stands, use --layout dir instead.\n\n## Verifying before import\n\n node -e \"const m=require('./${MANIFEST_FILE}');console.log(m.packages.length+' packages')\"\n\nEvery entry in ${MANIFEST_FILE} carries the integrity string the source registry\nadvertised, and each tarball was checked against it at download time.\n`;\n","/**\n * The manifest written into every bundle — the audit trail, answerable without\n * unpacking a single tarball. See `notes/requirements.md` § FR-10.\n */\nimport { bundlePath } from \"./layout.js\";\nimport type { BundleOptions } from \"./options.js\";\nimport { formatPlatformFilter } from \"./platform.js\";\nimport type { Resolution, ResolvedPackage } from \"./resolve.js\";\nimport { formatSpec } from \"./spec.js\";\n\n/** Schema version, bumped when the shape changes incompatibly. */\nexport const MANIFEST_VERSION = 1;\n\nexport type ManifestEntry = {\n\treadonly name: string;\n\treadonly version: string;\n\t/** Path of this tarball inside the bundle. */\n\treadonly path: string;\n\t/** The URL it was downloaded from. */\n\treadonly tarball: string;\n\t/** SRI integrity string as advertised by the source registry, when present. */\n\treadonly integrity?: string | undefined;\n\t/** Legacy sha1, present on older published versions. */\n\treadonly shasum?: string | undefined;\n\t/** Actual size on disk, in bytes. */\n\treadonly bytes?: number | undefined;\n\t/** Human-readable justifications: `root:react@18.2.0`, `prod:scheduler@0.23.0`. */\n\treadonly reasons: ReadonlyArray<string>;\n};\n\nexport type BundleManifest = {\n\treadonly manifestVersion: number;\n\treadonly tool: { readonly name: string; readonly version: string };\n\treadonly createdAt: string;\n\treadonly registry: { readonly kind: string; readonly url: string };\n\t/** What the user asked for, verbatim. */\n\treadonly requested: ReadonlyArray<string>;\n\t/** What each request expanded to. */\n\treadonly roots: ReadonlyArray<{\n\t\treadonly spec: string;\n\t\treadonly versions: ReadonlyArray<string>;\n\t\treadonly packageCount: number;\n\t}>;\n\treadonly options: {\n\t\treadonly layout: string;\n\t\treadonly optionalDependencies: boolean;\n\t\treadonly peerDependencies: boolean;\n\t\treadonly platforms: string;\n\t\treadonly allVersions: boolean;\n\t\treadonly includePrerelease: boolean;\n\t\treadonly integrityVerified: boolean;\n\t};\n\treadonly packages: ReadonlyArray<ManifestEntry>;\n\treadonly warnings: ReadonlyArray<string>;\n\treadonly totals: {\n\t\treadonly packages: number;\n\t\treadonly bytes: number;\n\t};\n};\n\n/** Renders a package's reasons into short, greppable strings. */\nexport const formatReasons = (pkg: ResolvedPackage): ReadonlyArray<string> =>\n\tpkg.reasons.map((reason) =>\n\t\treason._tag === \"Root\" ? `root:${reason.spec}` : `${reason.kind}:${reason.from}`,\n\t);\n\n/** Builds the manifest for a completed (or dry) run. */\nexport const buildManifest = (input: {\n\treadonly resolution: Resolution;\n\t/** Only the packages actually included in *this* archive. */\n\treadonly included: ReadonlyArray<ResolvedPackage>;\n\treadonly options: BundleOptions;\n\treadonly registry: { readonly kind: string; readonly url: string };\n\treadonly toolVersion: string;\n\treadonly sizes: ReadonlyMap<string, number>;\n\treadonly createdAt?: Date | undefined;\n}): BundleManifest => {\n\tconst includedNames = new Set(input.included.map((pkg) => `${pkg.name}@${pkg.version}`));\n\n\tconst packages: ReadonlyArray<ManifestEntry> = input.included.map((pkg) => {\n\t\tconst key = `${pkg.name}@${pkg.version}`;\n\t\treturn {\n\t\t\tname: pkg.name,\n\t\t\tversion: pkg.version,\n\t\t\tpath: bundlePath(input.options.layout, pkg.name, pkg.version),\n\t\t\ttarball: pkg.manifest.dist.tarball,\n\t\t\tintegrity: pkg.manifest.dist.integrity,\n\t\t\tshasum: pkg.manifest.dist.shasum,\n\t\t\tbytes: input.sizes.get(key),\n\t\t\treasons: formatReasons(pkg),\n\t\t};\n\t});\n\n\tconst totalBytes = packages.reduce((sum, entry) => sum + (entry.bytes ?? 0), 0);\n\n\treturn {\n\t\tmanifestVersion: MANIFEST_VERSION,\n\t\ttool: { name: \"packall\", version: input.toolVersion },\n\t\tcreatedAt: (input.createdAt ?? new Date()).toISOString(),\n\t\tregistry: input.registry,\n\t\trequested: input.resolution.roots.map((root) => formatSpec(root.spec)),\n\t\troots: input.resolution.roots.map((root) => ({\n\t\t\tspec: formatSpec(root.spec),\n\t\t\tversions: root.versions,\n\t\t\tpackageCount: root.closure.filter((key) => includedNames.has(key)).length,\n\t\t})),\n\t\toptions: {\n\t\t\tlayout: input.options.layout,\n\t\t\toptionalDependencies: input.options.scope.optional,\n\t\t\tpeerDependencies: input.options.scope.peer,\n\t\t\tplatforms: formatPlatformFilter(input.options.scope.platforms),\n\t\t\tallVersions: input.options.allVersions,\n\t\t\tincludePrerelease: input.options.includePrerelease,\n\t\t\tintegrityVerified: input.options.verifyIntegrity,\n\t\t},\n\t\tpackages,\n\t\twarnings: input.resolution.warnings.map((warning) =>\n\t\t\twarning.from === undefined ? warning.message : `${warning.from}: ${warning.message}`,\n\t\t),\n\t\ttotals: {\n\t\t\tpackages: packages.length,\n\t\t\tbytes: totalBytes,\n\t\t},\n\t};\n};\n\n/** Serialises a manifest with stable key order and a trailing newline. */\nexport const serializeManifest = (manifest: BundleManifest): string =>\n\t`${JSON.stringify(manifest, null, 2)}\\n`;\n","/**\n * Version selection and the dependency closure walk.\n *\n * This is the part that decides *what* ends up in a bundle. Its only side\n * effect is asking the `Registry` service for metadata, which makes the whole\n * of it testable against a fake registry with no network at all.\n *\n * The walk is breadth-first in waves: resolve the current frontier\n * concurrently, collect the newly discovered edges, repeat. Wave-based BFS\n * gives real parallelism without a dynamic worker pool, and because each wave\n * merges its results serially there is no shared mutable state being written\n * from more than one fiber.\n *\n * One subtlety worth calling out: metadata is cached across walks, but each\n * walk still traverses the full graph. That is what lets `per-spec` layout ask\n * \"what does *this* root version depend on\" many times over while the network\n * is touched exactly once per package.\n */\nimport * as Effect from \"effect/Effect\";\nimport semver from \"semver\";\n\nimport { parseDependencyTarget } from \"./dependency-range.js\";\nimport { EdgeKind } from \"./enums/edge-kind.js\";\nimport { Phase } from \"./enums/phase.js\";\nimport type { BundlerError } from \"./errors.js\";\nimport { NoMatchingVersionsError, VersionNotFoundError } from \"./errors.js\";\nimport type { ResolveOptions } from \"./options.js\";\nimport { isIncluded } from \"./platform.js\";\nimport * as Progress from \"./progress.js\";\nimport type { PackageManifest, Packument } from \"./registry.js\";\nimport { Registry } from \"./registry.js\";\nimport type { PackageSpec, Selector } from \"./spec.js\";\nimport { formatSelector, formatSpec } from \"./spec.js\";\n\n/** A single justification for including a package. */\nexport type Reason =\n\t| { readonly _tag: \"Root\"; readonly spec: string }\n\t| { readonly _tag: \"Edge\"; readonly from: string; readonly kind: EdgeKind };\n\n/** `name@version` — the identity of a resolved package throughout the engine. */\nexport type PackageKey = string;\n\n/** One package, pinned to one version, with every reason it was pulled in. */\nexport type ResolvedPackage = {\n\treadonly name: string;\n\treadonly version: string;\n\treadonly manifest: PackageManifest;\n\treadonly reasons: ReadonlyArray<Reason>;\n};\n\n/** Something we could not include, reported rather than thrown. */\nexport type ResolutionWarning = {\n\treadonly message: string;\n\t/** `name@version` of the package whose manifest contained the problem. */\n\treadonly from?: string | undefined;\n};\n\n/** What one requested spec expanded to. */\nexport type RootResolution = {\n\treadonly spec: PackageSpec;\n\t/** The concrete versions the spec selected — more than one under `--all-versions`. */\n\treadonly versions: ReadonlyArray<string>;\n\t/** Closure per selected version, keyed by version. Drives `per-spec` layout. */\n\treadonly closures: ReadonlyMap<string, ReadonlyArray<PackageKey>>;\n\t/** Union of every per-version closure. */\n\treadonly closure: ReadonlyArray<PackageKey>;\n};\n\n/** The complete result of resolving every requested spec. */\nexport type Resolution = {\n\treadonly roots: ReadonlyArray<RootResolution>;\n\t/** The deduplicated union of every closure, sorted by name then version. */\n\treadonly packages: ReadonlyArray<ResolvedPackage>;\n\treadonly warnings: ReadonlyArray<ResolutionWarning>;\n};\n\n/** One pending item on the BFS frontier. */\nexport type Task = {\n\treadonly name: string;\n\treadonly selector: Selector;\n\treadonly reason: Reason;\n\t/** Optional edges tolerate resolution failure; required ones do not. */\n\treadonly tolerateFailure: boolean;\n};\n\nexport const packageKey = (name: string, version: string): PackageKey => `${name}@${version}`;\n\n/** Index of a resolution by `name@version`, for lookups during bundling. */\nexport const indexPackages = (resolution: Resolution): ReadonlyMap<PackageKey, ResolvedPackage> =>\n\tnew Map(resolution.packages.map((pkg) => [packageKey(pkg.name, pkg.version), pkg]));\n\n/* -------------------------------------------------------------------------- */\n/* Version selection */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Turns a selector into the concrete version(s) it names.\n *\n * `all` controls whether a range collapses to its best match — npm's behaviour,\n * and what you always want for a transitive dependency — or expands to every\n * satisfying published version, which is what `--all-versions` is for.\n */\nexport const selectVersions = (\n\tpackument: Packument,\n\tselector: Selector,\n\toptions: {\n\t\treadonly all: boolean;\n\t\treadonly maxVersions?: number | undefined;\n\t\treadonly includePrerelease: boolean;\n\t},\n): ReadonlyArray<string> => {\n\tconst available = Object.keys(packument.versions);\n\n\tswitch (selector._tag) {\n\t\tcase \"Exact\": {\n\t\t\tif (!Object.hasOwn(packument.versions, selector.version)) {\n\t\t\t\tthrow new VersionNotFoundError(\n\t\t\t\t\tpackument.name,\n\t\t\t\t\tselector.version,\n\t\t\t\t\tsortVersions(available),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [selector.version];\n\t\t}\n\n\t\tcase \"Tag\": {\n\t\t\tconst version = packument.distTags[selector.tag];\n\t\t\tif (version === undefined || !Object.hasOwn(packument.versions, version)) {\n\t\t\t\tthrow new NoMatchingVersionsError(\n\t\t\t\t\tpackument.name,\n\t\t\t\t\tselector.tag,\n\t\t\t\t\tsortVersions(available),\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn [version];\n\t\t}\n\n\t\tcase \"Range\": {\n\t\t\tconst satisfying = available\n\t\t\t\t.filter((version) =>\n\t\t\t\t\tsemver.satisfies(version, selector.range, {\n\t\t\t\t\t\tloose: true,\n\t\t\t\t\t\tincludePrerelease: options.includePrerelease,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.toSorted(semver.rcompare);\n\n\t\t\tconst [best] = satisfying;\n\t\t\tif (best === undefined) {\n\t\t\t\tthrow new NoMatchingVersionsError(\n\t\t\t\t\tpackument.name,\n\t\t\t\t\tselector.range,\n\t\t\t\t\tsortVersions(available),\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!options.all) return [best];\n\n\t\t\treturn options.maxVersions !== undefined && options.maxVersions > 0\n\t\t\t\t? satisfying.slice(0, options.maxVersions)\n\t\t\t\t: satisfying;\n\t\t}\n\t}\n};\n\nconst sortVersions = (versions: ReadonlyArray<string>): ReadonlyArray<string> =>\n\tversions.toSorted((a, b) =>\n\t\tsemver.valid(a) && semver.valid(b) ? semver.compare(a, b) : a.localeCompare(b),\n\t);\n\n/* -------------------------------------------------------------------------- */\n/* Walk state */\n/* -------------------------------------------------------------------------- */\n\n/**\n * State shared across every walk in a run.\n *\n * Caching packuments and expanded edges here is what makes repeated walks\n * cheap: the second walk over `react@18.2.0` costs no network at all.\n */\ntype WalkState = {\n\treadonly resolved: Map<PackageKey, ResolvedPackage>;\n\treadonly edges: Map<PackageKey, ReadonlyArray<Task>>;\n\treadonly packuments: Map<string, Packument>;\n\treadonly warnings: Array<ResolutionWarning>;\n\t/** Warnings are deduplicated — the same skipped edge appears in many walks. */\n\treadonly warningKeys: Set<string>;\n};\n\nconst makeWalkState = (): WalkState => ({\n\tresolved: new Map(),\n\tedges: new Map(),\n\tpackuments: new Map(),\n\twarnings: [],\n\twarningKeys: new Set(),\n});\n\nconst addWarning = (state: WalkState, warning: ResolutionWarning): void => {\n\tconst key = `${warning.from ?? \"\"}|${warning.message}`;\n\tif (state.warningKeys.has(key)) return;\n\tstate.warningKeys.add(key);\n\tstate.warnings.push(warning);\n};\n\n/**\n * Fetches a packument, reusing anything already seen in this run.\n *\n * Two fibers in the same wave can race here and both fetch. That is one\n * duplicated GET at worst, and de-racing it would cost more complexity than it\n * saves.\n */\nconst getPackument = (\n\tstate: WalkState,\n\tname: string,\n): Effect.Effect<Packument, BundlerError, Registry> =>\n\tEffect.gen(function* () {\n\t\tconst cached = state.packuments.get(name);\n\t\tif (cached !== undefined) return cached;\n\t\tconst registry = yield* Registry;\n\t\tconst packument = yield* registry.packument(name);\n\t\tstate.packuments.set(name, packument);\n\t\treturn packument;\n\t});\n\n/**\n * Re-fails a thrown selection error into the Effect error channel.\n *\n * `selectVersions` throws `BundlerError` subclasses and nothing else, so this\n * narrows rather than casting; anything unexpected is rethrown as a defect,\n * which is what an unexpected exception actually is.\n */\nconst asBundlerError = (error: unknown): BundlerError => {\n\tif (error instanceof VersionNotFoundError || error instanceof NoMatchingVersionsError) {\n\t\treturn error;\n\t}\n\tthrow error;\n};\n\n/* -------------------------------------------------------------------------- */\n/* Edge expansion */\n/* -------------------------------------------------------------------------- */\n\n/** Expands one resolved manifest into the edges that follow from it. */\nexport const edgesOf = (\n\tmanifest: PackageManifest,\n\toptions: ResolveOptions,\n): {\n\treadonly tasks: ReadonlyArray<Task>;\n\treadonly warnings: ReadonlyArray<ResolutionWarning>;\n} => {\n\tconst from = packageKey(manifest.name, manifest.version);\n\tconst tasks: Array<Task> = [];\n\tconst warnings: Array<ResolutionWarning> = [];\n\n\tconst add = (\n\t\tentries: Readonly<Record<string, string>> | undefined,\n\t\tkind: EdgeKind,\n\t\ttolerateFailure: boolean,\n\t\tskip?: (name: string) => boolean,\n\t): void => {\n\t\tif (entries === undefined) return;\n\t\tfor (const [name, raw] of Object.entries(entries)) {\n\t\t\tif (skip?.(name)) continue;\n\t\t\tconst target = parseDependencyTarget(name, raw);\n\t\t\tif (target._tag === \"Unsupported\") {\n\t\t\t\twarnings.push({\n\t\t\t\t\tfrom,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Skipped ${name}@${target.raw} (${target.reason}) — it cannot be fetched from a ` +\n\t\t\t\t\t\t`registry. Vendor it separately if the offline install needs it.`,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\ttasks.push({\n\t\t\t\tname: target.name,\n\t\t\t\tselector: target.selector,\n\t\t\t\treason: { _tag: \"Edge\", from, kind },\n\t\t\t\ttolerateFailure,\n\t\t\t});\n\t\t}\n\t};\n\n\t// Runtime dependencies are non-negotiable.\n\tadd(manifest.dependencies, EdgeKind.Prod, false);\n\n\t// Optional dependencies are allowed to be missing — npm tolerates a 404 here\n\t// and so must we, or one unpublished platform package fails the whole run.\n\tif (options.scope.optional) {\n\t\tadd(manifest.optionalDependencies, EdgeKind.Optional, true);\n\t}\n\n\tif (options.scope.peer) {\n\t\tconst meta = manifest.peerDependenciesMeta ?? {};\n\t\tadd(\n\t\t\tmanifest.peerDependencies,\n\t\t\tEdgeKind.Peer,\n\t\t\tfalse,\n\t\t\t(name) => meta[name]?.optional === true,\n\t\t);\n\t}\n\n\treturn { tasks, warnings };\n};\n\n/** Edges for a package, computed once and cached. */\nconst edgesFor = (\n\tstate: WalkState,\n\tmanifest: PackageManifest,\n\toptions: ResolveOptions,\n): ReadonlyArray<Task> => {\n\tconst key = packageKey(manifest.name, manifest.version);\n\tconst cached = state.edges.get(key);\n\tif (cached !== undefined) return cached;\n\n\tconst { tasks, warnings } = edgesOf(manifest, options);\n\tfor (const warning of warnings) addWarning(state, warning);\n\tstate.edges.set(key, tasks);\n\treturn tasks;\n};\n\n/* -------------------------------------------------------------------------- */\n/* The walk */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Resolves everything reachable from `seeds`, returning the closure.\n *\n * `state` is mutated with newly resolved packages and warnings; the returned\n * array is scoped to *this* walk, which is what makes per-root-version\n * closures possible.\n */\nconst walk = (\n\tstate: WalkState,\n\tseeds: ReadonlyArray<Task>,\n\toptions: ResolveOptions,\n): Effect.Effect<ReadonlyArray<PackageKey>, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tconst discovered = new Set<PackageKey>();\n\t\t// Guards against re-resolving the same (name, selector) pair. Large trees\n\t\t// ask for `tslib@^2` hundreds of times, and this is also what terminates\n\t\t// dependency cycles.\n\t\tconst attempted = new Set<string>();\n\t\tlet frontier: ReadonlyArray<Task> = seeds;\n\n\t\twhile (frontier.length > 0) {\n\t\t\tconst wave: Array<Task> = [];\n\t\t\tfor (const task of frontier) {\n\t\t\t\tconst id = `${task.name} ${formatSelector(task.selector)}`;\n\t\t\t\tif (attempted.has(id)) continue;\n\t\t\t\tattempted.add(id);\n\t\t\t\twave.push(task);\n\t\t\t}\n\t\t\tif (wave.length === 0) break;\n\n\t\t\tconst results = yield* Effect.forEach(\n\t\t\t\twave,\n\t\t\t\t(task) => resolveTask(state, task, options),\n\t\t\t\t{ concurrency: options.concurrency },\n\t\t\t);\n\n\t\t\tconst next: Array<Task> = [];\n\n\t\t\t// Merged serially: every mutation of `state` happens on one fiber.\n\t\t\tfor (const result of results) {\n\t\t\t\tif (result === null) continue;\n\n\t\t\t\tfor (const { manifest, reason } of result) {\n\t\t\t\t\tconst key = packageKey(manifest.name, manifest.version);\n\t\t\t\t\tconst existing = state.resolved.get(key);\n\n\t\t\t\t\tif (existing === undefined) {\n\t\t\t\t\t\tstate.resolved.set(key, {\n\t\t\t\t\t\t\tname: manifest.name,\n\t\t\t\t\t\t\tversion: manifest.version,\n\t\t\t\t\t\t\tmanifest,\n\t\t\t\t\t\t\treasons: [reason],\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t\t\t_tag: \"PackageResolved\",\n\t\t\t\t\t\t\tname: manifest.name,\n\t\t\t\t\t\t\tversion: manifest.version,\n\t\t\t\t\t\t\tresolvedCount: state.resolved.size,\n\t\t\t\t\t\t\tpendingCount: next.length,\n\t\t\t\t\t\t});\n\n\t\t\t\t\t\tif (manifest.deprecated !== undefined && manifest.deprecated !== \"\") {\n\t\t\t\t\t\t\taddWarning(state, {\n\t\t\t\t\t\t\t\tfrom: key,\n\t\t\t\t\t\t\t\tmessage: `${key} is deprecated: ${manifest.deprecated}`,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (!hasReason(existing.reasons, reason)) {\n\t\t\t\t\t\tstate.resolved.set(key, {\n\t\t\t\t\t\t\t...existing,\n\t\t\t\t\t\t\treasons: [...existing.reasons, reason],\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\t// Expand regardless of whether the package is new. A package resolved\n\t\t\t\t\t// during an earlier walk still has to contribute its subtree to\n\t\t\t\t\t// *this* walk's closure; `attempted` stops that from looping.\n\t\t\t\t\tif (!discovered.has(key)) {\n\t\t\t\t\t\tdiscovered.add(key);\n\t\t\t\t\t\tnext.push(...edgesFor(state, manifest, options));\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfrontier = next;\n\t\t}\n\n\t\treturn [...discovered];\n\t});\n\nconst hasReason = (reasons: ReadonlyArray<Reason>, candidate: Reason): boolean =>\n\treasons.some((reason) => {\n\t\tif (reason._tag === \"Root\" && candidate._tag === \"Root\")\n\t\t\treturn reason.spec === candidate.spec;\n\t\tif (reason._tag === \"Edge\" && candidate._tag === \"Edge\") {\n\t\t\treturn reason.from === candidate.from && reason.kind === candidate.kind;\n\t\t}\n\t\treturn false;\n\t});\n\n/**\n * Resolves one task to its manifest(s).\n *\n * Returns `null` when an optional edge could not be resolved — the caller\n * treats that as \"skip quietly\", which is what npm does for\n * `optionalDependencies`.\n */\nconst resolveTask = (\n\tstate: WalkState,\n\ttask: Task,\n\toptions: ResolveOptions,\n): Effect.Effect<\n\tReadonlyArray<{ readonly manifest: PackageManifest; readonly reason: Reason }> | null,\n\tBundlerError,\n\tRegistry\n> =>\n\tEffect.gen(function* () {\n\t\tconst packument = yield* getPackument(state, task.name);\n\n\t\t// Transitive edges always collapse to a single best match; only root specs\n\t\t// ever fan out, and those arrive here already pinned to an exact version.\n\t\tconst versions = yield* Effect.try({\n\t\t\ttry: () =>\n\t\t\t\tselectVersions(packument, task.selector, {\n\t\t\t\t\tall: false,\n\t\t\t\t\tincludePrerelease: options.includePrerelease,\n\t\t\t\t}),\n\t\t\tcatch: asBundlerError,\n\t\t});\n\n\t\treturn versions.flatMap((version) => {\n\t\t\tconst manifest = packument.versions[version];\n\t\t\tif (manifest === undefined) return [];\n\n\t\t\t// Platform narrowing only ever applies to optional edges. Filtering a\n\t\t\t// required dependency by platform would produce a bundle that cannot\n\t\t\t// install anywhere.\n\t\t\tif (\n\t\t\t\ttask.reason._tag === \"Edge\" &&\n\t\t\t\ttask.reason.kind === EdgeKind.Optional &&\n\t\t\t\t!isIncluded(manifest, options.scope.platforms)\n\t\t\t) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\treturn { manifest, reason: task.reason };\n\t\t});\n\t}).pipe(\n\t\tEffect.catch((error) => {\n\t\t\t// A required edge that cannot be resolved is fatal. An optional one is\n\t\t\t// recorded and skipped, matching how npm treats `optionalDependencies`.\n\t\t\tif (!task.tolerateFailure) return Effect.fail(error);\n\t\t\treturn Effect.sync(() => {\n\t\t\t\taddWarning(state, {\n\t\t\t\t\tmessage:\n\t\t\t\t\t\t`Optional dependency ${task.name}@${formatSelector(task.selector)} could not be ` +\n\t\t\t\t\t\t`resolved and was skipped: ${error.message}`,\n\t\t\t\t});\n\t\t\t\treturn null;\n\t\t\t});\n\t\t}),\n\t);\n\n/* -------------------------------------------------------------------------- */\n/* Entry point */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Resolves every requested spec.\n *\n * Each selected root *version* is walked separately so `per-spec` layout has an\n * exact closure per tarball, while all walks share one cache, so a package\n * reached from twenty roots is fetched once.\n */\nexport const resolve = (\n\tspecs: ReadonlyArray<PackageSpec>,\n\toptions: ResolveOptions,\n): Effect.Effect<Resolution, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Resolve, total: specs.length });\n\n\t\tconst state = makeWalkState();\n\t\tconst roots: Array<RootResolution> = [];\n\n\t\tfor (const spec of specs) {\n\t\t\tconst packument = yield* getPackument(state, spec.name);\n\n\t\t\tconst versions = yield* Effect.try({\n\t\t\t\ttry: () =>\n\t\t\t\t\tselectVersions(packument, spec.selector, {\n\t\t\t\t\t\tall: options.allVersions,\n\t\t\t\t\t\tmaxVersions: options.maxVersions,\n\t\t\t\t\t\tincludePrerelease: options.includePrerelease,\n\t\t\t\t\t}),\n\t\t\t\tcatch: asBundlerError,\n\t\t\t});\n\n\t\t\tconst closures = new Map<string, ReadonlyArray<PackageKey>>();\n\t\t\tconst union = new Set<PackageKey>();\n\n\t\t\tfor (const version of versions) {\n\t\t\t\tconst closure = yield* walk(\n\t\t\t\t\tstate,\n\t\t\t\t\t[\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tname: spec.name,\n\t\t\t\t\t\t\tselector: { _tag: \"Exact\", version },\n\t\t\t\t\t\t\treason: { _tag: \"Root\", spec: formatSpec(spec) },\n\t\t\t\t\t\t\ttolerateFailure: false,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t\toptions,\n\t\t\t\t);\n\t\t\t\tclosures.set(version, closure);\n\t\t\t\tfor (const key of closure) union.add(key);\n\t\t\t}\n\n\t\t\troots.push({ spec, versions, closures, closure: [...union] });\n\t\t}\n\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Resolve });\n\n\t\treturn {\n\t\t\troots,\n\t\t\tpackages: [...state.resolved.values()].toSorted(compareResolved),\n\t\t\twarnings: state.warnings,\n\t\t};\n\t});\n\nconst compareResolved = (a: ResolvedPackage, b: ResolvedPackage): number => {\n\tif (a.name !== b.name) return a.name < b.name ? -1 : 1;\n\treturn semver.valid(a.version) && semver.valid(b.version)\n\t\t? semver.compare(a.version, b.version)\n\t\t: a.version.localeCompare(b.version);\n};\n","/**\n * Resolution driven by a lockfile instead of by semver.\n *\n * The distinction matters more than it first looks. Feeding a lockfile's\n * versions in as exact root specs and letting the ordinary walk run would still\n * produce the wrong bundle: every *transitive* edge is a range, and\n * `Resolve.walk` answers a range with whatever is newest today. Lock `tslib` at\n * 2.6.0 and let something depending on `tslib@^2` be re-resolved, and the\n * bundle grows a second copy at 2.8.1 that CI never installed.\n *\n * So the lockfile is treated as the graph, not as a set of hints. The package\n * set *is* what the file pins, and every edge is satisfied from inside it.\n * Nothing here calls `selectVersions`; the only thing the registry is asked for\n * is the metadata that a lockfile does not record — `dist`, and the `os`/`cpu`\n * constraints that `--platform` narrows on.\n *\n * The result is an ordinary `Resolution`, so layout, archiving, the manifest\n * and the summary cannot tell which path produced it.\n */\nimport * as Effect from \"effect/Effect\";\nimport semver from \"semver\";\n\nimport type { EdgeKind } from \"./enums/edge-kind.js\";\nimport { LockedRootKind } from \"./enums/edge-kind.js\";\nimport { Phase } from \"./enums/phase.js\";\nimport type { BundlerError } from \"./errors.js\";\nimport { LockfileIncompleteError, LockfileOutOfDateError } from \"./errors.js\";\nimport type { LockedRoot, LockedTree } from \"./lockfile/types.js\";\nimport type { ResolveOptions } from \"./options.js\";\nimport { isIncluded } from \"./platform.js\";\nimport * as Progress from \"./progress.js\";\nimport type { PackageManifest } from \"./registry.js\";\nimport { Registry } from \"./registry.js\";\nimport type {\n\tPackageKey,\n\tReason,\n\tResolution,\n\tResolutionWarning,\n\tResolvedPackage,\n\tRootResolution,\n} from \"./resolve.js\";\nimport { packageKey } from \"./resolve.js\";\nimport type { PackageSpec } from \"./spec.js\";\nimport { formatSpec } from \"./spec.js\";\n\n/** Options for a lockfile-pinned resolution. */\nexport type LockedResolveOptions = ResolveOptions & {\n\t/**\n\t * Include the project's `devDependencies`.\n\t *\n\t * Matches `--file package.json`: on by default, because a project without its\n\t * dev tooling does not build behind the firewall either.\n\t */\n\treadonly includeDev: boolean;\n\t/**\n\t * Direct dependency names declared by the accompanying package.json.\n\t *\n\t * When present, anything declared there but absent from the lockfile's roots\n\t * means the two have drifted — which is exactly the silent-mismatch case this\n\t * whole feature exists to catch, so it is reported rather than papered over.\n\t */\n\treadonly declared?: ReadonlyArray<string> | undefined;\n};\n\n/** Turns a parsed lockfile into a resolution, pinning every version. */\nexport const resolveLocked = (\n\tlock: LockedTree,\n\toptions: LockedResolveOptions,\n): Effect.Effect<Resolution, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tconst roots = selectRoots(lock, options);\n\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Resolve, total: roots.length });\n\n\t\tconst gap = findGaps(lock, roots, options.declared);\n\t\tif (gap !== null) return yield* Effect.fail(gap);\n\n\t\t// Everything the lockfile can reach, before the platform filter has had a\n\t\t// say. Cheap — no network at all — and it is what decides the fetch list.\n\t\tconst reachable = reachableKeys(lock, roots, options);\n\t\tconst manifests = yield* fetchManifests(lock, reachable, options);\n\n\t\tconst warnings: Array<ResolutionWarning> = lock.warnings.map((message) => ({ message }));\n\t\tconst resolved = new Map<PackageKey, ResolvedPackage>();\n\t\tconst seenWarnings = new Set<string>();\n\n\t\tconst addWarning = (warning: ResolutionWarning): void => {\n\t\t\tconst key = `${warning.from ?? \"\"}|${warning.message}`;\n\t\t\tif (seenWarnings.has(key)) return;\n\t\t\tseenWarnings.add(key);\n\t\t\twarnings.push(warning);\n\t\t};\n\n\t\tconst rootResolutions: Array<RootResolution> = [];\n\n\t\tfor (const root of roots) {\n\t\t\tconst key = packageKey(root.name, root.version);\n\t\t\tif (!manifests.has(key)) continue;\n\n\t\t\tconst spec: PackageSpec = {\n\t\t\t\tname: root.name,\n\t\t\t\tselector: { _tag: \"Exact\", version: root.version },\n\t\t\t\traw: `${root.name}@${root.version}`,\n\t\t\t};\n\n\t\t\t// Platform narrowing applies to optional roots for the same reason it\n\t\t\t// applies to optional edges: a native binding for another OS is exactly\n\t\t\t// what --platform is there to drop.\n\t\t\tif (root.kind === LockedRootKind.Optional && !platformAllows(manifests, key, options))\n\t\t\t\tcontinue;\n\n\t\t\tconst closure = walkLocked({\n\t\t\t\tlock,\n\t\t\t\tmanifests,\n\t\t\t\toptions,\n\t\t\t\tseed: key,\n\t\t\t\trootSpec: formatSpec(spec),\n\t\t\t\tresolved,\n\t\t\t\taddWarning,\n\t\t\t});\n\n\t\t\trootResolutions.push({\n\t\t\t\tspec,\n\t\t\t\tversions: [root.version],\n\t\t\t\tclosures: new Map([[root.version, closure]]),\n\t\t\t\tclosure,\n\t\t\t});\n\t\t}\n\n\t\tfor (const pkg of resolved.values()) {\n\t\t\tconst deprecated = pkg.manifest.deprecated;\n\t\t\tif (deprecated !== undefined && deprecated !== \"\") {\n\t\t\t\taddWarning({\n\t\t\t\t\tfrom: packageKey(pkg.name, pkg.version),\n\t\t\t\t\tmessage: `${packageKey(pkg.name, pkg.version)} is deprecated: ${deprecated}`,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Resolve });\n\n\t\treturn {\n\t\t\troots: rootResolutions,\n\t\t\tpackages: [...resolved.values()].toSorted(compareResolved),\n\t\t\twarnings,\n\t\t};\n\t});\n\n/* -------------------------------------------------------------------------- */\n/* Roots */\n/* -------------------------------------------------------------------------- */\n\n/** Which of the project's direct dependencies this run should bundle. */\nconst selectRoots = (lock: LockedTree, options: LockedResolveOptions): ReadonlyArray<LockedRoot> =>\n\tlock.roots\n\t\t.filter((root) => {\n\t\t\tif (root.kind === LockedRootKind.Dev) return options.includeDev;\n\t\t\tif (root.kind === LockedRootKind.Optional) return options.scope.optional;\n\t\t\tif (root.kind === LockedRootKind.Peer) return options.scope.peer;\n\t\t\treturn true;\n\t\t})\n\t\t// Sorted so the artifact order is a property of the dependency set rather\n\t\t// than of which manager wrote the file.\n\t\t.toSorted((a, b) => (a.name === b.name ? 0 : a.name < b.name ? -1 : 1));\n\n/**\n * The two ways a lockfile can be partial, checked before anything is fetched.\n *\n * Both mean the same thing to whoever is waiting on the bundle — a package they\n * expected will not be in it — and both are invisible unless something says so,\n * because the run otherwise succeeds and simply produces less.\n */\nconst findGaps = (\n\tlock: LockedTree,\n\troots: ReadonlyArray<LockedRoot>,\n\tdeclared: ReadonlyArray<string> | undefined,\n): LockfileIncompleteError | null => {\n\tconst remedy = `Run \\`${lock.format} install\\` to bring the lockfile up to date.`;\n\n\t// A dependency added to package.json without re-running the install. The\n\t// commonest way the two drift, and the cheapest to detect.\n\t//\n\t// Checked against everything the file pins rather than against its roots,\n\t// because the managers disagree about which blocks appear in the root entry —\n\t// pnpm's importers omit peers, npm's `packages[\"\"]` includes them — and a\n\t// package that is pinned somewhere will be in the bundle either way.\n\tif (declared !== undefined && declared.length > 0) {\n\t\tconst locked = new Set<string>();\n\t\tfor (const pkg of lock.packages.values()) locked.add(pkg.name);\n\t\tfor (const root of roots) locked.add(root.name);\n\n\t\tconst missing = declared.filter((name) => !locked.has(name));\n\t\tif (missing.length > 0) {\n\t\t\treturn new LockfileIncompleteError(\n\t\t\t\tlock.path,\n\t\t\t\tmissing,\n\t\t\t\t`the package.json declares ${missing.length} ` +\n\t\t\t\t\t`dependenc${missing.length === 1 ? \"y\" : \"ies\"} it does not pin`,\n\t\t\t\tremedy,\n\t\t\t);\n\t\t}\n\t}\n\n\t// A required edge inside the file pointing at nothing the file pins.\n\tif (lock.incomplete.length > 0) {\n\t\treturn new LockfileIncompleteError(\n\t\t\tlock.path,\n\t\t\tlock.incomplete,\n\t\t\t`${lock.incomplete.length} required ` +\n\t\t\t\t`dependenc${lock.incomplete.length === 1 ? \"y is\" : \"ies are\"} not pinned`,\n\t\t\tremedy,\n\t\t);\n\t}\n\n\treturn null;\n};\n\n/* -------------------------------------------------------------------------- */\n/* Reachability */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Every package the roots can reach through the locked edges.\n *\n * Scope filters apply here — `--no-optional` genuinely removes a subtree — but\n * the platform filter does not, because deciding it needs the `os`/`cpu` fields\n * that only the registry has.\n */\nconst reachableKeys = (\n\tlock: LockedTree,\n\troots: ReadonlyArray<LockedRoot>,\n\toptions: LockedResolveOptions,\n): ReadonlySet<PackageKey> => {\n\tconst seen = new Set<PackageKey>();\n\tconst queue = roots.map((root) => packageKey(root.name, root.version));\n\n\twhile (queue.length > 0) {\n\t\tconst key = queue.pop();\n\t\tif (key === undefined || seen.has(key)) continue;\n\t\tseen.add(key);\n\n\t\tfor (const edge of lock.packages.get(key)?.dependencies ?? []) {\n\t\t\tif (!followsEdge(edge.kind, options)) continue;\n\t\t\tqueue.push(packageKey(edge.name, edge.version));\n\t\t}\n\t}\n\n\treturn seen;\n};\n\nconst followsEdge = (kind: EdgeKind, options: LockedResolveOptions): boolean => {\n\tif (kind === LockedRootKind.Optional) return options.scope.optional;\n\tif (kind === LockedRootKind.Peer) return options.scope.peer;\n\treturn true;\n};\n\n/* -------------------------------------------------------------------------- */\n/* Metadata */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Fetches the published manifest for every pinned version.\n *\n * One packument per distinct *name*, not per version — a lockfile holding four\n * versions of `tslib` costs one request. Every pinned version that the registry\n * does not serve is collected and reported together, because \"refresh your\n * lockfile\" is a single action and finding out about the gaps one run at a time\n * would be miserable.\n */\nconst fetchManifests = (\n\tlock: LockedTree,\n\treachable: ReadonlySet<PackageKey>,\n\toptions: LockedResolveOptions,\n): Effect.Effect<\n\tReadonlyMap<PackageKey, PackageManifest>,\n\tBundlerError,\n\tRegistry | Progress.Progress\n> =>\n\tEffect.gen(function* () {\n\t\tconst registry = yield* Registry;\n\n\t\tconst wanted = new Map<string, Array<string>>();\n\t\tfor (const key of reachable) {\n\t\t\tconst pkg = lock.packages.get(key);\n\t\t\tif (pkg === undefined) continue;\n\t\t\tconst versions = wanted.get(pkg.name);\n\t\t\tif (versions === undefined) wanted.set(pkg.name, [pkg.version]);\n\t\t\telse versions.push(pkg.version);\n\t\t}\n\n\t\tconst manifests = new Map<PackageKey, PackageManifest>();\n\t\tconst missing: Array<{ name: string; version: string; detail: string }> = [];\n\n\t\tconst fetched = yield* Effect.forEach(\n\t\t\t[...wanted.entries()],\n\t\t\t([name, versions]) =>\n\t\t\t\tregistry.packument(name).pipe(\n\t\t\t\t\tEffect.map((packument) => ({ name, versions, packument })),\n\t\t\t\t\t// A package the registry has never heard of is the same problem as a\n\t\t\t\t\t// version it no longer serves, and belongs in the same report.\n\t\t\t\t\tEffect.catch((error) =>\n\t\t\t\t\t\terror._tag === \"PackageNotFoundError\"\n\t\t\t\t\t\t\t? Effect.succeed({ name, versions, packument: null })\n\t\t\t\t\t\t\t: Effect.fail(error),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\t{ concurrency: options.concurrency },\n\t\t);\n\n\t\tfor (const { name, versions, packument } of fetched) {\n\t\t\tfor (const version of versions) {\n\t\t\t\tif (packument === null) {\n\t\t\t\t\tmissing.push({ name, version, detail: \"package not found\" });\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tconst manifest = packument.versions[version];\n\t\t\t\tif (manifest === undefined) {\n\t\t\t\t\tmissing.push({\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tversion,\n\t\t\t\t\t\tdetail: describeAvailable(Object.keys(packument.versions)),\n\t\t\t\t\t});\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\n\t\t\t\tmanifests.set(packageKey(name, version), manifest);\n\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t_tag: \"PackageResolved\",\n\t\t\t\t\tname,\n\t\t\t\t\tversion,\n\t\t\t\t\tresolvedCount: manifests.size,\n\t\t\t\t\tpendingCount: reachable.size - manifests.size,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (missing.length > 0) {\n\t\t\treturn yield* Effect.fail(\n\t\t\t\tnew LockfileOutOfDateError(\n\t\t\t\t\tlock.path,\n\t\t\t\t\tregistry.registryFor(missing[0]?.name ?? \"\"),\n\t\t\t\t\tmissing,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\treturn manifests;\n\t});\n\nconst describeAvailable = (available: ReadonlyArray<string>): string => {\n\tconst recent = available\n\t\t.toSorted((a, b) =>\n\t\t\tsemver.valid(a) && semver.valid(b) ? semver.compare(a, b) : a.localeCompare(b),\n\t\t)\n\t\t.slice(-3);\n\treturn recent.length === 0\n\t\t? \"no published versions\"\n\t\t: `no longer published (latest: ${recent.join(\", \")})`;\n};\n\n/* -------------------------------------------------------------------------- */\n/* The walk */\n/* -------------------------------------------------------------------------- */\n\n/**\n * Collects one root's closure by following locked edges.\n *\n * Pure and synchronous — every manifest is already in hand — so a per-root\n * closure costs nothing beyond the traversal, which is what makes `per-spec`\n * layout as cheap here as it is for a range-resolved run.\n */\nconst walkLocked = (input: {\n\treadonly lock: LockedTree;\n\treadonly manifests: ReadonlyMap<PackageKey, PackageManifest>;\n\treadonly options: LockedResolveOptions;\n\treadonly seed: PackageKey;\n\treadonly rootSpec: string;\n\treadonly resolved: Map<PackageKey, ResolvedPackage>;\n\treadonly addWarning: (warning: ResolutionWarning) => void;\n}): ReadonlyArray<PackageKey> => {\n\tconst closure = new Set<PackageKey>();\n\tconst queue: Array<{ key: PackageKey; reason: Reason }> = [\n\t\t{ key: input.seed, reason: { _tag: \"Root\", spec: input.rootSpec } },\n\t];\n\n\twhile (queue.length > 0) {\n\t\tconst next = queue.pop();\n\t\tif (next === undefined) continue;\n\n\t\tconst manifest = input.manifests.get(next.key);\n\t\tconst locked = input.lock.packages.get(next.key);\n\t\tif (manifest === undefined || locked === undefined) continue;\n\n\t\trecord(input.resolved, next.key, manifest, locked, next.reason);\n\n\t\tif (closure.has(next.key)) continue;\n\t\tclosure.add(next.key);\n\n\t\tfor (const edge of locked.dependencies) {\n\t\t\tif (!followsEdge(edge.kind, input.options)) continue;\n\n\t\t\tconst target = packageKey(edge.name, edge.version);\n\t\t\tif (!input.manifests.has(target)) continue;\n\n\t\t\tif (\n\t\t\t\tedge.kind === LockedRootKind.Optional &&\n\t\t\t\t!platformAllows(input.manifests, target, input.options)\n\t\t\t) {\n\t\t\t\tinput.addWarning({\n\t\t\t\t\tfrom: next.key,\n\t\t\t\t\tmessage: `Skipped optional ${target} — it does not build for the selected platforms.`,\n\t\t\t\t});\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tqueue.push({ key: target, reason: { _tag: \"Edge\", from: next.key, kind: edge.kind } });\n\t\t}\n\t}\n\n\treturn [...closure];\n};\n\n/** Adds a package, or merges one more justification into an existing entry. */\nconst record = (\n\tresolved: Map<PackageKey, ResolvedPackage>,\n\tkey: PackageKey,\n\tmanifest: PackageManifest,\n\tlocked: { readonly name: string; readonly version: string },\n\treason: Reason,\n): void => {\n\tconst existing = resolved.get(key);\n\tif (existing === undefined) {\n\t\tresolved.set(key, {\n\t\t\tname: locked.name,\n\t\t\tversion: locked.version,\n\t\t\tmanifest,\n\t\t\treasons: [reason],\n\t\t});\n\t\treturn;\n\t}\n\tif (hasReason(existing.reasons, reason)) return;\n\tresolved.set(key, { ...existing, reasons: [...existing.reasons, reason] });\n};\n\nconst hasReason = (reasons: ReadonlyArray<Reason>, candidate: Reason): boolean =>\n\treasons.some((reason) => {\n\t\tif (reason._tag === \"Root\" && candidate._tag === \"Root\")\n\t\t\treturn reason.spec === candidate.spec;\n\t\tif (reason._tag === \"Edge\" && candidate._tag === \"Edge\") {\n\t\t\treturn reason.from === candidate.from && reason.kind === candidate.kind;\n\t\t}\n\t\treturn false;\n\t});\n\nconst platformAllows = (\n\tmanifests: ReadonlyMap<PackageKey, PackageManifest>,\n\tkey: PackageKey,\n\toptions: LockedResolveOptions,\n): boolean => {\n\tconst manifest = manifests.get(key);\n\tif (manifest === undefined) return false;\n\treturn isIncluded(manifest, options.scope.platforms);\n};\n\nconst compareResolved = (a: ResolvedPackage, b: ResolvedPackage): number => {\n\tif (a.name !== b.name) return a.name < b.name ? -1 : 1;\n\treturn semver.valid(a.version) && semver.valid(b.version)\n\t\t? semver.compare(a.version, b.version)\n\t\t: a.version.localeCompare(b.version);\n};\n","/**\n * Narrowing helpers for the untyped JSON and YAML a lockfile parses into.\n *\n * Everything here takes `unknown` and hands back something narrowed, which is\n * what keeps the parsers free of casts against files nobody controls. The\n * shape-level narrowing is Effect Schema — the same decoders the registry\n * response boundary uses — so \"tolerated\" means one thing across the codebase\n * rather than being re-decided per parser.\n */\nimport * as Option from \"effect/Option\";\nimport * as Schema from \"effect/Schema\";\n\nimport { LockfileError } from \"../errors.js\";\nimport { OptionalFlagRecordSchema, StringRecordSchema } from \"../schemas/lenient.js\";\nimport { isRecord } from \"../utils/is-record.js\";\n\nexport const stringOr = (value: unknown, fallback: string): string =>\n\ttypeof value === \"string\" ? value : fallback;\n\nconst decodeStringRecord = Schema.decodeUnknownOption(StringRecordSchema);\n\n/** Keeps only the string-valued members of an untyped object. */\nexport const stringRecord = (value: unknown): Readonly<Record<string, string>> =>\n\tOption.getOrElse(decodeStringRecord(value), (): Record<string, string> => ({}));\n\nconst decodeOptionalFlags = Schema.decodeUnknownOption(OptionalFlagRecordSchema);\n\n/** Names a package marked its peers optional with. */\nexport const optionalPeerNames = (value: unknown): ReadonlySet<string> => {\n\tconst flags = Option.getOrElse(\n\t\tdecodeOptionalFlags(value),\n\t\t(): Record<string, { readonly optional: boolean }> => ({}),\n\t);\n\treturn new Set(Object.entries(flags).flatMap(([name, meta]) => (meta.optional ? name : [])));\n};\n\nexport const parseJsonObject = (path: string, content: string): Record<string, unknown> => {\n\tconst parsed = tryParseJsonc(content);\n\tif (parsed === undefined) {\n\t\tthrow new LockfileError(path, \"not valid JSON\");\n\t}\n\tif (!isRecord(parsed)) {\n\t\tthrow new LockfileError(path, \"top level is not an object\");\n\t}\n\treturn parsed;\n};\n\n/**\n * Parses JSON, tolerating the comments and trailing commas bun writes.\n *\n * `bun.lock` is JSONC by design — bun puts explanatory comments in it — so\n * plain `JSON.parse` rejects real lockfiles. Returns `undefined` rather than\n * throwing so detection can use it as a probe.\n */\nexport const tryParseJsonc = (content: string): unknown => {\n\ttry {\n\t\treturn JSON.parse(content);\n\t} catch {\n\t\ttry {\n\t\t\treturn JSON.parse(stripJsonc(content));\n\t\t} catch {\n\t\t\treturn undefined;\n\t\t}\n\t}\n};\n\n/**\n * Removes comments and trailing commas.\n *\n * String-aware, because a `//` inside a tarball URL is not a comment and an\n * escaped quote does not end a string. Both appear in every real lockfile.\n */\nexport const stripJsonc = (content: string): string => {\n\tlet out = \"\";\n\tlet index = 0;\n\tlet inString = false;\n\n\twhile (index < content.length) {\n\t\tconst char = content[index];\n\n\t\tif (inString) {\n\t\t\tout += char;\n\t\t\tif (char === \"\\\\\") {\n\t\t\t\tout += content[index + 1] ?? \"\";\n\t\t\t\tindex += 2;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (char === '\"') inString = false;\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === '\"') {\n\t\t\tinString = true;\n\t\t\tout += char;\n\t\t\tindex += 1;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && content[index + 1] === \"/\") {\n\t\t\tconst end = content.indexOf(\"\\n\", index);\n\t\t\tindex = end === -1 ? content.length : end;\n\t\t\tcontinue;\n\t\t}\n\n\t\tif (char === \"/\" && content[index + 1] === \"*\") {\n\t\t\tconst end = content.indexOf(\"*/\", index + 2);\n\t\t\tindex = end === -1 ? content.length : end + 2;\n\t\t\tcontinue;\n\t\t}\n\n\t\t// A comma is trailing when the next thing that is not whitespace closes the\n\t\t// structure it sits in.\n\t\tif (char === \",\") {\n\t\t\tconst next = content.slice(index + 1).search(/\\S/);\n\t\t\tconst following = next === -1 ? \"\" : content[index + 1 + next];\n\t\t\tif (following === \"}\" || following === \"]\") {\n\t\t\t\tindex += 1;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\n\t\tout += char;\n\t\tindex += 1;\n\t}\n\n\treturn out;\n};\n\nexport const describeError = (error: unknown): string =>\n\terror instanceof Error ? error.message : String(error);\n","/**\n * Working out which lockfile — if any — some content is.\n *\n * Detection is by content, matching how `--file` treats everything else: a\n * lockfile renamed to `deps.txt` still parses, and a `package-lock.json` that\n * is actually a package.json still gets read as one.\n */\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { isRecord } from \"../utils/is-record.js\";\nimport { tryParseJsonc } from \"./json.js\";\n\n/** What a blob of file content turned out to be. */\nexport type LockfileDetection =\n\t| { readonly _tag: \"Supported\"; readonly format: LockfileFormat }\n\t/**\n\t * Recognisably a lockfile, but not one we can read. Named explicitly so the\n\t * error says \"yarn.lock is not supported yet\" rather than leaving somebody to\n\t * work out why their file parsed as a spec list.\n\t */\n\t| { readonly _tag: \"Unsupported\"; readonly label: string; readonly hint: string }\n\t| { readonly _tag: \"NotALockfile\" };\n\n/**\n * Deliberately cheap and total: it never throws, so `--file` can try this\n * first and fall through to its other shapes when the answer is `NotALockfile`.\n */\nexport const detectLockfile = (content: string): LockfileDetection => {\n\tconst trimmed = content.trimStart();\n\n\t// bun's binary lockfile leads with its own magic string. Worth naming,\n\t// because `bun install` wrote this by default until 1.2 and the fix is one\n\t// command.\n\tif (trimmed.startsWith(\"bun-lockfile-format-v0\")) {\n\t\treturn {\n\t\t\t_tag: \"Unsupported\",\n\t\t\tlabel: \"a binary bun lockfile (bun.lockb)\",\n\t\t\thint: \"Run `bun install --save-text-lockfile` to produce a bun.lock, and pass that instead.\",\n\t\t};\n\t}\n\n\tif (/^__metadata:/m.test(trimmed) || /^# yarn lockfile v\\d/m.test(trimmed)) {\n\t\treturn {\n\t\t\t_tag: \"Unsupported\",\n\t\t\tlabel: \"a yarn lockfile\",\n\t\t\thint: \"yarn is not supported yet. Point --file at the package.json instead, or pass --lockfile off.\",\n\t\t};\n\t}\n\n\tif (trimmed.startsWith(\"{\")) return detectJsonLockfile(trimmed);\n\n\t// pnpm is the only YAML one, and it always declares its version first.\n\tif (/^lockfileVersion:/m.test(trimmed) || /^(importers|snapshots):/m.test(trimmed)) {\n\t\treturn { _tag: \"Supported\", format: LockfileFormat.Pnpm };\n\t}\n\n\treturn { _tag: \"NotALockfile\" };\n};\n\n/**\n * Separates the two JSON lockfiles from each other and from a package.json.\n *\n * Both npm and bun write a numeric `lockfileVersion`, so that field alone\n * cannot decide it. bun is the one that carries a `workspaces` map keyed by the\n * empty string; npm keeps the root project under `packages[\"\"]` instead.\n */\nconst detectJsonLockfile = (trimmed: string): LockfileDetection => {\n\tconst parsed = tryParseJsonc(trimmed);\n\tif (!isRecord(parsed)) return { _tag: \"NotALockfile\" };\n\n\tconst workspaces = parsed[\"workspaces\"];\n\tif (isRecord(workspaces) && Object.hasOwn(workspaces, \"\")) {\n\t\treturn { _tag: \"Supported\", format: LockfileFormat.Bun };\n\t}\n\n\tif (typeof parsed[\"lockfileVersion\"] === \"number\") {\n\t\treturn { _tag: \"Supported\", format: LockfileFormat.Npm };\n\t}\n\n\treturn { _tag: \"NotALockfile\" };\n};\n","import { LockfileFormat } from \"../enums/lockfile-format.js\";\n\n/**\n * The file name each supported manager writes, in detection order.\n *\n * Ordered: `package-lock.json` before `npm-shrinkwrap.json` before pnpm's and\n * bun's, so a directory holding several is searched the way npm itself would.\n */\nexport const formatByLockfileName = {\n\t\"package-lock.json\": LockfileFormat.Npm,\n\t\"npm-shrinkwrap.json\": LockfileFormat.Npm,\n\t\"pnpm-lock.yaml\": LockfileFormat.Pnpm,\n\t\"bun.lock\": LockfileFormat.Bun,\n} as const satisfies Record<string, LockfileFormat>;\n\n/** The names a given manager writes. */\nexport const lockfileNamesFor = (format: LockfileFormat): ReadonlyArray<string> =>\n\tObject.entries(formatByLockfileName).flatMap(([name, candidate]) =>\n\t\tcandidate === format ? name : [],\n\t);\n","/**\n * The bookkeeping every lockfile parser shares.\n *\n * Packages, edges and skip warnings accumulate here while a parser walks a\n * file, which is what lets each parser stay focused on its own encoding.\n */\nimport semver from \"semver\";\n\nimport { parseDependencyTarget } from \"../dependency-range.js\";\nimport { LockedRootKind } from \"../enums/edge-kind.js\";\nimport type { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { LockfileError } from \"../errors.js\";\nimport { packageKey } from \"../resolve.js\";\nimport type { LockedEdge, LockedPackage, LockedRoot, LockedTree } from \"./types.js\";\n\n/**\n * Which manifest block each root kind is declared in.\n *\n * The block names are the same across npm, pnpm and bun; only which of them a\n * given format writes differs, which is why each parser supplies its own order\n * rather than iterating this.\n */\nexport const fieldByRootKind = {\n\t[LockedRootKind.Prod]: \"dependencies\",\n\t[LockedRootKind.Optional]: \"optionalDependencies\",\n\t[LockedRootKind.Dev]: \"devDependencies\",\n\t[LockedRootKind.Peer]: \"peerDependencies\",\n} as const satisfies Record<LockedRootKind, string>;\n\nexport class TreeBuilder {\n\treadonly packages = new Map<string, LockedPackage>();\n\treadonly roots: Array<LockedRoot> = [];\n\treadonly warnings: Array<string> = [];\n\treadonly incomplete: Array<string> = [];\n\t/** Names dropped on purpose, so an edge into one is explained, not alarming. */\n\tprivate readonly skipped = new Set<string>();\n\tprivate readonly seenWarnings = new Set<string>();\n\n\tadd(pkg: LockedPackage): void {\n\t\tconst key = packageKey(pkg.name, pkg.version);\n\t\tconst existing = this.packages.get(key);\n\t\tif (existing === undefined) {\n\t\t\tthis.packages.set(key, pkg);\n\t\t\treturn;\n\t\t}\n\t\t// The same package at the same version can appear at several paths in a\n\t\t// nested layout. They are the same bytes; merge the edge sets so a copy\n\t\t// recorded with fewer dependencies does not lose any.\n\t\tthis.packages.set(key, {\n\t\t\t...existing,\n\t\t\tdependencies: mergeEdges(existing.dependencies, pkg.dependencies),\n\t\t});\n\t}\n\n\taddRoot(root: LockedRoot): void {\n\t\tif (this.roots.some((existing) => existing.name === root.name)) return;\n\t\tthis.roots.push(root);\n\t}\n\n\twarn(message: string): void {\n\t\tif (this.seenWarnings.has(message)) return;\n\t\tthis.seenWarnings.add(message);\n\t\tthis.warnings.push(message);\n\t}\n\n\t/** Notes an entry that is real but cannot come from a registry. */\n\tskip(name: string, spec: string, reason: string): void {\n\t\tthis.skipped.add(name);\n\t\tthis.warn(`skipped ${name}@${spec} (${reason}) — not fetchable from a registry`);\n\t}\n\n\t/**\n\t * Records a required edge that resolved to nothing.\n\t *\n\t * An edge into something skipped on purpose is expected — you cannot bundle a\n\t * `workspace:` sibling from a registry — so it stays a warning. Anything else\n\t * means the file does not pin what it claims to.\n\t */\n\tdangling(from: string, name: string): void {\n\t\tif (this.skipped.has(name)) {\n\t\t\tthis.warn(`${from} requires ${name}, which is not fetchable from a registry`);\n\t\t\treturn;\n\t\t}\n\t\tthis.incomplete.push(`${name} (required by ${from})`);\n\t}\n\n\tfinish(input: {\n\t\treadonly format: LockfileFormat;\n\t\treadonly lockfileVersion: string;\n\t\treadonly path: string;\n\t\treadonly importer?: string | undefined;\n\t}): LockedTree {\n\t\tif (this.packages.size === 0) {\n\t\t\tthrow new LockfileError(input.path, \"lockfile pins no packages that can be bundled\");\n\t\t}\n\t\treturn {\n\t\t\tformat: input.format,\n\t\t\tlockfileVersion: input.lockfileVersion,\n\t\t\tpath: input.path,\n\t\t\timporter: input.importer,\n\t\t\tpackages: this.packages,\n\t\t\troots: this.roots,\n\t\t\twarnings: this.warnings,\n\t\t\tincomplete: this.incomplete,\n\t\t};\n\t}\n}\n\nconst mergeEdges = (\n\ta: ReadonlyArray<LockedEdge>,\n\tb: ReadonlyArray<LockedEdge>,\n): ReadonlyArray<LockedEdge> => {\n\tconst merged = new Map<string, LockedEdge>();\n\tfor (const edge of [...a, ...b]) {\n\t\tmerged.set(`${edge.name}@${edge.version}|${edge.kind}`, edge);\n\t}\n\treturn [...merged.values()];\n};\n\n/**\n * Reads the right-hand side of a locked entry as an exact version.\n *\n * Returns the version when it is one, or the reason it is not — `file:../x`,\n * `workspace:*`, a git URL. `parseDependencyTarget` already classifies every\n * one of those for package.json parsing, so the vocabulary of skip reasons\n * stays identical between the two paths.\n */\nexport const asExactVersion = (\n\tname: string,\n\traw: string,\n):\n\t| { readonly _tag: \"Version\"; readonly version: string }\n\t| { readonly _tag: \"Unsupported\"; readonly reason: string } => {\n\tconst exact = semver.valid(raw, { loose: true });\n\tif (exact !== null) return { _tag: \"Version\", version: exact };\n\n\tconst target = parseDependencyTarget(name, raw);\n\tif (target._tag === \"Unsupported\") return { _tag: \"Unsupported\", reason: target.reason };\n\treturn { _tag: \"Unsupported\", reason: \"not an exact version\" };\n};\n\n/**\n * Raised when a lockfile found by walking up turns out not to cover the\n * package.json that went looking for it.\n *\n * Worth distinguishing from \"no lockfile at all\": the file exists and is\n * readable, it simply belongs to a different project, and bundling it would\n * produce someone else's dependency set.\n */\nexport const notCovered = (path: string, importer: string, known: ReadonlyArray<string>): never => {\n\tconst listed = known\n\t\t.slice(0, 8)\n\t\t.map((entry) => ` ${entry}`)\n\t\t.join(\"\\n\");\n\tthrow new LockfileError(\n\t\tpath,\n\t\t`it does not cover ${importer}.\\n` +\n\t\t\t(known.length === 0\n\t\t\t\t? \" It records no workspace members.\"\n\t\t\t\t: ` Workspace members it does record:\\n${listed}` +\n\t\t\t\t\t(known.length > 8 ? `\\n … and ${known.length - 8} more` : \"\")),\n\t);\n};\n\n/** `\"\"` is how npm and bun spell the project at the lockfile's own level. */\nexport const importerKey = (importer: string): string => (importer === \".\" ? \"\" : importer);\n","/**\n * `bun.lock`.\n *\n * Like npm, bun records ranges on its edges and resolves them through the\n * install-path nesting — but it nests with a plain `/`, and package names\n * contain `/` too, so the parent of a key can only be found by asking which\n * prefixes are themselves entries.\n */\nimport { EdgeKind, LockedRootKind } from \"../enums/edge-kind.js\";\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { isRecord } from \"../utils/is-record.js\";\nimport { optionalPeerNames, parseJsonObject, stringRecord } from \"./json.js\";\nimport {\n\tasExactVersion,\n\tfieldByRootKind,\n\timporterKey,\n\tnotCovered,\n\tTreeBuilder,\n} from \"./tree-builder.js\";\nimport type { LockedEdge, LockedTree } from \"./types.js\";\n\n/** One narrowed `packages` entry, keyed by its install path. */\ntype BunEntry = {\n\treadonly key: string;\n\treadonly name: string;\n\treadonly version: string;\n\treadonly dependencies: Readonly<Record<string, string>>;\n\treadonly optionalDependencies: Readonly<Record<string, string>>;\n\treadonly peerDependencies: Readonly<Record<string, string>>;\n\treadonly optionalPeers: ReadonlySet<string>;\n};\n\n/** Root blocks in bun's precedence order — the first mention of a name wins. */\nconst ROOT_KINDS = [\n\tLockedRootKind.Prod,\n\tLockedRootKind.Optional,\n\tLockedRootKind.Dev,\n\tLockedRootKind.Peer,\n] as const;\n\nexport const parseBunLockfile = (\n\tpath: string,\n\tcontent: string,\n\timporter: string | undefined,\n): LockedTree => {\n\tconst root = parseJsonObject(path, content);\n\tconst version = String(root[\"lockfileVersion\"] ?? \"?\");\n\tconst builder = new TreeBuilder();\n\n\tconst packages = root[\"packages\"];\n\tconst entries = isRecord(packages)\n\t\t? collectEntries(builder, packages)\n\t\t: new Map<string, BunEntry>();\n\n\tconst keys = new Set(entries.keys());\n\tfor (const entry of entries.values()) {\n\t\tbuilder.add({\n\t\t\tname: entry.name,\n\t\t\tversion: entry.version,\n\t\t\tdependencies: edgesOf(builder, entries, keys, entry),\n\t\t});\n\t}\n\n\tcollectRoots(builder, entries, keys, root[\"workspaces\"], path, importer);\n\n\treturn builder.finish({ format: LockfileFormat.Bun, lockfileVersion: version, path, importer });\n};\n\n/**\n * Narrows bun's tuple entries.\n *\n * The value is a positional array whose shape depends on where the package came\n * from. A registry package is `[id, registry, info, integrity]`; a workspace\n * member or a git dependency is shorter and its `id` carries the protocol.\n */\nconst collectEntries = (\n\tbuilder: TreeBuilder,\n\tpackages: Record<string, unknown>,\n): Map<string, BunEntry> => {\n\tconst entries = new Map<string, BunEntry>();\n\n\tfor (const [key, raw] of Object.entries(packages)) {\n\t\tif (!Array.isArray(raw)) continue;\n\n\t\tconst [id, , info] = raw;\n\t\tif (typeof id !== \"string\") continue;\n\n\t\tconst at = id.lastIndexOf(\"@\");\n\t\tif (at <= 0) continue;\n\t\tconst name = id.slice(0, at);\n\t\tconst spec = id.slice(at + 1);\n\n\t\tconst version = asExactVersion(name, spec);\n\t\tif (version._tag === \"Unsupported\") {\n\t\t\tbuilder.skip(name, spec, version.reason);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst details = isRecord(info) ? info : {};\n\n\t\tentries.set(key, {\n\t\t\tkey,\n\t\t\tname,\n\t\t\tversion: version.version,\n\t\t\tdependencies: stringRecord(details[\"dependencies\"]),\n\t\t\toptionalDependencies: stringRecord(details[\"optionalDependencies\"]),\n\t\t\tpeerDependencies: stringRecord(details[\"peerDependencies\"]),\n\t\t\toptionalPeers: collectOptionalPeers(details),\n\t\t});\n\t}\n\n\treturn entries;\n};\n\n/** bun lists optional peers as a name array rather than npm's metadata object. */\nconst collectOptionalPeers = (details: Record<string, unknown>): ReadonlySet<string> => {\n\tconst listed = details[\"optionalPeers\"];\n\tconst names = Array.isArray(listed)\n\t\t? listed.flatMap((entry) => (typeof entry === \"string\" ? entry : []))\n\t\t: [];\n\treturn new Set([...names, ...optionalPeerNames(details[\"peerDependenciesMeta\"])]);\n};\n\nconst edgesOf = (\n\tbuilder: TreeBuilder,\n\tentries: ReadonlyMap<string, BunEntry>,\n\tkeys: ReadonlySet<string>,\n\tentry: BunEntry,\n): ReadonlyArray<LockedEdge> => {\n\tconst edges: Array<LockedEdge> = [];\n\n\tconst add = (names: ReadonlyArray<string>, kind: EdgeKind): void => {\n\t\tfor (const name of names) {\n\t\t\tconst target = findEntry(entries, keys, entry.key, name);\n\t\t\tif (target === undefined) {\n\t\t\t\tif (kind === EdgeKind.Prod)\n\t\t\t\t\tbuilder.dangling(`${entry.name}@${entry.version}`, name);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tedges.push({ name: target.name, version: target.version, kind });\n\t\t}\n\t};\n\n\tadd(Object.keys(entry.dependencies), EdgeKind.Prod);\n\tadd(Object.keys(entry.optionalDependencies), EdgeKind.Optional);\n\tadd(\n\t\tObject.keys(entry.peerDependencies).filter((name) => !entry.optionalPeers.has(name)),\n\t\tEdgeKind.Peer,\n\t);\n\n\treturn edges;\n};\n\nconst collectRoots = (\n\tbuilder: TreeBuilder,\n\tentries: ReadonlyMap<string, BunEntry>,\n\tkeys: ReadonlySet<string>,\n\tworkspaces: unknown,\n\tpath: string,\n\tmember: string | undefined,\n): void => {\n\tif (!isRecord(workspaces)) return;\n\n\tconst selected =\n\t\tmember === undefined\n\t\t\t? Object.values(workspaces)\n\t\t\t: Object.hasOwn(workspaces, importerKey(member))\n\t\t\t\t? [workspaces[importerKey(member)]]\n\t\t\t\t: notCovered(path, member, workspacePaths(workspaces));\n\n\tfor (const workspace of selected) {\n\t\tif (!isRecord(workspace)) continue;\n\t\tfor (const kind of ROOT_KINDS) {\n\t\t\tconst declared = stringRecord(workspace[fieldByRootKind[kind]]);\n\t\t\tfor (const [name, specifier] of Object.entries(declared)) {\n\t\t\t\tconst target = findEntry(entries, keys, \"\", name);\n\t\t\t\tif (target === undefined) continue;\n\t\t\t\tbuilder.addRoot({ name: target.name, version: target.version, kind, specifier });\n\t\t\t}\n\t\t}\n\t}\n};\n\nconst workspacePaths = (workspaces: Record<string, unknown>): ReadonlyArray<string> =>\n\tObject.keys(workspaces).map((key) => (key === \"\" ? \".\" : key));\n\n/**\n * bun nests with a plain `/`, and package names contain `/` too, so a parent\n * key cannot be found by string-splitting alone — `@babel/core` would split\n * into a scope that is not a key. `parentKey` only accepts a prefix that is\n * itself an entry, which resolves the ambiguity.\n */\nconst findEntry = (\n\tentries: ReadonlyMap<string, BunEntry>,\n\tkeys: ReadonlySet<string>,\n\tfromKey: string,\n\tname: string,\n): BunEntry | undefined => {\n\tlet scope = fromKey;\n\tfor (;;) {\n\t\tconst found = entries.get(scope === \"\" ? name : `${scope}/${name}`);\n\t\tif (found !== undefined) return found;\n\t\tif (scope === \"\") return undefined;\n\t\tscope = parentKey(keys, scope);\n\t}\n};\n\nconst parentKey = (keys: ReadonlySet<string>, key: string): string => {\n\tfor (let at = key.lastIndexOf(\"/\"); at > 0; at = key.lastIndexOf(\"/\", at - 1)) {\n\t\tconst prefix = key.slice(0, at);\n\t\tif (keys.has(prefix)) return prefix;\n\t}\n\treturn \"\";\n};\n","/**\n * `package-lock.json` / `npm-shrinkwrap.json`.\n *\n * npm records *ranges* on its edges and relies on the directory nesting to say\n * which copy of a package a range resolved to, so the node resolution walk-up —\n * look beside me, then in my parent, then my grandparent — is reimplemented\n * here.\n */\nimport { EdgeKind, LockedRootKind } from \"../enums/edge-kind.js\";\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { isRecord } from \"../utils/is-record.js\";\nimport { optionalPeerNames, parseJsonObject, stringOr, stringRecord } from \"./json.js\";\nimport {\n\tasExactVersion,\n\tfieldByRootKind,\n\timporterKey,\n\tnotCovered,\n\tTreeBuilder,\n} from \"./tree-builder.js\";\nimport type { LockedEdge, LockedTree } from \"./types.js\";\n\n/** One entry of the v2/v3 `packages` map, after narrowing. */\ntype NpmEntry = {\n\treadonly path: string;\n\treadonly version: string;\n\t/** Set when the install name differs from the real one — an `npm:` alias. */\n\treadonly realName: string;\n\treadonly dependencies: Readonly<Record<string, string>>;\n\treadonly optionalDependencies: Readonly<Record<string, string>>;\n\treadonly peerDependencies: Readonly<Record<string, string>>;\n\treadonly optionalPeers: ReadonlySet<string>;\n};\n\n/** Root blocks in npm's precedence order — the first mention of a name wins. */\nconst ROOT_KINDS = [\n\tLockedRootKind.Prod,\n\tLockedRootKind.Optional,\n\tLockedRootKind.Dev,\n\tLockedRootKind.Peer,\n] as const;\n\n/**\n * The node resolution walk-up, over a flat map of install paths.\n *\n * A package at `node_modules/a/node_modules/b` depending on `c` gets, in order,\n * `node_modules/a/node_modules/b/node_modules/c`, then\n * `node_modules/a/node_modules/c`, then `node_modules/c`. This is what makes a\n * range on an edge unambiguous: the nesting already recorded which copy won.\n */\nconst NESTING = \"/node_modules/\";\n\nexport const parseNpmLockfile = (\n\tpath: string,\n\tcontent: string,\n\timporter: string | undefined,\n): LockedTree => {\n\tconst root = parseJsonObject(path, content);\n\tconst version = String(root[\"lockfileVersion\"] ?? \"?\");\n\tconst builder = new TreeBuilder();\n\n\t// v2 carries both shapes for backwards compatibility; `packages` is the\n\t// accurate one, so it wins whenever it is there.\n\tconst packages = root[\"packages\"];\n\tconst entries = isRecord(packages)\n\t\t? collectEntries(builder, packages)\n\t\t: collectLegacyEntries(builder, root);\n\n\tfor (const entry of entries.values()) {\n\t\tbuilder.add({\n\t\t\tname: entry.realName,\n\t\t\tversion: entry.version,\n\t\t\tdependencies: edgesOf(builder, entries, entry),\n\t\t});\n\t}\n\n\tcollectRoots(builder, entries, isRecord(packages) ? packages : root, path, importer);\n\n\treturn builder.finish({ format: LockfileFormat.Npm, lockfileVersion: version, path, importer });\n};\n\n/** Narrows the v2/v3 `packages` map, dropping what cannot be bundled. */\nconst collectEntries = (\n\tbuilder: TreeBuilder,\n\tpackages: Record<string, unknown>,\n): Map<string, NpmEntry> => {\n\tconst entries = new Map<string, NpmEntry>();\n\n\tfor (const [entryPath, raw] of Object.entries(packages)) {\n\t\t// The root project itself, and workspace members, are not things to fetch.\n\t\tconst installName = installNameFromPath(entryPath);\n\t\tif (installName === null) continue;\n\t\tif (!isRecord(raw)) continue;\n\n\t\t// A symlinked workspace member. Nothing to fetch, but an edge into it has\n\t\t// to be explained rather than counted as a hole in the file.\n\t\tif (raw[\"link\"] === true) {\n\t\t\tbuilder.skip(installName, stringOr(raw[\"resolved\"], \"link\"), \"workspace link\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst rawVersion = raw[\"version\"];\n\t\tif (typeof rawVersion !== \"string\") {\n\t\t\tbuilder.warn(\n\t\t\t\t`skipped ${installName} — its lockfile entry records no version, so there is nothing to pin`,\n\t\t\t);\n\t\t\tcontinue;\n\t\t}\n\n\t\tconst resolvedName = typeof raw[\"name\"] === \"string\" ? raw[\"name\"] : installName;\n\t\tconst version = asExactVersion(resolvedName, rawVersion);\n\t\tif (version._tag === \"Unsupported\") {\n\t\t\tbuilder.skip(resolvedName, rawVersion, version.reason);\n\t\t\tcontinue;\n\t\t}\n\n\t\t// `resolved` names a git or tarball URL for anything not from a registry,\n\t\t// even when `version` looks ordinary.\n\t\tconst resolvedUrl = raw[\"resolved\"];\n\t\tif (typeof resolvedUrl === \"string\" && !isRegistryUrl(resolvedUrl)) {\n\t\t\tbuilder.skip(resolvedName, resolvedUrl, \"not a registry tarball\");\n\t\t\tcontinue;\n\t\t}\n\n\t\tentries.set(entryPath, {\n\t\t\tpath: entryPath,\n\t\t\tversion: version.version,\n\t\t\trealName: resolvedName,\n\t\t\tdependencies: stringRecord(raw[\"dependencies\"]),\n\t\t\toptionalDependencies: stringRecord(raw[\"optionalDependencies\"]),\n\t\t\tpeerDependencies: stringRecord(raw[\"peerDependencies\"]),\n\t\t\toptionalPeers: optionalPeerNames(raw[\"peerDependenciesMeta\"]),\n\t\t});\n\t}\n\n\treturn entries;\n};\n\n/**\n * Flattens a v1 lockfile's nested `dependencies` tree into the same\n * path-keyed shape v2 uses.\n *\n * v1 is old — npm 6 — but it is exactly the vintage still pinned inside a lot\n * of the locked-down environments this tool exists for, so it is worth the\n * thirty lines rather than an error telling somebody to upgrade npm.\n */\nconst collectLegacyEntries = (\n\tbuilder: TreeBuilder,\n\troot: Record<string, unknown>,\n): Map<string, NpmEntry> => {\n\tconst entries = new Map<string, NpmEntry>();\n\n\tconst visit = (tree: unknown, prefix: string): void => {\n\t\tif (!isRecord(tree)) return;\n\t\tfor (const [name, raw] of Object.entries(tree)) {\n\t\t\tif (!isRecord(raw)) continue;\n\t\t\tconst entryPath =\n\t\t\t\tprefix === \"\" ? `node_modules/${name}` : `${prefix}/node_modules/${name}`;\n\n\t\t\tconst rawVersion = raw[\"version\"];\n\t\t\tif (typeof rawVersion === \"string\") {\n\t\t\t\tconst version = asExactVersion(name, rawVersion);\n\t\t\t\tif (version._tag === \"Unsupported\") {\n\t\t\t\t\tbuilder.skip(name, rawVersion, version.reason);\n\t\t\t\t} else {\n\t\t\t\t\tentries.set(entryPath, {\n\t\t\t\t\t\tpath: entryPath,\n\t\t\t\t\t\tversion: version.version,\n\t\t\t\t\t\trealName: name,\n\t\t\t\t\t\t// v1 calls the edge set `requires`.\n\t\t\t\t\t\tdependencies: stringRecord(raw[\"requires\"]),\n\t\t\t\t\t\toptionalDependencies: {},\n\t\t\t\t\t\tpeerDependencies: {},\n\t\t\t\t\t\toptionalPeers: new Set(),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tvisit(raw[\"dependencies\"], entryPath);\n\t\t}\n\t};\n\n\tvisit(root[\"dependencies\"], \"\");\n\treturn entries;\n};\n\n/** Turns one entry's ranges into edges, resolved through the directory nesting. */\nconst edgesOf = (\n\tbuilder: TreeBuilder,\n\tentries: ReadonlyMap<string, NpmEntry>,\n\tentry: NpmEntry,\n): ReadonlyArray<LockedEdge> => {\n\tconst edges: Array<LockedEdge> = [];\n\n\tconst add = (names: ReadonlyArray<string>, kind: EdgeKind): void => {\n\t\tfor (const name of names) {\n\t\t\tconst targetPath = resolveNestedEdge(entries, entry.path, name);\n\t\t\tconst target = targetPath === null ? undefined : entries.get(targetPath);\n\t\t\tif (target === undefined) {\n\t\t\t\t// Only required edges are worth raising: an optional or peer edge that\n\t\t\t\t// resolves to nothing is how a lockfile records \"not installed here\",\n\t\t\t\t// which npm itself tolerates.\n\t\t\t\tif (kind === EdgeKind.Prod)\n\t\t\t\t\tbuilder.dangling(`${entry.realName}@${entry.version}`, name);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tedges.push({ name: target.realName, version: target.version, kind });\n\t\t}\n\t};\n\n\tconst optionalNames = Object.keys(entry.optionalDependencies);\n\tconst optional = new Set(optionalNames);\n\n\t// An entry listed in both is optional: that is how npm records \"wanted, but\n\t// the install may proceed without it\".\n\tadd(\n\t\tObject.keys(entry.dependencies).filter((name) => !optional.has(name)),\n\t\tEdgeKind.Prod,\n\t);\n\tadd(optionalNames, EdgeKind.Optional);\n\tadd(\n\t\tObject.keys(entry.peerDependencies).filter((name) => !entry.optionalPeers.has(name)),\n\t\tEdgeKind.Peer,\n\t);\n\n\treturn edges;\n};\n\n/**\n * Reads the root project's direct dependencies.\n *\n * The lockfile records these under `packages[\"\"]` for v2/v3. v1 has no such\n * entry, so every top-level `node_modules/x` is treated as direct — which\n * over-counts roots slightly on v1 and is the best that file can support.\n */\nconst collectRoots = (\n\tbuilder: TreeBuilder,\n\tentries: ReadonlyMap<string, NpmEntry>,\n\tsource: Record<string, unknown>,\n\tpath: string,\n\timporter: string | undefined,\n): void => {\n\t// Resolution starts from the member's own directory, so a dependency it\n\t// nests privately wins over the hoisted copy — the same rule node applies,\n\t// which is why the walk-up is shared with ordinary edges.\n\tconst collectFrom = (from: string, project: Record<string, unknown>): void => {\n\t\tfor (const kind of ROOT_KINDS) {\n\t\t\tconst field = fieldByRootKind[kind];\n\t\t\tfor (const [name, specifier] of Object.entries(stringRecord(project[field]))) {\n\t\t\t\tconst targetPath = resolveNestedEdge(entries, from, name);\n\t\t\t\tconst target = targetPath === null ? undefined : entries.get(targetPath);\n\t\t\t\tif (target === undefined) continue;\n\t\t\t\tbuilder.addRoot({\n\t\t\t\t\tname: target.realName,\n\t\t\t\t\tversion: target.version,\n\t\t\t\t\tkind,\n\t\t\t\t\tspecifier,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t};\n\n\tif (importer !== undefined) {\n\t\tconst key = importerKey(importer);\n\t\tconst project = source[key];\n\t\tif (!isRecord(project)) notCovered(path, importer, workspacePaths(source));\n\t\telse collectFrom(key, project);\n\t\treturn;\n\t}\n\n\t// No member named: every project the file records contributes, which is what\n\t// pointing --file straight at a monorepo's lockfile should mean.\n\tconst projects = Object.entries(source).flatMap(([key, value]) =>\n\t\tisRecord(value) && !key.includes(\"node_modules/\") ? [[key, value] as const] : [],\n\t);\n\n\tif (projects.length > 0) {\n\t\tfor (const [key, project] of projects) collectFrom(key, project);\n\t\treturn;\n\t}\n\n\t// v1 records no project entry at all, so every top-level install is direct.\n\tfor (const entry of entries.values()) {\n\t\tif (entry.path.includes(NESTING)) continue;\n\t\tbuilder.addRoot({\n\t\t\tname: entry.realName,\n\t\t\tversion: entry.version,\n\t\t\tkind: LockedRootKind.Prod,\n\t\t});\n\t}\n};\n\n/** The workspace paths a v2/v3 lockfile records, for a \"does not cover\" message. */\nconst workspacePaths = (source: Record<string, unknown>): ReadonlyArray<string> =>\n\tObject.keys(source).flatMap((key) =>\n\t\tkey === \"\" ? \".\" : key.includes(\"node_modules/\") ? [] : key,\n\t);\n\n/**\n * npm records non-registry sources as a URL in `resolved`. Registry tarballs\n * are ordinary http(s); anything with a `git+`, `file:` or bare path form is\n * something we cannot fetch.\n */\nconst isRegistryUrl = (url: string): boolean =>\n\turl.startsWith(\"http://\") || url.startsWith(\"https://\");\n\nconst resolveNestedEdge = (\n\tentries: ReadonlyMap<string, NpmEntry>,\n\tfromPath: string,\n\tname: string,\n): string | null => {\n\tlet scope = fromPath;\n\tfor (;;) {\n\t\tconst candidate = scope === \"\" ? `node_modules/${name}` : `${scope}${NESTING}${name}`;\n\t\tif (entries.has(candidate)) return candidate;\n\t\tif (scope === \"\") return null;\n\t\tconst at = scope.lastIndexOf(NESTING);\n\t\tscope = at === -1 ? \"\" : scope.slice(0, at);\n\t}\n};\n\n/** `node_modules/@babel/core` -> `@babel/core`; a workspace path -> `null`. */\nconst installNameFromPath = (entryPath: string): string | null => {\n\tconst marker = \"node_modules/\";\n\tconst at = entryPath.lastIndexOf(marker);\n\tif (at === -1) return null;\n\tconst name = entryPath.slice(at + marker.length);\n\treturn name.length === 0 ? null : name;\n};\n","/**\n * `pnpm-lock.yaml`.\n *\n * The easy one: pnpm's snapshots already name exact versions, so there is no\n * nesting walk-up to reimplement. The fiddly parts are the three package-key\n * encodings still in the wild and the parenthesised peer-resolution suffix.\n */\nimport semver from \"semver\";\nimport { parse as parseYaml } from \"yaml\";\n\nimport { parseDependencyTarget } from \"../dependency-range.js\";\nimport { EdgeKind, LockedRootKind } from \"../enums/edge-kind.js\";\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { LockfileError } from \"../errors.js\";\nimport { isRecord } from \"../utils/is-record.js\";\nimport { describeError } from \"./json.js\";\nimport { fieldByRootKind, notCovered, TreeBuilder } from \"./tree-builder.js\";\nimport type { LockedEdge, LockedTree } from \"./types.js\";\n\n/** `name@version`, as a snapshot or importer entry resolves to. */\ntype PnpmReference = {\n\treadonly name: string;\n\treadonly version: string;\n};\n\n/** pnpm never records peer dependencies against an importer. */\nconst ROOT_KINDS = [LockedRootKind.Prod, LockedRootKind.Optional, LockedRootKind.Dev] as const;\n\nexport const parsePnpmLockfile = (\n\tpath: string,\n\tcontent: string,\n\timporter: string | undefined,\n): LockedTree => {\n\tlet root: unknown;\n\ttry {\n\t\troot = parseYaml(content);\n\t} catch (error) {\n\t\tthrow new LockfileError(path, `not valid YAML — ${describeError(error)}`, { cause: error });\n\t}\n\tif (!isRecord(root)) {\n\t\tthrow new LockfileError(path, \"top level is not a mapping\");\n\t}\n\n\tconst version = String(root[\"lockfileVersion\"] ?? \"?\");\n\tconst builder = new TreeBuilder();\n\n\t// v9 split the graph in two: `packages` keeps resolution metadata, and\n\t// `snapshots` keeps the edges. Before that both lived in `packages`.\n\tconst packages = isRecord(root[\"packages\"]) ? root[\"packages\"] : {};\n\tconst snapshots = isRecord(root[\"snapshots\"]) ? root[\"snapshots\"] : packages;\n\n\tconst known = new Map<string, PnpmReference>();\n\tfor (const key of Object.keys(packages)) {\n\t\tconst parsed = parsePnpmKey(key);\n\t\tif (parsed === null) continue;\n\t\tknown.set(key, parsed);\n\t}\n\n\tfor (const [key, raw] of Object.entries(snapshots)) {\n\t\tconst parsed = parsePnpmKey(key) ?? known.get(key);\n\t\tif (parsed === undefined || parsed === null) {\n\t\t\tconst described = describeKey(key);\n\t\t\tif (described !== null) builder.skip(described.name, described.spec, described.reason);\n\t\t\tcontinue;\n\t\t}\n\t\tbuilder.add({\n\t\t\tname: parsed.name,\n\t\t\tversion: parsed.version,\n\t\t\tdependencies: edgesOf(builder, parsed, isRecord(raw) ? raw : {}),\n\t\t});\n\t}\n\n\tcollectRoots(builder, root, path, importer);\n\n\treturn builder.finish({\n\t\tformat: LockfileFormat.Pnpm,\n\t\tlockfileVersion: version,\n\t\tpath,\n\t\timporter,\n\t});\n};\n\nconst edgesOf = (\n\tbuilder: TreeBuilder,\n\tfrom: PnpmReference,\n\tsnapshot: Record<string, unknown>,\n): ReadonlyArray<LockedEdge> => {\n\tconst edges: Array<LockedEdge> = [];\n\n\tconst add = (field: string, kind: EdgeKind): void => {\n\t\tconst entries = snapshot[field];\n\t\tif (!isRecord(entries)) return;\n\t\tfor (const [name, raw] of Object.entries(entries)) {\n\t\t\tif (typeof raw !== \"string\") continue;\n\t\t\tconst target = parsePnpmReference(name, raw);\n\t\t\tif (target === null) {\n\t\t\t\tif (kind === EdgeKind.Prod) builder.dangling(`${from.name}@${from.version}`, name);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tedges.push({ ...target, kind });\n\t\t}\n\t};\n\n\tadd(fieldByRootKind[LockedRootKind.Prod], EdgeKind.Prod);\n\tadd(fieldByRootKind[LockedRootKind.Optional], EdgeKind.Optional);\n\tadd(fieldByRootKind[LockedRootKind.Peer], EdgeKind.Peer);\n\n\treturn edges;\n};\n\n/**\n * The importers' direct dependencies become the roots.\n *\n * pnpm is the format that makes this easy: `importers` is already keyed by the\n * path each package.json sits at, so scoping to one member is a lookup rather\n * than a reconstruction.\n */\nconst collectRoots = (\n\tbuilder: TreeBuilder,\n\troot: Record<string, unknown>,\n\tpath: string,\n\tmember: string | undefined,\n): void => {\n\t// A single-project lockfile has no `importers` block; its dependencies sit at\n\t// the top level, which is the same thing as an importer called \".\".\n\tconst importers = isRecord(root[\"importers\"]) ? root[\"importers\"] : { \".\": root };\n\n\tconst selected =\n\t\tmember === undefined\n\t\t\t? Object.values(importers)\n\t\t\t: Object.hasOwn(importers, member)\n\t\t\t\t? [importers[member]]\n\t\t\t\t: notCovered(path, member, Object.keys(importers));\n\n\tfor (const importer of selected) {\n\t\tif (!isRecord(importer)) continue;\n\t\tfor (const kind of ROOT_KINDS) {\n\t\t\tconst entries = importer[fieldByRootKind[kind]];\n\t\t\tif (!isRecord(entries)) continue;\n\n\t\t\tfor (const [name, raw] of Object.entries(entries)) {\n\t\t\t\t// v5 wrote a bare version string; v6 and v9 write\n\t\t\t\t// `{specifier, version}`.\n\t\t\t\tconst value =\n\t\t\t\t\ttypeof raw === \"string\" ? raw : isRecord(raw) ? raw[\"version\"] : undefined;\n\t\t\t\tif (typeof value !== \"string\") continue;\n\n\t\t\t\tconst target = parsePnpmReference(name, value);\n\t\t\t\tif (target === null) continue;\n\n\t\t\t\tconst specifier =\n\t\t\t\t\tisRecord(raw) && typeof raw[\"specifier\"] === \"string\"\n\t\t\t\t\t\t? raw[\"specifier\"]\n\t\t\t\t\t\t: undefined;\n\t\t\t\tbuilder.addRoot({ ...target, kind, specifier });\n\t\t\t}\n\t\t}\n\t}\n};\n\n/**\n * Reads a dependency value from a snapshot or importer.\n *\n * The value is either a bare version (`1.4.0`) or a full package key\n * (`/lodash@4.17.21`, used when the install name is an alias of another\n * package). Both may carry a peer-resolution suffix in parentheses.\n */\nconst parsePnpmReference = (name: string, raw: string): PnpmReference | null => {\n\tconst value = stripSuffix(raw);\n\n\tconst exact = semver.valid(value, { loose: true });\n\tif (exact !== null) return { name, version: exact };\n\n\treturn parsePnpmKey(raw);\n};\n\n/**\n * Splits a package key into name and version.\n *\n * Three encodings across the versions still in the wild:\n * v5 `/@babel/core/7.0.0`\n * v6 `/@babel/core@7.0.0`\n * v9 `@babel/core@7.0.0`\n *\n * plus an optional `(peer@1.0.0)` or `(patch_hash=…)` suffix on any of them.\n */\nexport const parsePnpmKey = (key: string): PnpmReference | null => {\n\tconst body = stripSuffix(key.startsWith(\"/\") ? key.slice(1) : key);\n\n\t// A scoped name's own `@` sits at index 0, so only a later one separates the\n\t// version. When there is none, this is the v5 form and the last `/` does it.\n\tconst at = body.lastIndexOf(\"@\");\n\tconst cut = at > 0 ? at : body.lastIndexOf(\"/\");\n\tif (cut <= 0) return null;\n\n\tconst name = body.slice(0, cut);\n\tconst version = semver.valid(body.slice(cut + 1), { loose: true });\n\tif (version === null || name.length === 0) return null;\n\n\treturn { name, version };\n};\n\n/** Describes a key we cannot pin, so the skip warning can say why. */\nconst describeKey = (\n\tkey: string,\n): { readonly name: string; readonly spec: string; readonly reason: string } | null => {\n\tconst body = key.startsWith(\"/\") ? key.slice(1) : key;\n\tconst at = body.lastIndexOf(\"@\");\n\tif (at <= 0) return null;\n\tconst name = body.slice(0, at);\n\tconst spec = body.slice(at + 1);\n\tconst target = parseDependencyTarget(name, spec);\n\treturn {\n\t\tname,\n\t\tspec,\n\t\treason: target._tag === \"Unsupported\" ? target.reason : \"not an exact version\",\n\t};\n};\n\n/**\n * Drops the parenthesised peer-resolution suffix.\n *\n * pnpm distinguishes the same version installed against different peers —\n * `react-dom@18.3.1(react@18.3.1)`. Those are the same published tarball, which\n * is all this tool downloads, so the suffix is noise here.\n */\nconst stripSuffix = (value: string): string => {\n\tconst open = value.indexOf(\"(\");\n\treturn open === -1 ? value : value.slice(0, open);\n};\n","/**\n * Lockfile parsing — npm, pnpm and bun.\n *\n * `--file package.json` reads *ranges*, and a range resolves to whatever is\n * newest at the moment the command runs. That is the right answer for \"bundle\n * me something installable\" and the wrong one for \"bundle exactly what CI\n * installed\" — which is what a lockfile records and what this module reads.\n *\n * Three formats, one output shape. Each parser's real job is the same: turn a\n * manager-specific encoding of \"package X at path P depends on Y\" into a flat\n * graph keyed by `name@version`, with every edge already pointing at a concrete\n * version. Once that is done, nothing downstream has to know which manager\n * wrote the file.\n */\nimport { LockfileFormat } from \"../enums/lockfile-format.js\";\nimport { LockfileError } from \"../errors.js\";\nimport { parseBunLockfile } from \"./bun.js\";\nimport { detectLockfile } from \"./detect.js\";\nimport { parseNpmLockfile } from \"./npm.js\";\nimport { parsePnpmLockfile } from \"./pnpm.js\";\nimport type { LockedTree, LockfileParseOptions } from \"./types.js\";\n\n/**\n * Parses lockfile content into a flat graph.\n *\n * Throws `LockfileError`; the caller is expected to be inside an `Effect.try`.\n */\nexport const parseLockfile = (\n\tpath: string,\n\tcontent: string,\n\tformat?: LockfileFormat,\n\toptions: LockfileParseOptions = {},\n): LockedTree => {\n\tconst resolved = format ?? resolveFormat(path, content);\n\tconst importer = options.importer;\n\tswitch (resolved) {\n\t\tcase LockfileFormat.Npm:\n\t\t\treturn parseNpmLockfile(path, content, importer);\n\t\tcase LockfileFormat.Pnpm:\n\t\t\treturn parsePnpmLockfile(path, content, importer);\n\t\tcase LockfileFormat.Bun:\n\t\t\treturn parseBunLockfile(path, content, importer);\n\t}\n};\n\nconst resolveFormat = (path: string, content: string): LockfileFormat => {\n\tconst detected = detectLockfile(content);\n\tif (detected._tag === \"Supported\") return detected.format;\n\tif (detected._tag === \"Unsupported\") {\n\t\tthrow new LockfileError(path, `${detected.label} — ${detected.hint}`);\n\t}\n\tthrow new LockfileError(\n\t\tpath,\n\t\t\"content does not look like a package-lock.json, pnpm-lock.yaml or bun.lock\",\n\t);\n};\n","/**\n * The package.json blocks `--file` reads, and what counts as readable.\n *\n * A narrow view on purpose: the only thing this tool wants from a package.json\n * is which packages it declares. Everything else — `scripts`, `exports`, the\n * half of the file that belongs to a bundler — is none of its business, and a\n * schema that insisted on understanding it would reject files that are fine.\n *\n * Every block is optional and every wrongly-typed one is simply absent, so a\n * hand-edited manifest produces a smaller spec list rather than a crash. That\n * is what `tolerant` buys: a `dependencies: \"all of them\"` loses one block, not\n * the file.\n */\nimport * as Schema from \"effect/Schema\";\n\nimport { OptionalFlagRecordSchema, StringRecordSchema, tolerant } from \"./lenient.js\";\n\nexport const PackageJsonSchema = Schema.Struct({\n\tdependencies: tolerant(StringRecordSchema),\n\tdevDependencies: tolerant(StringRecordSchema),\n\toptionalDependencies: tolerant(StringRecordSchema),\n\tpeerDependencies: tolerant(StringRecordSchema),\n\tpeerDependenciesMeta: tolerant(OptionalFlagRecordSchema),\n});\n\nexport type PackageJson = typeof PackageJsonSchema.Type;\n\nexport const decodePackageJson = Schema.decodeUnknownOption(PackageJsonSchema);\n","/**\n * `--file` handling.\n *\n * One flag, three accepted shapes, detected from the content rather than the\n * extension so that `--file deps.json` and `--file my-packages` both do the\n * obvious thing:\n *\n * - a **package.json** — bundle everything it depends on\n * - a **lockfile** — npm, pnpm or bun; bundle the exact versions it pins\n * - a **newline-delimited list** — one spec per line, `#` and `//` comments\n * allowed, blank lines ignored\n *\n * A lockfile is checked for first, because `package-lock.json` and\n * `package.json` are both JSON objects and only the content tells them apart.\n */\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Option from \"effect/Option\";\n\nimport { parseDependencyTarget } from \"./dependency-range.js\";\nimport { InputFileKind } from \"./enums/input-file-kind.js\";\nimport type { LockfileFormat } from \"./enums/lockfile-format.js\";\nimport type { InvalidSpecError, LockfileError } from \"./errors.js\";\nimport { InvalidInputFileError } from \"./errors.js\";\nimport { detectLockfile } from \"./lockfile/detect.js\";\nimport { parseLockfile } from \"./lockfile/parse.js\";\nimport type { LockedTree } from \"./lockfile/types.js\";\nimport type { PackageJson } from \"./schemas/package-json.js\";\nimport { decodePackageJson } from \"./schemas/package-json.js\";\nimport type { PackageSpec } from \"./spec.js\";\nimport { parseSpecs } from \"./spec.js\";\n\nexport type InputFileResult = {\n\treadonly kind: InputFileKind;\n\treadonly specs: ReadonlyArray<PackageSpec>;\n\t/** Entries that were recognised but cannot be bundled from a registry. */\n\treadonly warnings: ReadonlyArray<string>;\n\t/**\n\t * The pinned graph, set only for a lockfile.\n\t *\n\t * `specs` carries the same roots for display, but a lockfile run must resolve\n\t * from this — see `locked-resolve` for why re-resolving the roots' ranges\n\t * would quietly produce a different bundle.\n\t */\n\treadonly lockfile?: LockedTree | undefined;\n\t/**\n\t * Names from the blocks a package.json always installs — `dependencies` and,\n\t * unless `--prod`, `devDependencies`.\n\t *\n\t * Used to check a lockfile against the manifest beside it. Deliberately\n\t * excludes optional and peer entries: both are legitimately absent from a\n\t * lockfile (an optional dependency that failed to build, a peer the consumer\n\t * is expected to supply), so including them would turn a useful staleness\n\t * check into a false alarm.\n\t */\n\treadonly required?: ReadonlyArray<string> | undefined;\n};\n\n/** Which dependency blocks of a package.json become root specs. */\nexport type InputFileOptions = {\n\t/**\n\t * Include `devDependencies`.\n\t *\n\t * On by default: if you are pointing this tool at a package.json, you are\n\t * almost certainly trying to make that project installable behind the\n\t * firewall, and a project without its dev tooling does not build. `--prod`\n\t * turns it off.\n\t */\n\treadonly includeDev: boolean;\n\t/**\n\t * For a lockfile, which workspace member's dependencies are the roots.\n\t *\n\t * Set when a package.json found its lockfile by walking up: the file then\n\t * covers the whole repository, and only one member of it was asked for.\n\t */\n\treadonly importer?: string | undefined;\n};\n\nexport const defaultInputFileOptions: InputFileOptions = { includeDev: true };\n\n/** Reads and parses an input file. */\nexport const readInputFile = (\n\tfilePath: string,\n\toptions: InputFileOptions = defaultInputFileOptions,\n): Effect.Effect<InputFileResult, InvalidInputFileError | LockfileError, FileSystem.FileSystem> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\n\t\tconst exists = yield* fs\n\t\t\t.exists(filePath)\n\t\t\t.pipe(\n\t\t\t\tEffect.mapError(\n\t\t\t\t\t(cause) => new InvalidInputFileError(filePath, \"could not be read\", { cause }),\n\t\t\t\t),\n\t\t\t);\n\t\tif (!exists) {\n\t\t\treturn yield* Effect.fail(new InvalidInputFileError(filePath, \"file does not exist\"));\n\t\t}\n\n\t\tconst content = yield* fs\n\t\t\t.readFileString(filePath)\n\t\t\t.pipe(\n\t\t\t\tEffect.mapError(\n\t\t\t\t\t(cause) => new InvalidInputFileError(filePath, \"could not be read\", { cause }),\n\t\t\t\t),\n\t\t\t);\n\n\t\treturn yield* Effect.try({\n\t\t\ttry: () => parseInputFile(filePath, content, options),\n\t\t\tcatch: (error) =>\n\t\t\t\t// A LockfileError already names the file and says what is wrong with\n\t\t\t\t// it; wrapping it would only stutter.\n\t\t\t\terror instanceof InvalidInputFileError || isLockfileError(error)\n\t\t\t\t\t? error\n\t\t\t\t\t: new InvalidInputFileError(filePath, describeError(error), { cause: error }),\n\t\t});\n\t});\n\nconst isLockfileError = (error: unknown): error is LockfileError =>\n\terror instanceof Error && \"_tag\" in error && error._tag === \"LockfileError\";\n\n/**\n * Parses file content that has already been read.\n *\n * Split out from the IO so the whole of this logic is testable with plain\n * strings and no file system at all.\n */\nexport const parseInputFile = (\n\tfilePath: string,\n\tcontent: string,\n\toptions: InputFileOptions = defaultInputFileOptions,\n): InputFileResult => {\n\tconst trimmed = content.trim();\n\tif (trimmed.length === 0) {\n\t\tthrow new InvalidInputFileError(filePath, \"file is empty\");\n\t}\n\n\t// Checked first: a package-lock.json is also a JSON object whose top level\n\t// looks a lot like a package.json, and reading one as the other would produce\n\t// a bundle with none of the pinning that was asked for.\n\tconst detected = detectLockfile(trimmed);\n\tif (detected._tag === \"Unsupported\") {\n\t\tthrow new InvalidInputFileError(filePath, `${detected.label} — ${detected.hint}`);\n\t}\n\tif (detected._tag === \"Supported\") {\n\t\treturn fromLockfile(filePath, content, detected.format, options);\n\t}\n\n\treturn looksLikeJson(trimmed)\n\t\t? fromPackageJson(filePath, trimmed, options)\n\t\t: fromList(filePath, content);\n};\n\nconst looksLikeJson = (trimmed: string): boolean => trimmed.startsWith(\"{\");\n\n/* -------------------------------------------------------------------------- */\n/* Lockfile */\n/* -------------------------------------------------------------------------- */\n\nconst fromLockfile = (\n\tfilePath: string,\n\tcontent: string,\n\tformat: LockfileFormat,\n\toptions: InputFileOptions,\n): InputFileResult => {\n\tconst lockfile = parseLockfile(filePath, content, format, { importer: options.importer });\n\n\t// The same devDependency rule as a package.json, applied to the pinned roots\n\t// so that `specs` shows exactly what the run will bundle.\n\tconst roots = lockfile.roots.filter((root) => options.includeDev || root.kind !== \"dev\");\n\n\treturn {\n\t\tkind: InputFileKind.Lockfile,\n\t\tspecs: roots.map((root) => ({\n\t\t\tname: root.name,\n\t\t\tselector: { _tag: \"Exact\", version: root.version },\n\t\t\traw: `${root.name}@${root.version}`,\n\t\t})),\n\t\twarnings: lockfile.warnings,\n\t\tlockfile,\n\t};\n};\n\n/* -------------------------------------------------------------------------- */\n/* package.json */\n/* -------------------------------------------------------------------------- */\n\nconst fromPackageJson = (\n\tfilePath: string,\n\tcontent: string,\n\toptions: InputFileOptions,\n): InputFileResult => {\n\tconst parsed = parsePackageJson(filePath, content);\n\n\tconst specs: Array<PackageSpec> = [];\n\tconst warnings: Array<string> = [];\n\tconst required: Array<string> = [];\n\tconst seen = new Set<string>();\n\n\tconst collect = (\n\t\tentries: Record<string, string> | undefined,\n\t\tlabel: string,\n\t\tskip?: (name: string) => boolean,\n\t): void => {\n\t\tif (entries === undefined) return;\n\t\tfor (const [name, raw] of Object.entries(entries)) {\n\t\t\tif (skip?.(name)) continue;\n\t\t\tconst target = parseDependencyTarget(name, raw);\n\t\t\tif (target._tag === \"Unsupported\") {\n\t\t\t\twarnings.push(\n\t\t\t\t\t`${label}: skipped ${name}@${target.raw} (${target.reason}) — not fetchable from a registry`,\n\t\t\t\t);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// `target.name` rather than the key, so an `npm:` alias is recorded under\n\t\t\t// the name a lockfile would actually pin it as.\n\t\t\tif (label === \"dependencies\" || label === \"devDependencies\") required.push(target.name);\n\t\t\tconst key = `${target.name}|${JSON.stringify(target.selector)}`;\n\t\t\tif (seen.has(key)) continue;\n\t\t\tseen.add(key);\n\t\t\tspecs.push({\n\t\t\t\tname: target.name,\n\t\t\t\tselector: target.selector,\n\t\t\t\traw: `${target.name}@${raw}`,\n\t\t\t});\n\t\t}\n\t};\n\n\tcollect(parsed.dependencies, \"dependencies\");\n\tcollect(parsed.optionalDependencies, \"optionalDependencies\");\n\tif (options.includeDev) {\n\t\tcollect(parsed.devDependencies, \"devDependencies\");\n\t}\n\tconst meta = parsed.peerDependenciesMeta ?? {};\n\tcollect(parsed.peerDependencies, \"peerDependencies\", (name) => meta[name]?.optional === true);\n\n\tif (specs.length === 0) {\n\t\tthrow new InvalidInputFileError(\n\t\t\tfilePath,\n\t\t\toptions.includeDev\n\t\t\t\t? \"package.json declares no dependencies to bundle\"\n\t\t\t\t: \"package.json declares no non-dev dependencies to bundle (drop --prod to include devDependencies)\",\n\t\t);\n\t}\n\n\treturn { kind: InputFileKind.PackageJson, specs, warnings, required };\n};\n\n/**\n * Reads a package.json, or gives up on its contents rather than on the run.\n *\n * Invalid JSON is an error worth raising — somebody pointed `--file` at a\n * broken file. A well-formed JSON document this schema cannot recognise is\n * not: it decodes to no blocks, and the caller reports \"declares no\n * dependencies to bundle\", which is both true and more useful.\n */\nconst parsePackageJson = (filePath: string, content: string): PackageJson => {\n\tlet parsed: unknown;\n\ttry {\n\t\tparsed = JSON.parse(content);\n\t} catch (error) {\n\t\tthrow new InvalidInputFileError(filePath, `not valid JSON — ${describeError(error)}`, {\n\t\t\tcause: error,\n\t\t});\n\t}\n\n\treturn Option.getOrElse(decodePackageJson(parsed), (): PackageJson => ({}));\n};\n\n/* -------------------------------------------------------------------------- */\n/* Spec list */\n/* -------------------------------------------------------------------------- */\n\nconst fromList = (filePath: string, content: string): InputFileResult => {\n\tconst rawLines = content.split(/\\r?\\n/);\n\tconst lines = rawLines.flatMap((line) => {\n\t\tconst withoutComment = stripComment(line).trim();\n\t\treturn withoutComment.length === 0 ? [] : withoutComment;\n\t});\n\n\tif (lines.length === 0) {\n\t\tthrow new InvalidInputFileError(\n\t\t\tfilePath,\n\t\t\t\"no package specs found (only blank lines and comments)\",\n\t\t);\n\t}\n\n\tconst { specs, errors } = parseSpecs(lines);\n\tif (errors.length > 0) {\n\t\tthrow new InvalidInputFileError(filePath, formatSpecErrors(errors, rawLines));\n\t}\n\n\treturn { kind: InputFileKind.List, specs, warnings: [] };\n};\n\n/**\n * Strips `#` and `//` comments.\n *\n * `//` only counts when it is not part of a URL, so a future line containing\n * `https://…` does not get silently truncated.\n */\nconst stripComment = (line: string): string => {\n\tconst hash = line.indexOf(\"#\");\n\tconst result = hash === -1 ? line : line.slice(0, hash);\n\tconst slashes = result.indexOf(\"//\");\n\tif (slashes === 0) return \"\";\n\tif (slashes > 0 && result[slashes - 1] !== \":\") return result.slice(0, slashes);\n\treturn result;\n};\n\nconst formatSpecErrors = (\n\terrors: ReadonlyArray<InvalidSpecError>,\n\trawLines: ReadonlyArray<string>,\n): string => {\n\tconst details = errors.map((error) => {\n\t\tconst index = rawLines.findIndex((line) => stripComment(line).trim() === error.spec);\n\t\tconst where = index === -1 ? \"\" : ` (line ${index + 1})`;\n\t\treturn ` ${error.spec}${where}: ${error.reason}`;\n\t});\n\treturn `${errors.length} invalid spec(s):\\n${details.join(\"\\n\")}`;\n};\n\nconst describeError = (error: unknown): string =>\n\terror instanceof Error ? error.message : String(error);\n","/**\n * Fetching tarballs into the staging tree.\n *\n * Downloads run concurrently, every one is checksum-verified before it is\n * written, and the destination is always the scoped temp directory — nothing\n * lands next to the user's own files.\n */\nimport type * as Crypto from \"effect/Crypto\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport type { PlatformError } from \"effect/PlatformError\";\n\nimport { Phase } from \"./enums/phase.js\";\nimport type { BundlerError } from \"./errors.js\";\nimport { IntegrityError, OutputError } from \"./errors.js\";\nimport * as Integrity from \"./integrity.js\";\nimport { packagePath } from \"./layout.js\";\nimport * as Progress from \"./progress.js\";\nimport { Registry } from \"./registry.js\";\nimport type { ResolvedPackage } from \"./resolve.js\";\n\n/** What a completed download run produced. */\nexport type DownloadReport = {\n\t/** `name@version` -> bytes written. */\n\treadonly sizes: ReadonlyMap<string, number>;\n\t/** Packages the registry advertised no usable checksum for. */\n\treadonly unverified: ReadonlyArray<string>;\n\treadonly totalBytes: number;\n};\n\n/**\n * Downloads every package into `destDir`, laid out the way a registry serves\n * them.\n *\n * `verifyIntegrity` defaulting to on is deliberate: a corrupt tarball that\n * makes it into a corporate registry is far more expensive than a failed run.\n */\nexport const downloadAll = (\n\tpackages: ReadonlyArray<ResolvedPackage>,\n\tdestDir: string,\n\toptions: { readonly concurrency: number; readonly verifyIntegrity: boolean },\n): Effect.Effect<\n\tDownloadReport,\n\tBundlerError | PlatformError,\n\tRegistry | Progress.Progress | FileSystem.FileSystem | Path.Path | Crypto.Crypto\n> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\t\tconst registry = yield* Registry;\n\n\t\tyield* Progress.emit({\n\t\t\t_tag: \"PhaseStarted\",\n\t\t\tphase: Phase.Download,\n\t\t\ttotal: packages.length,\n\t\t});\n\n\t\tlet completed = 0;\n\t\tconst sizes = new Map<string, number>();\n\t\tconst unverified: Array<string> = [];\n\n\t\tconst results = yield* Effect.forEach(\n\t\t\tpackages,\n\t\t\t(pkg) =>\n\t\t\t\tEffect.gen(function* () {\n\t\t\t\t\tconst key = `${pkg.name}@${pkg.version}`;\n\n\t\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t\t_tag: \"DownloadStarted\",\n\t\t\t\t\t\tname: pkg.name,\n\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t});\n\n\t\t\t\t\tconst bytes = yield* registry.download(pkg.manifest);\n\n\t\t\t\t\tif (options.verifyIntegrity) {\n\t\t\t\t\t\tconst result = yield* Integrity.verify(bytes, pkg.manifest.dist);\n\t\t\t\t\t\tif (result._tag === \"Mismatch\") {\n\t\t\t\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\t\t\t\tnew IntegrityError(\n\t\t\t\t\t\t\t\t\tpkg.name,\n\t\t\t\t\t\t\t\t\tpkg.version,\n\t\t\t\t\t\t\t\t\tresult.expected,\n\t\t\t\t\t\t\t\t\tresult.actual,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (result._tag === \"Unverifiable\") {\n\t\t\t\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t\t\t\t_tag: \"Warning\",\n\t\t\t\t\t\t\t\tmessage: `${key} could not be verified (${result.reason})`,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst verifiable =\n\t\t\t\t\t\t(pkg.manifest.dist.integrity?.length ?? 0) > 0 ||\n\t\t\t\t\t\t(pkg.manifest.dist.shasum?.length ?? 0) > 0;\n\n\t\t\t\t\tconst relative = packagePath(pkg.name, pkg.version);\n\t\t\t\t\tconst target = path.join(destDir, ...relative.split(\"/\"));\n\n\t\t\t\t\tyield* fs\n\t\t\t\t\t\t.makeDirectory(path.dirname(target), { recursive: true })\n\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\tEffect.mapError(\n\t\t\t\t\t\t\t\t(cause) =>\n\t\t\t\t\t\t\t\t\tnew OutputError(\n\t\t\t\t\t\t\t\t\t\tpath.dirname(target),\n\t\t\t\t\t\t\t\t\t\t\"could not create directory\",\n\t\t\t\t\t\t\t\t\t\t{ cause },\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\tyield* fs\n\t\t\t\t\t\t.writeFile(target, bytes)\n\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\tEffect.mapError(\n\t\t\t\t\t\t\t\t(cause) =>\n\t\t\t\t\t\t\t\t\tnew OutputError(target, \"could not write tarball\", { cause }),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\n\t\t\t\t\t// Counting here rather than inside the concurrent body would be\n\t\t\t\t\t// wrong; each fiber increments as it finishes, which is what makes\n\t\t\t\t\t// the progress counter monotonic.\n\t\t\t\t\tcompleted += 1;\n\t\t\t\t\tyield* Progress.emit({\n\t\t\t\t\t\t_tag: \"DownloadCompleted\",\n\t\t\t\t\t\tname: pkg.name,\n\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\tbytes: bytes.byteLength,\n\t\t\t\t\t\tcompletedCount: completed,\n\t\t\t\t\t\ttotalCount: packages.length,\n\t\t\t\t\t});\n\n\t\t\t\t\treturn { key, bytes: bytes.byteLength, verifiable } as const;\n\t\t\t\t}),\n\t\t\t{ concurrency: options.concurrency },\n\t\t);\n\n\t\tfor (const result of results) {\n\t\t\tsizes.set(result.key, result.bytes);\n\t\t\tif (!result.verifiable) unverified.push(result.key);\n\t\t}\n\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Download });\n\n\t\treturn {\n\t\t\tsizes,\n\t\t\tunverified,\n\t\t\ttotalBytes: results.reduce((sum, result) => sum + result.bytes, 0),\n\t\t};\n\t});\n","/**\n * End-to-end orchestration: specs in, tarballs out.\n *\n * Two properties this module is responsible for — see `notes/requirements.md`\n * § FR-5 and § NFR-9 for why they are requirements, and the mechanisms below\n * for why the code reads as it does:\n *\n * 1. **Nothing is written outside the output directory.** Every intermediate\n * file lives in a scoped temp directory obtained from\n * `makeTempDirectoryScoped`, so the scope closing — on success, on failure,\n * or on Ctrl-C — takes the whole staging tree with it. The working\n * directory is never touched.\n *\n * 2. **Each package is downloaded exactly once**, no matter how many bundles\n * it ends up in. Per-spec archives are assembled by hard-linking out of one\n * shared download tree, so `per-spec` costs extra disk in the *output*, not\n * extra network.\n */\nimport type * as Crypto from \"effect/Crypto\";\nimport * as Effect from \"effect/Effect\";\nimport * as FileSystem from \"effect/FileSystem\";\nimport * as Path from \"effect/Path\";\nimport type { PlatformError } from \"effect/PlatformError\";\nimport type { Scope } from \"effect/Scope\";\n\nimport type { Archiver } from \"./archive.js\";\nimport { createArchive } from \"./archive.js\";\nimport { downloadAll } from \"./download.js\";\nimport { ArtifactKind } from \"./enums/artifact-kind.js\";\nimport { Layout } from \"./enums/layout.js\";\nimport { Phase } from \"./enums/phase.js\";\nimport type { BundlerError } from \"./errors.js\";\nimport { OutputError } from \"./errors.js\";\nimport {\n\tflatName,\n\timportGuide,\n\tMANIFEST_FILE,\n\tpackagePath,\n\tperSpecArchiveName,\n\tREADME_FILE,\n\tsingleArchiveName,\n} from \"./layout.js\";\nimport type { LockedResolveOptions } from \"./locked-resolve.js\";\nimport { resolveLocked } from \"./locked-resolve.js\";\nimport type { LockedTree } from \"./lockfile/types.js\";\nimport { buildManifest, serializeManifest } from \"./manifest.js\";\nimport type { BundleOptions } from \"./options.js\";\nimport * as Progress from \"./progress.js\";\nimport { Registry } from \"./registry.js\";\nimport type { PackageKey, Resolution, ResolvedPackage, RootResolution } from \"./resolve.js\";\nimport { indexPackages, resolve } from \"./resolve.js\";\nimport type { PackageSpec } from \"./spec.js\";\nimport { formatSpec } from \"./spec.js\";\n\n/** One thing written to the output directory. */\nexport type BundleArtifact = {\n\treadonly kind: ArtifactKind;\n\treadonly path: string;\n\treadonly bytes: number;\n\treadonly packageCount: number;\n\t/** Which spec this artifact covers. Only `per-spec` sets it. */\n\treadonly spec?: string | undefined;\n\treadonly version?: string | undefined;\n};\n\n/** The outcome of a bundle run. */\nexport type BundleResult = {\n\treadonly resolution: Resolution;\n\treadonly artifacts: ReadonlyArray<BundleArtifact>;\n\t/** Total bytes downloaded from the registry. */\n\treadonly downloadedBytes: number;\n\t/** Packages the registry advertised no usable checksum for. */\n\treadonly unverified: ReadonlyArray<string>;\n\treadonly dryRun: boolean;\n};\n\n/** Everything `bundle` needs beyond the user-facing options. */\nexport type BundleContext = BundleOptions & {\n\t/** Recorded in the manifest so a bundle can be traced to the tool that built it. */\n\treadonly toolVersion: string;\n};\n\n/**\n * A summary of what a resolution would produce, for deciding whether the\n * chosen layout is still the right one.\n */\nexport type PlanSummary = {\n\t/** Distinct packages in the deduplicated union. */\n\treadonly uniquePackages: number;\n\t/** How many archives `per-spec` layout would emit. */\n\treadonly perSpecArchives: number;\n\t/**\n\t * Total package entries across all per-spec archives, counting shared\n\t * dependencies once per archive they appear in. The gap between this and\n\t * `uniquePackages` is exactly what `single` layout would save.\n\t */\n\treadonly perSpecEntries: number;\n};\n\n/**\n * The files a run will write, known before anything is downloaded.\n *\n * `dir` and `flat` are the odd ones: they merge a package tree into `outDir`\n * rather than writing an archive. Either way a package's path is derived from\n * its name and version, so the same package at the same version is the same\n * bytes at the same path — an overlap is idempotent rather than destructive.\n * Only the two summary files are genuinely replaced, and those are the ones\n * worth guarding.\n */\nexport type PlannedOutput = {\n\treadonly file: string;\n\t/** The root this file belongs to, when one file corresponds to one spec. */\n\treadonly name?: string | undefined;\n\treadonly version?: string | undefined;\n};\n\ntype BundleEnv =\n\t| Registry\n\t| Progress.Progress\n\t| FileSystem.FileSystem\n\t| Path.Path\n\t| Crypto.Crypto\n\t| Archiver;\n\ntype EmitInput = {\n\treadonly resolution: Resolution;\n\treadonly options: BundleContext;\n\treadonly packagesDir: string;\n\treadonly report: { readonly sizes: ReadonlyMap<string, number> };\n\treadonly registryInfo: { readonly kind: string; readonly url: string };\n};\n\n/** One archive `per-spec` layout will write: a root, at one of its versions. */\ntype PerSpecTarget = {\n\treadonly root: RootResolution;\n\treadonly version: string;\n};\n\n/**\n * The archives `per-spec` emits — one per distinct root package version.\n *\n * Roots are *specs*, and several specs can name one package: `react`,\n * `react@latest` and `react@19.2.8` are three ways of asking for the same\n * thing, and after resolution they are indistinguishable. Without this they\n * were three archives — the same bytes, under the same file name, written over\n * each other. The run then reported three artifacts and three times the size\n * for one file on disk, and the duplication ratio it computes to decide whether\n * to ask about the layout counted them too, so the tool would offer to\n * deduplicate a bundle it had duplicated itself.\n *\n * Keyed by name and version rather than by the archive's file name. A scoped\n * name is flattened to make a file name, so `@foo/bar` and `foo-bar` can spell\n * the same one — and those are two different packages, which should collide\n * loudly rather than being merged here.\n *\n * Roots only. The packages *inside* an archive were deduplicated by resolution\n * long before this, which is why the same closure fetched from twenty specs is\n * fetched once.\n */\nconst perSpecTargets = (resolution: Resolution): ReadonlyArray<PerSpecTarget> => {\n\tconst seen = new Set<string>();\n\n\treturn resolution.roots.flatMap((root) =>\n\t\troot.versions.flatMap((version) => {\n\t\t\tconst key = `${root.spec.name}@${version}`;\n\t\t\tif (seen.has(key)) return [];\n\n\t\t\tseen.add(key);\n\t\t\treturn { root, version };\n\t\t}),\n\t);\n};\n\n/** Computes the plan summary for a resolution. */\nexport const summarize = (resolution: Resolution): PlanSummary => {\n\tlet perSpecArchives = 0;\n\tlet perSpecEntries = 0;\n\tfor (const { root, version } of perSpecTargets(resolution)) {\n\t\tperSpecArchives += 1;\n\t\tperSpecEntries += (root.closures.get(version) ?? []).length;\n\t}\n\treturn {\n\t\tuniquePackages: resolution.packages.length,\n\t\tperSpecArchives,\n\t\tperSpecEntries,\n\t};\n};\n\n/** Replaces the layout on a set of options. */\nexport const withLayout = <T extends BundleOptions>(options: T, layout: Layout): T => ({\n\t...options,\n\tlayout,\n});\n\n/**\n * Checks the registry is reachable, then resolves every spec.\n *\n * Split out from `bundle` so a caller can inspect the plan — how many packages,\n * how many archives — and act on it before any bytes move. The CLI uses this to\n * offer a different layout when a run turns out to be much larger than\n * expected.\n */\nexport const plan = (\n\tspecs: ReadonlyArray<PackageSpec>,\n\toptions: BundleOptions,\n): Effect.Effect<Resolution, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tyield* preflight;\n\t\treturn yield* resolve(specs, options);\n\t});\n\n/**\n * The lockfile counterpart of `plan`.\n *\n * Same preflight, same `Resolution` out; the difference is entirely in how the\n * package set is arrived at. Kept as a separate entry point rather than an\n * option on `plan` because the two take genuinely different inputs — a set of\n * specs to satisfy versus a graph to reproduce — and blurring that is how a\n * \"pinned\" run quietly starts resolving ranges again.\n */\nexport const planLocked = (\n\tlockfile: LockedTree,\n\toptions: BundleOptions & LockedResolveOptions,\n): Effect.Effect<Resolution, BundlerError, Registry | Progress.Progress> =>\n\tEffect.gen(function* () {\n\t\tyield* preflight;\n\t\treturn yield* resolveLocked(lockfile, options);\n\t});\n\nconst preflight: Effect.Effect<void, BundlerError, Registry | Progress.Progress> = Effect.gen(\n\tfunction* () {\n\t\tconst registry = yield* Registry;\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Preflight });\n\t\tyield* registry.preflight;\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Preflight });\n\t},\n);\n\n/**\n * Resolves, downloads and packages a set of specs.\n *\n * Under `dryRun` this stops after resolution and reports the plan — useful for\n * checking what a command *would* pull before committing to a multi-gigabyte\n * download over a slow VPN.\n */\nexport const bundle = (\n\tspecs: ReadonlyArray<PackageSpec>,\n\toptions: BundleContext,\n): Effect.Effect<BundleResult, BundlerError | PlatformError, BundleEnv> =>\n\tEffect.gen(function* () {\n\t\tconst resolution = yield* plan(specs, options);\n\t\treturn yield* bundleResolved(resolution, options);\n\t});\n\n/** `bundle`, pinned to a lockfile. */\nexport const bundleLocked = (\n\tlockfile: LockedTree,\n\toptions: BundleContext & LockedResolveOptions,\n): Effect.Effect<BundleResult, BundlerError | PlatformError, BundleEnv> =>\n\tEffect.gen(function* () {\n\t\tconst resolution = yield* planLocked(lockfile, options);\n\t\treturn yield* bundleResolved(resolution, options);\n\t});\n\n/**\n * Downloads and packages an already-computed resolution.\n *\n * Everything from here on touches the disk, and all of it happens inside\n * `Effect.scoped` — so the staging tree's lifetime is exactly this call,\n * including when it fails partway through or the user hits Ctrl-C.\n */\nexport const bundleResolved = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<BundleResult, BundlerError | PlatformError, BundleEnv> =>\n\tEffect.gen(function* () {\n\t\tif (options.dryRun) {\n\t\t\treturn {\n\t\t\t\tresolution,\n\t\t\t\tartifacts: [],\n\t\t\t\tdownloadedBytes: 0,\n\t\t\t\tunverified: [],\n\t\t\t\tdryRun: true,\n\t\t\t};\n\t\t}\n\t\treturn yield* Effect.scoped(runBundle(resolution, options));\n\t});\n\n/**\n * The files a run will write.\n *\n * Computed before anything is downloaded, so a collision is reported in the\n * first second rather than after a twenty-minute transfer.\n */\nexport const plannedOutputs = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): ReadonlyArray<PlannedOutput> => {\n\tif (options.layout === Layout.Dir || options.layout === Layout.Flat) {\n\t\treturn [{ file: MANIFEST_FILE }, { file: README_FILE }];\n\t}\n\tif (options.layout === Layout.Single) {\n\t\treturn [{ file: singleArchiveName(options.archiveName ?? \"bundle\") }];\n\t}\n\treturn perSpecTargets(resolution).map(({ root, version }) => ({\n\t\tfile: perSpecArchiveName(root.spec.name, version),\n\t\tname: root.spec.name,\n\t\tversion,\n\t}));\n};\n\nconst runBundle = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<BundleResult, BundlerError | PlatformError, BundleEnv | Scope> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\t\tconst registry = yield* Registry;\n\n\t\tyield* prepareOutputDir(resolution, options);\n\n\t\tconst staging = yield* fs.makeTempDirectoryScoped({ prefix: \"packall-\" });\n\t\tconst packagesDir = path.join(staging, \"packages\");\n\t\tyield* fs.makeDirectory(packagesDir, { recursive: true });\n\n\t\tconst report = yield* downloadAll(resolution.packages, packagesDir, {\n\t\t\tconcurrency: options.concurrency,\n\t\t\tverifyIntegrity: options.verifyIntegrity,\n\t\t});\n\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Archive });\n\n\t\tconst input: EmitInput = {\n\t\t\tresolution,\n\t\t\toptions,\n\t\t\tpackagesDir,\n\t\t\treport,\n\t\t\tregistryInfo: {\n\t\t\t\tkind: registry.kind,\n\t\t\t\turl: registry.registryFor(resolution.roots[0]?.spec.name ?? \"\"),\n\t\t\t},\n\t\t};\n\n\t\tconst artifacts = yield* emit(input, staging);\n\n\t\tyield* Progress.emit({ _tag: \"PhaseCompleted\", phase: Phase.Archive });\n\t\tyield* Progress.emit({ _tag: \"PhaseStarted\", phase: Phase.Done });\n\n\t\treturn {\n\t\t\tresolution,\n\t\t\tartifacts,\n\t\t\tdownloadedBytes: report.totalBytes,\n\t\t\tunverified: report.unverified,\n\t\t\tdryRun: false,\n\t\t};\n\t});\n\n/* -------------------------------------------------------------------------- */\n/* Emitters */\n/* -------------------------------------------------------------------------- */\n\nconst emit = (\n\tinput: EmitInput,\n\tstaging: string,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path | Progress.Progress | Archiver\n> => {\n\tswitch (input.options.layout) {\n\t\tcase Layout.Single:\n\t\t\treturn emitSingle(input);\n\t\tcase Layout.Dir:\n\t\t\treturn emitDirectory(input);\n\t\tcase Layout.PerSpec:\n\t\t\treturn emitPerSpec(input, staging);\n\t\tcase Layout.Flat:\n\t\t\treturn emitFlat(input, staging);\n\t}\n};\n\n/** One tarball containing the deduplicated union of every closure. */\nconst emitSingle = (\n\tinput: EmitInput,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path | Progress.Progress | Archiver\n> =>\n\tEffect.gen(function* () {\n\t\tconst path = yield* Path.Path;\n\n\t\tconst archiveName = singleArchiveName(input.options.archiveName ?? \"bundle\");\n\t\t// Declined at the prompt, and it is the run's only output.\n\t\tif (input.options.skipExisting?.has(archiveName) === true) return [];\n\n\t\tyield* writeBundleMetadata({\n\t\t\tdir: input.packagesDir,\n\t\t\tresolution: input.resolution,\n\t\t\tincluded: input.resolution.packages,\n\t\t\toptions: input.options,\n\t\t\tregistryInfo: input.registryInfo,\n\t\t\tsizes: input.report.sizes,\n\t\t});\n\n\t\tconst outPath = path.join(input.options.outDir, archiveName);\n\n\t\tconst result = yield* createArchive({\n\t\t\tcwd: input.packagesDir,\n\t\t\tentries: yield* topLevelEntries(input.packagesDir),\n\t\t\toutPath,\n\t\t});\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: ArtifactKind.Archive,\n\t\t\t\tpath: result.path,\n\t\t\t\tbytes: result.bytes,\n\t\t\t\tpackageCount: input.resolution.packages.length,\n\t\t\t},\n\t\t];\n\t});\n\n/** The raw npm-layout tree, no archive. */\nconst emitDirectory = (\n\tinput: EmitInput,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path\n> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\n\t\tyield* writeBundleMetadata({\n\t\t\tdir: input.packagesDir,\n\t\t\tresolution: input.resolution,\n\t\t\tincluded: input.resolution.packages,\n\t\t\toptions: input.options,\n\t\t\tregistryInfo: input.registryInfo,\n\t\t\tsizes: input.report.sizes,\n\t\t});\n\n\t\t// The staging tree is about to be deleted with its scope, so this is a\n\t\t// real copy rather than a move — `copy` also works across devices, which\n\t\t// matters because the temp dir often lives on a different filesystem.\n\t\tyield* fs.copy(input.packagesDir, input.options.outDir, { overwrite: true }).pipe(\n\t\t\tEffect.mapError(\n\t\t\t\t(cause) =>\n\t\t\t\t\tnew OutputError(input.options.outDir, \"could not write output tree\", {\n\t\t\t\t\t\tcause,\n\t\t\t\t\t}),\n\t\t\t),\n\t\t);\n\n\t\tconst bytes = [...input.report.sizes.values()].reduce((a, b) => a + b, 0);\n\n\t\treturn [\n\t\t\t{\n\t\t\t\tkind: ArtifactKind.Directory,\n\t\t\t\tpath: input.options.outDir,\n\t\t\t\tbytes,\n\t\t\t\tpackageCount: input.resolution.packages.length,\n\t\t\t},\n\t\t];\n\t});\n\n/**\n * The flat directory: every tarball side by side, no archive, no nesting.\n *\n * The tarballs are the untouched registry ones — only their names are ours,\n * and `bundlePath` says why.\n */\nconst emitFlat = (\n\tinput: EmitInput,\n\tstaging: string,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path\n> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\n\t\t// Staged and then copied rather than written straight into `outDir`, so a\n\t\t// failure partway through leaves the output directory as it was.\n\t\tconst flatDir = path.join(staging, \"flat\");\n\t\tyield* fs.makeDirectory(flatDir, { recursive: true });\n\n\t\tfor (const pkg of input.resolution.packages) {\n\t\t\tconst parts = packagePath(pkg.name, pkg.version).split(\"/\");\n\t\t\tyield* linkOrCopy(\n\t\t\t\tpath.join(input.packagesDir, ...parts),\n\t\t\t\tpath.join(flatDir, flatName(pkg.name, pkg.version)),\n\t\t\t);\n\t\t}\n\n\t\tyield* writeBundleMetadata({\n\t\t\tdir: flatDir,\n\t\t\tresolution: input.resolution,\n\t\t\tincluded: input.resolution.packages,\n\t\t\toptions: input.options,\n\t\t\tregistryInfo: input.registryInfo,\n\t\t\tsizes: input.report.sizes,\n\t\t});\n\n\t\tyield* fs.copy(flatDir, input.options.outDir, { overwrite: true }).pipe(\n\t\t\tEffect.mapError(\n\t\t\t\t(cause) =>\n\t\t\t\t\tnew OutputError(input.options.outDir, \"could not write output tree\", {\n\t\t\t\t\t\tcause,\n\t\t\t\t\t}),\n\t\t\t),\n\t\t);\n\n\t\t// One artifact per file, not one for the directory.\n\t\t//\n\t\t// `dir` reports its tree as a single artifact because the tree is the\n\t\t// unit: the paths are what make it importable, so half of it is worth\n\t\t// nothing. Flat has no paths to preserve and every file stands on its\n\t\t// own — `npm publish` takes them one at a time, in any order. Reporting\n\t\t// one artifact there contradicted the directory it had just written, and\n\t\t// the run said \"1 artifact\" over 56 files.\n\t\t//\n\t\t// The manifest and the import guide are counted too: under this layout\n\t\t// they are loose files the run produced, and a count that omitted them\n\t\t// would not match what `ls` shows.\n\t\tconst tarballs: ReadonlyArray<BundleArtifact> = input.resolution.packages.map((pkg) => ({\n\t\t\tkind: ArtifactKind.Archive,\n\t\t\tpath: path.join(input.options.outDir, flatName(pkg.name, pkg.version)),\n\t\t\tbytes: input.report.sizes.get(`${pkg.name}@${pkg.version}`) ?? 0,\n\t\t\tpackageCount: 1,\n\t\t}));\n\n\t\tconst summaries = yield* Effect.forEach([MANIFEST_FILE, README_FILE], (file) =>\n\t\t\tEffect.gen(function* () {\n\t\t\t\tconst info = yield* fs.stat(path.join(flatDir, file));\n\t\t\t\treturn {\n\t\t\t\t\tkind: ArtifactKind.File,\n\t\t\t\t\tpath: path.join(input.options.outDir, file),\n\t\t\t\t\tbytes: Number(info.size),\n\t\t\t\t\tpackageCount: 0,\n\t\t\t\t} satisfies BundleArtifact;\n\t\t\t}),\n\t\t);\n\n\t\treturn [...tarballs, ...summaries];\n\t});\n\n/**\n * One tarball per resolved root *version*.\n *\n * Under `--all-versions react@^18` this produces `react-18.0.0.tgz`,\n * `react-18.1.0.tgz` and so on, each independently importable — which is the\n * whole reason to prefer this layout.\n */\nconst emitPerSpec = (\n\tinput: EmitInput,\n\tstaging: string,\n): Effect.Effect<\n\tReadonlyArray<BundleArtifact>,\n\tBundlerError | PlatformError,\n\tFileSystem.FileSystem | Path.Path | Progress.Progress | Archiver\n> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\t\tconst index = indexPackages(input.resolution);\n\t\tconst artifacts: Array<BundleArtifact> = [];\n\n\t\tlet counter = 0;\n\t\tfor (const { root, version } of perSpecTargets(input.resolution)) {\n\t\t\t// Declined at the prompt: the existing file stays, and this archive is\n\t\t\t// simply never built. Skipping the staging work too, not just the write.\n\t\t\tif (\n\t\t\t\tinput.options.skipExisting?.has(perSpecArchiveName(root.spec.name, version)) ===\n\t\t\t\ttrue\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\tconst included = includedPackages(index, root.closures.get(version) ?? []);\n\n\t\t\tconst rootDir = path.join(staging, \"roots\", String(counter++));\n\t\t\tyield* fs.makeDirectory(rootDir, { recursive: true });\n\n\t\t\tfor (const pkg of included) {\n\t\t\t\tconst parts = packagePath(pkg.name, pkg.version).split(\"/\");\n\t\t\t\tconst source = path.join(input.packagesDir, ...parts);\n\t\t\t\tconst target = path.join(rootDir, ...parts);\n\t\t\t\tyield* fs.makeDirectory(path.dirname(target), { recursive: true });\n\t\t\t\tyield* linkOrCopy(source, target);\n\t\t\t}\n\n\t\t\tyield* writeBundleMetadata({\n\t\t\t\tdir: rootDir,\n\t\t\t\tresolution: {\n\t\t\t\t\t...input.resolution,\n\t\t\t\t\troots: [{ ...root, versions: [version] }],\n\t\t\t\t},\n\t\t\t\tincluded,\n\t\t\t\toptions: input.options,\n\t\t\t\tregistryInfo: input.registryInfo,\n\t\t\t\tsizes: input.report.sizes,\n\t\t\t});\n\n\t\t\tconst outPath = path.join(\n\t\t\t\tinput.options.outDir,\n\t\t\t\tperSpecArchiveName(root.spec.name, version),\n\t\t\t);\n\n\t\t\tconst result = yield* createArchive({\n\t\t\t\tcwd: rootDir,\n\t\t\t\tentries: yield* topLevelEntries(rootDir),\n\t\t\t\toutPath,\n\t\t\t});\n\n\t\t\tartifacts.push({\n\t\t\t\tkind: ArtifactKind.Archive,\n\t\t\t\tpath: result.path,\n\t\t\t\tbytes: result.bytes,\n\t\t\t\tpackageCount: included.length,\n\t\t\t\tspec: formatSpec(root.spec),\n\t\t\t\tversion,\n\t\t\t});\n\t\t}\n\n\t\treturn artifacts;\n\t});\n\n/* -------------------------------------------------------------------------- */\n/* Helpers */\n/* -------------------------------------------------------------------------- */\n\nconst includedPackages = (\n\tindex: ReadonlyMap<PackageKey, ResolvedPackage>,\n\tclosure: ReadonlyArray<PackageKey>,\n): ReadonlyArray<ResolvedPackage> => closure.flatMap((key) => index.get(key) ?? []);\n\n/**\n * Hard-links a file, falling back to a copy.\n *\n * Hard links make `per-spec` layout nearly free in the staging tree. They fail\n * across devices and on some Windows configurations, so the copy fallback is\n * not optional.\n */\nconst linkOrCopy = (\n\tsource: string,\n\ttarget: string,\n): Effect.Effect<void, PlatformError, FileSystem.FileSystem> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tyield* fs.link(source, target).pipe(Effect.catch(() => fs.copyFile(source, target)));\n\t});\n\n/** Writes the manifest and import guide into a staging directory. */\nconst writeBundleMetadata = (input: {\n\treadonly dir: string;\n\treadonly resolution: Resolution;\n\treadonly included: ReadonlyArray<ResolvedPackage>;\n\treadonly options: BundleContext;\n\treadonly registryInfo: { readonly kind: string; readonly url: string };\n\treadonly sizes: ReadonlyMap<string, number>;\n}): Effect.Effect<void, PlatformError, FileSystem.FileSystem | Path.Path> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\n\t\tconst createdAt = new Date();\n\t\tconst manifest = buildManifest({\n\t\t\tresolution: input.resolution,\n\t\t\tincluded: input.included,\n\t\t\toptions: input.options,\n\t\t\tregistry: input.registryInfo,\n\t\t\ttoolVersion: input.options.toolVersion,\n\t\t\tsizes: input.sizes,\n\t\t\tcreatedAt,\n\t\t});\n\n\t\tyield* fs.writeFileString(path.join(input.dir, MANIFEST_FILE), serializeManifest(manifest));\n\t\tyield* fs.writeFileString(\n\t\t\tpath.join(input.dir, README_FILE),\n\t\t\timportGuide({\n\t\t\t\tpackageCount: input.included.length,\n\t\t\t\tcreatedAt: createdAt.toISOString(),\n\t\t\t\ttoolVersion: input.options.toolVersion,\n\t\t\t\tlayout: input.options.layout,\n\t\t\t}),\n\t\t);\n\t});\n\n/** Sorted top-level entries of a directory, used as the tar entry list. */\nconst topLevelEntries = (\n\tdir: string,\n): Effect.Effect<ReadonlyArray<string>, PlatformError, FileSystem.FileSystem> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst entries = yield* fs.readDirectory(dir);\n\t\treturn entries.toSorted();\n\t});\n\n/**\n * `assertDistinctOutputs`, over package tarballs instead of archives.\n *\n * `flat` is the only layout with nothing but a file name to tell two packages\n * apart — everywhere else a tarball keeps its unique `name/-/` directory. What\n * is left to catch is the pathological pair, `@a/b-c` against `@a-b/c`; the\n * plausible one is impossible by construction, which is what `flatName` buys.\n */\nconst assertDistinctFlatNames = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<void, OutputError> =>\n\tEffect.gen(function* () {\n\t\tif (options.layout !== Layout.Flat) return;\n\n\t\tconst owners = new Map<string, Array<string>>();\n\t\tfor (const pkg of resolution.packages) {\n\t\t\tconst file = flatName(pkg.name, pkg.version);\n\t\t\tconst claimed = owners.get(file);\n\n\t\t\tif (claimed === undefined) owners.set(file, [`${pkg.name}@${pkg.version}`]);\n\t\t\telse claimed.push(`${pkg.name}@${pkg.version}`);\n\t\t}\n\n\t\tconst collisions = [...owners].filter(([, packages]) => packages.length > 1);\n\t\tif (collisions.length === 0) return;\n\n\t\tconst described = collisions\n\t\t\t.map(([file, packages]) => `${packages.join(\" and \")} would both be ${file}`)\n\t\t\t.join(\"; \");\n\n\t\treturn yield* Effect.fail(\n\t\t\tnew OutputError(\n\t\t\t\toptions.outDir,\n\t\t\t\t`two packages want the same file name — ${described}. \\`flat\\` layout has ` +\n\t\t\t\t\t`only the file name to tell them apart, and the \\`/\\` in a scope becomes ` +\n\t\t\t\t\t`a \\`-\\` to make one. Use --layout dir, which keeps each package in its ` +\n\t\t\t\t\t`own directory.`,\n\t\t\t),\n\t\t);\n\t});\n\n/**\n * Two different packages must not want the same file name.\n *\n * Most of what this used to catch is now impossible: an archive is named for\n * the spec, `@types-react@19.2.18.tgz`, and an unscoped npm name may not begin\n * with `@`, so it cannot spell a scoped one. What survives is **two scoped\n * packages whose scope boundary falls in a different place**, because that\n * boundary is the one character the file name drops:\n *\n * @a/b-c -> @a-b-c@1.0.0.tgz\n * @a-b/c -> @a-b-c@1.0.0.tgz\n *\n * Pathological rather than plausible — it needs somebody to hold the `@a-b`\n * scope as well as `@a`, and both packages in one run at one version. It is\n * kept anyway because of what it costs to be wrong: they are *different\n * packages*, so deduplicating them would be wrong, and writing both is worse —\n * the second lands on the first and the run reports two artifacts for the one\n * file that survived. A bundle short a package, called complete, found at the\n * far end of an air gap by somebody who cannot go and fetch the missing one.\n *\n * Nothing else would catch it. The overwrite check below compares this run's\n * planned files against what is *already on disk*, and both of these are new.\n *\n * So it refuses, and names both specs. Not silently renamed: an archive whose\n * name nobody chose is a file somebody has to identify later.\n *\n * Unconditional, unlike the overwrite check: `--force` is permission to replace\n * what was already in the directory, not to let one run overwrite itself.\n */\nconst assertDistinctOutputs = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<void, OutputError> =>\n\tEffect.gen(function* () {\n\t\tconst owners = new Map<string, Array<string>>();\n\n\t\t// Over `plannedOutputs` rather than the per-spec targets, so this asks\n\t\t// about the layout that is actually running. `single` writes one archive\n\t\t// and `dir` two summary files, neither of which can collide — and a check\n\t\t// that refused those would make its own advice impossible to take.\n\t\tfor (const planned of plannedOutputs(resolution, options)) {\n\t\t\tconst claimed = owners.get(planned.file);\n\t\t\tconst spec =\n\t\t\t\tplanned.name === undefined ? planned.file : `${planned.name}@${planned.version}`;\n\n\t\t\tif (claimed === undefined) owners.set(planned.file, [spec]);\n\t\t\telse claimed.push(spec);\n\t\t}\n\n\t\tconst collisions = [...owners].filter(([, specs]) => specs.length > 1);\n\t\tif (collisions.length === 0) return;\n\n\t\tconst described = collisions\n\t\t\t.map(([file, specs]) => `${specs.join(\" and \")} would both be ${file}`)\n\t\t\t.join(\"; \");\n\n\t\treturn yield* Effect.fail(\n\t\t\tnew OutputError(\n\t\t\t\toptions.outDir,\n\t\t\t\t`two packages want the same archive name — ${described}. The \\`/\\` in a ` +\n\t\t\t\t\t`scope becomes a \\`-\\` to make a file name, so \\`@a/b-c\\` and \\`@a-b/c\\` ` +\n\t\t\t\t\t`meet. Use --layout single, or bundle them into separate --out ` +\n\t\t\t\t\t`directories.`,\n\t\t\t),\n\t\t);\n\t});\n\n/**\n * Fails if the run would overwrite something, unless `--force`.\n *\n * The guard is on the *files this run writes*, not on whether the directory has\n * anything in it. An output directory accumulating bundles is the normal way to\n * use this — bundling `esbuild` into an `out/` that already holds `tsdown` is\n * not a conflict, and refusing it made `--out` a single-use directory and the\n * default `.` unusable.\n *\n * Checked before anything is downloaded. Discovering the collision *after* a\n * twenty-minute download would be a uniquely irritating way to fail — which is\n * also why `assertDistinctOutputs` runs from here rather than at emit time.\n */\nconst prepareOutputDir = (\n\tresolution: Resolution,\n\toptions: BundleContext,\n): Effect.Effect<void, OutputError | PlatformError, FileSystem.FileSystem | Path.Path> =>\n\tEffect.gen(function* () {\n\t\tconst fs = yield* FileSystem.FileSystem;\n\t\tconst path = yield* Path.Path;\n\t\tconst outDir = options.outDir;\n\n\t\tyield* assertDistinctOutputs(resolution, options);\n\t\tyield* assertDistinctFlatNames(resolution, options);\n\n\t\tif (!options.force) {\n\t\t\tconst clashes: Array<string> = [];\n\t\t\tfor (const planned of plannedOutputs(resolution, options)) {\n\t\t\t\tif (options.skipExisting?.has(planned.file) === true) continue;\n\t\t\t\tif (options.overwrite?.has(planned.file) === true) continue;\n\t\t\t\tconst exists = yield* fs\n\t\t\t\t\t.exists(path.join(outDir, planned.file))\n\t\t\t\t\t.pipe(Effect.orElseSucceed(() => false));\n\t\t\t\tif (exists) clashes.push(planned.file);\n\t\t\t}\n\n\t\t\tif (clashes.length > 0) {\n\t\t\t\treturn yield* Effect.fail(\n\t\t\t\t\tnew OutputError(\n\t\t\t\t\t\toutDir,\n\t\t\t\t\t\t`would overwrite ${clashes.length} existing file${clashes.length === 1 ? \"\" : \"s\"} ` +\n\t\t\t\t\t\t\t`(${clashes.slice(0, 3).join(\", \")}${clashes.length > 3 ? \", …\" : \"\"}). ` +\n\t\t\t\t\t\t\t`Pass --force true to replace ${clashes.length === 1 ? \"it\" : \"them\"}, or choose a different --out.`,\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tyield* fs\n\t\t\t.makeDirectory(outDir, { recursive: true })\n\t\t\t.pipe(\n\t\t\t\tEffect.mapError(\n\t\t\t\t\t(cause) =>\n\t\t\t\t\t\tnew OutputError(outDir, \"could not create output directory\", { cause }),\n\t\t\t\t),\n\t\t\t);\n\t});\n"],"mappings":";;;;;;;;;;;;;;;AAGA,MAAa,eAAe;CAC3B,SAAS;CACT,WAAW;CAMX,MAAM;CACN;;;;;;;;;;;;ACFD,MAAa,WAAW;CACvB,MAAM;CACN,UAAU;CACV,MAAM;CACN;;AAKD,MAAa,iBAAiB,EAC7B,KAAK,OACL;;AAKD,MAAa,iBAAiB;CAC7B,GAAG;CACH,GAAG;CACH;;;;;AC1BD,MAAa,gBAAgB;CAE5B,aAAa;CAEb,UAAU;CAEV,MAAM;CACN;;;;;ACPD,MAAa,SAAS;CAMrB,SAAS;CAKT,QAAQ;CAKR,KAAK;CAML,MAAM;CACN;AAID,MAAaA,UAAiC,OAAO,OAAO,OAAO;;;;;AC3BnE,MAAa,iBAAiB;CAC7B,KAAK;CACL,MAAM;CACN,KAAK;CACL;;;;;ACJD,MAAa,QAAQ;CACpB,WAAW;CACX,SAAS;CACT,UAAU;CACV,SAAS;CACT,MAAM;CACN;;;;;;;;;;ACHD,MAAa,YAAY,UACxB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,MAAM;;;;;;;;;;;;ACuBrE,MAAa,YAAkC,WAC9C,OAAO,SACN,OAAO,YAAY,OAAO,CAAC,KAC1B,OAAO,oBAAoB,OAAO,QAAQ,OAAO,KAAK,OAAU,CAAC,CAAC,CAClE,CACD;;;;;;;;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