@4399ywkf/core 5.3.1 → 5.4.0

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.
@@ -150,9 +150,7 @@ var browserCheckPlugin = createPlugin((options = {}) => ({
150
150
  }
151
151
  }
152
152
  const minVersions = explicitVersions ? { ...baseVersions, ...explicitVersions } : baseVersions;
153
- logger.info(
154
- `\u6D4F\u89C8\u5668\u517C\u5BB9\u6027\u68C0\u67E5\u5DF2\u542F\u7528 (\u7279\u6027\u68C0\u6D4B: ${features.join(", ")})`
155
- );
153
+ logger.info(`\u6D4F\u89C8\u5668\u517C\u5BB9\u6027\u68C0\u67E5\u5DF2\u542F\u7528 (\u7279\u6027\u68C0\u6D4B: ${features.join(", ")})`);
156
154
  logger.info(
157
155
  `\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)" : ""}`
158
156
  );
@@ -192,7 +190,7 @@ var browserCheckPlugin = createPlugin((options = {}) => ({
192
190
  const insertIndex = lastImportIndex >= 0 ? lastImportIndex + 1 : 0;
193
191
  lines.splice(insertIndex, 0, checkBlock);
194
192
  let result = lines.join("\n");
195
- result = result.replace(
193
+ result = result.replaceAll(
196
194
  /(\s*)(await\s+)?runApp\(\);?/g,
197
195
  (_, indent, awaitKw) => `${indent}if (__ywkfBrowserOk) { ${awaitKw || ""}runApp(); }`
198
196
  );
@@ -216,37 +214,39 @@ function buildFeatureChecks(features) {
216
214
  return lines;
217
215
  }
218
216
  function buildVersionChecks(minVersions) {
219
- const entries = Object.entries(minVersions).filter(
220
- ([, v]) => v != null
221
- );
217
+ const entries = Object.entries(minVersions).filter(([, v]) => v != null);
222
218
  if (entries.length === 0) return [];
223
219
  const lines = ["// UA \u7248\u672C\u68C0\u6D4B", "const ua = navigator.userAgent;"];
224
220
  for (const [browser, minVer] of entries) {
225
221
  switch (browser) {
226
- case "chrome":
222
+ case "chrome": {
227
223
  lines.push(
228
224
  `const chromeMatch = /Chrome\\/(\\d+)/.exec(ua);`,
229
225
  `if (chromeMatch && !/Edg\\//.test(ua) && Number(chromeMatch[1]) < ${minVer}) return false;`
230
226
  );
231
227
  break;
232
- case "edge":
228
+ }
229
+ case "edge": {
233
230
  lines.push(
234
231
  `const edgeMatch = /Edg\\/(\\d+)/.exec(ua);`,
235
232
  `if (edgeMatch && Number(edgeMatch[1]) < ${minVer}) return false;`
236
233
  );
237
234
  break;
238
- case "firefox":
235
+ }
236
+ case "firefox": {
239
237
  lines.push(
240
238
  `const firefoxMatch = /Firefox\\/(\\d+)/.exec(ua);`,
241
239
  `if (firefoxMatch && Number(firefoxMatch[1]) < ${minVer}) return false;`
242
240
  );
243
241
  break;
244
- case "safari":
242
+ }
243
+ case "safari": {
245
244
  lines.push(
246
245
  `const safariMatch = /Version\\/(\\d+\\.?\\d*)/.exec(ua);`,
247
246
  `if (safariMatch && /Safari/.test(ua) && !/Chrome/.test(ua) && Number(safariMatch[1]) < ${minVer}) return false;`
248
247
  );
249
248
  break;
249
+ }
250
250
  }
251
251
  }
252
252
  return lines;
@@ -339,9 +339,9 @@ function readBrowserslistFile(filePath) {
339
339
  function extractMinVersions(queries) {
340
340
  const result = {};
341
341
  const expanded = queries.flatMap((q) => q.split(",").map((s) => s.trim()));
342
- const versionPattern = /^(\w+)\s*(?:(>=?)\s*)?(\d+(?:\.\d+)?)\s*$/i;
342
+ const versionPattern = /^([a-z_]+)\s*(?:(>=?)\s*)?(\d+(?:\.\d+)?)\s*$/i;
343
343
  for (const query of expanded) {
344
- if (/^(not|dead|last|defaults|>?\s*\d+%|unreleased|current)/i.test(query)) {
344
+ if (/^(?:not|dead|last|defaults|>?\s*\d+%|unreleased|current)/i.test(query)) {
345
345
  continue;
346
346
  }
347
347
  const match = versionPattern.exec(query);
@@ -382,7 +382,7 @@ var garfishPlugin = createPlugin((options = {}) => ({
382
382
  rspackConfig.devServer = {
383
383
  ...rspackConfig.devServer,
384
384
  headers: {
385
- ...rspackConfig.devServer?.headers || {},
385
+ ...rspackConfig.devServer?.headers,
386
386
  "Access-Control-Allow-Origin": "*",
387
387
  "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
388
388
  "Access-Control-Allow-Headers": "*"
@@ -710,7 +710,7 @@ function getLocaleLabel(locale) {
710
710
  "ru-RU": "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
711
711
  "it-IT": "Italiano",
712
712
  "vi-VN": "Ti\u1EBFng Vi\u1EC7t",
713
- ar: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"
713
+ "ar": "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"
714
714
  };
715
715
  return map[locale] || locale;
716
716
  }
@@ -861,7 +861,7 @@ function scanMockFiles(dir) {
861
861
  for (const entry of entries) {
862
862
  const fullPath = join4(dir, entry);
863
863
  const stat = statSync(fullPath);
864
- if (stat.isFile() && /\.(ts|js|mjs)$/.test(entry)) {
864
+ if (stat.isFile() && /\.(?:ts|js|mjs)$/.test(entry)) {
865
865
  files.push(fullPath);
866
866
  } else if (stat.isDirectory()) {
867
867
  files.push(...scanMockFiles(fullPath));
@@ -1338,12 +1338,13 @@ function generateThemeProvider(opts) {
1338
1338
  scopePopupContainer
1339
1339
  } = opts;
1340
1340
  const isAutoLocale = locale === "auto";
1341
- const sections = [];
1342
- sections.push(`// \u6B64\u6587\u4EF6\u7531 @4399ywkf/plugin-theme v3 \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u4FEE\u6539`);
1343
- sections.push(buildImports({ globalReset, cssVar, scopePopupContainer, locale }));
1344
- sections.push(TYPES_CODE);
1345
- sections.push(buildStoreCode({ defaultAppearance, primaryColor, neutralColor, locale }));
1346
- sections.push(HOOKS_CODE);
1341
+ const sections = [
1342
+ `// \u6B64\u6587\u4EF6\u7531 @4399ywkf/plugin-theme v3 \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u4FEE\u6539`,
1343
+ buildImports({ globalReset, cssVar, scopePopupContainer, locale }),
1344
+ TYPES_CODE,
1345
+ buildStoreCode({ defaultAppearance, primaryColor, neutralColor, locale }),
1346
+ HOOKS_CODE
1347
+ ];
1347
1348
  if (globalReset) sections.push(GLOBAL_RESET_CODE);
1348
1349
  if (cssVar) sections.push(buildCssVarSyncCode());
1349
1350
  if (darkMode) sections.push(APPEARANCE_SYNC_CODE);
@@ -2038,18 +2039,58 @@ export type { StateCreator, StoreApi } from "zustand";
2038
2039
 
2039
2040
  // src/config/normalize.ts
2040
2041
  var BUILTIN_PLUGINS = [
2041
- { key: "reactQuery", factory: reactQueryPlugin, pluginName: "@4399ywkf/plugin-react-query" },
2042
- { key: "zustand", factory: zustandPlugin, pluginName: "@4399ywkf/plugin-zustand" },
2043
- { key: "tailwind", factory: tailwindPlugin, pluginName: "@4399ywkf/plugin-tailwind" }
2042
+ {
2043
+ key: "reactQuery",
2044
+ factory: reactQueryPlugin,
2045
+ pluginName: "@4399ywkf/plugin-react-query"
2046
+ },
2047
+ {
2048
+ key: "zustand",
2049
+ factory: zustandPlugin,
2050
+ pluginName: "@4399ywkf/plugin-zustand"
2051
+ },
2052
+ {
2053
+ key: "tailwind",
2054
+ factory: tailwindPlugin,
2055
+ pluginName: "@4399ywkf/plugin-tailwind"
2056
+ }
2044
2057
  ];
2045
2058
  var OPTIONAL_PLUGINS = [
2046
- { key: "biome", factory: biomePlugin, pluginName: "@4399ywkf/plugin-biome" },
2047
- { key: "analytics", factory: analyticsPlugin, pluginName: "@4399ywkf/plugin-analytics" },
2048
- { key: "mock", factory: mockPlugin, pluginName: "@4399ywkf/plugin-mock" },
2049
- { key: "theme", factory: themePlugin, pluginName: "@4399ywkf/plugin-theme" },
2050
- { key: "i18n", factory: i18nPlugin, pluginName: "@4399ywkf/plugin-i18n" },
2051
- { key: "garfish", factory: garfishPlugin, pluginName: "@4399ywkf/plugin-garfish" },
2052
- { key: "browserCheck", factory: browserCheckPlugin, pluginName: "@4399ywkf/plugin-browser-check" }
2059
+ {
2060
+ key: "biome",
2061
+ factory: biomePlugin,
2062
+ pluginName: "@4399ywkf/plugin-biome"
2063
+ },
2064
+ {
2065
+ key: "analytics",
2066
+ factory: analyticsPlugin,
2067
+ pluginName: "@4399ywkf/plugin-analytics"
2068
+ },
2069
+ {
2070
+ key: "mock",
2071
+ factory: mockPlugin,
2072
+ pluginName: "@4399ywkf/plugin-mock"
2073
+ },
2074
+ {
2075
+ key: "theme",
2076
+ factory: themePlugin,
2077
+ pluginName: "@4399ywkf/plugin-theme"
2078
+ },
2079
+ {
2080
+ key: "i18n",
2081
+ factory: i18nPlugin,
2082
+ pluginName: "@4399ywkf/plugin-i18n"
2083
+ },
2084
+ {
2085
+ key: "garfish",
2086
+ factory: garfishPlugin,
2087
+ pluginName: "@4399ywkf/plugin-garfish"
2088
+ },
2089
+ {
2090
+ key: "browserCheck",
2091
+ factory: browserCheckPlugin,
2092
+ pluginName: "@4399ywkf/plugin-browser-check"
2093
+ }
2053
2094
  ];
2054
2095
  var ALL_SHORTHAND_KEYS = /* @__PURE__ */ new Set([
2055
2096
  ...BUILTIN_PLUGINS.map((p) => p.key),
@@ -2086,7 +2127,7 @@ function winPath(path) {
2086
2127
  if (isExtendedLengthPath) {
2087
2128
  return path;
2088
2129
  }
2089
- return path.replace(/\\/g, "/");
2130
+ return path.replaceAll("\\", "/");
2090
2131
  }
2091
2132
  var EXCLUDED_DIRS = /* @__PURE__ */ new Set([
2092
2133
  "components",
@@ -2222,16 +2263,16 @@ var ConventionalRouteGenerator = class {
2222
2263
  */
2223
2264
  resolveRoutePath(dirName, parentPath) {
2224
2265
  let segment;
2225
- if (dirName.match(/^\[\.\.\.(.+)\]$/)) {
2266
+ if (/^\[\.\.\..+\]$/.test(dirName)) {
2226
2267
  segment = "*";
2227
- } else if (dirName.match(/^\[(.+)\$\]$/)) {
2268
+ } else if (/^\[.+\$\]$/.test(dirName)) {
2228
2269
  const param = dirName.slice(1, -2);
2229
2270
  segment = `:${param}?`;
2230
- } else if (dirName.match(/^\[(.+)\]$/)) {
2271
+ } else if (/^\[.+\]$/.test(dirName)) {
2231
2272
  const param = dirName.slice(1, -1);
2232
2273
  segment = `:${param}`;
2233
2274
  } else if (dirName.includes(".")) {
2234
- segment = dirName.replace(/\./g, "/");
2275
+ segment = dirName.replaceAll(".", "/");
2235
2276
  } else {
2236
2277
  segment = dirName;
2237
2278
  }
@@ -2242,7 +2283,7 @@ var ConventionalRouteGenerator = class {
2242
2283
  */
2243
2284
  generateRouteName(path) {
2244
2285
  const name = path.split("/").filter(Boolean).map((s) => s.replace(/^:/, "Param").replace(/\?$/, "Optional").replace(/^\*$/, "CatchAll")).map((s) => {
2245
- const cleaned = s.replace(/[^a-zA-Z0-9]/g, "");
2286
+ const cleaned = s.replaceAll(/[^a-z0-9]/gi, "");
2246
2287
  if (!cleaned) return "";
2247
2288
  return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
2248
2289
  }).join("");
@@ -2362,9 +2403,7 @@ export default routes;
2362
2403
  );
2363
2404
  }
2364
2405
  if (route.errorFile) {
2365
- errorImports.push(
2366
- `import ${name}Error from "@/pages/${toImportPath(route.errorFile)}";`
2367
- );
2406
+ errorImports.push(`import ${name}Error from "@/pages/${toImportPath(route.errorFile)}";`);
2368
2407
  }
2369
2408
  if (route.loadingFile) {
2370
2409
  loadingImports.push(
@@ -2875,7 +2914,7 @@ var YwkfGenerator = class {
2875
2914
  * 标准化内容(去掉时间戳等动态部分)
2876
2915
  */
2877
2916
  normalizeContent(content) {
2878
- return content.replace(/\/\/ Generated at: .+/g, "").replace(/\/\*\* Generated at: .+ \*\//g, "");
2917
+ return content.replaceAll(/\/\/ Generated at: .+/g, "").replaceAll(/\/\*\* Generated at: .+ \*\//g, "");
2879
2918
  }
2880
2919
  };
2881
2920
 
@@ -3095,7 +3134,16 @@ function resolveYwkfBuildId(appName) {
3095
3134
  function createBaseConfig(config, cwd, options = {}) {
3096
3135
  const isDev = options.isDev ?? process.env.NODE_ENV !== "production";
3097
3136
  const { resolveApp } = createPathResolver(cwd);
3098
- const { appName, appCName, output, html, alias: userAlias, microFrontend, router, reactCompiler } = config;
3137
+ const {
3138
+ appName,
3139
+ appCName,
3140
+ output,
3141
+ html,
3142
+ alias: userAlias,
3143
+ microFrontend,
3144
+ router,
3145
+ reactCompiler
3146
+ } = config;
3099
3147
  const buildId = resolveYwkfBuildId(appName);
3100
3148
  const { env: clientEnv, dropped: droppedEnvKeys } = buildClientEnv({ cwd, env: config.env });
3101
3149
  if (droppedEnvKeys.length > 0) {
@@ -3128,7 +3176,7 @@ function createBaseConfig(config, cwd, options = {}) {
3128
3176
  ...alias,
3129
3177
  "process/browser.js": require2.resolve("process/browser.js"),
3130
3178
  "process/browser": require2.resolve("process/browser.js"),
3131
- react: resolveApp("node_modules/react"),
3179
+ "react": resolveApp("node_modules/react"),
3132
3180
  "react-dom": resolveApp("node_modules/react-dom"),
3133
3181
  "react-router": resolveApp("node_modules/react-router")
3134
3182
  },