@dimina-kit/compiler 0.0.1 → 0.0.2-dev.20260711062001
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/README.md +8 -3
- package/dist/compile-core.browser.js +1331 -1252
- package/dist/{pool.node-chunks/chunk-FVCSERCO.js → compile-core.node-chunks/chunk-LUD2P6RM.js} +5 -1
- package/dist/compile-core.node-chunks/{chunk-5ND5V2SC.js → chunk-QJ34C5KK.js} +77 -2
- package/dist/compile-core.node-chunks/{logic-compiler-RX63Y2FZ.js → logic-compiler-2SQFOFEO.js} +2 -2
- package/dist/compile-core.node-chunks/{style-compiler-JUY5MZSO.js → style-compiler-ZEJ3XLTS.js} +3 -3
- package/dist/compile-core.node-chunks/{view-compiler-KA2OZG44.js → view-compiler-WQNV7H5G.js} +25 -23
- package/dist/compile-core.node.js +10 -7
- package/dist/pool.browser.js +6 -5
- package/dist/pool.node-chunks/{chunk-UYQ7D5I5.js → chunk-7FGOYOXU.js} +77 -2
- package/dist/{compile-core.node-chunks/chunk-CCZB2BJG.js → pool.node-chunks/chunk-C7GEIDCP.js} +5 -1
- package/dist/pool.node-chunks/{chunk-MHOA4NGC.js → chunk-PDHO4Y56.js} +8 -5
- package/dist/pool.node-chunks/{logic-compiler-3VVLN3YN.js → logic-compiler-BODAINZQ.js} +2 -2
- package/dist/pool.node-chunks/{style-compiler-QOUWS72U.js → style-compiler-TUNDVSR5.js} +3 -3
- package/dist/pool.node-chunks/{view-compiler-KAYOMOXO.js → view-compiler-HOFFL63K.js} +25 -23
- package/dist/pool.node.js +34 -11
- package/dist/stage-worker.browser.js +1337 -1258
- package/dist/stage-worker.node.js +2 -2
- package/package.json +4 -2
- package/scripts/test-pool-filetypes.js +159 -0
- package/scripts/test-pool-node.js +93 -3
- package/scripts/test-pool-toolchain-death.js +135 -0
- package/scripts/toolchain-setup-node-native.js +13 -0
- package/src/compile-core.js +8 -5
- package/src/pool-node.js +84 -17
- package/src/pool.js +23 -10
- package/src/stage-worker.js +12 -8
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
checkTemplateCompatibility
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-C7GEIDCP.js";
|
|
4
4
|
import {
|
|
5
5
|
isMainThread,
|
|
6
6
|
parentPort
|
|
@@ -12,11 +12,14 @@ import {
|
|
|
12
12
|
getComponent,
|
|
13
13
|
getContentByPath,
|
|
14
14
|
getTargetPath,
|
|
15
|
+
getTemplateExts,
|
|
16
|
+
getViewScriptExts,
|
|
17
|
+
getViewScriptTags,
|
|
15
18
|
getWorkPath,
|
|
16
19
|
resetStoreInfo,
|
|
17
20
|
tagWhiteList,
|
|
18
21
|
transformRpx
|
|
19
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-7FGOYOXU.js";
|
|
20
23
|
|
|
21
24
|
// ../../dimina/fe/packages/compiler/src/core/view-compiler.js
|
|
22
25
|
import fs from "node:fs";
|
|
@@ -152,7 +155,13 @@ function parseBindings(bindings) {
|
|
|
152
155
|
}
|
|
153
156
|
|
|
154
157
|
// ../../dimina/fe/packages/compiler/src/core/view-compiler.js
|
|
155
|
-
|
|
158
|
+
function buildExtStripRegex(exts) {
|
|
159
|
+
const alt = exts.map((e) => e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
|
|
160
|
+
return new RegExp(`(${alt})$`);
|
|
161
|
+
}
|
|
162
|
+
function stripViewScriptExt(p) {
|
|
163
|
+
return p.replace(buildExtStripRegex(getViewScriptExts()), "");
|
|
164
|
+
}
|
|
156
165
|
function parseJs(code, filename = "view-compiler.js", sourceType = "module") {
|
|
157
166
|
return parseSync2(filename, code, {
|
|
158
167
|
sourceType,
|
|
@@ -358,8 +367,8 @@ function scanWxsFiles(dir, workPath) {
|
|
|
358
367
|
const stat = fs.statSync(fullPath);
|
|
359
368
|
if (stat.isDirectory()) {
|
|
360
369
|
scanWxsFiles(fullPath, workPath);
|
|
361
|
-
} else if (stat.isFile() && item.endsWith(
|
|
362
|
-
const relativePath = fullPath.replace(workPath, "")
|
|
370
|
+
} else if (stat.isFile() && getViewScriptExts().some((ext) => item.endsWith(ext))) {
|
|
371
|
+
const relativePath = stripViewScriptExt(fullPath.replace(workPath, ""));
|
|
363
372
|
const moduleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
|
|
364
373
|
wxsFilePathMap.set(moduleName, fullPath);
|
|
365
374
|
}
|
|
@@ -589,7 +598,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
|
|
|
589
598
|
if (filePath && filePath.includes("/miniprogram_npm/")) {
|
|
590
599
|
const currentWxsDir = path.dirname(wxsFilePath);
|
|
591
600
|
resolvedWxsPath = path.resolve(currentWxsDir, requirePath);
|
|
592
|
-
const relativePath = resolvedWxsPath.replace(workPath, "")
|
|
601
|
+
const relativePath = stripViewScriptExt(resolvedWxsPath.replace(workPath, ""));
|
|
593
602
|
const moduleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
|
|
594
603
|
processWxsDependency(resolvedWxsPath, moduleName, scriptModule, workPath, filePath);
|
|
595
604
|
replacements.push({
|
|
@@ -600,7 +609,7 @@ function processWxsContent(wxsContent, wxsFilePath, scriptModule, workPath, file
|
|
|
600
609
|
} else {
|
|
601
610
|
const currentWxsDir = path.dirname(wxsFilePath);
|
|
602
611
|
resolvedWxsPath = path.resolve(currentWxsDir, requirePath);
|
|
603
|
-
const relativePath = resolvedWxsPath.replace(workPath, "")
|
|
612
|
+
const relativePath = stripViewScriptExt(resolvedWxsPath.replace(workPath, ""));
|
|
604
613
|
const depModuleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
|
|
605
614
|
processWxsDependency(resolvedWxsPath, depModuleName, scriptModule, workPath, filePath);
|
|
606
615
|
replacements.push({
|
|
@@ -816,7 +825,7 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
|
|
|
816
825
|
const src = $(elem).attr("src");
|
|
817
826
|
if (src) {
|
|
818
827
|
const includeFullPath = getAbsolutePath(workPath, path2, src);
|
|
819
|
-
let includePath = includeFullPath.replace(workPath, "").replace(
|
|
828
|
+
let includePath = includeFullPath.replace(workPath, "").replace(buildExtStripRegex(getTemplateExts()), "");
|
|
820
829
|
const includeDiagnosticSource = includeFullPath.startsWith(workPath) ? includeFullPath.slice(workPath.length) : includePath;
|
|
821
830
|
if (!includePath.startsWith("/")) {
|
|
822
831
|
includePath = "/" + includePath;
|
|
@@ -842,8 +851,7 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
|
|
|
842
851
|
);
|
|
843
852
|
processIncludedFileWxsDependencies(includeContent, includePath, scriptModule, components, processedPaths);
|
|
844
853
|
$includeContent("template").remove();
|
|
845
|
-
$includeContent("
|
|
846
|
-
$includeContent("dds").remove();
|
|
854
|
+
$includeContent(getViewScriptTags().join(",")).remove();
|
|
847
855
|
const processedContent = processIncludeConditionalAttrs($, elem, $includeContent.html());
|
|
848
856
|
$(elem).replaceWith(processedContent);
|
|
849
857
|
} else {
|
|
@@ -860,7 +868,7 @@ function toCompileTemplate(isComponent, path2, components, componentPlaceholder,
|
|
|
860
868
|
const src = $(elem).attr("src");
|
|
861
869
|
if (src) {
|
|
862
870
|
const importFullPath = getAbsolutePath(workPath, path2, src);
|
|
863
|
-
let importPath = importFullPath.replace(workPath, "").replace(
|
|
871
|
+
let importPath = importFullPath.replace(workPath, "").replace(buildExtStripRegex(getTemplateExts()), "");
|
|
864
872
|
const importDiagnosticSource = importFullPath.startsWith(workPath) ? importFullPath.slice(workPath.length) : importPath;
|
|
865
873
|
if (!importPath.startsWith("/")) {
|
|
866
874
|
importPath = "/" + importPath;
|
|
@@ -907,8 +915,7 @@ function transTagTemplate($, templateModule, path2, components, componentPlaceho
|
|
|
907
915
|
const templateContent = $(elem);
|
|
908
916
|
templateContent.find("import").remove();
|
|
909
917
|
templateContent.find("include").remove();
|
|
910
|
-
templateContent.find("
|
|
911
|
-
templateContent.find("dds").remove();
|
|
918
|
+
templateContent.find(getViewScriptTags().join(",")).remove();
|
|
912
919
|
transAsses($, templateContent.find("image"), path2);
|
|
913
920
|
const res = [];
|
|
914
921
|
transHtmlTag(templateContent.html(), res, components, componentPlaceholder);
|
|
@@ -1215,7 +1222,7 @@ function parseKeyExpression(exp, itemName = "item", indexName = "index") {
|
|
|
1215
1222
|
}
|
|
1216
1223
|
function getViewPath(workPath, src) {
|
|
1217
1224
|
const aSrc = src.startsWith("/") ? src : `/${src}`;
|
|
1218
|
-
for (const mlType of
|
|
1225
|
+
for (const mlType of getTemplateExts()) {
|
|
1219
1226
|
const mlFullPath = `${workPath}${aSrc}${mlType}`;
|
|
1220
1227
|
if (fs.existsSync(mlFullPath)) {
|
|
1221
1228
|
return mlFullPath;
|
|
@@ -1324,10 +1331,7 @@ function parseTemplateDataExp(exp) {
|
|
|
1324
1331
|
return `{${parseBraceExp(exp)}}`;
|
|
1325
1332
|
}
|
|
1326
1333
|
function transTagWxs($, scriptModule, filePath) {
|
|
1327
|
-
|
|
1328
|
-
if (wxsNodes.length === 0) {
|
|
1329
|
-
wxsNodes = $("dds");
|
|
1330
|
-
}
|
|
1334
|
+
const wxsNodes = $(getViewScriptTags().join(","));
|
|
1331
1335
|
wxsNodes.each((_, elem) => {
|
|
1332
1336
|
const smName = $(elem).attr("module");
|
|
1333
1337
|
if (smName) {
|
|
@@ -1346,7 +1350,7 @@ function transTagWxs($, scriptModule, filePath) {
|
|
|
1346
1350
|
wxsFilePath = getAbsolutePath(workPath, filePath, src);
|
|
1347
1351
|
}
|
|
1348
1352
|
if (wxsFilePath) {
|
|
1349
|
-
const relativePath = wxsFilePath.replace(workPath, "")
|
|
1353
|
+
const relativePath = stripViewScriptExt(wxsFilePath.replace(workPath, ""));
|
|
1350
1354
|
uniqueModuleName = relativePath.replace(/[\/\\@\-]/g, "_").replace(/^_/, "");
|
|
1351
1355
|
cacheKey = wxsFilePath;
|
|
1352
1356
|
}
|
|
@@ -1419,12 +1423,8 @@ function collectAllWxsModules(scriptRes, collectedPaths = /* @__PURE__ */ new Se
|
|
|
1419
1423
|
return allWxsModules;
|
|
1420
1424
|
}
|
|
1421
1425
|
function loadWxsModule(modulePath, workPath, scriptModule) {
|
|
1422
|
-
if (!modulePath.startsWith("miniprogram_npm__") || !modulePath.includes("_wxs_")) {
|
|
1423
|
-
return null;
|
|
1424
|
-
}
|
|
1425
1426
|
const wxsFilePath = wxsFilePathMap.get(modulePath);
|
|
1426
1427
|
if (!wxsFilePath) {
|
|
1427
|
-
console.warn(`[view] \u65E0\u6CD5\u627E\u5230 wxs \u6A21\u5757\u6587\u4EF6: ${modulePath}`);
|
|
1428
1428
|
return null;
|
|
1429
1429
|
}
|
|
1430
1430
|
try {
|
|
@@ -1516,6 +1516,8 @@ export {
|
|
|
1516
1516
|
compileML,
|
|
1517
1517
|
generateSlotDirective,
|
|
1518
1518
|
generateVModelTemplate,
|
|
1519
|
+
initWxsFilePathMap,
|
|
1520
|
+
loadWxsModule,
|
|
1519
1521
|
parseBraceExp,
|
|
1520
1522
|
parseClassRules,
|
|
1521
1523
|
parseKeyExpression,
|
package/dist/pool.node.js
CHANGED
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
publishToDist,
|
|
4
4
|
resetCompilerState,
|
|
5
5
|
setupCompile
|
|
6
|
-
} from "./pool.node-chunks/chunk-
|
|
6
|
+
} from "./pool.node-chunks/chunk-PDHO4Y56.js";
|
|
7
7
|
import {
|
|
8
8
|
getAppConfigInfo,
|
|
9
9
|
getAppId,
|
|
10
10
|
getAppName
|
|
11
|
-
} from "./pool.node-chunks/chunk-
|
|
11
|
+
} from "./pool.node-chunks/chunk-7FGOYOXU.js";
|
|
12
12
|
|
|
13
13
|
// src/pool-node.js
|
|
14
14
|
import { createRequire } from "node:module";
|
|
@@ -177,7 +177,10 @@ function createWorkerSlot({ name, spawnTransport, onEvent }) {
|
|
|
177
177
|
// src/pool-node.js
|
|
178
178
|
var { Worker } = createRequire(import.meta.url)("node:worker_threads");
|
|
179
179
|
var DEFAULT_SEND_TIMEOUT_MS = 12e4;
|
|
180
|
-
var WORKER_DEATH_CODES = /* @__PURE__ */ new Set(["compiler-worker-timeout", "compiler-worker-crashed", "compiler-worker-dead"]);
|
|
180
|
+
var WORKER_DEATH_CODES = /* @__PURE__ */ new Set(["compiler-worker-timeout", "compiler-worker-crashed", "compiler-worker-dead", "compiler-toolchain-dead"]);
|
|
181
|
+
function isDeadToolchainServiceError(message) {
|
|
182
|
+
return /The service (was stopped|is no longer running)/.test(String(message));
|
|
183
|
+
}
|
|
181
184
|
var DEFAULT_IDLE_SHRINK_MS = 3e5;
|
|
182
185
|
var chain = Promise.resolve();
|
|
183
186
|
function createNodeCompilerPool({
|
|
@@ -245,16 +248,25 @@ function createNodeCompilerPool({
|
|
|
245
248
|
if (err && err.code && !err.stage) err.stage = x.stage;
|
|
246
249
|
throw err;
|
|
247
250
|
})));
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
251
|
+
let firstErr = null;
|
|
252
|
+
for (let i = 0; i < results.length; i++) {
|
|
253
|
+
const r = results[i];
|
|
254
|
+
if (r && r.type !== "error") continue;
|
|
255
|
+
const info = r && r.error;
|
|
256
|
+
const cause = info && info.message || "unknown error";
|
|
257
|
+
const hint = oxcNativeBindingHint(cause) || esbuildAsarSpawnHint(cause);
|
|
258
|
+
const err = new Error(`[compiler] stage "${r && r.stage}" failed: ${cause}${hint ? ` \u2014 ${hint}` : ""}`);
|
|
259
|
+
if (info && info.stack) err.stack = info.stack;
|
|
260
|
+
err.stage = r && r.stage;
|
|
261
|
+
if (isDeadToolchainServiceError(cause)) {
|
|
262
|
+
err.code = "compiler-toolchain-dead";
|
|
263
|
+
workers[i].slot.shrink();
|
|
264
|
+
} else {
|
|
254
265
|
err.code = "compiler-stage-error";
|
|
255
|
-
throw err;
|
|
256
266
|
}
|
|
267
|
+
if (!firstErr) firstErr = err;
|
|
257
268
|
}
|
|
269
|
+
if (firstErr) throw firstErr;
|
|
258
270
|
publishToDist(outputDir, useAppIdDir);
|
|
259
271
|
return {
|
|
260
272
|
appId: getAppId(),
|
|
@@ -297,6 +309,15 @@ function createNodeCompilerPool({
|
|
|
297
309
|
return { build: build2, dispose, stages, _slots: workers };
|
|
298
310
|
}
|
|
299
311
|
var STAGE_TITLES = { logic: "\u7F16\u8BD1\u9875\u9762\u903B\u8F91", view: "\u7F16\u8BD1\u9875\u9762\u6587\u4EF6", style: "\u7F16\u8BD1\u6837\u5F0F\u6587\u4EF6" };
|
|
312
|
+
function esbuildAsarSpawnHint(message) {
|
|
313
|
+
const msg = String(message);
|
|
314
|
+
if (!/app\.asar/.test(msg) || !/esbuild/i.test(msg) || !/ENOENT/.test(msg)) return null;
|
|
315
|
+
return "esbuild \u7684\u539F\u751F\u4E8C\u8FDB\u5236\u65E0\u6CD5\u4ECE app.asar \u5185 spawn\uFF08Electron \u53EA\u4E3A execFile \u6253 asar \u8865\u4E01\uFF09\uFF1A\u6253\u5305\u914D\u7F6E\u9700 asarUnpack '**/node_modules/esbuild/**' \u4E0E '**/node_modules/@esbuild/**'\uFF0C\u5E76\u786E\u4FDD ESBUILD_BINARY_PATH \u6307\u5411 app.asar.unpacked \u4E0B\u7684\u771F\u5B9E\u4E8C\u8FDB\u5236\uFF08@dimina-kit/devkit \u5728 asar \u5185\u8FD0\u884C\u65F6\u4F1A\u81EA\u52A8\u8BBE\u7F6E\uFF09";
|
|
316
|
+
}
|
|
317
|
+
function oxcNativeBindingHint(message) {
|
|
318
|
+
if (!/Cannot find native binding/i.test(String(message))) return null;
|
|
319
|
+
return `oxc-parser \u7684\u8FD0\u884C\u65F6\u7ED1\u5B9A\u6CA1\u6709\u88AB\u6253\u8FDB\u5BBF\u4E3B\u5E94\u7528\uFF1A@dimina-kit/compiler \u7684 Node \u7F16\u8BD1\u8DEF\u5F84\u9700\u8981 @oxc-parser/binding-${process.platform}-${process.arch}\uFF08\u5E73\u53F0\u539F\u751F\u7ED1\u5B9A\uFF09\u6216 @oxc-parser/binding-wasm32-wasi\uFF08wasm \u515C\u5E95\uFF09\u4E8C\u8005\u4E4B\u4E00\u5B9E\u9645\u5B58\u5728\u4E8E\u5305\u5185\u3002\u6253\u5305\u5206\u53D1\uFF08\u5982 electron-builder\uFF09\u65F6\u8BF7\u628A\u5176\u4E2D\u4E00\u4E2A\u663E\u5F0F\u58F0\u660E\u4E3A\u5BBF\u4E3B\u4F9D\u8D56\uFF0C\u907F\u514D\u4F9D\u8D56\u6536\u96C6\u65F6\u88AB\u4E22\u5F03`;
|
|
320
|
+
}
|
|
300
321
|
var singleton = null;
|
|
301
322
|
async function build(outputDir, workPath, useAppIdDir = true, options = {}) {
|
|
302
323
|
if (!singleton) singleton = createNodeCompilerPool();
|
|
@@ -307,7 +328,7 @@ async function build(outputDir, workPath, useAppIdDir = true, options = {}) {
|
|
|
307
328
|
} catch (e) {
|
|
308
329
|
if (e && e.stage) console.error(`\u2716 ${STAGE_TITLES[e.stage] || e.stage}`);
|
|
309
330
|
console.error(`${workPath} \u7F16\u8BD1\u51FA\u9519: ${e && e.message}`);
|
|
310
|
-
|
|
331
|
+
throw e;
|
|
311
332
|
}
|
|
312
333
|
}
|
|
313
334
|
async function warmDefaultPool() {
|
|
@@ -325,5 +346,7 @@ export {
|
|
|
325
346
|
createNodeCompilerPool,
|
|
326
347
|
build as default,
|
|
327
348
|
disposeDefaultPool,
|
|
349
|
+
esbuildAsarSpawnHint,
|
|
350
|
+
oxcNativeBindingHint,
|
|
328
351
|
warmDefaultPool
|
|
329
352
|
};
|