1
0

Compiler robustness

This commit is contained in:
Zef Hemel 2022-07-06 12:17:14 +02:00
parent 0b46d5c7d9
commit 0388b6a2a4

View File

@ -28,32 +28,35 @@ export async function compile(
); );
} }
// TODO: Figure out how to make source maps work correctly with eval() code try {
let result = await esbuild.build({ // TODO: Figure out how to make source maps work correctly with eval() code
entryPoints: [path.basename(inFile)], let result = await esbuild.build({
bundle: true, entryPoints: [path.basename(inFile)],
format: "iife", bundle: true,
globalName: "mod", format: "iife",
platform: "browser", globalName: "mod",
sourcemap: false, //debug ? "inline" : false, platform: "browser",
minify: !debug, sourcemap: false, //debug ? "inline" : false,
outfile: outFile, minify: !debug,
metafile: true, outfile: outFile,
external: excludeModules, metafile: true,
absWorkingDir: path.resolve(path.dirname(inFile)), external: excludeModules,
}); absWorkingDir: path.resolve(path.dirname(inFile)),
});
if (meta) { if (meta) {
let text = await esbuild.analyzeMetafile(result.metafile); let text = await esbuild.analyzeMetafile(result.metafile);
console.log("Bundle info for", functionName, text); console.log("Bundle info for", functionName, text);
} }
let jsCode = (await readFile(outFile)).toString(); let jsCode = (await readFile(outFile)).toString();
await unlink(outFile); await unlink(outFile);
if (inFile !== filePath) { return `(() => { ${jsCode} return mod;})()`;
await unlink(inFile); } finally {
if (inFile !== filePath) {
await unlink(inFile);
}
} }
return `(() => { ${jsCode} return mod;})()`;
} }
export async function compileModule( export async function compileModule(