@lcap/nasl-unified-frontend-generator 4.1.0-beta.3 → 4.1.0-beta.5

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.d.mts CHANGED
@@ -28,6 +28,7 @@ interface CommonAppConfig {
28
28
  isExport?: boolean;
29
29
  needCompileViews?: string[];
30
30
  cacheChunksMapCode?: string;
31
+ feLoadDependenciesOnDemand?: boolean;
31
32
  /**
32
33
  * 插件用的配置项
33
34
  */
package/dist/index.d.ts CHANGED
@@ -28,6 +28,7 @@ interface CommonAppConfig {
28
28
  isExport?: boolean;
29
29
  needCompileViews?: string[];
30
30
  cacheChunksMapCode?: string;
31
+ feLoadDependenciesOnDemand?: boolean;
31
32
  /**
32
33
  * 插件用的配置项
33
34
  */
package/dist/index.js CHANGED
@@ -4157,7 +4157,7 @@ var ReactCodegenPlugin = class {
4157
4157
  const exts = packages.filter((x) => x.kind === "extension");
4158
4158
  const imports = exts.map((ext) => {
4159
4159
  return {
4160
- from: `@extension/${ext.name}`,
4160
+ from: `${ext.name}`,
4161
4161
  import: `* as ${kebab2Pascal(ext.name)}`
4162
4162
  };
4163
4163
  }).filter(isNotNil);
@@ -4786,7 +4786,7 @@ function getReferencedLibComponent(e) {
4786
4786
  if (tag === "Router") {
4787
4787
  return { kind: "library", libraryName: "react-router-dom", tag: "Outlet" };
4788
4788
  }
4789
- const libraryName = foundExtension ? `@extension/${foundExtension.name}` : DefaultComponentLibraryName;
4789
+ const libraryName = foundExtension ? `${foundExtension.name}` : DefaultComponentLibraryName;
4790
4790
  return { kind: "library", libraryName, tag };
4791
4791
  } else if (tag) {
4792
4792
  return { kind: "library", libraryName: DefaultComponentLibraryName, tag };
@@ -5476,14 +5476,14 @@ var NASLAppIRBuilderPlugin = class {
5476
5476
  }
5477
5477
  enchanceHackForAppPackageInfos(app, commonAppConfig) {
5478
5478
  app.loadPackageInfos(getPredefinedMaterialConfig());
5479
- const config = (0, import_nasl_concepts9.getConfig)();
5480
- if (commonAppConfig.allNodesAPI) {
5481
- config.allNodesAPI = commonAppConfig.allNodesAPI;
5482
- }
5483
- config.allNodesAPI ??= {};
5479
+ const naslStoreConfig = (0, import_nasl_concepts9.getConfig)();
5480
+ naslStoreConfig.allNodesAPI = commonAppConfig.allNodesAPI || {};
5484
5481
  (0, import_nasl_concepts9.initialize)({
5485
5482
  getConfig: () => {
5486
- return config;
5483
+ return {
5484
+ ...commonAppConfig || {},
5485
+ ...naslStoreConfig || {}
5486
+ };
5487
5487
  }
5488
5488
  });
5489
5489
  }
@@ -7014,13 +7014,12 @@ var BundlerConfigDataPlugin = class {
7014
7014
  if (target) {
7015
7015
  return {
7016
7016
  name: dep.name,
7017
- resolvedTo: `./src/${target}`.replace(/\/index\.js$/, ""),
7018
- scope: dep.kind === "extension" ? "@extension" : void 0
7017
+ resolvedTo: `./src/${target}`.replace(/\/index\.js$/, "")
7019
7018
  };
7020
7019
  }
7021
7020
  return void 0;
7022
7021
  }).filter(isNotNil).map((x) => {
7023
- const name = x.scope ? `${x.scope}/${x.name}` : x.name;
7022
+ const name = x.name;
7024
7023
  return {
7025
7024
  pkgName: name,
7026
7025
  ...x
@@ -7083,18 +7082,49 @@ var RspackConfigPlugin = class {
7083
7082
  );
7084
7083
  }
7085
7084
  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) {
7085
+ if (config.env === "dev" && config.needCompileViews && config.needCompileViews.length > 0 && config.cacheChunksMapCode) {
7087
7086
  rspackConfigSource = rspackConfigSource.replace("isIncremental: false", "isIncremental: true").replace("chunksMap: ''", `chunksMap: \`${config.cacheChunksMapCode}\``);
7088
7087
  }
7089
7088
  if (config.isExport) {
7090
7089
  rspackConfigSource = rspackConfigSource.replace(/\/\/ LcapPlugin start\s+new LcapPlugin\(\{[\s\S]*?\}\),\s+\/\/ LcapPlugin end/g, "");
7091
7090
  }
7091
+ rspackConfigSource = await this.processLoadOnDemand(rspackConfigSource, {
7092
+ app,
7093
+ frontend,
7094
+ config,
7095
+ fs,
7096
+ frameworkKind
7097
+ });
7092
7098
  fs.write(
7093
7099
  "/rspack.config.js",
7094
7100
  rspackConfigSource
7095
7101
  );
7096
7102
  }
7097
7103
  }
7104
+ /**
7105
+ * 处理按需加载
7106
+ * 注意:此功能仅在非dev环境下的vue3框架中可以启用。
7107
+ * @param source 源代码
7108
+ * @param options 选项
7109
+ * @returns 处理后的代码
7110
+ */
7111
+ async processLoadOnDemand(source, options) {
7112
+ let code = source;
7113
+ const { app, frontend, config, fs, frameworkKind } = options;
7114
+ const { env, feLoadDependenciesOnDemand, isExport } = config;
7115
+ const enablePerformance = feLoadDependenciesOnDemand && (isExport || env !== "dev") && ["vue3"].includes(frameworkKind);
7116
+ if (enablePerformance) {
7117
+ const feDeps = [...extractAppLevelFrontendDeps(app), ...extractFrontendLevelDeps(frontend)];
7118
+ code = code.replaceAll("// swc plugin placeholder", `experimental: {
7119
+ plugins: [
7120
+ ['@lcap/swc-plugin-import', require('./scripts/generateSwcImportPluginConfig')([
7121
+ ${feDeps.map((dep) => "'" + dep.name + "'").join(",\n")}
7122
+ ])]
7123
+ ]
7124
+ }`);
7125
+ }
7126
+ return code;
7127
+ }
7098
7128
  static install(c) {
7099
7129
  c.bind(ServiceMetaKind.FrontendBundlerFileConfig).to(RspackConfigPlugin).inSingletonScope();
7100
7130
  return c;
@@ -7503,10 +7533,8 @@ var Vue3LibrariesBuilderPlugin = class {
7503
7533
  const exportArr = [];
7504
7534
  const standardLib = ir.packages.find((x) => x.kind === "standard");
7505
7535
  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};`);
7536
+ importArr.push(`import { ConfigProvider, transformKeys } from '${standardLib.name}';`);
7537
+ exportArr.push(`window.lcapStandardUI = { ConfigProvider, transformKeys };`);
7510
7538
  const isPackageZipExists = await judgePackageZipExists(standardLib, config.STATIC_URL);
7511
7539
  importArr.push(
7512
7540
  `import '${standardLib.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
@@ -7514,18 +7542,23 @@ var Vue3LibrariesBuilderPlugin = class {
7514
7542
  }
7515
7543
  const extensions = ir.packages.filter((x) => x.kind === "extension");
7516
7544
  for (const ext of extensions) {
7517
- const formattedName = kebab2Pascal(ext.name.split("/").at(-1));
7518
7545
  const isPackageZipExists = await judgePackageZipExists(ext, config.STATIC_URL);
7519
- const prefix = isPackageZipExists ? "" : "@extension/";
7520
- exportArr.push(`export * as ${formattedName} from '${prefix}${ext.name}';`);
7521
7546
  if (ext.hasCss) {
7522
7547
  importArr.push(
7523
- `import '${prefix}${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7548
+ `import '${ext.name}${isPackageZipExists ? "/dist-theme" : ""}/index.css';`
7524
7549
  );
7525
7550
  }
7526
7551
  }
7527
7552
  return new ReactFileDescription("libraries.ts", [], [], [[...importArr, ...exportArr].join("\n")]);
7528
7553
  }
7554
+ findPackageByNameFromAllNodesAPI(name, allNodesAPI = {}) {
7555
+ for (const key in allNodesAPI) {
7556
+ if (allNodesAPI[key]?.package?.name === name) {
7557
+ return allNodesAPI[key].package;
7558
+ }
7559
+ }
7560
+ return void 0;
7561
+ }
7529
7562
  static install(c) {
7530
7563
  c.bind(Vue3LibrariesBuilderPlugin).toSelf();
7531
7564
  return c;
@@ -8049,7 +8082,11 @@ async function compileAsProject(app, frontend, config, container) {
8049
8082
  logger13.info("\u8FDC\u7A0B\u52A0\u8F7D\u6A21\u677F\u6210\u529F");
8050
8083
  const files = res.files;
8051
8084
  Object.entries(files).forEach(([k, v]) => {
8052
- fs.write(k, v.code);
8085
+ if (typeof v.code === "string") {
8086
+ fs.write(k, v.code);
8087
+ } else if (v.code?.type === "Buffer") {
8088
+ fs.write(k, Buffer.from(v.code.data));
8089
+ }
8053
8090
  });
8054
8091
  } catch (error) {
8055
8092
  throw new Error(`\u8FDC\u7A0B\u52A0\u8F7D\u6A21\u677F\u5931\u8D25`);