@lcap/nasl 4.3.0-beta.25 → 4.3.0-beta.27

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 (42) hide show
  1. package/out/generator/annotation/full.d.ts.map +1 -1
  2. package/out/generator/annotation/full.js +32 -0
  3. package/out/generator/annotation/full.js.map +1 -1
  4. package/out/generator/genBundleFiles.d.ts +2 -2
  5. package/out/generator/genBundleFiles.d.ts.map +1 -1
  6. package/out/generator/genBundleFiles.js +188 -138
  7. package/out/generator/genBundleFiles.js.map +1 -1
  8. package/out/generator/qiankun.d.ts +1 -1
  9. package/out/generator/qiankun.d.ts.map +1 -1
  10. package/out/generator/qiankun.js +1 -0
  11. package/out/generator/qiankun.js.map +1 -1
  12. package/out/generator/templates/chunk.d.ts +11 -0
  13. package/out/generator/templates/chunk.d.ts.map +1 -0
  14. package/out/generator/templates/chunk.js +29 -0
  15. package/out/generator/templates/chunk.js.map +1 -0
  16. package/out/generator/templates/runtime.d.ts +7 -0
  17. package/out/generator/templates/runtime.d.ts.map +1 -0
  18. package/out/generator/templates/runtime.js +409 -0
  19. package/out/generator/templates/runtime.js.map +1 -0
  20. package/out/manager/diagnostic.d.ts.map +1 -1
  21. package/out/manager/diagnostic.js +1 -0
  22. package/out/manager/diagnostic.js.map +1 -1
  23. package/out/server/OQL/oql-cache.js +1 -1
  24. package/out/server/OQL/oql-cache.js.map +1 -1
  25. package/out/server/OQL/utils.d.ts +0 -1
  26. package/out/server/OQL/utils.d.ts.map +1 -1
  27. package/out/server/OQL/utils.js +0 -1
  28. package/out/server/OQL/utils.js.map +1 -1
  29. package/out/server/findReference.js +1 -1
  30. package/out/server/findReference.js.map +1 -1
  31. package/out/server/naslServer.d.ts.map +1 -1
  32. package/out/server/naslServer.js +25 -22
  33. package/out/server/naslServer.js.map +1 -1
  34. package/out/templator/block2nasl/viewMergeBlock.js +3 -2
  35. package/out/templator/block2nasl/viewMergeBlock.js.map +1 -1
  36. package/out/utils/can-i-use.d.ts.map +1 -1
  37. package/out/utils/can-i-use.js +1 -0
  38. package/out/utils/can-i-use.js.map +1 -1
  39. package/package.json +11 -11
  40. package/sandbox/stdlib/nasl.core.ts +2 -0
  41. package/sandbox/stdlib/nasl.io.ts +1 -1
  42. package/sandbox/stdlib/nasl.oql.ts +2 -0
