@dimina/compiler 1.0.14-beta.0 → 1.0.15
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/bin/index.cjs +18 -19
- package/dist/bin/index.js +17 -18
- package/dist/compatibility-C_zWVjYl.js +166 -0
- package/dist/compatibility-DlYbbw0F.cjs +184 -0
- package/dist/core/logic-compiler.cjs +177 -85
- package/dist/core/logic-compiler.js +177 -84
- package/dist/core/style-compiler.cjs +7 -7
- package/dist/core/style-compiler.js +7 -7
- package/dist/core/view-compiler.cjs +201 -123
- package/dist/core/view-compiler.js +200 -119
- package/dist/{env-M-7lpbHL.cjs → env-Dmnqp9bD.cjs} +1 -1
- package/dist/{env-DgCLbrQb.js → env-p9Az8lv5.js} +1 -1
- package/dist/index.cjs +31 -8
- package/dist/index.js +31 -8
- package/package.json +13 -15
|
@@ -1,18 +1,103 @@
|
|
|
1
|
-
import { a as getContentByPath, d as resetStoreInfo, f as resolveAppAlias, g as hasCompileInfo, i as getComponent, l as getTargetPath, m as collectAssets, n as getAppId, o as getNpmResolver, t as getAppConfigInfo, u as getWorkPath } from "../env-
|
|
1
|
+
import { a as getContentByPath, d as resetStoreInfo, f as resolveAppAlias, g as hasCompileInfo, i as getComponent, l as getTargetPath, m as collectAssets, n as getAppId, o as getNpmResolver, t as getAppConfigInfo, u as getWorkPath } from "../env-p9Az8lv5.js";
|
|
2
|
+
import { n as getWxMemberName, r as warnUnsupportedWxApi } from "../compatibility-C_zWVjYl.js";
|
|
2
3
|
import { resolve, sep } from "node:path";
|
|
3
4
|
import { isMainThread, parentPort } from "node:worker_threads";
|
|
4
5
|
import fs from "node:fs";
|
|
5
|
-
import { transform } from "esbuild";
|
|
6
6
|
import { parseSync } from "oxc-parser";
|
|
7
7
|
import { walk } from "oxc-walker";
|
|
8
|
-
import { transformSync } from "oxc-transform";
|
|
9
8
|
import MagicString from "magic-string";
|
|
10
|
-
import
|
|
9
|
+
import { transform } from "esbuild";
|
|
10
|
+
import { SourceMapConsumer, SourceMapGenerator } from "source-map-js";
|
|
11
|
+
//#region src/core/sourcemap.js
|
|
12
|
+
function wrapModDefine(module) {
|
|
13
|
+
const code = module.code.endsWith("\n") ? module.code : module.code + "\n";
|
|
14
|
+
const extraLine = module.extraInfoCode || "";
|
|
15
|
+
return {
|
|
16
|
+
header: `modDefine('${module.path}', function(require, module, exports) {\n${extraLine}`,
|
|
17
|
+
code,
|
|
18
|
+
footer: "});\n"
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function mergeSourcemap(compileRes) {
|
|
22
|
+
const smg = new SourceMapGenerator({ file: "logic.js" });
|
|
23
|
+
let bundleCode = "";
|
|
24
|
+
let lineOffset = 0;
|
|
25
|
+
for (const module of compileRes) {
|
|
26
|
+
const { header, code, footer } = wrapModDefine(module);
|
|
27
|
+
bundleCode += header;
|
|
28
|
+
const headerLineCount = header.split("\n").length - 1;
|
|
29
|
+
lineOffset += headerLineCount;
|
|
30
|
+
if (module.map) {
|
|
31
|
+
const moduleMap = JSON.parse(module.map);
|
|
32
|
+
new SourceMapConsumer(moduleMap).eachMapping((mapping) => {
|
|
33
|
+
if (mapping.source == null) return;
|
|
34
|
+
smg.addMapping({
|
|
35
|
+
generated: {
|
|
36
|
+
line: mapping.generatedLine + lineOffset,
|
|
37
|
+
column: mapping.generatedColumn
|
|
38
|
+
},
|
|
39
|
+
original: {
|
|
40
|
+
line: mapping.originalLine,
|
|
41
|
+
column: mapping.originalColumn
|
|
42
|
+
},
|
|
43
|
+
source: mapping.source,
|
|
44
|
+
name: mapping.name
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
if (moduleMap.sourcesContent) moduleMap.sources.forEach((src, i) => {
|
|
48
|
+
smg.setSourceContent(src, moduleMap.sourcesContent[i]);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
bundleCode += code;
|
|
52
|
+
lineOffset += code.split("\n").length - 1;
|
|
53
|
+
bundleCode += footer;
|
|
54
|
+
lineOffset += footer.split("\n").length - 1;
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
bundleCode,
|
|
58
|
+
sourcemap: smg.toString()
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function remapSourcemap(nextMap, prevMap) {
|
|
62
|
+
if (!nextMap) return prevMap;
|
|
63
|
+
if (!prevMap) return nextMap;
|
|
64
|
+
const nextMapObj = typeof nextMap === "string" ? JSON.parse(nextMap) : nextMap;
|
|
65
|
+
const prevMapObj = typeof prevMap === "string" ? JSON.parse(prevMap) : prevMap;
|
|
66
|
+
const smg = new SourceMapGenerator({ file: nextMapObj.file || prevMapObj.file || "" });
|
|
67
|
+
const prevSmc = new SourceMapConsumer(prevMapObj);
|
|
68
|
+
new SourceMapConsumer(nextMapObj).eachMapping((mapping) => {
|
|
69
|
+
if (mapping.source == null || mapping.originalLine == null || mapping.originalColumn == null) return;
|
|
70
|
+
const original = prevSmc.originalPositionFor({
|
|
71
|
+
line: mapping.originalLine,
|
|
72
|
+
column: mapping.originalColumn
|
|
73
|
+
});
|
|
74
|
+
if (original.source == null || original.line == null || original.column == null) return;
|
|
75
|
+
smg.addMapping({
|
|
76
|
+
generated: {
|
|
77
|
+
line: mapping.generatedLine,
|
|
78
|
+
column: mapping.generatedColumn
|
|
79
|
+
},
|
|
80
|
+
original: {
|
|
81
|
+
line: original.line,
|
|
82
|
+
column: original.column
|
|
83
|
+
},
|
|
84
|
+
source: original.source,
|
|
85
|
+
name: original.name || mapping.name
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
if (prevMapObj.sourcesContent) prevMapObj.sources.forEach((src, i) => {
|
|
89
|
+
smg.setSourceContent(src, prevMapObj.sourcesContent[i]);
|
|
90
|
+
});
|
|
91
|
+
return smg.toString();
|
|
92
|
+
}
|
|
93
|
+
//#endregion
|
|
11
94
|
//#region src/core/logic-compiler.js
|
|
12
95
|
var processedModules = /* @__PURE__ */ new Set();
|
|
13
|
-
|
|
96
|
+
var enableSourcemap = false;
|
|
97
|
+
if (!isMainThread) parentPort.on("message", async ({ pages, storeInfo, sourcemap }) => {
|
|
14
98
|
try {
|
|
15
99
|
resetStoreInfo(storeInfo);
|
|
100
|
+
enableSourcemap = !!sourcemap;
|
|
16
101
|
const progress = {
|
|
17
102
|
_completedTasks: 0,
|
|
18
103
|
get completedTasks() {
|
|
@@ -45,25 +130,26 @@ if (!isMainThread) parentPort.on("message", async ({ pages, storeInfo }) => {
|
|
|
45
130
|
}
|
|
46
131
|
});
|
|
47
132
|
async function writeCompileRes(compileRes, root) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
133
|
+
const outputDir = root ? `${getTargetPath()}/${root}` : `${getTargetPath()}/main`;
|
|
134
|
+
if (!fs.existsSync(outputDir)) fs.mkdirSync(outputDir, { recursive: true });
|
|
135
|
+
if (enableSourcemap) {
|
|
136
|
+
const { bundleCode, sourcemap } = mergeSourcemap(compileRes);
|
|
137
|
+
const sourcemapFileName = "logic.js.map";
|
|
138
|
+
fs.writeFileSync(`${outputDir}/logic.js`, `${bundleCode}//# sourceMappingURL=${sourcemapFileName}\n`);
|
|
139
|
+
fs.writeFileSync(`${outputDir}/${sourcemapFileName}`, sourcemap);
|
|
140
|
+
} else {
|
|
141
|
+
let mergeCode = "";
|
|
142
|
+
for (const module of compileRes) {
|
|
143
|
+
const { code: minifiedCode } = await transform(`modDefine('${module.path}', function(require, module, exports) {
|
|
51
144
|
${module.code}
|
|
52
145
|
});`, {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const subDir = `${getTargetPath()}/${root}`;
|
|
61
|
-
if (!fs.existsSync(subDir)) fs.mkdirSync(subDir, { recursive: true });
|
|
62
|
-
fs.writeFileSync(`${subDir}/logic.js`, mergeCode);
|
|
63
|
-
} else {
|
|
64
|
-
const mainDir = `${getTargetPath()}/main`;
|
|
65
|
-
if (!fs.existsSync(mainDir)) fs.mkdirSync(mainDir, { recursive: true });
|
|
66
|
-
fs.writeFileSync(`${mainDir}/logic.js`, mergeCode);
|
|
146
|
+
minify: true,
|
|
147
|
+
target: ["es2023"],
|
|
148
|
+
platform: "neutral"
|
|
149
|
+
});
|
|
150
|
+
mergeCode += minifiedCode;
|
|
151
|
+
}
|
|
152
|
+
fs.writeFileSync(`${outputDir}/logic.js`, mergeCode);
|
|
67
153
|
}
|
|
68
154
|
}
|
|
69
155
|
/**
|
|
@@ -93,7 +179,8 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
93
179
|
if (hasCompileInfo(module.path, compileRes, mainCompileRes)) return;
|
|
94
180
|
const compileInfo = {
|
|
95
181
|
path: module.path,
|
|
96
|
-
code: ""
|
|
182
|
+
code: "",
|
|
183
|
+
sourceFile: null
|
|
97
184
|
};
|
|
98
185
|
const src = module.path.startsWith("/") ? module.path : `/${module.path}`;
|
|
99
186
|
const modulePath = getJSAbsolutePath(src);
|
|
@@ -101,29 +188,22 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
101
188
|
console.warn("[logic]", `找不到模块文件: ${src}`);
|
|
102
189
|
return;
|
|
103
190
|
}
|
|
191
|
+
const diagnosticSource = modulePath.startsWith(getWorkPath()) ? modulePath.slice(getWorkPath().length) : src;
|
|
104
192
|
const sourceCode = getContentByPath(modulePath);
|
|
105
193
|
if (!sourceCode) {
|
|
106
194
|
console.warn("[logic]", `无法读取模块文件: ${modulePath}`);
|
|
107
195
|
return;
|
|
108
196
|
}
|
|
109
|
-
|
|
110
|
-
if (
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
module: ts.ModuleKind.ESNext,
|
|
114
|
-
strict: false,
|
|
115
|
-
esModuleInterop: true,
|
|
116
|
-
skipLibCheck: true
|
|
117
|
-
} }).outputText;
|
|
118
|
-
} catch (error) {
|
|
119
|
-
console.error(`[logic] TypeScript 编译失败 ${modulePath}:`, error.message);
|
|
120
|
-
jsCode = sourceCode;
|
|
197
|
+
const isTypeScript = modulePath.endsWith(".ts");
|
|
198
|
+
if (enableSourcemap) {
|
|
199
|
+
const workPath = getWorkPath();
|
|
200
|
+
compileInfo.sourceFile = modulePath.startsWith(workPath) ? modulePath.slice(workPath.length) : src;
|
|
121
201
|
}
|
|
122
|
-
const ast = parseSync(modulePath,
|
|
202
|
+
const ast = parseSync(modulePath, sourceCode, {
|
|
123
203
|
sourceType: "module",
|
|
124
|
-
lang:
|
|
204
|
+
lang: isTypeScript ? "ts" : "js"
|
|
125
205
|
}).program;
|
|
126
|
-
const s = new MagicString(
|
|
206
|
+
const s = new MagicString(sourceCode);
|
|
127
207
|
const extraInfo = { path: module.path };
|
|
128
208
|
if (module.component) extraInfo.component = true;
|
|
129
209
|
if (module.usingComponents) {
|
|
@@ -147,13 +227,16 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
147
227
|
}
|
|
148
228
|
if (addExtra) {
|
|
149
229
|
const extraInfoCode = `globalThis.__extraInfo = ${JSON.stringify(extraInfo)};\n`;
|
|
150
|
-
|
|
230
|
+
if (enableSourcemap) compileInfo.extraInfoCode = extraInfoCode;
|
|
231
|
+
else s.prepend(extraInfoCode);
|
|
151
232
|
}
|
|
152
233
|
if (putMain) mainCompileRes.push(compileInfo);
|
|
153
234
|
else compileRes.push(compileInfo);
|
|
154
235
|
const pathReplacements = [];
|
|
155
236
|
const dependenciesToProcess = [];
|
|
156
237
|
walk(ast, { enter(node, parent) {
|
|
238
|
+
const wxMemberName = getWxMemberName(node);
|
|
239
|
+
if (wxMemberName) warnUnsupportedWxApi(wxMemberName, compileInfo.sourceFile || diagnosticSource, node.loc?.start?.line || getLineByIndex(sourceCode, node.start));
|
|
157
240
|
if ((node.type === "StringLiteral" || node.type === "Literal") && isLocalAssetString(node.value)) pathReplacements.push({
|
|
158
241
|
start: node.start,
|
|
159
242
|
end: node.end,
|
|
@@ -192,6 +275,21 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
192
275
|
}
|
|
193
276
|
}
|
|
194
277
|
}
|
|
278
|
+
if (node.type === "TSImportEqualsDeclaration" && node.moduleReference?.type === "TSExternalModuleReference") {
|
|
279
|
+
const importPathNode = node.moduleReference.expression;
|
|
280
|
+
const importPath = importPathNode?.value;
|
|
281
|
+
if (importPath) {
|
|
282
|
+
const { id, shouldProcess } = resolveDependencyId(importPath, modulePath, false);
|
|
283
|
+
if (shouldProcess) {
|
|
284
|
+
pathReplacements.push({
|
|
285
|
+
start: importPathNode.start,
|
|
286
|
+
end: importPathNode.end,
|
|
287
|
+
newValue: id
|
|
288
|
+
});
|
|
289
|
+
if (!processedModules.has(packageName + id)) dependenciesToProcess.push(id);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
195
293
|
if ((node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration") && node.source) {
|
|
196
294
|
const exportPath = node.source.value;
|
|
197
295
|
if (exportPath) {
|
|
@@ -210,62 +308,49 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
210
308
|
for (const depId of dependenciesToProcess) await buildJSByPath(packageName, { path: depId }, compileRes, mainCompileRes, false, depthChain, putMain);
|
|
211
309
|
for (const replacement of pathReplacements.reverse()) s.overwrite(replacement.start, replacement.end, `'${replacement.newValue}'`);
|
|
212
310
|
const modifiedCode = s.toString();
|
|
213
|
-
let
|
|
214
|
-
if (
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
}).
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
311
|
+
let preEsbuildMap = null;
|
|
312
|
+
if (enableSourcemap && compileInfo.sourceFile) {
|
|
313
|
+
const generatedMap = JSON.parse(s.generateMap({
|
|
314
|
+
file: compileInfo.sourceFile,
|
|
315
|
+
source: compileInfo.sourceFile,
|
|
316
|
+
includeContent: true,
|
|
317
|
+
hires: true
|
|
318
|
+
}).toString());
|
|
319
|
+
generatedMap.file = compileInfo.sourceFile;
|
|
320
|
+
generatedMap.sources = [compileInfo.sourceFile];
|
|
321
|
+
generatedMap.sourcesContent = [sourceCode];
|
|
322
|
+
preEsbuildMap = JSON.stringify(generatedMap);
|
|
224
323
|
}
|
|
225
324
|
try {
|
|
226
|
-
const
|
|
325
|
+
const esbuildOpts = {
|
|
227
326
|
format: "cjs",
|
|
228
327
|
target: "es2020",
|
|
229
328
|
platform: "neutral",
|
|
230
|
-
loader: "js"
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const isRequireProperty = node.callee.type === "MemberExpression" && node.callee.object?.type === "Identifier" && node.callee.object?.name === "require";
|
|
241
|
-
if ((isRequire || isRequireProperty) && node.arguments.length > 0 && (node.arguments[0].type === "StringLiteral" || node.arguments[0].type === "Literal")) {
|
|
242
|
-
const arg = node.arguments[0];
|
|
243
|
-
const requirePath = arg.value;
|
|
244
|
-
if (requirePath && (requirePath.startsWith("./") || requirePath.startsWith("../"))) {
|
|
245
|
-
const { id } = resolveDependencyId(requirePath, modulePath, false);
|
|
246
|
-
postEsbuildReplacements.push({
|
|
247
|
-
start: arg.start,
|
|
248
|
-
end: arg.end,
|
|
249
|
-
newValue: id
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
} });
|
|
255
|
-
if (postEsbuildReplacements.length > 0) {
|
|
256
|
-
const finalMagicString = new MagicString(esbuildCode);
|
|
257
|
-
for (const replacement of postEsbuildReplacements.reverse()) finalMagicString.overwrite(replacement.start, replacement.end, `"${replacement.newValue}"`);
|
|
258
|
-
compileInfo.code = finalMagicString.toString();
|
|
259
|
-
} else compileInfo.code = esbuildCode;
|
|
329
|
+
loader: isTypeScript ? "ts" : "js"
|
|
330
|
+
};
|
|
331
|
+
if (enableSourcemap && compileInfo.sourceFile) {
|
|
332
|
+
esbuildOpts.sourcemap = true;
|
|
333
|
+
esbuildOpts.sourcefile = compileInfo.sourceFile;
|
|
334
|
+
esbuildOpts.sourcesContent = true;
|
|
335
|
+
}
|
|
336
|
+
const esbuildResult = await transform(modifiedCode, esbuildOpts);
|
|
337
|
+
if (enableSourcemap && esbuildResult.map) compileInfo.map = preEsbuildMap ? remapSourcemap(esbuildResult.map, preEsbuildMap) : esbuildResult.map;
|
|
338
|
+
compileInfo.code = esbuildResult.code;
|
|
260
339
|
} catch (error) {
|
|
261
340
|
console.error(`[logic] esbuild 转换失败 ${modulePath}:`, error.message);
|
|
262
|
-
compileInfo.code =
|
|
341
|
+
compileInfo.code = modifiedCode;
|
|
263
342
|
}
|
|
264
343
|
processedModules.add(packageName + currentPath);
|
|
265
344
|
}
|
|
266
345
|
function isLocalAssetString(value) {
|
|
267
346
|
return typeof value === "string" && !value.startsWith("http") && !value.startsWith("//") && (value.startsWith("/") || value.startsWith("./") || value.startsWith("../")) && /\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(value);
|
|
268
347
|
}
|
|
348
|
+
function getLineByIndex(content, index) {
|
|
349
|
+
if (typeof index !== "number" || index < 0) return null;
|
|
350
|
+
let line = 1;
|
|
351
|
+
for (let i = 0; i < index; i++) if (content.charCodeAt(i) === 10) line++;
|
|
352
|
+
return line;
|
|
353
|
+
}
|
|
269
354
|
/**
|
|
270
355
|
* 获取 JavaScript 或 TypeScript 文件的绝对路径
|
|
271
356
|
* @param {string} modulePath - 模块路径
|
|
@@ -308,9 +393,14 @@ function resolveDependencyId(specifier, modulePath, allowAbsolute) {
|
|
|
308
393
|
};
|
|
309
394
|
if (specifier.startsWith("@") || isBareModuleSpecifier(specifier)) {
|
|
310
395
|
const npmModuleId = resolveNpmModuleId(specifier, modulePath);
|
|
396
|
+
if (npmModuleId) return {
|
|
397
|
+
id: npmModuleId,
|
|
398
|
+
shouldProcess: true
|
|
399
|
+
};
|
|
400
|
+
const siblingModuleId = resolveBareSiblingModuleId(specifier, modulePath);
|
|
311
401
|
return {
|
|
312
|
-
id:
|
|
313
|
-
shouldProcess: Boolean(
|
|
402
|
+
id: siblingModuleId || specifier,
|
|
403
|
+
shouldProcess: Boolean(siblingModuleId)
|
|
314
404
|
};
|
|
315
405
|
}
|
|
316
406
|
return {
|
|
@@ -325,6 +415,9 @@ function resolveRelativeModuleId(specifier, modulePath) {
|
|
|
325
415
|
const relativeId = resolve(modulePath, `../${specifier}`).split(`${getWorkPath()}${sep}`)[1];
|
|
326
416
|
return normalizeModuleId(relativeId);
|
|
327
417
|
}
|
|
418
|
+
function resolveBareSiblingModuleId(specifier, modulePath) {
|
|
419
|
+
return resolveModuleIdToExistingPath(resolveRelativeModuleId(`./${specifier}`, modulePath));
|
|
420
|
+
}
|
|
328
421
|
function normalizeModuleId(moduleId) {
|
|
329
422
|
let normalized = moduleId.replace(/\.(js|ts)$/, "").replace(/\\/g, "/");
|
|
330
423
|
if (!normalized.startsWith("/")) normalized = `/${normalized}`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_env = require("../env-
|
|
2
|
+
const require_env = require("../env-Dmnqp9bD.cjs");
|
|
3
3
|
let node_path = require("node:path");
|
|
4
4
|
node_path = require_env.__toESM(node_path, 1);
|
|
5
5
|
let node_worker_threads = require("node:worker_threads");
|
|
@@ -79,11 +79,11 @@ async function buildCompileCss(module, depthChain = [], compiledPaths = /* @__PU
|
|
|
79
79
|
const currentPath = module.path || module.absolutePath;
|
|
80
80
|
if (depthChain.includes(currentPath)) {
|
|
81
81
|
console.warn("[style]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
82
|
-
return;
|
|
82
|
+
return "";
|
|
83
83
|
}
|
|
84
84
|
if (depthChain.length > 20) {
|
|
85
85
|
console.warn("[style]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
86
|
-
return;
|
|
86
|
+
return "";
|
|
87
87
|
}
|
|
88
88
|
if (compiledPaths.has(currentPath)) return "";
|
|
89
89
|
compiledPaths.add(currentPath);
|
|
@@ -92,15 +92,15 @@ async function buildCompileCss(module, depthChain = [], compiledPaths = /* @__PU
|
|
|
92
92
|
if (module.usingComponents) for (const componentInfo of Object.values(module.usingComponents)) {
|
|
93
93
|
const componentModule = require_env.getComponent(componentInfo);
|
|
94
94
|
if (!componentModule) continue;
|
|
95
|
-
result += await buildCompileCss(componentModule, depthChain, compiledPaths);
|
|
95
|
+
result += await buildCompileCss(componentModule, depthChain, compiledPaths) || "";
|
|
96
96
|
}
|
|
97
97
|
return result;
|
|
98
98
|
}
|
|
99
99
|
async function enhanceCSS(module) {
|
|
100
100
|
const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
|
|
101
|
-
if (!absolutePath) return;
|
|
101
|
+
if (!absolutePath) return "";
|
|
102
102
|
const inputCSS = require_env.getContentByPath(absolutePath);
|
|
103
|
-
if (!inputCSS) return;
|
|
103
|
+
if (!inputCSS) return "";
|
|
104
104
|
if (compileRes.has(absolutePath)) return compileRes.get(absolutePath);
|
|
105
105
|
let processedCSS = normalizeRootStyleImports(inputCSS);
|
|
106
106
|
const ext = node_path.default.extname(absolutePath).toLowerCase();
|
|
@@ -158,7 +158,7 @@ async function enhanceCSS(module) {
|
|
|
158
158
|
const cleanedCode = await removeBaseComponentScope(scopedCode, moduleId);
|
|
159
159
|
const res = await (0, postcss.default)([(0, autoprefixer.default)({ overrideBrowserslist: ["cover 99.5%"] }), (0, cssnano.default)()]).process(cleanedCode, { from: void 0 });
|
|
160
160
|
const result = (await Promise.all(promises)).filter(Boolean).join("") + res.css;
|
|
161
|
-
compileRes.set(
|
|
161
|
+
compileRes.set(absolutePath, result);
|
|
162
162
|
return result;
|
|
163
163
|
}
|
|
164
164
|
function normalizeCssUrlValue(value, absolutePath) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as tagWhiteList, a as getContentByPath, d as resetStoreInfo, i as getComponent, l as getTargetPath, m as collectAssets, n as getAppId, u as getWorkPath, v as transformRpx } from "../env-
|
|
1
|
+
import { _ as tagWhiteList, a as getContentByPath, d as resetStoreInfo, i as getComponent, l as getTargetPath, m as collectAssets, n as getAppId, u as getWorkPath, v as transformRpx } from "../env-p9Az8lv5.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { isMainThread, parentPort } from "node:worker_threads";
|
|
4
4
|
import fs from "node:fs";
|
|
@@ -70,11 +70,11 @@ async function buildCompileCss(module, depthChain = [], compiledPaths = /* @__PU
|
|
|
70
70
|
const currentPath = module.path || module.absolutePath;
|
|
71
71
|
if (depthChain.includes(currentPath)) {
|
|
72
72
|
console.warn("[style]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
73
|
-
return;
|
|
73
|
+
return "";
|
|
74
74
|
}
|
|
75
75
|
if (depthChain.length > 20) {
|
|
76
76
|
console.warn("[style]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
77
|
-
return;
|
|
77
|
+
return "";
|
|
78
78
|
}
|
|
79
79
|
if (compiledPaths.has(currentPath)) return "";
|
|
80
80
|
compiledPaths.add(currentPath);
|
|
@@ -83,15 +83,15 @@ async function buildCompileCss(module, depthChain = [], compiledPaths = /* @__PU
|
|
|
83
83
|
if (module.usingComponents) for (const componentInfo of Object.values(module.usingComponents)) {
|
|
84
84
|
const componentModule = getComponent(componentInfo);
|
|
85
85
|
if (!componentModule) continue;
|
|
86
|
-
result += await buildCompileCss(componentModule, depthChain, compiledPaths);
|
|
86
|
+
result += await buildCompileCss(componentModule, depthChain, compiledPaths) || "";
|
|
87
87
|
}
|
|
88
88
|
return result;
|
|
89
89
|
}
|
|
90
90
|
async function enhanceCSS(module) {
|
|
91
91
|
const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
|
|
92
|
-
if (!absolutePath) return;
|
|
92
|
+
if (!absolutePath) return "";
|
|
93
93
|
const inputCSS = getContentByPath(absolutePath);
|
|
94
|
-
if (!inputCSS) return;
|
|
94
|
+
if (!inputCSS) return "";
|
|
95
95
|
if (compileRes.has(absolutePath)) return compileRes.get(absolutePath);
|
|
96
96
|
let processedCSS = normalizeRootStyleImports(inputCSS);
|
|
97
97
|
const ext = path.extname(absolutePath).toLowerCase();
|
|
@@ -149,7 +149,7 @@ async function enhanceCSS(module) {
|
|
|
149
149
|
const cleanedCode = await removeBaseComponentScope(scopedCode, moduleId);
|
|
150
150
|
const res = await postcss([autoprefixer({ overrideBrowserslist: ["cover 99.5%"] }), cssnano()]).process(cleanedCode, { from: void 0 });
|
|
151
151
|
const result = (await Promise.all(promises)).filter(Boolean).join("") + res.css;
|
|
152
|
-
compileRes.set(
|
|
152
|
+
compileRes.set(absolutePath, result);
|
|
153
153
|
return result;
|
|
154
154
|
}
|
|
155
155
|
function normalizeCssUrlValue(value, absolutePath) {
|