@graftland/package-manager 0.4.0 → 0.4.1
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/dist/index.d.ts +17 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +42 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Changes, PackageName } from "./manifest.js";
|
|
2
|
+
import { PackageManagerDeclaration, PackageManagerName } from "./PackageManagerDeclaration.js";
|
|
2
3
|
import { SnapshotCleanupFailure, UnsupportedFileTypeError } from "./snapshot.js";
|
|
3
|
-
import { PackageManagerDeclaration } from "./PackageManagerDeclaration.js";
|
|
4
4
|
import { Cause, Effect, FileSystem, HashMap, Option, Path, PlatformError, Schema } from "effect";
|
|
5
5
|
import { ChildProcessSpawner } from "effect/process";
|
|
6
6
|
export declare const Agent: Schema.Literals<readonly ["npm", "pnpm", "yarn-classic", "yarn-berry"]>;
|
|
@@ -34,6 +34,22 @@ export interface Options {
|
|
|
34
34
|
/** Optional npm_config_user_agent supplied by the caller; used only as a fallback. */
|
|
35
35
|
readonly userAgent?: string;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The agent that runs a package manager. Yarn 1 is Classic and later versions
|
|
39
|
+
* are Berry; without a version, `yarn` means the Classic global binary.
|
|
40
|
+
*/
|
|
41
|
+
export declare const agentFor: (name: typeof PackageManagerName.Type, version?: string) => Agent;
|
|
42
|
+
/** A package manager and its version, as named by `npm_config_user_agent`. */
|
|
43
|
+
export interface UserAgent {
|
|
44
|
+
readonly name: typeof PackageManagerName.Type;
|
|
45
|
+
readonly version: string;
|
|
46
|
+
}
|
|
47
|
+
/** The first `name/version` of a user agent; other package managers, such as Bun, are none. */
|
|
48
|
+
export declare const parseUserAgent: (userAgent: string) => Option.Option<UserAgent>;
|
|
49
|
+
/** What runs a project script, such as `npm run` in `npm run dev`. */
|
|
50
|
+
export declare const runPrefix: (agent: Agent) => string;
|
|
51
|
+
/** The command that installs a project's dependencies. */
|
|
52
|
+
export declare const installCommand: (agent: Agent) => string;
|
|
37
53
|
/** packageManager, then lockfile, then caller user-agent, then npm. Conflicting lockfiles fail. */
|
|
38
54
|
export declare const detectAgent: (options: Options) => Effect.Effect<"npm" | "pnpm" | "yarn-berry" | "yarn-classic", PackageManagerError | PlatformError.PlatformError | Schema.SchemaError, FileSystem.FileSystem | Path.Path>;
|
|
39
55
|
export interface PackageState {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;qBAqDa,OAAK,OAAA;YAMN,eAAe,MAAM;;;;;;WAGd;;qBAFN,4BAA4B;;;;;;;;;;WAUtB;;qBAFN,8BAA8B;YAoC/B,QACT,sBACA,2BACA,wBACA,cAAc,gBACd,OAAO;iBACO;;WAEP;;WAEA,QAAQ;;WAER
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";;;;;qBAqDa,OAAK,OAAA;YAMN,eAAe,MAAM;;;;;;WAGd;;qBAFN,4BAA4B;;;;;;;;;;WAUtB;;qBAFN,8BAA8B;YAoC/B,QACT,sBACA,2BACA,wBACA,cAAc,gBACd,OAAO;iBACO;;WAEP;;WAEA,QAAQ;;WAER;;;;;;qBAkGG,WAAQ,aACP,mBAAmB,MAAI,qBAElC;;iBAQc;WACP,aAAa,mBAAmB;WAChC;;;qBAUG,iBAAc,sBAAwB,OAAO,OAAO;;qBAOpD,YAAS,OAAW;;qBAIpB,iBAAc,OAAW;;qBAIzB,cAAW,SAAA,YAAA,OAAA,uDAAA,sBAAA,cAAA,gBAAA,OAAA,aAAA,WAAA,aAAA,KAAA;iBAsEP;WACP;;WAEA;WACA;;;YAGE,QAAQ,QAAQ,gBAAgB;iBAC3B;WACP;WACA,QAAQ;WACR,OAAO;;iBAEA;WACP,OAAO,cAAc;WACrB,SAAS,cAAc;WACvB,SAAS,cAAc;;qBAEpB,YAAS,QAAY,OAAK,OAAS,UAAQ;iBA0BvC,sBAAsB;WAC7B,OAAO;;WAEP,wBAAwB,OAAO,OAAO;;iBAE/B;WACP;WACA,OAAO;WACP,WAAW,OAAO,OAAO,OAAO;;WAEhC,kBAAkB,OAAO,OAAO,OAAO,OAAO;;WAE9C,UAAU,SAAS,YAAY,OAAO,OAAO,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA6BzD,OAAI,SAAA,YAAA,OAAA,OAAA,gBAAA,OAAA,oBAAA,sBAAA,WAAA,aAAA,KAAA"}
|
package/dist/index.js
CHANGED
|
@@ -120,7 +120,25 @@ const decodeUserAgent = Schema.decodeUnknownOption(Schema.TemplateLiteralParser(
|
|
|
120
120
|
Digits,
|
|
121
121
|
Schema.String
|
|
122
122
|
]));
|
|
123
|
-
|
|
123
|
+
/**
|
|
124
|
+
* The agent that runs a package manager. Yarn 1 is Classic and later versions
|
|
125
|
+
* are Berry; without a version, `yarn` means the Classic global binary.
|
|
126
|
+
*/
|
|
127
|
+
const agentFor = (name, version) => name === "yarn" ? version === void 0 || String.split(".")(version)[0] === "1" ? "yarn-classic" : "yarn-berry" : name;
|
|
128
|
+
const decodeUserAgentName = Schema.decodeUnknownOption(Schema.TemplateLiteralParser([
|
|
129
|
+
Executable,
|
|
130
|
+
"/",
|
|
131
|
+
Schema.String.check(Schema.isMinLength(1))
|
|
132
|
+
]));
|
|
133
|
+
/** The first `name/version` of a user agent; other package managers, such as Bun, are none. */
|
|
134
|
+
const parseUserAgent = (userAgent) => Option.map(decodeUserAgentName(String.split(" ")(userAgent)[0] ?? ""), ([name, , version]) => ({
|
|
135
|
+
name,
|
|
136
|
+
version
|
|
137
|
+
}));
|
|
138
|
+
/** What runs a project script, such as `npm run` in `npm run dev`. */
|
|
139
|
+
const runPrefix = (agent) => agent === "npm" ? "npm run" : agent === "pnpm" ? "pnpm" : "yarn";
|
|
140
|
+
/** The command that installs a project's dependencies. */
|
|
141
|
+
const installCommand = (agent) => agent === "npm" ? "npm install" : agent === "pnpm" ? "pnpm install" : "yarn";
|
|
124
142
|
/** packageManager, then lockfile, then caller user-agent, then npm. Conflicting lockfiles fail. */
|
|
125
143
|
const detectAgent = Effect.fnUntraced(function* (options) {
|
|
126
144
|
if (options.agent !== void 0) return yield* Schema.decodeEffect(Agent)(options.agent);
|
|
@@ -132,7 +150,7 @@ const detectAgent = Effect.fnUntraced(function* (options) {
|
|
|
132
150
|
operation: "detect",
|
|
133
151
|
message: `Unsupported packageManager: ${manifest.packageManager}\n${error.message}`
|
|
134
152
|
})));
|
|
135
|
-
return
|
|
153
|
+
return agentFor(name, `${version.major}`);
|
|
136
154
|
}
|
|
137
155
|
const found = yield* Effect.filter(lockfiles, (file) => fs.exists(path.join(options.directory, file)));
|
|
138
156
|
const kinds = Array.dedupe(Array.map(found, (file) => file === "pnpm-lock.yaml" ? "pnpm" : file === "yarn.lock" ? "yarn" : "npm"));
|
|
@@ -150,7 +168,7 @@ const detectAgent = Effect.fnUntraced(function* (options) {
|
|
|
150
168
|
if (kinds[0] !== void 0) return kinds[0];
|
|
151
169
|
return Option.match(decodeUserAgent(options.userAgent ?? ""), {
|
|
152
170
|
onNone: () => "npm",
|
|
153
|
-
onSome: ([name, , major]) =>
|
|
171
|
+
onSome: ([name, , major]) => agentFor(name, major)
|
|
154
172
|
});
|
|
155
173
|
});
|
|
156
174
|
const diffState = (before, after) => {
|
|
@@ -343,6 +361,6 @@ const make = Effect.fnUntraced(function* (options) {
|
|
|
343
361
|
install
|
|
344
362
|
};
|
|
345
363
|
});
|
|
346
|
-
export { Agent, Changes, PackageManagerDeclaration, PackageManagerError, PackageName, RecoveryRequiredError, UnsupportedFileTypeError, detectAgent, diffState, make };
|
|
364
|
+
export { Agent, Changes, PackageManagerDeclaration, PackageManagerError, PackageName, RecoveryRequiredError, UnsupportedFileTypeError, agentFor, detectAgent, diffState, installCommand, make, parseUserAgent, runPrefix };
|
|
347
365
|
|
|
348
366
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/** Non-interactive package installation. Provide platform services at the application boundary. */\nimport {\n\tArray,\n\tCause,\n\tData,\n\tEffect,\n\tExit,\n\tFileSystem,\n\tHashMap,\n\tMatch,\n\tOption,\n\tPath,\n\tPlatformError,\n\tRecord,\n\tRef,\n\tSchema,\n\tSemaphore,\n\tStream,\n\tString,\n} from \"effect\"\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\"\n\nimport {\n\tapplyChanges,\n\tChanges,\n\tdecodeManifest,\n\tencodeManifest,\n\tfields,\n\ttype Manifest,\n} from \"./manifest\"\nimport {\n\tPackageManagerDeclaration,\n\tPackageManagerName,\n} from \"./PackageManagerDeclaration\"\nimport { terminateProcess } from \"./process\"\nimport {\n\tinspectManagedFiles,\n\tUnsupportedFileTypeError,\n\twithSnapshot,\n\twriteSnapshot,\n\ttype Contents,\n\ttype SnapshotCleanupFailure,\n} from \"./snapshot\"\n\nexport { PackageManagerDeclaration } from \"./PackageManagerDeclaration\"\n\nexport {\n\tUnsupportedFileTypeError,\n\ttype SnapshotCleanupFailure,\n} from \"./snapshot\"\n\nexport { Changes, PackageName } from \"./manifest\"\n\nexport const Agent = Schema.Literals([\n\t\"npm\",\n\t\"pnpm\",\n\t\"yarn-classic\",\n\t\"yarn-berry\",\n])\nexport type Agent = typeof Agent.Type\nexport class PackageManagerError extends Schema.TaggedError<\n\tPackageManagerError,\n\t{ readonly brand: unique symbol }\n>()(\"PackageManagerError\", {\n\toperation: Schema.Literals([\"detect\", \"install\", \"recover\", \"state\"]),\n\tmessage: Schema.String,\n\texitCode: Schema.optionalKey(Schema.Int),\n}) {}\nexport class RecoveryRequiredError extends Schema.TaggedError<\n\tRecoveryRequiredError,\n\t{ readonly brand: unique symbol }\n>()(\"RecoveryRequiredError\", {\n\tdirectory: Schema.String,\n\tsnapshotDirectory: Schema.String,\n\toperation: Schema.Literals([\"install\", \"recover\", \"rollback\"]),\n\tprocessId: Schema.optionalKey(Schema.Int),\n\tmessage: Schema.String,\n\tterminationCause: Schema.optionalKey(\n\t\tSchema.Cause(Schema.Unknown, Schema.Unknown),\n\t),\n\trecoveryCause: Schema.Cause(Schema.Unknown, Schema.Unknown),\n}) {}\n\ntype WriterState = Data.TaggedEnum<{\n\tManagedWritersIdle: {}\n\tRunning: {}\n\tFileWrite: {}\n\tUnconfirmed: {\n\t\treadonly operation: \"install\" | \"recover\"\n\t\treadonly processId: number\n\t\treadonly cause: Cause.Cause<PlatformError.PlatformError>\n\t}\n}>\n\nconst WriterState = Data.taggedEnum<WriterState>()\n\ntype ManagerState = Data.TaggedEnum<{\n\tReady: {}\n\tActive: { readonly writer: WriterState }\n\tRecoveryRequired: { readonly error: RecoveryRequiredError }\n}>\n\nconst ManagerState = Data.taggedEnum<ManagerState>()\n\nexport type Error =\n\t| PackageManagerError\n\t| UnsupportedFileTypeError\n\t| RecoveryRequiredError\n\t| PlatformError.PlatformError\n\t| Schema.SchemaError\nexport interface Options {\n\t/** Project directory, containing package.json. Use the workspace root for workspace installs. */\n\treadonly directory: string\n\t/** Explicit selection takes precedence over detection. */\n\treadonly agent?: Agent\n\t/** Optional npm_config_user_agent supplied by the caller; used only as a fallback. */\n\treadonly userAgent?: string\n}\nconst lockfiles = [\n\t\"package-lock.json\",\n\t\"npm-shrinkwrap.json\",\n\t\"pnpm-lock.yaml\",\n\t\"yarn.lock\",\n] as const\nconst backupFiles = [\n\t\"package.json\",\n\t...lockfiles,\n\t\".npmrc\",\n\t\"pnpm-workspace.yaml\",\n\t\".yarnrc\",\n\t\".yarnrc.yml\",\n\t\".yarn/install-state.gz\",\n\t\".pnp.cjs\",\n\t\".pnp.loader.mjs\",\n]\nconst strategy = (agent: Agent, operation: \"install\" | \"recover\") => {\n\tconst recovery = operation === \"recover\"\n\treturn Match.value(agent).pipe(\n\t\tMatch.when(\"npm\", () => ({\n\t\t\texecutable: \"npm\",\n\t\t\targs: [\n\t\t\t\t\"install\",\n\t\t\t\t\"--no-audit\",\n\t\t\t\t\"--no-fund\",\n\t\t\t\t...(recovery ? [\"--prefer-offline\"] : []),\n\t\t\t],\n\t\t\tenv: { CI: \"true\" },\n\t\t\tlockfiles: [\"package-lock.json\", \"npm-shrinkwrap.json\"],\n\t\t})),\n\t\tMatch.when(\"pnpm\", () => ({\n\t\t\texecutable: \"pnpm\",\n\t\t\targs: [\n\t\t\t\t\"install\",\n\t\t\t\trecovery ? \"--frozen-lockfile\" : \"--no-frozen-lockfile\",\n\t\t\t\t\"--config.confirmModulesPurge=false\",\n\t\t\t],\n\t\t\tenv: { CI: \"true\" },\n\t\t\tlockfiles: [\"pnpm-lock.yaml\"],\n\t\t})),\n\t\tMatch.when(\"yarn-classic\", () => ({\n\t\t\texecutable: \"yarn\",\n\t\t\targs: [\n\t\t\t\t\"install\",\n\t\t\t\t\"--non-interactive\",\n\t\t\t\t...(recovery ? [\"--frozen-lockfile\", \"--prefer-offline\"] : []),\n\t\t\t],\n\t\t\tenv: { CI: \"true\" },\n\t\t\tlockfiles: [\"yarn.lock\"],\n\t\t})),\n\t\tMatch.when(\"yarn-berry\", () => ({\n\t\t\texecutable: \"yarn\",\n\t\t\targs: [\"install\", ...(recovery ? [\"--immutable\"] : [])],\n\t\t\tenv: {\n\t\t\t\tCI: \"true\",\n\t\t\t\tYARN_ENABLE_IMMUTABLE_INSTALLS: recovery ? \"true\" : \"false\",\n\t\t\t\tYARN_NODE_LINKER: \"node-modules\",\n\t\t\t},\n\t\t\tlockfiles: [\"yarn.lock\"],\n\t\t})),\n\t\tMatch.exhaustive,\n\t)\n}\n\nconst readSource = Effect.fnUntraced(function* (\n\tfs: FileSystem.FileSystem,\n\tfile: string,\n) {\n\tconst bytes = yield* fs.readFile(file)\n\treturn yield* Effect.try({\n\t\ttry: () =>\n\t\t\tnew TextDecoder(\"utf-8\", { ignoreBOM: true, fatal: true }).decode(bytes),\n\t\tcatch: (cause) =>\n\t\t\tPlatformError.badArgument({\n\t\t\t\tmodule: \"FileSystem\",\n\t\t\t\tmethod: \"readManifest\",\n\t\t\t\tdescription: \"The manifest must contain valid UTF-8\",\n\t\t\t\tcause,\n\t\t\t}),\n\t})\n})\n\nconst Executable = PackageManagerName\nconst Digits = Schema.String.check(Schema.isPattern(/^\\d+$/))\nconst decodePackageManager = Schema.decodeUnknownEffect(\n\tPackageManagerDeclaration,\n)\n/** `name/version ...`, as package managers set `npm_config_user_agent`. */\nconst decodeUserAgent = Schema.decodeUnknownOption(\n\tSchema.TemplateLiteralParser([Executable, \"/\", Digits, Schema.String]),\n)\nconst agentOf = (name: typeof Executable.Type, major: string): Agent =>\n\tname === \"yarn\" ? (major === \"1\" ? \"yarn-classic\" : \"yarn-berry\") : name\n\n/** packageManager, then lockfile, then caller user-agent, then npm. Conflicting lockfiles fail. */\nexport const detectAgent = Effect.fnUntraced(function* (options: Options) {\n\tif (options.agent !== undefined)\n\t\treturn yield* Schema.decodeEffect(Agent)(options.agent)\n\tconst fs = yield* FileSystem.FileSystem\n\tconst path = yield* Path.Path\n\tconst manifest = yield* readSource(\n\t\tfs,\n\t\tpath.join(options.directory, \"package.json\"),\n\t).pipe(Effect.flatMap(decodeManifest))\n\tif (manifest.packageManager !== undefined) {\n\t\tconst [name, , version] = yield* decodePackageManager(\n\t\t\tmanifest.packageManager,\n\t\t).pipe(\n\t\t\t// Keep the schema issue: it names the constraint the declaration failed.\n\t\t\tEffect.mapError((error) =>\n\t\t\t\tPackageManagerError.make({\n\t\t\t\t\toperation: \"detect\",\n\t\t\t\t\tmessage: `Unsupported packageManager: ${manifest.packageManager}\\n${error.message}`,\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\t\treturn agentOf(name, `${version.major}`)\n\t}\n\tconst found = yield* Effect.filter(lockfiles, (file) =>\n\t\tfs.exists(path.join(options.directory, file)),\n\t)\n\tconst kinds = Array.dedupe(\n\t\tArray.map(found, (file) =>\n\t\t\tfile === \"pnpm-lock.yaml\"\n\t\t\t\t? \"pnpm\"\n\t\t\t\t: file === \"yarn.lock\"\n\t\t\t\t\t? \"yarn\"\n\t\t\t\t\t: \"npm\",\n\t\t),\n\t)\n\tif (kinds.length > 1)\n\t\treturn yield* PackageManagerError.make({\n\t\t\toperation: \"detect\",\n\t\t\tmessage: \"Conflicting lockfiles; select an agent explicitly\",\n\t\t})\n\tif (kinds[0] === \"yarn\") {\n\t\tconst metadata = yield* fs\n\t\t\t.stream(path.join(options.directory, \"yarn.lock\"))\n\t\t\t.pipe(\n\t\t\t\tStream.decodeText(),\n\t\t\t\tStream.mapAccum(\n\t\t\t\t\t// The initial newline models the start of the file.\n\t\t\t\t\t() => \"\\n\",\n\t\t\t\t\t(tail, chunk) => {\n\t\t\t\t\t\tconst text = tail + chunk\n\t\t\t\t\t\t// Preserve all ECMAScript line terminators, including across chunk boundaries.\n\t\t\t\t\t\t// Eleven characters retain a partial marker and its preceding character.\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tString.slice(-11)(text),\n\t\t\t\t\t\t\t[/[\\n\\r\\u2028\\u2029]__metadata:/.test(text)],\n\t\t\t\t\t\t]\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t\tStream.filter((found) => found),\n\t\t\t\tStream.runHead,\n\t\t\t)\n\t\treturn Option.isSome(metadata) ? \"yarn-berry\" : \"yarn-classic\"\n\t}\n\tif (kinds[0] !== undefined) return kinds[0]\n\treturn Option.match(decodeUserAgent(options.userAgent ?? \"\"), {\n\t\tonNone: () => \"npm\" as const,\n\t\tonSome: ([name, , major]) => agentOf(name, major),\n\t})\n})\n\nexport interface PackageState {\n\treadonly spec: string\n\t/** Missing optional or not-yet-installed dependencies have no version/path. */\n\treadonly version: string | undefined\n\treadonly path: string | undefined\n}\n/** Direct dependencies only, keyed by their manifest names (including aliases). */\nexport type State = HashMap.HashMap<string, PackageState>\nexport interface PackageChange {\n\treadonly name: string\n\treadonly before: PackageState | undefined\n\treadonly after: PackageState | undefined\n}\nexport interface StateDiff {\n\treadonly added: ReadonlyArray<PackageChange>\n\treadonly removed: ReadonlyArray<PackageChange>\n\treadonly updated: ReadonlyArray<PackageChange>\n}\nexport const diffState = (before: State, after: State): StateDiff => {\n\tconst changes = Array.map(\n\t\tArray.sort(\n\t\t\tArray.dedupe([...HashMap.keys(before), ...HashMap.keys(after)]),\n\t\t\tString.Order,\n\t\t),\n\t\t(name) => ({\n\t\t\tname,\n\t\t\tbefore: Option.getOrUndefined(HashMap.get(before, name)),\n\t\t\tafter: Option.getOrUndefined(HashMap.get(after, name)),\n\t\t}),\n\t)\n\treturn {\n\t\tadded: Array.filter(changes, (change) => change.before === undefined),\n\t\tremoved: Array.filter(changes, (change) => change.after === undefined),\n\t\tupdated: Array.filter(\n\t\t\tchanges,\n\t\t\t({ before, after }) =>\n\t\t\t\tbefore !== undefined &&\n\t\t\t\tafter !== undefined &&\n\t\t\t\t(before.spec !== after.spec ||\n\t\t\t\t\tbefore.version !== after.version ||\n\t\t\t\t\tbefore.path !== after.path),\n\t\t),\n\t}\n}\nexport interface InstallResult extends StateDiff {\n\treadonly agent: Agent\n\t/** The install committed; retry only snapshot deletion, not installation. */\n\treadonly snapshotCleanupFailure: Option.Option<SnapshotCleanupFailure>\n}\nexport interface PackageManager {\n\treadonly directory: string\n\treadonly agent: Agent\n\treadonly readState: Effect.Effect<State, Error>\n\t/** Present when manual recovery is required; the manager cannot be reused. */\n\treadonly recoveryRequired: Effect.Effect<Option.Option<RecoveryRequiredError>>\n\t/** Serialized per manager. Empty changes installs the current manifest, including first installs. */\n\treadonly install: (changes: Changes) => Effect.Effect<InstallResult, Error>\n}\n\n/**\n * Own one manager per project. The caller must give this manager and its child\n * processes exclusive write access to the project for each install, including\n * recovery. Do not edit project files or run another installer concurrently.\n * Calls are serialized only within this manager; no cross-process lock is taken.\n * Managed paths must be regular files or absent. make and install reject symbolic\n * links and other file types with UnsupportedFileTypeError before any write.\n *\n * Accepted file writes finish before cancellation can start rollback or release\n * the lock. File writes and the original process group participate in the transaction.\n * Scripts must not create escaped writers in independent groups or daemons.\n * Failed or interrupted installs before commit restore backed-up package files byte-for-byte\n * with recorded permissions and ownership, and remove tracked files that did not\n * exist before installation. Writes made\n * during installation are overwritten by rollback, never merged. When a lockfile\n * existed, recovery also attempts to repair node_modules. Recovery failures are\n * combined with the original cause. If process termination cannot be confirmed,\n * no further restoration or recovery runs. Any failed rollback step also requires\n * manual recovery, even if all writers stopped. Only successful installation or\n * complete rollback permits snapshot deletion and reuse. RecoveryRequiredError\n * and recoveryRequired expose the retained snapshot directory and complete cause;\n * this manager rejects\n * all later installs. Complete manual recovery before making a new manager.\n * Committed installs report snapshot deletion failures in snapshotCleanupFailure\n * rather than failing or rolling back. No crash recovery is promised.\n */\nexport const make = Effect.fnUntraced(function* (\n\toptions: Options,\n): Effect.fn.Return<\n\tPackageManager,\n\tError,\n\tFileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner\n> {\n\tconst fs = yield* FileSystem.FileSystem\n\tconst path = yield* Path.Path\n\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n\tconst directory = path.resolve(options.directory)\n\tyield* inspectManagedFiles(fs, path, directory, backupFiles)\n\tconst agent = yield* detectAgent({ ...options, directory })\n\tconst lock = yield* Semaphore.make(1)\n\tconst transaction = yield* Ref.make<ManagerState>(ManagerState.Ready())\n\tconst manifestFile = path.join(directory, \"package.json\")\n\tconst readManifest = readSource(fs, manifestFile).pipe(\n\t\tEffect.flatMap(decodeManifest),\n\t)\n\tconst installed = Schema.decodeUnknownEffect(\n\t\tSchema.fromJsonString(\n\t\t\tSchema.Struct({ version: Schema.optionalKey(Schema.String) }),\n\t\t),\n\t)\n\tconst stateOf = Effect.fnUntraced(function* (manifest: Manifest) {\n\t\tif (yield* fs.exists(path.join(directory, \".pnp.cjs\")))\n\t\t\treturn yield* PackageManagerError.make({\n\t\t\t\toperation: \"state\",\n\t\t\t\tmessage:\n\t\t\t\t\t\"Plug'n'Play is not supported; configure Yarn with nodeLinker: node-modules\",\n\t\t\t})\n\t\tconst deps = Array.reduce(\n\t\t\tfields,\n\t\t\t{} as Readonly<Record<string, string>>,\n\t\t\t(all, field) => ({ ...all, ...manifest[field] }),\n\t\t)\n\t\tconst entries = yield* Effect.forEach(\n\t\t\tRecord.toEntries(deps),\n\t\t\tEffect.fnUntraced(function* ([name, spec]) {\n\t\t\t\tconst file = path.join(directory, \"node_modules\", name, \"package.json\")\n\t\t\t\tconst source = yield* fs.readFileString(file).pipe(\n\t\t\t\t\tEffect.asSome,\n\t\t\t\t\tEffect.catchCauseIf(\n\t\t\t\t\t\t(cause) =>\n\t\t\t\t\t\t\tArray.every(\n\t\t\t\t\t\t\t\tcause.reasons,\n\t\t\t\t\t\t\t\t(reason) =>\n\t\t\t\t\t\t\t\t\tCause.isFailReason(reason) &&\n\t\t\t\t\t\t\t\t\treason.error.reason.module === \"FileSystem\" &&\n\t\t\t\t\t\t\t\t\treason.error.reason._tag === \"NotFound\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t() => Effect.succeedNone,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\tif (Option.isNone(source))\n\t\t\t\t\treturn [name, { spec, version: undefined, path: undefined }] as const\n\t\t\t\tconst pkg = yield* installed(source.value)\n\t\t\t\treturn [\n\t\t\t\t\tname,\n\t\t\t\t\t{\n\t\t\t\t\t\tspec,\n\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\tpath: yield* fs.realPath(path.dirname(file)),\n\t\t\t\t\t},\n\t\t\t\t] as const\n\t\t\t}),\n\t\t\t{ concurrency: 16 },\n\t\t)\n\t\treturn HashMap.fromIterable<string, PackageState>(entries)\n\t})\n\tconst readState = Effect.flatMap(readManifest, stateOf)\n\tconst termination: ChildProcess.KillOptions = {\n\t\tforceKillAfter: \"5 seconds\",\n\t}\n\tconst run = Effect.fnUntraced(function* (operation: \"install\" | \"recover\") {\n\t\tconst command = strategy(agent, operation)\n\t\t// Acquire and install the release handler atomically, then wait interruptibly.\n\t\treturn yield* Effect.acquireUseRelease(\n\t\t\tspawner\n\t\t\t\t.spawn(\n\t\t\t\t\tChildProcess.make(command.executable, command.args, {\n\t\t\t\t\t\tcwd: directory,\n\t\t\t\t\t\textendEnv: true,\n\t\t\t\t\t\tstdin: \"ignore\",\n\t\t\t\t\t\tstdout: \"inherit\",\n\t\t\t\t\t\tstderr: \"inherit\",\n\t\t\t\t\t\tdetached: true,\n\t\t\t\t\t\t...termination,\n\t\t\t\t\t\tenv: command.env,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.tap(() =>\n\t\t\t\t\t\tRef.set(\n\t\t\t\t\t\t\ttransaction,\n\t\t\t\t\t\t\tManagerState.Active({ writer: WriterState.Running() }),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\tEffect.fnUntraced(function* (process) {\n\t\t\t\tconst code = yield* process.exitCode.pipe(\n\t\t\t\t\tEffect.timeoutOrElse({\n\t\t\t\t\t\tduration: \"10 minutes\",\n\t\t\t\t\t\torElse: () =>\n\t\t\t\t\t\t\tPackageManagerError.make({\n\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\tmessage: `${command.executable} ${operation} timed out`,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tif (code !== 0)\n\t\t\t\t\treturn yield* PackageManagerError.make({\n\t\t\t\t\t\toperation,\n\t\t\t\t\t\texitCode: code,\n\t\t\t\t\t\tmessage: `${command.executable} ${operation} exited with code ${code}`,\n\t\t\t\t\t})\n\t\t\t}),\n\t\t\t// The command owns its group; a stopped leader may leave live descendants.\n\t\t\t// Observe kill failures here rather than relying on best-effort scope cleanup.\n\t\t\tEffect.fnUntraced(function* (process) {\n\t\t\t\tconst result = yield* terminateProcess(process, termination)\n\t\t\t\tyield* Ref.set(\n\t\t\t\t\ttransaction,\n\t\t\t\t\tManagerState.Active({\n\t\t\t\t\t\twriter:\n\t\t\t\t\t\t\tresult._tag === \"OriginalGroupStopped\"\n\t\t\t\t\t\t\t\t? WriterState.ManagedWritersIdle()\n\t\t\t\t\t\t\t\t: WriterState.Unconfirmed({\n\t\t\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\t\t\tprocessId: process.pid,\n\t\t\t\t\t\t\t\t\t\tcause: result.cause,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tif (result._tag === \"Unconfirmed\")\n\t\t\t\t\treturn yield* Effect.failCause(result.cause)\n\t\t\t}),\n\t\t)\n\t}, Effect.scoped)\n\t// AbortSignal does not join accepted OS writes. Keep the writer owned until completion.\n\tconst withFileWriter = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n\t\tEffect.acquireUseRelease(\n\t\t\tRef.set(\n\t\t\t\ttransaction,\n\t\t\t\tManagerState.Active({ writer: WriterState.FileWrite() }),\n\t\t\t),\n\t\t\t() => effect,\n\t\t\t() =>\n\t\t\t\tRef.set(\n\t\t\t\t\ttransaction,\n\t\t\t\t\tManagerState.Active({ writer: WriterState.ManagedWritersIdle() }),\n\t\t\t\t),\n\t\t).pipe(Effect.uninterruptible)\n\n\tconst install = Effect.fnUntraced(function* (changes: Changes) {\n\t\tconst state = yield* Ref.get(transaction)\n\t\tif (state._tag === \"RecoveryRequired\") return yield* state.error\n\t\tconst validated = yield* Schema.decodeEffect(Changes)(changes)\n\t\tconst inspected = yield* inspectManagedFiles(\n\t\t\tfs,\n\t\t\tpath,\n\t\t\tdirectory,\n\t\t\tbackupFiles,\n\t\t)\n\t\tconst backups = yield* Effect.forEach(\n\t\t\tinspected,\n\t\t\tEffect.fnUntraced(function* ({ name, file, metadata }) {\n\t\t\t\tconst contents = yield* Option.match(metadata, {\n\t\t\t\t\tonNone: () => Effect.succeedNone,\n\t\t\t\t\tonSome: (info) =>\n\t\t\t\t\t\tfs\n\t\t\t\t\t\t\t.readFile(file)\n\t\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\t\tEffect.map((bytes) =>\n\t\t\t\t\t\t\t\t\tOption.some<Contents>({ ...info, bytes }),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t})\n\t\t\t\treturn { name, file, contents }\n\t\t\t}),\n\t\t)\n\t\tconst original = yield* readSource(fs, manifestFile)\n\t\tconst manifest = yield* decodeManifest(original)\n\t\tconst before = yield* stateOf(manifest)\n\t\tconst text = yield* encodeManifest(\n\t\t\tapplyChanges(manifest, validated),\n\t\t\toriginal,\n\t\t)\n\n\t\tconst agentLocks = strategy(agent, \"install\").lockfiles\n\t\tconst hasLock = Array.some(\n\t\t\tbackups,\n\t\t\t({ name, contents }) =>\n\t\t\t\tArray.contains(agentLocks, name) && Option.isSome(contents),\n\t\t)\n\t\tconst completed = yield* withSnapshot(\n\t\t\tfs,\n\t\t\tRef.get(transaction).pipe(Effect.map((state) => state._tag === \"Ready\")),\n\t\t\tEffect.fnUntraced(function* (snapshotDirectory) {\n\t\t\t\tconst snapshot = yield* writeSnapshot(\n\t\t\t\t\tfs,\n\t\t\t\t\tpath,\n\t\t\t\t\tsnapshotDirectory,\n\t\t\t\t\tdirectory,\n\t\t\t\t\tagent,\n\t\t\t\t\tbackups,\n\t\t\t\t)\n\t\t\t\tconst restore = Effect.flatMap(Ref.get(transaction), (state) =>\n\t\t\t\t\tstate._tag === \"Active\" && state.writer._tag === \"ManagedWritersIdle\"\n\t\t\t\t\t\t? withFileWriter(snapshot.restore(state.writer))\n\t\t\t\t\t\t: Effect.void,\n\t\t\t\t)\n\t\t\t\treturn yield* Effect.acquireUseRelease(\n\t\t\t\t\tRef.set(\n\t\t\t\t\t\ttransaction,\n\t\t\t\t\t\tManagerState.Active({\n\t\t\t\t\t\t\twriter: WriterState.ManagedWritersIdle(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t\tEffect.fnUntraced(function* () {\n\t\t\t\t\t\tyield* withFileWriter(fs.writeFileString(manifestFile, text))\n\t\t\t\t\t\tyield* run(\"install\")\n\t\t\t\t\t\tconst after = yield* readState\n\t\t\t\t\t\treturn { agent, ...diffState(before, after) }\n\t\t\t\t\t}),\n\t\t\t\t\tEffect.fnUntraced(function* (_, exit) {\n\t\t\t\t\t\tif (Exit.isFailure(exit)) {\n\t\t\t\t\t\t\tconst state = yield* Ref.get(transaction)\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tstate._tag !== \"Active\" ||\n\t\t\t\t\t\t\t\tstate.writer._tag !== \"ManagedWritersIdle\"\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\tyield* withFileWriter(snapshot.restore(state.writer))\n\t\t\t\t\t\t\tif (hasLock)\n\t\t\t\t\t\t\t\tyield* run(\"recover\").pipe(\n\t\t\t\t\t\t\t\t\t// Even a failed recovery must restore files, once its writer has stopped.\n\t\t\t\t\t\t\t\t\tEffect.onExit(() => restore),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Idle managed writers alone do not prove that the transaction completed.\n\t\t\t\t\t\tyield* Ref.set(transaction, ManagerState.Ready())\n\t\t\t\t\t}),\n\t\t\t\t).pipe(\n\t\t\t\t\tEffect.onExit(\n\t\t\t\t\t\tEffect.fnUntraced(function* (exit) {\n\t\t\t\t\t\t\tconst state = yield* Ref.get(transaction)\n\t\t\t\t\t\t\tif (Exit.isSuccess(exit) || state._tag !== \"Active\") return\n\t\t\t\t\t\t\tconst writer = state.writer\n\t\t\t\t\t\t\tconst error = RecoveryRequiredError.make({\n\t\t\t\t\t\t\t\tdirectory,\n\t\t\t\t\t\t\t\tsnapshotDirectory,\n\t\t\t\t\t\t\t\toperation:\n\t\t\t\t\t\t\t\t\twriter._tag === \"Unconfirmed\" ? writer.operation : \"rollback\",\n\t\t\t\t\t\t\t\t...(writer._tag === \"Unconfirmed\"\n\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\tprocessId: writer.processId,\n\t\t\t\t\t\t\t\t\t\t\tterminationCause: writer.cause,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\tmessage: `Manual recovery is required. Stop all writers before restoring the snapshot at ${snapshotDirectory}`,\n\t\t\t\t\t\t\t\trecoveryCause: exit.cause,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tyield* Ref.set(\n\t\t\t\t\t\t\t\ttransaction,\n\t\t\t\t\t\t\t\tManagerState.RecoveryRequired({ error }),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn yield* error\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t}),\n\t\t)\n\t\treturn {\n\t\t\t...completed.value,\n\t\t\tsnapshotCleanupFailure: completed.snapshotCleanupFailure,\n\t\t}\n\t}, lock.withPermits(1))\n\treturn {\n\t\tdirectory,\n\t\tagent,\n\t\trecoveryRequired: Ref.get(transaction).pipe(\n\t\t\tEffect.map((state) =>\n\t\t\t\tstate._tag === \"RecoveryRequired\"\n\t\t\t\t\t? Option.some(state.error)\n\t\t\t\t\t: Option.none(),\n\t\t\t),\n\t\t),\n\t\treadState: lock.withPermits(1)(readState),\n\t\tinstall,\n\t}\n})\n"],"mappings":";;;;;;;;AAqDA,MAAa,QAAQ,OAAO,SAAS;CACpC;CACA;CACA;CACA;AACD,CAAC;AAED,IAAa,sBAAb,cAAyC,OAAO,YAG9C,CAAC,CAAC,uBAAuB;CAC1B,WAAW,OAAO,SAAS;EAAC;EAAU;EAAW;EAAW;CAAO,CAAC;CACpE,SAAS,OAAO;CAChB,UAAU,OAAO,YAAY,OAAO,GAAG;AACxC,CAAC,CAAC,CAAC,CAAC;AACJ,IAAa,wBAAb,cAA2C,OAAO,YAG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.ts"],"sourcesContent":["/** Non-interactive package installation. Provide platform services at the application boundary. */\nimport {\n\tArray,\n\tCause,\n\tData,\n\tEffect,\n\tExit,\n\tFileSystem,\n\tHashMap,\n\tMatch,\n\tOption,\n\tPath,\n\tPlatformError,\n\tRecord,\n\tRef,\n\tSchema,\n\tSemaphore,\n\tStream,\n\tString,\n} from \"effect\"\nimport { ChildProcess, ChildProcessSpawner } from \"effect/process\"\n\nimport {\n\tapplyChanges,\n\tChanges,\n\tdecodeManifest,\n\tencodeManifest,\n\tfields,\n\ttype Manifest,\n} from \"./manifest\"\nimport {\n\tPackageManagerDeclaration,\n\tPackageManagerName,\n} from \"./PackageManagerDeclaration\"\nimport { terminateProcess } from \"./process\"\nimport {\n\tinspectManagedFiles,\n\tUnsupportedFileTypeError,\n\twithSnapshot,\n\twriteSnapshot,\n\ttype Contents,\n\ttype SnapshotCleanupFailure,\n} from \"./snapshot\"\n\nexport { PackageManagerDeclaration } from \"./PackageManagerDeclaration\"\n\nexport {\n\tUnsupportedFileTypeError,\n\ttype SnapshotCleanupFailure,\n} from \"./snapshot\"\n\nexport { Changes, PackageName } from \"./manifest\"\n\nexport const Agent = Schema.Literals([\n\t\"npm\",\n\t\"pnpm\",\n\t\"yarn-classic\",\n\t\"yarn-berry\",\n])\nexport type Agent = typeof Agent.Type\nexport class PackageManagerError extends Schema.TaggedError<\n\tPackageManagerError,\n\t{ readonly brand: unique symbol }\n>()(\"PackageManagerError\", {\n\toperation: Schema.Literals([\"detect\", \"install\", \"recover\", \"state\"]),\n\tmessage: Schema.String,\n\texitCode: Schema.optionalKey(Schema.Int),\n}) {}\nexport class RecoveryRequiredError extends Schema.TaggedError<\n\tRecoveryRequiredError,\n\t{ readonly brand: unique symbol }\n>()(\"RecoveryRequiredError\", {\n\tdirectory: Schema.String,\n\tsnapshotDirectory: Schema.String,\n\toperation: Schema.Literals([\"install\", \"recover\", \"rollback\"]),\n\tprocessId: Schema.optionalKey(Schema.Int),\n\tmessage: Schema.String,\n\tterminationCause: Schema.optionalKey(\n\t\tSchema.Cause(Schema.Unknown, Schema.Unknown),\n\t),\n\trecoveryCause: Schema.Cause(Schema.Unknown, Schema.Unknown),\n}) {}\n\ntype WriterState = Data.TaggedEnum<{\n\tManagedWritersIdle: {}\n\tRunning: {}\n\tFileWrite: {}\n\tUnconfirmed: {\n\t\treadonly operation: \"install\" | \"recover\"\n\t\treadonly processId: number\n\t\treadonly cause: Cause.Cause<PlatformError.PlatformError>\n\t}\n}>\n\nconst WriterState = Data.taggedEnum<WriterState>()\n\ntype ManagerState = Data.TaggedEnum<{\n\tReady: {}\n\tActive: { readonly writer: WriterState }\n\tRecoveryRequired: { readonly error: RecoveryRequiredError }\n}>\n\nconst ManagerState = Data.taggedEnum<ManagerState>()\n\nexport type Error =\n\t| PackageManagerError\n\t| UnsupportedFileTypeError\n\t| RecoveryRequiredError\n\t| PlatformError.PlatformError\n\t| Schema.SchemaError\nexport interface Options {\n\t/** Project directory, containing package.json. Use the workspace root for workspace installs. */\n\treadonly directory: string\n\t/** Explicit selection takes precedence over detection. */\n\treadonly agent?: Agent\n\t/** Optional npm_config_user_agent supplied by the caller; used only as a fallback. */\n\treadonly userAgent?: string\n}\nconst lockfiles = [\n\t\"package-lock.json\",\n\t\"npm-shrinkwrap.json\",\n\t\"pnpm-lock.yaml\",\n\t\"yarn.lock\",\n] as const\nconst backupFiles = [\n\t\"package.json\",\n\t...lockfiles,\n\t\".npmrc\",\n\t\"pnpm-workspace.yaml\",\n\t\".yarnrc\",\n\t\".yarnrc.yml\",\n\t\".yarn/install-state.gz\",\n\t\".pnp.cjs\",\n\t\".pnp.loader.mjs\",\n]\nconst strategy = (agent: Agent, operation: \"install\" | \"recover\") => {\n\tconst recovery = operation === \"recover\"\n\treturn Match.value(agent).pipe(\n\t\tMatch.when(\"npm\", () => ({\n\t\t\texecutable: \"npm\",\n\t\t\targs: [\n\t\t\t\t\"install\",\n\t\t\t\t\"--no-audit\",\n\t\t\t\t\"--no-fund\",\n\t\t\t\t...(recovery ? [\"--prefer-offline\"] : []),\n\t\t\t],\n\t\t\tenv: { CI: \"true\" },\n\t\t\tlockfiles: [\"package-lock.json\", \"npm-shrinkwrap.json\"],\n\t\t})),\n\t\tMatch.when(\"pnpm\", () => ({\n\t\t\texecutable: \"pnpm\",\n\t\t\targs: [\n\t\t\t\t\"install\",\n\t\t\t\trecovery ? \"--frozen-lockfile\" : \"--no-frozen-lockfile\",\n\t\t\t\t\"--config.confirmModulesPurge=false\",\n\t\t\t],\n\t\t\tenv: { CI: \"true\" },\n\t\t\tlockfiles: [\"pnpm-lock.yaml\"],\n\t\t})),\n\t\tMatch.when(\"yarn-classic\", () => ({\n\t\t\texecutable: \"yarn\",\n\t\t\targs: [\n\t\t\t\t\"install\",\n\t\t\t\t\"--non-interactive\",\n\t\t\t\t...(recovery ? [\"--frozen-lockfile\", \"--prefer-offline\"] : []),\n\t\t\t],\n\t\t\tenv: { CI: \"true\" },\n\t\t\tlockfiles: [\"yarn.lock\"],\n\t\t})),\n\t\tMatch.when(\"yarn-berry\", () => ({\n\t\t\texecutable: \"yarn\",\n\t\t\targs: [\"install\", ...(recovery ? [\"--immutable\"] : [])],\n\t\t\tenv: {\n\t\t\t\tCI: \"true\",\n\t\t\t\tYARN_ENABLE_IMMUTABLE_INSTALLS: recovery ? \"true\" : \"false\",\n\t\t\t\tYARN_NODE_LINKER: \"node-modules\",\n\t\t\t},\n\t\t\tlockfiles: [\"yarn.lock\"],\n\t\t})),\n\t\tMatch.exhaustive,\n\t)\n}\n\nconst readSource = Effect.fnUntraced(function* (\n\tfs: FileSystem.FileSystem,\n\tfile: string,\n) {\n\tconst bytes = yield* fs.readFile(file)\n\treturn yield* Effect.try({\n\t\ttry: () =>\n\t\t\tnew TextDecoder(\"utf-8\", { ignoreBOM: true, fatal: true }).decode(bytes),\n\t\tcatch: (cause) =>\n\t\t\tPlatformError.badArgument({\n\t\t\t\tmodule: \"FileSystem\",\n\t\t\t\tmethod: \"readManifest\",\n\t\t\t\tdescription: \"The manifest must contain valid UTF-8\",\n\t\t\t\tcause,\n\t\t\t}),\n\t})\n})\n\nconst Executable = PackageManagerName\nconst Digits = Schema.String.check(Schema.isPattern(/^\\d+$/))\nconst decodePackageManager = Schema.decodeUnknownEffect(\n\tPackageManagerDeclaration,\n)\n/** `name/version ...`, as package managers set `npm_config_user_agent`. */\nconst decodeUserAgent = Schema.decodeUnknownOption(\n\tSchema.TemplateLiteralParser([Executable, \"/\", Digits, Schema.String]),\n)\n/**\n * The agent that runs a package manager. Yarn 1 is Classic and later versions\n * are Berry; without a version, `yarn` means the Classic global binary.\n */\nexport const agentFor = (\n\tname: typeof PackageManagerName.Type,\n\tversion?: string,\n): Agent =>\n\tname === \"yarn\"\n\t\t? version === undefined || String.split(\".\")(version)[0] === \"1\"\n\t\t\t? \"yarn-classic\"\n\t\t\t: \"yarn-berry\"\n\t\t: name\n\n/** A package manager and its version, as named by `npm_config_user_agent`. */\nexport interface UserAgent {\n\treadonly name: typeof PackageManagerName.Type\n\treadonly version: string\n}\nconst decodeUserAgentName = Schema.decodeUnknownOption(\n\tSchema.TemplateLiteralParser([\n\t\tExecutable,\n\t\t\"/\",\n\t\tSchema.String.check(Schema.isMinLength(1)),\n\t]),\n)\n/** The first `name/version` of a user agent; other package managers, such as Bun, are none. */\nexport const parseUserAgent = (userAgent: string): Option.Option<UserAgent> =>\n\tOption.map(\n\t\tdecodeUserAgentName(String.split(\" \")(userAgent)[0] ?? \"\"),\n\t\t([name, , version]) => ({ name, version }),\n\t)\n\n/** What runs a project script, such as `npm run` in `npm run dev`. */\nexport const runPrefix = (agent: Agent): string =>\n\tagent === \"npm\" ? \"npm run\" : agent === \"pnpm\" ? \"pnpm\" : \"yarn\"\n\n/** The command that installs a project's dependencies. */\nexport const installCommand = (agent: Agent): string =>\n\tagent === \"npm\" ? \"npm install\" : agent === \"pnpm\" ? \"pnpm install\" : \"yarn\"\n\n/** packageManager, then lockfile, then caller user-agent, then npm. Conflicting lockfiles fail. */\nexport const detectAgent = Effect.fnUntraced(function* (options: Options) {\n\tif (options.agent !== undefined)\n\t\treturn yield* Schema.decodeEffect(Agent)(options.agent)\n\tconst fs = yield* FileSystem.FileSystem\n\tconst path = yield* Path.Path\n\tconst manifest = yield* readSource(\n\t\tfs,\n\t\tpath.join(options.directory, \"package.json\"),\n\t).pipe(Effect.flatMap(decodeManifest))\n\tif (manifest.packageManager !== undefined) {\n\t\tconst [name, , version] = yield* decodePackageManager(\n\t\t\tmanifest.packageManager,\n\t\t).pipe(\n\t\t\t// Keep the schema issue: it names the constraint the declaration failed.\n\t\t\tEffect.mapError((error) =>\n\t\t\t\tPackageManagerError.make({\n\t\t\t\t\toperation: \"detect\",\n\t\t\t\t\tmessage: `Unsupported packageManager: ${manifest.packageManager}\\n${error.message}`,\n\t\t\t\t}),\n\t\t\t),\n\t\t)\n\t\treturn agentFor(name, `${version.major}`)\n\t}\n\tconst found = yield* Effect.filter(lockfiles, (file) =>\n\t\tfs.exists(path.join(options.directory, file)),\n\t)\n\tconst kinds = Array.dedupe(\n\t\tArray.map(found, (file) =>\n\t\t\tfile === \"pnpm-lock.yaml\"\n\t\t\t\t? \"pnpm\"\n\t\t\t\t: file === \"yarn.lock\"\n\t\t\t\t\t? \"yarn\"\n\t\t\t\t\t: \"npm\",\n\t\t),\n\t)\n\tif (kinds.length > 1)\n\t\treturn yield* PackageManagerError.make({\n\t\t\toperation: \"detect\",\n\t\t\tmessage: \"Conflicting lockfiles; select an agent explicitly\",\n\t\t})\n\tif (kinds[0] === \"yarn\") {\n\t\tconst metadata = yield* fs\n\t\t\t.stream(path.join(options.directory, \"yarn.lock\"))\n\t\t\t.pipe(\n\t\t\t\tStream.decodeText(),\n\t\t\t\tStream.mapAccum(\n\t\t\t\t\t// The initial newline models the start of the file.\n\t\t\t\t\t() => \"\\n\",\n\t\t\t\t\t(tail, chunk) => {\n\t\t\t\t\t\tconst text = tail + chunk\n\t\t\t\t\t\t// Preserve all ECMAScript line terminators, including across chunk boundaries.\n\t\t\t\t\t\t// Eleven characters retain a partial marker and its preceding character.\n\t\t\t\t\t\treturn [\n\t\t\t\t\t\t\tString.slice(-11)(text),\n\t\t\t\t\t\t\t[/[\\n\\r\\u2028\\u2029]__metadata:/.test(text)],\n\t\t\t\t\t\t]\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t\tStream.filter((found) => found),\n\t\t\t\tStream.runHead,\n\t\t\t)\n\t\treturn Option.isSome(metadata) ? \"yarn-berry\" : \"yarn-classic\"\n\t}\n\tif (kinds[0] !== undefined) return kinds[0]\n\treturn Option.match(decodeUserAgent(options.userAgent ?? \"\"), {\n\t\tonNone: () => \"npm\" as const,\n\t\tonSome: ([name, , major]) => agentFor(name, major),\n\t})\n})\n\nexport interface PackageState {\n\treadonly spec: string\n\t/** Missing optional or not-yet-installed dependencies have no version/path. */\n\treadonly version: string | undefined\n\treadonly path: string | undefined\n}\n/** Direct dependencies only, keyed by their manifest names (including aliases). */\nexport type State = HashMap.HashMap<string, PackageState>\nexport interface PackageChange {\n\treadonly name: string\n\treadonly before: PackageState | undefined\n\treadonly after: PackageState | undefined\n}\nexport interface StateDiff {\n\treadonly added: ReadonlyArray<PackageChange>\n\treadonly removed: ReadonlyArray<PackageChange>\n\treadonly updated: ReadonlyArray<PackageChange>\n}\nexport const diffState = (before: State, after: State): StateDiff => {\n\tconst changes = Array.map(\n\t\tArray.sort(\n\t\t\tArray.dedupe([...HashMap.keys(before), ...HashMap.keys(after)]),\n\t\t\tString.Order,\n\t\t),\n\t\t(name) => ({\n\t\t\tname,\n\t\t\tbefore: Option.getOrUndefined(HashMap.get(before, name)),\n\t\t\tafter: Option.getOrUndefined(HashMap.get(after, name)),\n\t\t}),\n\t)\n\treturn {\n\t\tadded: Array.filter(changes, (change) => change.before === undefined),\n\t\tremoved: Array.filter(changes, (change) => change.after === undefined),\n\t\tupdated: Array.filter(\n\t\t\tchanges,\n\t\t\t({ before, after }) =>\n\t\t\t\tbefore !== undefined &&\n\t\t\t\tafter !== undefined &&\n\t\t\t\t(before.spec !== after.spec ||\n\t\t\t\t\tbefore.version !== after.version ||\n\t\t\t\t\tbefore.path !== after.path),\n\t\t),\n\t}\n}\nexport interface InstallResult extends StateDiff {\n\treadonly agent: Agent\n\t/** The install committed; retry only snapshot deletion, not installation. */\n\treadonly snapshotCleanupFailure: Option.Option<SnapshotCleanupFailure>\n}\nexport interface PackageManager {\n\treadonly directory: string\n\treadonly agent: Agent\n\treadonly readState: Effect.Effect<State, Error>\n\t/** Present when manual recovery is required; the manager cannot be reused. */\n\treadonly recoveryRequired: Effect.Effect<Option.Option<RecoveryRequiredError>>\n\t/** Serialized per manager. Empty changes installs the current manifest, including first installs. */\n\treadonly install: (changes: Changes) => Effect.Effect<InstallResult, Error>\n}\n\n/**\n * Own one manager per project. The caller must give this manager and its child\n * processes exclusive write access to the project for each install, including\n * recovery. Do not edit project files or run another installer concurrently.\n * Calls are serialized only within this manager; no cross-process lock is taken.\n * Managed paths must be regular files or absent. make and install reject symbolic\n * links and other file types with UnsupportedFileTypeError before any write.\n *\n * Accepted file writes finish before cancellation can start rollback or release\n * the lock. File writes and the original process group participate in the transaction.\n * Scripts must not create escaped writers in independent groups or daemons.\n * Failed or interrupted installs before commit restore backed-up package files byte-for-byte\n * with recorded permissions and ownership, and remove tracked files that did not\n * exist before installation. Writes made\n * during installation are overwritten by rollback, never merged. When a lockfile\n * existed, recovery also attempts to repair node_modules. Recovery failures are\n * combined with the original cause. If process termination cannot be confirmed,\n * no further restoration or recovery runs. Any failed rollback step also requires\n * manual recovery, even if all writers stopped. Only successful installation or\n * complete rollback permits snapshot deletion and reuse. RecoveryRequiredError\n * and recoveryRequired expose the retained snapshot directory and complete cause;\n * this manager rejects\n * all later installs. Complete manual recovery before making a new manager.\n * Committed installs report snapshot deletion failures in snapshotCleanupFailure\n * rather than failing or rolling back. No crash recovery is promised.\n */\nexport const make = Effect.fnUntraced(function* (\n\toptions: Options,\n): Effect.fn.Return<\n\tPackageManager,\n\tError,\n\tFileSystem.FileSystem | Path.Path | ChildProcessSpawner.ChildProcessSpawner\n> {\n\tconst fs = yield* FileSystem.FileSystem\n\tconst path = yield* Path.Path\n\tconst spawner = yield* ChildProcessSpawner.ChildProcessSpawner\n\tconst directory = path.resolve(options.directory)\n\tyield* inspectManagedFiles(fs, path, directory, backupFiles)\n\tconst agent = yield* detectAgent({ ...options, directory })\n\tconst lock = yield* Semaphore.make(1)\n\tconst transaction = yield* Ref.make<ManagerState>(ManagerState.Ready())\n\tconst manifestFile = path.join(directory, \"package.json\")\n\tconst readManifest = readSource(fs, manifestFile).pipe(\n\t\tEffect.flatMap(decodeManifest),\n\t)\n\tconst installed = Schema.decodeUnknownEffect(\n\t\tSchema.fromJsonString(\n\t\t\tSchema.Struct({ version: Schema.optionalKey(Schema.String) }),\n\t\t),\n\t)\n\tconst stateOf = Effect.fnUntraced(function* (manifest: Manifest) {\n\t\tif (yield* fs.exists(path.join(directory, \".pnp.cjs\")))\n\t\t\treturn yield* PackageManagerError.make({\n\t\t\t\toperation: \"state\",\n\t\t\t\tmessage:\n\t\t\t\t\t\"Plug'n'Play is not supported; configure Yarn with nodeLinker: node-modules\",\n\t\t\t})\n\t\tconst deps = Array.reduce(\n\t\t\tfields,\n\t\t\t{} as Readonly<Record<string, string>>,\n\t\t\t(all, field) => ({ ...all, ...manifest[field] }),\n\t\t)\n\t\tconst entries = yield* Effect.forEach(\n\t\t\tRecord.toEntries(deps),\n\t\t\tEffect.fnUntraced(function* ([name, spec]) {\n\t\t\t\tconst file = path.join(directory, \"node_modules\", name, \"package.json\")\n\t\t\t\tconst source = yield* fs.readFileString(file).pipe(\n\t\t\t\t\tEffect.asSome,\n\t\t\t\t\tEffect.catchCauseIf(\n\t\t\t\t\t\t(cause) =>\n\t\t\t\t\t\t\tArray.every(\n\t\t\t\t\t\t\t\tcause.reasons,\n\t\t\t\t\t\t\t\t(reason) =>\n\t\t\t\t\t\t\t\t\tCause.isFailReason(reason) &&\n\t\t\t\t\t\t\t\t\treason.error.reason.module === \"FileSystem\" &&\n\t\t\t\t\t\t\t\t\treason.error.reason._tag === \"NotFound\",\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t() => Effect.succeedNone,\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t\tif (Option.isNone(source))\n\t\t\t\t\treturn [name, { spec, version: undefined, path: undefined }] as const\n\t\t\t\tconst pkg = yield* installed(source.value)\n\t\t\t\treturn [\n\t\t\t\t\tname,\n\t\t\t\t\t{\n\t\t\t\t\t\tspec,\n\t\t\t\t\t\tversion: pkg.version,\n\t\t\t\t\t\tpath: yield* fs.realPath(path.dirname(file)),\n\t\t\t\t\t},\n\t\t\t\t] as const\n\t\t\t}),\n\t\t\t{ concurrency: 16 },\n\t\t)\n\t\treturn HashMap.fromIterable<string, PackageState>(entries)\n\t})\n\tconst readState = Effect.flatMap(readManifest, stateOf)\n\tconst termination: ChildProcess.KillOptions = {\n\t\tforceKillAfter: \"5 seconds\",\n\t}\n\tconst run = Effect.fnUntraced(function* (operation: \"install\" | \"recover\") {\n\t\tconst command = strategy(agent, operation)\n\t\t// Acquire and install the release handler atomically, then wait interruptibly.\n\t\treturn yield* Effect.acquireUseRelease(\n\t\t\tspawner\n\t\t\t\t.spawn(\n\t\t\t\t\tChildProcess.make(command.executable, command.args, {\n\t\t\t\t\t\tcwd: directory,\n\t\t\t\t\t\textendEnv: true,\n\t\t\t\t\t\tstdin: \"ignore\",\n\t\t\t\t\t\tstdout: \"inherit\",\n\t\t\t\t\t\tstderr: \"inherit\",\n\t\t\t\t\t\tdetached: true,\n\t\t\t\t\t\t...termination,\n\t\t\t\t\t\tenv: command.env,\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\t.pipe(\n\t\t\t\t\tEffect.tap(() =>\n\t\t\t\t\t\tRef.set(\n\t\t\t\t\t\t\ttransaction,\n\t\t\t\t\t\t\tManagerState.Active({ writer: WriterState.Running() }),\n\t\t\t\t\t\t),\n\t\t\t\t\t),\n\t\t\t\t),\n\t\t\tEffect.fnUntraced(function* (process) {\n\t\t\t\tconst code = yield* process.exitCode.pipe(\n\t\t\t\t\tEffect.timeoutOrElse({\n\t\t\t\t\t\tduration: \"10 minutes\",\n\t\t\t\t\t\torElse: () =>\n\t\t\t\t\t\t\tPackageManagerError.make({\n\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\tmessage: `${command.executable} ${operation} timed out`,\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tif (code !== 0)\n\t\t\t\t\treturn yield* PackageManagerError.make({\n\t\t\t\t\t\toperation,\n\t\t\t\t\t\texitCode: code,\n\t\t\t\t\t\tmessage: `${command.executable} ${operation} exited with code ${code}`,\n\t\t\t\t\t})\n\t\t\t}),\n\t\t\t// The command owns its group; a stopped leader may leave live descendants.\n\t\t\t// Observe kill failures here rather than relying on best-effort scope cleanup.\n\t\t\tEffect.fnUntraced(function* (process) {\n\t\t\t\tconst result = yield* terminateProcess(process, termination)\n\t\t\t\tyield* Ref.set(\n\t\t\t\t\ttransaction,\n\t\t\t\t\tManagerState.Active({\n\t\t\t\t\t\twriter:\n\t\t\t\t\t\t\tresult._tag === \"OriginalGroupStopped\"\n\t\t\t\t\t\t\t\t? WriterState.ManagedWritersIdle()\n\t\t\t\t\t\t\t\t: WriterState.Unconfirmed({\n\t\t\t\t\t\t\t\t\t\toperation,\n\t\t\t\t\t\t\t\t\t\tprocessId: process.pid,\n\t\t\t\t\t\t\t\t\t\tcause: result.cause,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t}),\n\t\t\t\t)\n\t\t\t\tif (result._tag === \"Unconfirmed\")\n\t\t\t\t\treturn yield* Effect.failCause(result.cause)\n\t\t\t}),\n\t\t)\n\t}, Effect.scoped)\n\t// AbortSignal does not join accepted OS writes. Keep the writer owned until completion.\n\tconst withFileWriter = <A, E, R>(effect: Effect.Effect<A, E, R>) =>\n\t\tEffect.acquireUseRelease(\n\t\t\tRef.set(\n\t\t\t\ttransaction,\n\t\t\t\tManagerState.Active({ writer: WriterState.FileWrite() }),\n\t\t\t),\n\t\t\t() => effect,\n\t\t\t() =>\n\t\t\t\tRef.set(\n\t\t\t\t\ttransaction,\n\t\t\t\t\tManagerState.Active({ writer: WriterState.ManagedWritersIdle() }),\n\t\t\t\t),\n\t\t).pipe(Effect.uninterruptible)\n\n\tconst install = Effect.fnUntraced(function* (changes: Changes) {\n\t\tconst state = yield* Ref.get(transaction)\n\t\tif (state._tag === \"RecoveryRequired\") return yield* state.error\n\t\tconst validated = yield* Schema.decodeEffect(Changes)(changes)\n\t\tconst inspected = yield* inspectManagedFiles(\n\t\t\tfs,\n\t\t\tpath,\n\t\t\tdirectory,\n\t\t\tbackupFiles,\n\t\t)\n\t\tconst backups = yield* Effect.forEach(\n\t\t\tinspected,\n\t\t\tEffect.fnUntraced(function* ({ name, file, metadata }) {\n\t\t\t\tconst contents = yield* Option.match(metadata, {\n\t\t\t\t\tonNone: () => Effect.succeedNone,\n\t\t\t\t\tonSome: (info) =>\n\t\t\t\t\t\tfs\n\t\t\t\t\t\t\t.readFile(file)\n\t\t\t\t\t\t\t.pipe(\n\t\t\t\t\t\t\t\tEffect.map((bytes) =>\n\t\t\t\t\t\t\t\t\tOption.some<Contents>({ ...info, bytes }),\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t),\n\t\t\t\t})\n\t\t\t\treturn { name, file, contents }\n\t\t\t}),\n\t\t)\n\t\tconst original = yield* readSource(fs, manifestFile)\n\t\tconst manifest = yield* decodeManifest(original)\n\t\tconst before = yield* stateOf(manifest)\n\t\tconst text = yield* encodeManifest(\n\t\t\tapplyChanges(manifest, validated),\n\t\t\toriginal,\n\t\t)\n\n\t\tconst agentLocks = strategy(agent, \"install\").lockfiles\n\t\tconst hasLock = Array.some(\n\t\t\tbackups,\n\t\t\t({ name, contents }) =>\n\t\t\t\tArray.contains(agentLocks, name) && Option.isSome(contents),\n\t\t)\n\t\tconst completed = yield* withSnapshot(\n\t\t\tfs,\n\t\t\tRef.get(transaction).pipe(Effect.map((state) => state._tag === \"Ready\")),\n\t\t\tEffect.fnUntraced(function* (snapshotDirectory) {\n\t\t\t\tconst snapshot = yield* writeSnapshot(\n\t\t\t\t\tfs,\n\t\t\t\t\tpath,\n\t\t\t\t\tsnapshotDirectory,\n\t\t\t\t\tdirectory,\n\t\t\t\t\tagent,\n\t\t\t\t\tbackups,\n\t\t\t\t)\n\t\t\t\tconst restore = Effect.flatMap(Ref.get(transaction), (state) =>\n\t\t\t\t\tstate._tag === \"Active\" && state.writer._tag === \"ManagedWritersIdle\"\n\t\t\t\t\t\t? withFileWriter(snapshot.restore(state.writer))\n\t\t\t\t\t\t: Effect.void,\n\t\t\t\t)\n\t\t\t\treturn yield* Effect.acquireUseRelease(\n\t\t\t\t\tRef.set(\n\t\t\t\t\t\ttransaction,\n\t\t\t\t\t\tManagerState.Active({\n\t\t\t\t\t\t\twriter: WriterState.ManagedWritersIdle(),\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t\tEffect.fnUntraced(function* () {\n\t\t\t\t\t\tyield* withFileWriter(fs.writeFileString(manifestFile, text))\n\t\t\t\t\t\tyield* run(\"install\")\n\t\t\t\t\t\tconst after = yield* readState\n\t\t\t\t\t\treturn { agent, ...diffState(before, after) }\n\t\t\t\t\t}),\n\t\t\t\t\tEffect.fnUntraced(function* (_, exit) {\n\t\t\t\t\t\tif (Exit.isFailure(exit)) {\n\t\t\t\t\t\t\tconst state = yield* Ref.get(transaction)\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tstate._tag !== \"Active\" ||\n\t\t\t\t\t\t\t\tstate.writer._tag !== \"ManagedWritersIdle\"\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\treturn\n\t\t\t\t\t\t\tyield* withFileWriter(snapshot.restore(state.writer))\n\t\t\t\t\t\t\tif (hasLock)\n\t\t\t\t\t\t\t\tyield* run(\"recover\").pipe(\n\t\t\t\t\t\t\t\t\t// Even a failed recovery must restore files, once its writer has stopped.\n\t\t\t\t\t\t\t\t\tEffect.onExit(() => restore),\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Idle managed writers alone do not prove that the transaction completed.\n\t\t\t\t\t\tyield* Ref.set(transaction, ManagerState.Ready())\n\t\t\t\t\t}),\n\t\t\t\t).pipe(\n\t\t\t\t\tEffect.onExit(\n\t\t\t\t\t\tEffect.fnUntraced(function* (exit) {\n\t\t\t\t\t\t\tconst state = yield* Ref.get(transaction)\n\t\t\t\t\t\t\tif (Exit.isSuccess(exit) || state._tag !== \"Active\") return\n\t\t\t\t\t\t\tconst writer = state.writer\n\t\t\t\t\t\t\tconst error = RecoveryRequiredError.make({\n\t\t\t\t\t\t\t\tdirectory,\n\t\t\t\t\t\t\t\tsnapshotDirectory,\n\t\t\t\t\t\t\t\toperation:\n\t\t\t\t\t\t\t\t\twriter._tag === \"Unconfirmed\" ? writer.operation : \"rollback\",\n\t\t\t\t\t\t\t\t...(writer._tag === \"Unconfirmed\"\n\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\tprocessId: writer.processId,\n\t\t\t\t\t\t\t\t\t\t\tterminationCause: writer.cause,\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\tmessage: `Manual recovery is required. Stop all writers before restoring the snapshot at ${snapshotDirectory}`,\n\t\t\t\t\t\t\t\trecoveryCause: exit.cause,\n\t\t\t\t\t\t\t})\n\t\t\t\t\t\t\tyield* Ref.set(\n\t\t\t\t\t\t\t\ttransaction,\n\t\t\t\t\t\t\t\tManagerState.RecoveryRequired({ error }),\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\treturn yield* error\n\t\t\t\t\t\t}),\n\t\t\t\t\t),\n\t\t\t\t)\n\t\t\t}),\n\t\t)\n\t\treturn {\n\t\t\t...completed.value,\n\t\t\tsnapshotCleanupFailure: completed.snapshotCleanupFailure,\n\t\t}\n\t}, lock.withPermits(1))\n\treturn {\n\t\tdirectory,\n\t\tagent,\n\t\trecoveryRequired: Ref.get(transaction).pipe(\n\t\t\tEffect.map((state) =>\n\t\t\t\tstate._tag === \"RecoveryRequired\"\n\t\t\t\t\t? Option.some(state.error)\n\t\t\t\t\t: Option.none(),\n\t\t\t),\n\t\t),\n\t\treadState: lock.withPermits(1)(readState),\n\t\tinstall,\n\t}\n})\n"],"mappings":";;;;;;;;AAqDA,MAAa,QAAQ,OAAO,SAAS;CACpC;CACA;CACA;CACA;AACD,CAAC;AAED,IAAa,sBAAb,cAAyC,OAAO,YAG9C,CAAC,CAAC,uBAAuB;CAC1B,WAAW,OAAO,SAAS;EAAC;EAAU;EAAW;EAAW;CAAO,CAAC;CACpE,SAAS,OAAO;CAChB,UAAU,OAAO,YAAY,OAAO,GAAG;AACxC,CAAC,CAAC,CAAC,CAAC;AACJ,IAAa,wBAAb,cAA2C,OAAO,YAGhD,CAAC,CAAC,yBAAyB;CAC5B,WAAW,OAAO;CAClB,mBAAmB,OAAO;CAC1B,WAAW,OAAO,SAAS;EAAC;EAAW;EAAW;CAAU,CAAC;CAC7D,WAAW,OAAO,YAAY,OAAO,GAAG;CACxC,SAAS,OAAO;CAChB,kBAAkB,OAAO,YACxB,OAAO,MAAM,OAAO,SAAS,OAAO,OAAO,CAC5C;CACA,eAAe,OAAO,MAAM,OAAO,SAAS,OAAO,OAAO;AAC3D,CAAC,CAAC,CAAC,CAAC;AAaJ,MAAM,cAAc,KAAK,WAAwB;AAQjD,MAAM,eAAe,KAAK,WAAyB;AAgBnD,MAAM,YAAY;CACjB;CACA;CACA;CACA;AACD;AACA,MAAM,cAAc;CACnB;CACA,GAAG;CACH;CACA;CACA;CACA;CACA;CACA;CACA;AACD;AACA,MAAM,YAAY,OAAc,cAAqC;CACpE,MAAM,WAAW,cAAc;CAC/B,OAAO,MAAM,MAAM,KAAK,CAAC,CAAC,KACzB,MAAM,K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,OAAO,SAAS,sBAEtB;KACD,OAAO,eAAe,SAAS,QAAQ,MAAM,MAAM,CAAC;KACpD,IAAI,SACH,OAAO,IAAI,SAAS,CAAC,CAAC,KAErB,OAAO,aAAa,OAAO,CAC5B;IACF;IAEA,OAAO,IAAI,IAAI,aAAa,aAAa,MAAM,CAAC;GACjD,CAAC,CACF,CAAC,CAAC,KACD,OAAO,OACN,OAAO,WAAW,WAAW,MAAM;IAClC,MAAM,QAAQ,OAAO,IAAI,IAAI,WAAW;IACxC,IAAI,KAAK,UAAU,IAAI,KAAK,MAAM,SAAS,UAAU;IACrD,MAAM,SAAS,MAAM;IACrB,MAAM,QAAQ,sBAAsB,KAAK;KACxC;KACA;KACA,WACC,OAAO,SAAS,gBAAgB,OAAO,YAAY;KACpD,GAAI,OAAO,SAAS,gBACjB;MACA,WAAW,OAAO;MAClB,kBAAkB,OAAO;KAC1B,IACC,CAAC;KACJ,SAAS,kFAAkF;KAC3F,eAAe,KAAK;IACrB,CAAC;IACD,OAAO,IAAI,IACV,aACA,aAAa,iBAAiB,EAAE,MAAM,CAAC,CACxC;IACA,OAAO,OAAO;GACf,CAAC,CACF,CACD;EACD,CAAC,CACF;EACA,OAAO;GACN,GAAG,UAAU;GACb,wBAAwB,UAAU;EACnC;CACD,GAAG,KAAK,YAAY,CAAC,CAAC;CACtB,OAAO;EACN;EACA;EACA,kBAAkB,IAAI,IAAI,WAAW,CAAC,CAAC,KACtC,OAAO,KAAK,UACX,MAAM,SAAS,qBACZ,OAAO,KAAK,MAAM,KAAK,IACvB,OAAO,KAAK,CAChB,CACD;EACA,WAAW,KAAK,YAAY,CAAC,CAAC,CAAC,SAAS;EACxC;CACD;AACD,CAAC"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -208,8 +208,46 @@ const decodePackageManager = Schema.decodeUnknownEffect(
|
|
|
208
208
|
const decodeUserAgent = Schema.decodeUnknownOption(
|
|
209
209
|
Schema.TemplateLiteralParser([Executable, "/", Digits, Schema.String]),
|
|
210
210
|
)
|
|
211
|
-
|
|
212
|
-
|
|
211
|
+
/**
|
|
212
|
+
* The agent that runs a package manager. Yarn 1 is Classic and later versions
|
|
213
|
+
* are Berry; without a version, `yarn` means the Classic global binary.
|
|
214
|
+
*/
|
|
215
|
+
export const agentFor = (
|
|
216
|
+
name: typeof PackageManagerName.Type,
|
|
217
|
+
version?: string,
|
|
218
|
+
): Agent =>
|
|
219
|
+
name === "yarn"
|
|
220
|
+
? version === undefined || String.split(".")(version)[0] === "1"
|
|
221
|
+
? "yarn-classic"
|
|
222
|
+
: "yarn-berry"
|
|
223
|
+
: name
|
|
224
|
+
|
|
225
|
+
/** A package manager and its version, as named by `npm_config_user_agent`. */
|
|
226
|
+
export interface UserAgent {
|
|
227
|
+
readonly name: typeof PackageManagerName.Type
|
|
228
|
+
readonly version: string
|
|
229
|
+
}
|
|
230
|
+
const decodeUserAgentName = Schema.decodeUnknownOption(
|
|
231
|
+
Schema.TemplateLiteralParser([
|
|
232
|
+
Executable,
|
|
233
|
+
"/",
|
|
234
|
+
Schema.String.check(Schema.isMinLength(1)),
|
|
235
|
+
]),
|
|
236
|
+
)
|
|
237
|
+
/** The first `name/version` of a user agent; other package managers, such as Bun, are none. */
|
|
238
|
+
export const parseUserAgent = (userAgent: string): Option.Option<UserAgent> =>
|
|
239
|
+
Option.map(
|
|
240
|
+
decodeUserAgentName(String.split(" ")(userAgent)[0] ?? ""),
|
|
241
|
+
([name, , version]) => ({ name, version }),
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
/** What runs a project script, such as `npm run` in `npm run dev`. */
|
|
245
|
+
export const runPrefix = (agent: Agent): string =>
|
|
246
|
+
agent === "npm" ? "npm run" : agent === "pnpm" ? "pnpm" : "yarn"
|
|
247
|
+
|
|
248
|
+
/** The command that installs a project's dependencies. */
|
|
249
|
+
export const installCommand = (agent: Agent): string =>
|
|
250
|
+
agent === "npm" ? "npm install" : agent === "pnpm" ? "pnpm install" : "yarn"
|
|
213
251
|
|
|
214
252
|
/** packageManager, then lockfile, then caller user-agent, then npm. Conflicting lockfiles fail. */
|
|
215
253
|
export const detectAgent = Effect.fnUntraced(function* (options: Options) {
|
|
@@ -233,7 +271,7 @@ export const detectAgent = Effect.fnUntraced(function* (options: Options) {
|
|
|
233
271
|
}),
|
|
234
272
|
),
|
|
235
273
|
)
|
|
236
|
-
return
|
|
274
|
+
return agentFor(name, `${version.major}`)
|
|
237
275
|
}
|
|
238
276
|
const found = yield* Effect.filter(lockfiles, (file) =>
|
|
239
277
|
fs.exists(path.join(options.directory, file)),
|
|
@@ -278,7 +316,7 @@ export const detectAgent = Effect.fnUntraced(function* (options: Options) {
|
|
|
278
316
|
if (kinds[0] !== undefined) return kinds[0]
|
|
279
317
|
return Option.match(decodeUserAgent(options.userAgent ?? ""), {
|
|
280
318
|
onNone: () => "npm" as const,
|
|
281
|
-
onSome: ([name, , major]) =>
|
|
319
|
+
onSome: ([name, , major]) => agentFor(name, major),
|
|
282
320
|
})
|
|
283
321
|
})
|
|
284
322
|
|