@@ -1 +1 @@
1
- {"version":3,"file":"full.d.ts","sourceRoot":"","sources":["../../../src/generator/annotation/full.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAGtD,WAAW;AACX,wBAAsB,+BAA+B,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oCAAiB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAoBjJ"}
1
+ {"version":3,"file":"full.d.ts","sourceRoot":"","sources":["../../../src/generator/annotation/full.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAE1C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,2BAA2B,EAAE,MAAM,SAAS,CAAC;AAGtD,WAAW;AACX,wBAAsB,+BAA+B,CAAC,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,oCAAiB,GAAG,OAAO,CAAC,2BAA2B,CAAC,CAkEjJ"}
@@ -11,6 +11,38 @@ async function getFullAnnotationAndModuleGraph(app, server, logger = nasl_utils_
11
11
  await server.openApp(app);
12
12
  await logger.info(utils_1.LogEventName, '结束 TS 代码翻译');
13
13
  await logger.info(utils_1.LogEventName, '开始类型标注');
14
+ // // 使用增量标注的模块图建立初始引用关系图
15
+ // // @ts-ignore
16
+ // server.symbolGraph = new SymbolGraph(app);
17
+ // // @ts-ignore
18
+ // server.refMgr = new ReferenceManager(server.symbolGraph, app);
19
+ // console.time('Collect All Global Definitions');
20
+ // // TODO wudengke 重构一下,把所有对nasl的加载放到一个函数里处理
21
+ // parseBuiltInFnTsDeclToMaps('nasl.util', naslStdlibMap['nasl.util.ts']);
22
+ // server.refMgr.buildTsQNameDefs('nasl.auth', naslStdlibMap['nasl.auth.ts']);
23
+ // server.refMgr.buildTsQNameDefs('nasl.http', naslStdlibMap['nasl.http.ts']);
24
+ // server.refMgr.buildTsQNameDefs('nasl.logging', naslStdlibMap['nasl.logging.ts']);
25
+ // server.refMgr.buildTsQNameDefs('nasl.error', naslStdlibMap['nasl.error.ts']);
26
+ // server.refMgr.buildTsQNameDefs('nasl.configuration', naslStdlibMap['nasl.configuration.ts']);
27
+ // server.refMgr.buildTsQNameDefs('nasl.ui', naslStdlibMap['nasl.ui.ts']);
28
+ // server.typingEnv = env.typeBindings;
29
+ // // @ts-ignore
30
+ // globalserver.getAllDiagnostics = () => {
31
+ // errorDiagnoser.getAllDiagnostics(server.toRaw(app));
32
+ // };
33
+ // // @ts-ignore
34
+ // globalserver.checkNode = (node) => {
35
+ // const { semErr, checkNode } = errorDiagnoser;
36
+ // semErr.clear();
37
+ // checkNode(server.toRaw(node));
38
+ // return semErr;
39
+ // };
40
+ // console.timeEnd('Collect All Global Definitions');
41
+ // // 必须先做这个
42
+ // env.setRefMgr(server.toRaw(server.refMgr));
43
+ // // 先检查 Entity、Structure、Enum
44
+ // console.log('先检查 Entity、Structure、Enum、依赖库、连接器中的定义');
45
+ // // 检查所有全局逻辑
14
46
  const annotationData = await (0, body_1.__getNaslAnnotatedJSON)(app);
15
47
  await logger.info(utils_1.LogEventName, '结束类型标注');
16
48
  await logger.info(utils_1.LogEventName, '开始构建模块依赖图');
@@ -1 +1 @@
1
- {"version":3,"file":"full.js","sourceRoot":"","sources":["../../../src/generator/annotation/full.ts"],"names":[],"mappings":";;;AACA,iDAAkD;AAElD,+CAA8D;AAE9D,mCAAsE;AAEtE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11
11
  redirect?: string;
12
- lazyPath?: string;
13
12
  meta?: {
14
13
  [key: string]: any;
15
14
  };
15
+ fullPath?: string;
16
16
  }
17
17
  export declare function genBundleFiles(app: App, frontend: Frontend, config: Config): Promise<any[]>;
18
18
  export declare function genFrontendBundleFiles(app: App, frontends: Array<Frontend>, config: Config): Promise<any[]>;
@@ -21,7 +21,7 @@ export declare function getOneFiles(options: {
21
21
  frontend: Frontend;
22
22
  view: View;
23
23
  action: 'current' | 'all';
24
- cacheRouters: Route[];
24
+ cacheRouters: string;
25
25
  config: Config;
26
26
  }): Promise<any[]>;
27
27
  //# sourceMappingURL=genBundleFiles.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"genBundleFiles.d.ts","sourceRoot":"","sources":["../../src/generator/genBundleFiles.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,GAAG,EAAU,IAAI,EAAE,QAAQ,EAAmG,MAAM,aAAa,CAAC;AAC3J,OAAO,EAAE,UAAU,EAAE,MAAM,GAAG,CAAC;AAM/B,OAAO,KAAK,EAAE,yBAAyB,IAAI,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAqBhF,eAAO,IAAI,UAAU,UAAgC,CAAA;AACrD,eAAO,IAAI,mBAAmB,UAAyD,CAAA;AAEvF,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,GAAG,WAanD;AACD,MAAM,WAAW,KAAK;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,QAAQ,CAAC,EAAE,KAAK,CAAC,KAAK,CAAC,CAAC;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE;QACL,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;KACpB,CAAA;CACF;AAgMD,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAA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ED,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,KAAK,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,MAAM,kBA2ChG;AA+BD,wBAAsB,WAAW,CAAC,OAAO,EAAE;IACzC,GAAG,EAAE,GAAG,CAAC;IACT,QAAQ,EAAE,QAAQ,CAAC;IACnB,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,SAAS,GAAG,KAAK,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,MAAM,CAAC;CAChB,kBAwKA"}
@@ -40,9 +40,11 @@ const concepts_1 = require("../concepts");
40
40
  const compileComponent_1 = require("./compileComponent");
41
41
  const nasl_unified_frontend_generator_1 = require("@lcap/nasl-unified-frontend-generator");
42
42
  const microApp_1 = require("./microApp");
43
- // @ts-ignore FIXME 类型在构建前找不到的问题
43
+ // @ts-ignore FIXME wudengke 类型在构建前找不到的问题
44
44
  const nasl_unified_frontend_generator_2 = require("@lcap/nasl-unified-frontend-generator");
45
45
  const axios_1 = __importDefault(require("axios"));
46
+ const runtime_1 = require("./templates/runtime");
47
+ const chunk_1 = require("./templates/chunk");
46
48
  const officalEntityMap = {
47
49
  LCAPUser: ['id', 'createdTime', 'updatedTime', 'userId', 'userName', 'password', 'phone', 'email', 'displayName', 'status', 'source'],
48
50
  LCAPLogicViewMapping: ['id', 'logicIdentifier', 'resourceName', 'resourceType', 'group', 'changeTime'],
@@ -139,8 +141,8 @@ function genComponentCode(component) {
139
141
  })()`;
140
142
  }
141
143
  // 生成导入组件代码
142
- function genImportComponetCode(componentPath) {
143
- return `() => importComponent('${componentPath}')`;
144
+ function genImportComponetCode(chunkId) {
145
+ return `() => __webpack_require__.e("${chunkId}").then(__webpack_require__.bind(__webpack_require__, "./${chunkId}.js"))`;
144
146
  }
145
147
  // 生成导出组件代码
146
148
  function genExportComponetCode(component) {
@@ -148,12 +150,13 @@ function genExportComponetCode(component) {
148
150
  const optionCode = renderCode
149
151
  ? `render: __render__,\n staticRenderFns: __staticRenderFns__,`
150
152
  : `template: \`${component.template.replace(/[`$]/g, (m) => `\\${m}`)}\`,`;
