toiljs 0.0.136 → 0.0.137
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/CHANGELOG.md +9 -0
- package/build/compiler/compiler-build.d.ts +9 -0
- package/build/compiler/compiler-build.js +177 -0
- package/build/compiler/compiler-cache.d.ts +28 -0
- package/build/compiler/compiler-cache.js +114 -0
- package/build/compiler/compiler-lock.d.ts +1 -0
- package/build/compiler/compiler-lock.js +99 -0
- package/build/compiler/emails.js +2 -3
- package/build/compiler/index.js +70 -40
- package/build/compiler/prerender.d.ts +1 -0
- package/build/compiler/prerender.js +55 -0
- package/build/compiler/ssg.js +5 -2
- package/build/compiler/template-build.js +10 -10
- package/build/compiler/toil-docs.generated.js +1 -1
- package/build/compiler/toilscript-worker.d.ts +1 -0
- package/build/compiler/toilscript-worker.js +78 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [v0.0.137] - 2026-10-27
|
|
4
|
+
|
|
5
|
+
- Compile request, stream, and daemon tiers in bounded parallel processes, dividing Binaryen's CPU budget among active jobs while preserving configured optimization levels and assertions.
|
|
6
|
+
- Reuse unchanged server tiers after checking actual dependency contents, failed import lookups, library listings, compiler implementation, options, and output hashes. Keep dependency manifests in `.toil/compiler` without duplicating compiled artifacts.
|
|
7
|
+
- Stage and validate tier outputs before publishing, isolate WAT, maps, bindings, and editor declarations, drain workers after failures or cancellation, and serialize complete builds of the same project across processes.
|
|
8
|
+
- Skip SSR/SSG module evaluation for routes with no matching exports and skip generic email rendering when every template is an auth override. Preserve re-exported and dynamic rendering opt-ins.
|
|
9
|
+
- Add `TOILJS_BUILD_CACHE=0` for forced recompilation and `TOILJS_BUILD_JOBS` to limit concurrent compiler jobs. Custom transforms and extended compiler configs keep serial, uncached CLI behavior.
|
|
10
|
+
- On `/root/nerva-ui`, full recompilation improved from 28.6 seconds to 13.7 seconds and builds with unchanged server inputs took 2.6 seconds. All three Wasm artifacts were identical across full, cached, and forced-recompile runs. Validation includes 796 passing tests, framework build, typecheck, and lint.
|
|
11
|
+
|
|
3
12
|
## [v0.0.136] - 2026-10-27
|
|
4
13
|
|
|
5
14
|
- Enable application server logging by default in development and keep production logs disabled unless `server.logging: true` is configured. Compile the policy into request, stream, and daemon Wasm artifacts, including edge deployments; rebuild after changing it.
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface CompilerPass {
|
|
2
|
+
readonly name: string;
|
|
3
|
+
readonly args: readonly string[];
|
|
4
|
+
}
|
|
5
|
+
export interface CompilerBuildOptions {
|
|
6
|
+
readonly signal?: AbortSignal;
|
|
7
|
+
readonly validate?: (readOutput: (file: string) => Buffer) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function runCompilerPasses(root: string, bin: string, passes: readonly CompilerPass[], finalize: () => void, options?: CompilerBuildOptions): Promise<void>;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import { availableParallelism } from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { compilerFingerprint, digest, fileDigest, inputsCurrent, outputsCurrent, readCompilerManifest, standardCompilerConfig, } from './compiler-cache.js';
|
|
7
|
+
function runProcess(root, args, name, signal, cores) {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
let failure;
|
|
10
|
+
const child = spawn(process.execPath, ['--enable-source-maps', ...args], {
|
|
11
|
+
cwd: root,
|
|
12
|
+
stdio: 'inherit',
|
|
13
|
+
signal,
|
|
14
|
+
env: { ...process.env, BINARYEN_CORES: process.env.BINARYEN_CORES ?? String(cores) },
|
|
15
|
+
});
|
|
16
|
+
child.on('error', (error) => {
|
|
17
|
+
failure = error;
|
|
18
|
+
if (child.pid === undefined)
|
|
19
|
+
reject(error);
|
|
20
|
+
});
|
|
21
|
+
child.on('close', (code) => code === 0 && !failure
|
|
22
|
+
? resolve()
|
|
23
|
+
: reject(failure ??
|
|
24
|
+
new Error(`toilscript ${name} build failed (exit ${String(code)})`)));
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function publish(staged, destination) {
|
|
28
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true });
|
|
29
|
+
try {
|
|
30
|
+
fs.renameSync(staged, destination);
|
|
31
|
+
}
|
|
32
|
+
catch (error) {
|
|
33
|
+
if (error.code !== 'EXDEV')
|
|
34
|
+
throw error;
|
|
35
|
+
const temporary = destination + `.toil-${process.pid}.tmp`;
|
|
36
|
+
try {
|
|
37
|
+
fs.copyFileSync(staged, temporary);
|
|
38
|
+
fs.renameSync(temporary, destination);
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
fs.rmSync(temporary, { force: true });
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
export async function runCompilerPasses(root, bin, passes, finalize, options = {}) {
|
|
46
|
+
const home = path.join(root, '.toil', 'compiler');
|
|
47
|
+
fs.mkdirSync(home, { recursive: true });
|
|
48
|
+
const work = fs.mkdtempSync(path.join(home, `pending-${process.pid}-`));
|
|
49
|
+
const builtWorker = fileURLToPath(new URL('./toilscript-worker.js', import.meta.url));
|
|
50
|
+
const worker = fs.existsSync(builtWorker) ? builtWorker : builtWorker.replace(/\.js$/, '.ts');
|
|
51
|
+
const standard = standardCompilerConfig(root);
|
|
52
|
+
const cacheable = standard && process.env.TOILJS_BUILD_CACHE !== '0';
|
|
53
|
+
const requested = Number(process.env.TOILJS_BUILD_JOBS ?? 3);
|
|
54
|
+
const jobs = Number.isInteger(requested) && requested > 0 ? requested : 3;
|
|
55
|
+
const cpus = availableParallelism();
|
|
56
|
+
const abort = new AbortController();
|
|
57
|
+
const cancel = () => abort.abort();
|
|
58
|
+
options.signal?.addEventListener('abort', cancel, { once: true });
|
|
59
|
+
if (options.signal?.aborted)
|
|
60
|
+
abort.abort();
|
|
61
|
+
const stop = () => {
|
|
62
|
+
process.exitCode = 130;
|
|
63
|
+
abort.abort();
|
|
64
|
+
};
|
|
65
|
+
process.once('SIGINT', stop);
|
|
66
|
+
process.once('SIGTERM', stop);
|
|
67
|
+
const completed = [];
|
|
68
|
+
let firstFailure;
|
|
69
|
+
let index = 0;
|
|
70
|
+
try {
|
|
71
|
+
if (!standard) {
|
|
72
|
+
for (const pass of passes)
|
|
73
|
+
await runProcess(root, [bin, ...pass.args], pass.name, abort.signal, cpus);
|
|
74
|
+
options.validate?.((file) => fs.readFileSync(path.resolve(root, file)));
|
|
75
|
+
finalize();
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const fingerprint = cacheable ? compilerFingerprint(bin, worker) : '';
|
|
79
|
+
const plans = passes.map((pass) => {
|
|
80
|
+
const cache = path.join(home, `${pass.name}.json`);
|
|
81
|
+
const key = digest(JSON.stringify({ version: 1, root, fingerprint, args: pass.args }));
|
|
82
|
+
const saved = cacheable ? readCompilerManifest(cache) : null;
|
|
83
|
+
const cached = saved?.key === key && inputsCurrent(saved) && outputsCurrent(saved) ? saved : null;
|
|
84
|
+
return { pass, cache, key, cached };
|
|
85
|
+
});
|
|
86
|
+
const concurrency = Math.max(1, Math.min(plans.filter((plan) => !plan.cached).length, 3, cpus, jobs));
|
|
87
|
+
const cores = Math.max(1, Math.floor(cpus / concurrency));
|
|
88
|
+
const run = async () => {
|
|
89
|
+
while (index < plans.length && !abort.signal.aborted) {
|
|
90
|
+
const { pass, cache, key, cached } = plans[index++];
|
|
91
|
+
if (cached) {
|
|
92
|
+
completed.push({ pass, manifest: cached, cache, key, reused: true });
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const staging = path.join(work, pass.name);
|
|
96
|
+
try {
|
|
97
|
+
fs.mkdirSync(staging);
|
|
98
|
+
await runProcess(root, [worker, bin, staging, ...pass.args], pass.name, abort.signal, cores);
|
|
99
|
+
const manifest = readCompilerManifest(path.join(staging, 'manifest.json'));
|
|
100
|
+
if (!manifest || !inputsCurrent(manifest))
|
|
101
|
+
throw new Error(`Server inputs changed while compiling ${pass.name}; retry the build.`);
|
|
102
|
+
completed.push({ pass, manifest, cache, key, reused: false });
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
if (!abort.signal.aborted)
|
|
106
|
+
firstFailure = { reason: error };
|
|
107
|
+
abort.abort();
|
|
108
|
+
throw error;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
const outcomes = await Promise.allSettled(Array.from({ length: concurrency }, run));
|
|
113
|
+
if (firstFailure)
|
|
114
|
+
throw firstFailure.reason;
|
|
115
|
+
const failed = outcomes.find((result) => result.status === 'rejected');
|
|
116
|
+
if (failed?.status === 'rejected')
|
|
117
|
+
throw failed.reason;
|
|
118
|
+
if (abort.signal.aborted)
|
|
119
|
+
throw new Error('Server build cancelled');
|
|
120
|
+
if (completed.some(({ manifest }) => !inputsCurrent(manifest)))
|
|
121
|
+
throw new Error('Server inputs changed during compilation; retry the build.');
|
|
122
|
+
if (completed.some((result) => result.reused && !outputsCurrent(result.manifest)))
|
|
123
|
+
throw new Error('Server outputs changed during compilation; retry the build.');
|
|
124
|
+
const outputs = new Map();
|
|
125
|
+
for (const pass of passes) {
|
|
126
|
+
const result = completed.find((entry) => entry.pass === pass);
|
|
127
|
+
if (!result)
|
|
128
|
+
throw new Error(`Compiler pass did not finish: ${pass.name}`);
|
|
129
|
+
for (const output of result.manifest.outputs) {
|
|
130
|
+
if (standard && outputs.has(output.path))
|
|
131
|
+
throw new Error(`Compiler tiers share an output path: ${output.path}`);
|
|
132
|
+
outputs.set(output.path, output.staged ?? output.path);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
options.validate?.((file) => fs.readFileSync(outputs.get(path.resolve(root, file)) ?? file));
|
|
136
|
+
for (const pass of passes) {
|
|
137
|
+
const result = completed.find((entry) => entry.pass === pass);
|
|
138
|
+
if (!result)
|
|
139
|
+
throw new Error(`Compiler pass did not finish: ${pass.name}`);
|
|
140
|
+
if (result.reused)
|
|
141
|
+
continue;
|
|
142
|
+
for (const output of result.manifest.outputs) {
|
|
143
|
+
if (!output.staged)
|
|
144
|
+
throw new Error(`Missing staged output: ${output.path}`);
|
|
145
|
+
publish(output.staged, output.path);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
finalize();
|
|
149
|
+
if (cacheable)
|
|
150
|
+
for (const result of completed) {
|
|
151
|
+
if (result.reused)
|
|
152
|
+
continue;
|
|
153
|
+
const manifest = {
|
|
154
|
+
...result.manifest,
|
|
155
|
+
key: result.key,
|
|
156
|
+
outputs: result.manifest.outputs.map((output) => {
|
|
157
|
+
const hash = fileDigest(output.path);
|
|
158
|
+
if (hash === null)
|
|
159
|
+
throw new Error(`Compiler output disappeared: ${output.path}`);
|
|
160
|
+
return { path: output.path, hash };
|
|
161
|
+
}),
|
|
162
|
+
};
|
|
163
|
+
const staged = path.join(work, `${result.pass.name}.json`);
|
|
164
|
+
fs.writeFileSync(staged, JSON.stringify(manifest));
|
|
165
|
+
publish(staged, result.cache);
|
|
166
|
+
}
|
|
167
|
+
const reused = completed.filter((pass) => pass.reused).map((pass) => pass.pass.name);
|
|
168
|
+
if (reused.length > 0)
|
|
169
|
+
process.stdout.write(` ✓ server unchanged: reused ${reused.join(', ')}\n`);
|
|
170
|
+
}
|
|
171
|
+
finally {
|
|
172
|
+
process.off('SIGINT', stop);
|
|
173
|
+
process.off('SIGTERM', stop);
|
|
174
|
+
options.signal?.removeEventListener('abort', cancel);
|
|
175
|
+
fs.rmSync(work, { recursive: true, force: true });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export interface CompilerInput {
|
|
2
|
+
readonly path: string;
|
|
3
|
+
readonly hash: string | null;
|
|
4
|
+
}
|
|
5
|
+
export interface CompilerDirectory {
|
|
6
|
+
readonly path: string;
|
|
7
|
+
readonly entries: readonly string[] | null;
|
|
8
|
+
}
|
|
9
|
+
export interface CompilerOutput {
|
|
10
|
+
readonly path: string;
|
|
11
|
+
readonly hash: string;
|
|
12
|
+
readonly staged?: string;
|
|
13
|
+
}
|
|
14
|
+
export interface CompilerManifest {
|
|
15
|
+
readonly key: string;
|
|
16
|
+
readonly inputs: readonly CompilerInput[];
|
|
17
|
+
readonly directories: readonly CompilerDirectory[];
|
|
18
|
+
readonly outputs: readonly CompilerOutput[];
|
|
19
|
+
readonly stable: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function digest(value: string | Uint8Array): string;
|
|
22
|
+
export declare function fileDigest(file: string): string | null;
|
|
23
|
+
export declare function libraryEntries(dir: string): string[] | null;
|
|
24
|
+
export declare function inputsCurrent(manifest: CompilerManifest): boolean;
|
|
25
|
+
export declare function outputsCurrent(manifest: CompilerManifest): boolean;
|
|
26
|
+
export declare function readCompilerManifest(file: string): CompilerManifest | null;
|
|
27
|
+
export declare function standardCompilerConfig(root: string): boolean;
|
|
28
|
+
export declare function compilerFingerprint(bin: string, worker: string): string;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
export function digest(value) {
|
|
5
|
+
return createHash('sha256').update(value).digest('hex');
|
|
6
|
+
}
|
|
7
|
+
export function fileDigest(file) {
|
|
8
|
+
try {
|
|
9
|
+
return digest(fs.readFileSync(file));
|
|
10
|
+
}
|
|
11
|
+
catch {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function libraryEntries(dir) {
|
|
16
|
+
try {
|
|
17
|
+
return fs
|
|
18
|
+
.readdirSync(dir)
|
|
19
|
+
.filter((name) => name.endsWith('.ts') && !name.endsWith('.d.ts'));
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
export function inputsCurrent(manifest) {
|
|
26
|
+
return (manifest.stable &&
|
|
27
|
+
manifest.inputs.every((input) => fileDigest(input.path) === input.hash) &&
|
|
28
|
+
manifest.directories.every((dir) => JSON.stringify(libraryEntries(dir.path)) === JSON.stringify(dir.entries)));
|
|
29
|
+
}
|
|
30
|
+
export function outputsCurrent(manifest) {
|
|
31
|
+
return (manifest.outputs.length > 0 &&
|
|
32
|
+
manifest.outputs.every((output) => fileDigest(output.path) === output.hash));
|
|
33
|
+
}
|
|
34
|
+
export function readCompilerManifest(file) {
|
|
35
|
+
try {
|
|
36
|
+
const value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
37
|
+
if (typeof value.key !== 'string' ||
|
|
38
|
+
typeof value.stable !== 'boolean' ||
|
|
39
|
+
!Array.isArray(value.inputs) ||
|
|
40
|
+
!Array.isArray(value.directories) ||
|
|
41
|
+
!Array.isArray(value.outputs))
|
|
42
|
+
return null;
|
|
43
|
+
if (!value.inputs.every((entry) => entry &&
|
|
44
|
+
typeof entry.path === 'string' &&
|
|
45
|
+
(entry.hash === null || typeof entry.hash === 'string')))
|
|
46
|
+
return null;
|
|
47
|
+
if (!value.directories.every((entry) => entry &&
|
|
48
|
+
typeof entry.path === 'string' &&
|
|
49
|
+
(entry.entries === null ||
|
|
50
|
+
(Array.isArray(entry.entries) &&
|
|
51
|
+
entry.entries.every((name) => typeof name === 'string')))))
|
|
52
|
+
return null;
|
|
53
|
+
if (!value.outputs.every((entry) => entry &&
|
|
54
|
+
typeof entry.path === 'string' &&
|
|
55
|
+
typeof entry.hash === 'string' &&
|
|
56
|
+
(entry.staged === undefined || typeof entry.staged === 'string')))
|
|
57
|
+
return null;
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
export function standardCompilerConfig(root) {
|
|
65
|
+
const inspect = (value) => {
|
|
66
|
+
if (Array.isArray(value))
|
|
67
|
+
return value.every(inspect);
|
|
68
|
+
if (value === null || typeof value !== 'object')
|
|
69
|
+
return true;
|
|
70
|
+
return Object.entries(value).every(([key, entry]) => {
|
|
71
|
+
if ((key === 'transform' || key === 'extends') &&
|
|
72
|
+
entry &&
|
|
73
|
+
(!Array.isArray(entry) || entry.length > 0))
|
|
74
|
+
return false;
|
|
75
|
+
return inspect(entry);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
try {
|
|
79
|
+
return inspect(JSON.parse(fs.readFileSync(path.join(root, 'toilconfig.json'), 'utf8')));
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
export function compilerFingerprint(bin, worker) {
|
|
86
|
+
const hash = createHash('sha256');
|
|
87
|
+
const compiler = path.resolve(path.dirname(bin), '..');
|
|
88
|
+
const visit = (file) => {
|
|
89
|
+
const stat = fs.statSync(file);
|
|
90
|
+
if (stat.isDirectory()) {
|
|
91
|
+
for (const entry of fs.readdirSync(file).sort()) {
|
|
92
|
+
if (entry !== 'node_modules' && !entry.endsWith('.map'))
|
|
93
|
+
visit(path.join(file, entry));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
hash.update(file).update('\0').update(fs.readFileSync(file)).update('\0');
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
visit(worker);
|
|
101
|
+
for (const name of ['compiler-cache', 'compiler-build'])
|
|
102
|
+
visit(path.join(path.dirname(worker), name + path.extname(worker)));
|
|
103
|
+
for (const dir of ['bin', 'dist', 'lib', 'util']) {
|
|
104
|
+
const full = path.join(compiler, dir);
|
|
105
|
+
if (fs.existsSync(full))
|
|
106
|
+
visit(full);
|
|
107
|
+
}
|
|
108
|
+
visit(path.join(compiler, 'package.json'));
|
|
109
|
+
hash.update(process.version).update(JSON.stringify({
|
|
110
|
+
NODE_OPTIONS: process.env.NODE_OPTIONS,
|
|
111
|
+
BINARYEN_CORES: process.env.BINARYEN_CORES,
|
|
112
|
+
}));
|
|
113
|
+
return hash.digest('hex');
|
|
114
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function withCompilerLock<T>(root: string, work: () => Promise<T>): Promise<T>;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { setTimeout } from 'node:timers/promises';
|
|
5
|
+
const queues = new Map();
|
|
6
|
+
function owner(file) {
|
|
7
|
+
try {
|
|
8
|
+
const value = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
9
|
+
return Number.isSafeInteger(value.pid) && value.pid > 0 && typeof value.token === 'string'
|
|
10
|
+
? value
|
|
11
|
+
: null;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function alive(pid) {
|
|
18
|
+
try {
|
|
19
|
+
process.kill(pid, 0);
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
return error.code !== 'ESRCH';
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export async function withCompilerLock(root, work) {
|
|
27
|
+
const canonical = fs.realpathSync(root);
|
|
28
|
+
const previous = queues.get(canonical) ?? Promise.resolve();
|
|
29
|
+
const next = Promise.withResolvers();
|
|
30
|
+
queues.set(canonical, next.promise);
|
|
31
|
+
await previous;
|
|
32
|
+
const dir = path.join(canonical, '.toil', 'compiler');
|
|
33
|
+
const lock = path.join(dir, 'lock');
|
|
34
|
+
const token = randomUUID();
|
|
35
|
+
let acquired = false;
|
|
36
|
+
try {
|
|
37
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
38
|
+
const deadline = Date.now() + 300_000;
|
|
39
|
+
while (!acquired) {
|
|
40
|
+
try {
|
|
41
|
+
const fd = fs.openSync(lock, 'wx');
|
|
42
|
+
acquired = true;
|
|
43
|
+
try {
|
|
44
|
+
fs.writeFileSync(fd, JSON.stringify({ pid: process.pid, token }));
|
|
45
|
+
}
|
|
46
|
+
finally {
|
|
47
|
+
fs.closeSync(fd);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error.code !== 'EEXIST')
|
|
52
|
+
throw error;
|
|
53
|
+
const stale = owner(lock);
|
|
54
|
+
if (stale && !alive(stale.pid)) {
|
|
55
|
+
const reaper = lock + '.reaping';
|
|
56
|
+
let fd;
|
|
57
|
+
try {
|
|
58
|
+
fd = fs.openSync(reaper, 'wx');
|
|
59
|
+
const current = owner(lock);
|
|
60
|
+
if (current?.token === stale.token && !alive(current.pid))
|
|
61
|
+
fs.unlinkSync(lock);
|
|
62
|
+
}
|
|
63
|
+
catch (failure) {
|
|
64
|
+
if (failure.code !== 'EEXIST' &&
|
|
65
|
+
failure.code !== 'ENOENT')
|
|
66
|
+
throw failure;
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
if (fd !== undefined) {
|
|
70
|
+
fs.closeSync(fd);
|
|
71
|
+
fs.rmSync(reaper, { force: true });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
if (Date.now() >= deadline)
|
|
76
|
+
throw new Error(`Another server build holds ${lock}. Check its process before removing a stale lock.`, { cause: error });
|
|
77
|
+
await setTimeout(50);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
for (const entry of fs.readdirSync(dir)) {
|
|
81
|
+
const match = /^pending-(\d+)-/.exec(entry);
|
|
82
|
+
if (match && !alive(Number(match[1])))
|
|
83
|
+
fs.rmSync(path.join(dir, entry), { recursive: true, force: true });
|
|
84
|
+
}
|
|
85
|
+
return await work();
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
try {
|
|
89
|
+
const recorded = acquired ? owner(lock) : null;
|
|
90
|
+
if (acquired && (recorded === null || recorded.token === token))
|
|
91
|
+
fs.rmSync(lock, { force: true });
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
next.resolve(undefined);
|
|
95
|
+
if (queues.get(canonical) === next.promise)
|
|
96
|
+
queues.delete(canonical);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
package/build/compiler/emails.js
CHANGED
|
@@ -201,6 +201,8 @@ export async function renderEmails(cfg, authOn = false) {
|
|
|
201
201
|
const files = fs
|
|
202
202
|
.readdirSync(emailsDir)
|
|
203
203
|
.filter((f) => /\.(tsx|jsx)$/.test(f))
|
|
204
|
+
.filter((f) => !authOn ||
|
|
205
|
+
!RESERVED_AUTH_EMAIL_NAMES.has(toPascal(path.basename(f).replace(/\.(tsx|jsx)$/, ''))))
|
|
204
206
|
.sort();
|
|
205
207
|
if (files.length === 0) {
|
|
206
208
|
if (fs.existsSync(generatedPath))
|
|
@@ -217,9 +219,6 @@ export async function renderEmails(cfg, authOn = false) {
|
|
|
217
219
|
const rendered = [];
|
|
218
220
|
try {
|
|
219
221
|
for (const file of files) {
|
|
220
|
-
if (authOn &&
|
|
221
|
-
RESERVED_AUTH_EMAIL_NAMES.has(toPascal(path.basename(file).replace(/\.(tsx|jsx)$/, ''))))
|
|
222
|
-
continue;
|
|
223
222
|
try {
|
|
224
223
|
const r = await renderEmailFile(server, emailsDir, file, renderToStaticMarkup);
|
|
225
224
|
if (r)
|