@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.
Files changed (73) hide show
  1. package/README.md +438 -0
  2. package/README.zh-CN.md +554 -0
  3. package/assets/container/assets/index.css +1 -0
  4. package/assets/container/assets/index.js +137 -0
  5. package/assets/container/assets/pageFrame.css +1 -0
  6. package/assets/container/assets/pageFrame.js +56 -0
  7. package/assets/container/assets/service.js +6 -0
  8. package/assets/container/assets/vconsole.js +931 -0
  9. package/assets/container/favicon.ico +0 -0
  10. package/assets/container/images/icon-arrow.png +0 -0
  11. package/assets/container/images/mini-action-white.png +0 -0
  12. package/assets/container/images/mini-action.png +0 -0
  13. package/assets/container/images/mini-arrow-left-white.png +0 -0
  14. package/assets/container/images/mini-arrow-left.jpg +0 -0
  15. package/assets/container/images/mini-arrow-left.png +0 -0
  16. package/assets/container/images/mini-close-white.png +0 -0
  17. package/assets/container/images/mini-close.png +0 -0
  18. package/assets/container/images/more.png +0 -0
  19. package/assets/container/images/search.jpg +0 -0
  20. package/assets/container/index.html +1 -0
  21. package/assets/container/pageFrame.html +1 -0
  22. package/assets/init/tabbar/home-active.png +0 -0
  23. package/assets/init/tabbar/home.png +0 -0
  24. package/assets/init/tabbar/list-active.png +0 -0
  25. package/assets/init/tabbar/list.png +0 -0
  26. package/assets/init/types/neux-api.d.ts +1402 -0
  27. package/package.json +68 -0
  28. package/scripts/generate-init-types.js +210 -0
  29. package/scripts/sync-compiler.js +22 -0
  30. package/scripts/sync-web-container.js +34 -0
  31. package/src/bin/cli.js +646 -0
  32. package/src/core/brand.js +11 -0
  33. package/src/core/compiler.js +305 -0
  34. package/src/core/defaults.js +12 -0
  35. package/src/core/dev.js +15 -0
  36. package/src/core/errors.js +17 -0
  37. package/src/core/fs.js +66 -0
  38. package/src/core/i18n.js +37 -0
  39. package/src/core/init.js +866 -0
  40. package/src/core/lifecycle.js +32 -0
  41. package/src/core/manifest.js +72 -0
  42. package/src/core/pack.js +156 -0
  43. package/src/core/package-info.js +27 -0
  44. package/src/core/preview-server.js +123 -0
  45. package/src/core/project.js +101 -0
  46. package/src/core/prompts.js +71 -0
  47. package/src/core/proxy-security.js +141 -0
  48. package/src/core/proxy.js +156 -0
  49. package/src/core/qr.js +41 -0
  50. package/src/core/terminal-qr.js +72 -0
  51. package/src/core/update.js +278 -0
  52. package/src/core/watch.js +113 -0
  53. package/src/core/web.js +649 -0
  54. package/src/core/zip.js +120 -0
  55. package/src/index.js +20 -0
  56. package/src/providers/service-client.js +149 -0
  57. package/src/providers/service-config.js +264 -0
  58. package/src/providers/service.js +146 -0
  59. package/src/providers/upload.js +112 -0
  60. package/vendor/dimina-compiler/bin/index.cjs +265 -0
  61. package/vendor/dimina-compiler/bin/index.js +263 -0
  62. package/vendor/dimina-compiler/compatibility-B-DoZtUX.cjs +395 -0
  63. package/vendor/dimina-compiler/compatibility-Cl3-DO6V.js +366 -0
  64. package/vendor/dimina-compiler/core/logic-compiler.cjs +378 -0
  65. package/vendor/dimina-compiler/core/logic-compiler.js +374 -0
  66. package/vendor/dimina-compiler/core/style-compiler.cjs +392 -0
  67. package/vendor/dimina-compiler/core/style-compiler.js +377 -0
  68. package/vendor/dimina-compiler/core/view-compiler.cjs +1601 -0
  69. package/vendor/dimina-compiler/core/view-compiler.js +1582 -0
  70. package/vendor/dimina-compiler/index.cjs +762 -0
  71. package/vendor/dimina-compiler/index.js +751 -0
  72. package/vendor/dimina-compiler/sourcemap-BgtIgqkC.cjs +1377 -0
  73. package/vendor/dimina-compiler/sourcemap-CKjhV9h7.js +1135 -0
