@4399ywkf/core 5.1.5 → 5.1.6

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/cli/index.js CHANGED
@@ -2743,12 +2743,13 @@ function LazyRoute({
2743
2743
 
2744
2744
  import React, { lazy, Suspense } from "react";
2745
2745
  import { createBrowserRouter, type RouteObject } from "react-router";
2746
+ import { RouteErrorBoundary } from "@4399ywkf/core/runtime";
2747
+ ${errorImports.length > 0 ? `
2748
+ // \u540C\u6B65\u9519\u8BEF\u8FB9\u754C\u7EC4\u4EF6
2749
+ ${errorImports.join("\n")}` : ""}
2746
2750
 
2747
2751
  // \u61D2\u52A0\u8F7D\u9875\u9762\u7EC4\u4EF6
2748
2752
  ${lazyImports.join("\n")}
2749
- ${errorImports.length > 0 ? `
2750
- // \u9519\u8BEF\u8FB9\u754C\u7EC4\u4EF6
2751
- ${errorImports.join("\n")}` : ""}
2752
2753
  ${loadingImports.length > 0 ? `
2753
2754
  // \u52A0\u8F7D\u72B6\u6001\u7EC4\u4EF6
2754
2755
  ${loadingImports.join("\n")}` : ""}
@@ -2783,7 +2784,7 @@ export default routes;
2783
2784
  }
2784
2785
  if (route.errorFile) {
2785
2786
  errorImports.push(
2786
- `const ${name}Error = lazy(() => import("@/pages/${toImportPath(route.errorFile)}"));`
2787
+ `import ${name}Error from "@/pages/${toImportPath(route.errorFile)}";`
2787
2788
  );
2788
2789
  }
2789
2790
  if (route.loadingFile) {
@@ -2798,13 +2799,13 @@ export default routes;
2798
2799
  }
2799
2800
  }
2800
2801
  }
2801
- emitRouteArray(routes, parentPath) {
2802
- const items = routes.map((r) => this.emitRouteObject(r, parentPath));
2802
+ emitRouteArray(routes, parentPath, depth = 0) {
2803
+ const items = routes.map((r) => this.emitRouteObject(r, parentPath, depth));
2803
2804
  return `[
2804
2805
  ${items.join(",\n ")}
2805
2806
  ]`;
2806
2807
  }
2807
- emitRouteObject(route, parentPath) {
2808
+ emitRouteObject(route, parentPath, depth) {
2808
2809
  const parts = [];
2809
2810
  const name = route.name;
2810
2811
  if (route.index) {
@@ -2825,11 +2826,13 @@ export default routes;
2825
2826
  parts.push(`element: <LazyRoute Component={${name}Page} />`);
2826
2827
  }
2827
2828
  if (route.errorFile) {
2828
- parts.push(`errorElement: <LazyRoute Component={${name}Error} />`);
2829
+ parts.push(`errorElement: <RouteErrorBoundary fallback={<${name}Error />} />`);
2830
+ } else if (depth === 0) {
2831
+ parts.push(`errorElement: <RouteErrorBoundary />`);
2829
2832
  }
2830
2833
  if (route.children && route.children.length > 0) {
2831
2834
  const childParent = route.pathless ? parentPath : route.path;
2832
- parts.push(`children: ${this.emitRouteArray(route.children, childParent)}`);
2835
+ parts.push(`children: ${this.emitRouteArray(route.children, childParent, depth + 1)}`);
2833
2836
  }
2834
2837
  return `{
2835
2838
  ${parts.join(",\n ")}
@@ -3438,10 +3441,20 @@ var YwkfGeneratorPlugin = class {
3438
3441
  var require2 = createRequire(import.meta.url);
3439
3442
  var __dirname = dirname(fileURLToPath(import.meta.url));
3440
3443
  var coreNodeModules = join12(__dirname, "../../node_modules");
3444
+ function resolveYwkfBuildId(appName) {
3445
+ const releaseId = [
3446
+ process.env.YWKF_BUILD_ID,
3447
+ process.env.CI_COMMIT_SHA,
3448
+ process.env.GITHUB_SHA,
3449
+ process.env.GIT_COMMIT
3450
+ ].find((value) => value?.trim())?.trim();
3451
+ return `${appName}:${releaseId || Date.now().toString(36)}`;
3452
+ }
3441
3453
  function createBaseConfig(config, cwd, options = {}) {
3442
3454
  const isDev = options.isDev ?? process.env.NODE_ENV !== "production";
3443
3455
  const { resolveApp } = createPathResolver(cwd);
3444
3456
  const { appName, appCName, output, html, alias: userAlias, microFrontend, router, reactCompiler } = config;
3457
+ const buildId = resolveYwkfBuildId(appName);
3445
3458
  const ywkfOutputDir = resolveApp(".ywkf");
3446
3459
  const defaultAlias = {
3447
3460
  "@": resolveApp("src"),
@@ -3565,6 +3578,7 @@ function createBaseConfig(config, cwd, options = {}) {
3565
3578
  Buffer: ["buffer", "Buffer"]
3566
3579
  }),
3567
3580
  new rspack2.DefinePlugin({
3581
+ "globalThis.__YWKF_BUILD_ID__": JSON.stringify(buildId),
3568
3582
  "process.env": JSON.stringify(process.env)
3569
3583
  }),
3570
3584
  new rspack2.HtmlRspackPlugin({