@lcap/nasl-unified-frontend-generator 4.1.0-beta.2 → 4.1.0-beta.20

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/index.js CHANGED
@@ -175,11 +175,11 @@ var import_axios2 = __toESM(require("axios"));
175
175
  var import_lodash9 = require("lodash");
176
176
 
177
177
  // src/default-container.ts
178
- var import_inversify31 = require("inversify");
178
+ var import_inversify32 = require("inversify");
179
179
 
180
180
  // src/plugins/vue/vue3/vue3-preset-plugin.ts
181
181
  var import_reflection6 = require("@abraham/reflection");
182
- var import_inversify30 = require("inversify");
182
+ var import_inversify31 = require("inversify");
183
183
 
184
184
  // src/service-metakind.ts
185
185
  var ServiceMetaKind = {
@@ -2617,6 +2617,9 @@ query: {`;
2617
2617
  s2.right,
2618
2618
  callbackBag
2619
2619
  )}`;
2620
+ } else if ((0, import_asserts.isVariadicExpression)(s2)) {
2621
+ const expressions = s2.expressions.map((exp) => getRuntimeStr(exp, callbackBag));
2622
+ return expressions.join(s2.operator);
2620
2623
  } else if ((0, import_asserts.isMatchCase)(s2)) {
2621
2624
  const p = s2.parentNode;
2622
2625
  if (!(0, import_asserts.isMatch)(p)) {
@@ -3827,12 +3830,13 @@ function getReactComponentName(c) {
3827
3830
  return c.component.tag;
3828
3831
  }
3829
3832
  var ReactCodegenPlugin = class {
3830
- constructor(javaScriptCodegen, reactStateManager, frontendPerformance, projectOrganizer, entrypointManager, reactHookProviders) {
3833
+ constructor(javaScriptCodegen, reactStateManager, frontendPerformance, projectOrganizer, entrypointManager, rspackConfigPlugin, reactHookProviders) {
3831
3834
  this.javaScriptCodegen = javaScriptCodegen;
3832
3835
  this.reactStateManager = reactStateManager;
3833
3836
  this.frontendPerformance = frontendPerformance;
3834
3837
  this.projectOrganizer = projectOrganizer;
3835
3838
  this.entrypointManager = entrypointManager;
3839
+ this.rspackConfigPlugin = rspackConfigPlugin;
3836
3840
  this.reactHookProviders = reactHookProviders;
3837
3841
  }
3838
3842
  genReactFragment(c, ctx) {
@@ -4157,7 +4161,7 @@ var ReactCodegenPlugin = class {
4157
4161
  const exts = packages.filter((x) => x.kind === "extension");
4158
4162
  const imports = exts.map((ext) => {
4159
4163
  return {
4160
- from: `@extension/${ext.name}`,
4164
+ from: `${ext.name}`,
4161
4165
  import: `* as ${kebab2Pascal(ext.name)}`
4162
4166
  };
4163
4167
  }).filter(isNotNil);
@@ -4186,7 +4190,8 @@ var ReactCodegenPlugin = class {
4186
4190
  * @param baseDir - 基目录
4187
4191
  * @returns 组织后的文件列表
4188
4192
  */
4189
- async genFiles(ir, baseDir) {
4193
+ async genFiles(ir, instruction) {
4194
+ const { baseDir, app, frontend, config, fs } = instruction;
4190
4195
  const utilHooks = ReactFileDescription.empty("Hooks").merge(new ReactFileDescription("", [{ from: "./init" }], [], [])).merge(reactRouterPlugin.functions.__hooksDefinitions()).merge(apiClientPlugin.functions.__hooksDefinitions()).merge(reactComponentLibHackPlugin.functions.__hooksDefinitions()).merge(i18nPlugin.functions.__hooksDefinitions()).merge(this.buildLibraryHook(ir.packages)).merge(new ReactFileDescription("", [], [], [`export {nasl, genInitFromSchema};`]));
4191
4196
  this.reactHookProviders?.forEach((reactHookProvider) => {
4192
4197
  utilHooks.merge(reactHookProvider.genHookDefinition());
@@ -4206,6 +4211,13 @@ var ReactCodegenPlugin = class {
4206
4211
  ir.configs.globalVariables,
4207
4212
  ir.baseCtx
4208
4213
  );
4214
+ const bundlerConfigFile = await this.rspackConfigPlugin.configBundlerConfig({
4215
+ app,
4216
+ frontend,
4217
+ config,
4218
+ fs,
4219
+ frameworkKind: "react"
4220
+ });
4209
4221
  const files = await this.projectOrganizer.organize({
4210
4222
  baseDir,
4211
4223
  project: {
@@ -4218,7 +4230,8 @@ var ReactCodegenPlugin = class {
4218
4230
  platformConfig: this.buildPlatformConfig(ir),
4219
4231
  init: this.buildInit(ir),
4220
4232
  masterCss,
4221
- globalVariables
4233
+ globalVariables,
4234
+ bundlerConfigFile
4222
4235
  }
4223
4236
  });
4224
4237
  return files;
@@ -4231,8 +4244,9 @@ ReactCodegenPlugin = __decorateClass([
4231
4244
  __decorateParam(2, (0, import_inversify3.inject)(ServiceMetaKind.FrontendPerformance)),
4232
4245
  __decorateParam(3, (0, import_inversify3.inject)(ServiceMetaKind.ProjectOrganizer)),
4233
4246
  __decorateParam(4, (0, import_inversify3.inject)(ServiceMetaKind.EntryPointManager)),
4234
- __decorateParam(5, (0, import_inversify3.multiInject)(ServiceMetaKind.ReactHookProvider)),
4235
- __decorateParam(5, (0, import_inversify3.optional)())
4247
+ __decorateParam(5, (0, import_inversify3.inject)(ServiceMetaKind.FrontendBundlerFileConfig)),
4248
+ __decorateParam(6, (0, import_inversify3.multiInject)(ServiceMetaKind.ReactHookProvider)),
4249
+ __decorateParam(6, (0, import_inversify3.optional)())
4236
4250
  ], ReactCodegenPlugin);
4237
4251
  function createImportIrFromReferencedComponent(c) {
4238
4252
  switch (c.kind) {
@@ -4364,40 +4378,40 @@ var metadataPlugin = makePlugin({
4364
4378
  // src/hack/material-config/material.config.js
4365
4379
  var materials = {
4366
4380
  framework: {
4367
- version: "2.0.1",
4381
+ version: "2.1.0",
4368
4382
  core: "@lcap/basic-template",
4369
4383
  pc: [
4370
4384
  {
4371
4385
  frameworkKind: "vue2",
4372
4386
  name: "@lcap/pc-template",
4373
- version: "2.0.1"
4387
+ version: "2.1.0"
4374
4388
  },
4375
4389
  {
4376
4390
  frameworkKind: "react",
4377
4391
  name: "@lcap/pc-template-react",
4378
- version: "2.0.1"
4392
+ version: "2.1.0"
4379
4393
  },
4380
4394
  {
4381
4395
  frameworkKind: "vue3",
4382
4396
  name: "@lcap/pc-template-vue3",
4383
- version: "2.0.1"
4397
+ version: "2.1.0"
4384
4398
  }
4385
4399
  ],
4386
4400
  h5: [
4387
4401
  {
4388
4402
  frameworkKind: "vue2",
4389
4403
  name: "@lcap/mobile-template",
4390
- version: "2.0.1"
4404
+ version: "2.1.0"
4391
4405
  },
4392
4406
  {
4393
4407
  frameworkKind: "react",
4394
4408
  name: "@lcap/mobile-template-react",
4395
- version: "2.0.1"
4409
+ version: "2.1.0"
4396
4410
  },
4397
4411
  {
4398
4412
  frameworkKind: "vue3",
4399
4413
  name: "@lcap/mobile-template-vue3",
4400
- version: "2.0.1"
4414
+ version: "2.1.0"
4401
4415
  }
4402
4416
  ]
4403
4417
  },
@@ -4448,7 +4462,7 @@ var materials = {
4448
4462
  frameworkVersion: "vue@3.5.13",
4449
4463
  name: "@lcap/vant",
4450
4464
  libName: "LcapVant",
4451
- version: "1.0.0-beta.1"
4465
+ version: "1.0.0"
4452
4466
  }
4453
4467
  ]
4454
4468
  },
@@ -4786,7 +4800,7 @@ function getReferencedLibComponent(e) {
4786
4800
  if (tag === "Router") {
4787
4801
  return { kind: "library", libraryName: "react-router-dom", tag: "Outlet" };
4788
4802
  }
4789
- const libraryName = foundExtension ? `@extension/${foundExtension.name}` : DefaultComponentLibraryName;
4803
+ const libraryName = foundExtension ? `${foundExtension.name}` : DefaultComponentLibraryName;
4790
4804
  return { kind: "library", libraryName, tag };
4791
4805
  } else if (tag) {
4792
4806
  return { kind: "library", libraryName: DefaultComponentLibraryName, tag };
@@ -5476,14 +5490,14 @@ var NASLAppIRBuilderPlugin = class {
5476
5490
  }
5477
5491
  enchanceHackForAppPackageInfos(app, commonAppConfig) {
5478
5492
  app.loadPackageInfos(getPredefinedMaterialConfig());
5479
- const config = (0, import_nasl_concepts9.getConfig)();
5480
- if (commonAppConfig.allNodesAPI) {
5481
- config.allNodesAPI = commonAppConfig.allNodesAPI;
5482
- }
5483
- config.allNodesAPI ??= {};
5493
+ const naslStoreConfig = (0, import_nasl_concepts9.getConfig)();
5494
+ naslStoreConfig.allNodesAPI = commonAppConfig.allNodesAPI || {};
5484
5495
  (0, import_nasl_concepts9.initialize)({
5485
5496
  getConfig: () => {
5486
- return config;
5497
+ return {
5498
+ ...commonAppConfig || {},
5499
+ ...naslStoreConfig || {}
5500
+ };
5487
5501
  }
5488
5502
  });
5489
5503
  }
@@ -5929,6 +5943,9 @@ var ProjectOrganizerPlugin = class {
5929
5943
  const to = f.getFolder().replace(originalBizComponentsFolderMark, "/components/");
5930
5944
  f.moveFileTo(to);
5931
5945
  l2.debug(`${f.originalAbsolutePath} -> ${f.currentAbsolutePath}`);
5946
+ } else if (/(rspack|vite).config.(j|t)s$/.test(f.originalAbsolutePath)) {
5947
+ f.moveFileTo("/");
5948
+ l2.debug(`${f.originalAbsolutePath} -> ${f.currentAbsolutePath}`);
5932
5949
  }
5933
5950
  }
5934
5951
  }
@@ -6765,10 +6782,10 @@ function normalizeStaticUrl(staticURL) {
6765
6782
  return ensureUrlHasProtocol(staticURL.replace(/^\/\//, ""));
6766
6783
  }
6767
6784
  function getPublicPath(app, config, frontend) {
6785
+ let publicPath = `${getBasePath(app, config)}${frontend.basePath ?? ""}`;
6768
6786
  if (config.isExport) {
6769
- return `/`;
6787
+ publicPath = frontend.prefixPath || `/`;
6770
6788
  }
6771
- const publicPath = `${getBasePath(app, config)}${frontend.basePath ?? ""}`;
6772
6789
  if (publicPath.endsWith("/")) {
6773
6790
  return publicPath;
6774
6791
  }
@@ -6985,6 +7002,7 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config) {
6985
7002
  downloadedDeps.forEach(({ pkgName, targetPath }) => {
6986
7003
  packageJson.lcap_modules[pkgName] = `.${targetPath}`;
6987
7004
  });
7005
+ packageJson = setApplicationName(packageJson, config.app?.name || config.app?.id);
6988
7006
  fs.write("/package.json", JSON.stringify(packageJson, null, 2));
6989
7007
  logger13.info("\u4E0B\u8F7D\u524D\u7AEF\u4F9D\u8D56\u5E93\u5230 lcap_modules \u76EE\u5F55\u5B8C\u6210");
6990
7008
  } catch (error) {
@@ -6993,6 +7011,12 @@ async function downloadDependenciesToLcapModules(feDeps, fs, config) {
6993
7011
  }
6994
7012
  }
6995
7013
  }
7014
+ function setApplicationName(packageJson, appName = Date.now().toString()) {
7015
+ if (packageJson && appName) {
7016
+ packageJson.name = appName;
7017
+ }
7018
+ return packageJson;
7019
+ }
6996
7020
 
6997
7021
  // src/plugins/misc/bundler/bundler-config-data-plugin.ts
6998
7022
  var logger11 = Logger("BundlerConfigDataPlugin");
@@ -7004,7 +7028,8 @@ var BundlerConfigDataPlugin = class {
7004
7028
  const feDeps = [...extractAppLevelFrontendDeps(app), ...extractFrontendLevelDeps(frontend)];
7005
7029
  await downloadDependenciesToLcapModules(feDeps, fs, {
7006
7030
  STATIC_URL: config.STATIC_URL,
7007
- frameworkKind
7031
+ frameworkKind,
7032
+ app
7008
7033
  });
7009
7034
  const orginDependencies = await downloadDependenciesToPackages(feDeps, fs, {
7010
7035
  STATIC_URL: config.STATIC_URL
@@ -7014,13 +7039,12 @@ var BundlerConfigDataPlugin = class {
7014
7039
  if (target) {
7015
7040
  return {
7016
7041
  name: dep.name,
7017
- resolvedTo: `./src/${target}`.replace(/\/index\.js$/, ""),
7018
- scope: dep.kind === "extension" ? "@extension" : void 0
7042
+ resolvedTo: `./src/${target}`.replace(/\/index\.js$/, "")
7019
7043
  };
7020
7044
  }
7021
7045
  return void 0;
7022
7046
  }).filter(isNotNil).map((x) => {
7023
- const name = x.scope ? `${x.scope}/${x.name}` : x.name;
7047
+ const name = x.name;
7024
7048
  return {
7025
7049
  pkgName: name,
7026
7050
  ...x
@@ -7039,7 +7063,7 @@ var BundlerConfigDataPlugin = class {
7039
7063
  const backendUrl = getBackendPath(app, config, logger11);
7040
7064
  logger11.info(
7041
7065
  { publicPath, backendUrl, aliasMapStr },
7042
- frameworkKind === "vue3" ? "vite\u914D\u7F6E" : "rspack\u914D\u7F6E"
7066
+ "bundler\u914D\u7F6E"
7043
7067
  );
7044
7068
  this.frontendBundlerConfigPlugin.setCompilerConfig({
7045
7069
  backendUrl,
@@ -7066,7 +7090,8 @@ var RspackConfigPlugin = class {
7066
7090
  this.bundlerConfigDataPlugin = bundlerConfigDataPlugin;
7067
7091
  this.frontendPerformancePlugin = frontendPerformancePlugin;
7068
7092
  }
7069
- async configBundlerConfig(app, frontend, config, fs, frameworkKind) {
7093
+ async configBundlerConfig(instruction) {
7094
+ const { app, frontend, config, fs, frameworkKind } = instruction;
7070
7095
  const { backendUrl, publicPath, aliasMapStr, dependenciesStr } = await this.bundlerConfigDataPlugin.getBundlerConfigData(
7071
7096
  app,
7072
7097
  frontend,
@@ -7083,17 +7108,42 @@ var RspackConfigPlugin = class {
7083
7108
  );
7084
7109
  }
7085
7110
  rspackConfigSource = rspackConfigSource.replace(`const backendUrl = '';`, `const backendUrl = '${backendUrl}'`).replace(`const publicPath = '';`, `const publicPath = '${publicPath}';`).replace(`sourceMap: false,`, `sourceMap: ${config.env === "dev"},`).replace("alias: {}", `alias: {${aliasMapStr}}`).replace("const isDev = false", `const isDev = ${config.env === "dev"}`);
7086
- if (config.needCompileViews && config.needCompileViews.length > 0 && config.cacheChunksMapCode) {
7111
+ if (!config.isExport && config.env === "dev" && config.needCompileViews && config.needCompileViews.length > 0 && config.cacheChunksMapCode) {
7087
7112
  rspackConfigSource = rspackConfigSource.replace("isIncremental: false", "isIncremental: true").replace("chunksMap: ''", `chunksMap: \`${config.cacheChunksMapCode}\``);
7088
7113
  }
7089
- if (config.isExport) {
7090
- rspackConfigSource = rspackConfigSource.replace(/\/\/ LcapPlugin start\s+new LcapPlugin\(\{[\s\S]*?\}\),\s+\/\/ LcapPlugin end/g, "");
7091
- }
7092
- fs.write(
7093
- "/rspack.config.js",
7094
- rspackConfigSource
7095
- );
7114
+ rspackConfigSource = await this.processLoadOnDemand(rspackConfigSource, {
7115
+ app,
7116
+ frontend,
7117
+ config,
7118
+ fs,
7119
+ frameworkKind
7120
+ });
7121
+ }
7122
+ return new ReactFileDescription("rspack.config.js", [], [], [rspackConfigSource || ""]);
7123
+ }
7124
+ /**
7125
+ * 处理按需加载
7126
+ * 注意:此功能仅在非dev环境下的vue3框架中可以启用。
7127
+ * @param source 源代码
7128
+ * @param options 选项
7129
+ * @returns 处理后的代码
7130
+ */
7131
+ async processLoadOnDemand(source, options) {
7132
+ let code = source;
7133
+ const { app, frontend, config, fs, frameworkKind } = options;
7134
+ const { env, feLoadDependenciesOnDemand, isExport } = config;
7135
+ const enablePerformance = feLoadDependenciesOnDemand && (isExport || env !== "dev") && ["vue3"].includes(frameworkKind);
7136
+ if (enablePerformance) {
7137
+ const feDeps = [...extractAppLevelFrontendDeps(app), ...extractFrontendLevelDeps(frontend)];
7138
+ code = code.replaceAll("// swc plugin placeholder", `experimental: {
7139
+ plugins: [
7140
+ ['@lcap/swc-plugin-import', require('./scripts/generateSwcImportPluginConfig')([
7141
+ ${feDeps.map((dep) => "'" + dep.name + "'").join(",\n")}
7142
+ ])]
7143
+ ]
7144
+ }`);
7096
7145
  }
7146
+ return code;
7097
7147
  }
7098
7148
  static install(c) {
7099
7149
  c.bind(ServiceMetaKind.FrontendBundlerFileConfig).to(RspackConfigPlugin).inSingletonScope();
@@ -7122,7 +7172,7 @@ var ReactPresetPlugin = class {
7122
7172
  const frontend = app.findNodeByPath(instruction.frontend.nodePath);
7123
7173
  const ir = this.irBuilder.buildIR(app, frontend, instruction.config);
7124
7174
  const entryScript = this.microFrontendManager.produceScript(ir);
7125
- const files = await this.reactCodeGenerator.genFiles(ir, instruction.baseDir);
7175
+ const files = await this.reactCodeGenerator.genFiles(ir, instruction);
7126
7176
  const isDebug = instruction.config.debug;
7127
7177
  const finalizedFiles = [
7128
7178
  ...files,
@@ -7503,10 +7553,16 @@ var Vue3LibrariesBuilderPlugin = class {
7503
7553
  const exportArr = [];
7504
7554
  const standardLib = ir.packages.find((x) => x.kind === "standard");
7505
7555
  if (standardLib) {
7506
- const formattedName = kebab2Pascal(standardLib.name.split("/").at(-1));
7507
- importArr.push(`import * as ${formattedName} from '${standardLib.name}';`);
7508
- exportArr.push(`export { ${formattedName} };`);
7509
- exportArr.push(`window.lcapStandardUI = ${formattedName};`);
7556
+ importArr.push(`import { ConfigProvider, transformKeys, Message, install } from '${standardLib.name}';`);
7557
+ exportArr.push(`export const LcapStandardUI = window.lcapStandardUI = {
7558
+ ConfigProvider,
7559
+ transformKeys,
7560
+ Message,
7561
+ install: (app) => {
7562
+ install(app);
7563
+ app.config.globalProperties.$message = Message;
7564
+ },
7565
+ };`);
7510
7566
  const isPackageZipExists = await judgePackageZipExists(standardLib, config.STATIC_URL);
7511
7567
  importArr.push(
7512
7568
  `import '${standardLib.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
@@ -7514,18 +7570,31 @@ var Vue3LibrariesBuilderPlugin = class {
7514
7570
  }
7515
7571
  const extensions = ir.packages.filter((x) => x.kind === "extension");
7516
7572
  for (const ext of extensions) {
7517
- const formattedName = kebab2Pascal(ext.name.split("/").at(-1));
7518
7573
  const isPackageZipExists = await judgePackageZipExists(ext, config.STATIC_URL);
7519
- const prefix = isPackageZipExists ? "" : "@extension/";
7520
- exportArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
7521
- if (ext.hasCss) {
7574
+ const { feLoadDependenciesOnDemand } = config;
7575
+ if (!feLoadDependenciesOnDemand && ext.used) {
7576
+ const formattedName = kebab2Pascal(ext.name.split("/").at(-1));
7577
+ importArr.push(`import { install as ${formattedName}Install } from '${ext.name}';`);
7578
+ exportArr.push(`export const ${formattedName} = {
7579
+ install: ${formattedName}Install || (() => {}),
7580
+ };`);
7581
+ }
7582
+ if (ext.used && ext.hasCss) {
7522
7583
  importArr.push(
7523
- `import '${prefix}${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7584
+ `import '${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7524
7585
  );
7525
7586
  }
7526
7587
  }
7527
7588
  return new ReactFileDescription("libraries.ts", [], [], [[...importArr, ...exportArr].join("\n")]);
7528
7589
  }
7590
+ findPackageByNameFromAllNodesAPI(name, allNodesAPI = {}) {
7591
+ for (const key in allNodesAPI) {
7592
+ if (allNodesAPI[key]?.package?.name === name) {
7593
+ return allNodesAPI[key].package;
7594
+ }
7595
+ }
7596
+ return void 0;
7597
+ }
7529
7598
  static install(c) {
7530
7599
  c.bind(Vue3LibrariesBuilderPlugin).toSelf();
7531
7600
  return c;
@@ -7740,7 +7809,7 @@ ComponentPathManager = __decorateClass([
7740
7809
  (0, import_inversify29.injectable)()
7741
7810
  ], ComponentPathManager);
7742
7811
  var Vue3ApplicationAssemblerPlugin = class {
7743
- constructor(vue3CodegenPlugin, routesExtactor, routerBuilder, entryBuilder, librariesBuilder, entryCssBuilder, componentsIndexBuilder, clientLazyloadTemplateBuilder, platformBuilder, metaDataBuilder) {
7812
+ constructor(vue3CodegenPlugin, routesExtactor, routerBuilder, entryBuilder, librariesBuilder, entryCssBuilder, componentsIndexBuilder, clientLazyloadTemplateBuilder, platformBuilder, metaDataBuilder, rspackConfigPlugin) {
7744
7813
  this.vue3CodegenPlugin = vue3CodegenPlugin;
7745
7814
  this.routesExtactor = routesExtactor;
7746
7815
  this.routerBuilder = routerBuilder;
@@ -7751,8 +7820,10 @@ var Vue3ApplicationAssemblerPlugin = class {
7751
7820
  this.clientLazyloadTemplateBuilder = clientLazyloadTemplateBuilder;
7752
7821
  this.platformBuilder = platformBuilder;
7753
7822
  this.metaDataBuilder = metaDataBuilder;
7823
+ this.rspackConfigPlugin = rspackConfigPlugin;
7754
7824
  }
7755
- async assemble(ir, config) {
7825
+ async assemble(ir, instruction) {
7826
+ const { config, fs, app, frontend } = instruction;
7756
7827
  const manager = new ComponentPathManager();
7757
7828
  const views = ir.views.flatMap((x) => {
7758
7829
  return this.vue3CodegenPlugin.genFiles(x, manager);
@@ -7773,6 +7844,13 @@ var Vue3ApplicationAssemblerPlugin = class {
7773
7844
  });
7774
7845
  const routerFile = new ReactFileDescription("router.ts", router.imports, [], [router.code]);
7775
7846
  const libraries = await this.librariesBuilder.buildLibrariesImport(ir, config);
7847
+ const bundlerConfigFile = await this.rspackConfigPlugin.configBundlerConfig({
7848
+ app,
7849
+ frontend,
7850
+ config,
7851
+ fs,
7852
+ frameworkKind: "vue3"
7853
+ });
7776
7854
  return {
7777
7855
  views,
7778
7856
  bizComponents,
@@ -7783,7 +7861,8 @@ var Vue3ApplicationAssemblerPlugin = class {
7783
7861
  clientLazyloadTemplate: this.clientLazyloadTemplateBuilder.buildClientLazyloadTemplate(ir),
7784
7862
  componentsIndex: this.componentsIndexBuilder.buildComponentsIndex(ir),
7785
7863
  libraries,
7786
- entryCss: this.entryCssBuilder.buildLibrariesImport(ir)
7864
+ entryCss: this.entryCssBuilder.buildLibrariesImport(ir),
7865
+ bundlerConfig: bundlerConfigFile
7787
7866
  };
7788
7867
  }
7789
7868
  static install(container) {
@@ -7803,9 +7882,185 @@ Vue3ApplicationAssemblerPlugin = __decorateClass([
7803
7882
  __decorateParam(6, (0, import_inversify29.inject)(Vue3ComponentsIndexBuilderPlugin)),
7804
7883
  __decorateParam(7, (0, import_inversify29.inject)(Vue3ClientLazyloadTemplateBuilderPlugin)),
7805
7884
  __decorateParam(8, (0, import_inversify29.inject)(Vue3PlatformBuilderPlugin)),
7806
- __decorateParam(9, (0, import_inversify29.inject)(Vue3MetaDataBuilderPlugin))
7885
+ __decorateParam(9, (0, import_inversify29.inject)(Vue3MetaDataBuilderPlugin)),
7886
+ __decorateParam(10, (0, import_inversify29.inject)(ServiceMetaKind.FrontendBundlerFileConfig))
7807
7887
  ], Vue3ApplicationAssemblerPlugin);
7808
7888
 
7889
+ // src/plugins/misc/program-analysis/analyzer-manager-plugin.ts
7890
+ var import_inversify30 = require("inversify");
7891
+
7892
+ // src/plugins/misc/program-analysis/analysis/async-analysis.ts
7893
+ function buildAsyncAnalyzer() {
7894
+ const resultCache = /* @__PURE__ */ new WeakMap();
7895
+ function isSubtreeAsync(node, analyzeFunc = analyze) {
7896
+ let hasAsync = false;
7897
+ node.traverseStrictChildrenWithPruning((n) => {
7898
+ if (n === node) {
7899
+ return false;
7900
+ }
7901
+ if (hasAsync) {
7902
+ return true;
7903
+ } else if (n) {
7904
+ hasAsync = analyzeFunc(n);
7905
+ return hasAsync;
7906
+ }
7907
+ });
7908
+ return hasAsync;
7909
+ }
7910
+ function analyze(node) {
7911
+ if (!node) {
7912
+ return false;
7913
+ }
7914
+ if (resultCache.has(node)) {
7915
+ return resultCache.get(node);
7916
+ }
7917
+ function dispatch(node2) {
7918
+ switch (node2.concept) {
7919
+ case "CallLogic": {
7920
+ const calleeNode = node2.getCallNode();
7921
+ return analyze(calleeNode) || isSubtreeAsync(node2);
7922
+ }
7923
+ case "CallInterface": {
7924
+ return true;
7925
+ }
7926
+ case "CallFunction": {
7927
+ return isSubtreeAsync(node2);
7928
+ }
7929
+ case "Match": {
7930
+ return isSubtreeAsync(node2);
7931
+ }
7932
+ case "Function": {
7933
+ return isSubtreeAsync(node2);
7934
+ }
7935
+ case "JSBlock": {
7936
+ return true;
7937
+ }
7938
+ case "ExternalDestination":
7939
+ case "Destination": {
7940
+ return true;
7941
+ }
7942
+ case "NewStructure":
7943
+ case "NewComposite":
7944
+ case "NewMap":
7945
+ case "NewList": {
7946
+ return isSubtreeAsync(node2);
7947
+ }
7948
+ case "SubLogic": {
7949
+ return true;
7950
+ }
7951
+ case "Logic": {
7952
+ if (node2.likeComponent) {
7953
+ return node2.subLogics?.some(analyze) || isSubtreeAsync(node2);
7954
+ } else {
7955
+ return true;
7956
+ }
7957
+ }
7958
+ case "AnonymousFunction": {
7959
+ return isSubtreeAsync(node2);
7960
+ }
7961
+ case "BindEvent": {
7962
+ return node2.logics?.some(analyze) ?? false;
7963
+ }
7964
+ case "Interface":
7965
+ case "OverriddenLogic": {
7966
+ return true;
7967
+ }
7968
+ default: {
7969
+ return isSubtreeAsync(node2);
7970
+ }
7971
+ }
7972
+ }
7973
+ resultCache.set(node, true);
7974
+ const res = dispatch(node);
7975
+ resultCache.set(node, res);
7976
+ return res;
7977
+ }
7978
+ return {
7979
+ query: (node) => {
7980
+ return { async: analyze(node) };
7981
+ }
7982
+ };
7983
+ }
7984
+
7985
+ // src/plugins/misc/program-analysis/analysis/dep-analysis.ts
7986
+ var import_nasl_concepts12 = require("@lcap/nasl-concepts");
7987
+ function analyzeDeps(ir, config) {
7988
+ const { views, bizComponents, packages } = ir;
7989
+ const deps = {};
7990
+ views.forEach((view) => {
7991
+ const { libs } = (0, import_nasl_concepts12.analyzeDepRef)(view.__raw, config);
7992
+ for (const key in libs) {
7993
+ deps[key] = deps[key] || [];
7994
+ libs[key].forEach((importer) => {
7995
+ if (!deps[key].some((d) => d.key === importer.key)) {
7996
+ deps[key].push(importer);
7997
+ }
7998
+ });
7999
+ }
8000
+ });
8001
+ bizComponents.forEach((component) => {
8002
+ const { libs } = (0, import_nasl_concepts12.analyzeDepRef)(component.__raw, config);
8003
+ for (const key in libs) {
8004
+ deps[key] = deps[key] || [];
8005
+ libs[key].forEach((importer) => {
8006
+ if (!deps[key].some((d) => d.key === importer.key)) {
8007
+ deps[key].push(importer);
8008
+ }
8009
+ });
8010
+ }
8011
+ });
8012
+ packages.forEach((pkg) => {
8013
+ if (deps[pkg.name]) {
8014
+ pkg.used = true;
8015
+ }
8016
+ });
8017
+ }
8018
+
8019
+ // src/plugins/misc/program-analysis/analyzer-manager-plugin.ts
8020
+ var AnalyzerManagerPlugin = class {
8021
+ constructor() {
8022
+ this.options = {
8023
+ depAnalysis: true
8024
+ };
8025
+ }
8026
+ preProcess(app, frontend, config) {
8027
+ const analyzer = buildAsyncAnalyzer();
8028
+ if (this.getOptions().asyncAnalysis) {
8029
+ app.analyzer = analyzer;
8030
+ }
8031
+ return { app, frontend, config };
8032
+ }
8033
+ postProcess(ir, config) {
8034
+ if (this.getOptions().depAnalysis) {
8035
+ analyzeDeps(ir, config);
8036
+ }
8037
+ return ir;
8038
+ }
8039
+ /**
8040
+ * 设置完整的分析选项
8041
+ * @param options
8042
+ */
8043
+ setOptions(options) {
8044
+ this.options = options;
8045
+ }
8046
+ /**
8047
+ * 获取分析选项
8048
+ * @returns 分析选项
8049
+ */
8050
+ getOptions() {
8051
+ return this.options;
8052
+ }
8053
+ static install(c) {
8054
+ c.bind(ServiceMetaKind.IRPreProcesser).to(AnalyzerManagerPlugin);
8055
+ c.bind(ServiceMetaKind.IRPostProcesser).to(AnalyzerManagerPlugin);
8056
+ c.bind(ServiceMetaKind.AnalyzerManager).to(AnalyzerManagerPlugin);
8057
+ return c;
8058
+ }
8059
+ };
8060
+ AnalyzerManagerPlugin = __decorateClass([
8061
+ (0, import_inversify30.injectable)()
8062
+ ], AnalyzerManagerPlugin);
8063
+
7809
8064
  // src/plugins/vue/vue3/vue3-preset-plugin.ts
7810
8065
  var logger12 = Logger("Vue3PresetPlugin");
7811
8066
  var Vue3PresetPlugin = class {
@@ -7846,7 +8101,7 @@ var Vue3PresetPlugin = class {
7846
8101
  });
7847
8102
  ir.bizComponents = [];
7848
8103
  }
7849
- const assembledApplication = await this.applicationAssembler.assemble(ir, instruction.config);
8104
+ const assembledApplication = await this.applicationAssembler.assemble(ir, instruction);
7850
8105
  const finalizedFiles = await this.projectOrganizer.organize({
7851
8106
  baseDir: instruction.baseDir,
7852
8107
  project: assembledApplication,
@@ -7881,6 +8136,7 @@ var Vue3PresetPlugin = class {
7881
8136
  c = VueRouterPlugin.install(c);
7882
8137
  c.bind(ServiceMetaKind.ProjectOrganizer).to(ProjectOrganizerPlugin);
7883
8138
  c.bind(ServiceMetaKind.FileSystemProvider).to(FileSystemPlugin).inSingletonScope();
8139
+ c = AnalyzerManagerPlugin.install(c);
7884
8140
  c = BundlerConfigDataPlugin.install(c);
7885
8141
  c = RspackConfigPlugin.install(c);
7886
8142
  c = FrontendBundlerConfigPlugin.install(c);
@@ -7899,20 +8155,20 @@ var Vue3PresetPlugin = class {
7899
8155
  }
7900
8156
  };
7901
8157
  Vue3PresetPlugin = __decorateClass([
7902
- (0, import_inversify30.injectable)(),
7903
- __decorateParam(0, (0, import_inversify30.inject)(ServiceMetaKind.IRBuilder)),
7904
- __decorateParam(1, (0, import_inversify30.inject)(ServiceMetaKind.FileSystemProvider)),
7905
- __decorateParam(2, (0, import_inversify30.inject)(NpmPackageJSONManagerPlugin)),
7906
- __decorateParam(3, (0, import_inversify30.inject)(ServiceMetaKind.ProjectOrganizer)),
7907
- __decorateParam(4, (0, import_inversify30.inject)(Vue3ApplicationAssemblerPlugin))
8158
+ (0, import_inversify31.injectable)(),
8159
+ __decorateParam(0, (0, import_inversify31.inject)(ServiceMetaKind.IRBuilder)),
8160
+ __decorateParam(1, (0, import_inversify31.inject)(ServiceMetaKind.FileSystemProvider)),
8161
+ __decorateParam(2, (0, import_inversify31.inject)(NpmPackageJSONManagerPlugin)),
8162
+ __decorateParam(3, (0, import_inversify31.inject)(ServiceMetaKind.ProjectOrganizer)),
8163
+ __decorateParam(4, (0, import_inversify31.inject)(Vue3ApplicationAssemblerPlugin))
7908
8164
  ], Vue3PresetPlugin);
7909
8165
 
7910
8166
  // src/default-container.ts
7911
8167
  function makeDefaultContainer(kind = "react") {
7912
8168
  if (kind === "react") {
7913
- return ReactPresetPlugin.install(new import_inversify31.Container());
8169
+ return ReactPresetPlugin.install(new import_inversify32.Container());
7914
8170
  } else if (kind === "vue3") {
7915
- return Vue3PresetPlugin.install(new import_inversify31.Container());
8171
+ return Vue3PresetPlugin.install(new import_inversify32.Container());
7916
8172
  } else {
7917
8173
  throw new Error(`\u672A\u5B9E\u73B0${kind}\u7684\u9ED8\u8BA4\u5BB9\u5668`);
7918
8174
  }
@@ -7959,18 +8215,9 @@ async function translateNASLToApp(app, frontend, config, baseDir = "./out", cont
7959
8215
  app,
7960
8216
  frontend,
7961
8217
  config,
7962
- baseDir
8218
+ baseDir,
8219
+ fs
7963
8220
  });
7964
- const frontendBundlerFileConfig = container.get(
7965
- ServiceMetaKind.FrontendBundlerFileConfig
7966
- );
7967
- await frontendBundlerFileConfig.configBundlerConfig(
7968
- app,
7969
- frontend,
7970
- config,
7971
- fs,
7972
- frontend.frameworkKind
7973
- );
7974
8221
  if (container.isBound(ServiceMetaKind.CodeGenerationLifecycleHooks)) {
7975
8222
  const hooks = container.getAll(
7976
8223
  ServiceMetaKind.CodeGenerationLifecycleHooks
@@ -8049,7 +8296,11 @@ async function compileAsProject(app, frontend, config, container) {
8049
8296
  logger13.info("\u8FDC\u7A0B\u52A0\u8F7D\u6A21\u677F\u6210\u529F");
8050
8297
  const files = res.files;
8051
8298
  Object.entries(files).forEach(([k, v]) => {
8052
- fs.write(k, v.code);
8299
+ if (typeof v.code === "string") {
8300
+ fs.write(k, v.code);
8301
+ } else if (v.code?.type === "Buffer") {
8302
+ fs.write(k, Buffer.from(v.code.data));
8303
+ }
8053
8304
  });
8054
8305
  } catch (error) {
8055
8306
  throw new Error(`\u8FDC\u7A0B\u52A0\u8F7D\u6A21\u677F\u5931\u8D25`);
@@ -8108,137 +8359,6 @@ async function compileNASLToReactDist(app, frontend, config, http) {
8108
8359
  }
8109
8360
  }
8110
8361
 
8111
- // src/plugins/misc/program-analysis/analyzer-manager-plugin.ts
8112
- var import_inversify32 = require("inversify");
8113
-
8114
- // src/plugins/misc/program-analysis/analysis/async-analysis.ts
8115
- function buildAsyncAnalyzer() {
8116
- const resultCache = /* @__PURE__ */ new WeakMap();
8117
- function isSubtreeAsync(node, analyzeFunc = analyze) {
8118
- let hasAsync = false;
8119
- node.traverseStrictChildrenWithPruning((n) => {
8120
- if (n === node) {
8121
- return false;
8122
- }
8123
- if (hasAsync) {
8124
- return true;
8125
- } else if (n) {
8126
- hasAsync = analyzeFunc(n);
8127
- return hasAsync;
8128
- }
8129
- });
8130
- return hasAsync;
8131
- }
8132
- function analyze(node) {
8133
- if (!node) {
8134
- return false;
8135
- }
8136
- if (resultCache.has(node)) {
8137
- return resultCache.get(node);
8138
- }
8139
- function dispatch(node2) {
8140
- switch (node2.concept) {
8141
- case "CallLogic": {
8142
- const calleeNode = node2.getCallNode();
8143
- return analyze(calleeNode) || isSubtreeAsync(node2);
8144
- }
8145
- case "CallInterface": {
8146
- return true;
8147
- }
8148
- case "CallFunction": {
8149
- return isSubtreeAsync(node2);
8150
- }
8151
- case "Match": {
8152
- return isSubtreeAsync(node2);
8153
- }
8154
- case "Function": {
8155
- return isSubtreeAsync(node2);
8156
- }
8157
- case "JSBlock": {
8158
- return true;
8159
- }
8160
- case "ExternalDestination":
8161
- case "Destination": {
8162
- return true;
8163
- }
8164
- case "NewStructure":
8165
- case "NewComposite":
8166
- case "NewMap":
8167
- case "NewList": {
8168
- return isSubtreeAsync(node2);
8169
- }
8170
- case "SubLogic": {
8171
- return true;
8172
- }
8173
- case "Logic": {
8174
- if (node2.likeComponent) {
8175
- return node2.subLogics?.some(analyze) || isSubtreeAsync(node2);
8176
- } else {
8177
- return true;
8178
- }
8179
- }
8180
- case "AnonymousFunction": {
8181
- return isSubtreeAsync(node2);
8182
- }
8183
- case "BindEvent": {
8184
- return node2.logics?.some(analyze) ?? false;
8185
- }
8186
- case "Interface":
8187
- case "OverriddenLogic": {
8188
- return true;
8189
- }
8190
- default: {
8191
- return isSubtreeAsync(node2);
8192
- }
8193
- }
8194
- }
8195
- resultCache.set(node, true);
8196
- const res = dispatch(node);
8197
- resultCache.set(node, res);
8198
- return res;
8199
- }
8200
- return {
8201
- query: (node) => {
8202
- return { async: analyze(node) };
8203
- }
8204
- };
8205
- }
8206
-
8207
- // src/plugins/misc/program-analysis/analyzer-manager-plugin.ts
8208
- var AnalyzerManagerPlugin = class {
8209
- constructor() {
8210
- this.options = {};
8211
- }
8212
- preProcess(app, frontend, config) {
8213
- const analyzer = buildAsyncAnalyzer();
8214
- if (this.getOptions().asyncAnalysis) {
8215
- app.analyzer = analyzer;
8216
- }
8217
- return { app, frontend, config };
8218
- }
8219
- /**
8220
- * 设置完整的分析选项
8221
- * @param options
8222
- */
8223
- setOptions(options) {
8224
- this.options = options;
8225
- }
8226
- /**
8227
- * 获取分析选项
8228
- * @returns 分析选项
8229
- */
8230
- getOptions() {
8231
- return this.options;
8232
- }
8233
- static install(c) {
8234
- c.bind(ServiceMetaKind.IRPreProcesser).to(AnalyzerManagerPlugin);
8235
- c.bind(ServiceMetaKind.AnalyzerManager).to(AnalyzerManagerPlugin);
8236
- }
8237
- };
8238
- AnalyzerManagerPlugin = __decorateClass([
8239
- (0, import_inversify32.injectable)()
8240
- ], AnalyzerManagerPlugin);
8241
-
8242
8362
  // src/plugins/misc/name-mangler/name-mangler-manager-plugin.ts
8243
8363
  var import_inversify33 = require("inversify");
8244
8364