@4399ywkf/core 5.3.1 → 5.4.1

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
@@ -152,9 +152,7 @@ var browserCheckPlugin = createPlugin((options = {}) => ({
152
152
  }
153
153
  }
154
154
  const minVersions = explicitVersions ? { ...baseVersions, ...explicitVersions } : baseVersions;
155
- logger.info(
156
- `\u6D4F\u89C8\u5668\u517C\u5BB9\u6027\u68C0\u67E5\u5DF2\u542F\u7528 (\u7279\u6027\u68C0\u6D4B: ${features.join(", ")})`
157
- );
155
+ logger.info(`\u6D4F\u89C8\u5668\u517C\u5BB9\u6027\u68C0\u67E5\u5DF2\u542F\u7528 (\u7279\u6027\u68C0\u6D4B: ${features.join(", ")})`);
158
156
  logger.info(
159
157
  `\u6700\u4F4E\u7248\u672C\u8981\u6C42: Chrome ${minVersions.chrome ?? "\u2014"}, Edge ${minVersions.edge ?? "\u2014"}, Firefox ${minVersions.firefox ?? "\u2014"}, Safari ${minVersions.safari ?? "\u2014"}${fromBrowserslist !== false ? " (\u4ECE browserslist \u8BFB\u53D6)" : ""}`
160
158
  );
@@ -194,7 +192,7 @@ var browserCheckPlugin = createPlugin((options = {}) => ({
194
192
  const insertIndex = lastImportIndex >= 0 ? lastImportIndex + 1 : 0;
195
193
  lines.splice(insertIndex, 0, checkBlock);
196
194
  let result = lines.join("\n");
197
- result = result.replace(
195
+ result = result.replaceAll(
198
196
  /(\s*)(await\s+)?runApp\(\);?/g,
199
197
  (_, indent, awaitKw) => `${indent}if (__ywkfBrowserOk) { ${awaitKw || ""}runApp(); }`
200
198
  );
@@ -218,37 +216,39 @@ function buildFeatureChecks(features) {
218
216
  return lines;
219
217
  }
220
218
  function buildVersionChecks(minVersions) {
221
- const entries = Object.entries(minVersions).filter(
222
- ([, v]) => v != null
223
- );
219
+ const entries = Object.entries(minVersions).filter(([, v]) => v != null);
224
220
  if (entries.length === 0) return [];
225
221
  const lines = ["// UA \u7248\u672C\u68C0\u6D4B", "const ua = navigator.userAgent;"];
226
222
  for (const [browser, minVer] of entries) {
227
223
  switch (browser) {
228
- case "chrome":
224
+ case "chrome": {
229
225
  lines.push(
230
226
  `const chromeMatch = /Chrome\\/(\\d+)/.exec(ua);`,
231
227
  `if (chromeMatch && !/Edg\\//.test(ua) && Number(chromeMatch[1]) < ${minVer}) return false;`
232
228
  );
233
229
  break;
234
- case "edge":
230
+ }
231
+ case "edge": {
235
232
  lines.push(
236
233
  `const edgeMatch = /Edg\\/(\\d+)/.exec(ua);`,
237
234
  `if (edgeMatch && Number(edgeMatch[1]) < ${minVer}) return false;`
238
235
  );
239
236
  break;
240
- case "firefox":
237
+ }
238
+ case "firefox": {
241
239
  lines.push(
242
240
  `const firefoxMatch = /Firefox\\/(\\d+)/.exec(ua);`,
243
241
  `if (firefoxMatch && Number(firefoxMatch[1]) < ${minVer}) return false;`
244
242
  );
245
243
  break;
246
- case "safari":
244
+ }
245
+ case "safari": {
247
246
  lines.push(
248
247
  `const safariMatch = /Version\\/(\\d+\\.?\\d*)/.exec(ua);`,
249
248
  `if (safariMatch && /Safari/.test(ua) && !/Chrome/.test(ua) && Number(safariMatch[1]) < ${minVer}) return false;`
250
249
  );
251
250
  break;
251
+ }
252
252
  }
253
253
  }
254
254
  return lines;
@@ -341,9 +341,9 @@ function readBrowserslistFile(filePath) {
341
341
  function extractMinVersions(queries) {
342
342
  const result = {};
343
343
  const expanded = queries.flatMap((q) => q.split(",").map((s) => s.trim()));
344
- const versionPattern = /^(\w+)\s*(?:(>=?)\s*)?(\d+(?:\.\d+)?)\s*$/i;
344
+ const versionPattern = /^([a-z_]+)\s*(?:(>=?)\s*)?(\d+(?:\.\d+)?)\s*$/i;
345
345
  for (const query of expanded) {
346
- if (/^(not|dead|last|defaults|>?\s*\d+%|unreleased|current)/i.test(query)) {
346
+ if (/^(?:not|dead|last|defaults|>?\s*\d+%|unreleased|current)/i.test(query)) {
347
347
  continue;
348
348
  }
349
349
  const match = versionPattern.exec(query);
@@ -384,7 +384,7 @@ var garfishPlugin = createPlugin((options = {}) => ({
384
384
  rspackConfig.devServer = {
385
385
  ...rspackConfig.devServer,
386
386
  headers: {
387
- ...rspackConfig.devServer?.headers || {},
387
+ ...rspackConfig.devServer?.headers,
388
388
  "Access-Control-Allow-Origin": "*",
389
389
  "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
390
390
  "Access-Control-Allow-Headers": "*"
@@ -628,7 +628,7 @@ function scaffoldSourceFiles(cwd, sourceDir, namespaces, logger) {
628
628
  }
629
629
  const indexPath = join3(dir, "index.ts");
630
630
  if (!existsSync3(indexPath)) {
631
- const imports = namespaces.map((ns) => `import ${ns} from "./${ns}";`).join("\n");
631
+ const imports = namespaces.map((ns) => `import ${ns} from './${ns}';`).join("\n");
632
632
  const entries = namespaces.join(",\n ");
633
633
  const content = `${imports}
634
634
 
@@ -645,19 +645,19 @@ export default resources;
645
645
  function buildDefaultNsFile(ns) {
646
646
  if (ns === "common") {
647
647
  return `export default {
648
- welcome: "\u6B22\u8FCE\u4F7F\u7528",
649
- loading: "\u52A0\u8F7D\u4E2D...",
650
- confirm: "\u786E\u5B9A",
651
- cancel: "\u53D6\u6D88",
652
- save: "\u4FDD\u5B58",
653
- delete: "\u5220\u9664",
654
- edit: "\u7F16\u8F91",
655
- back: "\u8FD4\u56DE",
648
+ welcome: '\u6B22\u8FCE\u4F7F\u7528',
649
+ loading: '\u52A0\u8F7D\u4E2D...',
650
+ confirm: '\u786E\u5B9A',
651
+ cancel: '\u53D6\u6D88',
652
+ save: '\u4FDD\u5B58',
653
+ delete: '\u5220\u9664',
654
+ edit: '\u7F16\u8F91',
655
+ back: '\u8FD4\u56DE',
656
656
  } as const;
657
657
  `;
658
658
  }
659
659
  return `export default {
660
- title: "${ns}",
660
+ title: '${ns}',
661
661
  } as const;
662
662
  `;
663
663
  }
@@ -665,11 +665,11 @@ function scaffoldResourcesFile(cwd, sourceDir, _namespaces, locales, defaultLoca
665
665
  const parentDir = join3(cwd, sourceDir, "..");
666
666
  const filePath = join3(parentDir, "resources.ts");
667
667
  if (existsSync3(filePath)) return;
668
- const content = `import resources from "./default";
668
+ const content = `import type resources from './default';
669
669
 
670
- export const DEFAULT_LOCALE = "${defaultLocale}";
670
+ export const DEFAULT_LOCALE = '${defaultLocale}';
671
671
 
672
- export const SUPPORTED_LOCALES = ${JSON.stringify(locales)} as const;
672
+ export const SUPPORTED_LOCALES = [${locales.map((l) => `'${l}'`).join(", ")}] as const;
673
673
 
674
674
  export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
675
675
 
@@ -681,7 +681,7 @@ export const normalizeLocale = (locale?: string): SupportedLocale => {
681
681
  if (!locale) return DEFAULT_LOCALE as SupportedLocale;
682
682
 
683
683
  for (const l of SUPPORTED_LOCALES) {
684
- if (l.startsWith(locale) || locale.startsWith(l.split("-")[0])) {
684
+ if (l.startsWith(locale) || locale.startsWith(l.split('-')[0])) {
685
685
  return l;
686
686
  }
687
687
  }
@@ -689,11 +689,9 @@ export const normalizeLocale = (locale?: string): SupportedLocale => {
689
689
  return DEFAULT_LOCALE as SupportedLocale;
690
690
  };
691
691
 
692
- export const localeOptions = ${JSON.stringify(
693
- locales.map((l) => ({ value: l, label: getLocaleLabel(l) })),
694
- null,
695
- 2
696
- )} as const;
692
+ export const localeOptions = [
693
+ ${locales.map((l) => ` { value: '${l}', label: '${getLocaleLabel(l)}' },`).join("\n")}
694
+ ] as const;
697
695
  `;
698
696
  writeFileSync2(filePath, content, "utf-8");
699
697
  logger.info(`\u5DF2\u751F\u6210\u7C7B\u578B\u6587\u4EF6: ${sourceDir}/../resources.ts`);
@@ -712,35 +710,35 @@ function getLocaleLabel(locale) {
712
710
  "ru-RU": "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
713
711
  "it-IT": "Italiano",
714
712
  "vi-VN": "Ti\u1EBFng Vi\u1EC7t",
715
- ar: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"
713
+ "ar": "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"
716
714
  };
717
715
  return map[locale] || locale;
718
716
  }
719
717
  function scaffoldConvertScript(cwd, sourceDir, localesDir, defaultLocale, logger) {
720
718
  const scriptsDir = join3(cwd, "scripts");
721
- const scriptPath = join3(scriptsDir, "i18n-gen.js");
722
- if (existsSync3(scriptPath)) return;
719
+ const scriptPath = join3(scriptsDir, "i18n-gen.cjs");
720
+ if (existsSync3(scriptPath) || existsSync3(join3(scriptsDir, "i18n-gen.js"))) return;
723
721
  if (!existsSync3(scriptsDir)) {
724
722
  mkdirSync(scriptsDir, { recursive: true });
725
723
  }
726
- const content = `const fs = require("fs");
727
- const path = require("path");
724
+ const content = `const fs = require('node:fs');
725
+ const path = require('node:path');
728
726
 
729
- const sourceDir = path.join(__dirname, "../${sourceDir}");
730
- const targetDir = path.join(__dirname, "../${localesDir}/${defaultLocale}");
727
+ const sourceDir = path.join(__dirname, '../${sourceDir}');
728
+ const targetDir = path.join(__dirname, '../${localesDir}/${defaultLocale}');
731
729
 
732
730
  const files = fs
733
731
  .readdirSync(sourceDir)
734
- .filter((file) => file.endsWith(".ts") && file !== "index.ts")
735
- .map((file) => path.basename(file, ".ts"));
732
+ .filter((file) => file.endsWith('.ts') && file !== 'index.ts')
733
+ .map((file) => path.basename(file, '.ts'));
736
734
 
737
- require("ts-node/register");
735
+ require('ts-node/register');
738
736
 
739
737
  if (!fs.existsSync(targetDir)) {
740
738
  fs.mkdirSync(targetDir, { recursive: true });
741
739
  }
742
740
 
743
- console.log("\u5F00\u59CB\u8F6C\u6362 TypeScript \u6587\u4EF6\u5230 JSON...\\n");
741
+ console.log('\u5F00\u59CB\u8F6C\u6362 TypeScript \u6587\u4EF6\u5230 JSON...\\n');
744
742
 
745
743
  files.forEach((fileName) => {
746
744
  try {
@@ -749,28 +747,28 @@ files.forEach((fileName) => {
749
747
  const moduleContent = require(modulePath).default;
750
748
  const jsonContent = JSON.stringify(moduleContent, null, 2);
751
749
  const targetPath = path.join(targetDir, \`\${fileName}.json\`);
752
- fs.writeFileSync(targetPath, jsonContent, "utf8");
750
+ fs.writeFileSync(targetPath, jsonContent, 'utf8');
753
751
  console.log(\` \${fileName}.ts \u2192 \${fileName}.json\`);
754
752
  } catch (error) {
755
753
  console.error(\` \u8F6C\u6362 \${fileName}.ts \u5931\u8D25:\`, error.message);
756
754
  }
757
755
  });
758
756
 
759
- console.log("\\n\u8F6C\u6362\u5B8C\u6210\uFF01");
757
+ console.log('\\n\u8F6C\u6362\u5B8C\u6210\uFF01');
760
758
  `;
761
759
  writeFileSync2(scriptPath, content, "utf-8");
762
- logger.info("\u5DF2\u751F\u6210\u8F6C\u6362\u811A\u672C: scripts/i18n-gen.js");
760
+ logger.info("\u5DF2\u751F\u6210\u8F6C\u6362\u811A\u672C: scripts/i18n-gen.cjs");
763
761
  }
764
762
  function scaffoldI18nRc(cwd, localesDir, defaultLocale, locales, logger) {
765
763
  const filePath = join3(cwd, ".i18nrc.js");
766
764
  if (existsSync3(filePath)) return;
767
- const outputLocales = locales.filter((l) => l !== defaultLocale).map((l) => `"${l}"`).join(", ");
768
- const content = `const { defineConfig } = require("@4399ywkf/i18n");
765
+ const outputLocales = locales.filter((l) => l !== defaultLocale).map((l) => `'${l}'`).join(", ");
766
+ const content = `const { defineConfig } = require('@4399ywkf/i18n');
769
767
 
770
768
  module.exports = defineConfig({
771
- entry: "${localesDir}/${defaultLocale}",
772
- entryLocale: "${defaultLocale}",
773
- output: "${localesDir}",
769
+ entry: '${localesDir}/${defaultLocale}',
770
+ entryLocale: '${defaultLocale}',
771
+ output: '${localesDir}',
774
772
  outputLocales: [${outputLocales}],
775
773
  });
776
774
  `;
@@ -789,15 +787,16 @@ function scaffoldLocaleJsonDirs(cwd, localesDir, locales, defaultLocale, namespa
789
787
  const filePath = join3(localeDir, `${ns}.json`);
790
788
  if (!existsSync3(filePath)) {
791
789
  const placeholder = ns === "common" ? JSON.stringify(
790
+ // 键按字母序排列,与 @4399ywkf/lint 的 Prettier(prettier-plugin-sort-json)一致
792
791
  {
793
- welcome: "Welcome",
794
- loading: "Loading...",
795
- confirm: "OK",
792
+ back: "Back",
796
793
  cancel: "Cancel",
797
- save: "Save",
794
+ confirm: "OK",
798
795
  delete: "Delete",
799
796
  edit: "Edit",
800
- back: "Back"
797
+ loading: "Loading...",
798
+ save: "Save",
799
+ welcome: "Welcome"
801
800
  },
802
801
  null,
803
802
  2
@@ -863,7 +862,7 @@ function scanMockFiles(dir) {
863
862
  for (const entry of entries) {
864
863
  const fullPath = join4(dir, entry);
865
864
  const stat = statSync(fullPath);
866
- if (stat.isFile() && /\.(ts|js|mjs)$/.test(entry)) {
865
+ if (stat.isFile() && /\.(?:ts|js|mjs)$/.test(entry)) {
867
866
  files.push(fullPath);
868
867
  } else if (stat.isDirectory()) {
869
868
  files.push(...scanMockFiles(fullPath));
@@ -1340,12 +1339,13 @@ function generateThemeProvider(opts) {
1340
1339
  scopePopupContainer
1341
1340
  } = opts;
1342
1341
  const isAutoLocale = locale === "auto";
1343
- const sections = [];
1344
- sections.push(`// \u6B64\u6587\u4EF6\u7531 @4399ywkf/plugin-theme v3 \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u4FEE\u6539`);
1345
- sections.push(buildImports({ globalReset, cssVar, scopePopupContainer, locale }));
1346
- sections.push(TYPES_CODE);
1347
- sections.push(buildStoreCode({ defaultAppearance, primaryColor, neutralColor, locale }));
1348
- sections.push(HOOKS_CODE);
1342
+ const sections = [
1343
+ `// \u6B64\u6587\u4EF6\u7531 @4399ywkf/plugin-theme v3 \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u4FEE\u6539`,
1344
+ buildImports({ globalReset, cssVar, scopePopupContainer, locale }),
1345
+ TYPES_CODE,
1346
+ buildStoreCode({ defaultAppearance, primaryColor, neutralColor, locale }),
1347
+ HOOKS_CODE
1348
+ ];
1349
1349
  if (globalReset) sections.push(GLOBAL_RESET_CODE);
1350
1350
  if (cssVar) sections.push(buildCssVarSyncCode());
1351
1351
  if (darkMode) sections.push(APPEARANCE_SYNC_CODE);
@@ -2040,18 +2040,58 @@ export type { StateCreator, StoreApi } from "zustand";
2040
2040
 
2041
2041
  // src/config/normalize.ts
2042
2042
  var BUILTIN_PLUGINS = [
2043
- { key: "reactQuery", factory: reactQueryPlugin, pluginName: "@4399ywkf/plugin-react-query" },
2044
- { key: "zustand", factory: zustandPlugin, pluginName: "@4399ywkf/plugin-zustand" },
2045
- { key: "tailwind", factory: tailwindPlugin, pluginName: "@4399ywkf/plugin-tailwind" }
2043
+ {
2044
+ key: "reactQuery",
2045
+ factory: reactQueryPlugin,
2046
+ pluginName: "@4399ywkf/plugin-react-query"
2047
+ },
2048
+ {
2049
+ key: "zustand",
2050
+ factory: zustandPlugin,
2051
+ pluginName: "@4399ywkf/plugin-zustand"
2052
+ },
2053
+ {
2054
+ key: "tailwind",
2055
+ factory: tailwindPlugin,
2056
+ pluginName: "@4399ywkf/plugin-tailwind"
2057
+ }
2046
2058
  ];
2047
2059
  var OPTIONAL_PLUGINS = [
2048
- { key: "biome", factory: biomePlugin, pluginName: "@4399ywkf/plugin-biome" },
2049
- { key: "analytics", factory: analyticsPlugin, pluginName: "@4399ywkf/plugin-analytics" },
2050
- { key: "mock", factory: mockPlugin, pluginName: "@4399ywkf/plugin-mock" },
2051
- { key: "theme", factory: themePlugin, pluginName: "@4399ywkf/plugin-theme" },
2052
- { key: "i18n", factory: i18nPlugin, pluginName: "@4399ywkf/plugin-i18n" },
2053
- { key: "garfish", factory: garfishPlugin, pluginName: "@4399ywkf/plugin-garfish" },
2054
- { key: "browserCheck", factory: browserCheckPlugin, pluginName: "@4399ywkf/plugin-browser-check" }
2060
+ {
2061
+ key: "biome",
2062
+ factory: biomePlugin,
2063
+ pluginName: "@4399ywkf/plugin-biome"
2064
+ },
2065
+ {
2066
+ key: "analytics",
2067
+ factory: analyticsPlugin,
2068
+ pluginName: "@4399ywkf/plugin-analytics"
2069
+ },
2070
+ {
2071
+ key: "mock",
2072
+ factory: mockPlugin,
2073
+ pluginName: "@4399ywkf/plugin-mock"
2074
+ },
2075
+ {
2076
+ key: "theme",
2077
+ factory: themePlugin,
2078
+ pluginName: "@4399ywkf/plugin-theme"
2079
+ },
2080
+ {
2081
+ key: "i18n",
2082
+ factory: i18nPlugin,
2083
+ pluginName: "@4399ywkf/plugin-i18n"
2084
+ },
2085
+ {
2086
+ key: "garfish",
2087
+ factory: garfishPlugin,
2088
+ pluginName: "@4399ywkf/plugin-garfish"
2089
+ },
2090
+ {
2091
+ key: "browserCheck",
2092
+ factory: browserCheckPlugin,
2093
+ pluginName: "@4399ywkf/plugin-browser-check"
2094
+ }
2055
2095
  ];
2056
2096
  var ALL_SHORTHAND_KEYS = /* @__PURE__ */ new Set([
2057
2097
  ...BUILTIN_PLUGINS.map((p) => p.key),
@@ -2184,7 +2224,12 @@ var defaultConfig = {
2184
2224
  };
2185
2225
 
2186
2226
  // src/config/loader.ts
2187
- var CONFIG_FILES = ["ywkf.config.ts", "ywkf.config.mts", "ywkf.config.js", "ywkf.config.mjs"];
2227
+ var CONFIG_FILES = [
2228
+ "ywkf.config.ts",
2229
+ "ywkf.config.mts",
2230
+ "ywkf.config.js",
2231
+ "ywkf.config.mjs"
2232
+ ];
2188
2233
  function findConfigFile(cwd) {
2189
2234
  for (const file of CONFIG_FILES) {
2190
2235
  const configPath = resolve2(cwd, file);
@@ -2509,7 +2554,7 @@ function winPath(path) {
2509
2554
  if (isExtendedLengthPath) {
2510
2555
  return path;
2511
2556
  }
2512
- return path.replace(/\\/g, "/");
2557
+ return path.replaceAll("\\", "/");
2513
2558
  }
2514
2559
  var EXCLUDED_DIRS = /* @__PURE__ */ new Set([
2515
2560
  "components",
@@ -2645,16 +2690,16 @@ var ConventionalRouteGenerator = class {
2645
2690
  */
2646
2691
  resolveRoutePath(dirName, parentPath) {
2647
2692
  let segment;
2648
- if (dirName.match(/^\[\.\.\.(.+)\]$/)) {
2693
+ if (/^\[\.\.\..+\]$/.test(dirName)) {
2649
2694
  segment = "*";
2650
- } else if (dirName.match(/^\[(.+)\$\]$/)) {
2695
+ } else if (/^\[.+\$\]$/.test(dirName)) {
2651
2696
  const param = dirName.slice(1, -2);
2652
2697
  segment = `:${param}?`;
2653
- } else if (dirName.match(/^\[(.+)\]$/)) {
2698
+ } else if (/^\[.+\]$/.test(dirName)) {
2654
2699
  const param = dirName.slice(1, -1);
2655
2700
  segment = `:${param}`;
2656
2701
  } else if (dirName.includes(".")) {
2657
- segment = dirName.replace(/\./g, "/");
2702
+ segment = dirName.replaceAll(".", "/");
2658
2703
  } else {
2659
2704
  segment = dirName;
2660
2705
  }
@@ -2665,7 +2710,7 @@ var ConventionalRouteGenerator = class {
2665
2710
  */
2666
2711
  generateRouteName(path) {
2667
2712
  const name = path.split("/").filter(Boolean).map((s) => s.replace(/^:/, "Param").replace(/\?$/, "Optional").replace(/^\*$/, "CatchAll")).map((s) => {
2668
- const cleaned = s.replace(/[^a-zA-Z0-9]/g, "");
2713
+ const cleaned = s.replaceAll(/[^a-z0-9]/gi, "");
2669
2714
  if (!cleaned) return "";
2670
2715
  return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
2671
2716
  }).join("");
@@ -2785,9 +2830,7 @@ export default routes;
2785
2830
  );
2786
2831
  }
2787
2832
  if (route.errorFile) {
2788
- errorImports.push(
2789
- `import ${name}Error from "@/pages/${toImportPath(route.errorFile)}";`
2790
- );
2833
+ errorImports.push(`import ${name}Error from "@/pages/${toImportPath(route.errorFile)}";`);
2791
2834
  }
2792
2835
  if (route.loadingFile) {
2793
2836
  loadingImports.push(
@@ -3301,7 +3344,7 @@ var YwkfGenerator = class {
3301
3344
  * 标准化内容(去掉时间戳等动态部分)
3302
3345
  */
3303
3346
  normalizeContent(content) {
3304
- return content.replace(/\/\/ Generated at: .+/g, "").replace(/\/\*\* Generated at: .+ \*\//g, "");
3347
+ return content.replaceAll(/\/\/ Generated at: .+/g, "").replaceAll(/\/\*\* Generated at: .+ \*\//g, "");
3305
3348
  }
3306
3349
  };
3307
3350
 
@@ -3521,7 +3564,16 @@ function resolveYwkfBuildId(appName) {
3521
3564
  function createBaseConfig(config, cwd, options = {}) {
3522
3565
  const isDev = options.isDev ?? process.env.NODE_ENV !== "production";
3523
3566
  const { resolveApp } = createPathResolver(cwd);
3524
- const { appName, appCName, output, html, alias: userAlias, microFrontend, router, reactCompiler } = config;
3567
+ const {
3568
+ appName,
3569
+ appCName,
3570
+ output,
3571
+ html,
3572
+ alias: userAlias,
3573
+ microFrontend,
3574
+ router,
3575
+ reactCompiler
3576
+ } = config;
3525
3577
  const buildId = resolveYwkfBuildId(appName);
3526
3578
  const { env: clientEnv, dropped: droppedEnvKeys } = buildClientEnv({ cwd, env: config.env });
3527
3579
  if (droppedEnvKeys.length > 0) {
@@ -3554,7 +3606,7 @@ function createBaseConfig(config, cwd, options = {}) {
3554
3606
  ...alias,
3555
3607
  "process/browser.js": require2.resolve("process/browser.js"),
3556
3608
  "process/browser": require2.resolve("process/browser.js"),
3557
- react: resolveApp("node_modules/react"),
3609
+ "react": resolveApp("node_modules/react"),
3558
3610
  "react-dom": resolveApp("node_modules/react-dom"),
3559
3611
  "react-router": resolveApp("node_modules/react-router")
3560
3612
  },
@@ -4406,9 +4458,10 @@ function registerShortcuts(getPrinter, opts) {
4406
4458
  const cmd = buffer.trim().toLowerCase();
4407
4459
  buffer = "";
4408
4460
  switch (cmd) {
4409
- case "h":
4461
+ case "h": {
4410
4462
  getPrinter().printShortcuts();
4411
4463
  break;
4464
+ }
4412
4465
  case "o": {
4413
4466
  const url = `http://${displayHost(opts.getHost())}:${opts.getPort()}/`;
4414
4467
  import("child_process").then((cp) => {
@@ -4418,12 +4471,14 @@ function registerShortcuts(getPrinter, opts) {
4418
4471
  console.log(` ${chalk.green("\u279C")} Opening ${chalk.cyan(url)}...`);
4419
4472
  break;
4420
4473
  }
4421
- case "c":
4474
+ case "c": {
4422
4475
  console.clear();
4423
4476
  break;
4424
- case "q":
4477
+ }
4478
+ case "q": {
4425
4479
  opts.onQuit();
4426
4480
  break;
4481
+ }
4427
4482
  }
4428
4483
  };
4429
4484
  process.stdin.on("data", handler);
@@ -4574,20 +4629,16 @@ async function findPortHolder(port) {
4574
4629
  const pid2 = parseWindowsNetstatPid(stdout2, port);
4575
4630
  return pid2 === null ? null : { pid: pid2 };
4576
4631
  }
4577
- const { stdout } = await execFileAsync(
4578
- "lsof",
4579
- ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"],
4580
- { timeout: 1500 }
4581
- );
4632
+ const { stdout } = await execFileAsync("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"], {
4633
+ timeout: 1500
4634
+ });
4582
4635
  const pid = Number.parseInt(stdout.trim().split(/\s+/)[0], 10);
4583
4636
  if (!Number.isInteger(pid)) return null;
4584
4637
  let name;
4585
4638
  try {
4586
- const { stdout: comm } = await execFileAsync(
4587
- "ps",
4588
- ["-p", String(pid), "-o", "comm="],
4589
- { timeout: 1500 }
4590
- );
4639
+ const { stdout: comm } = await execFileAsync("ps", ["-p", String(pid), "-o", "comm="], {
4640
+ timeout: 1500
4641
+ });
4591
4642
  name = comm.trim().split("/").pop() || void 0;
4592
4643
  } catch {
4593
4644
  }
@@ -4734,7 +4785,7 @@ async function startDevServer(cwd, config) {
4734
4785
  printer.updateProgress(0, "rebuilding");
4735
4786
  });
4736
4787
  const devServerOptions = {
4737
- ...rspackConfig.devServer || {},
4788
+ ...rspackConfig.devServer,
4738
4789
  host,
4739
4790
  port,
4740
4791
  setupExitSignals: false
@@ -4895,7 +4946,7 @@ var ConventionalRoutePlugin = class {
4895
4946
  * 标准化内容(去掉时间戳等动态部分)
4896
4947
  */
4897
4948
  normalizeContent(content) {
4898
- return content.replace(/\/\/ Generated at: .+/g, "");
4949
+ return content.replaceAll(/\/\/ Generated at: .+/g, "");
4899
4950
  }
4900
4951
  /**
4901
4952
  * 监听页面目录变化
@@ -4932,12 +4983,8 @@ var ConventionalRoutePlugin = class {
4932
4983
  var DEFAULT_CHUNK_RECOVERY_COOLDOWN_MS = 3e4;
4933
4984
  var CHUNK_RECOVERY_STORAGE_KEY = "@4399ywkf/core:chunk-recovery-attempt";
4934
4985
  var CHUNK_RECOVERY_CACHE_BUST_PARAM = "__ywkf_chunk_retry";
4935
- var CHUNK_RECOVERY_ACTIVE_SYMBOL = /* @__PURE__ */ Symbol.for(
4936
- "@4399ywkf/core/chunk-recovery-active"
4937
- );
4938
- var CHUNK_RECOVERY_REGISTRY_SYMBOL = /* @__PURE__ */ Symbol.for(
4939
- "@4399ywkf/core/chunk-recovery-registry"
4940
- );
4986
+ var CHUNK_RECOVERY_ACTIVE_SYMBOL = /* @__PURE__ */ Symbol.for("@4399ywkf/core/chunk-recovery-active");
4987
+ var CHUNK_RECOVERY_REGISTRY_SYMBOL = /* @__PURE__ */ Symbol.for("@4399ywkf/core/chunk-recovery-registry");
4941
4988
  var CHUNK_LOAD_ERROR_PATTERNS = [
4942
4989
  /\bChunkLoadError\b/i,
4943
4990
  /\bLoading (?:CSS )?chunk\s+\S+\s+failed\b/i,
@@ -5544,7 +5591,6 @@ function DefaultErrorFallback({
5544
5591
  !isChunkError && onReset && /* @__PURE__ */ jsx2(
5545
5592
  "button",
5546
5593
  {
5547
- onClick: onReset,
5548
5594
  style: {
5549
5595
  padding: "8px 16px",
5550
5596
  backgroundColor: "#1890ff",
@@ -5553,13 +5599,13 @@ function DefaultErrorFallback({
5553
5599
  borderRadius: 4,
5554
5600
  cursor: "pointer"
5555
5601
  },
5602
+ onClick: onReset,
5556
5603
  children: "\u91CD\u8BD5"
5557
5604
  }
5558
5605
  ),
5559
5606
  canReloadPage && /* @__PURE__ */ jsx2(
5560
5607
  "button",
5561
5608
  {
5562
- onClick: () => window.location.reload(),
5563
5609
  style: {
5564
5610
  padding: "8px 16px",
5565
5611
  backgroundColor: "#fff",
@@ -5568,6 +5614,7 @@ function DefaultErrorFallback({
5568
5614
  borderRadius: 4,
5569
5615
  cursor: "pointer"
5570
5616
  },
5617
+ onClick: () => window.location.reload(),
5571
5618
  children: "\u5237\u65B0\u9875\u9762"
5572
5619
  }
5573
5620
  )
@@ -5695,7 +5742,7 @@ async function resolveAppConfig(config) {
5695
5742
  const createRouter = routesModule.createRouter || routesModule.default?.createRouter;
5696
5743
  if (typeof createRouter === "function") {
5697
5744
  const router = createRouter(config.basename);
5698
- console.log("[ywkf] \u5DF2\u81EA\u52A8\u6CE8\u5165\u7EA6\u5B9A\u5F0F\u8DEF\u7531");
5745
+ console.info("[ywkf] \u5DF2\u81EA\u52A8\u6CE8\u5165\u7EA6\u5B9A\u5F0F\u8DEF\u7531");
5699
5746
  return { ...config, router };
5700
5747
  } else {
5701
5748
  console.warn("[ywkf] @ywkf/routes \u672A\u5BFC\u51FA createRouter \u51FD\u6570");
@@ -5763,13 +5810,13 @@ function createMicroApp(getConfig) {
5763
5810
  * 微前端 bootstrap 生命周期
5764
5811
  */
5765
5812
  async bootstrap() {
5766
- console.log("[MicroApp] bootstrap");
5813
+ console.info("[MicroApp] bootstrap");
5767
5814
  },
5768
5815
  /**
5769
5816
  * 微前端 mount 生命周期
5770
5817
  */
5771
5818
  async mount(props) {
5772
- console.log("[MicroApp] mount", props);
5819
+ console.info("[MicroApp] mount", props);
5773
5820
  const config = getConfig(props);
5774
5821
  const resolvedConfig = await resolveAppConfig(config);
5775
5822
  const container = props?.masterProps?.container;
@@ -5790,7 +5837,7 @@ function createMicroApp(getConfig) {
5790
5837
  });
5791
5838
  try {
5792
5839
  microRoot = createRoot(rootElement);
5793
- microRoot.render(/* @__PURE__ */ jsx4(RootProvider, { config: resolvedConfig, isMicroApp: true }));
5840
+ microRoot.render(/* @__PURE__ */ jsx4(RootProvider, { isMicroApp: true, config: resolvedConfig }));
5794
5841
  disposeMicroChunkRecoveryHandlers = nextDisposeMicroChunkRecoveryHandlers;
5795
5842
  } catch (error) {
5796
5843
  nextDisposeMicroChunkRecoveryHandlers();
@@ -5807,7 +5854,7 @@ function createMicroApp(getConfig) {
5807
5854
  * 微前端 unmount 生命周期
5808
5855
  */
5809
5856
  async unmount(props) {
5810
- console.log("[MicroApp] unmount", props);
5857
+ console.info("[MicroApp] unmount", props);
5811
5858
  const config = getConfig(props);
5812
5859
  if (config.lifecycle?.onUnmount) {
5813
5860
  config.lifecycle.onUnmount();
@@ -5823,7 +5870,7 @@ function createMicroApp(getConfig) {
5823
5870
  * 微前端 update 生命周期(可选)
5824
5871
  */
5825
5872
  async update(props) {
5826
- console.log("[MicroApp] update", props);
5873
+ console.info("[MicroApp] update", props);
5827
5874
  }
5828
5875
  };
5829
5876
  }