@webtypen/webframez-core 0.3.95 → 0.3.97
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/dist/BuildCompiler.js +17 -5
- package/package.json +1 -1
package/dist/BuildCompiler.js
CHANGED
|
@@ -18,7 +18,7 @@ const node_path_1 = __importDefault(require("node:path"));
|
|
|
18
18
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
19
19
|
/** A separate process releases the compiler AST before runtime copies and bundling. */
|
|
20
20
|
function compile({ projectRoot, tsconfig, outDir, buildRoot, root, stagingDir }) {
|
|
21
|
-
var _a;
|
|
21
|
+
var _a, _b;
|
|
22
22
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
23
|
const ts = require(require.resolve("typescript", { paths: [projectRoot, __dirname] }));
|
|
24
24
|
const scope = node_crypto_1.default.createHash("sha256").update(tsconfig).digest("hex").slice(0, 24);
|
|
@@ -29,24 +29,36 @@ function compile({ projectRoot, tsconfig, outDir, buildRoot, root, stagingDir })
|
|
|
29
29
|
throw new Error("Build compilation requires emitted output; remove noEmit from the build configuration.");
|
|
30
30
|
// Resolve the original project before redirecting output. Otherwise allowJs
|
|
31
31
|
// projects accidentally compile their previous build into build/build/.
|
|
32
|
-
const generated = [outDir, buildRoot, root, parsed.options.outDir].filter(Boolean);
|
|
33
32
|
const inside = (parent, file) => file === parent || file.startsWith(parent + node_path_1.default.sep);
|
|
33
|
+
// Compact runners may place the source checkout inside the shared cache root.
|
|
34
|
+
const generated = [outDir, buildRoot, inside(root, projectRoot) ? cache : root, parsed.options.outDir].filter(Boolean);
|
|
34
35
|
const files = parsed.fileNames.filter((file) => !generated.some(directory => inside(directory, file)));
|
|
35
|
-
const key = node_crypto_1.default.createHash("sha256").update(JSON.stringify([files, parsed.options, ts.version])).digest("hex");
|
|
36
|
+
const key = node_crypto_1.default.createHash("sha256").update(JSON.stringify(["bounded-generated-imports-v1", files, parsed.options, ts.version])).digest("hex");
|
|
36
37
|
const previous = yield promises_1.default.readFile(node_path_1.default.join(cache, "key"), "utf8").catch(() => "");
|
|
37
38
|
if (previous !== key)
|
|
38
39
|
yield promises_1.default.rm(cache, { recursive: true, force: true });
|
|
39
40
|
yield promises_1.default.mkdir(output, { recursive: true });
|
|
40
41
|
console.log(`[webframez] TypeScript cache: ${previous === key ? "reuse" : "cold"} (${files.length} source files)`);
|
|
41
42
|
try {
|
|
42
|
-
const
|
|
43
|
+
const options = Object.assign(Object.assign({}, parsed.options), { outDir: output, incremental: true, tsBuildInfoFile: node_path_1.default.join(cache, "build.tsbuildinfo") });
|
|
44
|
+
const host = ts.createIncrementalCompilerHost(options);
|
|
45
|
+
// JavaScript scripts may require the previous build for smoke checks.
|
|
46
|
+
// Do not let those imports pull generated code and a second dependency
|
|
47
|
+
// tree back into compilation. The last good output remains untouched.
|
|
48
|
+
const hidden = (file) => file !== options.tsBuildInfoFile && generated.some(directory => inside(directory, node_path_1.default.resolve(file)));
|
|
49
|
+
for (const name of ["fileExists", "directoryExists", "readFile"]) {
|
|
50
|
+
const original = (_a = host[name]) === null || _a === void 0 ? void 0 : _a.bind(host);
|
|
51
|
+
if (original)
|
|
52
|
+
host[name] = (file) => hidden(file) ? (name === "readFile" ? undefined : false) : original(file);
|
|
53
|
+
}
|
|
54
|
+
const builder = ts.createIncrementalProgram({ rootNames: files, options, host, projectReferences: parsed.projectReferences });
|
|
43
55
|
const diagnostics = [...(loaded.error ? [loaded.error] : []), ...parsed.errors, ...builder.getOptionsDiagnostics(), ...builder.getGlobalDiagnostics(), ...builder.getSyntacticDiagnostics(), ...builder.getSemanticDiagnostics()];
|
|
44
56
|
if (diagnostics.length)
|
|
45
57
|
console.error(ts.formatDiagnosticsWithColorAndContext(diagnostics, { getCanonicalFileName: (name) => name, getCurrentDirectory: () => projectRoot, getNewLine: () => "\n" }));
|
|
46
58
|
if (diagnostics.some((entry) => entry.category === ts.DiagnosticCategory.Error))
|
|
47
59
|
throw new Error("tsc exited with code 1");
|
|
48
60
|
const emitted = builder.emit();
|
|
49
|
-
if ((
|
|
61
|
+
if ((_b = emitted.diagnostics) === null || _b === void 0 ? void 0 : _b.length) {
|
|
50
62
|
console.error(ts.formatDiagnosticsWithColorAndContext(emitted.diagnostics, { getCanonicalFileName: (name) => name, getCurrentDirectory: () => projectRoot, getNewLine: () => "\n" }));
|
|
51
63
|
if (emitted.diagnostics.some((entry) => entry.category === ts.DiagnosticCategory.Error))
|
|
52
64
|
throw new Error("tsc exited with code 1");
|
package/package.json
CHANGED