@webtypen/webframez-core 0.3.94 → 0.3.96
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/BuildApplication.js +16 -44
- package/dist/BuildCompiler.d.ts +1 -0
- package/dist/BuildCompiler.js +71 -0
- package/package.json +1 -1
package/dist/BuildApplication.js
CHANGED
|
@@ -167,51 +167,23 @@ class BuildApplication {
|
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
runTypescriptBuild(_context) {
|
|
170
|
-
var _a, _b
|
|
170
|
+
var _a, _b;
|
|
171
171
|
return __awaiter(this, void 0, void 0, function* () {
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
const key = node_crypto_1.default.createHash("sha256").update(JSON.stringify([files, parsed.options, ts.version])).digest("hex");
|
|
188
|
-
const previous = yield promises_1.default.readFile(node_path_1.default.join(cache, "key"), "utf8").catch(() => "");
|
|
189
|
-
if (previous !== key)
|
|
190
|
-
yield promises_1.default.rm(cache, { recursive: true, force: true });
|
|
191
|
-
yield promises_1.default.mkdir(output, { recursive: true });
|
|
192
|
-
console.log(`[webframez] TypeScript cache: ${previous === key ? "reuse" : "cold"} (${files.length} source files)`);
|
|
193
|
-
try {
|
|
194
|
-
const builder = ts.createIncrementalProgram({ rootNames: files, options: Object.assign(Object.assign({}, parsed.options), { outDir: output, incremental: true, tsBuildInfoFile: node_path_1.default.join(cache, "build.tsbuildinfo") }), projectReferences: parsed.projectReferences });
|
|
195
|
-
const diagnostics = [...(loaded.error ? [loaded.error] : []), ...parsed.errors, ...builder.getOptionsDiagnostics(), ...builder.getGlobalDiagnostics(), ...builder.getSyntacticDiagnostics(), ...builder.getSemanticDiagnostics()];
|
|
196
|
-
if (diagnostics.length)
|
|
197
|
-
console.error(ts.formatDiagnosticsWithColorAndContext(diagnostics, { getCanonicalFileName: (name) => name, getCurrentDirectory: () => this.projectRoot, getNewLine: () => "\n" }));
|
|
198
|
-
if (diagnostics.some((entry) => entry.category === ts.DiagnosticCategory.Error))
|
|
199
|
-
throw new Error("tsc exited with code 1");
|
|
200
|
-
const emitted = builder.emit();
|
|
201
|
-
if ((_c = emitted.diagnostics) === null || _c === void 0 ? void 0 : _c.length) {
|
|
202
|
-
console.error(ts.formatDiagnosticsWithColorAndContext(emitted.diagnostics, { getCanonicalFileName: (name) => name, getCurrentDirectory: () => this.projectRoot, getNewLine: () => "\n" }));
|
|
203
|
-
if (emitted.diagnostics.some((entry) => entry.category === ts.DiagnosticCategory.Error))
|
|
204
|
-
throw new Error("tsc exited with code 1");
|
|
205
|
-
}
|
|
206
|
-
if (emitted.emitSkipped)
|
|
207
|
-
throw new Error("tsc exited without emitting output");
|
|
208
|
-
yield this.copyTree(output, this.stagingDir);
|
|
209
|
-
yield promises_1.default.writeFile(node_path_1.default.join(cache, "key"), key);
|
|
210
|
-
}
|
|
211
|
-
catch (error) {
|
|
212
|
-
yield promises_1.default.rm(cache, { recursive: true, force: true });
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
172
|
+
const options = {
|
|
173
|
+
projectRoot: this.projectRoot,
|
|
174
|
+
tsconfig: node_path_1.default.resolve(this.projectRoot, ((_a = this.config.build) === null || _a === void 0 ? void 0 : _a.tsconfig) || "tsconfig.json"),
|
|
175
|
+
outDir: this.outDir,
|
|
176
|
+
buildRoot: this.buildRoot,
|
|
177
|
+
root: node_path_1.default.resolve(this.projectRoot, ((_b = this.config.build) === null || _b === void 0 ? void 0 : _b.cacheDirectory) || process.env.WEBFRAMEZ_BUILD_CACHE_DIRECTORY || node_path_1.default.join(this.buildRoot, "cache")),
|
|
178
|
+
stagingDir: this.stagingDir,
|
|
179
|
+
};
|
|
180
|
+
yield new Promise((resolve, reject) => {
|
|
181
|
+
const child = (0, node_child_process_1.spawn)(process.execPath, [node_path_1.default.join(__dirname, "BuildCompiler.js"), JSON.stringify(options)], {
|
|
182
|
+
cwd: this.projectRoot, stdio: "inherit", env: process.env,
|
|
183
|
+
});
|
|
184
|
+
child.once("error", reject);
|
|
185
|
+
child.once("exit", (code, signal) => code === 0 ? resolve() : reject(new Error(`tsc exited with code ${code}${signal ? ` (${signal})` : ""}`)));
|
|
186
|
+
});
|
|
215
187
|
});
|
|
216
188
|
}
|
|
217
189
|
copyTree(source, target) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
16
|
+
const promises_1 = __importDefault(require("node:fs/promises"));
|
|
17
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
+
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
19
|
+
/** A separate process releases the compiler AST before runtime copies and bundling. */
|
|
20
|
+
function compile({ projectRoot, tsconfig, outDir, buildRoot, root, stagingDir }) {
|
|
21
|
+
var _a;
|
|
22
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
+
const ts = require(require.resolve("typescript", { paths: [projectRoot, __dirname] }));
|
|
24
|
+
const scope = node_crypto_1.default.createHash("sha256").update(tsconfig).digest("hex").slice(0, 24);
|
|
25
|
+
const cache = node_path_1.default.join(root, "typescript", scope), output = node_path_1.default.join(cache, "output");
|
|
26
|
+
const loaded = ts.readConfigFile(tsconfig, ts.sys.readFile);
|
|
27
|
+
const parsed = ts.parseJsonConfigFileContent(loaded.config || {}, ts.sys, node_path_1.default.dirname(tsconfig), undefined, tsconfig);
|
|
28
|
+
if (parsed.options.noEmit)
|
|
29
|
+
throw new Error("Build compilation requires emitted output; remove noEmit from the build configuration.");
|
|
30
|
+
// Resolve the original project before redirecting output. Otherwise allowJs
|
|
31
|
+
// projects accidentally compile their previous build into build/build/.
|
|
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);
|
|
35
|
+
const files = parsed.fileNames.filter((file) => !generated.some(directory => inside(directory, file)));
|
|
36
|
+
const key = node_crypto_1.default.createHash("sha256").update(JSON.stringify([files, parsed.options, ts.version])).digest("hex");
|
|
37
|
+
const previous = yield promises_1.default.readFile(node_path_1.default.join(cache, "key"), "utf8").catch(() => "");
|
|
38
|
+
if (previous !== key)
|
|
39
|
+
yield promises_1.default.rm(cache, { recursive: true, force: true });
|
|
40
|
+
yield promises_1.default.mkdir(output, { recursive: true });
|
|
41
|
+
console.log(`[webframez] TypeScript cache: ${previous === key ? "reuse" : "cold"} (${files.length} source files)`);
|
|
42
|
+
try {
|
|
43
|
+
const builder = ts.createIncrementalProgram({ rootNames: files, options: Object.assign(Object.assign({}, parsed.options), { outDir: output, incremental: true, tsBuildInfoFile: node_path_1.default.join(cache, "build.tsbuildinfo") }), projectReferences: parsed.projectReferences });
|
|
44
|
+
const diagnostics = [...(loaded.error ? [loaded.error] : []), ...parsed.errors, ...builder.getOptionsDiagnostics(), ...builder.getGlobalDiagnostics(), ...builder.getSyntacticDiagnostics(), ...builder.getSemanticDiagnostics()];
|
|
45
|
+
if (diagnostics.length)
|
|
46
|
+
console.error(ts.formatDiagnosticsWithColorAndContext(diagnostics, { getCanonicalFileName: (name) => name, getCurrentDirectory: () => projectRoot, getNewLine: () => "\n" }));
|
|
47
|
+
if (diagnostics.some((entry) => entry.category === ts.DiagnosticCategory.Error))
|
|
48
|
+
throw new Error("tsc exited with code 1");
|
|
49
|
+
const emitted = builder.emit();
|
|
50
|
+
if ((_a = emitted.diagnostics) === null || _a === void 0 ? void 0 : _a.length) {
|
|
51
|
+
console.error(ts.formatDiagnosticsWithColorAndContext(emitted.diagnostics, { getCanonicalFileName: (name) => name, getCurrentDirectory: () => projectRoot, getNewLine: () => "\n" }));
|
|
52
|
+
if (emitted.diagnostics.some((entry) => entry.category === ts.DiagnosticCategory.Error))
|
|
53
|
+
throw new Error("tsc exited with code 1");
|
|
54
|
+
}
|
|
55
|
+
if (emitted.emitSkipped)
|
|
56
|
+
throw new Error("tsc exited without emitting output");
|
|
57
|
+
yield promises_1.default.cp(output, stagingDir, { recursive: true, mode: node_fs_1.default.constants.COPYFILE_FICLONE });
|
|
58
|
+
yield promises_1.default.writeFile(node_path_1.default.join(cache, "key"), key);
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
yield promises_1.default.rm(cache, { recursive: true, force: true });
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
if (require.main === module) {
|
|
67
|
+
compile(JSON.parse(process.argv[2])).catch(error => {
|
|
68
|
+
console.error((error === null || error === void 0 ? void 0 : error.stack) || error);
|
|
69
|
+
process.exitCode = 1;
|
|
70
|
+
});
|
|
71
|
+
}
|
package/package.json
CHANGED