@neuxnet/neux-cli 0.2.3
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 +438 -0
- package/README.zh-CN.md +554 -0
- package/assets/container/assets/index.css +1 -0
- package/assets/container/assets/index.js +137 -0
- package/assets/container/assets/pageFrame.css +1 -0
- package/assets/container/assets/pageFrame.js +56 -0
- package/assets/container/assets/service.js +6 -0
- package/assets/container/assets/vconsole.js +931 -0
- package/assets/container/favicon.ico +0 -0
- package/assets/container/images/icon-arrow.png +0 -0
- package/assets/container/images/mini-action-white.png +0 -0
- package/assets/container/images/mini-action.png +0 -0
- package/assets/container/images/mini-arrow-left-white.png +0 -0
- package/assets/container/images/mini-arrow-left.jpg +0 -0
- package/assets/container/images/mini-arrow-left.png +0 -0
- package/assets/container/images/mini-close-white.png +0 -0
- package/assets/container/images/mini-close.png +0 -0
- package/assets/container/images/more.png +0 -0
- package/assets/container/images/search.jpg +0 -0
- package/assets/container/index.html +1 -0
- package/assets/container/pageFrame.html +1 -0
- package/assets/init/tabbar/home-active.png +0 -0
- package/assets/init/tabbar/home.png +0 -0
- package/assets/init/tabbar/list-active.png +0 -0
- package/assets/init/tabbar/list.png +0 -0
- package/assets/init/types/neux-api.d.ts +1402 -0
- package/package.json +68 -0
- package/scripts/generate-init-types.js +210 -0
- package/scripts/sync-compiler.js +22 -0
- package/scripts/sync-web-container.js +34 -0
- package/src/bin/cli.js +646 -0
- package/src/core/brand.js +11 -0
- package/src/core/compiler.js +305 -0
- package/src/core/defaults.js +12 -0
- package/src/core/dev.js +15 -0
- package/src/core/errors.js +17 -0
- package/src/core/fs.js +66 -0
- package/src/core/i18n.js +37 -0
- package/src/core/init.js +866 -0
- package/src/core/lifecycle.js +32 -0
- package/src/core/manifest.js +72 -0
- package/src/core/pack.js +156 -0
- package/src/core/package-info.js +27 -0
- package/src/core/preview-server.js +123 -0
- package/src/core/project.js +101 -0
- package/src/core/prompts.js +71 -0
- package/src/core/proxy-security.js +141 -0
- package/src/core/proxy.js +156 -0
- package/src/core/qr.js +41 -0
- package/src/core/terminal-qr.js +72 -0
- package/src/core/update.js +278 -0
- package/src/core/watch.js +113 -0
- package/src/core/web.js +649 -0
- package/src/core/zip.js +120 -0
- package/src/index.js +20 -0
- package/src/providers/service-client.js +149 -0
- package/src/providers/service-config.js +264 -0
- package/src/providers/service.js +146 -0
- package/src/providers/upload.js +112 -0
- package/vendor/dimina-compiler/bin/index.cjs +265 -0
- package/vendor/dimina-compiler/bin/index.js +263 -0
- package/vendor/dimina-compiler/compatibility-B-DoZtUX.cjs +395 -0
- package/vendor/dimina-compiler/compatibility-Cl3-DO6V.js +366 -0
- package/vendor/dimina-compiler/core/logic-compiler.cjs +378 -0
- package/vendor/dimina-compiler/core/logic-compiler.js +374 -0
- package/vendor/dimina-compiler/core/style-compiler.cjs +392 -0
- package/vendor/dimina-compiler/core/style-compiler.js +377 -0
- package/vendor/dimina-compiler/core/view-compiler.cjs +1601 -0
- package/vendor/dimina-compiler/core/view-compiler.js +1582 -0
- package/vendor/dimina-compiler/index.cjs +762 -0
- package/vendor/dimina-compiler/index.js +751 -0
- package/vendor/dimina-compiler/sourcemap-BgtIgqkC.cjs +1377 -0
- package/vendor/dimina-compiler/sourcemap-CKjhV9h7.js +1135 -0
|
@@ -0,0 +1,1377 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let node_fs = require("node:fs");
|
|
24
|
+
node_fs = __toESM(node_fs, 1);
|
|
25
|
+
let node_path = require("node:path");
|
|
26
|
+
node_path = __toESM(node_path, 1);
|
|
27
|
+
let node_process = require("node:process");
|
|
28
|
+
node_process = __toESM(node_process, 1);
|
|
29
|
+
let node_os = require("node:os");
|
|
30
|
+
node_os = __toESM(node_os, 1);
|
|
31
|
+
let oxc_parser = require("oxc-parser");
|
|
32
|
+
let oxc_walker = require("oxc-walker");
|
|
33
|
+
let node_crypto = require("node:crypto");
|
|
34
|
+
node_crypto = __toESM(node_crypto, 1);
|
|
35
|
+
let source_map_js = require("source-map-js");
|
|
36
|
+
//#region src/common/dependency-graph.js
|
|
37
|
+
function normalizeFilePath(filePath) {
|
|
38
|
+
return node_path.default.resolve(filePath);
|
|
39
|
+
}
|
|
40
|
+
function normalizeKinds(kinds) {
|
|
41
|
+
if (!kinds) return null;
|
|
42
|
+
return new Set(Array.isArray(kinds) ? kinds : [kinds]);
|
|
43
|
+
}
|
|
44
|
+
var DependencyGraph = class DependencyGraph {
|
|
45
|
+
constructor(snapshot) {
|
|
46
|
+
this.nodes = /* @__PURE__ */ new Map();
|
|
47
|
+
this.dependencies = /* @__PURE__ */ new Map();
|
|
48
|
+
this.dependents = /* @__PURE__ */ new Map();
|
|
49
|
+
this.fileOwners = /* @__PURE__ */ new Map();
|
|
50
|
+
this.fileKinds = /* @__PURE__ */ new Map();
|
|
51
|
+
if (snapshot) this.merge(snapshot);
|
|
52
|
+
}
|
|
53
|
+
addNode(id, metadata = {}) {
|
|
54
|
+
if (!id) return null;
|
|
55
|
+
const current = this.nodes.get(id) || {
|
|
56
|
+
id,
|
|
57
|
+
type: "module",
|
|
58
|
+
entry: false,
|
|
59
|
+
packageRoot: null,
|
|
60
|
+
files: /* @__PURE__ */ new Set()
|
|
61
|
+
};
|
|
62
|
+
if (metadata.type) current.type = metadata.type;
|
|
63
|
+
if (metadata.entry === true) current.entry = true;
|
|
64
|
+
if (metadata.packageRoot !== void 0) current.packageRoot = metadata.packageRoot;
|
|
65
|
+
this.nodes.set(id, current);
|
|
66
|
+
for (const filePath of metadata.files || []) this.addFile(id, filePath);
|
|
67
|
+
return current;
|
|
68
|
+
}
|
|
69
|
+
addFile(id, filePath, kind = "module") {
|
|
70
|
+
if (!id || !filePath) return;
|
|
71
|
+
const node = this.addNode(id);
|
|
72
|
+
const normalizedPath = normalizeFilePath(filePath);
|
|
73
|
+
node.files.add(normalizedPath);
|
|
74
|
+
const owners = this.fileOwners.get(normalizedPath) || /* @__PURE__ */ new Set();
|
|
75
|
+
owners.add(id);
|
|
76
|
+
this.fileOwners.set(normalizedPath, owners);
|
|
77
|
+
const ownerKinds = this.fileKinds.get(normalizedPath) || /* @__PURE__ */ new Map();
|
|
78
|
+
const kinds = ownerKinds.get(id) || /* @__PURE__ */ new Set();
|
|
79
|
+
kinds.add(kind);
|
|
80
|
+
ownerKinds.set(id, kinds);
|
|
81
|
+
this.fileKinds.set(normalizedPath, ownerKinds);
|
|
82
|
+
}
|
|
83
|
+
addDependency(from, to, kind = "module") {
|
|
84
|
+
if (!from || !to) return;
|
|
85
|
+
this.addNode(from);
|
|
86
|
+
this.addNode(to);
|
|
87
|
+
const outgoing = this.dependencies.get(from) || /* @__PURE__ */ new Map();
|
|
88
|
+
const kinds = outgoing.get(to) || /* @__PURE__ */ new Set();
|
|
89
|
+
kinds.add(kind);
|
|
90
|
+
outgoing.set(to, kinds);
|
|
91
|
+
this.dependencies.set(from, outgoing);
|
|
92
|
+
const incoming = this.dependents.get(to) || /* @__PURE__ */ new Map();
|
|
93
|
+
const reverseKinds = incoming.get(from) || /* @__PURE__ */ new Set();
|
|
94
|
+
reverseKinds.add(kind);
|
|
95
|
+
incoming.set(from, reverseKinds);
|
|
96
|
+
this.dependents.set(to, incoming);
|
|
97
|
+
}
|
|
98
|
+
getDirectDependencies(id, kinds) {
|
|
99
|
+
return this.#filterEdges(this.dependencies.get(id), kinds);
|
|
100
|
+
}
|
|
101
|
+
getDirectDependents(id, kinds) {
|
|
102
|
+
return this.#filterEdges(this.dependents.get(id), kinds);
|
|
103
|
+
}
|
|
104
|
+
getAffectedEntries(filePath) {
|
|
105
|
+
const pending = [...this.fileOwners.get(normalizeFilePath(filePath)) || /* @__PURE__ */ new Set()];
|
|
106
|
+
const visited = /* @__PURE__ */ new Set();
|
|
107
|
+
const entries = /* @__PURE__ */ new Set();
|
|
108
|
+
while (pending.length > 0) {
|
|
109
|
+
const id = pending.pop();
|
|
110
|
+
if (visited.has(id)) continue;
|
|
111
|
+
visited.add(id);
|
|
112
|
+
if (this.nodes.get(id)?.entry) entries.add(id);
|
|
113
|
+
for (const dependent of this.getDirectDependents(id)) pending.push(dependent);
|
|
114
|
+
}
|
|
115
|
+
return [...entries].sort();
|
|
116
|
+
}
|
|
117
|
+
hasFile(filePath) {
|
|
118
|
+
return this.fileOwners.has(normalizeFilePath(filePath));
|
|
119
|
+
}
|
|
120
|
+
getFileKinds(filePath) {
|
|
121
|
+
const ownerKinds = this.fileKinds.get(normalizeFilePath(filePath));
|
|
122
|
+
if (!ownerKinds) return [];
|
|
123
|
+
return [...new Set([...ownerKinds.values()].flatMap((kinds) => [...kinds]))].sort();
|
|
124
|
+
}
|
|
125
|
+
merge(snapshotOrGraph) {
|
|
126
|
+
const snapshot = snapshotOrGraph instanceof DependencyGraph ? snapshotOrGraph.toJSON() : snapshotOrGraph;
|
|
127
|
+
const fileEdges = snapshot?.fileEdges || [];
|
|
128
|
+
for (const node of snapshot?.nodes || []) {
|
|
129
|
+
this.addNode(node.id, {
|
|
130
|
+
...node,
|
|
131
|
+
files: []
|
|
132
|
+
});
|
|
133
|
+
if (fileEdges.length === 0) for (const filePath of node.files || []) this.addFile(node.id, filePath);
|
|
134
|
+
}
|
|
135
|
+
for (const fileEdge of fileEdges) for (const kind of fileEdge.kinds || ["module"]) this.addFile(fileEdge.owner, fileEdge.file, kind);
|
|
136
|
+
for (const edge of snapshot?.edges || []) for (const kind of edge.kinds || ["module"]) this.addDependency(edge.from, edge.to, kind);
|
|
137
|
+
return this;
|
|
138
|
+
}
|
|
139
|
+
toJSON() {
|
|
140
|
+
return {
|
|
141
|
+
nodes: [...this.nodes.values()].map((node) => ({
|
|
142
|
+
id: node.id,
|
|
143
|
+
type: node.type,
|
|
144
|
+
entry: node.entry,
|
|
145
|
+
packageRoot: node.packageRoot,
|
|
146
|
+
files: [...node.files].sort()
|
|
147
|
+
})).sort((a, b) => a.id.localeCompare(b.id)),
|
|
148
|
+
edges: [...this.dependencies.entries()].flatMap(([from, targets]) => [...targets.entries()].map(([to, kinds]) => ({
|
|
149
|
+
from,
|
|
150
|
+
to,
|
|
151
|
+
kinds: [...kinds].sort()
|
|
152
|
+
}))).sort((a, b) => a.from.localeCompare(b.from) || a.to.localeCompare(b.to)),
|
|
153
|
+
fileEdges: [...this.fileKinds.entries()].flatMap(([file, owners]) => [...owners.entries()].map(([owner, kinds]) => ({
|
|
154
|
+
file,
|
|
155
|
+
owner,
|
|
156
|
+
kinds: [...kinds].sort()
|
|
157
|
+
}))).sort((a, b) => a.file.localeCompare(b.file) || a.owner.localeCompare(b.owner))
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
#filterEdges(edges, kinds) {
|
|
161
|
+
if (!edges) return [];
|
|
162
|
+
const acceptedKinds = normalizeKinds(kinds);
|
|
163
|
+
return [...edges.entries()].filter(([, edgeKinds]) => !acceptedKinds || [...edgeKinds].some((kind) => acceptedKinds.has(kind))).map(([id]) => id);
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
//#endregion
|
|
167
|
+
//#region src/common/path-utils.js
|
|
168
|
+
var WINDOWS_FS_PATH_RE = /^(?:[a-zA-Z]:[\\/]|\\\\)/;
|
|
169
|
+
function isWindowsFsPath(targetPath) {
|
|
170
|
+
return typeof targetPath === "string" && (WINDOWS_FS_PATH_RE.test(targetPath) || targetPath.includes("\\"));
|
|
171
|
+
}
|
|
172
|
+
function getFsPathApi(targetPath) {
|
|
173
|
+
return isWindowsFsPath(targetPath) ? node_path.default.win32 : node_path.default.posix;
|
|
174
|
+
}
|
|
175
|
+
function normalizeToPosixPath(targetPath) {
|
|
176
|
+
return targetPath.replace(/\\/g, "/");
|
|
177
|
+
}
|
|
178
|
+
function resolveMiniProgramPath(workPath, importerPath, sourcePath) {
|
|
179
|
+
const pathApi = getFsPathApi(importerPath || workPath);
|
|
180
|
+
return sourcePath.startsWith("/") ? pathApi.join(workPath, sourcePath) : pathApi.resolve(pathApi.dirname(importerPath), sourcePath);
|
|
181
|
+
}
|
|
182
|
+
function toMiniProgramModuleId(resolvedPath, workPath) {
|
|
183
|
+
const normalizedResolvedPath = normalizeToPosixPath(resolvedPath);
|
|
184
|
+
const normalizedWorkPath = normalizeToPosixPath(workPath);
|
|
185
|
+
let moduleId = normalizedResolvedPath.startsWith(normalizedWorkPath) ? normalizedResolvedPath.slice(normalizedWorkPath.length) : normalizedResolvedPath;
|
|
186
|
+
moduleId = moduleId.replace(/\/+/g, "/");
|
|
187
|
+
if (!moduleId.startsWith("/")) moduleId = `/${moduleId}`;
|
|
188
|
+
return moduleId;
|
|
189
|
+
}
|
|
190
|
+
function getRelativePosixPath(targetPath, rootPath) {
|
|
191
|
+
return normalizeToPosixPath(targetPath).replace(normalizeToPosixPath(rootPath), "").replace(/^\//, "");
|
|
192
|
+
}
|
|
193
|
+
//#endregion
|
|
194
|
+
//#region src/common/utils.js
|
|
195
|
+
function hasCompileInfo(modulePath, list, preList) {
|
|
196
|
+
const mergeList = Array.isArray(preList) ? [...preList, ...list] : list;
|
|
197
|
+
for (const element of mergeList) if (element.path === modulePath) return true;
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
function getAbsolutePath(workPath, pagePath, src) {
|
|
201
|
+
if (src.startsWith("/")) return node_path.default.join(workPath, src);
|
|
202
|
+
if (pagePath.includes("/miniprogram_npm/")) {
|
|
203
|
+
const componentFullPath = workPath + pagePath.split("/").slice(0, -1).join("/");
|
|
204
|
+
return node_path.default.resolve(componentFullPath, src);
|
|
205
|
+
}
|
|
206
|
+
const relativePath = pagePath.split("/").filter((part) => part !== "").slice(0, -1).join("/");
|
|
207
|
+
return node_path.default.resolve(workPath, relativePath, src);
|
|
208
|
+
}
|
|
209
|
+
var assetsMap = {};
|
|
210
|
+
function resetAssetCache() {
|
|
211
|
+
for (const assetPath of Object.keys(assetsMap)) delete assetsMap[assetPath];
|
|
212
|
+
}
|
|
213
|
+
function isPathInside(rootPath, targetPath) {
|
|
214
|
+
const relativePath = node_path.default.relative(rootPath, targetPath);
|
|
215
|
+
return relativePath === "" || !relativePath.startsWith(`..${node_path.default.sep}`) && relativePath !== ".." && !node_path.default.isAbsolute(relativePath);
|
|
216
|
+
}
|
|
217
|
+
function resolveAssetSourcePath(workPath, pagePath, src) {
|
|
218
|
+
const projectRoot = node_path.default.resolve(workPath);
|
|
219
|
+
if (src.startsWith("/")) return node_path.default.resolve(projectRoot, `.${src}`);
|
|
220
|
+
const normalizedPagePath = node_path.default.resolve(pagePath);
|
|
221
|
+
const pageDirectory = node_path.default.isAbsolute(pagePath) && isPathInside(projectRoot, normalizedPagePath) ? node_path.default.dirname(normalizedPagePath) : node_path.default.resolve(projectRoot, node_path.default.dirname(pagePath.replace(/^[/\\]+/, "")));
|
|
222
|
+
const resolvedPath = node_path.default.resolve(pageDirectory, src);
|
|
223
|
+
if (isPathInside(projectRoot, resolvedPath)) return resolvedPath;
|
|
224
|
+
return node_path.default.resolve(projectRoot, src.replace(/^(?:\.\.[/\\])+/, ""));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* 将静态资源存储到 static 文件夹
|
|
228
|
+
*/
|
|
229
|
+
function collectAssets(workPath, pagePath, src, targetPath, appId) {
|
|
230
|
+
if (src.startsWith("http") || src.startsWith("//")) return src;
|
|
231
|
+
if (!/\.(?:png|jpe?g|gif|svg|mp3|m4a|aac|wav)(?:\?.*)?$/.test(src)) return src;
|
|
232
|
+
const absolutePath = resolveAssetSourcePath(workPath, pagePath, src);
|
|
233
|
+
if (assetsMap[absolutePath]) return assetsMap[absolutePath];
|
|
234
|
+
try {
|
|
235
|
+
const ext = `.${src.split(".").pop()}`;
|
|
236
|
+
const dirPath = absolutePath.split(node_path.default.sep).slice(0, -1).join("/");
|
|
237
|
+
const prefix = uuid(node_path.default.relative(node_path.default.resolve(workPath), dirPath).split(node_path.default.sep).join("/") || ".");
|
|
238
|
+
const targetStatic = `${targetPath}/main/static`;
|
|
239
|
+
if (!node_fs.default.existsSync(targetStatic)) node_fs.default.mkdirSync(targetStatic, { recursive: true });
|
|
240
|
+
getFilesWithExtension(dirPath, ext).forEach((file) => {
|
|
241
|
+
node_fs.default.copyFileSync(node_path.default.resolve(dirPath, file), `${targetStatic}/${prefix}_${file}`);
|
|
242
|
+
});
|
|
243
|
+
const filename = src.split("/").pop();
|
|
244
|
+
assetsMap[absolutePath] = `${node_process.default.env.ASSETS_PATH_PREFIX ? "" : "/"}${appId}/main/static/${prefix}_${filename}`;
|
|
245
|
+
} catch (error) {
|
|
246
|
+
console.log(error);
|
|
247
|
+
}
|
|
248
|
+
return assetsMap[absolutePath] || src;
|
|
249
|
+
}
|
|
250
|
+
function getFilesWithExtension(directory, extension) {
|
|
251
|
+
return node_fs.default.readdirSync(directory).filter((file) => node_path.default.extname(file) === extension);
|
|
252
|
+
}
|
|
253
|
+
function isObjectEmpty(objectName) {
|
|
254
|
+
if (!objectName) return true;
|
|
255
|
+
return Object.keys(objectName).length === 0 && objectName.constructor === Object;
|
|
256
|
+
}
|
|
257
|
+
function isString(o) {
|
|
258
|
+
return Object.prototype.toString.call(o) === "[object String]";
|
|
259
|
+
}
|
|
260
|
+
function transformRpx(styleText) {
|
|
261
|
+
if (!isString(styleText)) return styleText;
|
|
262
|
+
return styleText.replace(/([+-]?\d+(?:\.\d+)?)rpx/g, (_, pixel) => {
|
|
263
|
+
const viewportWidth = Number((Number(pixel) / 7.5).toFixed(6));
|
|
264
|
+
return `${Object.is(viewportWidth, -0) ? 0 : viewportWidth}vw`;
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
function uuid(str) {
|
|
268
|
+
return node_crypto.default.createHash("sha256").update(str).digest().readBigUInt64BE(0).toString(36);
|
|
269
|
+
}
|
|
270
|
+
var tagWhiteList = [
|
|
271
|
+
"page",
|
|
272
|
+
"wrapper",
|
|
273
|
+
"audio",
|
|
274
|
+
"component-host",
|
|
275
|
+
"block",
|
|
276
|
+
"button",
|
|
277
|
+
"camera",
|
|
278
|
+
"checkbox-group",
|
|
279
|
+
"checkbox",
|
|
280
|
+
"cover-image",
|
|
281
|
+
"cover-view",
|
|
282
|
+
"form",
|
|
283
|
+
"icon",
|
|
284
|
+
"image",
|
|
285
|
+
"input",
|
|
286
|
+
"keyboard-accessory",
|
|
287
|
+
"label",
|
|
288
|
+
"map",
|
|
289
|
+
"movable-area",
|
|
290
|
+
"movable-view",
|
|
291
|
+
"navigation-bar",
|
|
292
|
+
"navigator",
|
|
293
|
+
"open-data",
|
|
294
|
+
"page-meta",
|
|
295
|
+
"page-container",
|
|
296
|
+
"picker-view-column",
|
|
297
|
+
"picker-view",
|
|
298
|
+
"picker",
|
|
299
|
+
"progress",
|
|
300
|
+
"radio-group",
|
|
301
|
+
"radio",
|
|
302
|
+
"rich-text",
|
|
303
|
+
"root-portal",
|
|
304
|
+
"scroll-view",
|
|
305
|
+
"slider",
|
|
306
|
+
"swiper-item",
|
|
307
|
+
"swiper",
|
|
308
|
+
"switch",
|
|
309
|
+
"template",
|
|
310
|
+
"text",
|
|
311
|
+
"textarea",
|
|
312
|
+
"video",
|
|
313
|
+
"view",
|
|
314
|
+
"web-view"
|
|
315
|
+
];
|
|
316
|
+
var miniProgramBuiltinTags = /* @__PURE__ */ new Set([
|
|
317
|
+
...tagWhiteList,
|
|
318
|
+
"canvas",
|
|
319
|
+
"match-media",
|
|
320
|
+
"page-container",
|
|
321
|
+
"share-element",
|
|
322
|
+
"editor",
|
|
323
|
+
"audio",
|
|
324
|
+
"channel-live",
|
|
325
|
+
"channel-video",
|
|
326
|
+
"live-player",
|
|
327
|
+
"live-pusher",
|
|
328
|
+
"voip-room",
|
|
329
|
+
"ad",
|
|
330
|
+
"ad-custom",
|
|
331
|
+
"official-account",
|
|
332
|
+
"xr-frame"
|
|
333
|
+
]);
|
|
334
|
+
//#endregion
|
|
335
|
+
//#region src/common/npm-resolver.js
|
|
336
|
+
/**
|
|
337
|
+
* npm 组件解析器
|
|
338
|
+
* 根据微信小程序 npm 支持规范实现组件寻址
|
|
339
|
+
* https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html
|
|
340
|
+
*/
|
|
341
|
+
var NpmResolver = class {
|
|
342
|
+
constructor(workPath) {
|
|
343
|
+
this.workPath = workPath;
|
|
344
|
+
this.miniprogramNpmCache = /* @__PURE__ */ new Map();
|
|
345
|
+
this.packageCache = /* @__PURE__ */ new Map();
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* 解析组件路径,支持 npm 包组件
|
|
349
|
+
* @param {string} componentPath 组件路径
|
|
350
|
+
* @param {string} pageFilePath 页面文件路径
|
|
351
|
+
* @returns {string} 解析后的组件路径
|
|
352
|
+
*/
|
|
353
|
+
resolveComponentPath(componentPath, pageFilePath) {
|
|
354
|
+
if (componentPath.startsWith("./") || componentPath.startsWith("../") || componentPath.startsWith("/")) return this.resolveRelativePath(componentPath, pageFilePath);
|
|
355
|
+
const npmPath = this.resolveNpmComponent(componentPath, pageFilePath);
|
|
356
|
+
if (npmPath) return npmPath;
|
|
357
|
+
return this.resolveRelativePath(componentPath, pageFilePath);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* 解析相对路径组件
|
|
361
|
+
* @param {string} componentPath 组件路径
|
|
362
|
+
* @param {string} pageFilePath 页面文件路径
|
|
363
|
+
* @returns {string} 解析后的路径
|
|
364
|
+
*/
|
|
365
|
+
resolveRelativePath(componentPath, pageFilePath) {
|
|
366
|
+
return toMiniProgramModuleId(resolveMiniProgramPath(this.workPath, pageFilePath, componentPath), this.workPath);
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* 解析 npm 组件
|
|
370
|
+
* @param {string} componentName 组件名称
|
|
371
|
+
* @param {string} pageFilePath 页面文件路径
|
|
372
|
+
* @returns {string|null} 解析后的组件路径,如果找不到返回 null
|
|
373
|
+
*/
|
|
374
|
+
resolveNpmComponent(componentName, pageFilePath) {
|
|
375
|
+
const searchPaths = this.generateSearchPaths(pageFilePath);
|
|
376
|
+
for (const searchPath of searchPaths) {
|
|
377
|
+
const componentPath = this.findComponentInMiniprogramNpm(componentName, searchPath);
|
|
378
|
+
if (componentPath) return componentPath;
|
|
379
|
+
}
|
|
380
|
+
return null;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* 解析脚本模块路径,支持微信小程序 npm 逐级寻址和 package.json 入口
|
|
384
|
+
* @param {string} specifier 模块导入路径
|
|
385
|
+
* @param {string} modulePath 当前模块绝对文件路径
|
|
386
|
+
* @param {(moduleId: string) => string | null} resolveExistingModuleId 解析真实存在模块的回调
|
|
387
|
+
* @returns {string|null} 解析后的模块 id
|
|
388
|
+
*/
|
|
389
|
+
resolveScriptModule(specifier, modulePath, resolveExistingModuleId) {
|
|
390
|
+
if (!specifier || !resolveExistingModuleId) return null;
|
|
391
|
+
for (const searchPath of this.generateSearchPaths(modulePath)) {
|
|
392
|
+
const resolvedModuleId = resolveExistingModuleId(this.normalizeModuleId(`/${searchPath}/${specifier}`));
|
|
393
|
+
if (resolvedModuleId) return resolvedModuleId;
|
|
394
|
+
}
|
|
395
|
+
return null;
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* 生成 miniprogram_npm 搜索路径
|
|
399
|
+
* 按照微信小程序的寻址顺序生成搜索路径
|
|
400
|
+
* @param {string} pageFilePath 页面文件路径
|
|
401
|
+
* @returns {string[]} 搜索路径数组
|
|
402
|
+
*/
|
|
403
|
+
generateSearchPaths(pageFilePath) {
|
|
404
|
+
const pathParts = getRelativePosixPath(pageFilePath, this.workPath).split("/").slice(0, -1);
|
|
405
|
+
const searchPaths = [];
|
|
406
|
+
for (let i = pathParts.length; i >= 0; i--) {
|
|
407
|
+
const currentPath = pathParts.slice(0, i).join("/");
|
|
408
|
+
const miniprogramNpmPath = currentPath ? `${currentPath}/miniprogram_npm` : "miniprogram_npm";
|
|
409
|
+
searchPaths.push(miniprogramNpmPath);
|
|
410
|
+
}
|
|
411
|
+
return searchPaths;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* 在指定的 miniprogram_npm 目录中查找组件
|
|
415
|
+
* @param {string} componentName 组件名称
|
|
416
|
+
* @param {string} miniprogramNpmPath miniprogram_npm 路径
|
|
417
|
+
* @returns {string|null} 组件路径,如果找不到返回 null
|
|
418
|
+
*/
|
|
419
|
+
findComponentInMiniprogramNpm(componentName, miniprogramNpmPath) {
|
|
420
|
+
const fullMiniprogramNpmPath = node_path.default.join(this.workPath, miniprogramNpmPath);
|
|
421
|
+
if (!node_fs.default.existsSync(fullMiniprogramNpmPath)) return null;
|
|
422
|
+
const cacheKey = `${miniprogramNpmPath}/${componentName}`;
|
|
423
|
+
if (this.miniprogramNpmCache.has(cacheKey)) return this.miniprogramNpmCache.get(cacheKey);
|
|
424
|
+
const candidatePaths = [componentName, `${componentName}/index`];
|
|
425
|
+
for (const candidatePath of candidatePaths) {
|
|
426
|
+
const componentDir = node_path.default.join(fullMiniprogramNpmPath, candidatePath);
|
|
427
|
+
if (this.isValidComponent(componentDir)) {
|
|
428
|
+
const resolvedPath = `/${miniprogramNpmPath}/${candidatePath}`.replace(/\/+/g, "/");
|
|
429
|
+
this.miniprogramNpmCache.set(cacheKey, resolvedPath);
|
|
430
|
+
return resolvedPath;
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
this.miniprogramNpmCache.set(cacheKey, null);
|
|
434
|
+
return null;
|
|
435
|
+
}
|
|
436
|
+
normalizeModuleId(moduleId) {
|
|
437
|
+
let normalized = moduleId.replace(/\.(js|ts)$/, "").replace(/\\/g, "/");
|
|
438
|
+
if (!normalized.startsWith("/")) normalized = `/${normalized}`;
|
|
439
|
+
return normalized;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* 检查是否为有效的组件
|
|
443
|
+
* @param {string} componentPath 组件路径
|
|
444
|
+
* @returns {boolean} 是否为有效组件
|
|
445
|
+
*/
|
|
446
|
+
isValidComponent(componentPath) {
|
|
447
|
+
const requiredFiles = [".json", ".js"];
|
|
448
|
+
if (!requiredFiles.some((ext) => {
|
|
449
|
+
return node_fs.default.existsSync(`${componentPath}${ext}`);
|
|
450
|
+
})) {
|
|
451
|
+
if (!requiredFiles.some((ext) => {
|
|
452
|
+
return node_fs.default.existsSync(node_path.default.join(componentPath, `index${ext}`));
|
|
453
|
+
})) return false;
|
|
454
|
+
const indexJsonFile = node_path.default.join(componentPath, "index.json");
|
|
455
|
+
if (node_fs.default.existsSync(indexJsonFile)) try {
|
|
456
|
+
return JSON.parse(node_fs.default.readFileSync(indexJsonFile, "utf-8")).component === true;
|
|
457
|
+
} catch (e) {
|
|
458
|
+
return false;
|
|
459
|
+
}
|
|
460
|
+
return true;
|
|
461
|
+
}
|
|
462
|
+
const jsonFile = `${componentPath}.json`;
|
|
463
|
+
if (node_fs.default.existsSync(jsonFile)) try {
|
|
464
|
+
return JSON.parse(node_fs.default.readFileSync(jsonFile, "utf-8")).component === true;
|
|
465
|
+
} catch (e) {
|
|
466
|
+
return false;
|
|
467
|
+
}
|
|
468
|
+
return true;
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* 获取 npm 包信息
|
|
472
|
+
* @param {string} packageName 包名
|
|
473
|
+
* @param {string} searchPath 搜索路径
|
|
474
|
+
* @returns {object|null} 包信息,如果找不到返回 null
|
|
475
|
+
*/
|
|
476
|
+
getPackageInfo(packageName, searchPath) {
|
|
477
|
+
const cacheKey = `${searchPath}/${packageName}`;
|
|
478
|
+
if (this.packageCache.has(cacheKey)) return this.packageCache.get(cacheKey);
|
|
479
|
+
const packageJsonPath = node_path.default.join(this.workPath, searchPath, packageName, "package.json");
|
|
480
|
+
if (!node_fs.default.existsSync(packageJsonPath)) {
|
|
481
|
+
this.packageCache.set(cacheKey, null);
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
try {
|
|
485
|
+
const packageInfo = JSON.parse(node_fs.default.readFileSync(packageJsonPath, "utf-8"));
|
|
486
|
+
this.packageCache.set(cacheKey, packageInfo);
|
|
487
|
+
return packageInfo;
|
|
488
|
+
} catch (e) {
|
|
489
|
+
this.packageCache.set(cacheKey, null);
|
|
490
|
+
return null;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
/**
|
|
494
|
+
* 清除缓存
|
|
495
|
+
*/
|
|
496
|
+
clearCache() {
|
|
497
|
+
this.miniprogramNpmCache.clear();
|
|
498
|
+
this.packageCache.clear();
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
//#endregion
|
|
502
|
+
//#region src/env.js
|
|
503
|
+
var pathInfo = {};
|
|
504
|
+
var configInfo = {};
|
|
505
|
+
var npmResolver = null;
|
|
506
|
+
var dependencyGraph = new DependencyGraph();
|
|
507
|
+
var DEFAULT_TEMPLATE_EXTS = [".wxml", ".ddml"];
|
|
508
|
+
var DEFAULT_TEMPLATE_DIRECTIVE_PREFIXES = [
|
|
509
|
+
"wx",
|
|
510
|
+
"dd",
|
|
511
|
+
"a"
|
|
512
|
+
];
|
|
513
|
+
var DEFAULT_STYLE_EXTS = [
|
|
514
|
+
".wxss",
|
|
515
|
+
".ddss",
|
|
516
|
+
".less",
|
|
517
|
+
".scss",
|
|
518
|
+
".sass"
|
|
519
|
+
];
|
|
520
|
+
var DEFAULT_VIEW_SCRIPT_EXTS = [".wxs"];
|
|
521
|
+
var DEFAULT_VIEW_SCRIPT_TAGS = ["wxs", "dds"];
|
|
522
|
+
var CUSTOM_TAB_BAR_COMPONENT_PATH = "/custom-tab-bar/index";
|
|
523
|
+
var STYLE_ISOLATION_VALUES = /* @__PURE__ */ new Set([
|
|
524
|
+
"isolated",
|
|
525
|
+
"apply-shared",
|
|
526
|
+
"shared"
|
|
527
|
+
]);
|
|
528
|
+
var RESERVED_EXTS = /* @__PURE__ */ new Set([
|
|
529
|
+
...DEFAULT_TEMPLATE_EXTS,
|
|
530
|
+
...DEFAULT_STYLE_EXTS,
|
|
531
|
+
...DEFAULT_VIEW_SCRIPT_EXTS,
|
|
532
|
+
".js",
|
|
533
|
+
".ts",
|
|
534
|
+
".json"
|
|
535
|
+
]);
|
|
536
|
+
var compilerOptions = normalizeFileTypes();
|
|
537
|
+
/**
|
|
538
|
+
* 将单项规范化为扩展名:去除首尾空白、转小写并补一个前导点。
|
|
539
|
+
* 仅接受字母、数字、连字符和下划线;空字符串、路径分隔符或其他元字符
|
|
540
|
+
* 均返回 null,由调用方丢弃。扩展名会用于生成尾部匹配正则和查找文件,
|
|
541
|
+
* 放行元字符可能导致误匹配。
|
|
542
|
+
*/
|
|
543
|
+
function normalizeExt(raw) {
|
|
544
|
+
if (typeof raw !== "string") return null;
|
|
545
|
+
const v = raw.trim().toLowerCase().replace(/^\.+/, "");
|
|
546
|
+
if (!/^[a-z0-9_-]+$/.test(v)) return null;
|
|
547
|
+
return `.${v}`;
|
|
548
|
+
}
|
|
549
|
+
/**
|
|
550
|
+
* 将单项规范化为内联标签名:去除首尾空白、转小写并移除前导点。
|
|
551
|
+
* 标签名会用于拼接 Cheerio 选择器(如 transTagWxs),因此必须以字母开头,
|
|
552
|
+
* 且只能包含字母、数字、连字符和下划线。拒绝选择器元字符,避免 'qds,view'
|
|
553
|
+
* 误选并删除 <view>,破坏编译产物。
|
|
554
|
+
*/
|
|
555
|
+
function normalizeTag(raw) {
|
|
556
|
+
if (typeof raw !== "string") return null;
|
|
557
|
+
const v = raw.trim().toLowerCase().replace(/^\.+/, "");
|
|
558
|
+
if (!/^[a-z][a-z0-9_-]*$/.test(v)) return null;
|
|
559
|
+
return v;
|
|
560
|
+
}
|
|
561
|
+
/**
|
|
562
|
+
* 合并并去重内置项和自定义项;内置项在前,顺序即同名文件的查找优先级。
|
|
563
|
+
* 传入 reserved 时,落在其中的自定义项被丢弃(防止占用其他角色/逻辑/配置的扩展名)。
|
|
564
|
+
*/
|
|
565
|
+
function mergeUnique(builtins, custom, normalizer, reserved) {
|
|
566
|
+
const out = [...builtins];
|
|
567
|
+
const seen = new Set(builtins);
|
|
568
|
+
if (Array.isArray(custom)) for (const raw of custom) {
|
|
569
|
+
const n = normalizer(raw);
|
|
570
|
+
if (n && !seen.has(n) && !reserved?.has(n)) {
|
|
571
|
+
seen.add(n);
|
|
572
|
+
out.push(n);
|
|
573
|
+
}
|
|
574
|
+
}
|
|
575
|
+
return out;
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* 根据 options.fileTypes 生成本次构建使用的自定义扩展名和标签。
|
|
579
|
+
* viewScript 同时用于生成文件扩展名和内联标签。
|
|
580
|
+
*/
|
|
581
|
+
function normalizeFileTypes(fileTypes = {}) {
|
|
582
|
+
const ft = fileTypes || {};
|
|
583
|
+
const templateExts = mergeUnique(DEFAULT_TEMPLATE_EXTS, ft.template, normalizeExt, RESERVED_EXTS);
|
|
584
|
+
return {
|
|
585
|
+
templateExts,
|
|
586
|
+
templateDirectivePrefixes: [.../* @__PURE__ */ new Set([...DEFAULT_TEMPLATE_DIRECTIVE_PREFIXES, ...templateExts.map((extension) => {
|
|
587
|
+
const name = extension.slice(1);
|
|
588
|
+
return name.endsWith("ml") ? name.slice(0, -2) : name;
|
|
589
|
+
}).filter(Boolean)])],
|
|
590
|
+
styleExts: mergeUnique(DEFAULT_STYLE_EXTS, ft.style, normalizeExt, RESERVED_EXTS),
|
|
591
|
+
viewScriptExts: mergeUnique(DEFAULT_VIEW_SCRIPT_EXTS, ft.viewScript, normalizeExt, RESERVED_EXTS),
|
|
592
|
+
viewScriptTags: mergeUnique(DEFAULT_VIEW_SCRIPT_TAGS, ft.viewScript, normalizeTag)
|
|
593
|
+
};
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* 持久化编译过程的上下文
|
|
597
|
+
* @param {string} workPath 编译工作目录
|
|
598
|
+
* @param {{ fileTypes?: { template?: string[], style?: string[], viewScript?: string[] } }} [options] 构建选项
|
|
599
|
+
*/
|
|
600
|
+
function storeInfo(workPath, options = {}) {
|
|
601
|
+
compilerOptions = normalizeFileTypes(options.fileTypes);
|
|
602
|
+
storePathInfo(workPath);
|
|
603
|
+
storeProjectConfig();
|
|
604
|
+
storeAppConfig();
|
|
605
|
+
storePageConfig();
|
|
606
|
+
dependencyGraph = createInitialDependencyGraph();
|
|
607
|
+
dependencyGraph.merge(options.dependencyGraph);
|
|
608
|
+
return {
|
|
609
|
+
pathInfo,
|
|
610
|
+
configInfo,
|
|
611
|
+
compilerOptions,
|
|
612
|
+
dependencyGraph: dependencyGraph.toJSON()
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function resetStoreInfo(opts) {
|
|
616
|
+
pathInfo = opts.pathInfo;
|
|
617
|
+
configInfo = opts.configInfo;
|
|
618
|
+
compilerOptions = opts.compilerOptions || normalizeFileTypes();
|
|
619
|
+
dependencyGraph = new DependencyGraph(opts.dependencyGraph);
|
|
620
|
+
if (pathInfo.workPath) npmResolver = new NpmResolver(pathInfo.workPath);
|
|
621
|
+
}
|
|
622
|
+
function getTemplateExts() {
|
|
623
|
+
return compilerOptions.templateExts;
|
|
624
|
+
}
|
|
625
|
+
function getTemplateDirectivePrefixes() {
|
|
626
|
+
return compilerOptions.templateDirectivePrefixes || normalizeFileTypes({ template: compilerOptions.templateExts }).templateDirectivePrefixes;
|
|
627
|
+
}
|
|
628
|
+
function getStyleExts() {
|
|
629
|
+
return compilerOptions.styleExts;
|
|
630
|
+
}
|
|
631
|
+
function getViewScriptExts() {
|
|
632
|
+
return compilerOptions.viewScriptExts;
|
|
633
|
+
}
|
|
634
|
+
function getViewScriptTags() {
|
|
635
|
+
return compilerOptions.viewScriptTags;
|
|
636
|
+
}
|
|
637
|
+
function getDependencyGraph() {
|
|
638
|
+
return dependencyGraph;
|
|
639
|
+
}
|
|
640
|
+
function storePathInfo(workPath) {
|
|
641
|
+
pathInfo.workPath = workPath;
|
|
642
|
+
if (node_process.default.env.TARGET_PATH) pathInfo.targetPath = node_process.default.env.TARGET_PATH;
|
|
643
|
+
else {
|
|
644
|
+
const tempDir = node_process.default.env.GITHUB_WORKSPACE || node_os.default.tmpdir();
|
|
645
|
+
const targetDir = node_path.default.join(tempDir, `dimina-fe-dist-${Date.now()}`);
|
|
646
|
+
if (!node_fs.default.existsSync(targetDir)) node_fs.default.mkdirSync(targetDir, { recursive: true });
|
|
647
|
+
pathInfo.targetPath = targetDir;
|
|
648
|
+
}
|
|
649
|
+
npmResolver = new NpmResolver(workPath);
|
|
650
|
+
}
|
|
651
|
+
function storeProjectConfig() {
|
|
652
|
+
const privateConfigPath = `${pathInfo.workPath}/project.private.config.json`;
|
|
653
|
+
const defaultConfigPath = `${pathInfo.workPath}/project.config.json`;
|
|
654
|
+
let privateConfig = {};
|
|
655
|
+
let defaultConfig = {};
|
|
656
|
+
if (node_fs.default.existsSync(defaultConfigPath)) try {
|
|
657
|
+
defaultConfig = parseContentByPath(defaultConfigPath);
|
|
658
|
+
} catch (e) {
|
|
659
|
+
console.warn("Failed to parse project.config.json:", e.message);
|
|
660
|
+
}
|
|
661
|
+
if (node_fs.default.existsSync(privateConfigPath)) try {
|
|
662
|
+
privateConfig = parseContentByPath(privateConfigPath);
|
|
663
|
+
} catch (e) {
|
|
664
|
+
console.warn("Failed to parse project.private.config.json:", e.message);
|
|
665
|
+
}
|
|
666
|
+
configInfo.projectInfo = {
|
|
667
|
+
...defaultConfig,
|
|
668
|
+
...privateConfig
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
function getProjectConfig() {
|
|
672
|
+
return configInfo.projectInfo;
|
|
673
|
+
}
|
|
674
|
+
function storeAppConfig() {
|
|
675
|
+
const content = parseContentByPath(`${pathInfo.workPath}/app.json`);
|
|
676
|
+
const newObj = {};
|
|
677
|
+
for (const key in content) if (Object.prototype.hasOwnProperty.call(content, key)) if (key === "subpackages") newObj.subPackages = content[key];
|
|
678
|
+
else newObj[key] = content[key];
|
|
679
|
+
configInfo.appInfo = newObj;
|
|
680
|
+
}
|
|
681
|
+
function getContentByPath(path) {
|
|
682
|
+
return node_fs.default.readFileSync(path, { encoding: "utf-8" });
|
|
683
|
+
}
|
|
684
|
+
function parseContentByPath(path) {
|
|
685
|
+
return JSON.parse(getContentByPath(path));
|
|
686
|
+
}
|
|
687
|
+
/**
|
|
688
|
+
* 收集页面 json 信息
|
|
689
|
+
*/
|
|
690
|
+
function storePageConfig() {
|
|
691
|
+
const { pages, subPackages } = configInfo.appInfo;
|
|
692
|
+
configInfo.pageInfo = {};
|
|
693
|
+
configInfo.componentInfo = {};
|
|
694
|
+
if (configInfo.appInfo.usingComponents) {
|
|
695
|
+
const appFilePath = `${pathInfo.workPath}/app.json`;
|
|
696
|
+
storeComponentConfig(configInfo.appInfo, appFilePath);
|
|
697
|
+
}
|
|
698
|
+
collectionPageJson(pages);
|
|
699
|
+
if (subPackages) subPackages.forEach((subPkg) => {
|
|
700
|
+
collectionPageJson(subPkg.pages, subPkg.root);
|
|
701
|
+
});
|
|
702
|
+
storeCustomTabBarConfig();
|
|
703
|
+
}
|
|
704
|
+
/**
|
|
705
|
+
* 微信会把 custom-tab-bar/index 作为每个 tab 页的直属组件创建。业务页面
|
|
706
|
+
* 不需要在 usingComponents 中显式声明它,因此编译阶段补一个内部组件引用,
|
|
707
|
+
* 让逻辑、视图和样式三个编译器都能沿现有依赖图收集该组件。
|
|
708
|
+
*/
|
|
709
|
+
function storeCustomTabBarConfig() {
|
|
710
|
+
const tabBar = configInfo.appInfo?.tabBar;
|
|
711
|
+
if (tabBar?.custom !== true || !Array.isArray(tabBar.list)) return;
|
|
712
|
+
const componentJsonPath = node_path.default.join(pathInfo.workPath, "custom-tab-bar/index.json");
|
|
713
|
+
if (!node_fs.default.existsSync(componentJsonPath)) {
|
|
714
|
+
console.warn("[env] tabBar.custom 已启用,但找不到 custom-tab-bar/index.json");
|
|
715
|
+
return;
|
|
716
|
+
}
|
|
717
|
+
const dependencyName = `dimina-${uuid(CUSTOM_TAB_BAR_COMPONENT_PATH)}`;
|
|
718
|
+
storeComponentConfig({ usingComponents: { [dependencyName]: CUSTOM_TAB_BAR_COMPONENT_PATH } }, node_path.default.join(pathInfo.workPath, "app.json"));
|
|
719
|
+
const componentConfig = configInfo.componentInfo[CUSTOM_TAB_BAR_COMPONENT_PATH];
|
|
720
|
+
if (componentConfig) componentConfig.customTabBar = true;
|
|
721
|
+
for (const item of tabBar.list) {
|
|
722
|
+
const pagePath = typeof item?.pagePath === "string" ? item.pagePath.replace(/^\/+/, "") : "";
|
|
723
|
+
if (!pagePath || !configInfo.appInfo.pages?.includes(pagePath)) continue;
|
|
724
|
+
const pageConfig = configInfo.pageInfo[pagePath] ||= {};
|
|
725
|
+
pageConfig.usingComponents ||= {};
|
|
726
|
+
const declaredComponents = {
|
|
727
|
+
...configInfo.appInfo.usingComponents || {},
|
|
728
|
+
...pageConfig.usingComponents
|
|
729
|
+
};
|
|
730
|
+
let componentName = Object.entries(declaredComponents).find(([, componentPath]) => componentPath === CUSTOM_TAB_BAR_COMPONENT_PATH)?.[0] || dependencyName;
|
|
731
|
+
let suffix = 0;
|
|
732
|
+
while (declaredComponents[componentName] && declaredComponents[componentName] !== CUSTOM_TAB_BAR_COMPONENT_PATH) {
|
|
733
|
+
suffix++;
|
|
734
|
+
componentName = `${dependencyName}-${suffix}`;
|
|
735
|
+
}
|
|
736
|
+
pageConfig.usingComponents[componentName] = CUSTOM_TAB_BAR_COMPONENT_PATH;
|
|
737
|
+
pageConfig.customTabBar = { componentName };
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
/**
|
|
741
|
+
* 匹配页面和对应的配置信息
|
|
742
|
+
* @param {*} pages
|
|
743
|
+
*/
|
|
744
|
+
function collectionPageJson(pages, root) {
|
|
745
|
+
pages.forEach((pagePath) => {
|
|
746
|
+
let np = pagePath;
|
|
747
|
+
if (root) {
|
|
748
|
+
if (!root.endsWith("/")) root += "/";
|
|
749
|
+
np = root + np;
|
|
750
|
+
}
|
|
751
|
+
const pageFilePath = `${pathInfo.workPath}/${np}.json`;
|
|
752
|
+
if (node_fs.default.existsSync(pageFilePath)) {
|
|
753
|
+
const pageJsonContent = parseContentByPath(pageFilePath);
|
|
754
|
+
if (root) pageJsonContent.root = transSubDir(root);
|
|
755
|
+
configInfo.pageInfo[np] = pageJsonContent;
|
|
756
|
+
storeComponentConfig(pageJsonContent, pageFilePath);
|
|
757
|
+
}
|
|
758
|
+
});
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* 按页面收集组件 json 信息
|
|
762
|
+
* @param {*} pageJsonContent
|
|
763
|
+
* @param {*} pageFilePath
|
|
764
|
+
*/
|
|
765
|
+
function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
766
|
+
if (isObjectEmpty(pageJsonContent.usingComponents)) return;
|
|
767
|
+
for (const [componentName, componentPath] of Object.entries(pageJsonContent.usingComponents)) {
|
|
768
|
+
const moduleId = getModuleId(componentPath, pageFilePath);
|
|
769
|
+
pageJsonContent.usingComponents[componentName] = moduleId;
|
|
770
|
+
if (configInfo.componentInfo[moduleId]) continue;
|
|
771
|
+
let componentFilePath = node_path.default.resolve(getWorkPath(), `./${moduleId}.json`);
|
|
772
|
+
let cContent = null;
|
|
773
|
+
if (node_fs.default.existsSync(componentFilePath)) cContent = parseContentByPath(componentFilePath);
|
|
774
|
+
else {
|
|
775
|
+
const indexJsonPath = node_path.default.resolve(getWorkPath(), `./${moduleId}/index.json`);
|
|
776
|
+
if (node_fs.default.existsSync(indexJsonPath)) {
|
|
777
|
+
componentFilePath = indexJsonPath;
|
|
778
|
+
cContent = parseContentByPath(componentFilePath);
|
|
779
|
+
} else if (moduleId.includes("/miniprogram_npm/")) {
|
|
780
|
+
console.log(`[env] 为 npm 组件创建默认配置: ${moduleId}`);
|
|
781
|
+
cContent = {
|
|
782
|
+
component: true,
|
|
783
|
+
usingComponents: {}
|
|
784
|
+
};
|
|
785
|
+
} else {
|
|
786
|
+
console.warn(`[env] 组件配置文件不存在: ${componentFilePath}`);
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
const cUsing = cContent.usingComponents || {};
|
|
791
|
+
const isComponent = cContent.component || false;
|
|
792
|
+
const styleIsolation = resolveComponentStyleIsolation(cContent, componentFilePath);
|
|
793
|
+
const cComponents = Object.keys(cUsing).reduce((acc, key) => {
|
|
794
|
+
acc[key] = getModuleId(cUsing[key], componentFilePath);
|
|
795
|
+
return acc;
|
|
796
|
+
}, {});
|
|
797
|
+
configInfo.componentInfo[moduleId] = {
|
|
798
|
+
id: uuid(moduleId),
|
|
799
|
+
path: moduleId,
|
|
800
|
+
component: isComponent,
|
|
801
|
+
styleIsolation,
|
|
802
|
+
usingComponents: cComponents,
|
|
803
|
+
componentPlaceholder: { ...cContent.componentPlaceholder || {} }
|
|
804
|
+
};
|
|
805
|
+
if (cContent.usingComponents && Object.keys(cContent.usingComponents).length > 0) storeComponentConfig(configInfo.componentInfo[moduleId], componentFilePath);
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
function getStaticProperty(objectExpression, propertyName) {
|
|
809
|
+
if (objectExpression?.type !== "ObjectExpression") return;
|
|
810
|
+
return objectExpression.properties?.find((property) => {
|
|
811
|
+
if (property.type !== "Property" || property.computed) return false;
|
|
812
|
+
return property.key?.name === propertyName || property.key?.value === propertyName;
|
|
813
|
+
})?.value;
|
|
814
|
+
}
|
|
815
|
+
function normalizeStyleIsolation(value) {
|
|
816
|
+
return STYLE_ISOLATION_VALUES.has(value) ? value : void 0;
|
|
817
|
+
}
|
|
818
|
+
/**
|
|
819
|
+
* styleIsolation can be declared either in component.json or in
|
|
820
|
+
* Component({ options }). The style compiler must know it before service
|
|
821
|
+
* runtime starts, so only statically-declared literal options participate.
|
|
822
|
+
* addGlobalClass is the legacy equivalent of apply-shared.
|
|
823
|
+
*/
|
|
824
|
+
function resolveComponentStyleIsolation(componentConfig, componentJsonPath) {
|
|
825
|
+
const jsonValue = normalizeStyleIsolation(componentConfig?.styleIsolation);
|
|
826
|
+
if (jsonValue) return jsonValue;
|
|
827
|
+
const basePath = componentJsonPath.replace(/\.json$/i, "");
|
|
828
|
+
const scriptPath = [".js", ".ts"].map((ext) => `${basePath}${ext}`).find((candidate) => node_fs.default.existsSync(candidate));
|
|
829
|
+
if (!scriptPath) return "isolated";
|
|
830
|
+
try {
|
|
831
|
+
const { program } = (0, oxc_parser.parseSync)(scriptPath, getContentByPath(scriptPath), { sourceType: "unambiguous" });
|
|
832
|
+
let extractedValue;
|
|
833
|
+
(0, oxc_walker.walk)(program, { enter(expression) {
|
|
834
|
+
if (extractedValue) return;
|
|
835
|
+
if (expression?.type !== "CallExpression" || expression.callee?.type !== "Identifier" || expression.callee.name !== "Component") return;
|
|
836
|
+
const definition = expression.arguments?.[0];
|
|
837
|
+
const options = getStaticProperty(definition, "options");
|
|
838
|
+
const styleIsolation = getStaticProperty(options, "styleIsolation")?.value;
|
|
839
|
+
const normalized = normalizeStyleIsolation(styleIsolation);
|
|
840
|
+
if (normalized) {
|
|
841
|
+
extractedValue = normalized;
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
if (getStaticProperty(options, "addGlobalClass")?.value === true) extractedValue = "apply-shared";
|
|
845
|
+
} });
|
|
846
|
+
if (extractedValue) return extractedValue;
|
|
847
|
+
} catch (error) {
|
|
848
|
+
console.warn(`[env] 无法解析组件样式隔离配置 ${scriptPath}: ${error.message}`);
|
|
849
|
+
}
|
|
850
|
+
return "isolated";
|
|
851
|
+
}
|
|
852
|
+
/**
|
|
853
|
+
* 转化为相对小程序根目录的绝对路径,作为模块唯一性 id
|
|
854
|
+
* 支持 npm 组件解析
|
|
855
|
+
* @param {string} src
|
|
856
|
+
*/
|
|
857
|
+
function getModuleId(src, pageFilePath) {
|
|
858
|
+
const resolvedAlias = resolveAppAlias(src);
|
|
859
|
+
if (resolvedAlias) return resolvedAlias;
|
|
860
|
+
if (!npmResolver) {
|
|
861
|
+
const workPath = getWorkPath();
|
|
862
|
+
return toMiniProgramModuleId(resolveMiniProgramPath(workPath, pageFilePath, src), workPath);
|
|
863
|
+
}
|
|
864
|
+
return npmResolver.resolveComponentPath(src, pageFilePath);
|
|
865
|
+
}
|
|
866
|
+
function resolveAppAlias(src) {
|
|
867
|
+
const resolveAlias = configInfo.appInfo?.resolveAlias;
|
|
868
|
+
if (!resolveAlias || typeof src !== "string") return null;
|
|
869
|
+
for (const [alias, target] of Object.entries(resolveAlias)) if (alias.endsWith("/*") && target.endsWith("/*")) {
|
|
870
|
+
const aliasPrefix = alias.slice(0, -1);
|
|
871
|
+
const targetPrefix = target.slice(0, -1);
|
|
872
|
+
if (src.startsWith(aliasPrefix)) return src.replace(aliasPrefix, targetPrefix);
|
|
873
|
+
} else if (src === alias) return target;
|
|
874
|
+
return null;
|
|
875
|
+
}
|
|
876
|
+
function getTargetPath() {
|
|
877
|
+
return pathInfo.targetPath;
|
|
878
|
+
}
|
|
879
|
+
function getComponent(src) {
|
|
880
|
+
return configInfo.componentInfo[src];
|
|
881
|
+
}
|
|
882
|
+
function getPageConfigInfo() {
|
|
883
|
+
return configInfo.pageInfo;
|
|
884
|
+
}
|
|
885
|
+
function getAppConfigInfo() {
|
|
886
|
+
return configInfo.appInfo;
|
|
887
|
+
}
|
|
888
|
+
function getWorkPath() {
|
|
889
|
+
return pathInfo.workPath;
|
|
890
|
+
}
|
|
891
|
+
function getNpmResolver() {
|
|
892
|
+
return npmResolver;
|
|
893
|
+
}
|
|
894
|
+
function getAppId() {
|
|
895
|
+
return configInfo.projectInfo.appid;
|
|
896
|
+
}
|
|
897
|
+
function getAppName() {
|
|
898
|
+
if (configInfo.projectInfo.projectname) return decodeURIComponent(configInfo.projectInfo.projectname);
|
|
899
|
+
return getAppId();
|
|
900
|
+
}
|
|
901
|
+
function transSubDir(name) {
|
|
902
|
+
return `sub_${name.replace(/\/$/, "")}`;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* 获取页面及其配置信息,并生成id(输出的 json 文件没有 id)
|
|
906
|
+
*/
|
|
907
|
+
function getPages() {
|
|
908
|
+
const { pages, subPackages = [], usingComponents: globalComponents = {} } = getAppConfigInfo();
|
|
909
|
+
const pageInfo = getPageConfigInfo();
|
|
910
|
+
const mainPages = pages.map((path) => {
|
|
911
|
+
const pageComponents = pageInfo[path]?.usingComponents || {};
|
|
912
|
+
const mergedComponents = {
|
|
913
|
+
...globalComponents,
|
|
914
|
+
...pageComponents
|
|
915
|
+
};
|
|
916
|
+
return {
|
|
917
|
+
id: uuid(path),
|
|
918
|
+
path,
|
|
919
|
+
appStyleScopeId: getAppStyleScopeId(),
|
|
920
|
+
sharedStyleScopeIds: collectSharedStyleScopeIds(mergedComponents),
|
|
921
|
+
usingComponents: mergedComponents,
|
|
922
|
+
componentPlaceholder: { ...pageInfo[path]?.componentPlaceholder || {} },
|
|
923
|
+
customTabBar: pageInfo[path]?.customTabBar
|
|
924
|
+
};
|
|
925
|
+
});
|
|
926
|
+
const subPages = {};
|
|
927
|
+
subPackages.forEach((subPkg) => {
|
|
928
|
+
const rootPath = subPkg.root.endsWith("/") ? subPkg.root : `${subPkg.root}/`;
|
|
929
|
+
const independent = subPkg.independent ? subPkg.independent : false;
|
|
930
|
+
subPages[transSubDir(rootPath)] = {
|
|
931
|
+
independent,
|
|
932
|
+
info: subPkg.pages.map((path) => {
|
|
933
|
+
const fullPath = rootPath + path;
|
|
934
|
+
const pageComponents = pageInfo[fullPath]?.usingComponents || {};
|
|
935
|
+
const mergedComponents = {
|
|
936
|
+
...globalComponents,
|
|
937
|
+
...pageComponents
|
|
938
|
+
};
|
|
939
|
+
return {
|
|
940
|
+
id: uuid(fullPath),
|
|
941
|
+
path: fullPath,
|
|
942
|
+
appStyleScopeId: getAppStyleScopeId(),
|
|
943
|
+
sharedStyleScopeIds: collectSharedStyleScopeIds(mergedComponents),
|
|
944
|
+
usingComponents: mergedComponents,
|
|
945
|
+
componentPlaceholder: { ...pageInfo[fullPath]?.componentPlaceholder || {} },
|
|
946
|
+
customTabBar: pageInfo[fullPath]?.customTabBar
|
|
947
|
+
};
|
|
948
|
+
})
|
|
949
|
+
};
|
|
950
|
+
});
|
|
951
|
+
return {
|
|
952
|
+
mainPages,
|
|
953
|
+
subPages
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
function addExistingModuleFiles(graph, moduleId) {
|
|
957
|
+
const relativeId = moduleId.replace(/^\/+/, "");
|
|
958
|
+
const basePath = node_path.default.resolve(getWorkPath(), relativeId);
|
|
959
|
+
const baseCandidates = [basePath, node_path.default.join(basePath, "index")];
|
|
960
|
+
const extensions = [
|
|
961
|
+
".json",
|
|
962
|
+
".js",
|
|
963
|
+
".ts",
|
|
964
|
+
...getTemplateExts(),
|
|
965
|
+
...getStyleExts(),
|
|
966
|
+
...getViewScriptExts()
|
|
967
|
+
];
|
|
968
|
+
for (const candidateBase of baseCandidates) for (const extension of extensions) {
|
|
969
|
+
const filePath = `${candidateBase}${extension}`;
|
|
970
|
+
if (node_fs.default.existsSync(filePath)) graph.addFile(moduleId, filePath, getFileDependencyKind(filePath));
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
function getFileDependencyKind(filePath) {
|
|
974
|
+
const extension = node_path.default.extname(filePath).toLowerCase();
|
|
975
|
+
if (extension === ".json") return "config";
|
|
976
|
+
if (extension === ".js" || extension === ".ts") return "logic";
|
|
977
|
+
if (getTemplateExts().includes(extension) || getViewScriptExts().includes(extension)) return "view";
|
|
978
|
+
if (getStyleExts().includes(extension)) return "style";
|
|
979
|
+
return "module";
|
|
980
|
+
}
|
|
981
|
+
function createInitialDependencyGraph() {
|
|
982
|
+
const graph = new DependencyGraph();
|
|
983
|
+
graph.addNode("app", { type: "app" });
|
|
984
|
+
for (const fileName of [
|
|
985
|
+
"app.json",
|
|
986
|
+
"app.js",
|
|
987
|
+
"app.ts",
|
|
988
|
+
"project.config.json",
|
|
989
|
+
"project.private.config.json"
|
|
990
|
+
]) {
|
|
991
|
+
const filePath = node_path.default.resolve(getWorkPath(), fileName);
|
|
992
|
+
if (node_fs.default.existsSync(filePath)) graph.addFile("app", filePath, getFileDependencyKind(filePath));
|
|
993
|
+
}
|
|
994
|
+
addExistingModuleFiles(graph, "app");
|
|
995
|
+
for (const item of getAppConfigInfo().tabBar?.list || []) for (const field of ["iconPath", "selectedIconPath"]) {
|
|
996
|
+
if (!item[field]) continue;
|
|
997
|
+
const assetPath = resolveAssetSourcePath(getWorkPath(), "", item[field]);
|
|
998
|
+
if (node_fs.default.existsSync(assetPath)) graph.addFile("app", assetPath, "config");
|
|
999
|
+
}
|
|
1000
|
+
for (const component of Object.values(configInfo.componentInfo || {})) {
|
|
1001
|
+
graph.addNode(component.path, { type: "component" });
|
|
1002
|
+
addExistingModuleFiles(graph, component.path);
|
|
1003
|
+
}
|
|
1004
|
+
for (const component of Object.values(configInfo.componentInfo || {})) for (const dependencyPath of Object.values(component.usingComponents || {})) graph.addDependency(component.path, dependencyPath, "component");
|
|
1005
|
+
const pages = getPages();
|
|
1006
|
+
const addEntry = (page, packageRoot) => {
|
|
1007
|
+
graph.addNode(page.path, {
|
|
1008
|
+
type: "page",
|
|
1009
|
+
entry: true,
|
|
1010
|
+
packageRoot
|
|
1011
|
+
});
|
|
1012
|
+
addExistingModuleFiles(graph, page.path);
|
|
1013
|
+
graph.addDependency(page.path, "app", "app");
|
|
1014
|
+
for (const dependencyPath of Object.values(page.usingComponents || {})) graph.addDependency(page.path, dependencyPath, "component");
|
|
1015
|
+
};
|
|
1016
|
+
for (const page of pages.mainPages) addEntry(page, null);
|
|
1017
|
+
for (const [packageRoot, subPackage] of Object.entries(pages.subPages)) for (const page of subPackage.info) addEntry(page, packageRoot);
|
|
1018
|
+
return graph;
|
|
1019
|
+
}
|
|
1020
|
+
function collectSharedStyleScopeIds(usingComponents) {
|
|
1021
|
+
const result = [];
|
|
1022
|
+
const visited = /* @__PURE__ */ new Set();
|
|
1023
|
+
const visit = (componentPath) => {
|
|
1024
|
+
if (visited.has(componentPath)) return;
|
|
1025
|
+
visited.add(componentPath);
|
|
1026
|
+
const component = configInfo.componentInfo[componentPath];
|
|
1027
|
+
if (!component) return;
|
|
1028
|
+
if (component.styleIsolation === "shared") result.push(component.id);
|
|
1029
|
+
for (const childPath of Object.values(component.usingComponents || {})) visit(childPath);
|
|
1030
|
+
};
|
|
1031
|
+
for (const componentPath of Object.values(usingComponents || {})) visit(componentPath);
|
|
1032
|
+
return result;
|
|
1033
|
+
}
|
|
1034
|
+
function getAppStyleScopeId() {
|
|
1035
|
+
return uuid("app");
|
|
1036
|
+
}
|
|
1037
|
+
//#endregion
|
|
1038
|
+
//#region src/core/sourcemap.js
|
|
1039
|
+
function wrapModDefine(module) {
|
|
1040
|
+
const code = module.code.endsWith("\n") ? module.code : module.code + "\n";
|
|
1041
|
+
const extraLine = module.extraInfoCode || "";
|
|
1042
|
+
return {
|
|
1043
|
+
header: `modDefine('${module.path}', function(require, module, exports) {\n${extraLine}`,
|
|
1044
|
+
code,
|
|
1045
|
+
footer: "});\n"
|
|
1046
|
+
};
|
|
1047
|
+
}
|
|
1048
|
+
function appendSourceMap(smg, map, lineOffset, columnOffset) {
|
|
1049
|
+
const mapObject = typeof map === "string" ? JSON.parse(map) : map;
|
|
1050
|
+
new source_map_js.SourceMapConsumer(mapObject).eachMapping((mapping) => {
|
|
1051
|
+
if (mapping.source == null || mapping.originalLine == null || mapping.originalColumn == null) return;
|
|
1052
|
+
smg.addMapping({
|
|
1053
|
+
generated: {
|
|
1054
|
+
line: mapping.generatedLine + lineOffset,
|
|
1055
|
+
column: mapping.generatedColumn + (mapping.generatedLine === 1 ? columnOffset : 0)
|
|
1056
|
+
},
|
|
1057
|
+
original: {
|
|
1058
|
+
line: mapping.originalLine,
|
|
1059
|
+
column: mapping.originalColumn
|
|
1060
|
+
},
|
|
1061
|
+
source: mapping.source,
|
|
1062
|
+
name: mapping.name
|
|
1063
|
+
});
|
|
1064
|
+
});
|
|
1065
|
+
if (mapObject.sourcesContent) mapObject.sources.forEach((source, index) => {
|
|
1066
|
+
smg.setSourceContent(source, mapObject.sourcesContent[index]);
|
|
1067
|
+
});
|
|
1068
|
+
}
|
|
1069
|
+
function advanceGeneratedPosition(position, code) {
|
|
1070
|
+
const lines = code.split("\n");
|
|
1071
|
+
if (lines.length === 1) {
|
|
1072
|
+
position.column += code.length;
|
|
1073
|
+
return;
|
|
1074
|
+
}
|
|
1075
|
+
position.line += lines.length - 1;
|
|
1076
|
+
position.column = lines.at(-1).length;
|
|
1077
|
+
}
|
|
1078
|
+
function concatSourcemap(chunks, file = "") {
|
|
1079
|
+
const smg = new source_map_js.SourceMapGenerator({ file });
|
|
1080
|
+
const position = {
|
|
1081
|
+
line: 1,
|
|
1082
|
+
column: 0
|
|
1083
|
+
};
|
|
1084
|
+
let code = "";
|
|
1085
|
+
for (const chunk of chunks) {
|
|
1086
|
+
const chunkCode = typeof chunk === "string" ? chunk : chunk.code;
|
|
1087
|
+
if (typeof chunk !== "string" && chunk.map) appendSourceMap(smg, chunk.map, position.line - 1, position.column);
|
|
1088
|
+
code += chunkCode;
|
|
1089
|
+
advanceGeneratedPosition(position, chunkCode);
|
|
1090
|
+
}
|
|
1091
|
+
return {
|
|
1092
|
+
code,
|
|
1093
|
+
sourcemap: smg.toString()
|
|
1094
|
+
};
|
|
1095
|
+
}
|
|
1096
|
+
function createLineSourcemap(generatedCode, source, sourceContent, startLine = 1) {
|
|
1097
|
+
const smg = new source_map_js.SourceMapGenerator({ file: source });
|
|
1098
|
+
const generatedLineCount = generatedCode.split("\n").length;
|
|
1099
|
+
const sourceLineCount = Math.max(1, sourceContent.split("\n").length);
|
|
1100
|
+
for (let line = 1; line <= generatedLineCount; line++) smg.addMapping({
|
|
1101
|
+
generated: {
|
|
1102
|
+
line,
|
|
1103
|
+
column: 0
|
|
1104
|
+
},
|
|
1105
|
+
original: {
|
|
1106
|
+
line: Math.min(sourceLineCount, startLine + line - 1),
|
|
1107
|
+
column: 0
|
|
1108
|
+
},
|
|
1109
|
+
source
|
|
1110
|
+
});
|
|
1111
|
+
smg.setSourceContent(source, sourceContent);
|
|
1112
|
+
return JSON.parse(smg.toString());
|
|
1113
|
+
}
|
|
1114
|
+
function mergeSourcemap(compileRes, file = "logic.js") {
|
|
1115
|
+
const chunks = [];
|
|
1116
|
+
for (const module of compileRes) {
|
|
1117
|
+
const { header, code, footer } = wrapModDefine(module);
|
|
1118
|
+
chunks.push(header, {
|
|
1119
|
+
code,
|
|
1120
|
+
map: module.map
|
|
1121
|
+
}, footer);
|
|
1122
|
+
}
|
|
1123
|
+
const { code: bundleCode, sourcemap } = concatSourcemap(chunks, file);
|
|
1124
|
+
return {
|
|
1125
|
+
bundleCode,
|
|
1126
|
+
sourcemap
|
|
1127
|
+
};
|
|
1128
|
+
}
|
|
1129
|
+
function remapSourcemap(nextMap, prevMap) {
|
|
1130
|
+
if (!nextMap) return prevMap;
|
|
1131
|
+
if (!prevMap) return nextMap;
|
|
1132
|
+
const nextMapObj = typeof nextMap === "string" ? JSON.parse(nextMap) : nextMap;
|
|
1133
|
+
const prevMapObj = typeof prevMap === "string" ? JSON.parse(prevMap) : prevMap;
|
|
1134
|
+
const smg = new source_map_js.SourceMapGenerator({ file: nextMapObj.file || prevMapObj.file || "" });
|
|
1135
|
+
const prevSmc = new source_map_js.SourceMapConsumer(prevMapObj);
|
|
1136
|
+
new source_map_js.SourceMapConsumer(nextMapObj).eachMapping((mapping) => {
|
|
1137
|
+
if (mapping.source == null || mapping.originalLine == null || mapping.originalColumn == null) return;
|
|
1138
|
+
const original = prevSmc.originalPositionFor({
|
|
1139
|
+
line: mapping.originalLine,
|
|
1140
|
+
column: mapping.originalColumn
|
|
1141
|
+
});
|
|
1142
|
+
if (original.source == null || original.line == null || original.column == null) return;
|
|
1143
|
+
smg.addMapping({
|
|
1144
|
+
generated: {
|
|
1145
|
+
line: mapping.generatedLine,
|
|
1146
|
+
column: mapping.generatedColumn
|
|
1147
|
+
},
|
|
1148
|
+
original: {
|
|
1149
|
+
line: original.line,
|
|
1150
|
+
column: original.column
|
|
1151
|
+
},
|
|
1152
|
+
source: original.source,
|
|
1153
|
+
name: original.name || mapping.name
|
|
1154
|
+
});
|
|
1155
|
+
});
|
|
1156
|
+
if (prevMapObj.sourcesContent) prevMapObj.sources.forEach((src, i) => {
|
|
1157
|
+
smg.setSourceContent(src, prevMapObj.sourcesContent[i]);
|
|
1158
|
+
});
|
|
1159
|
+
return smg.toString();
|
|
1160
|
+
}
|
|
1161
|
+
//#endregion
|
|
1162
|
+
Object.defineProperty(exports, "DependencyGraph", {
|
|
1163
|
+
enumerable: true,
|
|
1164
|
+
get: function() {
|
|
1165
|
+
return DependencyGraph;
|
|
1166
|
+
}
|
|
1167
|
+
});
|
|
1168
|
+
Object.defineProperty(exports, "__toESM", {
|
|
1169
|
+
enumerable: true,
|
|
1170
|
+
get: function() {
|
|
1171
|
+
return __toESM;
|
|
1172
|
+
}
|
|
1173
|
+
});
|
|
1174
|
+
Object.defineProperty(exports, "collectAssets", {
|
|
1175
|
+
enumerable: true,
|
|
1176
|
+
get: function() {
|
|
1177
|
+
return collectAssets;
|
|
1178
|
+
}
|
|
1179
|
+
});
|
|
1180
|
+
Object.defineProperty(exports, "concatSourcemap", {
|
|
1181
|
+
enumerable: true,
|
|
1182
|
+
get: function() {
|
|
1183
|
+
return concatSourcemap;
|
|
1184
|
+
}
|
|
1185
|
+
});
|
|
1186
|
+
Object.defineProperty(exports, "createLineSourcemap", {
|
|
1187
|
+
enumerable: true,
|
|
1188
|
+
get: function() {
|
|
1189
|
+
return createLineSourcemap;
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
Object.defineProperty(exports, "getAbsolutePath", {
|
|
1193
|
+
enumerable: true,
|
|
1194
|
+
get: function() {
|
|
1195
|
+
return getAbsolutePath;
|
|
1196
|
+
}
|
|
1197
|
+
});
|
|
1198
|
+
Object.defineProperty(exports, "getAppConfigInfo", {
|
|
1199
|
+
enumerable: true,
|
|
1200
|
+
get: function() {
|
|
1201
|
+
return getAppConfigInfo;
|
|
1202
|
+
}
|
|
1203
|
+
});
|
|
1204
|
+
Object.defineProperty(exports, "getAppId", {
|
|
1205
|
+
enumerable: true,
|
|
1206
|
+
get: function() {
|
|
1207
|
+
return getAppId;
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
Object.defineProperty(exports, "getAppName", {
|
|
1211
|
+
enumerable: true,
|
|
1212
|
+
get: function() {
|
|
1213
|
+
return getAppName;
|
|
1214
|
+
}
|
|
1215
|
+
});
|
|
1216
|
+
Object.defineProperty(exports, "getAppStyleScopeId", {
|
|
1217
|
+
enumerable: true,
|
|
1218
|
+
get: function() {
|
|
1219
|
+
return getAppStyleScopeId;
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
Object.defineProperty(exports, "getComponent", {
|
|
1223
|
+
enumerable: true,
|
|
1224
|
+
get: function() {
|
|
1225
|
+
return getComponent;
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1228
|
+
Object.defineProperty(exports, "getContentByPath", {
|
|
1229
|
+
enumerable: true,
|
|
1230
|
+
get: function() {
|
|
1231
|
+
return getContentByPath;
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
Object.defineProperty(exports, "getDependencyGraph", {
|
|
1235
|
+
enumerable: true,
|
|
1236
|
+
get: function() {
|
|
1237
|
+
return getDependencyGraph;
|
|
1238
|
+
}
|
|
1239
|
+
});
|
|
1240
|
+
Object.defineProperty(exports, "getNpmResolver", {
|
|
1241
|
+
enumerable: true,
|
|
1242
|
+
get: function() {
|
|
1243
|
+
return getNpmResolver;
|
|
1244
|
+
}
|
|
1245
|
+
});
|
|
1246
|
+
Object.defineProperty(exports, "getPageConfigInfo", {
|
|
1247
|
+
enumerable: true,
|
|
1248
|
+
get: function() {
|
|
1249
|
+
return getPageConfigInfo;
|
|
1250
|
+
}
|
|
1251
|
+
});
|
|
1252
|
+
Object.defineProperty(exports, "getPages", {
|
|
1253
|
+
enumerable: true,
|
|
1254
|
+
get: function() {
|
|
1255
|
+
return getPages;
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
Object.defineProperty(exports, "getProjectConfig", {
|
|
1259
|
+
enumerable: true,
|
|
1260
|
+
get: function() {
|
|
1261
|
+
return getProjectConfig;
|
|
1262
|
+
}
|
|
1263
|
+
});
|
|
1264
|
+
Object.defineProperty(exports, "getStyleExts", {
|
|
1265
|
+
enumerable: true,
|
|
1266
|
+
get: function() {
|
|
1267
|
+
return getStyleExts;
|
|
1268
|
+
}
|
|
1269
|
+
});
|
|
1270
|
+
Object.defineProperty(exports, "getTargetPath", {
|
|
1271
|
+
enumerable: true,
|
|
1272
|
+
get: function() {
|
|
1273
|
+
return getTargetPath;
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
Object.defineProperty(exports, "getTemplateDirectivePrefixes", {
|
|
1277
|
+
enumerable: true,
|
|
1278
|
+
get: function() {
|
|
1279
|
+
return getTemplateDirectivePrefixes;
|
|
1280
|
+
}
|
|
1281
|
+
});
|
|
1282
|
+
Object.defineProperty(exports, "getTemplateExts", {
|
|
1283
|
+
enumerable: true,
|
|
1284
|
+
get: function() {
|
|
1285
|
+
return getTemplateExts;
|
|
1286
|
+
}
|
|
1287
|
+
});
|
|
1288
|
+
Object.defineProperty(exports, "getViewScriptExts", {
|
|
1289
|
+
enumerable: true,
|
|
1290
|
+
get: function() {
|
|
1291
|
+
return getViewScriptExts;
|
|
1292
|
+
}
|
|
1293
|
+
});
|
|
1294
|
+
Object.defineProperty(exports, "getViewScriptTags", {
|
|
1295
|
+
enumerable: true,
|
|
1296
|
+
get: function() {
|
|
1297
|
+
return getViewScriptTags;
|
|
1298
|
+
}
|
|
1299
|
+
});
|
|
1300
|
+
Object.defineProperty(exports, "getWorkPath", {
|
|
1301
|
+
enumerable: true,
|
|
1302
|
+
get: function() {
|
|
1303
|
+
return getWorkPath;
|
|
1304
|
+
}
|
|
1305
|
+
});
|
|
1306
|
+
Object.defineProperty(exports, "hasCompileInfo", {
|
|
1307
|
+
enumerable: true,
|
|
1308
|
+
get: function() {
|
|
1309
|
+
return hasCompileInfo;
|
|
1310
|
+
}
|
|
1311
|
+
});
|
|
1312
|
+
Object.defineProperty(exports, "mergeSourcemap", {
|
|
1313
|
+
enumerable: true,
|
|
1314
|
+
get: function() {
|
|
1315
|
+
return mergeSourcemap;
|
|
1316
|
+
}
|
|
1317
|
+
});
|
|
1318
|
+
Object.defineProperty(exports, "miniProgramBuiltinTags", {
|
|
1319
|
+
enumerable: true,
|
|
1320
|
+
get: function() {
|
|
1321
|
+
return miniProgramBuiltinTags;
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
Object.defineProperty(exports, "remapSourcemap", {
|
|
1325
|
+
enumerable: true,
|
|
1326
|
+
get: function() {
|
|
1327
|
+
return remapSourcemap;
|
|
1328
|
+
}
|
|
1329
|
+
});
|
|
1330
|
+
Object.defineProperty(exports, "resetAssetCache", {
|
|
1331
|
+
enumerable: true,
|
|
1332
|
+
get: function() {
|
|
1333
|
+
return resetAssetCache;
|
|
1334
|
+
}
|
|
1335
|
+
});
|
|
1336
|
+
Object.defineProperty(exports, "resetStoreInfo", {
|
|
1337
|
+
enumerable: true,
|
|
1338
|
+
get: function() {
|
|
1339
|
+
return resetStoreInfo;
|
|
1340
|
+
}
|
|
1341
|
+
});
|
|
1342
|
+
Object.defineProperty(exports, "resolveAppAlias", {
|
|
1343
|
+
enumerable: true,
|
|
1344
|
+
get: function() {
|
|
1345
|
+
return resolveAppAlias;
|
|
1346
|
+
}
|
|
1347
|
+
});
|
|
1348
|
+
Object.defineProperty(exports, "resolveAssetSourcePath", {
|
|
1349
|
+
enumerable: true,
|
|
1350
|
+
get: function() {
|
|
1351
|
+
return resolveAssetSourcePath;
|
|
1352
|
+
}
|
|
1353
|
+
});
|
|
1354
|
+
Object.defineProperty(exports, "storeInfo", {
|
|
1355
|
+
enumerable: true,
|
|
1356
|
+
get: function() {
|
|
1357
|
+
return storeInfo;
|
|
1358
|
+
}
|
|
1359
|
+
});
|
|
1360
|
+
Object.defineProperty(exports, "tagWhiteList", {
|
|
1361
|
+
enumerable: true,
|
|
1362
|
+
get: function() {
|
|
1363
|
+
return tagWhiteList;
|
|
1364
|
+
}
|
|
1365
|
+
});
|
|
1366
|
+
Object.defineProperty(exports, "toMiniProgramModuleId", {
|
|
1367
|
+
enumerable: true,
|
|
1368
|
+
get: function() {
|
|
1369
|
+
return toMiniProgramModuleId;
|
|
1370
|
+
}
|
|
1371
|
+
});
|
|
1372
|
+
Object.defineProperty(exports, "transformRpx", {
|
|
1373
|
+
enumerable: true,
|
|
1374
|
+
get: function() {
|
|
1375
|
+
return transformRpx;
|
|
1376
|
+
}
|
|
1377
|
+
});
|