@4399ywkf/core 5.3.0 → 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.
package/biome.json CHANGED
@@ -1,32 +1,49 @@
1
1
  {
2
- "$schema": "https://biomejs.dev/schemas/2.3.11/schema.json",
3
- "vcs": {
4
- "enabled": true,
5
- "defaultBranch": "main",
6
- "clientKind": "git",
7
- "useIgnoreFile": true
8
- },
9
- "formatter": {
10
- "enabled": true,
11
- "indentStyle": "space"
2
+ "assist": {
3
+ "actions": {
4
+ "source": {
5
+ "organizeImports": "on"
6
+ }
7
+ }
12
8
  },
13
9
  "css": {
14
10
  "formatter": {
15
11
  "quoteStyle": "single"
16
12
  }
17
13
  },
14
+ "files": {
15
+ "ignoreUnknown": true,
16
+ "includes": [
17
+ "**",
18
+ "!**/.vscode/**/*",
19
+ "!**/node_modules/**/*",
20
+ "!**/dist/**/*",
21
+ "!**/.ywkf/**/*",
22
+ "!**/public/**/*.html"
23
+ ]
24
+ },
25
+ "formatter": {
26
+ "enabled": true,
27
+ "indentStyle": "space",
28
+ "indentWidth": 2,
29
+ "lineWidth": 100,
30
+ "lineEnding": "lf"
31
+ },
18
32
  "javascript": {
19
33
  "formatter": {
20
34
  "quoteStyle": "single",
21
- "arrowParentheses": "asNeeded",
22
35
  "jsxQuoteStyle": "double",
23
- "lineWidth": 100
36
+ "quoteProperties": "preserve",
37
+ "trailingCommas": "all",
38
+ "semicolons": "always",
39
+ "arrowParentheses": "always",
40
+ "bracketSpacing": true,
41
+ "bracketSameLine": false
24
42
  }
25
43
  },
26
44
  "linter": {
27
45
  "enabled": true,
28
46
  "rules": {
29
- "recommended": true,
30
47
  "style": {
31
48
  "useNodejsImportProtocol": "off",
32
49
  "noNonNullAssertion": "off",
@@ -67,22 +84,9 @@
67
84
  }
68
85
  }
69
86
  },
70
- "assist": {
71
- "actions": {
72
- "source": {
73
- "organizeImports": "on"
74
- }
75
- }
76
- },
77
- "files": {
78
- "ignoreUnknown": true,
79
- "includes": [
80
- "**",
81
- "!**/.vscode/**/*",
82
- "!**/node_modules/**/*",
83
- "!**/dist/**/*",
84
- "!**/.ywkf/**/*",
85
- "!**/public/**/*.html"
86
- ]
87
+ "vcs": {
88
+ "enabled": true,
89
+ "clientKind": "git",
90
+ "useIgnoreFile": true
87
91
  }
88
92
  }
package/dist/cli/index.js CHANGED
@@ -155,9 +155,7 @@ var browserCheckPlugin = createPlugin((options = {}) => ({
155
155
  }
156
156
  }
157
157
  const minVersions = explicitVersions ? { ...baseVersions, ...explicitVersions } : baseVersions;
158
- logger.info(
159
- `\u6D4F\u89C8\u5668\u517C\u5BB9\u6027\u68C0\u67E5\u5DF2\u542F\u7528 (\u7279\u6027\u68C0\u6D4B: ${features.join(", ")})`
160
- );
158
+ logger.info(`\u6D4F\u89C8\u5668\u517C\u5BB9\u6027\u68C0\u67E5\u5DF2\u542F\u7528 (\u7279\u6027\u68C0\u6D4B: ${features.join(", ")})`);
161
159
  logger.info(
162
160
  `\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)" : ""}`
163
161
  );
@@ -197,7 +195,7 @@ var browserCheckPlugin = createPlugin((options = {}) => ({
197
195
  const insertIndex = lastImportIndex >= 0 ? lastImportIndex + 1 : 0;
198
196
  lines.splice(insertIndex, 0, checkBlock);
199
197
  let result = lines.join("\n");
200
- result = result.replace(
198
+ result = result.replaceAll(
201
199
  /(\s*)(await\s+)?runApp\(\);?/g,
202
200
  (_, indent, awaitKw) => `${indent}if (__ywkfBrowserOk) { ${awaitKw || ""}runApp(); }`
203
201
  );
@@ -221,37 +219,39 @@ function buildFeatureChecks(features) {
221
219
  return lines;
222
220
  }
223
221
  function buildVersionChecks(minVersions) {
224
- const entries = Object.entries(minVersions).filter(
225
- ([, v]) => v != null
226
- );
222
+ const entries = Object.entries(minVersions).filter(([, v]) => v != null);
227
223
  if (entries.length === 0) return [];
228
224
  const lines = ["// UA \u7248\u672C\u68C0\u6D4B", "const ua = navigator.userAgent;"];
229
225
  for (const [browser, minVer] of entries) {
230
226
  switch (browser) {
231
- case "chrome":
227
+ case "chrome": {
232
228
  lines.push(
233
229
  `const chromeMatch = /Chrome\\/(\\d+)/.exec(ua);`,
234
230
  `if (chromeMatch && !/Edg\\//.test(ua) && Number(chromeMatch[1]) < ${minVer}) return false;`
235
231
  );
236
232
  break;
237
- case "edge":
233
+ }
234
+ case "edge": {
238
235
  lines.push(
239
236
  `const edgeMatch = /Edg\\/(\\d+)/.exec(ua);`,
240
237
  `if (edgeMatch && Number(edgeMatch[1]) < ${minVer}) return false;`
241
238
  );
242
239
  break;
243
- case "firefox":
240
+ }
241
+ case "firefox": {
244
242
  lines.push(
245
243
  `const firefoxMatch = /Firefox\\/(\\d+)/.exec(ua);`,
246
244
  `if (firefoxMatch && Number(firefoxMatch[1]) < ${minVer}) return false;`
247
245
  );
248
246
  break;
249
- case "safari":
247
+ }
248
+ case "safari": {
250
249
  lines.push(
251
250
  `const safariMatch = /Version\\/(\\d+\\.?\\d*)/.exec(ua);`,
252
251
  `if (safariMatch && /Safari/.test(ua) && !/Chrome/.test(ua) && Number(safariMatch[1]) < ${minVer}) return false;`
253
252
  );
254
253
  break;
254
+ }
255
255
  }
256
256
  }
257
257
  return lines;
@@ -344,9 +344,9 @@ function readBrowserslistFile(filePath) {
344
344
  function extractMinVersions(queries) {
345
345
  const result = {};
346
346
  const expanded = queries.flatMap((q) => q.split(",").map((s) => s.trim()));
347
- const versionPattern = /^(\w+)\s*(?:(>=?)\s*)?(\d+(?:\.\d+)?)\s*$/i;
347
+ const versionPattern = /^([a-z_]+)\s*(?:(>=?)\s*)?(\d+(?:\.\d+)?)\s*$/i;
348
348
  for (const query of expanded) {
349
- if (/^(not|dead|last|defaults|>?\s*\d+%|unreleased|current)/i.test(query)) {
349
+ if (/^(?:not|dead|last|defaults|>?\s*\d+%|unreleased|current)/i.test(query)) {
350
350
  continue;
351
351
  }
352
352
  const match = versionPattern.exec(query);
@@ -387,7 +387,7 @@ var garfishPlugin = createPlugin((options = {}) => ({
387
387
  rspackConfig.devServer = {
388
388
  ...rspackConfig.devServer,
389
389
  headers: {
390
- ...rspackConfig.devServer?.headers || {},
390
+ ...rspackConfig.devServer?.headers,
391
391
  "Access-Control-Allow-Origin": "*",
392
392
  "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
393
393
  "Access-Control-Allow-Headers": "*"
@@ -715,7 +715,7 @@ function getLocaleLabel(locale) {
715
715
  "ru-RU": "\u0420\u0443\u0441\u0441\u043A\u0438\u0439",
716
716
  "it-IT": "Italiano",
717
717
  "vi-VN": "Ti\u1EBFng Vi\u1EC7t",
718
- ar: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"
718
+ "ar": "\u0627\u0644\u0639\u0631\u0628\u064A\u0629"
719
719
  };
720
720
  return map[locale] || locale;
721
721
  }
@@ -768,7 +768,7 @@ function scaffoldI18nRc(cwd, localesDir, defaultLocale, locales, logger) {
768
768
  const filePath = join3(cwd, ".i18nrc.js");
769
769
  if (existsSync3(filePath)) return;
770
770
  const outputLocales = locales.filter((l) => l !== defaultLocale).map((l) => `"${l}"`).join(", ");
771
- const content = `const { defineConfig } = require("@lobehub/i18n-cli");
771
+ const content = `const { defineConfig } = require("@4399ywkf/i18n");
772
772
 
773
773
  module.exports = defineConfig({
774
774
  entry: "${localesDir}/${defaultLocale}",
@@ -778,7 +778,7 @@ module.exports = defineConfig({
778
778
  });
779
779
  `;
780
780
  writeFileSync2(filePath, content, "utf-8");
781
- logger.info("\u5DF2\u751F\u6210\u7FFB\u8BD1\u914D\u7F6E: .i18nrc.js\uFF08@lobehub/i18n-cli\uFF09");
781
+ logger.info("\u5DF2\u751F\u6210\u7FFB\u8BD1\u914D\u7F6E: .i18nrc.js\uFF08\u9700\u5B89\u88C5 @4399ywkf/i18n\uFF09");
782
782
  }
783
783
  function scaffoldLocaleJsonDirs(cwd, localesDir, locales, defaultLocale, namespaces, logger) {
784
784
  const baseDir = join3(cwd, localesDir);
@@ -866,7 +866,7 @@ function scanMockFiles(dir) {
866
866
  for (const entry of entries) {
867
867
  const fullPath = join4(dir, entry);
868
868
  const stat = statSync(fullPath);
869
- if (stat.isFile() && /\.(ts|js|mjs)$/.test(entry)) {
869
+ if (stat.isFile() && /\.(?:ts|js|mjs)$/.test(entry)) {
870
870
  files.push(fullPath);
871
871
  } else if (stat.isDirectory()) {
872
872
  files.push(...scanMockFiles(fullPath));
@@ -1343,12 +1343,13 @@ function generateThemeProvider(opts) {
1343
1343
  scopePopupContainer
1344
1344
  } = opts;
1345
1345
  const isAutoLocale = locale === "auto";
1346
- const sections = [];
1347
- sections.push(`// \u6B64\u6587\u4EF6\u7531 @4399ywkf/plugin-theme v3 \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u4FEE\u6539`);
1348
- sections.push(buildImports({ globalReset, cssVar, scopePopupContainer, locale }));
1349
- sections.push(TYPES_CODE);
1350
- sections.push(buildStoreCode({ defaultAppearance, primaryColor, neutralColor, locale }));
1351
- sections.push(HOOKS_CODE);
1346
+ const sections = [
1347
+ `// \u6B64\u6587\u4EF6\u7531 @4399ywkf/plugin-theme v3 \u81EA\u52A8\u751F\u6210\uFF0C\u8BF7\u52FF\u624B\u52A8\u4FEE\u6539`,
1348
+ buildImports({ globalReset, cssVar, scopePopupContainer, locale }),
1349
+ TYPES_CODE,
1350
+ buildStoreCode({ defaultAppearance, primaryColor, neutralColor, locale }),
1351
+ HOOKS_CODE
1352
+ ];
1352
1353
  if (globalReset) sections.push(GLOBAL_RESET_CODE);
1353
1354
  if (cssVar) sections.push(buildCssVarSyncCode());
1354
1355
  if (darkMode) sections.push(APPEARANCE_SYNC_CODE);
@@ -2043,18 +2044,58 @@ export type { StateCreator, StoreApi } from "zustand";
2043
2044
 
2044
2045
  // src/config/normalize.ts
2045
2046
  var BUILTIN_PLUGINS = [
2046
- { key: "reactQuery", factory: reactQueryPlugin, pluginName: "@4399ywkf/plugin-react-query" },
2047
- { key: "zustand", factory: zustandPlugin, pluginName: "@4399ywkf/plugin-zustand" },
2048
- { key: "tailwind", factory: tailwindPlugin, pluginName: "@4399ywkf/plugin-tailwind" }
2047
+ {
2048
+ key: "reactQuery",
2049
+ factory: reactQueryPlugin,
2050
+ pluginName: "@4399ywkf/plugin-react-query"
2051
+ },
2052
+ {
2053
+ key: "zustand",
2054
+ factory: zustandPlugin,
2055
+ pluginName: "@4399ywkf/plugin-zustand"
2056
+ },
2057
+ {
2058
+ key: "tailwind",
2059
+ factory: tailwindPlugin,
2060
+ pluginName: "@4399ywkf/plugin-tailwind"
2061
+ }
2049
2062
  ];
2050
2063
  var OPTIONAL_PLUGINS = [
2051
- { key: "biome", factory: biomePlugin, pluginName: "@4399ywkf/plugin-biome" },
2052
- { key: "analytics", factory: analyticsPlugin, pluginName: "@4399ywkf/plugin-analytics" },
2053
- { key: "mock", factory: mockPlugin, pluginName: "@4399ywkf/plugin-mock" },
2054
- { key: "theme", factory: themePlugin, pluginName: "@4399ywkf/plugin-theme" },
2055
- { key: "i18n", factory: i18nPlugin, pluginName: "@4399ywkf/plugin-i18n" },
2056
- { key: "garfish", factory: garfishPlugin, pluginName: "@4399ywkf/plugin-garfish" },
2057
- { key: "browserCheck", factory: browserCheckPlugin, pluginName: "@4399ywkf/plugin-browser-check" }
2064
+ {
2065
+ key: "biome",
2066
+ factory: biomePlugin,
2067
+ pluginName: "@4399ywkf/plugin-biome"
2068
+ },
2069
+ {
2070
+ key: "analytics",
2071
+ factory: analyticsPlugin,
2072
+ pluginName: "@4399ywkf/plugin-analytics"
2073
+ },
2074
+ {
2075
+ key: "mock",
2076
+ factory: mockPlugin,
2077
+ pluginName: "@4399ywkf/plugin-mock"
2078
+ },
2079
+ {
2080
+ key: "theme",
2081
+ factory: themePlugin,
2082
+ pluginName: "@4399ywkf/plugin-theme"
2083
+ },
2084
+ {
2085
+ key: "i18n",
2086
+ factory: i18nPlugin,
2087
+ pluginName: "@4399ywkf/plugin-i18n"
2088
+ },
2089
+ {
2090
+ key: "garfish",
2091
+ factory: garfishPlugin,
2092
+ pluginName: "@4399ywkf/plugin-garfish"
2093
+ },
2094
+ {
2095
+ key: "browserCheck",
2096
+ factory: browserCheckPlugin,
2097
+ pluginName: "@4399ywkf/plugin-browser-check"
2098
+ }
2058
2099
  ];
2059
2100
  var ALL_SHORTHAND_KEYS = /* @__PURE__ */ new Set([
2060
2101
  ...BUILTIN_PLUGINS.map((p) => p.key),
@@ -2184,7 +2225,12 @@ var defaultConfig = {
2184
2225
  };
2185
2226
 
2186
2227
  // src/config/loader.ts
2187
- var CONFIG_FILES = ["ywkf.config.ts", "ywkf.config.mts", "ywkf.config.js", "ywkf.config.mjs"];
2228
+ var CONFIG_FILES = [
2229
+ "ywkf.config.ts",
2230
+ "ywkf.config.mts",
2231
+ "ywkf.config.js",
2232
+ "ywkf.config.mjs"
2233
+ ];
2188
2234
  function findConfigFile(cwd) {
2189
2235
  for (const file of CONFIG_FILES) {
2190
2236
  const configPath = resolve2(cwd, file);
@@ -2509,7 +2555,7 @@ function winPath(path) {
2509
2555
  if (isExtendedLengthPath) {
2510
2556
  return path;
2511
2557
  }
2512
- return path.replace(/\\/g, "/");
2558
+ return path.replaceAll("\\", "/");
2513
2559
  }
2514
2560
  var EXCLUDED_DIRS = /* @__PURE__ */ new Set([
2515
2561
  "components",
@@ -2645,16 +2691,16 @@ var ConventionalRouteGenerator = class {
2645
2691
  */
2646
2692
  resolveRoutePath(dirName, parentPath) {
2647
2693
  let segment;
2648
- if (dirName.match(/^\[\.\.\.(.+)\]$/)) {
2694
+ if (/^\[\.\.\..+\]$/.test(dirName)) {
2649
2695
  segment = "*";
2650
- } else if (dirName.match(/^\[(.+)\$\]$/)) {
2696
+ } else if (/^\[.+\$\]$/.test(dirName)) {
2651
2697
  const param = dirName.slice(1, -2);
2652
2698
  segment = `:${param}?`;
2653
- } else if (dirName.match(/^\[(.+)\]$/)) {
2699
+ } else if (/^\[.+\]$/.test(dirName)) {
2654
2700
  const param = dirName.slice(1, -1);
2655
2701
  segment = `:${param}`;
2656
2702
  } else if (dirName.includes(".")) {
2657
- segment = dirName.replace(/\./g, "/");
2703
+ segment = dirName.replaceAll(".", "/");
2658
2704
  } else {
2659
2705
  segment = dirName;
2660
2706
  }
@@ -2665,7 +2711,7 @@ var ConventionalRouteGenerator = class {
2665
2711
  */
2666
2712
  generateRouteName(path) {
2667
2713
  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, "");
2714
+ const cleaned = s.replaceAll(/[^a-z0-9]/gi, "");
2669
2715
  if (!cleaned) return "";
2670
2716
  return cleaned.charAt(0).toUpperCase() + cleaned.slice(1);
2671
2717
  }).join("");
@@ -2785,9 +2831,7 @@ export default routes;
2785
2831
  );
2786
2832
  }
2787
2833
  if (route.errorFile) {
2788
- errorImports.push(
2789
- `import ${name}Error from "@/pages/${toImportPath(route.errorFile)}";`
2790
- );
2834
+ errorImports.push(`import ${name}Error from "@/pages/${toImportPath(route.errorFile)}";`);
2791
2835
  }
2792
2836
  if (route.loadingFile) {
2793
2837
  loadingImports.push(
@@ -3298,7 +3342,7 @@ var YwkfGenerator = class {
3298
3342
  * 标准化内容(去掉时间戳等动态部分)
3299
3343
  */
3300
3344
  normalizeContent(content) {
3301
- return content.replace(/\/\/ Generated at: .+/g, "").replace(/\/\*\* Generated at: .+ \*\//g, "");
3345
+ return content.replaceAll(/\/\/ Generated at: .+/g, "").replaceAll(/\/\*\* Generated at: .+ \*\//g, "");
3302
3346
  }
3303
3347
  };
3304
3348
 
@@ -3518,7 +3562,16 @@ function resolveYwkfBuildId(appName) {
3518
3562
  function createBaseConfig(config, cwd, options = {}) {
3519
3563
  const isDev = options.isDev ?? process.env.NODE_ENV !== "production";
3520
3564
  const { resolveApp } = createPathResolver(cwd);
3521
- const { appName, appCName, output, html, alias: userAlias, microFrontend, router, reactCompiler } = config;
3565
+ const {
3566
+ appName,
3567
+ appCName,
3568
+ output,
3569
+ html,
3570
+ alias: userAlias,
3571
+ microFrontend,
3572
+ router,
3573
+ reactCompiler
3574
+ } = config;
3522
3575
  const buildId = resolveYwkfBuildId(appName);
3523
3576
  const { env: clientEnv, dropped: droppedEnvKeys } = buildClientEnv({ cwd, env: config.env });
3524
3577
  if (droppedEnvKeys.length > 0) {
@@ -3551,7 +3604,7 @@ function createBaseConfig(config, cwd, options = {}) {
3551
3604
  ...alias,
3552
3605
  "process/browser.js": require2.resolve("process/browser.js"),
3553
3606
  "process/browser": require2.resolve("process/browser.js"),
3554
- react: resolveApp("node_modules/react"),
3607
+ "react": resolveApp("node_modules/react"),
3555
3608
  "react-dom": resolveApp("node_modules/react-dom"),
3556
3609
  "react-router": resolveApp("node_modules/react-router")
3557
3610
  },
@@ -4403,9 +4456,10 @@ function registerShortcuts(getPrinter, opts) {
4403
4456
  const cmd = buffer.trim().toLowerCase();
4404
4457
  buffer = "";
4405
4458
  switch (cmd) {
4406
- case "h":
4459
+ case "h": {
4407
4460
  getPrinter().printShortcuts();
4408
4461
  break;
4462
+ }
4409
4463
  case "o": {
4410
4464
  const url = `http://${displayHost(opts.getHost())}:${opts.getPort()}/`;
4411
4465
  import("child_process").then((cp) => {
@@ -4415,12 +4469,14 @@ function registerShortcuts(getPrinter, opts) {
4415
4469
  console.log(` ${chalk.green("\u279C")} Opening ${chalk.cyan(url)}...`);
4416
4470
  break;
4417
4471
  }
4418
- case "c":
4472
+ case "c": {
4419
4473
  console.clear();
4420
4474
  break;
4421
- case "q":
4475
+ }
4476
+ case "q": {
4422
4477
  opts.onQuit();
4423
4478
  break;
4479
+ }
4424
4480
  }
4425
4481
  };
4426
4482
  process.stdin.on("data", handler);
@@ -4571,20 +4627,16 @@ async function findPortHolder(port) {
4571
4627
  const pid2 = parseWindowsNetstatPid(stdout2, port);
4572
4628
  return pid2 === null ? null : { pid: pid2 };
4573
4629
  }
4574
- const { stdout } = await execFileAsync(
4575
- "lsof",
4576
- ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"],
4577
- { timeout: 1500 }
4578
- );
4630
+ const { stdout } = await execFileAsync("lsof", ["-nP", `-iTCP:${port}`, "-sTCP:LISTEN", "-t"], {
4631
+ timeout: 1500
4632
+ });
4579
4633
  const pid = Number.parseInt(stdout.trim().split(/\s+/)[0], 10);
4580
4634
  if (!Number.isInteger(pid)) return null;
4581
4635
  let name;
4582
4636
  try {
4583
- const { stdout: comm } = await execFileAsync(
4584
- "ps",
4585
- ["-p", String(pid), "-o", "comm="],
4586
- { timeout: 1500 }
4587
- );
4637
+ const { stdout: comm } = await execFileAsync("ps", ["-p", String(pid), "-o", "comm="], {
4638
+ timeout: 1500
4639
+ });
4588
4640
  name = comm.trim().split("/").pop() || void 0;
4589
4641
  } catch {
4590
4642
  }
@@ -4731,7 +4783,7 @@ async function startDevServer(cwd, config) {
4731
4783
  printer.updateProgress(0, "rebuilding");
4732
4784
  });
4733
4785
  const devServerOptions = {
4734
- ...rspackConfig.devServer || {},
4786
+ ...rspackConfig.devServer,
4735
4787
  host,
4736
4788
  port,
4737
4789
  setupExitSignals: false