@dimina/compiler 1.0.6 → 1.0.7
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 +3 -3
- package/dist/bin/index.js +3 -3
- package/dist/core/logic-compiler.cjs +37 -24
- package/dist/core/logic-compiler.js +37 -25
- package/dist/core/style-compiler.cjs +20 -15
- package/dist/core/style-compiler.js +19 -15
- package/dist/core/view-compiler.cjs +152 -119
- package/dist/core/view-compiler.js +150 -118
- package/dist/{env-Chow6VXH.cjs → env-CGYKCSjT.cjs} +35 -11
- package/dist/{env-CezfCSQz.js → env-fkuCnng-.js} +41 -17
- package/dist/index.cjs +65 -37
- package/dist/index.js +65 -37
- package/package.json +9 -10
package/dist/bin/index.cjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
const process = require("node:process");
|
|
4
3
|
const path = require("node:path");
|
|
5
|
-
const
|
|
4
|
+
const process = require("node:process");
|
|
6
5
|
const chokidar = require("chokidar");
|
|
6
|
+
const commander = require("commander");
|
|
7
7
|
const index = require("../index.cjs");
|
|
8
|
-
const version = "1.0.
|
|
8
|
+
const version = "1.0.7";
|
|
9
9
|
const pack = {
|
|
10
10
|
version
|
|
11
11
|
};
|
package/dist/bin/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import process from "node:process";
|
|
3
2
|
import path from "node:path";
|
|
4
|
-
import
|
|
3
|
+
import process from "node:process";
|
|
5
4
|
import chokidar from "chokidar";
|
|
5
|
+
import { program } from "commander";
|
|
6
6
|
import build from "../index.js";
|
|
7
|
-
const version = "1.0.
|
|
7
|
+
const version = "1.0.7";
|
|
8
8
|
const pack = {
|
|
9
9
|
version
|
|
10
10
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
3
|
const fs = require("node:fs");
|
|
3
4
|
const path = require("node:path");
|
|
4
5
|
const node_worker_threads = require("node:worker_threads");
|
|
5
6
|
const babel = require("@babel/core");
|
|
6
|
-
const types = require("@babel/types");
|
|
7
7
|
const _traverse = require("@babel/traverse");
|
|
8
|
+
const types = require("@babel/types");
|
|
8
9
|
const esbuild = require("esbuild");
|
|
9
|
-
const env = require("../env-
|
|
10
|
+
const env = require("../env-CGYKCSjT.cjs");
|
|
10
11
|
const traverse = _traverse.default ? _traverse.default : _traverse;
|
|
11
12
|
const processedModules = /* @__PURE__ */ new Set();
|
|
12
13
|
if (!node_worker_threads.isMainThread) {
|
|
@@ -25,18 +26,33 @@ if (!node_worker_threads.isMainThread) {
|
|
|
25
26
|
};
|
|
26
27
|
const mainCompileRes = await compileJS(pages.mainPages, null, null, progress);
|
|
27
28
|
for (const [root, subPages] of Object.entries(pages.subPages)) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
try {
|
|
30
|
+
const subCompileRes = await compileJS(
|
|
31
|
+
subPages.info,
|
|
32
|
+
root,
|
|
33
|
+
subPages.independent ? [] : mainCompileRes,
|
|
34
|
+
progress
|
|
35
|
+
);
|
|
36
|
+
await writeCompileRes(subCompileRes, root);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
throw new Error(`Error processing subpackage ${root}: ${error.message}
|
|
39
|
+
${error.stack}`);
|
|
40
|
+
}
|
|
35
41
|
}
|
|
36
42
|
await writeCompileRes(mainCompileRes, null);
|
|
37
43
|
node_worker_threads.parentPort.postMessage({ success: true });
|
|
38
44
|
} catch (error) {
|
|
39
|
-
node_worker_threads.parentPort.postMessage({
|
|
45
|
+
node_worker_threads.parentPort.postMessage({
|
|
46
|
+
success: false,
|
|
47
|
+
error: {
|
|
48
|
+
message: error.message,
|
|
49
|
+
stack: error.stack,
|
|
50
|
+
name: error.name,
|
|
51
|
+
file: error.file || null,
|
|
52
|
+
line: error.line || null,
|
|
53
|
+
code: error.code || null
|
|
54
|
+
}
|
|
55
|
+
});
|
|
40
56
|
}
|
|
41
57
|
});
|
|
42
58
|
}
|
|
@@ -63,7 +79,7 @@ ${module2.code}
|
|
|
63
79
|
} else {
|
|
64
80
|
const mainDir = `${env.getTargetPath()}/main`;
|
|
65
81
|
if (!fs.existsSync(mainDir)) {
|
|
66
|
-
fs.mkdirSync(mainDir);
|
|
82
|
+
fs.mkdirSync(mainDir, { recursive: true });
|
|
67
83
|
}
|
|
68
84
|
fs.writeFileSync(`${mainDir}/logic.js`, mergeCode);
|
|
69
85
|
}
|
|
@@ -82,10 +98,12 @@ async function compileJS(pages, root, mainCompileRes, progress) {
|
|
|
82
98
|
function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
|
|
83
99
|
const currentPath = module2.path;
|
|
84
100
|
if (depthChain.includes(currentPath)) {
|
|
85
|
-
console.warn(`检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
101
|
+
console.warn("[logic]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
102
|
+
return;
|
|
86
103
|
}
|
|
87
|
-
if (depthChain.length >
|
|
88
|
-
console.warn(`检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
104
|
+
if (depthChain.length > 20) {
|
|
105
|
+
console.warn("[logic]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
106
|
+
return;
|
|
89
107
|
}
|
|
90
108
|
depthChain = [...depthChain, currentPath];
|
|
91
109
|
if (!module2.path) {
|
|
@@ -115,7 +133,6 @@ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtr
|
|
|
115
133
|
for (const [name, path2] of Object.entries(module2.usingComponents)) {
|
|
116
134
|
let toMainSubPackage = true;
|
|
117
135
|
if (packageName) {
|
|
118
|
-
const rootPackageName = packageName.startsWith("sub_") ? packageName.slice(4) : packageName;
|
|
119
136
|
const normalizedPath = path2.startsWith("/") ? path2.substring(1) : path2;
|
|
120
137
|
for (const subPackage of allSubPackages) {
|
|
121
138
|
if (normalizedPath.startsWith(`${subPackage.root}/`)) {
|
|
@@ -123,11 +140,6 @@ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtr
|
|
|
123
140
|
break;
|
|
124
141
|
}
|
|
125
142
|
}
|
|
126
|
-
if (!toMainSubPackage) {
|
|
127
|
-
if (!normalizedPath.startsWith(`${rootPackageName}/`)) {
|
|
128
|
-
continue;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
143
|
} else {
|
|
132
144
|
toMainSubPackage = false;
|
|
133
145
|
}
|
|
@@ -155,9 +167,9 @@ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtr
|
|
|
155
167
|
const requirePath = ap.node.arguments[0].value;
|
|
156
168
|
if (requirePath) {
|
|
157
169
|
const requireFullPath = path.resolve(modulePath, `../${requirePath}`);
|
|
158
|
-
const id = requireFullPath.split(`${env.getWorkPath()}
|
|
170
|
+
const id = requireFullPath.split(`${env.getWorkPath()}${path.sep}`)[1].split(".js")[0].replace(/\\/g, "/");
|
|
159
171
|
ap.node.arguments[0] = types.stringLiteral(id);
|
|
160
|
-
if (!processedModules.has(id)) {
|
|
172
|
+
if (!processedModules.has(packageName + id)) {
|
|
161
173
|
buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false, depthChain);
|
|
162
174
|
}
|
|
163
175
|
}
|
|
@@ -168,7 +180,7 @@ function buildJSByPath(packageName, module2, compileRes, mainCompileRes, addExtr
|
|
|
168
180
|
comments: false
|
|
169
181
|
});
|
|
170
182
|
compileInfo.code = code;
|
|
171
|
-
processedModules.add(currentPath);
|
|
183
|
+
processedModules.add(packageName + currentPath);
|
|
172
184
|
}
|
|
173
185
|
function getExtraInfoStatement(type, addedArgs) {
|
|
174
186
|
const propertyAssignment = types.objectProperty(types.identifier("__extraInfo"), addedArgs);
|
|
@@ -181,4 +193,5 @@ function getExtraInfoStatement(type, addedArgs) {
|
|
|
181
193
|
);
|
|
182
194
|
return propertyAssignmentStatement;
|
|
183
195
|
}
|
|
184
|
-
|
|
196
|
+
exports.buildJSByPath = buildJSByPath;
|
|
197
|
+
exports.compileJS = compileJS;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
|
-
import { resolve } from "node:path";
|
|
2
|
+
import { resolve, sep } from "node:path";
|
|
3
3
|
import { isMainThread, parentPort } from "node:worker_threads";
|
|
4
4
|
import babel from "@babel/core";
|
|
5
|
-
import types from "@babel/types";
|
|
6
5
|
import _traverse from "@babel/traverse";
|
|
6
|
+
import types from "@babel/types";
|
|
7
7
|
import { transform } from "esbuild";
|
|
8
|
-
import { r as resetStoreInfo, g as getTargetPath, i as hasCompileInfo,
|
|
8
|
+
import { r as resetStoreInfo, g as getTargetPath, i as hasCompileInfo, d as getWorkPath, b as getContentByPath, j as getAppConfigInfo, a as getComponent } from "../env-fkuCnng-.js";
|
|
9
9
|
const traverse = _traverse.default ? _traverse.default : _traverse;
|
|
10
10
|
const processedModules = /* @__PURE__ */ new Set();
|
|
11
11
|
if (!isMainThread) {
|
|
@@ -24,18 +24,33 @@ if (!isMainThread) {
|
|
|
24
24
|
};
|
|
25
25
|
const mainCompileRes = await compileJS(pages.mainPages, null, null, progress);
|
|
26
26
|
for (const [root, subPages] of Object.entries(pages.subPages)) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
try {
|
|
28
|
+
const subCompileRes = await compileJS(
|
|
29
|
+
subPages.info,
|
|
30
|
+
root,
|
|
31
|
+
subPages.independent ? [] : mainCompileRes,
|
|
32
|
+
progress
|
|
33
|
+
);
|
|
34
|
+
await writeCompileRes(subCompileRes, root);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
throw new Error(`Error processing subpackage ${root}: ${error.message}
|
|
37
|
+
${error.stack}`);
|
|
38
|
+
}
|
|
34
39
|
}
|
|
35
40
|
await writeCompileRes(mainCompileRes, null);
|
|
36
41
|
parentPort.postMessage({ success: true });
|
|
37
42
|
} catch (error) {
|
|
38
|
-
parentPort.postMessage({
|
|
43
|
+
parentPort.postMessage({
|
|
44
|
+
success: false,
|
|
45
|
+
error: {
|
|
46
|
+
message: error.message,
|
|
47
|
+
stack: error.stack,
|
|
48
|
+
name: error.name,
|
|
49
|
+
file: error.file || null,
|
|
50
|
+
line: error.line || null,
|
|
51
|
+
code: error.code || null
|
|
52
|
+
}
|
|
53
|
+
});
|
|
39
54
|
}
|
|
40
55
|
});
|
|
41
56
|
}
|
|
@@ -62,7 +77,7 @@ ${module.code}
|
|
|
62
77
|
} else {
|
|
63
78
|
const mainDir = `${getTargetPath()}/main`;
|
|
64
79
|
if (!fs.existsSync(mainDir)) {
|
|
65
|
-
fs.mkdirSync(mainDir);
|
|
80
|
+
fs.mkdirSync(mainDir, { recursive: true });
|
|
66
81
|
}
|
|
67
82
|
fs.writeFileSync(`${mainDir}/logic.js`, mergeCode);
|
|
68
83
|
}
|
|
@@ -81,10 +96,12 @@ async function compileJS(pages, root, mainCompileRes, progress) {
|
|
|
81
96
|
function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra, depthChain = [], putMain = false) {
|
|
82
97
|
const currentPath = module.path;
|
|
83
98
|
if (depthChain.includes(currentPath)) {
|
|
84
|
-
console.warn(`检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
99
|
+
console.warn("[logic]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
100
|
+
return;
|
|
85
101
|
}
|
|
86
|
-
if (depthChain.length >
|
|
87
|
-
console.warn(`检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
102
|
+
if (depthChain.length > 20) {
|
|
103
|
+
console.warn("[logic]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
104
|
+
return;
|
|
88
105
|
}
|
|
89
106
|
depthChain = [...depthChain, currentPath];
|
|
90
107
|
if (!module.path) {
|
|
@@ -114,7 +131,6 @@ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra
|
|
|
114
131
|
for (const [name, path] of Object.entries(module.usingComponents)) {
|
|
115
132
|
let toMainSubPackage = true;
|
|
116
133
|
if (packageName) {
|
|
117
|
-
const rootPackageName = packageName.startsWith("sub_") ? packageName.slice(4) : packageName;
|
|
118
134
|
const normalizedPath = path.startsWith("/") ? path.substring(1) : path;
|
|
119
135
|
for (const subPackage of allSubPackages) {
|
|
120
136
|
if (normalizedPath.startsWith(`${subPackage.root}/`)) {
|
|
@@ -122,11 +138,6 @@ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra
|
|
|
122
138
|
break;
|
|
123
139
|
}
|
|
124
140
|
}
|
|
125
|
-
if (!toMainSubPackage) {
|
|
126
|
-
if (!normalizedPath.startsWith(`${rootPackageName}/`)) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
141
|
} else {
|
|
131
142
|
toMainSubPackage = false;
|
|
132
143
|
}
|
|
@@ -154,9 +165,9 @@ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra
|
|
|
154
165
|
const requirePath = ap.node.arguments[0].value;
|
|
155
166
|
if (requirePath) {
|
|
156
167
|
const requireFullPath = resolve(modulePath, `../${requirePath}`);
|
|
157
|
-
const id = requireFullPath.split(`${getWorkPath()}
|
|
168
|
+
const id = requireFullPath.split(`${getWorkPath()}${sep}`)[1].split(".js")[0].replace(/\\/g, "/");
|
|
158
169
|
ap.node.arguments[0] = types.stringLiteral(id);
|
|
159
|
-
if (!processedModules.has(id)) {
|
|
170
|
+
if (!processedModules.has(packageName + id)) {
|
|
160
171
|
buildJSByPath(packageName, { path: id }, compileRes, mainCompileRes, false, depthChain);
|
|
161
172
|
}
|
|
162
173
|
}
|
|
@@ -167,7 +178,7 @@ function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra
|
|
|
167
178
|
comments: false
|
|
168
179
|
});
|
|
169
180
|
compileInfo.code = code;
|
|
170
|
-
processedModules.add(currentPath);
|
|
181
|
+
processedModules.add(packageName + currentPath);
|
|
171
182
|
}
|
|
172
183
|
function getExtraInfoStatement(type, addedArgs) {
|
|
173
184
|
const propertyAssignment = types.objectProperty(types.identifier("__extraInfo"), addedArgs);
|
|
@@ -181,5 +192,6 @@ function getExtraInfoStatement(type, addedArgs) {
|
|
|
181
192
|
return propertyAssignmentStatement;
|
|
182
193
|
}
|
|
183
194
|
export {
|
|
184
|
-
|
|
195
|
+
buildJSByPath,
|
|
196
|
+
compileJS
|
|
185
197
|
};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
3
|
const fs = require("node:fs");
|
|
3
4
|
const path = require("node:path");
|
|
4
5
|
const node_worker_threads = require("node:worker_threads");
|
|
5
|
-
const
|
|
6
|
+
const compilerSfc = require("@vue/compiler-sfc");
|
|
6
7
|
const autoprefixer = require("autoprefixer");
|
|
7
|
-
const selectorParser = require("postcss-selector-parser");
|
|
8
8
|
const cssnano = require("cssnano");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const postcss = require("postcss");
|
|
10
|
+
const selectorParser = require("postcss-selector-parser");
|
|
11
|
+
const env = require("../env-CGYKCSjT.cjs");
|
|
11
12
|
const fileType = [".wxss", ".ddss"];
|
|
12
13
|
const compileRes = /* @__PURE__ */ new Map();
|
|
13
|
-
const processedModules = /* @__PURE__ */ new Set();
|
|
14
14
|
if (!node_worker_threads.isMainThread) {
|
|
15
15
|
node_worker_threads.parentPort.on("message", async ({ pages, storeInfo }) => {
|
|
16
16
|
try {
|
|
@@ -42,13 +42,13 @@ async function compileSS(pages, root, progress) {
|
|
|
42
42
|
if (root) {
|
|
43
43
|
const subDir = `${env.getTargetPath()}/${root}`;
|
|
44
44
|
if (!fs.existsSync(subDir)) {
|
|
45
|
-
fs.mkdirSync(subDir);
|
|
45
|
+
fs.mkdirSync(subDir, { recursive: true });
|
|
46
46
|
}
|
|
47
47
|
fs.writeFileSync(`${subDir}/${filename}.css`, code);
|
|
48
48
|
} else {
|
|
49
49
|
const mainDir = `${env.getTargetPath()}/main`;
|
|
50
50
|
if (!fs.existsSync(mainDir)) {
|
|
51
|
-
fs.mkdirSync(mainDir);
|
|
51
|
+
fs.mkdirSync(mainDir, { recursive: true });
|
|
52
52
|
}
|
|
53
53
|
fs.writeFileSync(`${mainDir}/${filename}.css`, code);
|
|
54
54
|
}
|
|
@@ -58,10 +58,12 @@ async function compileSS(pages, root, progress) {
|
|
|
58
58
|
async function buildCompileCss(module2, depthChain = []) {
|
|
59
59
|
const currentPath = module2.path;
|
|
60
60
|
if (depthChain.includes(currentPath)) {
|
|
61
|
-
console.warn(`检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
61
|
+
console.warn("[style]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
62
|
+
return;
|
|
62
63
|
}
|
|
63
|
-
if (depthChain.length >
|
|
64
|
-
console.warn(`检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
64
|
+
if (depthChain.length > 20) {
|
|
65
|
+
console.warn("[style]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
66
|
+
return;
|
|
65
67
|
}
|
|
66
68
|
depthChain = [...depthChain, currentPath];
|
|
67
69
|
let result = await enhanceCSS(module2) || "";
|
|
@@ -74,7 +76,6 @@ async function buildCompileCss(module2, depthChain = []) {
|
|
|
74
76
|
result += await buildCompileCss(componentModule, depthChain);
|
|
75
77
|
}
|
|
76
78
|
}
|
|
77
|
-
processedModules.add(currentPath);
|
|
78
79
|
return result;
|
|
79
80
|
}
|
|
80
81
|
async function enhanceCSS(module2) {
|
|
@@ -89,9 +90,7 @@ async function enhanceCSS(module2) {
|
|
|
89
90
|
if (compileRes.has(absolutePath)) {
|
|
90
91
|
return compileRes.get(absolutePath);
|
|
91
92
|
}
|
|
92
|
-
const fixedCSS = inputCSS
|
|
93
|
-
return match.endsWith(";") ? match : `${match};`;
|
|
94
|
-
});
|
|
93
|
+
const fixedCSS = ensureImportSemicolons(inputCSS);
|
|
95
94
|
const ast = postcss.parse(fixedCSS);
|
|
96
95
|
const promises = [];
|
|
97
96
|
ast.walk(async (node) => {
|
|
@@ -153,4 +152,10 @@ function getAbsolutePath(modulePath) {
|
|
|
153
152
|
}
|
|
154
153
|
}
|
|
155
154
|
}
|
|
156
|
-
|
|
155
|
+
function ensureImportSemicolons(css) {
|
|
156
|
+
return css.replace(/@import[^;\n]*$/gm, (match) => {
|
|
157
|
+
return match.endsWith(";") ? match : `${match};`;
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
exports.compileSS = compileSS;
|
|
161
|
+
exports.ensureImportSemicolons = ensureImportSemicolons;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { isMainThread, parentPort } from "node:worker_threads";
|
|
4
|
-
import
|
|
4
|
+
import { compileStyle } from "@vue/compiler-sfc";
|
|
5
5
|
import autoprefixer from "autoprefixer";
|
|
6
|
-
import selectorParser from "postcss-selector-parser";
|
|
7
6
|
import cssnano from "cssnano";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
7
|
+
import postcss from "postcss";
|
|
8
|
+
import selectorParser from "postcss-selector-parser";
|
|
9
|
+
import { r as resetStoreInfo, g as getTargetPath, a as getComponent, b as getContentByPath, h as tagWhiteList, e as collectAssets, f as getAppId, d as getWorkPath, t as transformRpx } from "../env-fkuCnng-.js";
|
|
10
10
|
const fileType = [".wxss", ".ddss"];
|
|
11
11
|
const compileRes = /* @__PURE__ */ new Map();
|
|
12
|
-
const processedModules = /* @__PURE__ */ new Set();
|
|
13
12
|
if (!isMainThread) {
|
|
14
13
|
parentPort.on("message", async ({ pages, storeInfo }) => {
|
|
15
14
|
try {
|
|
@@ -41,13 +40,13 @@ async function compileSS(pages, root, progress) {
|
|
|
41
40
|
if (root) {
|
|
42
41
|
const subDir = `${getTargetPath()}/${root}`;
|
|
43
42
|
if (!fs.existsSync(subDir)) {
|
|
44
|
-
fs.mkdirSync(subDir);
|
|
43
|
+
fs.mkdirSync(subDir, { recursive: true });
|
|
45
44
|
}
|
|
46
45
|
fs.writeFileSync(`${subDir}/${filename}.css`, code);
|
|
47
46
|
} else {
|
|
48
47
|
const mainDir = `${getTargetPath()}/main`;
|
|
49
48
|
if (!fs.existsSync(mainDir)) {
|
|
50
|
-
fs.mkdirSync(mainDir);
|
|
49
|
+
fs.mkdirSync(mainDir, { recursive: true });
|
|
51
50
|
}
|
|
52
51
|
fs.writeFileSync(`${mainDir}/${filename}.css`, code);
|
|
53
52
|
}
|
|
@@ -57,10 +56,12 @@ async function compileSS(pages, root, progress) {
|
|
|
57
56
|
async function buildCompileCss(module, depthChain = []) {
|
|
58
57
|
const currentPath = module.path;
|
|
59
58
|
if (depthChain.includes(currentPath)) {
|
|
60
|
-
console.warn(`检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
59
|
+
console.warn("[style]", `检测到循环依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
60
|
+
return;
|
|
61
61
|
}
|
|
62
|
-
if (depthChain.length >
|
|
63
|
-
console.warn(`检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
62
|
+
if (depthChain.length > 20) {
|
|
63
|
+
console.warn("[style]", `检测到深度依赖: ${[...depthChain, currentPath].join(" -> ")}`);
|
|
64
|
+
return;
|
|
64
65
|
}
|
|
65
66
|
depthChain = [...depthChain, currentPath];
|
|
66
67
|
let result = await enhanceCSS(module) || "";
|
|
@@ -73,7 +74,6 @@ async function buildCompileCss(module, depthChain = []) {
|
|
|
73
74
|
result += await buildCompileCss(componentModule, depthChain);
|
|
74
75
|
}
|
|
75
76
|
}
|
|
76
|
-
processedModules.add(currentPath);
|
|
77
77
|
return result;
|
|
78
78
|
}
|
|
79
79
|
async function enhanceCSS(module) {
|
|
@@ -88,9 +88,7 @@ async function enhanceCSS(module) {
|
|
|
88
88
|
if (compileRes.has(absolutePath)) {
|
|
89
89
|
return compileRes.get(absolutePath);
|
|
90
90
|
}
|
|
91
|
-
const fixedCSS = inputCSS
|
|
92
|
-
return match.endsWith(";") ? match : `${match};`;
|
|
93
|
-
});
|
|
91
|
+
const fixedCSS = ensureImportSemicolons(inputCSS);
|
|
94
92
|
const ast = postcss.parse(fixedCSS);
|
|
95
93
|
const promises = [];
|
|
96
94
|
ast.walk(async (node) => {
|
|
@@ -152,6 +150,12 @@ function getAbsolutePath(modulePath) {
|
|
|
152
150
|
}
|
|
153
151
|
}
|
|
154
152
|
}
|
|
153
|
+
function ensureImportSemicolons(css) {
|
|
154
|
+
return css.replace(/@import[^;\n]*$/gm, (match) => {
|
|
155
|
+
return match.endsWith(";") ? match : `${match};`;
|
|
156
|
+
});
|
|
157
|
+
}
|
|
155
158
|
export {
|
|
156
|
-
compileSS
|
|
159
|
+
compileSS,
|
|
160
|
+
ensureImportSemicolons
|
|
157
161
|
};
|