151
- return `var componentOptions = ${component.script ? `(function(){\n${component.script.trim().replace(/export default |module\.exports +=/, 'return ')}\n})()` : '{}'};
153
+ let code = `var componentOptions = ${component.script ? `(function(){\n${component.script.trim().replace(/export default |module\.exports +=/, 'return ')}\n})()` : '{}'};
152
154
  ${renderCode}
153
155
  Object.assign(componentOptions, {
154
156
  ${optionCode}
155
157
  });
156
- return componentOptions;`;
158
+ `;
159
+ return code;
157
160
  }
158
161
  // 获取文件路径
159
162
  // name 或者 文件 至少有一个必填
@@ -166,27 +169,44 @@ const getCompletePath = (name, fileContent, config) => {
166
169
  fileName += `${(0, nasl_utils_1.genHash)(fileContent)}.`;
167
170
  }
168
171
  fileName += `min.js`;
169
- // if(config?.isExport && !fileName.includes('bundle')&& !fileName.includes('router')){
170
- // fileName =`${config.sysPrefixPath}/${fileName}`
171
- // }
172
172
  return fileName;
173
173
  };
174
- function genRouterFileContent(routes, defaultRoute) {
174
+ function genRouterFileContent(routes, defaultRoute, config) {
175
+ // 单页面发布
176
+ if (config.isOneFile) {
177
+ let code = config?.cacheRouters;
178
+ const changedChunks = config?.asyncChunksMap;
179
+ let newRoutesCode = 'window.lcap_routes = [\n';
180
+ routes.forEach((route) => {
181
+ newRoutesCode += `${routeToString(route)},\n`;
182
+ });
183
+ newRoutesCode += '];\n';
184
+ const [start, end] = ['// lcap_routes start', '// lcap_routes end'];
185
+ // 将start和end之间的代码替换掉
186
+ code = code.slice(0, code.indexOf(start) + start.length) + '\n' + newRoutesCode + code.slice(code.indexOf(end));
187
+ const placeholderIdx = code.indexOf('// lcap_changed_chunks placeholder');
188
+ // 前面插入代码
189
+ if (placeholderIdx !== -1) {
190
+ code = code.slice(0, placeholderIdx) + `Object.assign(lcap_changed_chunks, ${JSON.stringify(changedChunks)});\n` + code.slice(placeholderIdx);
191
+ }
192
+ return code;
193
+ }
175
194
  function routeToString(route) {
176
195
  let content = `{
177
196
  path: '${route.path}',\n`;
178
- if (route?.lazyPath) {
179
- const routeLazyPath = route.lazyPath;
180
- content += `lazyPath: '${routeLazyPath}',\n`;
181
- content += `component: ${genImportComponetCode(route.lazyPath)},\n`;
197
+ if (route?.fullPath) {
198
+ // 单页面发布时需要
199
+ content += `fullPath: '${route.fullPath}',\n`;
200
+ const chunkId = (0, nasl_utils_1.genHash)(route.fullPath);
201
+ content += `component: ${genImportComponetCode(chunkId)},\n`;
182
202
  }
183
203
  if (route?.meta) {
184
204
  content += `meta: ${stringifyMetaData(route.meta)},`;
185
205
  }
186
- if (route?.children?.length) {
206
+ if (route.children?.length) {
187
207
  content += `children: [
188
- ${route.children.map(routeToString).join(',\n')}
189
- ],\n`;
208
+ ${route.children?.map?.(routeToString)?.join(',\n')}
209
+ ],\n`;
190
210
  }
191
211
  if (route?.redirect) {
192
212
  content += `redirect: '${route?.redirect}',\n`;
@@ -194,35 +214,64 @@ function genRouterFileContent(routes, defaultRoute) {
194
214
  content += '}';
195
215
  return content;
196
216
  }
217
+ // 生成异步块映射表
218
+ const name = config?.app?.name;
219
+ let code = `window["${name}LcapChunksMap"] = ${JSON5.stringify(config?.asyncChunksMap || {})};\n`;
197
220
  // 生成路由配置
198
- let routesStr = `const routers = [`;
221
+ code += `// lcap_routes start
222
+ window.lcap_routes = [\n`;
199
223
  routes.forEach((route) => {
200
- routesStr += `${routeToString(route)},\n`;
224
+ code += `${routeToString(route)},\n`;
201
225
  });
202
226
  if (defaultRoute) {
203
- routesStr += `{
227
+ code += `{
204
228
  path: '*',
205
229
  redirect: '${defaultRoute}',
206
230
  }\n`;
207
231
  }
208
- routesStr += `];
209
- return routers;`;
210
- return routesStr;
232
+ code += `];
233
+ // lcap_routes end\n`;
234
+ // changedChunk
235
+ code += `var lcap_changed_chunks = {};
236
+
237
+ // lcap_changed_chunks placeholder
238
+
239
+ Object.keys(lcap_changed_chunks).forEach(function(chunkId) {
240
+ window["${name}LcapChunksMap"][chunkId] = lcap_changed_chunks[chunkId];
241
+ });`;
242
+ return (0, chunk_1.generate)({
243
+ name: config?.app?.name,
244
+ chunkId: 'router',
245
+ moduleId: 'router',
246
+ content: code,
247
+ exports: [],
248
+ exec: false,
249
+ });
211
250
  }
212
251
  // 生成路由文件
213
252
  function genRouteFiles(routes, defaultRoute, config) {
214
253
  // 生成路由文件列表
215
254
  const routeFiles = [];
255
+ const asyncChunksMap = {};
216
256
  function routeToFile(route) {
217
257
  if (route?.component?.script) {
218
258
  const content = genExportComponetCode(route.component);
219
- const lazyPath = getCompletePath(null, content, config);
220
- route.lazyPath = lazyPath;
221
- // let outFilePath =`${config?.sysPrefixPath? config?.sysPrefixPath +'/' :''}${lazyPath}`;
259
+ const chunkId = (0, nasl_utils_1.genHash)(route.fullPath);
260
+ const contentHash = (0, nasl_utils_1.genHash)(content);
222
261
  routeFiles.push({
223
- name: lazyPath,
224
- content,
262
+ name: chunkId + '.' + contentHash + '.js',
263
+ content: (0, chunk_1.generate)({
264
+ name: config?.app?.name,
265
+ chunkId,
266
+ moduleId: chunkId,
267
+ content,
268
+ exports: [
269
+ ['componentOptions', 'default'],
270
+ ],
271
+ exec: false,
272
+ }),
225
273
  });
274
+ asyncChunksMap[chunkId] = contentHash;
226
275
  }
227
276
  if (route?.children?.length) {
228
277
  route.children.map(routeToFile);
@@ -231,13 +280,16 @@ function genRouteFiles(routes, defaultRoute, config) {
231
280
  routes.forEach((route) => {
232
281
  routeToFile(route);
233
282
  });
234
- let routerPath = getCompletePath('router', null, config);
235
283
  routeFiles.push({
236
- name: routerPath,
284
+ name: getCompletePath('router', null, config),
237
285
  isRouterFile: true,
238
- content: genRouterFileContent(routes, defaultRoute),
286
+ content: genRouterFileContent(routes, defaultRoute, Object.assign({}, config, { asyncChunksMap })),
239
287
  });
240
- return routeFiles;
288
+ const { publicPath } = config;
289
+ return routeFiles.map(file => ({
290
+ ...file,
291
+ name: publicPath + file.name,
292
+ }));
241
293
  }
242
294
  async function genBundleFiles(app, frontend, config) {
243
295
  config.sysPrefixPath = app?.sysPrefixPath;
@@ -252,6 +304,7 @@ async function genBundleFiles(app, frontend, config) {
252
304
  const fnLowcodeDomain = config?.envLcpDomain?.[config?.env]?.lcpDomain || config?.lowcodeDomain;
253
305
  const modules = [];
254
306
  const views = [];
307
+ const isExport = !!config.isExport;
255
308
  const STATIC_URL = config.isExport ? '' : config.STATIC_URL;
256
309
  app.dependencies && modules.push(...app.dependencies);
257
310
  app.interfaceDependencies && modules.push(...app.interfaceDependencies);
@@ -322,24 +375,19 @@ async function genBundleFiles(app, frontend, config) {
322
375
  (0, nasl_log_1.clearLogs)(app);
323
376
  }
324
377
  }
325
- const getBundleFileName = () => {
326
- if (config.isPreviewFe && config.previewVersion) {
327
- return `mockBundle-${config.previewVersion}`;
328
- }
329
- else {
330
- return 'bundle';
331
- }
332
- };
333
- let baseUrl = `${config.USER_STATIC_URL}/${config.tenant}/${app.id}/${config.env}`;
334
- let { basePath } = frontend;
335
- // isPreviewFe 资产中心的预览模式,优先级最高
336
- if (config.isPreviewFe) {
337
- baseUrl = `${config.USER_STATIC_URL}/asset-center/preview/${config.tenant}/${app.id}/${config.env}`;
338
- }
339
- else if (config.isExport) {
340
- baseUrl = '';
378
+ // @ts-expect-error
379
+ const publicPath = (0, nasl_unified_frontend_generator_2.getPublicPath)(app, config, frontend);
380
+ /**
381
+ * 为什么要加这个呢,因为导出静态资源的场景下,所有资源都会经过一道loadJSWrap
382
+ * 这个loadJSWrap会补上统一前缀,但是不带端路径
383
+ * 所以client.js里的资源需要是:
384
+ * /packages/pc-ui/index.js
385
+ * /m/bundle.js
386
+ */
387
+ let basePath = frontend.basePath || '/';
388
+ if (!basePath.endsWith('/')) {
389
+ basePath += '/';
341
390
  }
342
- let completePath = `${baseUrl}${basePath || ''}/`;
343
391
  /**
344
392
  * vue.config.js page options
345
393
  */
@@ -379,11 +427,18 @@ async function genBundleFiles(app, frontend, config) {
379
427
  }
380
428
  }
381
429
  }
430
+ let fullPath = `/${viewName}`;
431
+ let parent = view.parentNode;
432
+ while (parent?.concept === 'View') {
433
+ fullPath = `/${parent.name}${fullPath}`;
434
+ parent = parent.parentNode;
435
+ }
382
436
  const route = {
383
437
  path: routePath,
384
438
  component: (0, compileComponent_1.compileComponent)(componentMap[view.id]),
385
439
  children: [],
386
440
  meta: view.getRouteMeta(),
441
+ fullPath,
387
442
  };
388
443
  const viewChildren = view.children;
389
444
  if (Array.isArray(viewChildren) && viewChildren.length) {
@@ -458,15 +513,7 @@ async function genBundleFiles(app, frontend, config) {
458
513
  // authResourcePathMap={}
459
514
  }
460
515
  const authResourcePaths = Object.keys(authResourcePathMap);
461
- const routerFiles = genRouteFiles(routes, defaultRoute, config);
462
- routerFiles.forEach(item => {
463
- let temp = completePath;
464
- // if(completePath=='/'){temp=''}else{temp = `${completePath}/`}
465
- if (config?.isExport && config?.sysPrefixPath?.length > 0) {
466
- temp = config?.sysPrefixPath + temp;
467
- }
468
- item.name = temp + item.name;
469
- });
516
+ const routerFiles = genRouteFiles(routes, defaultRoute, Object.assign({}, config, { app, publicPath }));
470
517
  let fileI18nInfo = {
471
518
  enabled: false,
472
519
  locale: 'zh-CN',
@@ -581,8 +628,6 @@ async function genBundleFiles(app, frontend, config) {
581
628
  }
582
629
  const assetsInfo = app.genAllAssetsInfo(STATIC_URL, frontend.type, frontendType.frameworkKind);
583
630
  const customNames = JSON5.stringify(assetsInfo.custom.names);
584
- let content1 = `(async function(){
585
- `;
586
631
  let contentScale = '';
587
632
  if (frontend.globalScaleEnabled)
588
633
  contentScale = `{
@@ -692,67 +737,6 @@ async function genBundleFiles(app, frontend, config) {
692
737
  let contentImport = `
693
738
  var platformConfig = ${platformConfig};
694
739
  var metaData = ${metaDataStr};
695
-
696
- var getCompletePath = (path) => {
697
- return '${config?.isExport ? config.sysPrefixPath : ''}${completePath}' + path;
698
- }
699
-
700
- // 低版本
701
- function importXMLHttpRequestComponent (scriptUrl) {
702
- return new Promise(function(resolve, reject) {
703
- var xhr = new XMLHttpRequest();
704
- xhr.open('GET', scriptUrl, true);
705
- xhr.onreadystatechange = function() {
706
- if (xhr.readyState === 4) {
707
- if (xhr.status === 200) {
708
- var scriptContent = xhr.responseText;
709
- try {
710
- var func = new Function('importComponent', 'window', scriptContent + '\\n//# sourceURL=' + scriptUrl);
711
- var result = func(window.importComponent, window);
712
- resolve(result);
713
- } catch (error) {
714
- if (typeof window.$appUtils.createErrorLayout === 'function') {
715
- window.$appUtils.createErrorLayout(error);
716
- }
717
- reject(error);
718
- }
719
- } else {
720
- reject(new Error('Failed to fetch script'));
721
- }
722
- }
723
- };
724
- xhr.send();
725
- });
726
- };
727
- function importFetchComponent(scriptUrl) {
728
- return fetch(scriptUrl)
729
- .then(function(response) {
730
- if (!response.ok) {
731
- throw new Error('Network response was not ok');
732
- }
733
- return response.text();
734
- }).then(function(scriptText) {
735
- var func = new Function('importComponent', 'window', scriptText + '\\n//# sourceURL=' + scriptUrl);
736
- var result = func(window.importComponent, window);
737
- return result;
738
- })
739
- .catch(error => {
740
- console.error('Error loading script:', error);
741
- if (typeof window.$appUtils.createErrorLayout === 'function') {
742
- window.$appUtils.createErrorLayout(error);
743
- }
744
- });
745
- }
746
- window.importComponent = (scriptUrl) => {
747
- scriptUrl = getCompletePath(scriptUrl);
748
- // 浏览器支持fetch,直接使用fetch
749
- if (window.fetch) {
750
- return importFetchComponent(scriptUrl);
751
- }
752
- return importXMLHttpRequestComponent(scriptUrl);
753
- }
754
-
755
- var routes = await importComponent('${getCompletePath('router', null, config)}?t=' + Date.now());
756
740
  `;
757
741
  // 按页面维度发布先不考虑鉴权,页面维度新增的页面都算是不鉴权的数组中
758
742
  // 只有完全页面维度新增的才会进入到这个数组中
@@ -771,11 +755,11 @@ async function genBundleFiles(app, frontend, config) {
771
755
  }
772
756
  });
773
757
  }
774
- iterateRouters(routes);` : '';
758
+ iterateRouters(window.lcap_routes);` : '';
775
759
  let contentCreateLCAPApp = `
776
760
  window.createLcapApp = () => {
777
761
  ${compRegStr}
778
- appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, routes, metaData);
762
+ var appVM = window.cloudAdminDesigner.init(platformConfig.appConfig, platformConfig, window.lcap_routes, metaData);
779
763
  try {
780
764
  var push = appVM.$router.history.push;
781
765
  appVM.$router.history.push = function (a, b) {
@@ -854,8 +838,6 @@ async function genBundleFiles(app, frontend, config) {
854
838
  if(shortcutIconLink) parent.document.head.appendChild(shortcutIconLink);
855
839
  }
856
840
  ` : '';
857
- let content10 = `
858
- })();`;
859
841
  let contentDevOnly = config.env === 'dev' ? `
860
842
  var _div = document.createElement('div');
861
843
  _div.classList = "div-load"
@@ -971,10 +953,21 @@ async function genBundleFiles(app, frontend, config) {
971
953
  };
972
954
  fetchAnnoData();
973
955
  ` : '';
974
- let content = [content1, contentScale, contentStyleCss, contentDocIcon, contentCustomNames, contentImport,
975
- contentLogReportCode, contentRouter, contentCreateLCAPApp, contentPCIframe, content10,
976
- contentDevOnly, contentVueDirectives.join(''), contentViewElemAnno].join('');
977
- content1 = null;
956
+ let content = [
957
+ `__webpack_require__('./router.js');`,
958
+ contentScale,
959
+ contentStyleCss,
960
+ contentDocIcon,
961
+ contentCustomNames,
962
+ contentImport,
963
+ contentLogReportCode,
964
+ contentRouter,
965
+ contentCreateLCAPApp,
966
+ contentPCIframe,
967
+ contentDevOnly,
968
+ contentVueDirectives.join(''),
969
+ contentViewElemAnno
970
+ ].join('');
978
971
  contentScale = null;
979
972
  contentStyleCss = null;
980
973
  contentDocIcon = null;
@@ -984,19 +977,35 @@ async function genBundleFiles(app, frontend, config) {
984
977
  contentRouter = null;
985
978
  contentCreateLCAPApp = null;
986
979
  contentPCIframe = null;
987
- content10 = null;
988
980
  contentDevOnly = null;
989
981
  contentVueDirectives = null;
990
982
  contentViewElemAnno = null;
991
983
  const timestamp = Date.now();
992
984
  utils.delay(100);
993
- let bundleMinPath = completePath + getCompletePath(getBundleFileName(), content, config);
985
+ content = (0, chunk_1.generate)({
986
+ name: app.name,
987
+ chunkId: 'bundle',
988
+ moduleId: 'bundle',
989
+ content,
990
+ exports: [],
991
+ exec: true,
992
+ });
993
+ const routerFileName = getCompletePath('router', null, config);
994
+ const bundleFileName = getCompletePath(getBundleFileName(config), content, config);
995
+ let clientPath = publicPath + 'client.js';
996
+ let runtimePath = publicPath + 'runtime.js';
997
+ let routerPath = publicPath + routerFileName;
998
+ let bundleMinPath = publicPath + bundleFileName;
994
999
  const otherJsList = frontend?.appletsConfig?.enable ? ['//res.wx.qq.com/open/js/jweixin-1.3.2.js'] : [];
995
1000
  const microAppIntegration = (0, microApp_1.integrateMicroApp)(frontend);
996
1001
  if (config?.debug) {
997
1002
  otherJsList.push(`${STATIC_URL}/packages/@lcap/breakpoint-client@1.0.0/dist/index.js?time=${timestamp}`);
998
1003
  }
999
- let jsAssetsList = assetsInfo.basic.js.concat(assetsInfo.custom.js, otherJsList).concat([bundleMinPath]);
1004
+ let jsAssetsList = assetsInfo.basic.js.concat(assetsInfo.custom.js, otherJsList).concat([
1005
+ isExport ? (basePath + 'runtime.js') : runtimePath,
1006
+ isExport ? (basePath + routerFileName) : routerPath,
1007
+ isExport ? (basePath + bundleFileName) : bundleMinPath,
1008
+ ]);
1000
1009
  let cssAssetsList = assetsInfo.basic.css.concat(assetsInfo.custom.css);
1001
1010
  if (config.isPreviewFe) {
1002
1011
  const changeToRelativePath = (str) => {
@@ -1192,18 +1201,26 @@ async function genBundleFiles(app, frontend, config) {
1192
1201
  `;
1193
1202
  const outputs = [
1194
1203
  {
1195
- name: bundleMinPath,
1196
- content,
1204
+ name: clientPath,
1205
+ content: assetsContent,
1197
1206
  },
1198
1207
  {
1199
- name: basePath ? `${baseUrl}${basePath}/client.js` : `${baseUrl}/client.js`,
1200
- content: assetsContent,
1208
+ name: runtimePath,
1209
+ content: (0, runtime_1.generate)({
1210
+ name: app.name,
1211
+ publicPath: JSON.stringify(publicPath),
1212
+ }),
1213
+ },
1214
+ {
1215
+ name: bundleMinPath,
1216
+ content,
1201
1217
  },
1202
1218
  ...routerFiles,
1203
1219
  ];
1204
1220
  assetsContent = null;
1205
1221
  content = null;
1206
1222
  processAssetsInOutputs(outputs, frontend, config);
1223
+ console.info('编译结果', outputs.map((x) => x.name));
1207
1224
  return outputs;
1208
1225
  }
1209
1226
  exports.genBundleFiles = genBundleFiles;
@@ -1336,16 +1353,23 @@ async function getOneFiles(options) {
1336
1353
  if (isRootView) {
1337
1354
  routePath = `${frontend.prefixPath}/${viewName}`;
1338
1355
  }
1356
+ let fullPath = `/${viewName}`;
1357
+ let parent = view.parentNode;
1358
+ while (parent?.concept === 'View') {
1359
+ fullPath = `/${parent.name}${fullPath}`;
1360
+ parent = parent.parentNode;
1361
+ }
1339
1362
  const route = {
1340
1363
  path: routePath,
1341
1364
  component: (0, compileComponent_1.compileComponent)(viewOption),
1342
1365
  children: [],
1343
1366
  meta: view.getRouteMeta(),
1367
+ fullPath,
1344
1368
  };
1345
1369
  return route;
1346
1370
  }
1347
- let currentView = view;
1348
1371
  let currentRoute = null;
1372
+ let currentView = view;
1349
1373
  while (currentView?.concept === 'View') {
1350
1374
  if (currentRoute) {
1351
1375
  const child = currentRoute;
@@ -1379,6 +1403,7 @@ async function getOneFiles(options) {
1379
1403
  // 如果找到了现有路由,更新 component 和 meta
1380
1404
  existingRoute.component = newRoute.component;
1381
1405
  existingRoute.meta = newRoute.meta;
1406
+ existingRoute.fullPath = newRoute.fullPath;
1382
1407
  // 递归合并子路由
1383
1408
  if (newRoute.children) {
1384
1409
  existingRoute.children = existingRoute.children || [];
@@ -1395,9 +1420,25 @@ async function getOneFiles(options) {
1395
1420
  routes.unshift(newRoute);
1396
1421
  }
1397
1422
  }
1423
+ let existingRoutes = [];
1424
+ try {
1425
+ // 获取// lcap_routes start 到 // lcap_routes end 之间的代码
1426
+ const [start, end] = ['// lcap_routes start', '// lcap_routes end'];
1427
+ const routesCode = cacheRouters
1428
+ .substring(cacheRouters.indexOf(start) + start.length, cacheRouters.indexOf(end))
1429
+ .replace('window.lcap_routes = ', 'return ');
1430
+ const fn = new Function(`${routesCode}`);
1431
+ existingRoutes = fn();
1432
+ }
1433
+ catch (error) {
1434
+ console.error('路由代码 eval 失败:', error);
1435
+ }
1398
1436
  // Bug-3156542745982976: 原本直接找到顶层直接删除,在新增节点,遗漏处理中间层也有节点的情况,单页发布就直接增量合并,为了性能,暂时不考虑删除节点
1399
- addOrUpdateRoute(cacheRouters, currentRoute);
1400
- const routerFiles = genRouteFiles(cacheRouters, null);
1437
+ addOrUpdateRoute(existingRoutes, currentRoute);
1438
+ // @ts-expect-error
1439
+ const publicPath = (0, nasl_unified_frontend_generator_2.getPublicPath)(app, config, frontend);
1440
+ const routerFiles = genRouteFiles(existingRoutes, null, Object.assign({}, config, { app, cacheRouters, isOneFile: true, publicPath }));
1441
+ console.info('编译结果', routerFiles.map((x) => x.name));
1401
1442
  return routerFiles;
1402
1443
  }
1403
1444
  exports.getOneFiles = getOneFiles;
@@ -1491,4 +1532,13 @@ function processAssetsInOutputs(outputs, frontend, config) {
1491
1532
  });
1492
1533
  }
1493
1534
  }
1535
+ function getBundleFileName(config) {
1536
+ if (config.isPreviewFe && config.previewVersion) {
1537
+ return `mockBundle-${config.previewVersion}`;
1538
+ }
1539
+ else {
1540
+ return 'bundle';
1541
+ }
1542
+ }
1543
+ ;
1494
1544
  //# sourceMappingURL=genBundleFiles.js.map