Skip to content

Commit 5e918f6

Browse files
committed
feat: prepend @ts-nocheck header to generated worker files
Adds "// @ts-nocheck: auto-generated worker file" at the top of every worker file written to .workers/. Strips any existing header before patching to prevent duplication in nested worker scenarios.
1 parent 2311694 commit 5e918f6

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

src/lib/lib.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,13 @@ globalThis.__worker_wrapper__ = async (
119119
let filePath = PATH_CACHE.get(signatureKey);
120120

121121
if (!filePath) {
122+
const noCheckHeader = "// @ts-nocheck: auto-generated worker file\n";
123+
122124
let rawCode = readFileSync(fileURLToPath(url), "utf-8");
123125
const splitIdx = rawCode.indexOf(WORKER_SPLIT_MARKER);
124126
if (splitIdx > -1) rawCode = rawCode.substring(0, splitIdx);
127+
// Strip existing header to avoid doubling it in nested workers
128+
if (rawCode.startsWith(noCheckHeader)) rawCode = rawCode.substring(noCheckHeader.length);
125129

126130
let patchedCode = PATCHED_SOURCE_CACHE.get(url);
127131
if (!patchedCode) {
@@ -137,7 +141,7 @@ globalThis.__worker_wrapper__ = async (
137141

138142
const fileExt = extname(fileURLToPath(url)) || ".js";
139143
filePath = join(workerDir, `${hash}${fileExt}`);
140-
writeFileSync(filePath, patchedCode + workerBody(wrapper));
144+
writeFileSync(filePath, noCheckHeader + patchedCode + workerBody(wrapper));
141145
PATH_CACHE.set(signatureKey, filePath);
142146
}
143147

0 commit comments

Comments
 (0)