@poe-platform/safe-js 0.1.730 → 0.1.731
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 +5 -5
- package/dist/safe-js/chunks/{chunk-SJZWSPWD.js → chunk-2GVBG23M.js} +1 -1
- package/dist/safe-js/chunks/{chunk-SJZWSPWD.js.map → chunk-2GVBG23M.js.map} +1 -1
- package/dist/safe-js/chunks/{chunk-VIMROAQA.js → chunk-E4XLBT7R.js} +2 -2
- package/dist/safe-js/chunks/chunk-F6CV74HU.js +114 -0
- package/dist/safe-js/chunks/chunk-F6CV74HU.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-OZLTLIHX.js → chunk-G6WTEIJJ.js} +2 -2
- package/dist/safe-js/chunks/{chunk-XX57YCGZ.js → chunk-GNEORAQI.js} +55 -50
- package/dist/safe-js/chunks/chunk-GNEORAQI.js.map +7 -0
- package/dist/safe-js/chunks/chunk-GVKXZW53.js +76 -0
- package/dist/safe-js/chunks/chunk-GVKXZW53.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-3LSNBW5N.js → chunk-IRDQDZ5R.js} +4 -4
- package/dist/safe-js/chunks/{chunk-MRULOD5J.js → chunk-K4T4EBED.js} +59 -38
- package/dist/safe-js/chunks/chunk-K4T4EBED.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-MFCEBCGV.js → chunk-KETIFEA7.js} +17 -8
- package/dist/safe-js/chunks/chunk-KETIFEA7.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-S5YDMMM3.js → chunk-MDIWQFYU.js} +95 -169
- package/dist/safe-js/chunks/{chunk-S5YDMMM3.js.map → chunk-MDIWQFYU.js.map} +4 -4
- package/dist/safe-js/chunks/{chunk-MW2QLYVN.js → chunk-MGHE7ZFI.js} +74 -63
- package/dist/safe-js/chunks/chunk-MGHE7ZFI.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-EN724VH3.js → chunk-O4IDRXW7.js} +4 -4
- package/dist/safe-js/chunks/{chunk-EA7AHM2X.js → chunk-PSVV3IG2.js} +3 -3
- package/dist/safe-js/chunks/{chunk-Y5EZYHU6.js → chunk-QKO4FATZ.js} +33 -5
- package/dist/safe-js/chunks/chunk-QKO4FATZ.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-EG3QWREA.js → chunk-RULU2F5J.js} +2 -2
- package/dist/safe-js/chunks/chunk-UQPYTZOZ.js +72 -0
- package/dist/safe-js/chunks/chunk-UQPYTZOZ.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-LRSWTDIV.js → chunk-W4SWUHCQ.js} +58 -23
- package/dist/safe-js/chunks/chunk-W4SWUHCQ.js.map +7 -0
- package/dist/safe-js/chunks/{chunk-W3IY6FKO.js → chunk-WS2FJBH6.js} +2 -2
- package/dist/safe-js/chunks/{chunk-MVLDRXWS.js → chunk-X3CKAZQ4.js} +3 -3
- package/dist/safe-js/chunks/chunk-YUQFFRUF.js +26 -0
- package/dist/safe-js/chunks/chunk-YUQFFRUF.js.map +7 -0
- package/dist/safe-js/chunks/{cli-runtime-WSVW5DNT.js → cli-runtime-NUEFUM64.js} +51 -30
- package/dist/safe-js/chunks/cli-runtime-NUEFUM64.js.map +7 -0
- package/dist/safe-js/chunks/{dump-UNYK24YS.js → dump-RGRC3CG3.js} +5 -4
- package/dist/safe-js/chunks/harness-UMOMFXDT.js +11 -0
- package/dist/safe-js/chunks/mcp-S672263Q.js +12 -0
- package/dist/safe-js/chunks/migration-file-KRXQYI3Q.js +15 -0
- package/dist/safe-js/chunks/restore-GEO7VN2R.js +14 -0
- package/dist/safe-js/chunks/run-ZSFX66RN.js +20 -0
- package/dist/safe-js/chunks/runtime-modules-A3U2DKFL.js +11 -0
- package/dist/safe-js/chunks/source-files-L3SGK63Z.js +10 -0
- package/dist/safe-js/cli-runtime.d.ts +2 -0
- package/dist/safe-js/cli.js +4 -4
- package/dist/safe-js/core.d.ts +1 -0
- package/dist/safe-js/core.js +15 -8
- package/dist/safe-js/error/shape.js +170 -0
- package/dist/safe-js/index.js +42 -33
- package/dist/safe-js/index.js.map +2 -2
- package/dist/safe-js/interp/budget.js +600 -0
- package/dist/safe-js/interp/internal-symbols.js +1 -0
- package/dist/safe-js/interp/promise-replay.d.ts +1 -1
- package/dist/safe-js/interp/template-cache.js +7 -0
- package/dist/safe-js/migration-file.d.ts +2 -0
- package/dist/safe-js/modules/fs-config.d.ts +3 -1
- package/dist/safe-js/modules/fs.d.ts +8 -4
- package/dist/safe-js/modules/fs.js +16 -0
- package/dist/safe-js/modules/source-files.d.ts +3 -2
- package/dist/safe-js/platform/context.js +58 -0
- package/dist/safe-js/platform/node.js +64 -0
- package/dist/safe-js/platform/types.js +63 -0
- package/dist/safe-js/platform/workerd.js +39 -0
- package/dist/safe-js/runner/run-harness.d.ts +2 -0
- package/dist/safe-js/snapshot/backend.d.ts +2 -0
- package/package.json +9 -2
- package/dist/safe-js/chunks/chunk-FCCA27RC.js +0 -69
- package/dist/safe-js/chunks/chunk-FCCA27RC.js.map +0 -7
- package/dist/safe-js/chunks/chunk-LRSWTDIV.js.map +0 -7
- package/dist/safe-js/chunks/chunk-MFCEBCGV.js.map +0 -7
- package/dist/safe-js/chunks/chunk-MRULOD5J.js.map +0 -7
- package/dist/safe-js/chunks/chunk-MW2QLYVN.js.map +0 -7
- package/dist/safe-js/chunks/chunk-XX57YCGZ.js.map +0 -7
- package/dist/safe-js/chunks/chunk-Y5EZYHU6.js.map +0 -7
- package/dist/safe-js/chunks/cli-runtime-WSVW5DNT.js.map +0 -7
- package/dist/safe-js/chunks/fs-AOV77RQC.js +0 -13
- package/dist/safe-js/chunks/harness-ZIEO7NAV.js +0 -10
- package/dist/safe-js/chunks/mcp-E2AJXEQM.js +0 -11
- package/dist/safe-js/chunks/migration-file-3SWGNDS2.js +0 -12
- package/dist/safe-js/chunks/restore-FCTWPLU3.js +0 -13
- package/dist/safe-js/chunks/run-ESJHEXCE.js +0 -17
- package/dist/safe-js/chunks/runtime-modules-7V6BWCRK.js +0 -10
- package/dist/safe-js/chunks/source-files-73OHLNGH.js +0 -8
- /package/dist/safe-js/chunks/{chunk-VIMROAQA.js.map → chunk-E4XLBT7R.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-OZLTLIHX.js.map → chunk-G6WTEIJJ.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-3LSNBW5N.js.map → chunk-IRDQDZ5R.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-EN724VH3.js.map → chunk-O4IDRXW7.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-EA7AHM2X.js.map → chunk-PSVV3IG2.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-EG3QWREA.js.map → chunk-RULU2F5J.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-W3IY6FKO.js.map → chunk-WS2FJBH6.js.map} +0 -0
- /package/dist/safe-js/chunks/{chunk-MVLDRXWS.js.map → chunk-X3CKAZQ4.js.map} +0 -0
- /package/dist/safe-js/chunks/{dump-UNYK24YS.js.map → dump-RGRC3CG3.js.map} +0 -0
- /package/dist/safe-js/chunks/{fs-AOV77RQC.js.map → harness-UMOMFXDT.js.map} +0 -0
- /package/dist/safe-js/chunks/{harness-ZIEO7NAV.js.map → mcp-S672263Q.js.map} +0 -0
- /package/dist/safe-js/chunks/{mcp-E2AJXEQM.js.map → migration-file-KRXQYI3Q.js.map} +0 -0
- /package/dist/safe-js/chunks/{migration-file-3SWGNDS2.js.map → restore-GEO7VN2R.js.map} +0 -0
- /package/dist/safe-js/chunks/{restore-FCTWPLU3.js.map → run-ZSFX66RN.js.map} +0 -0
- /package/dist/safe-js/chunks/{run-ESJHEXCE.js.map → runtime-modules-A3U2DKFL.js.map} +0 -0
- /package/dist/safe-js/chunks/{runtime-modules-7V6BWCRK.js.map → source-files-L3SGK63Z.js.map} +0 -0
- /package/dist/safe-js/{chunks/source-files-73OHLNGH.js.map → modules/fs.js.map} +0 -0
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
numericTypedArrayConstructors,
|
|
9
9
|
parseModule,
|
|
10
10
|
tokenize
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-QKO4FATZ.js";
|
|
12
12
|
|
|
13
13
|
// packages/safe-js/src/lint/rules/AS001.ts
|
|
14
14
|
function AS001(source, options = {}) {
|
|
@@ -11177,4 +11177,4 @@ function hasOnlyRegexLiteralDiagnostics(diagnostics) {
|
|
|
11177
11177
|
export {
|
|
11178
11178
|
lint
|
|
11179
11179
|
};
|
|
11180
|
-
//# sourceMappingURL=chunk-
|
|
11180
|
+
//# sourceMappingURL=chunk-RULU2F5J.js.map
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// packages/safe-js/src/platform/node.ts
|
|
2
|
+
import * as nodeUtil from "node:util";
|
|
3
|
+
import * as nativeFsPromises from "node:fs/promises";
|
|
4
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
5
|
+
import { MessageChannel, MessagePort, receiveMessageOnPort } from "node:worker_threads";
|
|
6
|
+
import { setImmediate } from "node:timers/promises";
|
|
7
|
+
import { inspect } from "node:util";
|
|
8
|
+
import { formatWithOptions } from "node:util";
|
|
9
|
+
import { constants } from "node:fs";
|
|
10
|
+
var nativeClone = structuredClone;
|
|
11
|
+
var sharedByteLength = Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get;
|
|
12
|
+
var postMessage = MessagePort.prototype.postMessage;
|
|
13
|
+
var closePort = MessagePort.prototype.close;
|
|
14
|
+
var probe = new SharedArrayBuffer(1);
|
|
15
|
+
var nativeSharesStorage = false;
|
|
16
|
+
try {
|
|
17
|
+
const copy = nativeClone(probe);
|
|
18
|
+
Reflect.apply(sharedByteLength, copy, []);
|
|
19
|
+
new Uint8Array(copy)[0] = 1;
|
|
20
|
+
nativeSharesStorage = copy !== probe && new Uint8Array(probe)[0] === 1;
|
|
21
|
+
} catch {
|
|
22
|
+
}
|
|
23
|
+
var cloneSharedBufferWrapper = nativeSharesStorage ? nativeClone : (value) => {
|
|
24
|
+
Reflect.apply(sharedByteLength, value, []);
|
|
25
|
+
const { port1, port2 } = new MessageChannel();
|
|
26
|
+
try {
|
|
27
|
+
Reflect.apply(postMessage, port1, [value]);
|
|
28
|
+
const copy = receiveMessageOnPort(port2)?.message;
|
|
29
|
+
Reflect.apply(sharedByteLength, copy, []);
|
|
30
|
+
if (copy === value) throw new TypeError("Shared storage requires a distinct wrapper.");
|
|
31
|
+
return copy;
|
|
32
|
+
} finally {
|
|
33
|
+
Reflect.apply(closePort, port1, []);
|
|
34
|
+
Reflect.apply(closePort, port2, []);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
function createHostCallbackContext() {
|
|
38
|
+
return new AsyncLocalStorage();
|
|
39
|
+
}
|
|
40
|
+
var accessDeniedSystemError = readSystemError("EACCES");
|
|
41
|
+
function readSystemError(code) {
|
|
42
|
+
const fallback = /* @__PURE__ */ new Map([
|
|
43
|
+
[process.platform === "win32" ? -4092 : -13, ["EACCES", "permission denied"]]
|
|
44
|
+
]);
|
|
45
|
+
const systemErrors = nodeUtil.getSystemErrorMap?.() ?? fallback;
|
|
46
|
+
for (const [errno, [name, message]] of systemErrors) {
|
|
47
|
+
if (name === code) {
|
|
48
|
+
return [errno, message];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
throw new Error(`node does not define the ${code} system error.`);
|
|
52
|
+
}
|
|
53
|
+
var types2 = nodeUtil.types;
|
|
54
|
+
var hostFs = nativeFsPromises;
|
|
55
|
+
var hostCwd = process.cwd.bind(process);
|
|
56
|
+
var hostPlatform = process.platform;
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
AsyncLocalStorage,
|
|
60
|
+
cloneSharedBufferWrapper,
|
|
61
|
+
createHostCallbackContext,
|
|
62
|
+
accessDeniedSystemError,
|
|
63
|
+
types2 as types,
|
|
64
|
+
hostFs,
|
|
65
|
+
hostCwd,
|
|
66
|
+
hostPlatform,
|
|
67
|
+
setImmediate,
|
|
68
|
+
inspect,
|
|
69
|
+
formatWithOptions,
|
|
70
|
+
constants
|
|
71
|
+
};
|
|
72
|
+
//# sourceMappingURL=chunk-UQPYTZOZ.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/platform/node.ts"],
|
|
4
|
+
"sourcesContent": ["import * as nodeUtil from \"node:util\";\nimport * as nativeFsPromises from \"node:fs/promises\";\nimport { AsyncLocalStorage } from \"node:async_hooks\";\nimport { MessageChannel, MessagePort, receiveMessageOnPort } from \"node:worker_threads\";\nimport type { HostCallbackContext } from \"../interp/host-callback-context.js\";\n\nconst nativeClone = structuredClone;\nconst sharedByteLength = Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, \"byteLength\")!.get!;\nconst postMessage = MessagePort.prototype.postMessage;\nconst closePort = MessagePort.prototype.close;\n\n// Probe private storage once: a broken native clone must never copy a guest's\n// potentially large allocation before selecting the shared-wrapper fallback.\nconst probe = new SharedArrayBuffer(1);\nlet nativeSharesStorage = false;\ntry {\n const copy = nativeClone(probe);\n Reflect.apply(sharedByteLength, copy, []);\n new Uint8Array(copy)[0] = 1;\n nativeSharesStorage = copy !== probe && new Uint8Array(probe)[0] === 1;\n} catch {\n // Some supported hosts do not implement shared-buffer structured cloning.\n}\n\nexport const cloneSharedBufferWrapper: (value: SharedArrayBuffer) => SharedArrayBuffer = nativeSharesStorage\n ? nativeClone\n : (value) => {\n Reflect.apply(sharedByteLength, value, []);\n const { port1, port2 } = new MessageChannel();\n try {\n Reflect.apply(postMessage, port1, [value]);\n const copy: unknown = receiveMessageOnPort(port2)?.message;\n Reflect.apply(sharedByteLength, copy, []);\n if (copy === value) throw new TypeError(\"Shared storage requires a distinct wrapper.\");\n return copy as SharedArrayBuffer;\n } finally {\n Reflect.apply(closePort, port1, []);\n Reflect.apply(closePort, port2, []);\n }\n };\n\nexport function createHostCallbackContext(): HostCallbackContext {\n return new AsyncLocalStorage<boolean>();\n}\n\nexport const accessDeniedSystemError: readonly [number, string] = readSystemError(\"EACCES\");\n\nfunction readSystemError(code: string): [number, string] {\n const fallback = new Map<number, [string, string]>([\n [process.platform === \"win32\" ? -4092 : -13, [\"EACCES\", \"permission denied\"]]\n ]);\n const systemErrors = nodeUtil.getSystemErrorMap?.() ?? fallback;\n for (const [errno, [name, message]] of systemErrors) {\n if (name === code) {\n return [errno, message];\n }\n }\n\n throw new Error(`node does not define the ${code} system error.`);\n}\n\nexport { AsyncLocalStorage };\nexport const types = nodeUtil.types;\nexport { setImmediate as yieldToHost } from \"node:timers/promises\";\nexport { inspect } from \"node:util\";\nexport { formatWithOptions } from \"node:util\";\nexport { constants as fsConstants } from \"node:fs\";\nexport const hostFs = nativeFsPromises;\nexport const hostCwd = process.cwd.bind(process);\nexport const hostPlatform = process.platform;\n"],
|
|
5
|
+
"mappings": ";AAAA,YAAY,cAAc;AAC1B,YAAY,sBAAsB;AAClC,SAAS,yBAAyB;AAClC,SAAS,gBAAgB,aAAa,4BAA4B;AA4DlE,SAAyB,oBAAmB;AAC5C,SAAS,eAAe;AACxB,SAAS,yBAAyB;AAClC,SAAsB,iBAAmB;AA5DzC,IAAM,cAAc;AACpB,IAAM,mBAAmB,OAAO,yBAAyB,kBAAkB,WAAW,YAAY,EAAG;AACrG,IAAM,cAAc,YAAY,UAAU;AAC1C,IAAM,YAAY,YAAY,UAAU;AAIxC,IAAM,QAAQ,IAAI,kBAAkB,CAAC;AACrC,IAAI,sBAAsB;AAC1B,IAAI;AACF,QAAM,OAAO,YAAY,KAAK;AAC9B,UAAQ,MAAM,kBAAkB,MAAM,CAAC,CAAC;AACxC,MAAI,WAAW,IAAI,EAAE,CAAC,IAAI;AAC1B,wBAAsB,SAAS,SAAS,IAAI,WAAW,KAAK,EAAE,CAAC,MAAM;AACvE,QAAQ;AAER;AAEO,IAAM,2BAA4E,sBACrF,cACA,CAAC,UAAU;AACX,UAAQ,MAAM,kBAAkB,OAAO,CAAC,CAAC;A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|
validateMigrationJournal,
|
|
7
10
|
validateMigrationReconciliation,
|
|
8
11
|
validateMigrationSemantics,
|
|
9
12
|
validateSnapshotMigration
|
|
10
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-PSVV3IG2.js";
|
|
11
14
|
import {
|
|
12
15
|
DUMP_FORMAT_VERSION,
|
|
13
16
|
EXECUTION_SEMANTICS,
|
|
@@ -17,15 +20,20 @@ import {
|
|
|
17
20
|
serializeSafeJSSnapshot,
|
|
18
21
|
validateDumpEnvelope,
|
|
19
22
|
validateSnapshotData
|
|
20
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-MDIWQFYU.js";
|
|
21
24
|
import {
|
|
22
25
|
parseModule
|
|
23
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-QKO4FATZ.js";
|
|
27
|
+
import {
|
|
28
|
+
paths_default
|
|
29
|
+
} from "./chunk-YUQFFRUF.js";
|
|
30
|
+
import {
|
|
31
|
+
hostCwd,
|
|
32
|
+
hostFs
|
|
33
|
+
} from "./chunk-UQPYTZOZ.js";
|
|
24
34
|
|
|
25
35
|
// packages/safe-js/src/migration-file.ts
|
|
26
|
-
import {
|
|
27
|
-
import { link, open, readFile, unlink } from "node:fs/promises";
|
|
28
|
-
import path from "node:path";
|
|
36
|
+
import { createFsBridge } from "@poe-platform/safe-fs/core";
|
|
29
37
|
|
|
30
38
|
// packages/safe-js/src/migrate.ts
|
|
31
39
|
import { sha256 } from "@noble/hashes/sha2.js";
|
|
@@ -104,11 +112,14 @@ function canonicalData(value) {
|
|
|
104
112
|
|
|
105
113
|
// packages/safe-js/src/migration-file.ts
|
|
106
114
|
async function migrateSnapshotFile(options) {
|
|
107
|
-
const
|
|
115
|
+
const adapter = options.adapter;
|
|
116
|
+
const io = adapter ? createFsBridge(adapter, { codec: fsCodec }) : hostFs;
|
|
117
|
+
const readFile = io.readFile.bind(io);
|
|
118
|
+
const cwd = options.cwd ?? hostCwd();
|
|
108
119
|
const resolvePath = (value, label) => {
|
|
109
120
|
if (typeof value !== "string" || value.trim().length === 0)
|
|
110
121
|
throw new TypeError(`Migration requires ${label}.`);
|
|
111
|
-
return
|
|
122
|
+
return paths_default.resolve(cwd, value);
|
|
112
123
|
};
|
|
113
124
|
const snapshotPath = resolvePath(options.snapshotPath, "a snapshot path");
|
|
114
125
|
const sourcePath = resolvePath(options.sourcePath, "--from <original.ajs>");
|
|
@@ -120,7 +131,7 @@ async function migrateSnapshotFile(options) {
|
|
|
120
131
|
const targetSourcePath = options.inspect ? void 0 : resolvePath(options.targetSourcePath, "--to <continuation.ajs>");
|
|
121
132
|
const planPath = options.inspect ? void 0 : resolvePath(options.planPath, "--plan <migration.json>");
|
|
122
133
|
for (const filepath of [sourcePath, targetSourcePath]) {
|
|
123
|
-
if (filepath !== void 0 && ![".ajs", ".safejs"].includes(
|
|
134
|
+
if (filepath !== void 0 && ![".ajs", ".safejs"].includes(paths_default.extname(filepath)))
|
|
124
135
|
throw new TypeError(
|
|
125
136
|
"Migration source paths must name executable .ajs or .safejs files, not harness Markdown."
|
|
126
137
|
);
|
|
@@ -141,22 +152,43 @@ async function migrateSnapshotFile(options) {
|
|
|
141
152
|
});
|
|
142
153
|
const contents = serializeSafeJSSnapshot(migrated);
|
|
143
154
|
if (!options.dryRun) {
|
|
144
|
-
const temporaryPath =
|
|
145
|
-
|
|
146
|
-
`.safejs-migration-${randomUUID()}.tmp`
|
|
155
|
+
const temporaryPath = paths_default.join(
|
|
156
|
+
paths_default.dirname(outputPath),
|
|
157
|
+
`.safejs-migration-${globalThis.crypto.randomUUID()}.tmp`
|
|
147
158
|
);
|
|
148
159
|
let created = false;
|
|
149
160
|
try {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
await
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
161
|
+
if (adapter) {
|
|
162
|
+
if (!adapter.open || !adapter.link || !adapter.unlink)
|
|
163
|
+
throw new TypeError("Migration filesystem must support retained writes, hard links and unlink.");
|
|
164
|
+
const handle = await adapter.open(temporaryPath, { access: "write", creation: "exclusive", mode: 384 });
|
|
165
|
+
created = true;
|
|
166
|
+
try {
|
|
167
|
+
const bytes = new TextEncoder().encode(contents);
|
|
168
|
+
let position = 0;
|
|
169
|
+
while (position < bytes.byteLength) {
|
|
170
|
+
const written = await handle.write(bytes.subarray(position), position);
|
|
171
|
+
if (!Number.isSafeInteger(written) || written <= 0 || written > bytes.byteLength - position)
|
|
172
|
+
throw new Error("Migration filesystem returned an invalid write count.");
|
|
173
|
+
position += written;
|
|
174
|
+
}
|
|
175
|
+
await handle.sync(false);
|
|
176
|
+
} finally {
|
|
177
|
+
await handle.close();
|
|
178
|
+
}
|
|
179
|
+
} else {
|
|
180
|
+
const handle = await hostFs.open(temporaryPath, "wx", 384);
|
|
181
|
+
created = true;
|
|
182
|
+
try {
|
|
183
|
+
await handle.writeFile(contents, "utf8");
|
|
184
|
+
await handle.sync();
|
|
185
|
+
} finally {
|
|
186
|
+
await handle.close();
|
|
187
|
+
}
|
|
157
188
|
}
|
|
158
189
|
try {
|
|
159
|
-
await link(temporaryPath, outputPath);
|
|
190
|
+
if (adapter) await adapter.link(temporaryPath, outputPath);
|
|
191
|
+
else await hostFs.link(temporaryPath, outputPath);
|
|
160
192
|
} catch (error) {
|
|
161
193
|
if (hasOwnErrorCode(error, "EEXIST"))
|
|
162
194
|
throw Object.assign(
|
|
@@ -169,7 +201,10 @@ async function migrateSnapshotFile(options) {
|
|
|
169
201
|
throw error;
|
|
170
202
|
}
|
|
171
203
|
} finally {
|
|
172
|
-
if (created)
|
|
204
|
+
if (created) {
|
|
205
|
+
if (adapter) await adapter.unlink(temporaryPath);
|
|
206
|
+
else await hostFs.unlink(temporaryPath);
|
|
207
|
+
}
|
|
173
208
|
}
|
|
174
209
|
}
|
|
175
210
|
return { inspection, outputPath, dryRun: options.dryRun === true };
|
|
@@ -180,4 +215,4 @@ export {
|
|
|
180
215
|
migrateSnapshot,
|
|
181
216
|
migrateSnapshotFile
|
|
182
217
|
};
|
|
183
|
-
//# sourceMappingURL=chunk-
|
|
218
|
+
//# sourceMappingURL=chunk-W4SWUHCQ.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/migration-file.ts", "../../src/migrate.ts"],
|
|
4
|
+
"sourcesContent": ["import { hostFs, hostCwd } from \"#safe-js-platform\";\nimport {createFsBridge, type FileSystem} from \"@poe-code/safe-fs/core\";\nimport {fsCodec} from \"./modules/fs-codec.js\";\nimport path from \"./modules/paths.js\";\nimport { hasOwnErrorCode } from \"./error-codes.js\";\n\nimport {\n inspectSnapshotMigration,\n migrateSnapshot,\n type SnapshotMigrationOptions\n} from \"./migrate.js\";\nimport type { SafeJSSnapshot } from \"./restore.js\";\nimport { serializeSafeJSSnapshot } from \"./snapshot/dump-format.js\";\n\nexport type SnapshotMigrationFileOptions = {\n adapter?: FileSystem;\n snapshotPath: string;\n sourcePath: string;\n targetSourcePath?: string;\n planPath?: string;\n outputPath?: string;\n inspect?: boolean;\n dryRun?: boolean;\n cwd?: string;\n};\n\nexport async function migrateSnapshotFile(options: SnapshotMigrationFileOptions) {\n const adapter = options.adapter;\n const io = adapter ? createFsBridge(adapter, {codec: fsCodec}) : hostFs;\n const readFile = io.readFile.bind(io);\n const cwd = options.cwd ?? hostCwd();\n const resolvePath = (value: string | undefined, label: string) => {\n if (typeof value !== \"string\" || value.trim().length === 0)\n throw new TypeError(`Migration requires ${label}.`);\n return path.resolve(cwd, value);\n };\n const snapshotPath = resolvePath(options.snapshotPath, \"a snapshot path\");\n const sourcePath = resolvePath(options.sourcePath, \"--from <original.ajs>\");\n if (\n options.inspect &&\n [options.targetSourcePath, options.planPath, options.outputPath].some(\n (value) => value !== undefined\n )\n )\n throw new TypeError(\"Migration --inspect cannot be combined with --to, --plan, or --output.\");\n const outputPath = options.inspect\n ? undefined\n : resolvePath(options.outputPath, \"--output <new-checkpoint.json>\");\n const targetSourcePath = options.inspect\n ? undefined\n : resolvePath(options.targetSourcePath, \"--to <continuation.ajs>\");\n const planPath = options.inspect\n ? undefined\n : resolvePath(options.planPath, \"--plan <migration.json>\");\n for (const filepath of [sourcePath, targetSourcePath]) {\n if (filepath !== undefined && ![\".ajs\", \".safejs\"].includes(path.extname(filepath)))\n throw new TypeError(\n \"Migration source paths must name executable .ajs or .safejs files, not harness Markdown.\"\n );\n }\n const snapshot: SafeJSSnapshot = JSON.parse(await readFile(snapshotPath, \"utf8\"));\n const source = await readFile(sourcePath, \"utf8\");\n const inspection = inspectSnapshotMigration(snapshot, { source });\n if (options.inspect) return { inspection };\n const plan: unknown = JSON.parse(await readFile(planPath!, \"utf8\"));\n if (\n plan === null ||\n typeof plan !== \"object\" ||\n !Object.hasOwn(plan, \"state\") ||\n !Object.hasOwn(plan, \"reconciliation\")\n )\n throw new TypeError(\"Migration plan requires explicit state and reconciliation fields.\");\n const targetSource = await readFile(targetSourcePath!, \"utf8\");\n const migrated = migrateSnapshot(snapshot, {\n source,\n targetSource,\n state: (plan as SnapshotMigrationOptions).state,\n reconciliation: (plan as SnapshotMigrationOptions).reconciliation\n });\n const contents = serializeSafeJSSnapshot(migrated);\n if (!options.dryRun) {\n const temporaryPath = path.join(\n path.dirname(outputPath!),\n `.safejs-migration-${globalThis.crypto.randomUUID()}.tmp`\n );\n let created = false;\n try {\n if (adapter) {\n if (!adapter.open || !adapter.link || !adapter.unlink)\n throw new TypeError(\"Migration filesystem must support retained writes, hard links and unlink.\");\n const handle = await adapter.open(temporaryPath, {access: \"write\", creation: \"exclusive\", mode: 0o600});\n created = true;\n try {\n const bytes = new TextEncoder().encode(contents);\n let position = 0;\n while (position < bytes.byteLength) {\n const written = await handle.write(bytes.subarray(position), position);\n if (!Number.isSafeInteger(written) || written <= 0 || written > bytes.byteLength - position)\n throw new Error(\"Migration filesystem returned an invalid write count.\");\n position += written;\n }\n await handle.sync(false);\n } finally {await handle.close();}\n } else {\n const handle = await hostFs.open(temporaryPath, \"wx\", 0o600);\n created = true;\n try {\n await handle.writeFile(contents, \"utf8\");\n await handle.sync();\n } finally {\n await handle.close();\n }\n }\n try {\n if (adapter) await adapter.link!(temporaryPath, outputPath!);\n else await hostFs.link(temporaryPath, outputPath!);\n } catch (error) {\n if (hasOwnErrorCode(error, \"EEXIST\"))\n throw Object.assign(\n new Error(\n `Migration output already exists: ${JSON.stringify(outputPath)}. Choose a new output path; existing files are never overwritten.`,\n { cause: error }\n ),\n { code: \"EEXIST\" }\n );\n throw error;\n }\n } finally {\n if (created) {\n if (adapter) await adapter.unlink!(temporaryPath);\n else await hostFs.unlink(temporaryPath);\n }\n }\n }\n return { inspection, outputPath, dryRun: options.dryRun === true };\n}\n", "import { sha256 } from \"@noble/hashes/sha2.js\";\nimport { bytesToHex } from \"@noble/hashes/utils.js\";\n\nimport { assertSnapshotInactive } from \"./interp/running-state.js\";\nimport { deepCopyToSandbox } from \"./interp/values.js\";\nimport { hashSource } from \"./parse/hash.js\";\nimport { parseModule } from \"./parse/parser.js\";\nimport type { SafeJSSnapshot } from \"./restore.js\";\nimport { DUMP_FORMAT_VERSION, EXECUTION_SEMANTICS } from \"./snapshot/dump-format.js\";\nimport {\n validateMigrationJournal,\n validateMigrationReconciliation,\n validateMigrationSemantics,\n validateSnapshotMigration,\n type SnapshotMigration,\n type SnapshotMigrationReconciliation\n} from \"./snapshot/migration.js\";\nimport { encodeReplayData } from \"./snapshot/replay-data.js\";\nimport { validateDumpEnvelope, validateSnapshotData } from \"./snapshot/validation.js\";\n\nexport type {\n SnapshotMigration,\n SnapshotMigrationReconciliation,\n SnapshotMigrationResolution\n} from \"./snapshot/migration.js\";\n\nexport type SnapshotMigrationOptions = {\n source: string;\n targetSource: string;\n state: unknown;\n reconciliation: SnapshotMigrationReconciliation;\n};\n\nexport function inspectSnapshotMigration(snapshot: SafeJSSnapshot, options: { source: string }) {\n assertSnapshotInactive(snapshot);\n validateSnapshotData(snapshot);\n validateDumpEnvelope(snapshot);\n validateMigrationSemantics(snapshot.executionSemantics);\n const sourceHash = hashSource(\n options.source,\n undefined,\n snapshot.executionSemantics === \"jobs-v8\" || snapshot.executionSemantics === EXECUTION_SEMANTICS\n );\n if (snapshot.sourceHash !== sourceHash)\n throw new TypeError(\n `Migration requires the original executable source (checkpoint hash ${snapshot.sourceHash}, supplied ${sourceHash}). Preserve the checkpoint; do not replace its hash.`\n );\n validateSnapshotMigration(snapshot.migration, sourceHash);\n const replay = validateMigrationJournal(sourceHash, snapshot.replay, snapshot.hostCalls);\n return {\n checkpointDigest: bytesToHex(sha256(new TextEncoder().encode(canonicalData(snapshot)))),\n sourceHash,\n executionSemantics: snapshot.executionSemantics,\n calls: replay.calls,\n unresolvedCalls: replay.calls.filter(\n (call) => ![\"settled\", \"consumed\"].includes(call.lifecycle)\n )\n };\n}\n\nexport function migrateSnapshot(\n snapshot: SafeJSSnapshot,\n options: SnapshotMigrationOptions\n): SafeJSSnapshot & { migration: SnapshotMigration } {\n if (!Object.hasOwn(options, \"state\"))\n throw new TypeError(\"Migration requires explicit application state.\");\n const inspection = inspectSnapshotMigration(snapshot, { source: options.source });\n parseModule(options.targetSource);\n const targetSourceHash = hashSource(options.targetSource);\n validateMigrationReconciliation(\n options.reconciliation,\n inspection.checkpointDigest,\n inspection.calls\n );\n const state = encodeReplayData(deepCopyToSandbox(options.state));\n const previous = snapshot.migration as SnapshotMigration | undefined;\n const migration: SnapshotMigration = {\n version: 1,\n state,\n history: [\n ...structuredClone(previous?.history ?? []),\n {\n sourceHash: inspection.sourceHash,\n targetSourceHash,\n executionSemantics: inspection.executionSemantics,\n replay: { version: 1, calls: inspection.calls },\n reconciliation: structuredClone(options.reconciliation)\n }\n ]\n };\n validateSnapshotMigration(migration, targetSourceHash);\n return {\n version: DUMP_FORMAT_VERSION,\n executionSemantics: EXECUTION_SEMANTICS,\n sourceHash: targetSourceHash,\n bindings: {},\n replay: { version: 1, calls: [] },\n migration\n };\n}\n\nfunction canonicalData(value: unknown): string {\n if (Array.isArray(value)) return `[${value.map(canonicalData).join(\",\")}]`;\n if (value !== null && typeof value === \"object\")\n return `{${Object.keys(value)\n .sort()\n .map(\n (key) => `${JSON.stringify(key)}:${canonicalData((value as Record<string, unknown>)[key])}`\n )\n .join(\",\")}}`;\n return JSON.stringify(value);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,SAAQ,sBAAsC;;;ACD9C,SAAS,cAAc;AACvB,SAAS,kBAAkB;AAgCpB,SAAS,yBAAyB,UAA0B,SAA6B;AAC9F,yBAAuB,QAAQ;AAC/B,uBAAqB,QAAQ;AAC7B,uBAAqB,QAAQ;AAC7B,6BAA2B,SAAS,kBAAkB;AACtD,QAAM,aAAa;AAAA,IACjB,QAAQ;AAAA,IACR;AAAA,IACA,SAAS,uBAAuB,aAAa,SAAS,uBAAuB;AAAA,EAC/E;AACA,MAAI,SAAS,eAAe;AAC1B,UAAM,IAAI;AAAA,MACR,sEAAsE,SAAS,UAAU,cAAc,UAAU;AAAA,IACnH;AACF,4BAA0B,SAAS,WAAW,UAAU;AACxD,QAAM,SAAS,yBAAyB,YAAY,SAAS,QAAQ,SAAS,SAAS;AACvF,SAAO;AAAA,IACL,kBAAkB,WAAW,OAAO,IAAI,YAAY,EAAE,OAAO,cAAc,QAAQ,CAAC,CAAC,CAAC;AAAA,IACtF;AAAA,IACA,oBAAoB,SAAS;AAAA,IAC7B,OAAO,OAAO;AAAA,IACd,iBAAiB,OAAO,MAAM;AAAA,MAC5B,CAAC,SAAS,CAAC,CAAC,WAAW,UAAU,EAAE,SAAS,KAAK,SAAS;AAAA,IAC5D;AAAA,EACF;AACF;AAEO,SAAS,gBACd,UACA,SACmD;AACnD,MAAI,CAAC,OAAO,OAAO,SAAS,OAAO;AACjC,UAAM,IAAI,UAAU,gDAAgD;AACtE,QAAM,aAAa,yBAAyB,UAAU,EAAE,QAAQ,QAAQ,OAAO,CAAC;AAChF,cAAY,QAAQ,YAAY;AAChC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AAAA,QACrB;AAAA,MACF;AACA,UAAI;AACF,YAAI,QAAS,OAAM,QAAQ,KAAM,eAAe,UAAW;AAAA,YACtD,OAAM,OAAO,KAAK,eAAe,UAAW;AAAA,MACnD,SAAS,OAAO;AACd,YAAI,gBAAgB,OAAO,QAAQ;AACjC,gBAAM,OAAO;AAAA,YACX,IAAI;AAAA,cACF,oCAAoC,KAAK,UAAU,UAAU,CAAC;AAAA,cAC9D,EAAE,OAAO,MAAM;AAAA,YACjB;AAAA,YACA,EAAE,MAAM,SAAS;AAAA,UACnB;AACF,cAAM;AAAA,MACR;AAAA,IACF,UAAE;AACA,UAAI,SAAS;AACX,YAAI,QAAS,OAAM,QAAQ,OAAQ,aAAa;AAAA,YAC3C,OAAM,OAAO,OAAO,aAAa;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AACA,SAAO,EAAE,YAAY,YAAY,QAAQ,QAAQ,WAAW,KAAK;AACnE;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
deepCopyToSandbox
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MDIWQFYU.js";
|
|
4
4
|
|
|
5
5
|
// packages/safe-js/src/modules/harness.ts
|
|
6
6
|
function makeHarnessModule(frontmatter, meta) {
|
|
@@ -52,4 +52,4 @@ ${prompt}`;
|
|
|
52
52
|
export {
|
|
53
53
|
makeHarnessModule
|
|
54
54
|
};
|
|
55
|
-
//# sourceMappingURL=chunk-
|
|
55
|
+
//# sourceMappingURL=chunk-WS2FJBH6.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SnapshotNotReadyError,
|
|
3
3
|
serializeSafeJSSnapshot
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-MDIWQFYU.js";
|
|
5
5
|
import {
|
|
6
6
|
SandboxError
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-QKO4FATZ.js";
|
|
8
8
|
|
|
9
9
|
// packages/safe-js/src/snapshot/dump.ts
|
|
10
10
|
var RUN_DUMP_CONTROLLER = /* @__PURE__ */ Symbol("SafeJS.run-dump-controller");
|
|
@@ -195,4 +195,4 @@ export {
|
|
|
195
195
|
dumpCurrent,
|
|
196
196
|
serializeRunSnapshot
|
|
197
197
|
};
|
|
198
|
-
//# sourceMappingURL=chunk-
|
|
198
|
+
//# sourceMappingURL=chunk-X3CKAZQ4.js.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hostCwd
|
|
3
|
+
} from "./chunk-UQPYTZOZ.js";
|
|
4
|
+
|
|
5
|
+
// packages/safe-js/src/modules/paths.ts
|
|
6
|
+
import { basename, dirname, extname, isAbsolutePath, joinPath, relativePath, resolvePath } from "@poe-platform/safe-fs/core";
|
|
7
|
+
var sep = "/";
|
|
8
|
+
function resolve(...paths) {
|
|
9
|
+
return resolvePath(hostCwd(), ...paths);
|
|
10
|
+
}
|
|
11
|
+
function relative(from, to) {
|
|
12
|
+
return relativePath(resolve(from), resolve(to));
|
|
13
|
+
}
|
|
14
|
+
var paths_default = { basename, dirname, extname, isAbsolute: isAbsolutePath, join: joinPath, relative, resolve, sep };
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
basename,
|
|
18
|
+
dirname,
|
|
19
|
+
extname,
|
|
20
|
+
isAbsolutePath,
|
|
21
|
+
sep,
|
|
22
|
+
resolve,
|
|
23
|
+
relative,
|
|
24
|
+
paths_default
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-YUQFFRUF.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/modules/paths.ts"],
|
|
4
|
+
"sourcesContent": ["import { basename, dirname, extname, isAbsolutePath, joinPath, relativePath, resolvePath } from \"@poe-code/safe-fs/core\";\nimport { hostCwd } from \"#safe-js-platform\";\nexport { basename, dirname, extname, isAbsolutePath as isAbsolute, joinPath as join };\nexport const sep = \"/\";\nexport function resolve(...paths: string[]): string { return resolvePath(hostCwd(), ...paths); }\nexport function relative(from: string, to: string): string { return relativePath(resolve(from), resolve(to)); }\nexport default { basename, dirname, extname, isAbsolute: isAbsolutePath, join: joinPath, relative, resolve, sep };\n\nexport function pathToFileURL(path: string): URL {\n return new URL(\"file://\" + resolve(path).split(\"/\").map(segment => encodeURIComponent(segment)).join(\"/\"));\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AAAA,SAAS,UAAU,SAAS,SAAS,gBAAgB,UAAU,cAAc,mBAAmB;AAGzF,IAAM,MAAM;AACZ,SAAS,WAAW,OAAyB;AAAE,SAAO,YAAY,QAAQ,GAAG,GAAG,KAAK;AAAG;AACxF,SAAS,SAAS,MAAc,IAAoB;AAAE,SAAO,aAAa,QAAQ,IAAI,GAAG,QAAQ,EAAE,CAAC;AAAG;AAC9G,IAAO,gBAAQ,EAAE,UAAU,SAAS,SAAS,YAAY,gBAAgB,MAAM,UAAU,UAAU,SAAS,IAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -12,40 +12,57 @@ import {
|
|
|
12
12
|
parseFsConfig,
|
|
13
13
|
resolveFsConfig,
|
|
14
14
|
splitFrontmatter
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-KETIFEA7.js";
|
|
16
16
|
import {
|
|
17
17
|
parseMcpConfig
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-MGHE7ZFI.js";
|
|
19
19
|
import {
|
|
20
20
|
lint
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-RULU2F5J.js";
|
|
22
22
|
import {
|
|
23
23
|
createBrokenPipeState,
|
|
24
24
|
createSafeOutputStream,
|
|
25
25
|
withBrokenPipeGuard
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-G6WTEIJJ.js";
|
|
27
|
+
import {
|
|
28
|
+
createRootedSourceResolver
|
|
29
|
+
} from "./chunk-F6CV74HU.js";
|
|
27
30
|
import "./chunk-U7ZNMTSQ.js";
|
|
31
|
+
import {
|
|
32
|
+
fsCodec
|
|
33
|
+
} from "./chunk-GVKXZW53.js";
|
|
28
34
|
import {
|
|
29
35
|
hasOwnErrorCode
|
|
30
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-2GVBG23M.js";
|
|
31
37
|
import {
|
|
32
38
|
Budget,
|
|
33
39
|
SandboxError,
|
|
34
40
|
parseModule,
|
|
35
41
|
parseSourceModule,
|
|
36
42
|
replaceErrorStack
|
|
37
|
-
} from "./chunk-
|
|
43
|
+
} from "./chunk-QKO4FATZ.js";
|
|
44
|
+
import {
|
|
45
|
+
dirname,
|
|
46
|
+
extname,
|
|
47
|
+
paths_default
|
|
48
|
+
} from "./chunk-YUQFFRUF.js";
|
|
49
|
+
import {
|
|
50
|
+
formatWithOptions,
|
|
51
|
+
hostFs
|
|
52
|
+
} from "./chunk-UQPYTZOZ.js";
|
|
38
53
|
import "./chunk-4YIDX44G.js";
|
|
39
54
|
|
|
40
55
|
// packages/safe-js/src/cli-runtime.ts
|
|
41
|
-
import {
|
|
42
|
-
import path, { dirname, extname } from "node:path";
|
|
43
|
-
import { formatWithOptions } from "node:util";
|
|
56
|
+
import { createFsBridge } from "@poe-platform/safe-fs/core";
|
|
44
57
|
var EXIT_RUNTIME = 1;
|
|
45
58
|
var EXIT_PARSE = 2;
|
|
46
59
|
var EXIT_BUDGET = 3;
|
|
47
60
|
var EXIT_SIGINT = 130;
|
|
48
61
|
async function runCli(argv, options, usage) {
|
|
62
|
+
const io = options.adapter ? createFsBridge(options.adapter, { codec: fsCodec }) : hostFs;
|
|
63
|
+
const readFile = io.readFile.bind(io);
|
|
64
|
+
const writeFile = io.writeFile.bind(io);
|
|
65
|
+
const stat = io.stat.bind(io);
|
|
49
66
|
const brokenPipe = createBrokenPipeState();
|
|
50
67
|
const stdout = createSafeOutputStream(options.stdout ?? process.stdout, brokenPipe);
|
|
51
68
|
const stderr = createSafeOutputStream(options.stderr ?? process.stderr, brokenPipe);
|
|
@@ -55,10 +72,11 @@ async function runCli(argv, options, usage) {
|
|
|
55
72
|
async () => {
|
|
56
73
|
try {
|
|
57
74
|
if (argv[0] === "migrate") {
|
|
58
|
-
const { migrateSnapshotFile } = await import("./migration-file-
|
|
75
|
+
const { migrateSnapshotFile } = await import("./migration-file-KRXQYI3Q.js");
|
|
59
76
|
const result = await migrateSnapshotFile({
|
|
60
77
|
...parseMigrationArgs(argv.slice(1)),
|
|
61
|
-
cwd: options.cwd ?? readCurrentWorkingDirectory()
|
|
78
|
+
cwd: options.cwd ?? readCurrentWorkingDirectory(),
|
|
79
|
+
adapter: options.adapter
|
|
62
80
|
});
|
|
63
81
|
stdout.write(`${JSON.stringify(result, null, 2)}
|
|
64
82
|
`);
|
|
@@ -71,10 +89,10 @@ async function runCli(argv, options, usage) {
|
|
|
71
89
|
return brokenPipe.closed ? 0 : EXIT_RUNTIME;
|
|
72
90
|
}
|
|
73
91
|
const cwd = options.cwd ?? readCurrentWorkingDirectory();
|
|
74
|
-
const filepath =
|
|
92
|
+
const filepath = paths_default.resolve(cwd, parsed.filepath);
|
|
75
93
|
const configuredFs = parsed.fsConfig === void 0 ? void 0 : await resolveFsConfig(
|
|
76
94
|
parseFsConfig(
|
|
77
|
-
await (options.readFile ?? readFile)(
|
|
95
|
+
await (options.readFile ?? readFile)(paths_default.resolve(cwd, parsed.fsConfig), "utf8")
|
|
78
96
|
)
|
|
79
97
|
);
|
|
80
98
|
await assertHarnessFile({
|
|
@@ -85,6 +103,7 @@ async function runCli(argv, options, usage) {
|
|
|
85
103
|
return await runScriptFile(filepath, parsed, {
|
|
86
104
|
cwd,
|
|
87
105
|
configuredFs,
|
|
106
|
+
adapter: options.adapter,
|
|
88
107
|
env: options.env,
|
|
89
108
|
mcp: options.mcp,
|
|
90
109
|
modulesFor: options.modulesFor,
|
|
@@ -272,12 +291,12 @@ async function assertHarnessFile(input) {
|
|
|
272
291
|
}
|
|
273
292
|
async function runScriptFile(filepath, parsed, options) {
|
|
274
293
|
const [{ run }, { restore }, { dump, dumpCurrent }, { createLintModulesFromRuntimeRegistry }, { makeFsModule }, { makeMcpModule }] = await Promise.all([
|
|
275
|
-
import("./run-
|
|
276
|
-
import("./restore-
|
|
277
|
-
import("./dump-
|
|
278
|
-
import("./runtime-modules-
|
|
279
|
-
import("
|
|
280
|
-
import("./mcp-
|
|
294
|
+
import("./run-ZSFX66RN.js"),
|
|
295
|
+
import("./restore-GEO7VN2R.js"),
|
|
296
|
+
import("./dump-RGRC3CG3.js"),
|
|
297
|
+
import("./runtime-modules-A3U2DKFL.js"),
|
|
298
|
+
import("../modules/fs.js"),
|
|
299
|
+
import("./mcp-S672263Q.js")
|
|
281
300
|
]);
|
|
282
301
|
const loaded = loadExecutableSource(filepath, await options.readFile(filepath, "utf8"));
|
|
283
302
|
const meta = {
|
|
@@ -286,7 +305,7 @@ async function runScriptFile(filepath, parsed, options) {
|
|
|
286
305
|
version: loaded.frontmatter.version
|
|
287
306
|
};
|
|
288
307
|
const runtime = await createRuntime(loaded.frontmatter, meta, {
|
|
289
|
-
fs: parsed.fs ? { root:
|
|
308
|
+
fs: parsed.fs ? { root: paths_default.resolve(options.cwd, parsed.fsRoot ?? dirname(filepath)), ...options.adapter ? { adapter: options.adapter } : {} } : void 0,
|
|
290
309
|
modulesFor: options.modulesFor,
|
|
291
310
|
stderr: options.stderr,
|
|
292
311
|
stdout: options.stdout
|
|
@@ -303,7 +322,7 @@ async function runScriptFile(filepath, parsed, options) {
|
|
|
303
322
|
if (parsed.envConfig !== void 0) {
|
|
304
323
|
if (env !== void 0)
|
|
305
324
|
throw new TypeError("Pass environment options or --env-config, not both.");
|
|
306
|
-
const configPath =
|
|
325
|
+
const configPath = paths_default.resolve(options.cwd, parsed.envConfig);
|
|
307
326
|
env = parseEnvConfig(await options.readFile(configPath, "utf8"));
|
|
308
327
|
}
|
|
309
328
|
if (env !== void 0) {
|
|
@@ -318,7 +337,7 @@ async function runScriptFile(filepath, parsed, options) {
|
|
|
318
337
|
let mcp = options.mcp;
|
|
319
338
|
if (parsed.mcpConfig !== void 0) {
|
|
320
339
|
if (mcp !== void 0) throw new TypeError("Pass MCP options or --mcp-config, not both.");
|
|
321
|
-
const configPath =
|
|
340
|
+
const configPath = paths_default.resolve(options.cwd, parsed.mcpConfig);
|
|
322
341
|
mcp = parseMcpConfig(await options.readFile(configPath, "utf8"), dirname(configPath));
|
|
323
342
|
}
|
|
324
343
|
if (mcp !== void 0) {
|
|
@@ -399,14 +418,16 @@ ${formatDiagnostics(lintWarnings)}
|
|
|
399
418
|
signalSnapshotWrite = writeCurrentSnapshot(runPromise, parsed.snapshotPath, options, dumpCurrent);
|
|
400
419
|
}
|
|
401
420
|
};
|
|
421
|
+
const sourceResolver = parsed.sourceRoot !== void 0 && options.adapter !== void 0 ? await createRootedSourceResolver(paths_default.resolve(options.cwd, parsed.sourceRoot), options.adapter) : void 0;
|
|
402
422
|
options.process.on("SIGINT", onSigint);
|
|
403
423
|
try {
|
|
404
424
|
runPromise = run(executableSource, {
|
|
405
425
|
budget: parsed.maxSteps === void 0 && parsed.dataSize === void 0 ? void 0 : new Budget({ dataSize: parsed.dataSize, maxSteps: parsed.maxSteps }),
|
|
406
426
|
entryPointArgs: parsed.sourceType === "module" ? void 0 : hasDefaultExport(executableSource, diagnosticFilename) ? [] : void 0,
|
|
407
427
|
sourceType: parsed.sourceType,
|
|
408
|
-
|
|
409
|
-
|
|
428
|
+
sourceResolver,
|
|
429
|
+
sourceRoot: sourceResolver !== void 0 || parsed.sourceRoot === void 0 ? void 0 : paths_default.resolve(options.cwd, parsed.sourceRoot),
|
|
430
|
+
filename: sourceResolver === void 0 ? diagnosticFilename : await sourceResolver.entryId(filepath),
|
|
410
431
|
modules,
|
|
411
432
|
signal: abortController.signal,
|
|
412
433
|
sink: createConsoleSink(options.stdout, options.stderr),
|
|
@@ -513,8 +534,8 @@ async function createRuntime(frontmatter, meta, options) {
|
|
|
513
534
|
};
|
|
514
535
|
}
|
|
515
536
|
const [{ makeHarnessModule }, { makeFsModule }] = await Promise.all([
|
|
516
|
-
import("./harness-
|
|
517
|
-
import("
|
|
537
|
+
import("./harness-UMOMFXDT.js"),
|
|
538
|
+
import("../modules/fs.js")
|
|
518
539
|
]);
|
|
519
540
|
const state = {
|
|
520
541
|
metricCalls: /* @__PURE__ */ new Map(),
|
|
@@ -555,7 +576,7 @@ async function readRestoreSnapshot(restorePath, options) {
|
|
|
555
576
|
if (restorePath === void 0) {
|
|
556
577
|
return void 0;
|
|
557
578
|
}
|
|
558
|
-
const snapshotPath =
|
|
579
|
+
const snapshotPath = paths_default.resolve(options.cwd, restorePath);
|
|
559
580
|
let rawSnapshot;
|
|
560
581
|
try {
|
|
561
582
|
rawSnapshot = await options.readFile(snapshotPath, "utf8");
|
|
@@ -582,8 +603,8 @@ async function writeCurrentSnapshot(result, snapshotPath, options, capture) {
|
|
|
582
603
|
}
|
|
583
604
|
}
|
|
584
605
|
async function writeSnapshot(snapshotPath, content, options) {
|
|
585
|
-
const resolvedPath =
|
|
586
|
-
await mkdir(dirname(resolvedPath), { recursive: true });
|
|
606
|
+
const resolvedPath = paths_default.resolve(options.cwd, snapshotPath);
|
|
607
|
+
await (options.adapter ? createFsBridge(options.adapter, { codec: fsCodec }) : hostFs).mkdir(dirname(resolvedPath), { recursive: true });
|
|
587
608
|
await options.writeFile(resolvedPath, content, { encoding: "utf8" });
|
|
588
609
|
}
|
|
589
610
|
function createConsoleSink(stdout, stderr) {
|
|
@@ -704,4 +725,4 @@ export {
|
|
|
704
725
|
exitCodeForError,
|
|
705
726
|
runCli
|
|
706
727
|
};
|
|
707
|
-
//# sourceMappingURL=cli-runtime-
|
|
728
|
+
//# sourceMappingURL=cli-runtime-NUEFUM64.js.map
|