@dimina/compiler 1.0.12 → 1.0.14-beta.0
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 +100 -29
- package/dist/bin/index.js +92 -23
- package/dist/core/logic-compiler.cjs +351 -361
- package/dist/core/logic-compiler.js +340 -355
- package/dist/core/style-compiler.cjs +220 -228
- package/dist/core/style-compiler.js +200 -206
- package/dist/core/view-compiler.cjs +1224 -8312
- package/dist/core/view-compiler.js +1201 -8289
- package/dist/env-DgCLbrQb.js +560 -0
- package/dist/env-M-7lpbHL.cjs +705 -0
- package/dist/index.cjs +420 -461
- package/dist/index.js +410 -455
- package/package.json +10 -10
- package/dist/env-Cmen1qwy.cjs +0 -543
- package/dist/env-QQjdhY-G.js +0 -544
|
@@ -0,0 +1,705 @@
|
|
|
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_path = require("node:path");
|
|
24
|
+
node_path = __toESM(node_path, 1);
|
|
25
|
+
let node_process = require("node:process");
|
|
26
|
+
node_process = __toESM(node_process, 1);
|
|
27
|
+
let node_fs = require("node:fs");
|
|
28
|
+
node_fs = __toESM(node_fs, 1);
|
|
29
|
+
let node_os = require("node:os");
|
|
30
|
+
node_os = __toESM(node_os, 1);
|
|
31
|
+
//#region src/common/path-utils.js
|
|
32
|
+
var WINDOWS_FS_PATH_RE = /^(?:[a-zA-Z]:[\\/]|\\\\)/;
|
|
33
|
+
function isWindowsFsPath(targetPath) {
|
|
34
|
+
return typeof targetPath === "string" && (WINDOWS_FS_PATH_RE.test(targetPath) || targetPath.includes("\\"));
|
|
35
|
+
}
|
|
36
|
+
function getFsPathApi(targetPath) {
|
|
37
|
+
return isWindowsFsPath(targetPath) ? node_path.default.win32 : node_path.default.posix;
|
|
38
|
+
}
|
|
39
|
+
function normalizeToPosixPath(targetPath) {
|
|
40
|
+
return targetPath.replace(/\\/g, "/");
|
|
41
|
+
}
|
|
42
|
+
function resolveMiniProgramPath(workPath, importerPath, sourcePath) {
|
|
43
|
+
const pathApi = getFsPathApi(importerPath || workPath);
|
|
44
|
+
return sourcePath.startsWith("/") ? pathApi.join(workPath, sourcePath) : pathApi.resolve(pathApi.dirname(importerPath), sourcePath);
|
|
45
|
+
}
|
|
46
|
+
function toMiniProgramModuleId(resolvedPath, workPath) {
|
|
47
|
+
const normalizedResolvedPath = normalizeToPosixPath(resolvedPath);
|
|
48
|
+
const normalizedWorkPath = normalizeToPosixPath(workPath);
|
|
49
|
+
let moduleId = normalizedResolvedPath.startsWith(normalizedWorkPath) ? normalizedResolvedPath.slice(normalizedWorkPath.length) : normalizedResolvedPath;
|
|
50
|
+
moduleId = moduleId.replace(/\/+/g, "/");
|
|
51
|
+
if (!moduleId.startsWith("/")) moduleId = `/${moduleId}`;
|
|
52
|
+
return moduleId;
|
|
53
|
+
}
|
|
54
|
+
function getRelativePosixPath(targetPath, rootPath) {
|
|
55
|
+
return normalizeToPosixPath(targetPath).replace(normalizeToPosixPath(rootPath), "").replace(/^\//, "");
|
|
56
|
+
}
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/common/art.js
|
|
59
|
+
var artCode = `
|
|
60
|
+
██████╗ ██╗███╗ ███╗██╗███╗ ██╗ █████╗
|
|
61
|
+
██╔══██╗██║████╗ ████║██║████╗ ██║██╔══██╗
|
|
62
|
+
██║ ██║██║██╔████╔██║██║██╔██╗ ██║███████║
|
|
63
|
+
██║ ██║██║██║╚██╔╝██║██║██║╚██╗██║██╔══██║
|
|
64
|
+
██████╔╝██║██║ ╚═╝ ██║██║██║ ╚████║██║ ██║
|
|
65
|
+
╚═════╝ ╚═╝╚═╝ ╚═╝╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝
|
|
66
|
+
`;
|
|
67
|
+
function art_default() {
|
|
68
|
+
console.log(artCode);
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/common/utils.js
|
|
72
|
+
function hasCompileInfo(modulePath, list, preList) {
|
|
73
|
+
const mergeList = Array.isArray(preList) ? [...preList, ...list] : list;
|
|
74
|
+
for (const element of mergeList) if (element.path === modulePath) return true;
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
function getAbsolutePath(workPath, pagePath, src) {
|
|
78
|
+
if (src.startsWith("/")) return node_path.default.join(workPath, src);
|
|
79
|
+
if (pagePath.includes("/miniprogram_npm/")) {
|
|
80
|
+
const componentFullPath = workPath + pagePath.split("/").slice(0, -1).join("/");
|
|
81
|
+
return node_path.default.resolve(componentFullPath, src);
|
|
82
|
+
}
|
|
83
|
+
const relativePath = pagePath.split("/").filter((part) => part !== "").slice(0, -1).join("/");
|
|
84
|
+
return node_path.default.resolve(workPath, relativePath, src);
|
|
85
|
+
}
|
|
86
|
+
var assetsMap = {};
|
|
87
|
+
/**
|
|
88
|
+
* 将静态资源存储到 static 文件夹
|
|
89
|
+
*/
|
|
90
|
+
function collectAssets(workPath, pagePath, src, targetPath, appId) {
|
|
91
|
+
if (src.startsWith("http") || src.startsWith("//")) return src;
|
|
92
|
+
if (!/\.(?:png|jpe?g|gif|svg)(?:\?.*)?$/.test(src)) return src;
|
|
93
|
+
const relativePath = pagePath.split("/").slice(0, -1).join("/");
|
|
94
|
+
const absolutePath = src.startsWith("/") ? workPath + src : node_path.default.resolve(workPath, relativePath, src);
|
|
95
|
+
if (assetsMap[absolutePath]) return assetsMap[absolutePath];
|
|
96
|
+
try {
|
|
97
|
+
const ext = `.${src.split(".").pop()}`;
|
|
98
|
+
const dirPath = absolutePath.split(node_path.default.sep).slice(0, -1).join("/");
|
|
99
|
+
const prefix = uuid();
|
|
100
|
+
const targetStatic = `${targetPath}/main/static`;
|
|
101
|
+
if (!node_fs.default.existsSync(targetStatic)) node_fs.default.mkdirSync(targetStatic, { recursive: true });
|
|
102
|
+
getFilesWithExtension(dirPath, ext).forEach((file) => {
|
|
103
|
+
node_fs.default.copyFileSync(node_path.default.resolve(dirPath, file), `${targetStatic}/${prefix}_${file}`);
|
|
104
|
+
});
|
|
105
|
+
const filename = src.split("/").pop();
|
|
106
|
+
assetsMap[absolutePath] = `${node_process.default.env.ASSETS_PATH_PREFIX ? "" : "/"}${appId}/main/static/${prefix}_${filename}`;
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.log(error);
|
|
109
|
+
}
|
|
110
|
+
return assetsMap[absolutePath] || src;
|
|
111
|
+
}
|
|
112
|
+
function getFilesWithExtension(directory, extension) {
|
|
113
|
+
return node_fs.default.readdirSync(directory).filter((file) => node_path.default.extname(file) === extension);
|
|
114
|
+
}
|
|
115
|
+
function isObjectEmpty(objectName) {
|
|
116
|
+
if (!objectName) return true;
|
|
117
|
+
return Object.keys(objectName).length === 0 && objectName.constructor === Object;
|
|
118
|
+
}
|
|
119
|
+
function isString(o) {
|
|
120
|
+
return Object.prototype.toString.call(o) === "[object String]";
|
|
121
|
+
}
|
|
122
|
+
function transformRpx(styleText) {
|
|
123
|
+
if (!isString(styleText)) return styleText;
|
|
124
|
+
return styleText.replace(/([+-]?\d+(?:\.\d+)?)rpx/g, (_, pixel) => {
|
|
125
|
+
return `${Number(pixel)}rem`;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
function uuid() {
|
|
129
|
+
return Math.random().toString(36).slice(2, 7);
|
|
130
|
+
}
|
|
131
|
+
var tagWhiteList = [
|
|
132
|
+
"page",
|
|
133
|
+
"wrapper",
|
|
134
|
+
"block",
|
|
135
|
+
"button",
|
|
136
|
+
"camera",
|
|
137
|
+
"checkbox-group",
|
|
138
|
+
"checkbox",
|
|
139
|
+
"cover-image",
|
|
140
|
+
"cover-view",
|
|
141
|
+
"form",
|
|
142
|
+
"icon",
|
|
143
|
+
"image",
|
|
144
|
+
"input",
|
|
145
|
+
"keyboard-accessory",
|
|
146
|
+
"label",
|
|
147
|
+
"map",
|
|
148
|
+
"movable-area",
|
|
149
|
+
"movable-view",
|
|
150
|
+
"navigation-bar",
|
|
151
|
+
"navigator",
|
|
152
|
+
"open-data",
|
|
153
|
+
"page-meta",
|
|
154
|
+
"picker-view-column",
|
|
155
|
+
"picker-view",
|
|
156
|
+
"picker",
|
|
157
|
+
"progress",
|
|
158
|
+
"radio-group",
|
|
159
|
+
"radio",
|
|
160
|
+
"rich-text",
|
|
161
|
+
"root-portal",
|
|
162
|
+
"scroll-view",
|
|
163
|
+
"slider",
|
|
164
|
+
"swiper-item",
|
|
165
|
+
"swiper",
|
|
166
|
+
"switch",
|
|
167
|
+
"template",
|
|
168
|
+
"text",
|
|
169
|
+
"textarea",
|
|
170
|
+
"video",
|
|
171
|
+
"view",
|
|
172
|
+
"web-view"
|
|
173
|
+
];
|
|
174
|
+
//#endregion
|
|
175
|
+
//#region src/common/npm-resolver.js
|
|
176
|
+
/**
|
|
177
|
+
* npm 组件解析器
|
|
178
|
+
* 根据微信小程序 npm 支持规范实现组件寻址
|
|
179
|
+
* https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html
|
|
180
|
+
*/
|
|
181
|
+
var NpmResolver = class {
|
|
182
|
+
constructor(workPath) {
|
|
183
|
+
this.workPath = workPath;
|
|
184
|
+
this.miniprogramNpmCache = /* @__PURE__ */ new Map();
|
|
185
|
+
this.packageCache = /* @__PURE__ */ new Map();
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 解析组件路径,支持 npm 包组件
|
|
189
|
+
* @param {string} componentPath 组件路径
|
|
190
|
+
* @param {string} pageFilePath 页面文件路径
|
|
191
|
+
* @returns {string} 解析后的组件路径
|
|
192
|
+
*/
|
|
193
|
+
resolveComponentPath(componentPath, pageFilePath) {
|
|
194
|
+
if (componentPath.startsWith("./") || componentPath.startsWith("../") || componentPath.startsWith("/")) return this.resolveRelativePath(componentPath, pageFilePath);
|
|
195
|
+
const npmPath = this.resolveNpmComponent(componentPath, pageFilePath);
|
|
196
|
+
if (npmPath) return npmPath;
|
|
197
|
+
return this.resolveRelativePath(componentPath, pageFilePath);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* 解析相对路径组件
|
|
201
|
+
* @param {string} componentPath 组件路径
|
|
202
|
+
* @param {string} pageFilePath 页面文件路径
|
|
203
|
+
* @returns {string} 解析后的路径
|
|
204
|
+
*/
|
|
205
|
+
resolveRelativePath(componentPath, pageFilePath) {
|
|
206
|
+
return toMiniProgramModuleId(resolveMiniProgramPath(this.workPath, pageFilePath, componentPath), this.workPath);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* 解析 npm 组件
|
|
210
|
+
* @param {string} componentName 组件名称
|
|
211
|
+
* @param {string} pageFilePath 页面文件路径
|
|
212
|
+
* @returns {string|null} 解析后的组件路径,如果找不到返回 null
|
|
213
|
+
*/
|
|
214
|
+
resolveNpmComponent(componentName, pageFilePath) {
|
|
215
|
+
const searchPaths = this.generateSearchPaths(pageFilePath);
|
|
216
|
+
for (const searchPath of searchPaths) {
|
|
217
|
+
const componentPath = this.findComponentInMiniprogramNpm(componentName, searchPath);
|
|
218
|
+
if (componentPath) return componentPath;
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* 解析脚本模块路径,支持微信小程序 npm 逐级寻址和 package.json 入口
|
|
224
|
+
* @param {string} specifier 模块导入路径
|
|
225
|
+
* @param {string} modulePath 当前模块绝对文件路径
|
|
226
|
+
* @param {(moduleId: string) => string | null} resolveExistingModuleId 解析真实存在模块的回调
|
|
227
|
+
* @returns {string|null} 解析后的模块 id
|
|
228
|
+
*/
|
|
229
|
+
resolveScriptModule(specifier, modulePath, resolveExistingModuleId) {
|
|
230
|
+
if (!specifier || !resolveExistingModuleId) return null;
|
|
231
|
+
for (const searchPath of this.generateSearchPaths(modulePath)) {
|
|
232
|
+
const resolvedModuleId = resolveExistingModuleId(this.normalizeModuleId(`/${searchPath}/${specifier}`));
|
|
233
|
+
if (resolvedModuleId) return resolvedModuleId;
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* 生成 miniprogram_npm 搜索路径
|
|
239
|
+
* 按照微信小程序的寻址顺序生成搜索路径
|
|
240
|
+
* @param {string} pageFilePath 页面文件路径
|
|
241
|
+
* @returns {string[]} 搜索路径数组
|
|
242
|
+
*/
|
|
243
|
+
generateSearchPaths(pageFilePath) {
|
|
244
|
+
const pathParts = getRelativePosixPath(pageFilePath, this.workPath).split("/").slice(0, -1);
|
|
245
|
+
const searchPaths = [];
|
|
246
|
+
for (let i = pathParts.length; i >= 0; i--) {
|
|
247
|
+
const currentPath = pathParts.slice(0, i).join("/");
|
|
248
|
+
const miniprogramNpmPath = currentPath ? `${currentPath}/miniprogram_npm` : "miniprogram_npm";
|
|
249
|
+
searchPaths.push(miniprogramNpmPath);
|
|
250
|
+
}
|
|
251
|
+
return searchPaths;
|
|
252
|
+
}
|
|
253
|
+
/**
|
|
254
|
+
* 在指定的 miniprogram_npm 目录中查找组件
|
|
255
|
+
* @param {string} componentName 组件名称
|
|
256
|
+
* @param {string} miniprogramNpmPath miniprogram_npm 路径
|
|
257
|
+
* @returns {string|null} 组件路径,如果找不到返回 null
|
|
258
|
+
*/
|
|
259
|
+
findComponentInMiniprogramNpm(componentName, miniprogramNpmPath) {
|
|
260
|
+
const fullMiniprogramNpmPath = node_path.default.join(this.workPath, miniprogramNpmPath);
|
|
261
|
+
if (!node_fs.default.existsSync(fullMiniprogramNpmPath)) return null;
|
|
262
|
+
const cacheKey = `${miniprogramNpmPath}/${componentName}`;
|
|
263
|
+
if (this.miniprogramNpmCache.has(cacheKey)) return this.miniprogramNpmCache.get(cacheKey);
|
|
264
|
+
const candidatePaths = [componentName, `${componentName}/index`];
|
|
265
|
+
for (const candidatePath of candidatePaths) {
|
|
266
|
+
const componentDir = node_path.default.join(fullMiniprogramNpmPath, candidatePath);
|
|
267
|
+
if (this.isValidComponent(componentDir)) {
|
|
268
|
+
const resolvedPath = `/${miniprogramNpmPath}/${candidatePath}`.replace(/\/+/g, "/");
|
|
269
|
+
this.miniprogramNpmCache.set(cacheKey, resolvedPath);
|
|
270
|
+
return resolvedPath;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
this.miniprogramNpmCache.set(cacheKey, null);
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
normalizeModuleId(moduleId) {
|
|
277
|
+
let normalized = moduleId.replace(/\.(js|ts)$/, "").replace(/\\/g, "/");
|
|
278
|
+
if (!normalized.startsWith("/")) normalized = `/${normalized}`;
|
|
279
|
+
return normalized;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* 检查是否为有效的组件
|
|
283
|
+
* @param {string} componentPath 组件路径
|
|
284
|
+
* @returns {boolean} 是否为有效组件
|
|
285
|
+
*/
|
|
286
|
+
isValidComponent(componentPath) {
|
|
287
|
+
const requiredFiles = [".json", ".js"];
|
|
288
|
+
if (!requiredFiles.some((ext) => {
|
|
289
|
+
return node_fs.default.existsSync(`${componentPath}${ext}`);
|
|
290
|
+
})) {
|
|
291
|
+
if (!requiredFiles.some((ext) => {
|
|
292
|
+
return node_fs.default.existsSync(node_path.default.join(componentPath, `index${ext}`));
|
|
293
|
+
})) return false;
|
|
294
|
+
const indexJsonFile = node_path.default.join(componentPath, "index.json");
|
|
295
|
+
if (node_fs.default.existsSync(indexJsonFile)) try {
|
|
296
|
+
return JSON.parse(node_fs.default.readFileSync(indexJsonFile, "utf-8")).component === true;
|
|
297
|
+
} catch (e) {
|
|
298
|
+
return false;
|
|
299
|
+
}
|
|
300
|
+
return true;
|
|
301
|
+
}
|
|
302
|
+
const jsonFile = `${componentPath}.json`;
|
|
303
|
+
if (node_fs.default.existsSync(jsonFile)) try {
|
|
304
|
+
return JSON.parse(node_fs.default.readFileSync(jsonFile, "utf-8")).component === true;
|
|
305
|
+
} catch (e) {
|
|
306
|
+
return false;
|
|
307
|
+
}
|
|
308
|
+
return true;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* 获取 npm 包信息
|
|
312
|
+
* @param {string} packageName 包名
|
|
313
|
+
* @param {string} searchPath 搜索路径
|
|
314
|
+
* @returns {object|null} 包信息,如果找不到返回 null
|
|
315
|
+
*/
|
|
316
|
+
getPackageInfo(packageName, searchPath) {
|
|
317
|
+
const cacheKey = `${searchPath}/${packageName}`;
|
|
318
|
+
if (this.packageCache.has(cacheKey)) return this.packageCache.get(cacheKey);
|
|
319
|
+
const packageJsonPath = node_path.default.join(this.workPath, searchPath, packageName, "package.json");
|
|
320
|
+
if (!node_fs.default.existsSync(packageJsonPath)) {
|
|
321
|
+
this.packageCache.set(cacheKey, null);
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
try {
|
|
325
|
+
const packageInfo = JSON.parse(node_fs.default.readFileSync(packageJsonPath, "utf-8"));
|
|
326
|
+
this.packageCache.set(cacheKey, packageInfo);
|
|
327
|
+
return packageInfo;
|
|
328
|
+
} catch (e) {
|
|
329
|
+
this.packageCache.set(cacheKey, null);
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* 清除缓存
|
|
335
|
+
*/
|
|
336
|
+
clearCache() {
|
|
337
|
+
this.miniprogramNpmCache.clear();
|
|
338
|
+
this.packageCache.clear();
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/env.js
|
|
343
|
+
var pathInfo = {};
|
|
344
|
+
var configInfo = {};
|
|
345
|
+
var npmResolver = null;
|
|
346
|
+
/**
|
|
347
|
+
* 持久化编译过程的上下文
|
|
348
|
+
*/
|
|
349
|
+
function storeInfo(workPath) {
|
|
350
|
+
storePathInfo(workPath);
|
|
351
|
+
storeProjectConfig();
|
|
352
|
+
storeAppConfig();
|
|
353
|
+
storePageConfig();
|
|
354
|
+
return {
|
|
355
|
+
pathInfo,
|
|
356
|
+
configInfo
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function resetStoreInfo(opts) {
|
|
360
|
+
pathInfo = opts.pathInfo;
|
|
361
|
+
configInfo = opts.configInfo;
|
|
362
|
+
if (pathInfo.workPath) npmResolver = new NpmResolver(pathInfo.workPath);
|
|
363
|
+
}
|
|
364
|
+
function storePathInfo(workPath) {
|
|
365
|
+
pathInfo.workPath = workPath;
|
|
366
|
+
if (node_process.default.env.TARGET_PATH) pathInfo.targetPath = node_process.default.env.TARGET_PATH;
|
|
367
|
+
else {
|
|
368
|
+
const tempDir = node_process.default.env.GITHUB_WORKSPACE || node_os.default.tmpdir();
|
|
369
|
+
const targetDir = node_path.default.join(tempDir, `dimina-fe-dist-${Date.now()}`);
|
|
370
|
+
if (!node_fs.default.existsSync(targetDir)) node_fs.default.mkdirSync(targetDir, { recursive: true });
|
|
371
|
+
pathInfo.targetPath = targetDir;
|
|
372
|
+
}
|
|
373
|
+
npmResolver = new NpmResolver(workPath);
|
|
374
|
+
}
|
|
375
|
+
function storeProjectConfig() {
|
|
376
|
+
const privateConfigPath = `${pathInfo.workPath}/project.private.config.json`;
|
|
377
|
+
const defaultConfigPath = `${pathInfo.workPath}/project.config.json`;
|
|
378
|
+
let privateConfig = {};
|
|
379
|
+
let defaultConfig = {};
|
|
380
|
+
if (node_fs.default.existsSync(defaultConfigPath)) try {
|
|
381
|
+
defaultConfig = parseContentByPath(defaultConfigPath);
|
|
382
|
+
} catch (e) {
|
|
383
|
+
console.warn("Failed to parse project.config.json:", e.message);
|
|
384
|
+
}
|
|
385
|
+
if (node_fs.default.existsSync(privateConfigPath)) try {
|
|
386
|
+
privateConfig = parseContentByPath(privateConfigPath);
|
|
387
|
+
} catch (e) {
|
|
388
|
+
console.warn("Failed to parse project.private.config.json:", e.message);
|
|
389
|
+
}
|
|
390
|
+
configInfo.projectInfo = {
|
|
391
|
+
...defaultConfig,
|
|
392
|
+
...privateConfig
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
function storeAppConfig() {
|
|
396
|
+
const content = parseContentByPath(`${pathInfo.workPath}/app.json`);
|
|
397
|
+
const newObj = {};
|
|
398
|
+
for (const key in content) if (Object.hasOwn(content, key)) if (key === "subpackages") newObj.subPackages = content[key];
|
|
399
|
+
else newObj[key] = content[key];
|
|
400
|
+
configInfo.appInfo = newObj;
|
|
401
|
+
}
|
|
402
|
+
function getContentByPath(path) {
|
|
403
|
+
return node_fs.default.readFileSync(path, { encoding: "utf-8" });
|
|
404
|
+
}
|
|
405
|
+
function parseContentByPath(path) {
|
|
406
|
+
return JSON.parse(getContentByPath(path));
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* 收集页面 json 信息
|
|
410
|
+
*/
|
|
411
|
+
function storePageConfig() {
|
|
412
|
+
const { pages, subPackages } = configInfo.appInfo;
|
|
413
|
+
configInfo.pageInfo = {};
|
|
414
|
+
configInfo.componentInfo = {};
|
|
415
|
+
if (configInfo.appInfo.usingComponents) {
|
|
416
|
+
const appFilePath = `${pathInfo.workPath}/app.json`;
|
|
417
|
+
storeComponentConfig(configInfo.appInfo, appFilePath);
|
|
418
|
+
}
|
|
419
|
+
collectionPageJson(pages);
|
|
420
|
+
if (subPackages) subPackages.forEach((subPkg) => {
|
|
421
|
+
collectionPageJson(subPkg.pages, subPkg.root);
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* 匹配页面和对应的配置信息
|
|
426
|
+
* @param {*} pages
|
|
427
|
+
*/
|
|
428
|
+
function collectionPageJson(pages, root) {
|
|
429
|
+
pages.forEach((pagePath) => {
|
|
430
|
+
let np = pagePath;
|
|
431
|
+
if (root) {
|
|
432
|
+
if (!root.endsWith("/")) root += "/";
|
|
433
|
+
np = root + np;
|
|
434
|
+
}
|
|
435
|
+
const pageFilePath = `${pathInfo.workPath}/${np}.json`;
|
|
436
|
+
if (node_fs.default.existsSync(pageFilePath)) {
|
|
437
|
+
const pageJsonContent = parseContentByPath(pageFilePath);
|
|
438
|
+
if (root) pageJsonContent.root = transSubDir(root);
|
|
439
|
+
configInfo.pageInfo[np] = pageJsonContent;
|
|
440
|
+
storeComponentConfig(pageJsonContent, pageFilePath);
|
|
441
|
+
}
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* 按页面收集组件 json 信息
|
|
446
|
+
* @param {*} pageJsonContent
|
|
447
|
+
* @param {*} pageFilePath
|
|
448
|
+
*/
|
|
449
|
+
function storeComponentConfig(pageJsonContent, pageFilePath) {
|
|
450
|
+
if (isObjectEmpty(pageJsonContent.usingComponents)) return;
|
|
451
|
+
for (const [componentName, componentPath] of Object.entries(pageJsonContent.usingComponents)) {
|
|
452
|
+
const moduleId = getModuleId(componentPath, pageFilePath);
|
|
453
|
+
pageJsonContent.usingComponents[componentName] = moduleId;
|
|
454
|
+
if (configInfo.componentInfo[moduleId]) continue;
|
|
455
|
+
let componentFilePath = node_path.default.resolve(getWorkPath(), `./${moduleId}.json`);
|
|
456
|
+
let cContent = null;
|
|
457
|
+
if (node_fs.default.existsSync(componentFilePath)) cContent = parseContentByPath(componentFilePath);
|
|
458
|
+
else {
|
|
459
|
+
const indexJsonPath = node_path.default.resolve(getWorkPath(), `./${moduleId}/index.json`);
|
|
460
|
+
if (node_fs.default.existsSync(indexJsonPath)) {
|
|
461
|
+
componentFilePath = indexJsonPath;
|
|
462
|
+
cContent = parseContentByPath(componentFilePath);
|
|
463
|
+
} else if (moduleId.includes("/miniprogram_npm/")) {
|
|
464
|
+
console.log(`[env] 为 npm 组件创建默认配置: ${moduleId}`);
|
|
465
|
+
cContent = {
|
|
466
|
+
component: true,
|
|
467
|
+
usingComponents: {}
|
|
468
|
+
};
|
|
469
|
+
} else {
|
|
470
|
+
console.warn(`[env] 组件配置文件不存在: ${componentFilePath}`);
|
|
471
|
+
continue;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const cUsing = cContent.usingComponents || {};
|
|
475
|
+
const isComponent = cContent.component || false;
|
|
476
|
+
const cComponents = Object.keys(cUsing).reduce((acc, key) => {
|
|
477
|
+
acc[key] = getModuleId(cUsing[key], componentFilePath);
|
|
478
|
+
return acc;
|
|
479
|
+
}, {});
|
|
480
|
+
configInfo.componentInfo[moduleId] = {
|
|
481
|
+
id: uuid(),
|
|
482
|
+
path: moduleId,
|
|
483
|
+
component: isComponent,
|
|
484
|
+
usingComponents: cComponents
|
|
485
|
+
};
|
|
486
|
+
if (cContent.usingComponents && Object.keys(cContent.usingComponents).length > 0) storeComponentConfig(configInfo.componentInfo[moduleId], componentFilePath);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* 转化为相对小程序根目录的绝对路径,作为模块唯一性 id
|
|
491
|
+
* 支持 npm 组件解析
|
|
492
|
+
* @param {string} src
|
|
493
|
+
*/
|
|
494
|
+
function getModuleId(src, pageFilePath) {
|
|
495
|
+
const resolvedAlias = resolveAppAlias(src);
|
|
496
|
+
if (resolvedAlias) return resolvedAlias;
|
|
497
|
+
if (!npmResolver) {
|
|
498
|
+
const workPath = getWorkPath();
|
|
499
|
+
return toMiniProgramModuleId(resolveMiniProgramPath(workPath, pageFilePath, src), workPath);
|
|
500
|
+
}
|
|
501
|
+
return npmResolver.resolveComponentPath(src, pageFilePath);
|
|
502
|
+
}
|
|
503
|
+
function resolveAppAlias(src) {
|
|
504
|
+
const resolveAlias = configInfo.appInfo?.resolveAlias;
|
|
505
|
+
if (!resolveAlias || typeof src !== "string") return null;
|
|
506
|
+
for (const [alias, target] of Object.entries(resolveAlias)) if (alias.endsWith("/*") && target.endsWith("/*")) {
|
|
507
|
+
const aliasPrefix = alias.slice(0, -1);
|
|
508
|
+
const targetPrefix = target.slice(0, -1);
|
|
509
|
+
if (src.startsWith(aliasPrefix)) return src.replace(aliasPrefix, targetPrefix);
|
|
510
|
+
} else if (src === alias) return target;
|
|
511
|
+
return null;
|
|
512
|
+
}
|
|
513
|
+
function getTargetPath() {
|
|
514
|
+
return pathInfo.targetPath;
|
|
515
|
+
}
|
|
516
|
+
function getComponent(src) {
|
|
517
|
+
return configInfo.componentInfo[src];
|
|
518
|
+
}
|
|
519
|
+
function getPageConfigInfo() {
|
|
520
|
+
return configInfo.pageInfo;
|
|
521
|
+
}
|
|
522
|
+
function getAppConfigInfo() {
|
|
523
|
+
return configInfo.appInfo;
|
|
524
|
+
}
|
|
525
|
+
function getWorkPath() {
|
|
526
|
+
return pathInfo.workPath;
|
|
527
|
+
}
|
|
528
|
+
function getNpmResolver() {
|
|
529
|
+
return npmResolver;
|
|
530
|
+
}
|
|
531
|
+
function getAppId() {
|
|
532
|
+
return configInfo.projectInfo.appid;
|
|
533
|
+
}
|
|
534
|
+
function getAppName() {
|
|
535
|
+
if (configInfo.projectInfo.projectname) return decodeURIComponent(configInfo.projectInfo.projectname);
|
|
536
|
+
return getAppId();
|
|
537
|
+
}
|
|
538
|
+
function transSubDir(name) {
|
|
539
|
+
return `sub_${name.replace(/\/$/, "")}`;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* 获取页面及其配置信息,并生成id(输出的 json 文件没有 id)
|
|
543
|
+
*/
|
|
544
|
+
function getPages() {
|
|
545
|
+
const { pages, subPackages = [], usingComponents: globalComponents = {} } = getAppConfigInfo();
|
|
546
|
+
const pageInfo = getPageConfigInfo();
|
|
547
|
+
const mainPages = pages.map((path) => {
|
|
548
|
+
const pageComponents = pageInfo[path]?.usingComponents || {};
|
|
549
|
+
const mergedComponents = {
|
|
550
|
+
...globalComponents,
|
|
551
|
+
...pageComponents
|
|
552
|
+
};
|
|
553
|
+
return {
|
|
554
|
+
id: uuid(),
|
|
555
|
+
path,
|
|
556
|
+
usingComponents: mergedComponents
|
|
557
|
+
};
|
|
558
|
+
});
|
|
559
|
+
const subPages = {};
|
|
560
|
+
subPackages.forEach((subPkg) => {
|
|
561
|
+
const rootPath = subPkg.root.endsWith("/") ? subPkg.root : `${subPkg.root}/`;
|
|
562
|
+
const independent = subPkg.independent ? subPkg.independent : false;
|
|
563
|
+
subPages[transSubDir(rootPath)] = {
|
|
564
|
+
independent,
|
|
565
|
+
info: subPkg.pages.map((path) => {
|
|
566
|
+
const fullPath = rootPath + path;
|
|
567
|
+
const pageComponents = pageInfo[fullPath]?.usingComponents || {};
|
|
568
|
+
const mergedComponents = {
|
|
569
|
+
...globalComponents,
|
|
570
|
+
...pageComponents
|
|
571
|
+
};
|
|
572
|
+
return {
|
|
573
|
+
id: uuid(),
|
|
574
|
+
path: fullPath,
|
|
575
|
+
usingComponents: mergedComponents
|
|
576
|
+
};
|
|
577
|
+
})
|
|
578
|
+
};
|
|
579
|
+
});
|
|
580
|
+
return {
|
|
581
|
+
mainPages,
|
|
582
|
+
subPages
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
//#endregion
|
|
586
|
+
Object.defineProperty(exports, "__toESM", {
|
|
587
|
+
enumerable: true,
|
|
588
|
+
get: function() {
|
|
589
|
+
return __toESM;
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
Object.defineProperty(exports, "art_default", {
|
|
593
|
+
enumerable: true,
|
|
594
|
+
get: function() {
|
|
595
|
+
return art_default;
|
|
596
|
+
}
|
|
597
|
+
});
|
|
598
|
+
Object.defineProperty(exports, "collectAssets", {
|
|
599
|
+
enumerable: true,
|
|
600
|
+
get: function() {
|
|
601
|
+
return collectAssets;
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
Object.defineProperty(exports, "getAbsolutePath", {
|
|
605
|
+
enumerable: true,
|
|
606
|
+
get: function() {
|
|
607
|
+
return getAbsolutePath;
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
Object.defineProperty(exports, "getAppConfigInfo", {
|
|
611
|
+
enumerable: true,
|
|
612
|
+
get: function() {
|
|
613
|
+
return getAppConfigInfo;
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
Object.defineProperty(exports, "getAppId", {
|
|
617
|
+
enumerable: true,
|
|
618
|
+
get: function() {
|
|
619
|
+
return getAppId;
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
Object.defineProperty(exports, "getAppName", {
|
|
623
|
+
enumerable: true,
|
|
624
|
+
get: function() {
|
|
625
|
+
return getAppName;
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
Object.defineProperty(exports, "getComponent", {
|
|
629
|
+
enumerable: true,
|
|
630
|
+
get: function() {
|
|
631
|
+
return getComponent;
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
Object.defineProperty(exports, "getContentByPath", {
|
|
635
|
+
enumerable: true,
|
|
636
|
+
get: function() {
|
|
637
|
+
return getContentByPath;
|
|
638
|
+
}
|
|
639
|
+
});
|
|
640
|
+
Object.defineProperty(exports, "getNpmResolver", {
|
|
641
|
+
enumerable: true,
|
|
642
|
+
get: function() {
|
|
643
|
+
return getNpmResolver;
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
Object.defineProperty(exports, "getPageConfigInfo", {
|
|
647
|
+
enumerable: true,
|
|
648
|
+
get: function() {
|
|
649
|
+
return getPageConfigInfo;
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
Object.defineProperty(exports, "getPages", {
|
|
653
|
+
enumerable: true,
|
|
654
|
+
get: function() {
|
|
655
|
+
return getPages;
|
|
656
|
+
}
|
|
657
|
+
});
|
|
658
|
+
Object.defineProperty(exports, "getTargetPath", {
|
|
659
|
+
enumerable: true,
|
|
660
|
+
get: function() {
|
|
661
|
+
return getTargetPath;
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
Object.defineProperty(exports, "getWorkPath", {
|
|
665
|
+
enumerable: true,
|
|
666
|
+
get: function() {
|
|
667
|
+
return getWorkPath;
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
Object.defineProperty(exports, "hasCompileInfo", {
|
|
671
|
+
enumerable: true,
|
|
672
|
+
get: function() {
|
|
673
|
+
return hasCompileInfo;
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
Object.defineProperty(exports, "resetStoreInfo", {
|
|
677
|
+
enumerable: true,
|
|
678
|
+
get: function() {
|
|
679
|
+
return resetStoreInfo;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
Object.defineProperty(exports, "resolveAppAlias", {
|
|
683
|
+
enumerable: true,
|
|
684
|
+
get: function() {
|
|
685
|
+
return resolveAppAlias;
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
Object.defineProperty(exports, "storeInfo", {
|
|
689
|
+
enumerable: true,
|
|
690
|
+
get: function() {
|
|
691
|
+
return storeInfo;
|
|
692
|
+
}
|
|
693
|
+
});
|
|
694
|
+
Object.defineProperty(exports, "tagWhiteList", {
|
|
695
|
+
enumerable: true,
|
|
696
|
+
get: function() {
|
|
697
|
+
return tagWhiteList;
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
Object.defineProperty(exports, "transformRpx", {
|
|
701
|
+
enumerable: true,
|
|
702
|
+
get: function() {
|
|
703
|
+
return transformRpx;
|
|
704
|
+
}
|
|
705
|
+
});
|