@@ -0,0 +1,378 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_sourcemap = require("../sourcemap-BgtIgqkC.cjs");
3
+ const require_compatibility = require("../compatibility-B-DoZtUX.cjs");
4
+ let node_fs = require("node:fs");
5
+ node_fs = require_sourcemap.__toESM(node_fs, 1);
6
+ let node_path = require("node:path");
7
+ let node_worker_threads = require("node:worker_threads");
8
+ let oxc_parser = require("oxc-parser");
9
+ let oxc_walker = require("oxc-walker");
10
+ let magic_string = require("magic-string");
11
+ magic_string = require_sourcemap.__toESM(magic_string, 1);
12
+ let esbuild = require("esbuild");
13
+ //#region src/core/logic-compiler.js
14
+ var processedModules = /* @__PURE__ */ new Set();
15
+ var enableSourcemap = false;
16
+ if (!node_worker_threads.isMainThread) node_worker_threads.parentPort.on("message", async ({ pages, storeInfo, sourcemap }) => {
17
+ try {
18
+ require_sourcemap.resetStoreInfo(storeInfo);
19
+ enableSourcemap = !!sourcemap;
20
+ const progress = {
21
+ _completedTasks: 0,
22
+ get completedTasks() {
23
+ return this._completedTasks;
24
+ },
25
+ set completedTasks(value) {
26
+ this._completedTasks = value;
27
+ node_worker_threads.parentPort.postMessage({ completedTasks: this.completedTasks });
28
+ }
29
+ };
30
+ const mainCompileRes = await compileJS(pages.mainPages, null, null, progress);
31
+ for (const [root, subPages] of Object.entries(pages.subPages)) try {
32
+ await writeCompileRes(await compileJS(subPages.info, root, subPages.independent ? [] : mainCompileRes, progress), root);
33
+ } catch (error) {
34
+ throw new Error(`Error processing subpackage ${root}: ${error.message}\n${error.stack}`);
35
+ }
36
+ await writeCompileRes(mainCompileRes, null);
37
+ processedModules.clear();
38
+ node_worker_threads.parentPort.postMessage({
39
+ success: true,
40
+ compatibilityWarnings: require_compatibility.takeCompatibilityWarnings(),
41
+ dependencyGraph: require_sourcemap.getDependencyGraph().toJSON()
42
+ });
43
+ } catch (error) {
44
+ processedModules.clear();
45
+ node_worker_threads.parentPort.postMessage({
46
+ success: false,
47
+ error: {
48
+ message: error.message,
49
+ stack: error.stack,
50
+ name: error.name
51
+ }
52
+ });
53
+ }
54
+ });
55
+ async function writeCompileRes(compileRes, root) {
56
+ const outputDir = root ? `${require_sourcemap.getTargetPath()}/${root}` : `${require_sourcemap.getTargetPath()}/main`;
57
+ if (!node_fs.default.existsSync(outputDir)) node_fs.default.mkdirSync(outputDir, { recursive: true });
58
+ if (enableSourcemap) {
59
+ const { bundleCode, sourcemap } = require_sourcemap.mergeSourcemap(compileRes);
60
+ const sourcemapFileName = "logic.js.map";
61
+ node_fs.default.writeFileSync(`${outputDir}/logic.js`, `${bundleCode}//# sourceMappingURL=${sourcemapFileName}\n`);
62
+ node_fs.default.writeFileSync(`${outputDir}/${sourcemapFileName}`, sourcemap);
63
+ } else {
64
+ let mergeCode = "";
65
+ for (const module of compileRes) {
66
+ const { code: minifiedCode } = await (0, esbuild.transform)(`modDefine('${module.path}', function(require, module, exports) {
67
+ ${module.code}
68
+ });`, {
69
+ minify: true,
70
+ target: ["es2023"],
71
+ platform: "neutral"
72
+ });
73
+ mergeCode += minifiedCode;
74
+ }
75
+ node_fs.default.writeFileSync(`${outputDir}/logic.js`, mergeCode);
76
+ }
77
+ }
78
+ /**
79
+ * 编译 js 文件
80
+ */
81
+ async function compileJS(pages, root, mainCompileRes, progress) {
82
+ const compileRes = [];
83
+ if (!root) await buildJSByPath(root, { path: "app" }, compileRes, mainCompileRes, false);
84
+ for (const page of pages) {
85
+ await buildJSByPath(root, page, compileRes, mainCompileRes, true);
86
+ progress.completedTasks++;
87
+ }
88
+ return compileRes;
89
+ }
90
+ async function buildJSByPath(packageName, module, compileRes, mainCompileRes, addExtra, activePaths = /* @__PURE__ */ new Set(), putMain = false) {
91
+ const currentPath = module.path;
92
+ if (!currentPath) return;
93
+ if (activePaths.has(currentPath)) return;
94
+ if (require_sourcemap.hasCompileInfo(module.path, compileRes, mainCompileRes)) return;
95
+ const compileInfo = {
96
+ path: module.path,
97
+ code: "",
98
+ sourceFile: null
99
+ };
100
+ const src = module.path.startsWith("/") ? module.path : `/${module.path}`;
101
+ const modulePath = getJSAbsolutePath(src);
102
+ if (!modulePath) {
103
+ console.warn("[logic]", `找不到模块文件: ${src}`);
104
+ return;
105
+ }
106
+ require_sourcemap.getDependencyGraph().addFile(currentPath, modulePath, "logic");
107
+ const diagnosticSource = modulePath.startsWith(require_sourcemap.getWorkPath()) ? modulePath.slice(require_sourcemap.getWorkPath().length) : src;
108
+ const sourceCode = require_sourcemap.getContentByPath(modulePath);
109
+ if (!sourceCode) {
110
+ console.warn("[logic]", `无法读取模块文件: ${modulePath}`);
111
+ return;
112
+ }
113
+ const isTypeScript = modulePath.endsWith(".ts");
114
+ if (enableSourcemap) {
115
+ const workPath = require_sourcemap.getWorkPath();
116
+ compileInfo.sourceFile = modulePath.startsWith(workPath) ? modulePath.slice(workPath.length) : src;
117
+ }
118
+ const ast = (0, oxc_parser.parseSync)(modulePath, sourceCode, {
119
+ sourceType: "module",
120
+ lang: isTypeScript ? "ts" : "js"
121
+ }).program;
122
+ const s = new magic_string.default(sourceCode);
123
+ const extraInfo = { path: module.path };
124
+ activePaths.add(currentPath);
125
+ if (module.component) extraInfo.component = true;
126
+ if (module.usingComponents) {
127
+ const componentsObj = {};
128
+ const allSubPackages = require_sourcemap.getAppConfigInfo().subPackages;
129
+ const graphDependencies = require_sourcemap.getDependencyGraph().getDirectDependencies(module.path, "component");
130
+ const componentDependencies = graphDependencies.length > 0 ? new Set(graphDependencies) : null;
131
+ for (const [name, path] of Object.entries(module.usingComponents)) {
132
+ if (componentDependencies && !componentDependencies.has(path)) continue;
133
+ let toMainSubPackage = true;
134
+ if (packageName) {
135
+ const normalizedPath = path.startsWith("/") ? path.substring(1) : path;
136
+ for (const subPackage of allSubPackages) if (normalizedPath.startsWith(`${subPackage.root}/`)) {
137
+ toMainSubPackage = false;
138
+ break;
139
+ }
140
+ } else toMainSubPackage = false;
141
+ const componentModule = require_sourcemap.getComponent(path);
142
+ if (!componentModule) continue;
143
+ await buildJSByPath(packageName, componentModule, compileRes, mainCompileRes, true, activePaths, putMain || toMainSubPackage);
144
+ componentsObj[name] = path;
145
+ }
146
+ extraInfo.usingComponents = componentsObj;
147
+ }
148
+ if (addExtra) {
149
+ const extraInfoCode = `globalThis.__extraInfo = ${JSON.stringify(extraInfo)};\n`;
150
+ if (enableSourcemap) compileInfo.extraInfoCode = extraInfoCode;
151
+ else s.prepend(extraInfoCode);
152
+ }
153
+ if (putMain) mainCompileRes.push(compileInfo);
154
+ else compileRes.push(compileInfo);
155
+ const pathReplacements = [];
156
+ const dependenciesToProcess = [];
157
+ (0, oxc_walker.walk)(ast, { enter(node, parent) {
158
+ const wxMemberName = require_compatibility.getWxMemberName(node);
159
+ if (wxMemberName) require_compatibility.warnUnsupportedWxApi(wxMemberName, compileInfo.sourceFile || diagnosticSource, node.loc?.start?.line || getLineByIndex(sourceCode, node.start));
160
+ if ((node.type === "StringLiteral" || node.type === "Literal") && isLocalAssetString(node.value)) {
161
+ require_sourcemap.getDependencyGraph().addFile(currentPath, require_sourcemap.resolveAssetSourcePath(require_sourcemap.getWorkPath(), modulePath, node.value), "logic");
162
+ pathReplacements.push({
163
+ start: node.start,
164
+ end: node.end,
165
+ newValue: require_sourcemap.collectAssets(require_sourcemap.getWorkPath(), modulePath, node.value, require_sourcemap.getTargetPath(), require_sourcemap.getAppId())
166
+ });
167
+ }
168
+ if (node.type === "CallExpression") {
169
+ const isRequire = node.callee.type === "Identifier" && node.callee.name === "require";
170
+ const isRequireProperty = node.callee.type === "MemberExpression" && node.callee.object?.type === "Identifier" && node.callee.object?.name === "require";
171
+ if ((isRequire || isRequireProperty) && node.arguments.length > 0 && (node.arguments[0].type === "StringLiteral" || node.arguments[0].type === "Literal")) {
172
+ const arg = node.arguments[0];
173
+ const requirePath = arg.value;
174
+ if (requirePath) {
175
+ const { id, shouldProcess } = resolveDependencyId(requirePath, modulePath, false);
176
+ if (shouldProcess) {
177
+ require_sourcemap.getDependencyGraph().addDependency(currentPath, id, "logic");
178
+ pathReplacements.push({
179
+ start: arg.start,
180
+ end: arg.end,
181
+ newValue: id
182
+ });
183
+ if (!processedModules.has(packageName + id)) dependenciesToProcess.push(id);
184
+ }
185
+ }
186
+ }
187
+ }
188
+ if (node.type === "ImportDeclaration") {
189
+ const importPath = node.source.value;
190
+ if (importPath) {
191
+ const { id, shouldProcess } = resolveDependencyId(importPath, modulePath, true);
192
+ if (shouldProcess) {
193
+ require_sourcemap.getDependencyGraph().addDependency(currentPath, id, "logic");
194
+ pathReplacements.push({
195
+ start: node.source.start,
196
+ end: node.source.end,
197
+ newValue: id
198
+ });
199
+ if (!processedModules.has(packageName + id)) dependenciesToProcess.push(id);
200
+ }
201
+ }
202
+ }
203
+ if (node.type === "TSImportEqualsDeclaration" && node.moduleReference?.type === "TSExternalModuleReference") {
204
+ const importPathNode = node.moduleReference.expression;
205
+ const importPath = importPathNode?.value;
206
+ if (importPath) {
207
+ const { id, shouldProcess } = resolveDependencyId(importPath, modulePath, false);
208
+ if (shouldProcess) {
209
+ require_sourcemap.getDependencyGraph().addDependency(currentPath, id, "logic");
210
+ pathReplacements.push({
211
+ start: importPathNode.start,
212
+ end: importPathNode.end,
213
+ newValue: id
214
+ });
215
+ if (!processedModules.has(packageName + id)) dependenciesToProcess.push(id);
216
+ }
217
+ }
218
+ }
219
+ if ((node.type === "ExportAllDeclaration" || node.type === "ExportNamedDeclaration") && node.source) {
220
+ const exportPath = node.source.value;
221
+ if (exportPath) {
222
+ const { id, shouldProcess } = resolveDependencyId(exportPath, modulePath, true);
223
+ if (shouldProcess) {
224
+ require_sourcemap.getDependencyGraph().addDependency(currentPath, id, "logic");
225
+ pathReplacements.push({
226
+ start: node.source.start,
227
+ end: node.source.end,
228
+ newValue: id
229
+ });
230
+ if (!processedModules.has(packageName + id)) dependenciesToProcess.push(id);
231
+ }
232
+ }
233
+ }
234
+ } });
235
+ for (const depId of dependenciesToProcess) await buildJSByPath(packageName, { path: depId }, compileRes, mainCompileRes, false, activePaths, putMain);
236
+ for (const replacement of pathReplacements.reverse()) s.overwrite(replacement.start, replacement.end, `'${replacement.newValue}'`);
237
+ const modifiedCode = s.toString();
238
+ let preEsbuildMap = null;
239
+ if (enableSourcemap && compileInfo.sourceFile) {
240
+ const generatedMap = JSON.parse(s.generateMap({
241
+ file: compileInfo.sourceFile,
242
+ source: compileInfo.sourceFile,
243
+ includeContent: true,
244
+ hires: true
245
+ }).toString());
246
+ generatedMap.file = compileInfo.sourceFile;
247
+ generatedMap.sources = [compileInfo.sourceFile];
248
+ generatedMap.sourcesContent = [sourceCode];
249
+ preEsbuildMap = JSON.stringify(generatedMap);
250
+ }
251
+ try {
252
+ const esbuildOpts = {
253
+ format: "cjs",
254
+ target: "es2020",
255
+ platform: "neutral",
256
+ loader: isTypeScript ? "ts" : "js"
257
+ };
258
+ if (enableSourcemap && compileInfo.sourceFile) {
259
+ esbuildOpts.sourcemap = true;
260
+ esbuildOpts.sourcefile = compileInfo.sourceFile;
261
+ esbuildOpts.sourcesContent = true;
262
+ }
263
+ const esbuildResult = await (0, esbuild.transform)(modifiedCode, esbuildOpts);
264
+ if (enableSourcemap && esbuildResult.map) compileInfo.map = preEsbuildMap ? require_sourcemap.remapSourcemap(esbuildResult.map, preEsbuildMap) : esbuildResult.map;
265
+ compileInfo.code = esbuildResult.code;
266
+ } catch (error) {
267
+ console.error(`[logic] esbuild 转换失败 ${modulePath}:`, error.message);
268
+ compileInfo.code = modifiedCode;
269
+ }
270
+ processedModules.add(packageName + currentPath);
271
+ activePaths.delete(currentPath);
272
+ }
273
+ function isLocalAssetString(value) {
274
+ return typeof value === "string" && !value.startsWith("http") && !value.startsWith("//") && (value.startsWith("/") || value.startsWith("./") || value.startsWith("../")) && /\.(?:png|jpe?g|gif|svg|mp3|m4a|aac|wav)(?:\?.*)?$/.test(value);
275
+ }
276
+ function getLineByIndex(content, index) {
277
+ if (typeof index !== "number" || index < 0) return null;
278
+ let line = 1;
279
+ for (let i = 0; i < index; i++) if (content.charCodeAt(i) === 10) line++;
280
+ return line;
281
+ }
282
+ /**
283
+ * 获取 JavaScript 或 TypeScript 文件的绝对路径
284
+ * @param {string} modulePath - 模块路径
285
+ * @returns {string|null} - 文件的绝对路径,如果找不到则返回 null
286
+ */
287
+ function getJSAbsolutePath(modulePath) {
288
+ const workPath = require_sourcemap.getWorkPath();
289
+ const resolvedModuleId = resolveModuleIdToExistingPath(modulePath);
290
+ if (!resolvedModuleId) return null;
291
+ for (const ext of [".js", ".ts"]) {
292
+ const fullPath = `${workPath}${resolvedModuleId}${ext}`;
293
+ if (node_fs.default.existsSync(fullPath)) return fullPath;
294
+ }
295
+ return null;
296
+ }
297
+ function resolveDependencyId(specifier, modulePath, allowAbsolute) {
298
+ if (!specifier) return {
299
+ id: specifier,
300
+ shouldProcess: false
301
+ };
302
+ if (specifier.startsWith("miniprogram_npm/")) {
303
+ const npmModuleId = normalizeModuleId(`/${specifier}`);
304
+ return {
305
+ id: resolveModuleIdToExistingPath(npmModuleId) || npmModuleId,
306
+ shouldProcess: true
307
+ };
308
+ }
309
+ if (specifier.startsWith("./") || specifier.startsWith("../")) return {
310
+ id: resolveRelativeModuleId(specifier, modulePath),
311
+ shouldProcess: true
312
+ };
313
+ if (specifier.startsWith("/")) return {
314
+ id: allowAbsolute ? normalizeModuleId(specifier) : resolveRelativeModuleId(specifier, modulePath),
315
+ shouldProcess: true
316
+ };
317
+ const aliasResolved = require_sourcemap.resolveAppAlias(specifier);
318
+ if (aliasResolved) return {
319
+ id: normalizeModuleId(aliasResolved),
320
+ shouldProcess: true
321
+ };
322
+ if (specifier.startsWith("@") || isBareModuleSpecifier(specifier)) {
323
+ const npmModuleId = resolveNpmModuleId(specifier, modulePath);
324
+ if (npmModuleId) return {
325
+ id: npmModuleId,
326
+ shouldProcess: true
327
+ };
328
+ const siblingModuleId = resolveBareSiblingModuleId(specifier, modulePath);
329
+ return {
330
+ id: siblingModuleId || specifier,
331
+ shouldProcess: Boolean(siblingModuleId)
332
+ };
333
+ }
334
+ return {
335
+ id: specifier,
336
+ shouldProcess: false
337
+ };
338
+ }
339
+ function isBareModuleSpecifier(specifier) {
340
+ return !specifier.startsWith(".") && !specifier.startsWith("/");
341
+ }
342
+ function resolveRelativeModuleId(specifier, modulePath) {
343
+ const relativeId = (0, node_path.resolve)(modulePath, `../${specifier}`).split(`${require_sourcemap.getWorkPath()}${node_path.sep}`)[1];
344
+ return normalizeModuleId(relativeId);
345
+ }
346
+ function resolveBareSiblingModuleId(specifier, modulePath) {
347
+ return resolveModuleIdToExistingPath(resolveRelativeModuleId(`./${specifier}`, modulePath));
348
+ }
349
+ function normalizeModuleId(moduleId) {
350
+ let normalized = moduleId.replace(/\.(js|ts)$/, "").replace(/\\/g, "/");
351
+ if (!normalized.startsWith("/")) normalized = `/${normalized}`;
352
+ return normalized;
353
+ }
354
+ function resolveNpmModuleId(specifier, modulePath) {
355
+ const npmResolver = require_sourcemap.getNpmResolver();
356
+ if (!npmResolver) return null;
357
+ return npmResolver.resolveScriptModule(specifier, modulePath, resolveModuleIdToExistingPath);
358
+ }
359
+ function resolveModuleIdToExistingPath(moduleId) {
360
+ const normalizedModuleId = normalizeModuleId(moduleId);
361
+ const workPath = require_sourcemap.getWorkPath();
362
+ for (const ext of [".js", ".ts"]) if (node_fs.default.existsSync(`${workPath}${normalizedModuleId}${ext}`)) return normalizedModuleId;
363
+ for (const ext of [".js", ".ts"]) if (node_fs.default.existsSync(`${workPath}${normalizedModuleId}/index${ext}`)) return `${normalizedModuleId}/index`;
364
+ const packageJsonPath = `${workPath}${normalizedModuleId}/package.json`;
365
+ if (node_fs.default.existsSync(packageJsonPath)) try {
366
+ const packageInfo = JSON.parse(node_fs.default.readFileSync(packageJsonPath, "utf-8"));
367
+ for (const entryField of ["miniprogram", "main"]) if (typeof packageInfo[entryField] === "string" && packageInfo[entryField]) {
368
+ const resolvedEntry = resolveModuleIdToExistingPath(normalizeModuleId((0, node_path.resolve)(normalizedModuleId, packageInfo[entryField])));
369
+ if (resolvedEntry) return resolvedEntry;
370
+ }
371
+ } catch (error) {
372
+ console.warn("[logic]", `解析 package.json 失败: ${packageJsonPath}`, error.message);
373
+ }
374
+ return null;
375
+ }
376
+ //#endregion
377
+ exports.buildJSByPath = buildJSByPath;
378
+ exports.compileJS = compileJS;