@umijs/preset-umi 4.0.83 → 4.0.85

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.
@@ -129,5 +129,3 @@ var configPlugins_default = (api) => {
129
129
  return memo;
130
130
  });
131
131
  };
132
- // Annotate the CommonJS export names for ESM import in node:
133
- 0 && (module.exports = {});
@@ -93,5 +93,3 @@ var devTool_default = (api) => {
93
93
  ];
94
94
  });
95
95
  };
96
- // Annotate the CommonJS export names for ESM import in node:
97
- 0 && (module.exports = {});
@@ -220,5 +220,3 @@ export function modifyClientRenderOpts(memo: any) {
220
220
  return [`@@/core/exportStaticRuntimePlugin.ts`];
221
221
  });
222
222
  };
223
- // Annotate the CommonJS export names for ESM import in node:
224
- 0 && (module.exports = {});
@@ -46,7 +46,7 @@ var overrides_default = (api) => {
46
46
  if (selector === "html") {
47
47
  return `html:first-child`;
48
48
  } else if (/^body([\s+~>[:]|$)/.test(selector)) {
49
- return `* + ${selector}`;
49
+ return `html ${selector}`;
50
50
  }
51
51
  return prefixedSelector;
52
52
  }
@@ -144,8 +144,9 @@ export function useServerInsertedHTML(callback: () => React.ReactNode): void {
144
144
  (0, import_fs.writeFileSync)(
145
145
  (0, import_path.join)(api.cwd, "api/umi.server.js"),
146
146
  `
147
+ const manifest = require('../server/build-manifest.json');
147
148
  export default function handler(request, response) {
148
- require('../server/umi.server.js').default(request, response);
149
+ require(manifest.assets["umi.js"]).default(request, response);
149
150
  }
150
151
  `.trimStart(),
151
152
  "utf-8"
@@ -153,6 +154,9 @@ export default function handler(request, response) {
153
154
  import_utils.logger.info(`[SSR] write api/umi.server.js`);
154
155
  }
155
156
  });
157
+ api.onBuildHtmlComplete(() => {
158
+ import_utils.fsExtra.copyFileSync((0, import_path.join)(api.paths.absOutputPath, "index.html"), (0, import_path.join)(api.paths.absOutputPath, "*.html"));
159
+ });
156
160
  const pluginName = "ProcessAssetsPlugin";
157
161
  class ProcessAssetsPlugin {
158
162
  apply(compiler) {
@@ -187,5 +191,3 @@ export default function handler(request, response) {
187
191
  return config;
188
192
  });
189
193
  };
190
- // Annotate the CommonJS export names for ESM import in node:
191
- 0 && (module.exports = {});
@@ -23,6 +23,7 @@ __export(utils_exports, {
23
23
  esbuildUmiPlugin: () => esbuildUmiPlugin
24
24
  });
25
25
  module.exports = __toCommonJS(utils_exports);
26
+ var import_fs = require("fs");
26
27
  var import_path = require("path");
27
28
  function esbuildUmiPlugin(api) {
28
29
  return {
@@ -41,10 +42,16 @@ function absServerBuildPath(api) {
41
42
  if (api.env === "development") {
42
43
  return (0, import_path.join)(api.paths.absTmpPath, "server/umi.server.js");
43
44
  }
44
- return (0, import_path.join)(
45
- api.paths.cwd,
46
- api.userConfig.ssr.serverBuildPath || "server/umi.server.js"
47
- );
45
+ const manifestPath = (0, import_path.join)(api.paths.cwd, "server", "build-manifest.json");
46
+ if (api.userConfig.ssr.serverBuildPath || !(0, import_fs.existsSync)(manifestPath)) {
47
+ return (0, import_path.join)(
48
+ api.paths.cwd,
49
+ api.userConfig.ssr.serverBuildPath || "server/umi.server.js"
50
+ );
51
+ }
52
+ delete require.cache[manifestPath];
53
+ const manifest = require(manifestPath);
54
+ return (0, import_path.join)(api.paths.cwd, "server", (0, import_path.basename)(manifest.assets["umi.js"]));
48
55
  }
49
56
  // Annotate the CommonJS export names for ESM import in node:
50
57
  0 && (module.exports = {
@@ -36,11 +36,13 @@ var bundlerWebpack = __toESM(require("@umijs/bundler-webpack"));
36
36
  var import_utils = require("@umijs/utils");
37
37
  var import_path = require("path");
38
38
  var import_utils2 = require("../utils");
39
+ var import_types = require("@umijs/bundler-webpack/dist/types");
39
40
  var build2 = async (api, opts) => {
40
41
  import_utils.logger.wait("[SSR] Compiling...");
41
- const now = new Date().getTime();
42
+ const now = (/* @__PURE__ */ new Date()).getTime();
42
43
  const bundlerOpts = import_utils.lodash.cloneDeep(opts);
43
44
  const oChainWebpack = bundlerOpts.chainWebpack;
45
+ const useHash = api.config.hash && api.env === import_types.Env.production;
44
46
  delete bundlerOpts.config.deadCode;
45
47
  bundlerOpts.extraBabelPlugins.push([
46
48
  require.resolve("babel-plugin-dynamic-import-node"),
@@ -57,13 +59,15 @@ var build2 = async (api, opts) => {
57
59
  memo.target("node");
58
60
  memo.name("umi");
59
61
  memo.devtool(false);
60
- memo.output.path((0, import_path.dirname)(absOutputFile)).filename("umi.server.js").chunkFilename("[name].server.js").libraryTarget("commonjs2");
62
+ memo.output.path((0, import_path.dirname)(absOutputFile)).filename(useHash ? "umi.[contenthash:8].server.js" : "umi.server.js").chunkFilename(
63
+ useHash ? "umi.[contenthash:8].server.js" : "umi.server.js"
64
+ ).libraryTarget("commonjs2");
61
65
  memo.plugins.delete("progress-plugin");
62
66
  memo.optimization.minimize(false);
63
67
  return memo;
64
68
  };
65
69
  await bundlerWebpack.build(bundlerOpts);
66
- const diff = new Date().getTime() - now;
70
+ const diff = (/* @__PURE__ */ new Date()).getTime() - now;
67
71
  import_utils.logger.info(`[SSR] Compiled in ${diff}ms`);
68
72
  };
69
73
  // Annotate the CommonJS export names for ESM import in node:
@@ -94,10 +94,43 @@ async function getRoutes(opts) {
94
94
  return path;
95
95
  }
96
96
  }
97
+ const absLayoutPath = ((_c = opts.api.config) == null ? void 0 : _c.conventionLayout) === false ? false : (0, import_utils.tryPaths)([
98
+ (0, import_path.join)(opts.api.paths.absSrcPath, "layouts/index.tsx"),
99
+ (0, import_path.join)(opts.api.paths.absSrcPath, "layouts/index.vue"),
100
+ (0, import_path.join)(opts.api.paths.absSrcPath, "layouts/index.jsx"),
101
+ (0, import_path.join)(opts.api.paths.absSrcPath, "layouts/index.js")
102
+ ]);
103
+ const layouts = await opts.api.applyPlugins({
104
+ key: "addLayouts",
105
+ initialValue: [
106
+ absLayoutPath && {
107
+ id: "@@/global-layout",
108
+ file: (0, import_utils.winPath)(absLayoutPath),
109
+ test(route) {
110
+ return route.layout !== false;
111
+ }
112
+ }
113
+ ].filter(Boolean)
114
+ });
115
+ for (const layout of layouts) {
116
+ (0, import_core.addParentRoute)({
117
+ addToAll: true,
118
+ target: {
119
+ id: layout.id,
120
+ path: "/",
121
+ file: layout.file,
122
+ parentId: void 0,
123
+ absPath: "/",
124
+ isLayout: true
125
+ },
126
+ routes,
127
+ test: layout.test
128
+ });
129
+ }
97
130
  for (const id of Object.keys(routes)) {
98
131
  if (routes[id].file) {
99
132
  let file = routes[id].file;
100
- const basedir = ((_c = opts.api.config.conventionRoutes) == null ? void 0 : _c.base) || opts.api.paths.absPagesPath;
133
+ const basedir = ((_d = opts.api.config.conventionRoutes) == null ? void 0 : _d.base) || opts.api.paths.absPagesPath;
101
134
  if (!(0, import_path.isAbsolute)(file)) {
102
135
  if (file.startsWith("@/")) {
103
136
  file = file.replace("@/", "../");
@@ -108,9 +141,11 @@ async function getRoutes(opts) {
108
141
  });
109
142
  }
110
143
  const isJSFile = /.[jt]sx?$/.test(file);
111
- routes[id].__content = (0, import_fs.readFileSync)(file, "utf-8");
144
+ if (!routes[id].isLayout) {
145
+ routes[id].__content = (0, import_fs.readFileSync)(file, "utf-8");
146
+ routes[id].__isJSFile = isJSFile;
147
+ }
112
148
  routes[id].__absFile = (0, import_utils.winPath)(file);
113
- routes[id].__isJSFile = isJSFile;
114
149
  const enableSSR = opts.api.config.ssr;
115
150
  const enableClientLoader = opts.api.config.clientLoader;
116
151
  const enableRouteProps = !opts.api.userConfig.routes;
@@ -131,39 +166,6 @@ async function getRoutes(opts) {
131
166
  }
132
167
  }
133
168
  }
134
- const absLayoutPath = ((_d = opts.api.config) == null ? void 0 : _d.conventionLayout) === false ? false : (0, import_utils.tryPaths)([
135
- (0, import_path.join)(opts.api.paths.absSrcPath, "layouts/index.tsx"),
136
- (0, import_path.join)(opts.api.paths.absSrcPath, "layouts/index.vue"),
137
- (0, import_path.join)(opts.api.paths.absSrcPath, "layouts/index.jsx"),
138
- (0, import_path.join)(opts.api.paths.absSrcPath, "layouts/index.js")
139
- ]);
140
- const layouts = await opts.api.applyPlugins({
141
- key: "addLayouts",
142
- initialValue: [
143
- absLayoutPath && {
144
- id: "@@/global-layout",
145
- file: (0, import_utils.winPath)(absLayoutPath),
146
- test(route) {
147
- return route.layout !== false;
148
- }
149
- }
150
- ].filter(Boolean)
151
- });
152
- for (const layout of layouts) {
153
- (0, import_core.addParentRoute)({
154
- addToAll: true,
155
- target: {
156
- id: layout.id,
157
- path: "/",
158
- file: layout.file,
159
- parentId: void 0,
160
- absPath: "/",
161
- isLayout: true
162
- },
163
- routes,
164
- test: layout.test
165
- });
166
- }
167
169
  for (const id of Object.keys(routes)) {
168
170
  await opts.api.applyPlugins({
169
171
  key: "onPatchRoute",
@@ -249,7 +251,7 @@ function componentToChunkName(component, cwd = "/") {
249
251
  import_utils.lodash.escapeRegExp(lastSlash(getProjectRootCwd(cwd)))})`
250
252
  ),
251
253
  ""
252
- ).replace(/^.(\/|\\)/, "").replace(/(\/|\\)/g, "__").replace(/@/g, "_").replace(/\.jsx?$/, "").replace(/\.tsx?$/, "").replace(/\.vue?$/, "").replace(/^src__/, "").replace(/\.\.__/g, "").replace(/[\[\]]/g, "").replace(/^node_modules__/, "nm__").replace(/^.umi-production__/, "t__").replace(/^\./, "").replace(/^pages__/, "p__") : "";
254
+ ).replace(/.+(node_modules(\/|\\))/, "$1").replace(/(\/|\\)_@?([^@]+@){2}/, "$1").replace(/^.(\/|\\)/, "").replace(/(\/|\\)/g, "__").replace(/@/g, "_").replace(/\.jsx?$/, "").replace(/\.tsx?$/, "").replace(/\.vue?$/, "").replace(/^src__/, "").replace(/\.\.__/g, "").replace(/[\[\]]/g, "").replace(/^node_modules__/, "nm__").replace(/^.umi-production__/, "t__").replace(/^\./, "").replace(/^pages__/, "p__") : "";
253
255
  }
254
256
  // Annotate the CommonJS export names for ESM import in node:
255
257
  0 && (module.exports = {
@@ -407,6 +407,22 @@ if (process.env.NODE_ENV === 'development') {
407
407
  key: "addRuntimePlugin",
408
408
  initialValue: [(_c = api.appData.appJS) == null ? void 0 : _c.path].filter(Boolean)
409
409
  });
410
+ function checkDuplicatePluginKeys(arr) {
411
+ const duplicates = [];
412
+ arr.reduce((prev, curr) => {
413
+ if (prev[curr]) {
414
+ duplicates.push(curr);
415
+ } else {
416
+ prev[curr] = true;
417
+ }
418
+ return prev;
419
+ }, {});
420
+ if (duplicates.length) {
421
+ throw new Error(
422
+ `The plugin key cannot be duplicated. (${duplicates.join(", ")})`
423
+ );
424
+ }
425
+ }
410
426
  const validKeys = await api.applyPlugins({
411
427
  key: "addRuntimePluginKey",
412
428
  initialValue: [
@@ -424,6 +440,7 @@ if (process.env.NODE_ENV === 'development') {
424
440
  "onRouteChange"
425
441
  ]
426
442
  });
443
+ checkDuplicatePluginKeys(validKeys);
427
444
  const appPluginRegExp = /(\/|\\)app.(ts|tsx|jsx|js)$/;
428
445
  api.writeTmpFile({
429
446
  noPluginDir: true,
@@ -654,5 +671,3 @@ if (process.env.NODE_ENV === 'development') {
654
671
  stage: 1e4
655
672
  });
656
673
  };
657
- // Annotate the CommonJS export names for ESM import in node:
658
- 0 && (module.exports = {});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.0.83",
3
+ "version": "4.0.85",
4
4
  "description": "@umijs/preset-umi",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/preset-umi#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -37,21 +37,21 @@
37
37
  "react-router": "6.3.0",
38
38
  "react-router-dom": "6.3.0",
39
39
  "regenerator-runtime": "0.13.11",
40
- "@umijs/ast": "4.0.83",
41
- "@umijs/bundler-webpack": "4.0.83",
42
- "@umijs/bundler-esbuild": "4.0.83",
43
- "@umijs/babel-preset-umi": "4.0.83",
44
- "@umijs/bundler-vite": "4.0.83",
45
- "@umijs/bundler-utils": "4.0.83",
46
- "@umijs/mfsu": "4.0.83",
47
- "@umijs/did-you-know": "1.0.3",
48
- "@umijs/plugin-run": "4.0.83",
49
- "@umijs/renderer-react": "4.0.83",
50
- "@umijs/server": "4.0.83",
51
- "@umijs/core": "4.0.83",
52
- "@umijs/zod2ts": "4.0.83",
40
+ "@umijs/ast": "4.0.85",
41
+ "@umijs/bundler-vite": "4.0.85",
42
+ "@umijs/bundler-utils": "4.0.85",
43
+ "@umijs/bundler-webpack": "4.0.85",
44
+ "@umijs/babel-preset-umi": "4.0.85",
45
+ "@umijs/mfsu": "4.0.85",
46
+ "@umijs/core": "4.0.85",
47
+ "@umijs/bundler-esbuild": "4.0.85",
48
+ "@umijs/plugin-run": "4.0.85",
49
+ "@umijs/server": "4.0.85",
50
+ "@umijs/renderer-react": "4.0.85",
53
51
  "@umijs/ui": "3.0.1",
54
- "@umijs/utils": "4.0.83"
52
+ "@umijs/utils": "4.0.85",
53
+ "@umijs/zod2ts": "4.0.85",
54
+ "@umijs/did-you-know": "1.0.3"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@manypkg/get-packages": "1.1.3",
@@ -4,7 +4,7 @@ import { createHistory as createClientHistory } from './core/history';
4
4
  import { getPlugins as getClientPlugins } from './core/plugin';
5
5
  import { ServerInsertedHTMLContext } from './core/serverInsertedHTMLContext';
6
6
  import { PluginManager } from '{{{ umiPluginPath }}}';
7
- import createRequestHandler, { createMarkupGenerator } from '{{{ umiServerPath }}}';
7
+ import createRequestHandler, { createMarkupGenerator, createUmiHandler, createUmiServerLoader } from '{{{ umiServerPath }}}';
8
8
 
9
9
  let helmetContext;
10
10
 
@@ -26,8 +26,9 @@ export function getValidKeys() {
26
26
  return [{{#validKeys}}'{{{ . }}}',{{/validKeys}}];
27
27
  }
28
28
 
29
- export function getManifest() {
30
- return JSON.parse(require('fs').readFileSync('{{{ assetsPath }}}', 'utf-8'));
29
+ export function getManifest(sourceDir) {
30
+ return JSON.parse(require('fs').readFileSync(
31
+ sourceDir ? require('path').join(sourceDir,'build-manifest.json') : '{{{ assetsPath }}}', 'utf-8'));
31
32
  }
32
33
 
33
34
  export function createHistory(opts) {
@@ -36,24 +37,24 @@ export function createHistory(opts) {
36
37
 
37
38
  // TODO: remove global variable
38
39
  global.g_getAssets = (fileName) => {
39
- let m = typeof manifest === 'function' ? manifest() : manifest;
40
+ let m = getManifest();
40
41
  return m.assets[fileName];
41
42
  };
42
-
43
- const manifest = {{{ env }}} === 'development' ? getManifest : getManifest();
44
43
  const createOpts = {
45
44
  routesWithServerLoader,
46
45
  PluginManager,
47
46
  getPlugins,
48
47
  getValidKeys,
49
48
  getRoutes,
50
- manifest,
49
+ manifest: getManifest,
51
50
  getClientRootComponent,
52
51
  helmetContext,
53
52
  createHistory,
54
53
  ServerInsertedHTMLContext,
55
54
  };
56
55
  const requestHandler = createRequestHandler(createOpts);
56
+ export const renderRoot = createUmiHandler(createOpts);
57
+ export const serverLoader = createUmiServerLoader(createOpts);
57
58
 
58
59
  export const _markupGenerator = createMarkupGenerator(createOpts);
59
60