@dimina-kit/compiler 0.0.2-dev.20260728065133 → 0.0.2-dev.20260728095034
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/compile-core.browser.js +14759 -16081
- package/dist/compile-core.node-chunks/chunk-2VRS523Z.js +8 -0
- package/dist/compile-core.node-chunks/chunk-LUD2P6RM.js +211 -0
- package/dist/compile-core.node-chunks/{chunk-M62ZDT7T.js → chunk-QJ34C5KK.js} +66 -542
- package/dist/compile-core.node-chunks/{logic-compiler-AEZPY2MO.js → logic-compiler-2SQFOFEO.js} +113 -37
- package/dist/compile-core.node-chunks/style-compiler-ZEJ3XLTS.js +277 -0
- package/dist/compile-core.node-chunks/{view-compiler-2SMUHAPD.js → view-compiler-WQNV7H5G.js} +161 -425
- package/dist/compile-core.node.js +6 -11
- package/dist/pool.node-chunks/{chunk-CKQISGZS.js → chunk-7FGOYOXU.js} +66 -542
- package/dist/pool.node-chunks/chunk-C7GEIDCP.js +211 -0
- package/dist/pool.node-chunks/chunk-KLXXOLDF.js +8 -0
- package/dist/pool.node-chunks/{chunk-WX4462A5.js → chunk-PDHO4Y56.js} +6 -11
- package/dist/pool.node-chunks/{logic-compiler-P4T4OMTG.js → logic-compiler-BODAINZQ.js} +113 -37
- package/dist/pool.node-chunks/style-compiler-TUNDVSR5.js +277 -0
- package/dist/pool.node-chunks/{view-compiler-2D7HPYIN.js → view-compiler-HOFFL63K.js} +161 -425
- package/dist/pool.node.js +2 -2
- package/dist/stage-worker.browser.js +1940 -3262
- package/dist/stage-worker.node.js +2 -2
- package/package.json +3 -3
- package/dist/compile-core.node-chunks/chunk-23PCGQQU.js +0 -141
- package/dist/compile-core.node-chunks/chunk-QYHGF3MS.js +0 -1601
- package/dist/compile-core.node-chunks/style-compiler-4PHMBQIC.js +0 -470
- package/dist/pool.node-chunks/chunk-LGB3AH5C.js +0 -1601
- package/dist/pool.node-chunks/chunk-VHWKAXDL.js +0 -141
- package/dist/pool.node-chunks/style-compiler-W7EA2Y7R.js +0 -470
package/dist/compile-core.node-chunks/{logic-compiler-AEZPY2MO.js → logic-compiler-2SQFOFEO.js}
RENAMED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getWxMemberName,
|
|
3
|
-
takeCompatibilityWarnings,
|
|
4
3
|
warnUnsupportedWxApi
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-LUD2P6RM.js";
|
|
6
5
|
import {
|
|
7
6
|
isMainThread,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
remapSourcemap
|
|
11
|
-
} from "./chunk-23PCGQQU.js";
|
|
7
|
+
parentPort
|
|
8
|
+
} from "./chunk-2VRS523Z.js";
|
|
12
9
|
import {
|
|
13
10
|
collectAssets,
|
|
14
11
|
fs_default,
|
|
@@ -16,15 +13,13 @@ import {
|
|
|
16
13
|
getAppId,
|
|
17
14
|
getComponent,
|
|
18
15
|
getContentByPath,
|
|
19
|
-
getDependencyGraph,
|
|
20
16
|
getNpmResolver,
|
|
21
17
|
getTargetPath,
|
|
22
18
|
getWorkPath,
|
|
23
19
|
hasCompileInfo,
|
|
24
20
|
resetStoreInfo,
|
|
25
|
-
resolveAppAlias
|
|
26
|
-
|
|
27
|
-
} from "./chunk-M62ZDT7T.js";
|
|
21
|
+
resolveAppAlias
|
|
22
|
+
} from "./chunk-QJ34C5KK.js";
|
|
28
23
|
|
|
29
24
|
// ../../dimina/fe/packages/compiler/src/core/logic-compiler.js
|
|
30
25
|
import { resolve, sep } from "node:path";
|
|
@@ -32,6 +27,102 @@ import { parseSync } from "oxc-parser";
|
|
|
32
27
|
import { walk } from "oxc-walker";
|
|
33
28
|
import MagicString from "magic-string";
|
|
34
29
|
import { transform } from "esbuild";
|
|
30
|
+
|
|
31
|
+
// ../../dimina/fe/packages/compiler/src/core/sourcemap.js
|
|
32
|
+
import { SourceMapConsumer, SourceMapGenerator } from "source-map-js";
|
|
33
|
+
function wrapModDefine(module) {
|
|
34
|
+
const code = module.code.endsWith("\n") ? module.code : module.code + "\n";
|
|
35
|
+
const extraLine = module.extraInfoCode || "";
|
|
36
|
+
const header = `modDefine('${module.path}', function(require, module, exports) {
|
|
37
|
+
${extraLine}`;
|
|
38
|
+
const footer = "});\n";
|
|
39
|
+
return { header, code, footer };
|
|
40
|
+
}
|
|
41
|
+
function mergeSourcemap(compileRes) {
|
|
42
|
+
const smg = new SourceMapGenerator({ file: "logic.js" });
|
|
43
|
+
let bundleCode = "";
|
|
44
|
+
let lineOffset = 0;
|
|
45
|
+
for (const module of compileRes) {
|
|
46
|
+
const { header, code, footer } = wrapModDefine(module);
|
|
47
|
+
bundleCode += header;
|
|
48
|
+
const headerLineCount = header.split("\n").length - 1;
|
|
49
|
+
lineOffset += headerLineCount;
|
|
50
|
+
if (module.map) {
|
|
51
|
+
const moduleMap = JSON.parse(module.map);
|
|
52
|
+
const smc = new SourceMapConsumer(moduleMap);
|
|
53
|
+
smc.eachMapping((mapping) => {
|
|
54
|
+
if (mapping.source == null) return;
|
|
55
|
+
smg.addMapping({
|
|
56
|
+
generated: {
|
|
57
|
+
line: mapping.generatedLine + lineOffset,
|
|
58
|
+
column: mapping.generatedColumn
|
|
59
|
+
},
|
|
60
|
+
original: {
|
|
61
|
+
line: mapping.originalLine,
|
|
62
|
+
column: mapping.originalColumn
|
|
63
|
+
},
|
|
64
|
+
source: mapping.source,
|
|
65
|
+
name: mapping.name
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
if (moduleMap.sourcesContent) {
|
|
69
|
+
moduleMap.sources.forEach((src, i) => {
|
|
70
|
+
smg.setSourceContent(src, moduleMap.sourcesContent[i]);
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
bundleCode += code;
|
|
75
|
+
lineOffset += code.split("\n").length - 1;
|
|
76
|
+
bundleCode += footer;
|
|
77
|
+
lineOffset += footer.split("\n").length - 1;
|
|
78
|
+
}
|
|
79
|
+
return { bundleCode, sourcemap: smg.toString() };
|
|
80
|
+
}
|
|
81
|
+
function remapSourcemap(nextMap, prevMap) {
|
|
82
|
+
if (!nextMap) {
|
|
83
|
+
return prevMap;
|
|
84
|
+
}
|
|
85
|
+
if (!prevMap) {
|
|
86
|
+
return nextMap;
|
|
87
|
+
}
|
|
88
|
+
const nextMapObj = typeof nextMap === "string" ? JSON.parse(nextMap) : nextMap;
|
|
89
|
+
const prevMapObj = typeof prevMap === "string" ? JSON.parse(prevMap) : prevMap;
|
|
90
|
+
const smg = new SourceMapGenerator({ file: nextMapObj.file || prevMapObj.file || "" });
|
|
91
|
+
const prevSmc = new SourceMapConsumer(prevMapObj);
|
|
92
|
+
const nextSmc = new SourceMapConsumer(nextMapObj);
|
|
93
|
+
nextSmc.eachMapping((mapping) => {
|
|
94
|
+
if (mapping.source == null || mapping.originalLine == null || mapping.originalColumn == null) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const original = prevSmc.originalPositionFor({
|
|
98
|
+
line: mapping.originalLine,
|
|
99
|
+
column: mapping.originalColumn
|
|
100
|
+
});
|
|
101
|
+
if (original.source == null || original.line == null || original.column == null) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
smg.addMapping({
|
|
105
|
+
generated: {
|
|
106
|
+
line: mapping.generatedLine,
|
|
107
|
+
column: mapping.generatedColumn
|
|
108
|
+
},
|
|
109
|
+
original: {
|
|
110
|
+
line: original.line,
|
|
111
|
+
column: original.column
|
|
112
|
+
},
|
|
113
|
+
source: original.source,
|
|
114
|
+
name: original.name || mapping.name
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
if (prevMapObj.sourcesContent) {
|
|
118
|
+
prevMapObj.sources.forEach((src, i) => {
|
|
119
|
+
smg.setSourceContent(src, prevMapObj.sourcesContent[i]);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
return smg.toString();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// ../../dimina/fe/packages/compiler/src/core/logic-compiler.js
|
|
35
126
|
var processedModules = /* @__PURE__ */ new Set();
|
|
36
127
|
var enableSourcemap = false;
|
|
37
128
|
if (!isMainThread) {
|
|
@@ -66,11 +157,7 @@ ${error.stack}`);
|
|
|
66
157
|
}
|
|
67
158
|
await writeCompileRes(mainCompileRes, null);
|
|
68
159
|
processedModules.clear();
|
|
69
|
-
parentPort.postMessage({
|
|
70
|
-
success: true,
|
|
71
|
-
compatibilityWarnings: takeCompatibilityWarnings(),
|
|
72
|
-
dependencyGraph: getDependencyGraph().toJSON()
|
|
73
|
-
});
|
|
160
|
+
parentPort.postMessage({ success: true });
|
|
74
161
|
} catch (error) {
|
|
75
162
|
processedModules.clear();
|
|
76
163
|
parentPort.postMessage({
|
|
@@ -123,12 +210,18 @@ async function compileJS(pages, root, mainCompileRes, progress) {
|
|
|
123
210
|
}
|
|
124
211
|
return compileRes;
|
|
125
212
|
}
|
|
126
|
-
async function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra,
|
|
213
|
+
async function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
|
|
127
214
|
const currentPath = module.path;
|
|
128
|
-
if (
|
|
215
|
+
if (depthChain.includes(currentPath)) {
|
|
216
|
+
console.warn("[logic]", `\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
129
217
|
return;
|
|
130
218
|
}
|
|
131
|
-
if (
|
|
219
|
+
if (depthChain.length > 20) {
|
|
220
|
+
console.warn("[logic]", `\u68C0\u6D4B\u5230\u6DF1\u5EA6\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
depthChain = [...depthChain, currentPath];
|
|
224
|
+
if (!module.path) {
|
|
132
225
|
return;
|
|
133
226
|
}
|
|
134
227
|
if (hasCompileInfo(module.path, compileRes, mainCompileRes)) {
|
|
@@ -145,7 +238,6 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
145
238
|
console.warn("[logic]", `\u627E\u4E0D\u5230\u6A21\u5757\u6587\u4EF6: ${src}`);
|
|
146
239
|
return;
|
|
147
240
|
}
|
|
148
|
-
getDependencyGraph().addFile(currentPath, modulePath, "logic");
|
|
149
241
|
const diagnosticSource = modulePath.startsWith(getWorkPath()) ? modulePath.slice(getWorkPath().length) : src;
|
|
150
242
|
const sourceCode = getContentByPath(modulePath);
|
|
151
243
|
if (!sourceCode) {
|
|
@@ -166,19 +258,13 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
166
258
|
const extraInfo = {
|
|
167
259
|
path: module.path
|
|
168
260
|
};
|
|
169
|
-
activePaths.add(currentPath);
|
|
170
261
|
if (module.component) {
|
|
171
262
|
extraInfo.component = true;
|
|
172
263
|
}
|
|
173
264
|
if (module.usingComponents) {
|
|
174
265
|
const componentsObj = {};
|
|
175
266
|
const allSubPackages = getAppConfigInfo().subPackages;
|
|
176
|
-
const graphDependencies = getDependencyGraph().getDirectDependencies(module.path, "component");
|
|
177
|
-
const componentDependencies = graphDependencies.length > 0 ? new Set(graphDependencies) : null;
|
|
178
267
|
for (const [name, path] of Object.entries(module.usingComponents)) {
|
|
179
|
-
if (componentDependencies && !componentDependencies.has(path)) {
|
|
180
|
-
continue;
|
|
181
|
-
}
|
|
182
268
|
let toMainSubPackage = true;
|
|
183
269
|
if (packageName) {
|
|
184
270
|
const normalizedPath = path.startsWith("/") ? path.substring(1) : path;
|
|
@@ -195,7 +281,7 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
195
281
|
if (!componentModule) {
|
|
196
282
|
continue;
|
|
197
283
|
}
|
|
198
|
-
await buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true,
|
|
284
|
+
await buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, depthChain, putMain || toMainSubPackage);
|
|
199
285
|
componentsObj[name] = path;
|
|
200
286
|
}
|
|
201
287
|
extraInfo.usingComponents = componentsObj;
|
|
@@ -227,11 +313,6 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
227
313
|
);
|
|
228
314
|
}
|
|
229
315
|
if ((node.type === "StringLiteral" || node.type === "Literal") && isLocalAssetString(node.value)) {
|
|
230
|
-
getDependencyGraph().addFile(
|
|
231
|
-
currentPath,
|
|
232
|
-
resolveAssetSourcePath(getWorkPath(), modulePath, node.value),
|
|
233
|
-
"logic"
|
|
234
|
-
);
|
|
235
316
|
pathReplacements.push({
|
|
236
317
|
start: node.start,
|
|
237
318
|
end: node.end,
|
|
@@ -247,7 +328,6 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
247
328
|
if (requirePath) {
|
|
248
329
|
const { id, shouldProcess } = resolveDependencyId(requirePath, modulePath, false);
|
|
249
330
|
if (shouldProcess) {
|
|
250
|
-
getDependencyGraph().addDependency(currentPath, id, "logic");
|
|
251
331
|
pathReplacements.push({
|
|
252
332
|
start: arg.start,
|
|
253
333
|
end: arg.end,
|
|
@@ -265,7 +345,6 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
265
345
|
if (importPath) {
|
|
266
346
|
const { id, shouldProcess } = resolveDependencyId(importPath, modulePath, true);
|
|
267
347
|
if (shouldProcess) {
|
|
268
|
-
getDependencyGraph().addDependency(currentPath, id, "logic");
|
|
269
348
|
pathReplacements.push({
|
|
270
349
|
start: node.source.start,
|
|
271
350
|
end: node.source.end,
|
|
@@ -283,7 +362,6 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
283
362
|
if (importPath) {
|
|
284
363
|
const { id, shouldProcess } = resolveDependencyId(importPath, modulePath, false);
|
|
285
364
|
if (shouldProcess) {
|
|
286
|
-
getDependencyGraph().addDependency(currentPath, id, "logic");
|
|
287
365
|
pathReplacements.push({
|
|
288
366
|
start: importPathNode.start,
|
|
289
367
|
end: importPathNode.end,
|
|
@@ -300,7 +378,6 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
300
378
|
if (exportPath) {
|
|
301
379
|
const { id, shouldProcess } = resolveDependencyId(exportPath, modulePath, true);
|
|
302
380
|
if (shouldProcess) {
|
|
303
|
-
getDependencyGraph().addDependency(currentPath, id, "logic");
|
|
304
381
|
pathReplacements.push({
|
|
305
382
|
start: node.source.start,
|
|
306
383
|
end: node.source.end,
|
|
@@ -315,7 +392,7 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
315
392
|
}
|
|
316
393
|
});
|
|
317
394
|
for (const depId of dependenciesToProcess) {
|
|
318
|
-
await buildJSByPath(packageName, { path: depId }, compileRes, mainCompileRes, false,
|
|
395
|
+
await buildJSByPath(packageName, { path: depId }, compileRes, mainCompileRes, false, depthChain, putMain);
|
|
319
396
|
}
|
|
320
397
|
for (const replacement of pathReplacements.reverse()) {
|
|
321
398
|
s.overwrite(replacement.start, replacement.end, `'${replacement.newValue}'`);
|
|
@@ -356,7 +433,6 @@ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, ad
|
|
|
356
433
|
compileInfo.code = modifiedCode;
|
|
357
434
|
}
|
|
358
435
|
processedModules.add(packageName + currentPath);
|
|
359
|
-
activePaths.delete(currentPath);
|
|
360
436
|
}
|
|
361
437
|
function isLocalAssetString(value) {
|
|
362
438
|
return typeof value === "string" && !value.startsWith("http") && !value.startsWith("//") && (value.startsWith("/") || value.startsWith("./") || value.startsWith("../")) && /\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(value);
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isMainThread,
|
|
3
|
+
parentPort
|
|
4
|
+
} from "./chunk-2VRS523Z.js";
|
|
5
|
+
import {
|
|
6
|
+
collectAssets,
|
|
7
|
+
fs_default,
|
|
8
|
+
getAppId,
|
|
9
|
+
getComponent,
|
|
10
|
+
getContentByPath,
|
|
11
|
+
getStyleExts,
|
|
12
|
+
getTargetPath,
|
|
13
|
+
getWorkPath,
|
|
14
|
+
resetStoreInfo,
|
|
15
|
+
tagWhiteList,
|
|
16
|
+
transformRpx
|
|
17
|
+
} from "./chunk-QJ34C5KK.js";
|
|
18
|
+
|
|
19
|
+
// ../../dimina/fe/packages/compiler/src/core/style-compiler.js
|
|
20
|
+
import path from "node:path";
|
|
21
|
+
import { compileStyle } from "@vue/compiler-sfc";
|
|
22
|
+
import autoprefixer from "autoprefixer";
|
|
23
|
+
import cssnano from "cssnano";
|
|
24
|
+
import less from "less";
|
|
25
|
+
import postcss from "postcss";
|
|
26
|
+
import selectorParser from "postcss-selector-parser";
|
|
27
|
+
import * as sass from "sass";
|
|
28
|
+
var compileRes = /* @__PURE__ */ new Map();
|
|
29
|
+
if (!isMainThread) {
|
|
30
|
+
parentPort.on("message", async ({ pages, storeInfo }) => {
|
|
31
|
+
try {
|
|
32
|
+
resetStoreInfo(storeInfo);
|
|
33
|
+
const progress = {
|
|
34
|
+
_completedTasks: 0,
|
|
35
|
+
get completedTasks() {
|
|
36
|
+
return this._completedTasks;
|
|
37
|
+
},
|
|
38
|
+
set completedTasks(value) {
|
|
39
|
+
this._completedTasks = value;
|
|
40
|
+
parentPort.postMessage({ completedTasks: this._completedTasks });
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
await compileSS(pages.mainPages, null, progress);
|
|
44
|
+
for (const [root, subPages] of Object.entries(pages.subPages)) {
|
|
45
|
+
await compileSS(subPages.info, root, progress);
|
|
46
|
+
}
|
|
47
|
+
compileRes.clear();
|
|
48
|
+
parentPort.postMessage({ success: true });
|
|
49
|
+
} catch (error) {
|
|
50
|
+
compileRes.clear();
|
|
51
|
+
parentPort.postMessage({
|
|
52
|
+
success: false,
|
|
53
|
+
error: {
|
|
54
|
+
message: error.message,
|
|
55
|
+
stack: error.stack,
|
|
56
|
+
name: error.name
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
async function compileSS(pages, root, progress) {
|
|
63
|
+
for (const page of pages) {
|
|
64
|
+
const code = await buildCompileCss(page, [], /* @__PURE__ */ new Set()) || "";
|
|
65
|
+
const filename = `${page.path.replace(/\//g, "_")}`;
|
|
66
|
+
if (root) {
|
|
67
|
+
const subDir = `${getTargetPath()}/${root}`;
|
|
68
|
+
if (!fs_default.existsSync(subDir)) {
|
|
69
|
+
fs_default.mkdirSync(subDir, { recursive: true });
|
|
70
|
+
}
|
|
71
|
+
fs_default.writeFileSync(`${subDir}/${filename}.css`, code);
|
|
72
|
+
} else {
|
|
73
|
+
const mainDir = `${getTargetPath()}/main`;
|
|
74
|
+
if (!fs_default.existsSync(mainDir)) {
|
|
75
|
+
fs_default.mkdirSync(mainDir, { recursive: true });
|
|
76
|
+
}
|
|
77
|
+
fs_default.writeFileSync(`${mainDir}/${filename}.css`, code);
|
|
78
|
+
}
|
|
79
|
+
progress.completedTasks++;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async function buildCompileCss(module, depthChain = [], compiledPaths = /* @__PURE__ */ new Set()) {
|
|
83
|
+
const currentPath = module.path || module.absolutePath;
|
|
84
|
+
if (depthChain.includes(currentPath)) {
|
|
85
|
+
console.warn("[style]", `\u68C0\u6D4B\u5230\u5FAA\u73AF\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
86
|
+
return "";
|
|
87
|
+
}
|
|
88
|
+
if (depthChain.length > 20) {
|
|
89
|
+
console.warn("[style]", `\u68C0\u6D4B\u5230\u6DF1\u5EA6\u4F9D\u8D56: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
if (compiledPaths.has(currentPath)) {
|
|
93
|
+
return "";
|
|
94
|
+
}
|
|
95
|
+
compiledPaths.add(currentPath);
|
|
96
|
+
depthChain = [...depthChain, currentPath];
|
|
97
|
+
let result = await enhanceCSS(module) || "";
|
|
98
|
+
if (module.usingComponents) {
|
|
99
|
+
for (const componentInfo of Object.values(module.usingComponents)) {
|
|
100
|
+
const componentModule = getComponent(componentInfo);
|
|
101
|
+
if (!componentModule) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
result += await buildCompileCss(componentModule, depthChain, compiledPaths) || "";
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return result;
|
|
108
|
+
}
|
|
109
|
+
async function enhanceCSS(module) {
|
|
110
|
+
const absolutePath = module.absolutePath ? module.absolutePath : getAbsolutePath(module.path);
|
|
111
|
+
if (!absolutePath) {
|
|
112
|
+
return "";
|
|
113
|
+
}
|
|
114
|
+
const cacheKey = `${absolutePath}::${module.id || ""}`;
|
|
115
|
+
const inputCSS = getContentByPath(absolutePath);
|
|
116
|
+
if (!inputCSS) {
|
|
117
|
+
return "";
|
|
118
|
+
}
|
|
119
|
+
if (compileRes.has(cacheKey)) {
|
|
120
|
+
return compileRes.get(cacheKey);
|
|
121
|
+
}
|
|
122
|
+
let processedCSS = normalizeRootStyleImports(inputCSS);
|
|
123
|
+
const ext = path.extname(absolutePath).toLowerCase();
|
|
124
|
+
try {
|
|
125
|
+
if (ext === ".less") {
|
|
126
|
+
const result2 = await less.render(processedCSS, {
|
|
127
|
+
filename: absolutePath,
|
|
128
|
+
paths: [path.dirname(absolutePath), getWorkPath()]
|
|
129
|
+
});
|
|
130
|
+
processedCSS = result2.css;
|
|
131
|
+
} else if (ext === ".scss" || ext === ".sass") {
|
|
132
|
+
const result2 = sass.compileString(processedCSS, {
|
|
133
|
+
loadPaths: [path.dirname(absolutePath), getWorkPath()],
|
|
134
|
+
syntax: ext === ".sass" ? "indented" : "scss"
|
|
135
|
+
});
|
|
136
|
+
processedCSS = result2.css;
|
|
137
|
+
}
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error(`[style] \u9884\u5904\u7406\u5668\u7F16\u8BD1\u5931\u8D25 ${absolutePath}:`, error.message);
|
|
140
|
+
processedCSS = inputCSS;
|
|
141
|
+
}
|
|
142
|
+
const fixedCSS = ensureImportSemicolons(processedCSS);
|
|
143
|
+
let ast;
|
|
144
|
+
try {
|
|
145
|
+
ast = postcss.parse(fixedCSS);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
console.error(`[style] PostCSS \u89E3\u6790\u5931\u8D25 ${absolutePath}:`, error.message);
|
|
148
|
+
return "";
|
|
149
|
+
}
|
|
150
|
+
const promises = [];
|
|
151
|
+
ast.walk(async (node) => {
|
|
152
|
+
if (node.type === "atrule" && node.name === "import") {
|
|
153
|
+
const str = node.params.replace(/^['"]|['"]$/g, "");
|
|
154
|
+
const importFullPath = resolveStyleImportPath(absolutePath, str);
|
|
155
|
+
node.remove();
|
|
156
|
+
promises.push(buildCompileCss({ absolutePath: importFullPath, id: module.id }, [], /* @__PURE__ */ new Set()));
|
|
157
|
+
} else if (node.type === "rule") {
|
|
158
|
+
if (node.selector.includes("::v-deep")) {
|
|
159
|
+
node.selector = node.selector.replace(/::v-deep\s+(\S[^{]*)/g, ":deep($1)");
|
|
160
|
+
}
|
|
161
|
+
if (node.selector.includes(":host")) {
|
|
162
|
+
node.selector = processHostSelector(node.selector, module.id);
|
|
163
|
+
}
|
|
164
|
+
node.selector = selectorParser((selectors) => {
|
|
165
|
+
selectors.walkTags((tag) => {
|
|
166
|
+
if (tagWhiteList.includes(tag.value)) {
|
|
167
|
+
tag.value = `.dd-${tag.value}`;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
}).processSync(node.selector);
|
|
171
|
+
} else if (node.type === "comment") {
|
|
172
|
+
node.remove();
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
ast.walkDecls((decl) => {
|
|
176
|
+
decl.value = normalizeCssUrlValue(decl.value, absolutePath);
|
|
177
|
+
decl.value = transformRpx(decl.value);
|
|
178
|
+
});
|
|
179
|
+
const cssCode = ast.toResult().css;
|
|
180
|
+
const moduleId = module.id;
|
|
181
|
+
const scopedCode = compileStyle({
|
|
182
|
+
source: cssCode,
|
|
183
|
+
id: moduleId,
|
|
184
|
+
scoped: !!moduleId
|
|
185
|
+
}).code;
|
|
186
|
+
const cleanedCode = await removeBaseComponentScope(scopedCode, moduleId);
|
|
187
|
+
const res = await postcss([
|
|
188
|
+
autoprefixer({ overrideBrowserslist: ["cover 99.5%"] }),
|
|
189
|
+
cssnano()
|
|
190
|
+
]).process(cleanedCode, { from: void 0 });
|
|
191
|
+
const importCss = (await Promise.all(promises)).filter(Boolean).join("");
|
|
192
|
+
const result = importCss + res.css;
|
|
193
|
+
compileRes.set(cacheKey, result);
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
function normalizeCssUrlValue(value, absolutePath) {
|
|
197
|
+
return value.replace(/url\(([^)]+)\)/g, (fullMatch, rawUrl) => {
|
|
198
|
+
const cleanedUrl = rawUrl.trim().replace(/^['"]|['"]$/g, "");
|
|
199
|
+
if (!cleanedUrl || cleanedUrl.startsWith("data:image")) {
|
|
200
|
+
return fullMatch;
|
|
201
|
+
}
|
|
202
|
+
if (cleanedUrl.startsWith("//")) {
|
|
203
|
+
return `url(https:${cleanedUrl})`;
|
|
204
|
+
}
|
|
205
|
+
if (/^(https?:|blob:|data:)/.test(cleanedUrl)) {
|
|
206
|
+
return fullMatch;
|
|
207
|
+
}
|
|
208
|
+
const realSrc = collectAssets(getWorkPath(), absolutePath, cleanedUrl, getTargetPath(), getAppId());
|
|
209
|
+
return `url(${realSrc})`;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function getAbsolutePath(modulePath) {
|
|
213
|
+
const workPath = getWorkPath();
|
|
214
|
+
const src = modulePath.startsWith("/") ? modulePath : `/${modulePath}`;
|
|
215
|
+
for (const ssType of getStyleExts()) {
|
|
216
|
+
const ssFullPath = `${workPath}${src}${ssType}`;
|
|
217
|
+
if (fs_default.existsSync(ssFullPath)) {
|
|
218
|
+
return ssFullPath;
|
|
219
|
+
}
|
|
220
|
+
const indexSsFullPath = `${workPath}${src}/index${ssType}`;
|
|
221
|
+
if (fs_default.existsSync(indexSsFullPath)) {
|
|
222
|
+
return indexSsFullPath;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
function resolveStyleImportPath(absolutePath, importPath, workPath = getWorkPath()) {
|
|
227
|
+
if (importPath.startsWith("/")) {
|
|
228
|
+
return path.join(workPath, importPath);
|
|
229
|
+
}
|
|
230
|
+
return path.resolve(path.dirname(absolutePath), importPath);
|
|
231
|
+
}
|
|
232
|
+
function normalizeRootStyleImports(source, workPath = getWorkPath()) {
|
|
233
|
+
return source.replace(/(@import\s+(?:\(.*?\)\s*)?(?:url\()?['"])(\/[^'")]+)(['"]\)?)/g, (_, prefix, importPath, suffix) => {
|
|
234
|
+
return `${prefix}${path.join(workPath, importPath)}${suffix}`;
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
async function removeBaseComponentScope(css, moduleId) {
|
|
238
|
+
if (!moduleId) return css;
|
|
239
|
+
const ast = postcss.parse(css);
|
|
240
|
+
const scopeAttrName = `data-v-${moduleId}`;
|
|
241
|
+
ast.walkRules((rule) => {
|
|
242
|
+
const hasBaseComponent = tagWhiteList.some(
|
|
243
|
+
(tag) => rule.selector.includes(`.dd-${tag}`)
|
|
244
|
+
);
|
|
245
|
+
if (hasBaseComponent && rule.selector.includes(scopeAttrName)) {
|
|
246
|
+
rule.selector = selectorParser((selectors) => {
|
|
247
|
+
selectors.walkAttributes((attr) => {
|
|
248
|
+
if (attr.attribute === scopeAttrName) {
|
|
249
|
+
attr.remove();
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
}).processSync(rule.selector);
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
return ast.toResult().css;
|
|
256
|
+
}
|
|
257
|
+
function ensureImportSemicolons(css) {
|
|
258
|
+
return css.replace(/@import[^;\n]*$/gm, (match) => {
|
|
259
|
+
return match.endsWith(";") ? match : `${match};`;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function processHostSelector(selector, moduleId) {
|
|
263
|
+
return selector.replace(/^:host$/, `[data-v-${moduleId}]`).replace(/:host\(([^)]+)\)/g, `[data-v-${moduleId}]$1`).replace(/:host\s+/g, `[data-v-${moduleId}] `).replace(/:host(?=\.|#|:)/g, `[data-v-${moduleId}]`);
|
|
264
|
+
}
|
|
265
|
+
function __resetStyleState() {
|
|
266
|
+
compileRes.clear();
|
|
267
|
+
}
|
|
268
|
+
export {
|
|
269
|
+
__resetStyleState,
|
|
270
|
+
compileSS,
|
|
271
|
+
ensureImportSemicolons,
|
|
272
|
+
normalizeCssUrlValue,
|
|
273
|
+
normalizeRootStyleImports,
|
|
274
|
+
processHostSelector,
|
|
275
|
+
removeBaseComponentScope,
|
|
276
|
+
resolveStyleImportPath
|
|
277
|
+
};
|