@onereach/json-schema-aot 0.0.0-stage → 0.2.0-framework.2
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 +271 -2
- package/dist/index.d.mts +17 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +189 -0
- package/dist/index.mjs.map +1 -0
- package/dist/replace-directory.d.mts +20 -0
- package/dist/replace-directory.d.mts.map +1 -0
- package/dist/replace-directory.mjs +41 -0
- package/dist/replace-directory.mjs.map +1 -0
- package/dist/rolldown/authoring-inputs.d.mts +13 -0
- package/dist/rolldown/authoring-inputs.d.mts.map +1 -0
- package/dist/rolldown/authoring-inputs.mjs +86 -0
- package/dist/rolldown/authoring-inputs.mjs.map +1 -0
- package/dist/rolldown/directories.d.mts +7 -0
- package/dist/rolldown/directories.d.mts.map +1 -0
- package/dist/rolldown/directories.mjs +65 -0
- package/dist/rolldown/directories.mjs.map +1 -0
- package/dist/rolldown/generate.d.mts +7 -0
- package/dist/rolldown/generate.d.mts.map +1 -0
- package/dist/rolldown/generate.mjs +49 -0
- package/dist/rolldown/generate.mjs.map +1 -0
- package/dist/rolldown/index.d.mts +18 -0
- package/dist/rolldown/index.d.mts.map +1 -0
- package/dist/rolldown/index.mjs +185 -0
- package/dist/rolldown/index.mjs.map +1 -0
- package/dist/rolldown/inputs.d.mts +7 -0
- package/dist/rolldown/inputs.d.mts.map +1 -0
- package/dist/rolldown/inputs.mjs +65 -0
- package/dist/rolldown/inputs.mjs.map +1 -0
- package/dist/rolldown/node-options.d.mts +10 -0
- package/dist/rolldown/node-options.d.mts.map +1 -0
- package/dist/rolldown/node-options.mjs +95 -0
- package/dist/rolldown/node-options.mjs.map +1 -0
- package/dist/rolldown/publish.d.mts +10 -0
- package/dist/rolldown/publish.d.mts.map +1 -0
- package/dist/rolldown/publish.mjs +25 -0
- package/dist/rolldown/publish.mjs.map +1 -0
- package/dist/rolldown/resolution.d.mts +10 -0
- package/dist/rolldown/resolution.d.mts.map +1 -0
- package/dist/rolldown/resolution.mjs +105 -0
- package/dist/rolldown/resolution.mjs.map +1 -0
- package/dist/rolldown/schema-worker.d.mts +2 -0
- package/dist/rolldown/schema-worker.d.mts.map +1 -0
- package/dist/rolldown/schema-worker.mjs +24 -0
- package/dist/rolldown/schema-worker.mjs.map +1 -0
- package/dist/rolldown/worker-protocol.d.mts +10 -0
- package/dist/rolldown/worker-protocol.d.mts.map +1 -0
- package/dist/rolldown/worker-protocol.mjs +9 -0
- package/dist/rolldown/worker-protocol.mjs.map +1 -0
- package/dist/validator-source.d.mts +10 -0
- package/dist/validator-source.d.mts.map +1 -0
- package/dist/validator-source.mjs +62 -0
- package/dist/validator-source.mjs.map +1 -0
- package/package.json +49 -3
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { readlink, realpath } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { areInputsCurrent, digest } from './inputs.mjs';
|
|
4
|
+
/**
|
|
5
|
+
* Keep lexical resolver paths alongside canonical module IDs. Content alone cannot
|
|
6
|
+
* detect a symlink retargeted to identical source with different relative imports.
|
|
7
|
+
*/
|
|
8
|
+
export function authoringInputs(watchFile) {
|
|
9
|
+
const contents = new Map();
|
|
10
|
+
const identities = new Map();
|
|
11
|
+
const ancestorChecks = new Map();
|
|
12
|
+
let isChanged = false;
|
|
13
|
+
function snapshot(file, bytes) {
|
|
14
|
+
const hash = digest(bytes);
|
|
15
|
+
const previous = contents.get(file);
|
|
16
|
+
if (previous !== undefined && previous !== hash)
|
|
17
|
+
isChanged = true;
|
|
18
|
+
else
|
|
19
|
+
contents.set(file, hash);
|
|
20
|
+
}
|
|
21
|
+
function identity(file, canonical) {
|
|
22
|
+
watchFile(file);
|
|
23
|
+
const previous = identities.get(file);
|
|
24
|
+
if (previous !== undefined && previous !== canonical)
|
|
25
|
+
isChanged = true;
|
|
26
|
+
else
|
|
27
|
+
identities.set(file, canonical);
|
|
28
|
+
}
|
|
29
|
+
function watchAncestors(directory) {
|
|
30
|
+
const previous = ancestorChecks.get(directory);
|
|
31
|
+
if (previous)
|
|
32
|
+
return previous;
|
|
33
|
+
const checking = (async () => {
|
|
34
|
+
try {
|
|
35
|
+
await readlink(directory);
|
|
36
|
+
identity(directory, await realpath(directory));
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
39
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'EINVAL'))
|
|
40
|
+
throw error;
|
|
41
|
+
}
|
|
42
|
+
const parent = path.dirname(directory);
|
|
43
|
+
if (parent !== directory)
|
|
44
|
+
await watchAncestors(parent);
|
|
45
|
+
})();
|
|
46
|
+
// Share in-flight checks as well as completed ones across concurrent resolves.
|
|
47
|
+
ancestorChecks.set(directory, checking);
|
|
48
|
+
return checking;
|
|
49
|
+
}
|
|
50
|
+
async function resolveFile(file) {
|
|
51
|
+
const lexical = path.resolve(file);
|
|
52
|
+
const canonical = await realpath(lexical);
|
|
53
|
+
identity(lexical, canonical);
|
|
54
|
+
watchFile(canonical);
|
|
55
|
+
// Watch directory aliases too: replacing one must invalidate its descendants.
|
|
56
|
+
await watchAncestors(path.dirname(lexical));
|
|
57
|
+
return canonical;
|
|
58
|
+
}
|
|
59
|
+
async function areCurrent() {
|
|
60
|
+
// A later resolution pass must rediscover aliases, including newly created ones.
|
|
61
|
+
ancestorChecks.clear();
|
|
62
|
+
if (isChanged || !(await areInputsCurrent(contents)))
|
|
63
|
+
return false;
|
|
64
|
+
try {
|
|
65
|
+
for (const [file, canonical] of identities) {
|
|
66
|
+
if ((await realpath(file)) !== canonical)
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
catch (error) {
|
|
72
|
+
if (error instanceof Error && 'code' in error && ['ENOENT', 'ENOTDIR'].includes(String(error.code)))
|
|
73
|
+
return false;
|
|
74
|
+
throw error;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
contents,
|
|
79
|
+
identities,
|
|
80
|
+
snapshot,
|
|
81
|
+
resolveFile,
|
|
82
|
+
areCurrent,
|
|
83
|
+
paths: () => [...contents.keys(), ...identities.keys()],
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=authoring-inputs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authoring-inputs.mjs","sourceRoot":"","sources":["../../src/rolldown/authoring-inputs.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,gBAAgB,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAExD;;;GAGG;AACH,MAAM,UAAU,eAAe,CAAC,SAAiC;IAC/D,MAAM,QAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC3C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC7C,MAAM,cAAc,GAAG,IAAI,GAAG,EAAyB,CAAC;IACxD,IAAI,SAAS,GAAG,KAAK,CAAC;IAEtB,SAAS,QAAQ,CAAC,IAAY,EAAE,KAAiB;QAC/C,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC3B,MAAM,QAAQ,GAAG,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,IAAI;YAAE,SAAS,GAAG,IAAI,CAAC;;YAC7D,QAAQ,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAChC,CAAC;IAED,SAAS,QAAQ,CAAC,IAAY,EAAE,SAAiB;QAC/C,SAAS,CAAC,IAAI,CAAC,CAAC;QAChB,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,QAAQ,KAAK,SAAS,IAAI,QAA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CAAC,OAAO,CAAC,CAAC,CAAC;QAC5C,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,KAAK,UAAU,UAAU;QACvB,iFAAiF;QACjF,cAAc,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,SAAS,IAAI,CAAC,CAAC,MAAM,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YAAE,OAAO,KAAK,CAAC;QACnE,IAAI,CAAC;YACH,KAAK,MAAM,CAAC,IAAI,EAAE,SAAS,CAAC,IAAI,UAAU,EAAE,CAAC;gBAC3C,IAAI,CAAC,MAAM,QAAQ,CAAC,IAAI,CAAC,CAAC,KAAK,SAAS;oBAAE,OAAO,KAAK,CAAC;YACzD,CAAC;YACD,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;YAClH,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO;QACL,QAAQ;QACR,UAAU;QACV,QAAQ;QACR,WAAW;QACX,UAAU;QACV,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,GAAG,UAAU,CAAC,IAAI,EAAE,CAAC;KACxD,CAAC;AACJ,CAAC","sourcesContent":["import { readlink, realpath } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { areInputsCurrent, digest } from './inputs.mjs';\n\n/**\n * Keep lexical resolver paths alongside canonical module IDs. Content alone cannot\n * detect a symlink retargeted to identical source with different relative imports.\n */\nexport function authoringInputs(watchFile: (file: string) => void) {\n const contents = new Map<string, string>();\n const identities = new Map<string, string>();\n const ancestorChecks = new Map<string, Promise<void>>();\n let isChanged = false;\n\n function snapshot(file: string, bytes: Uint8Array): void {\n const hash = digest(bytes);\n const previous = contents.get(file);\n if (previous !== undefined && previous !== hash) isChanged = true;\n else contents.set(file, hash);\n }\n\n function identity(file: string, canonical: string): void {\n watchFile(file);\n const previous = identities.get(file);\n if (previous !== undefined && previous !== canonical) isChanged = true;\n else identities.set(file, canonical);\n }\n\n function watchAncestors(directory: string): Promise<void> {\n const previous = ancestorChecks.get(directory);\n if (previous) return previous;\n const checking = (async () => {\n try {\n await readlink(directory);\n identity(directory, await realpath(directory));\n } catch (error) {\n if (!(error instanceof Error && 'code' in error && error.code === 'EINVAL')) throw error;\n }\n const parent = path.dirname(directory);\n if (parent !== directory) await watchAncestors(parent);\n })();\n // Share in-flight checks as well as completed ones across concurrent resolves.\n ancestorChecks.set(directory, checking);\n return checking;\n }\n\n async function resolveFile(file: string): Promise<string> {\n const lexical = path.resolve(file);\n const canonical = await realpath(lexical);\n identity(lexical, canonical);\n watchFile(canonical);\n // Watch directory aliases too: replacing one must invalidate its descendants.\n await watchAncestors(path.dirname(lexical));\n return canonical;\n }\n\n async function areCurrent(): Promise<boolean> {\n // A later resolution pass must rediscover aliases, including newly created ones.\n ancestorChecks.clear();\n if (isChanged || !(await areInputsCurrent(contents))) return false;\n try {\n for (const [file, canonical] of identities) {\n if ((await realpath(file)) !== canonical) return false;\n }\n return true;\n } catch (error) {\n if (error instanceof Error && 'code' in error && ['ENOENT', 'ENOTDIR'].includes(String(error.code))) return false;\n throw error;\n }\n }\n\n return {\n contents,\n identities,\n snapshot,\n resolveFile,\n areCurrent,\n paths: () => [...contents.keys(), ...identities.keys()],\n };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Protect both directory entries and their resolved targets, including authored
|
|
3
|
+
* symlinks pointing outside an output or staging tree. Resolve existing symlink
|
|
4
|
+
* ancestors even when a generation directory does not yet exist.
|
|
5
|
+
*/
|
|
6
|
+
export declare function assertSafeDirectories(outputDirectory: string, temporaryDirectory: string, authoredInputs: Iterable<string>): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=directories.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directories.d.mts","sourceRoot":"","sources":["../../src/rolldown/directories.mts"],"names":[],"mappings":"AAkDA;;;;GAIG;AACH,wBAAsB,qBAAqB,CACzC,eAAe,EAAE,MAAM,EACvB,kBAAkB,EAAE,MAAM,EAC1B,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,GAC/B,OAAO,CAAC,IAAI,CAAC,CAWf"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { readlink, realpath } from 'node:fs/promises';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { isInsideDirectory } from './inputs.mjs';
|
|
4
|
+
async function canonicalPath(file) {
|
|
5
|
+
const missing = [];
|
|
6
|
+
let current = path.resolve(file);
|
|
7
|
+
while (true) {
|
|
8
|
+
try {
|
|
9
|
+
return path.join(await realpath(current), ...missing);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT'))
|
|
13
|
+
throw error;
|
|
14
|
+
let link;
|
|
15
|
+
try {
|
|
16
|
+
link = await readlink(current);
|
|
17
|
+
}
|
|
18
|
+
catch (linkError) {
|
|
19
|
+
if (!(linkError instanceof Error &&
|
|
20
|
+
'code' in linkError &&
|
|
21
|
+
['ENOENT', 'EINVAL'].includes(String(linkError.code))))
|
|
22
|
+
throw linkError;
|
|
23
|
+
}
|
|
24
|
+
if (link !== undefined) {
|
|
25
|
+
const target = path.resolve(path.dirname(current), link);
|
|
26
|
+
const canonical = await canonicalPath(target);
|
|
27
|
+
return path.join(canonical, ...missing);
|
|
28
|
+
}
|
|
29
|
+
const parent = path.dirname(current);
|
|
30
|
+
if (parent === current)
|
|
31
|
+
throw error;
|
|
32
|
+
missing.unshift(path.basename(current));
|
|
33
|
+
current = parent;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function isWithin(directory, file) {
|
|
38
|
+
return path.relative(directory, file) === '' || isInsideDirectory(directory, file);
|
|
39
|
+
}
|
|
40
|
+
function assertLayout(output, temporary, authoredInputs) {
|
|
41
|
+
if (isWithin(output, temporary) || isWithin(temporary, output))
|
|
42
|
+
throw new Error('Schema output and temporary directories must not overlap.');
|
|
43
|
+
for (const input of authoredInputs) {
|
|
44
|
+
if (isWithin(output, input) || isWithin(temporary, input))
|
|
45
|
+
throw new Error(`Schema generation directories must not contain authored input: ${input}`);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Protect both directory entries and their resolved targets, including authored
|
|
50
|
+
* symlinks pointing outside an output or staging tree. Resolve existing symlink
|
|
51
|
+
* ancestors even when a generation directory does not yet exist.
|
|
52
|
+
*/
|
|
53
|
+
export async function assertSafeDirectories(outputDirectory, temporaryDirectory, authoredInputs) {
|
|
54
|
+
const output = path.resolve(outputDirectory);
|
|
55
|
+
const temporary = path.resolve(temporaryDirectory);
|
|
56
|
+
const inputs = [...authoredInputs].map((input) => path.resolve(input));
|
|
57
|
+
assertLayout(output, temporary, inputs);
|
|
58
|
+
const [canonicalOutput, canonicalTemporary, canonicalInputs] = await Promise.all([
|
|
59
|
+
canonicalPath(output),
|
|
60
|
+
canonicalPath(temporary),
|
|
61
|
+
Promise.all(inputs.map((input) => canonicalPath(input))),
|
|
62
|
+
]);
|
|
63
|
+
assertLayout(canonicalOutput, canonicalTemporary, canonicalInputs);
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=directories.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"directories.mjs","sourceRoot":"","sources":["../../src/rolldown/directories.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CA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EAAE,eAAe,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC/E,aAAa,CAAC,MAAM,CAAC;QACrB,aAAa,CAAC,SAAS,CAAC;QACxB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;KACzD,CAAC,CAAC;IACH,YAAY,CAAC,eAAe,EAAE,kBAAkB,EAAE,eAAe,CAAC,CAAC;AACrE,CAAC","sourcesContent":["import { readlink, realpath } from 'node:fs/promises';\nimport path from 'node:path';\n\nimport { isInsideDirectory } from './inputs.mjs';\n\nasync function canonicalPath(file: string): Promise<string> {\n const missing: string[] = [];\n let current = path.resolve(file);\n while (true) {\n try {\n return path.join(await realpath(current), ...missing);\n } catch (error) {\n if (!(error instanceof Error && 'code' in error && error.code === 'ENOENT')) throw error;\n let link: string | undefined;\n try {\n link = await readlink(current);\n } catch (linkError) {\n if (!(\n linkError instanceof Error &&\n 'code' in linkError &&\n ['ENOENT', 'EINVAL'].includes(String(linkError.code))\n ))\n throw linkError;\n }\n if (link !== undefined) {\n const target = path.resolve(path.dirname(current), link);\n const canonical = await canonicalPath(target);\n return path.join(canonical, ...missing);\n }\n const parent = path.dirname(current);\n if (parent === current) throw error;\n missing.unshift(path.basename(current));\n current = parent;\n }\n }\n}\n\nfunction isWithin(directory: string, file: string): boolean {\n return path.relative(directory, file) === '' || isInsideDirectory(directory, file);\n}\n\nfunction assertLayout(output: string, temporary: string, authoredInputs: Iterable<string>): void {\n if (isWithin(output, temporary) || isWithin(temporary, output))\n throw new Error('Schema output and temporary directories must not overlap.');\n for (const input of authoredInputs) {\n if (isWithin(output, input) || isWithin(temporary, input))\n throw new Error(`Schema generation directories must not contain authored input: ${input}`);\n }\n}\n\n/**\n * Protect both directory entries and their resolved targets, including authored\n * symlinks pointing outside an output or staging tree. Resolve existing symlink\n * ancestors even when a generation directory does not yet exist.\n */\nexport async function assertSafeDirectories(\n outputDirectory: string,\n temporaryDirectory: string,\n authoredInputs: Iterable<string>,\n): Promise<void> {\n const output = path.resolve(outputDirectory);\n const temporary = path.resolve(temporaryDirectory);\n const inputs = [...authoredInputs].map((input) => path.resolve(input));\n assertLayout(output, temporary, inputs);\n const [canonicalOutput, canonicalTemporary, canonicalInputs] = await Promise.all([\n canonicalPath(output),\n canonicalPath(temporary),\n Promise.all(inputs.map((input) => canonicalPath(input))),\n ]);\n assertLayout(canonicalOutput, canonicalTemporary, canonicalInputs);\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { GenerateOptions } from '../index.mjs';
|
|
2
|
+
/**
|
|
3
|
+
* Evaluate one staged generation job in a fresh worker, waiting for thread exit
|
|
4
|
+
* after completion or cancellation before the parent may publish or clean up.
|
|
5
|
+
*/
|
|
6
|
+
export declare function generateInWorker(entry: string, exportName: string | undefined, options: GenerateOptions, signal: AbortSignal, execArgv: string[]): Promise<void>;
|
|
7
|
+
//# sourceMappingURL=generate.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.mts","sourceRoot":"","sources":["../../src/rolldown/generate.mts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAKpD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,OAAO,EAAE,eAAe,EACxB,MAAM,EAAE,WAAW,EACnB,QAAQ,EAAE,MAAM,EAAE,GACjB,OAAO,CAAC,IAAI,CAAC,CAqCf"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Worker } from 'node:worker_threads';
|
|
2
|
+
import { isGenerationResult } from './worker-protocol.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Evaluate one staged generation job in a fresh worker, waiting for thread exit
|
|
5
|
+
* after completion or cancellation before the parent may publish or clean up.
|
|
6
|
+
*/
|
|
7
|
+
export function generateInWorker(entry, exportName, options, signal, execArgv) {
|
|
8
|
+
signal.throwIfAborted();
|
|
9
|
+
return new Promise((resolve, reject) => {
|
|
10
|
+
// A new worker releases the entire authoring module cache after every generation.
|
|
11
|
+
const worker = new Worker(new URL('schema-worker.mjs', import.meta.url), {
|
|
12
|
+
workerData: { entry, exportName, options },
|
|
13
|
+
execArgv,
|
|
14
|
+
});
|
|
15
|
+
const cancel = () => {
|
|
16
|
+
void worker.terminate();
|
|
17
|
+
};
|
|
18
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
19
|
+
let failure;
|
|
20
|
+
let result;
|
|
21
|
+
worker.on('message', (message) => {
|
|
22
|
+
if (result || !isGenerationResult(message))
|
|
23
|
+
return;
|
|
24
|
+
result = message;
|
|
25
|
+
// Completion is explicit: authoring-module timers must not keep a finished job alive.
|
|
26
|
+
cancel();
|
|
27
|
+
});
|
|
28
|
+
worker.once('error', (error) => {
|
|
29
|
+
failure = error instanceof Error ? error : new Error('Schema generation worker failed.', { cause: error });
|
|
30
|
+
cancel();
|
|
31
|
+
});
|
|
32
|
+
worker.once('exit', (code) => {
|
|
33
|
+
signal.removeEventListener('abort', cancel);
|
|
34
|
+
if (signal.aborted)
|
|
35
|
+
reject(new DOMException('Schema generation aborted.', 'AbortError'));
|
|
36
|
+
else if (failure)
|
|
37
|
+
reject(failure);
|
|
38
|
+
else if (!result)
|
|
39
|
+
reject(new Error(`Schema generation worker exited before reporting completion (code ${code}).`));
|
|
40
|
+
else if (result.success) {
|
|
41
|
+
resolve();
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
reject(result.error);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=generate.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.mjs","sourceRoot":"","sources":["../../src/rolldown/generate.mts"],"names":[],"mappings":"AAAA,OAAO,E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E,CAAC;QACX,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;YAC3B,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;YAC5C,IAAI,MAAM,CAAC,OAAO;gBAAE,MAAM,CAAC,IAAI,YAAY,CAAC,4BAA4B,EAAE,YAAY,CAAC,CAAC,CAAC;iBACpF,IAAI,OAAO;gBAAE,MAAM,CAAC,OAAO,CAAC,CAAC;iBAC7B,IAAI,CAAC,MAAM;gBACd,MAAM,CAAC,IAAI,KAAK,CAAC,qEAAqE,IAAI,IAAI,CAAC,CAAC,CAAC;iBAC9F,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;gBACxB,OAAO,EAAE,CAAC;YACZ,CAAC;iBAAM,CAAC;gBACN,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACvB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Worker } from 'node:worker_threads';\n\nimport type { GenerateOptions } from '../index.mjs';\n\nimport { isGenerationResult } from './worker-protocol.mjs';\nimport type { GenerationResult } from './worker-protocol.mjs';\n\n/**\n * Evaluate one staged generation job in a fresh worker, waiting for thread exit\n * after completion or cancellation before the parent may publish or clean up.\n */\nexport function generateInWorker(\n entry: string,\n exportName: string | undefined,\n options: GenerateOptions,\n signal: AbortSignal,\n execArgv: string[],\n): Promise<void> {\n signal.throwIfAborted();\n return new Promise((resolve, reject) => {\n // A new worker releases the entire authoring module cache after every generation.\n const worker = new Worker(new URL('schema-worker.mjs', import.meta.url), {\n workerData: { entry, exportName, options },\n execArgv,\n });\n const cancel = () => {\n void worker.terminate();\n };\n signal.addEventListener('abort', cancel, { once: true });\n let failure: Error | undefined;\n let result: GenerationResult | undefined;\n worker.on('message', (message: unknown) => {\n if (result || !isGenerationResult(message)) return;\n result = message;\n // Completion is explicit: authoring-module timers must not keep a finished job alive.\n cancel();\n });\n worker.once('error', (error: unknown) => {\n failure = error instanceof Error ? error : new Error('Schema generation worker failed.', { cause: error });\n cancel();\n });\n worker.once('exit', (code) => {\n signal.removeEventListener('abort', cancel);\n if (signal.aborted) reject(new DOMException('Schema generation aborted.', 'AbortError'));\n else if (failure) reject(failure);\n else if (!result)\n reject(new Error(`Schema generation worker exited before reporting completion (code ${code}).`));\n else if (result.success) {\n resolve();\n } else {\n reject(result.error);\n }\n });\n });\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Plugin } from 'rolldown';
|
|
2
|
+
import type { GenerateOptions } from '../index.mjs';
|
|
3
|
+
/**
|
|
4
|
+
* Schema authoring inputs and generation policies for the Rolldown adapter.
|
|
5
|
+
*/
|
|
6
|
+
export interface JsonSchemaAotOptions extends Omit<GenerateOptions, 'promote'> {
|
|
7
|
+
entry: string | URL;
|
|
8
|
+
exportName?: string;
|
|
9
|
+
tsconfig?: string;
|
|
10
|
+
watchFiles?: (string | URL)[];
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generate schema artifacts before other build-start hooks and module loading.
|
|
15
|
+
* Use one plugin instance per output directory; do not run independent writers.
|
|
16
|
+
*/
|
|
17
|
+
export declare function jsonSchemaAot({ entry, exportName, tsconfig, watchFiles, signal: externalSignal, ...options }: JsonSchemaAotOptions): Plugin;
|
|
18
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/rolldown/index.mts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAWpD;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC;IAC5E,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,MAAM,GAAG,GAAG,CAAC,EAAE,CAAC;IAC9B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAMD;;;GAGG;AACH,wBAAgB,aAAa,CAAC,EAC5B,KAAK,EACL,UAAU,EACV,QAAQ,EACR,UAAe,EACf,MAAM,EAAE,cAAc,EACtB,GAAG,OAAO,EACX,EAAE,oBAAoB,GAAG,MAAM,CA+J/B"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
/* eslint unicorn/no-this-outside-of-class: off -- Rolldown supplies plugin hook contexts. */
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { mkdir, mkdtemp, readFile, rm } from 'node:fs/promises';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { rolldown } from 'rolldown';
|
|
7
|
+
import { DirectoryRecoveryError } from '../replace-directory.mjs';
|
|
8
|
+
import { authoringInputs } from './authoring-inputs.mjs';
|
|
9
|
+
import { assertSafeDirectories } from './directories.mjs';
|
|
10
|
+
import { generateInWorker } from './generate.mjs';
|
|
11
|
+
import { artifactManifest, areArtifactsCurrent, digest, isInsideDirectory } from './inputs.mjs';
|
|
12
|
+
import { authoringNodeOptions } from './node-options.mjs';
|
|
13
|
+
import { publishArtifacts } from './publish.mjs';
|
|
14
|
+
import { resolutionInputs } from './resolution.mjs';
|
|
15
|
+
function filename(value) {
|
|
16
|
+
return value instanceof URL ? fileURLToPath(value) : path.resolve(value);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Generate schema artifacts before other build-start hooks and module loading.
|
|
20
|
+
* Use one plugin instance per output directory; do not run independent writers.
|
|
21
|
+
*/
|
|
22
|
+
export function jsonSchemaAot({ entry, exportName, tsconfig, watchFiles = [], signal: externalSignal, ...options }) {
|
|
23
|
+
const input = filename(entry);
|
|
24
|
+
const outputDirectory = filename(options.outputDirectory);
|
|
25
|
+
const temporaryDirectory = filename(options.temporaryDirectory);
|
|
26
|
+
const extraInputs = [...watchFiles.map((file) => filename(file)), ...(tsconfig ? [filename(tsconfig)] : [])];
|
|
27
|
+
let fingerprint;
|
|
28
|
+
let manifest;
|
|
29
|
+
let pending = Promise.resolve();
|
|
30
|
+
const shutdown = new AbortController();
|
|
31
|
+
const signal = externalSignal ? AbortSignal.any([externalSignal, shutdown.signal]) : shutdown.signal;
|
|
32
|
+
return {
|
|
33
|
+
name: 'json-schema-aot',
|
|
34
|
+
buildStart: {
|
|
35
|
+
order: 'pre',
|
|
36
|
+
sequential: true,
|
|
37
|
+
async handler(buildOptions) {
|
|
38
|
+
const hostEntries = Object.values(buildOptions.input)
|
|
39
|
+
.filter((file) => !file.includes('\0'))
|
|
40
|
+
.map((file) => path.resolve(buildOptions.cwd, file));
|
|
41
|
+
const knownInputs = [input, ...hostEntries, ...extraInputs];
|
|
42
|
+
const attempt = async () => {
|
|
43
|
+
signal.throwIfAborted();
|
|
44
|
+
const nodeOptions = authoringNodeOptions(process.execArgv, process.env.NODE_OPTIONS);
|
|
45
|
+
await assertSafeDirectories(outputDirectory, temporaryDirectory, knownInputs);
|
|
46
|
+
this.addWatchFile(input);
|
|
47
|
+
for (const file of extraInputs)
|
|
48
|
+
this.addWatchFile(file);
|
|
49
|
+
const watchInput = (id) => this.addWatchFile(id);
|
|
50
|
+
const inputs = authoringInputs(watchInput);
|
|
51
|
+
for (const file of extraInputs)
|
|
52
|
+
inputs.snapshot(file, await readFile(file));
|
|
53
|
+
await mkdir(temporaryDirectory, { recursive: true });
|
|
54
|
+
const work = await mkdtemp(path.join(temporaryDirectory, 'schema-entry-'));
|
|
55
|
+
let bundle;
|
|
56
|
+
let isPreserveWork = false;
|
|
57
|
+
try {
|
|
58
|
+
const metadata = resolutionInputs(inputs.snapshot, watchInput, tsconfig ? filename(tsconfig) : undefined);
|
|
59
|
+
bundle = await rolldown({
|
|
60
|
+
input,
|
|
61
|
+
platform: 'node',
|
|
62
|
+
// Expose aliases for ownership/watch checks, then canonicalize below
|
|
63
|
+
// to retain normal module identity and relative-import semantics.
|
|
64
|
+
resolve: { symlinks: false, conditionNames: nodeOptions.conditions },
|
|
65
|
+
tsconfig,
|
|
66
|
+
onLog(level, log, handler) {
|
|
67
|
+
if (log.code === 'UNRESOLVED_IMPORT')
|
|
68
|
+
throw new Error(log.message);
|
|
69
|
+
handler(level, log);
|
|
70
|
+
},
|
|
71
|
+
plugins: [
|
|
72
|
+
{
|
|
73
|
+
name: 'json-schema-aot:inputs',
|
|
74
|
+
async resolveId(source, importer, resolveOptions) {
|
|
75
|
+
await metadata.beforeResolve(source, importer);
|
|
76
|
+
const resolved = await this.resolve(source, importer, { ...resolveOptions, skipSelf: true });
|
|
77
|
+
if (resolved && !resolved.external && path.isAbsolute(resolved.id)) {
|
|
78
|
+
const canonical = await inputs.resolveFile(resolved.id);
|
|
79
|
+
await metadata.resolved(resolved.id, resolved.packageJsonPath);
|
|
80
|
+
if (canonical !== resolved.id)
|
|
81
|
+
await metadata.resolved(canonical);
|
|
82
|
+
return { ...resolved, id: canonical };
|
|
83
|
+
}
|
|
84
|
+
return resolved;
|
|
85
|
+
},
|
|
86
|
+
load: async (id) => {
|
|
87
|
+
// Register before parsing so syntax errors remain recoverable in watch mode.
|
|
88
|
+
if (!path.isAbsolute(id)) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
watchInput(id);
|
|
92
|
+
const source = await readFile(id);
|
|
93
|
+
inputs.snapshot(id, source);
|
|
94
|
+
// Compile the bytes that were snapshotted, not a second filesystem read.
|
|
95
|
+
return { code: source.toString('utf8') };
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
});
|
|
100
|
+
const result = await bundle.write({
|
|
101
|
+
file: path.join(work, 'schemas.mjs'),
|
|
102
|
+
format: 'esm',
|
|
103
|
+
codeSplitting: false,
|
|
104
|
+
});
|
|
105
|
+
const hash = createHash('sha256');
|
|
106
|
+
hash.update(JSON.stringify(nodeOptions.conditions));
|
|
107
|
+
for (const item of result.output)
|
|
108
|
+
hash.update(JSON.stringify([item.fileName, digest(item.type === 'chunk' ? item.code : item.source)]));
|
|
109
|
+
for (const file of extraInputs)
|
|
110
|
+
hash.update(JSON.stringify([file, inputs.contents.get(file)]));
|
|
111
|
+
// eslint-disable-next-line unicorn/no-array-sort -- The package targets ES2022 libraries.
|
|
112
|
+
const metadataFiles = [...metadata.files].sort((left, right) => left.localeCompare(right));
|
|
113
|
+
for (const file of metadataFiles)
|
|
114
|
+
hash.update(JSON.stringify([file, inputs.contents.get(file)]));
|
|
115
|
+
if (!(await inputs.areCurrent()))
|
|
116
|
+
return { inputs, retry: true };
|
|
117
|
+
await assertSafeDirectories(outputDirectory, temporaryDirectory, [...knownInputs, ...inputs.paths()]);
|
|
118
|
+
const next = hash.digest('hex');
|
|
119
|
+
if (next !== fingerprint || !(await areArtifactsCurrent(outputDirectory, manifest))) {
|
|
120
|
+
const prepared = path.join(work, 'prepared');
|
|
121
|
+
await generateInWorker(path.join(work, 'schemas.mjs'), exportName, {
|
|
122
|
+
...options,
|
|
123
|
+
outputDirectory: prepared,
|
|
124
|
+
temporaryDirectory: path.join(work, 'temporary'),
|
|
125
|
+
}, signal, nodeOptions.execArgv);
|
|
126
|
+
if (!(await inputs.areCurrent()))
|
|
127
|
+
return { inputs, retry: true };
|
|
128
|
+
const nextManifest = await artifactManifest(prepared);
|
|
129
|
+
// Only the parent promotes live outputs. Cancellation can safely terminate staging workers.
|
|
130
|
+
const publication = await publishArtifacts({ prepared, output: outputDirectory, backup: path.join(work, 'previous') }, temporaryDirectory, [...knownInputs, ...inputs.paths()], { signal, areInputsCurrent: inputs.areCurrent });
|
|
131
|
+
if (publication === 'retry')
|
|
132
|
+
return { inputs, retry: true };
|
|
133
|
+
manifest = nextManifest;
|
|
134
|
+
fingerprint = next;
|
|
135
|
+
return { inputs, retry: false };
|
|
136
|
+
}
|
|
137
|
+
return { inputs, retry: false };
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
isPreserveWork = error instanceof DirectoryRecoveryError;
|
|
141
|
+
if (!isPreserveWork && !signal.aborted && !(await inputs.areCurrent()))
|
|
142
|
+
return { inputs, retry: true };
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
finally {
|
|
146
|
+
await bundle?.close();
|
|
147
|
+
if (!isPreserveWork)
|
|
148
|
+
await rm(work, { recursive: true, force: true });
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const previous = pending;
|
|
152
|
+
let release;
|
|
153
|
+
// eslint-disable-next-line unicorn/prefer-promise-with-resolvers -- The package targets ES2022 libraries.
|
|
154
|
+
pending = new Promise((resolve) => {
|
|
155
|
+
release = resolve;
|
|
156
|
+
});
|
|
157
|
+
await previous;
|
|
158
|
+
try {
|
|
159
|
+
while (true) {
|
|
160
|
+
const result = await attempt();
|
|
161
|
+
// Native watch inputs may not be active during the first build.
|
|
162
|
+
// Verify snapshots before consumers can load artifacts, retrying edits made during generation.
|
|
163
|
+
if (!result.retry && (await result.inputs.areCurrent()))
|
|
164
|
+
break;
|
|
165
|
+
}
|
|
166
|
+
signal.throwIfAborted();
|
|
167
|
+
// Another output configuration may have promoted artifacts while this build was queued.
|
|
168
|
+
// Each consumer graph must invalidate its own cached modules even on a generation cache hit.
|
|
169
|
+
for (const id of this.getModuleIds()) {
|
|
170
|
+
if (isInsideDirectory(outputDirectory, id))
|
|
171
|
+
await this.load({ id, invalidate: true });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
release();
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
},
|
|
179
|
+
async closeWatcher() {
|
|
180
|
+
shutdown.abort();
|
|
181
|
+
await pending;
|
|
182
|
+
},
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
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AM,QAAQ,GAAG,OAAO,CAAC;gBACzB,IAAI,OAAoB,CAAC;gBACzB,0GAA0G;gBAC1G,OAAO,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;oBACtC,OAAO,GAAG,OAAO,CAAC;gBACpB,CAAC,CAAC,CAAC;gBACH,MAAM,QAAQ,CAAC;gBACf,IAAI,CAAC;oBACH,OAAO,IAAI,EAAE,CAAC;wBACZ,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,CAAC;wBAC/B,gEAAgE;wBAChE,+FAA+F;wBAC/F,IAAI,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,MAAM,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC;4BAAE,MAAM;oBACjE,CAAC;oBACD,MAAM,CAAC,cAAc,EAAE,CAAC;oBACxB,wFAAwF;oBACxF,6FAA6F;oBAC7F,KAAK,MAAM,EAAE,IAAI,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;wBACrC,IAAI,iBAAiB,CAAC,eAAe,EAAE,EAAE,CAAC;4BAAE,MAAM,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;oBACxF,CAAC;gBACH,CAAC;wBAAS,CAAC;oBACT,OAAO,EAAE,CAAC;gBACZ,CAAC;YACH,CAAC;SACF;QACD,KAAK,CAAC,YAAY;YAChB,QAAQ,CAAC,KAAK,EAAE,CAAC;YACjB,MAAM,OAAO,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["/* eslint unicorn/no-this-outside-of-class: off -- Rolldown supplies plugin hook contexts. */\nimport { createHash } from 'node:crypto';\nimport { mkdir, mkdtemp, readFile, rm } from 'node:fs/promises';\nimport path from 'node:path';\nimport { fileURLToPath } from 'node:url';\nimport { rolldown } from 'rolldown';\nimport type { Plugin } from 'rolldown';\n\nimport type { GenerateOptions } from '../index.mjs';\nimport { DirectoryRecoveryError } from '../replace-directory.mjs';\n\nimport { authoringInputs } from './authoring-inputs.mjs';\nimport { assertSafeDirectories } from './directories.mjs';\nimport { generateInWorker } from './generate.mjs';\nimport { artifactManifest, areArtifactsCurrent, digest, isInsideDirectory } from './inputs.mjs';\nimport { authoringNodeOptions } from './node-options.mjs';\nimport { publishArtifacts } from './publish.mjs';\nimport { resolutionInputs } from './resolution.mjs';\n\n/**\n * Schema authoring inputs and generation policies for the Rolldown adapter.\n */\nexport interface JsonSchemaAotOptions extends Omit<GenerateOptions, 'promote'> {\n entry: string | URL;\n exportName?: string;\n tsconfig?: string;\n watchFiles?: (string | URL)[];\n signal?: AbortSignal;\n}\n\nfunction filename(value: string | URL): string {\n return value instanceof URL ? fileURLToPath(value) : path.resolve(value);\n}\n\n/**\n * Generate schema artifacts before other build-start hooks and module loading.\n * Use one plugin instance per output directory; do not run independent writers.\n */\nexport function jsonSchemaAot({\n entry,\n exportName,\n tsconfig,\n watchFiles = [],\n signal: externalSignal,\n ...options\n}: JsonSchemaAotOptions): Plugin {\n const input = filename(entry);\n const outputDirectory = filename(options.outputDirectory);\n const temporaryDirectory = filename(options.temporaryDirectory);\n const extraInputs = [...watchFiles.map((file) => filename(file)), ...(tsconfig ? [filename(tsconfig)] : [])];\n let fingerprint: string | undefined;\n let manifest: Map<string, string> | undefined;\n let pending = Promise.resolve();\n const shutdown = new AbortController();\n const signal = externalSignal ? AbortSignal.any([externalSignal, shutdown.signal]) : shutdown.signal;\n\n return {\n name: 'json-schema-aot',\n buildStart: {\n order: 'pre',\n sequential: true,\n async handler(buildOptions) {\n const hostEntries = Object.values(buildOptions.input)\n .filter((file) => !file.includes('\\0'))\n .map((file) => path.resolve(buildOptions.cwd, file));\n const knownInputs = [input, ...hostEntries, ...extraInputs];\n const attempt = async (): Promise<{ inputs: ReturnType<typeof authoringInputs>; retry: boolean }> => {\n signal.throwIfAborted();\n const nodeOptions = authoringNodeOptions(process.execArgv, process.env.NODE_OPTIONS);\n await assertSafeDirectories(outputDirectory, temporaryDirectory, knownInputs);\n this.addWatchFile(input);\n for (const file of extraInputs) this.addWatchFile(file);\n const watchInput = (id: string) => this.addWatchFile(id);\n const inputs = authoringInputs(watchInput);\n for (const file of extraInputs) inputs.snapshot(file, await readFile(file));\n await mkdir(temporaryDirectory, { recursive: true });\n const work = await mkdtemp(path.join(temporaryDirectory, 'schema-entry-'));\n let bundle: Awaited<ReturnType<typeof rolldown>> | undefined;\n let isPreserveWork = false;\n try {\n const metadata = resolutionInputs(inputs.snapshot, watchInput, tsconfig ? filename(tsconfig) : undefined);\n bundle = await rolldown({\n input,\n platform: 'node',\n // Expose aliases for ownership/watch checks, then canonicalize below\n // to retain normal module identity and relative-import semantics.\n resolve: { symlinks: false, conditionNames: nodeOptions.conditions },\n tsconfig,\n onLog(level, log, handler) {\n if (log.code === 'UNRESOLVED_IMPORT') throw new Error(log.message);\n handler(level, log);\n },\n plugins: [\n {\n name: 'json-schema-aot:inputs',\n async resolveId(source, importer, resolveOptions) {\n await metadata.beforeResolve(source, importer);\n const resolved = await this.resolve(source, importer, { ...resolveOptions, skipSelf: true });\n if (resolved && !resolved.external && path.isAbsolute(resolved.id)) {\n const canonical = await inputs.resolveFile(resolved.id);\n await metadata.resolved(resolved.id, resolved.packageJsonPath);\n if (canonical !== resolved.id) await metadata.resolved(canonical);\n return { ...resolved, id: canonical };\n }\n return resolved;\n },\n load: async (id) => {\n // Register before parsing so syntax errors remain recoverable in watch mode.\n if (!path.isAbsolute(id)) {\n return;\n }\n\n watchInput(id);\n const source = await readFile(id);\n inputs.snapshot(id, source);\n // Compile the bytes that were snapshotted, not a second filesystem read.\n return { code: source.toString('utf8') };\n },\n },\n ],\n });\n const result = await bundle.write({\n file: path.join(work, 'schemas.mjs'),\n format: 'esm',\n codeSplitting: false,\n });\n const hash = createHash('sha256');\n hash.update(JSON.stringify(nodeOptions.conditions));\n for (const item of result.output)\n hash.update(JSON.stringify([item.fileName, digest(item.type === 'chunk' ? item.code : item.source)]));\n for (const file of extraInputs) hash.update(JSON.stringify([file, inputs.contents.get(file)]));\n // eslint-disable-next-line unicorn/no-array-sort -- The package targets ES2022 libraries.\n const metadataFiles = [...metadata.files].sort((left, right) => left.localeCompare(right));\n for (const file of metadataFiles) hash.update(JSON.stringify([file, inputs.contents.get(file)]));\n if (!(await inputs.areCurrent())) return { inputs, retry: true };\n await assertSafeDirectories(outputDirectory, temporaryDirectory, [...knownInputs, ...inputs.paths()]);\n const next = hash.digest('hex');\n if (next !== fingerprint || !(await areArtifactsCurrent(outputDirectory, manifest))) {\n const prepared = path.join(work, 'prepared');\n await generateInWorker(\n path.join(work, 'schemas.mjs'),\n exportName,\n {\n ...options,\n outputDirectory: prepared,\n temporaryDirectory: path.join(work, 'temporary'),\n },\n signal,\n nodeOptions.execArgv,\n );\n if (!(await inputs.areCurrent())) return { inputs, retry: true };\n const nextManifest = await artifactManifest(prepared);\n // Only the parent promotes live outputs. Cancellation can safely terminate staging workers.\n const publication = await publishArtifacts(\n { prepared, output: outputDirectory, backup: path.join(work, 'previous') },\n temporaryDirectory,\n [...knownInputs, ...inputs.paths()],\n { signal, areInputsCurrent: inputs.areCurrent },\n );\n if (publication === 'retry') return { inputs, retry: true };\n manifest = nextManifest;\n fingerprint = next;\n return { inputs, retry: false };\n }\n return { inputs, retry: false };\n } catch (error) {\n isPreserveWork = error instanceof DirectoryRecoveryError;\n if (!isPreserveWork && !signal.aborted && !(await inputs.areCurrent())) return { inputs, retry: true };\n throw error;\n } finally {\n await bundle?.close();\n if (!isPreserveWork) await rm(work, { recursive: true, force: true });\n }\n };\n const previous = pending;\n let release!: () => void;\n // eslint-disable-next-line unicorn/prefer-promise-with-resolvers -- The package targets ES2022 libraries.\n pending = new Promise<void>((resolve) => {\n release = resolve;\n });\n await previous;\n try {\n while (true) {\n const result = await attempt();\n // Native watch inputs may not be active during the first build.\n // Verify snapshots before consumers can load artifacts, retrying edits made during generation.\n if (!result.retry && (await result.inputs.areCurrent())) break;\n }\n signal.throwIfAborted();\n // Another output configuration may have promoted artifacts while this build was queued.\n // Each consumer graph must invalidate its own cached modules even on a generation cache hit.\n for (const id of this.getModuleIds()) {\n if (isInsideDirectory(outputDirectory, id)) await this.load({ id, invalidate: true });\n }\n } finally {\n release();\n }\n },\n },\n async closeWatcher() {\n shutdown.abort();\n await pending;\n },\n };\n}\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
export declare function digest(value: string | Uint8Array): string;
|
|
3
|
+
export declare function areInputsCurrent(inputs: ReadonlyMap<string, string>): Promise<boolean>;
|
|
4
|
+
export declare function artifactManifest(directory: string): Promise<Map<string, string>>;
|
|
5
|
+
export declare function areArtifactsCurrent(directory: string, expected: ReadonlyMap<string, string> | undefined): Promise<boolean>;
|
|
6
|
+
export declare function isInsideDirectory(directory: string, file: string, implementation?: Pick<typeof path, 'relative' | 'isAbsolute' | 'sep'>): boolean;
|
|
7
|
+
//# sourceMappingURL=inputs.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.d.mts","sourceRoot":"","sources":["../../src/rolldown/inputs.mts"],"names":[],"mappings":"AAEA,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,GAAG,MAAM,CAEzD;AAMD,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAU5F;AAED,wBAAsB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAetF;AAED,wBAAsB,mBAAmB,CACvC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS,GAChD,OAAO,CAAC,OAAO,CAAC,CASlB;AAED,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,IAAI,CAAC,OAAO,IAAI,EAAE,UAAU,GAAG,YAAY,GAAG,KAAK,CAAQ,GAC1E,OAAO,CAST"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { readFile, readdir } from 'node:fs/promises';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export function digest(value) {
|
|
5
|
+
return createHash('sha256').update(value).digest('hex');
|
|
6
|
+
}
|
|
7
|
+
function isMissing(error) {
|
|
8
|
+
return error instanceof Error && 'code' in error && ['ENOENT', 'ENOTDIR'].includes(String(error.code));
|
|
9
|
+
}
|
|
10
|
+
export async function areInputsCurrent(inputs) {
|
|
11
|
+
try {
|
|
12
|
+
for (const [file, expected] of inputs) {
|
|
13
|
+
if (digest(await readFile(file)) !== expected)
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (isMissing(error))
|
|
20
|
+
return false;
|
|
21
|
+
throw error;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function artifactManifest(directory) {
|
|
25
|
+
const result = new Map();
|
|
26
|
+
async function visit(relative) {
|
|
27
|
+
const entries = await readdir(path.join(directory, relative), { withFileTypes: true });
|
|
28
|
+
for (const entry of entries) {
|
|
29
|
+
const name = path.join(relative, entry.name);
|
|
30
|
+
if (entry.isDirectory())
|
|
31
|
+
await visit(name);
|
|
32
|
+
else if (entry.isFile()) {
|
|
33
|
+
const contents = await readFile(path.join(directory, name));
|
|
34
|
+
result.set(name, digest(contents));
|
|
35
|
+
}
|
|
36
|
+
else
|
|
37
|
+
result.set(name, 'unsupported-entry');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
await visit('');
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
export async function areArtifactsCurrent(directory, expected) {
|
|
44
|
+
if (!expected)
|
|
45
|
+
return false;
|
|
46
|
+
try {
|
|
47
|
+
const actual = await artifactManifest(directory);
|
|
48
|
+
return actual.size === expected.size && [...expected].every(([file, hash]) => actual.get(file) === hash);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (isMissing(error))
|
|
52
|
+
return false;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export function isInsideDirectory(directory, file, implementation = path) {
|
|
57
|
+
if (!implementation.isAbsolute(file))
|
|
58
|
+
return false;
|
|
59
|
+
const relative = implementation.relative(directory, file);
|
|
60
|
+
return (relative.length > 0 &&
|
|
61
|
+
relative !== '..' &&
|
|
62
|
+
!relative.startsWith(`..${implementation.sep}`) &&
|
|
63
|
+
!implementation.isAbsolute(relative));
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=inputs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.mjs","sourceRoot":"","sources":["../../src/rolldown/inputs.mts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,MAAM,UAAU,MAAM,CAAC,KAA0B;IAC/C,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,SAAS,CAAC,KAAc;IAC/B,OAAO,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AACzG,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAmC;IACxE,IAAI,CAAC;Q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ChB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,SAAiB,EACjB,QAAiD;IAEjD,IAAI,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAC5B,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,gBAAgB,CAAC,SAAS,CAAC,CAAC;QACjD,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC;IAC3G,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,SAAS,CAAC,KAAK,CAAC;YAAE,OAAO,KAAK,CAAC;QACnC,MAAM,KAAK,CAAC;IACd,CAAC;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,SAAiB,EACjB,IAAY,EACZ,iBAAuE,IAAI;IAE3E,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC;IACnD,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IAC1D,OAAO,CACL,QAAQ,CAAC,MAAM,GAAG,CAAC;QACnB,QAAQ,KAAK,IAAI;QACjB,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,cAAc,CAAC,GAAG,EAAE,CAAC;QAC/C,CAAC,cAAc,CAAC,UAAU,CAAC,QAAQ,CAAC,CACrC,CAAC;AACJ,CAAC","sourcesContent":["import { createHash } from 'node:crypto';\nimport { readFile, readdir } from 'node:fs/promises';\nimport path from 'node:path';\n\nexport function digest(value: string | Uint8Array): string {\n return createHash('sha256').update(value).digest('hex');\n}\n\nfunction isMissing(error: unknown): boolean {\n return error instanceof Error && 'code' in error && ['ENOENT', 'ENOTDIR'].includes(String(error.code));\n}\n\nexport async function areInputsCurrent(inputs: ReadonlyMap<string, string>): Promise<boolean> {\n try {\n for (const [file, expected] of inputs) {\n if (digest(await readFile(file)) !== expected) return false;\n }\n return true;\n } catch (error) {\n if (isMissing(error)) return false;\n throw error;\n }\n}\n\nexport async function artifactManifest(directory: string): Promise<Map<string, string>> {\n const result = new Map<string, string>();\n async function visit(relative: string): Promise<void> {\n const entries = await readdir(path.join(directory, relative), { withFileTypes: true });\n for (const entry of entries) {\n const name = path.join(relative, entry.name);\n if (entry.isDirectory()) await visit(name);\n else if (entry.isFile()) {\n const contents = await readFile(path.join(directory, name));\n result.set(name, digest(contents));\n } else result.set(name, 'unsupported-entry');\n }\n }\n await visit('');\n return result;\n}\n\nexport async function areArtifactsCurrent(\n directory: string,\n expected: ReadonlyMap<string, string> | undefined,\n): Promise<boolean> {\n if (!expected) return false;\n try {\n const actual = await artifactManifest(directory);\n return actual.size === expected.size && [...expected].every(([file, hash]) => actual.get(file) === hash);\n } catch (error) {\n if (isMissing(error)) return false;\n throw error;\n }\n}\n\nexport function isInsideDirectory(\n directory: string,\n file: string,\n implementation: Pick<typeof path, 'relative' | 'isAbsolute' | 'sep'> = path,\n): boolean {\n if (!implementation.isAbsolute(file)) return false;\n const relative = implementation.relative(directory, file);\n return (\n relative.length > 0 &&\n relative !== '..' &&\n !relative.startsWith(`..${implementation.sep}`) &&\n !implementation.isAbsolute(relative)\n );\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function workerExecArgv(arguments_: readonly string[]): string[];
|
|
2
|
+
/**
|
|
3
|
+
* Use the same custom conditions for static authoring resolution and fresh workers.
|
|
4
|
+
* NODE_OPTIONS is not included in process.execArgv; do not replay its preloads.
|
|
5
|
+
*/
|
|
6
|
+
export declare function authoringNodeOptions(arguments_: readonly string[], nodeOptions?: string): {
|
|
7
|
+
conditions: string[];
|
|
8
|
+
execArgv: string[];
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=node-options.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-options.d.mts","sourceRoot":"","sources":["../../src/rolldown/node-options.mts"],"names":[],"mappings":"AAmEA,wBAAgB,cAAc,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,EAAE,CAEtE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,EAAE,WAAW,SAAK;;;EAQnF"}
|