@umijs/preset-umi 4.0.32 → 4.0.34

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.
@@ -120,7 +120,8 @@ umi build --clean
120
120
  args: opts2
121
121
  });
122
122
  },
123
- clean: true
123
+ clean: true,
124
+ htmlFiles: []
124
125
  };
125
126
  await api.applyPlugins({
126
127
  key: "onBeforeCompiler",
@@ -141,6 +142,7 @@ umi build --clean
141
142
  buildFolder: absOutputPath
142
143
  });
143
144
  }
145
+ let htmlFiles = [];
144
146
  if (!api.config.mpa) {
145
147
  const assetsMap = api.config.vite ? {} : (0, import_getAssetsMap.getAssetsMap)({
146
148
  stats,
@@ -161,7 +163,7 @@ umi build --clean
161
163
  esmScript: !!opts.config.esm || vite,
162
164
  path: "/"
163
165
  };
164
- const htmlFiles = await api.applyPlugins({
166
+ htmlFiles = await api.applyPlugins({
165
167
  key: "modifyExportHTMLFiles",
166
168
  initialValue: [
167
169
  {
@@ -180,7 +182,10 @@ umi build --clean
180
182
  }
181
183
  await api.applyPlugins({
182
184
  key: "onBuildHtmlComplete",
183
- args: opts
185
+ args: {
186
+ ...opts,
187
+ htmlFiles
188
+ }
184
189
  });
185
190
  }
186
191
  });
@@ -1,2 +1,2 @@
1
1
  import { IApi } from '../../types';
2
- export declare function set(api: IApi, name: string, value: any): void;
2
+ export declare function set(api: IApi, name: string, value: string): void;
@@ -35,22 +35,22 @@ function getAssetsMap(opts) {
35
35
  const { stats, publicPath } = opts;
36
36
  const displayPublicPath = publicPath === "auto" ? "/" : publicPath;
37
37
  let ret = {};
38
- let json = stats.toJson();
39
- const entrypoints = json.entrypoints || json.children[0].entrypoints;
40
- for (const asset of entrypoints["umi"].assets) {
41
- if (!asset.name.includes(HOT_UPDATE)) {
42
- if (UMI_ASSETS_REG.js.test(asset.name)) {
43
- ret["umi.js"] = [`${displayPublicPath}${asset.name}`];
38
+ const realStats = stats.stats ? stats.stats[0] : stats;
39
+ const assets = Object.keys(realStats.compilation.assets);
40
+ for (const asset of assets) {
41
+ if (!asset.includes(HOT_UPDATE)) {
42
+ if (UMI_ASSETS_REG.js.test(asset)) {
43
+ ret["umi.js"] = [`${displayPublicPath}${asset}`];
44
44
  }
45
- if (FRAMEWORK_ASSETS_REG.js.test(asset.name)) {
46
- ret["framework.js"] = [`${displayPublicPath}${asset.name}`];
45
+ if (FRAMEWORK_ASSETS_REG.js.test(asset)) {
46
+ ret["framework.js"] = [`${displayPublicPath}${asset}`];
47
47
  }
48
48
  }
49
- if (UMI_ASSETS_REG.css.test(asset.name)) {
50
- ret["umi.css"] = [`${displayPublicPath}${asset.name}`];
49
+ if (UMI_ASSETS_REG.css.test(asset)) {
50
+ ret["umi.css"] = [`${displayPublicPath}${asset}`];
51
51
  }
52
- if (FRAMEWORK_ASSETS_REG.css.test(asset.name)) {
53
- ret["framework.css"] = [`${displayPublicPath}${asset.name}`];
52
+ if (FRAMEWORK_ASSETS_REG.css.test(asset)) {
53
+ ret["framework.css"] = [`${displayPublicPath}${asset}`];
54
54
  }
55
55
  }
56
56
  return ret;
@@ -80,7 +80,9 @@ var precommit_default = (api) => {
80
80
  npx --no-install ${cliName} verify-commit $1
81
81
  `.trimStart());
82
82
  import_utils.logger.info("Write commit-msg");
83
- import_utils.execa.execaCommandSync("chmod +x .husky/commit-msg");
83
+ if (process.platform !== "win32") {
84
+ import_utils.execa.execaCommandSync("chmod +x .husky/commit-msg");
85
+ }
84
86
  }
85
87
  if (!(0, import_fs.existsSync)((0, import_path.join)(api.cwd, ".husky/pre-commit"))) {
86
88
  (0, import_fs.writeFileSync)((0, import_path.join)(api.cwd, ".husky/pre-commit"), `
@@ -90,7 +92,9 @@ npx --no-install ${cliName} verify-commit $1
90
92
  npx --no-install lint-staged --quiet
91
93
  `.trimStart());
92
94
  import_utils.logger.info("Write pre-commit");
93
- import_utils.execa.execaCommandSync("chmod +x .husky/pre-commit");
95
+ if (process.platform !== "win32") {
96
+ import_utils.execa.execaCommandSync("chmod +x .husky/pre-commit");
97
+ }
94
98
  }
95
99
  h.installDeps();
96
100
  }
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import type { IncomingMessage } from 'http';
3
4
  import type { IRoute } from '../../types';
4
5
  declare class UmiApiRequest {
@@ -99,12 +99,13 @@ var codeSplitting_default = (api) => {
99
99
  },
100
100
  lib: {
101
101
  test(module2) {
102
- return module2.size() > 16e4 && /node_modules[/\\]/.test(module2.identifier());
102
+ return !isModuleCSS(module2) && module2.size() > 16e4 && /node_modules[/\\]/.test(module2.identifier());
103
103
  },
104
104
  name(module2) {
105
105
  const rawRequest = module2.rawRequest && module2.rawRequest.replace(/^@(\w+)[/\\]/, "$1-");
106
- if (rawRequest)
107
- return `${rawRequest}-lib`;
106
+ if (rawRequest) {
107
+ return `${rawRequest.replace(/\./g, "_").replace(/\//g, "-")}-lib`;
108
+ }
108
109
  const identifier = module2.identifier();
109
110
  const trimmedIdentifier = /(?:^|[/\\])node_modules[/\\](.*)/.exec(identifier);
110
111
  const processedIdentifier = trimmedIdentifier && trimmedIdentifier[1].replace(/^@(\w+)[/\\]/, "$1-");
@@ -119,7 +120,7 @@ var codeSplitting_default = (api) => {
119
120
  name(_module, chunks) {
120
121
  const cryptoName = import_crypto.default.createHash("sha1").update(chunks.reduce((acc, chunk) => {
121
122
  return acc + chunk.name;
122
- }, "")).digest("base64").replace(/\//g, "");
123
+ }, "")).digest("base64").replace(/\//g, "").replace(/\+/g, "-").replace(/=/g, "_");
123
124
  return `shared-${cryptoName}`;
124
125
  },
125
126
  chunks: "async",
@@ -136,5 +137,8 @@ var codeSplitting_default = (api) => {
136
137
  return memo;
137
138
  });
138
139
  };
140
+ function isModuleCSS(module2) {
141
+ return module2.type === `css/mini-extract` || module2.type === `css/extract-chunks` || module2.type === `css/extract-css-chunks`;
142
+ }
139
143
  // Annotate the CommonJS export names for ESM import in node:
140
144
  0 && (module.exports = {});
@@ -25,7 +25,7 @@ module.exports = __toCommonJS(schema_exports);
25
25
  var import_utils = require("@umijs/utils");
26
26
  function getSchemas() {
27
27
  return {
28
- base: (Joi) => Joi.string().label("base").pattern(/\/$/, { name: `"endsWith '/'"` }),
28
+ base: (Joi) => Joi.string(),
29
29
  conventionRoutes: (Joi) => Joi.object({
30
30
  base: Joi.string(),
31
31
  exclude: Joi.array().items(Joi.any())
@@ -54,7 +54,7 @@ var favicons_default = (api) => {
54
54
  });
55
55
  api.addBeforeMiddlewares(() => [
56
56
  (req, res, next) => {
57
- const iconFile = (api.appData.faviconFiles || []).find((file) => req.path === `/${file}`);
57
+ const iconFile = (api.appData.faviconFiles || []).find((file) => req.path === `${api.config.publicPath}${file}`);
58
58
  if (!iconFile) {
59
59
  next();
60
60
  } else {
@@ -1,3 +1,7 @@
1
1
  import type { IApi } from '../../types';
2
2
  declare const _default: (api: IApi) => void;
3
3
  export default _default;
4
+ interface IOpts {
5
+ root: string;
6
+ }
7
+ export declare function isMonorepo(opts: IOpts): any;
@@ -22,7 +22,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/features/monorepo/redirect.ts
23
23
  var redirect_exports = {};
24
24
  __export(redirect_exports, {
25
- default: () => redirect_default
25
+ default: () => redirect_default,
26
+ isMonorepo: () => isMonorepo
26
27
  });
27
28
  module.exports = __toCommonJS(redirect_exports);
28
29
  var import_utils = require("@umijs/utils");
@@ -118,4 +119,6 @@ function isMonorepo(opts) {
118
119
  }) || (pkg == null ? void 0 : pkg.workspaces));
119
120
  }
120
121
  // Annotate the CommonJS export names for ESM import in node:
121
- 0 && (module.exports = {});
122
+ 0 && (module.exports = {
123
+ isMonorepo
124
+ });
@@ -65,7 +65,9 @@ export {};
65
65
  ],
66
66
  plugins: [
67
67
  require.resolve("@umijs/babel-preset-umi/dist/plugins/lockCoreJS")
68
- ]
68
+ ],
69
+ babelrc: false,
70
+ configFile: false
69
71
  });
70
72
  api.writeTmpFile({
71
73
  path: "core/polyfill.ts",
@@ -37,6 +37,9 @@ var test_default = (api) => {
37
37
  schema(Joi) {
38
38
  return Joi.object();
39
39
  }
40
+ },
41
+ enableBy() {
42
+ return api.appData.framework === "react";
40
43
  }
41
44
  });
42
45
  api.onGenerateFiles(async () => {
@@ -29,6 +29,7 @@ var import_core = require("@umijs/core");
29
29
  var import_utils = require("@umijs/utils");
30
30
  var import_fs = require("fs");
31
31
  var import_path = require("path");
32
+ var import_redirect = require("../monorepo/redirect");
32
33
  var import_getModuleExports = require("./getModuleExports");
33
34
  async function getApiRoutes(opts) {
34
35
  const routes = (0, import_core.getConventionRoutes)({
@@ -199,8 +200,21 @@ ${imports}
199
200
  function lastSlash(str) {
200
201
  return str[str.length - 1] === "/" ? str : `${str}/`;
201
202
  }
202
- function componentToChunkName(component, cwd) {
203
- return typeof component === "string" ? component.replace(new RegExp(`^${import_utils.lodash.escapeRegExp(lastSlash((0, import_utils.winPath)(cwd || "/")))}`), "").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__") : "";
203
+ function getProjectRootCwd(cwd) {
204
+ const splittedCwd = cwd.split("/");
205
+ for (let level = -1; level >= -3; level -= 1) {
206
+ const rootCwd = splittedCwd.slice(0, level).join("/");
207
+ if (!rootCwd)
208
+ break;
209
+ if ((0, import_redirect.isMonorepo)({ root: rootCwd })) {
210
+ return rootCwd;
211
+ }
212
+ }
213
+ return cwd;
214
+ }
215
+ function componentToChunkName(component, cwd = "/") {
216
+ cwd = (0, import_utils.winPath)(cwd);
217
+ return typeof component === "string" ? component.replace(new RegExp(`^(${import_utils.lodash.escapeRegExp(lastSlash(cwd))}|${import_utils.lodash.escapeRegExp(lastSlash(getProjectRootCwd(cwd)))})`), "").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__") : "";
204
218
  }
205
219
  // Annotate the CommonJS export names for ESM import in node:
206
220
  0 && (module.exports = {
@@ -337,6 +337,7 @@ export default function EmptyRoute() {
337
337
  "patchRoutes",
338
338
  "patchClientRoutes",
339
339
  "modifyContextOpts",
340
+ "modifyClientRenderOpts",
340
341
  "rootContainer",
341
342
  "innerProvider",
342
343
  "i18nProvider",
@@ -452,8 +453,10 @@ export default function EmptyRoute() {
452
453
  path: "@@/core/terminal.ts"
453
454
  });
454
455
  }
455
- if (process.env.NODE_ENV === "test" || process.env.NODE_ENV === "development") {
456
- exports.push(`export { TestBrowser } from './testBrowser';`);
456
+ if (api.appData.framework === "react") {
457
+ if (process.env.NODE_ENV === "test" || process.env.NODE_ENV === "development") {
458
+ exports.push(`export { TestBrowser } from './testBrowser';`);
459
+ }
457
460
  }
458
461
  exports.push("// plugins");
459
462
  const allPlugins = (0, import_fs.readdirSync)(api.paths.absTmpPath).filter((file) => file.startsWith("plugin-"));
@@ -163,7 +163,8 @@ async function esbuildTransform(files, opts) {
163
163
  ".js": "tsx",
164
164
  ".jsx": "tsx"
165
165
  },
166
- logLevel: "error"
166
+ logLevel: "error",
167
+ tsconfig: (0, import_path.join)(__dirname, "empty.tsconfig.json")
167
168
  });
168
169
  } catch (e) {
169
170
  if (((_a = e.errors) == null ? void 0 : _a.length) || ((_b = e.warnings) == null ? void 0 : _b.length)) {
package/dist/types.d.ts CHANGED
@@ -42,7 +42,7 @@ export declare type ILink = Partial<{
42
42
  }>;
43
43
  export declare type IMeta = Partial<{
44
44
  content: string;
45
- httpEquiv: string;
45
+ 'http-equiv': string;
46
46
  name: string;
47
47
  scheme: string;
48
48
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.0.32",
3
+ "version": "4.0.34",
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",
@@ -25,19 +25,19 @@
25
25
  "test": "umi-scripts jest-turbo"
26
26
  },
27
27
  "dependencies": {
28
- "@umijs/ast": "4.0.32",
29
- "@umijs/babel-preset-umi": "4.0.32",
30
- "@umijs/bundler-utils": "4.0.32",
31
- "@umijs/bundler-vite": "4.0.32",
32
- "@umijs/bundler-webpack": "4.0.32",
33
- "@umijs/core": "4.0.32",
28
+ "@umijs/ast": "4.0.34",
29
+ "@umijs/babel-preset-umi": "4.0.34",
30
+ "@umijs/bundler-utils": "4.0.34",
31
+ "@umijs/bundler-vite": "4.0.34",
32
+ "@umijs/bundler-webpack": "4.0.34",
33
+ "@umijs/core": "4.0.34",
34
34
  "@umijs/did-you-know": "^1.0.0",
35
35
  "@umijs/history": "5.3.1",
36
- "@umijs/mfsu": "4.0.32",
37
- "@umijs/plugin-run": "4.0.32",
38
- "@umijs/renderer-react": "4.0.32",
39
- "@umijs/server": "4.0.32",
40
- "@umijs/utils": "4.0.32",
36
+ "@umijs/mfsu": "4.0.34",
37
+ "@umijs/plugin-run": "4.0.34",
38
+ "@umijs/renderer-react": "4.0.34",
39
+ "@umijs/server": "4.0.34",
40
+ "@umijs/utils": "4.0.34",
41
41
  "babel-plugin-dynamic-import-node": "2.3.3",
42
42
  "click-to-react-component": "^1.0.8",
43
43
  "core-js": "3.22.4",
@@ -43,7 +43,7 @@ export function TestBrowser(props: TestBrowserProps) {
43
43
  type: 'memory',
44
44
  basename,
45
45
  });
46
- return {
46
+ const context = {
47
47
  routes,
48
48
  {{#hydrate}}
49
49
  hydrate: true,
@@ -63,6 +63,12 @@ export function TestBrowser(props: TestBrowserProps) {
63
63
  basename,
64
64
  components: true,
65
65
  };
66
+ const modifiedContext = pluginManager.applyPlugins({
67
+ key: 'modifyClientRenderOpts',
68
+ type: ApplyPluginsType.modify,
69
+ initialValue: context,
70
+ });
71
+ return modifiedContext;
66
72
  };
67
73
  genContext().then((context) => {
68
74
  setContext(context);
@@ -18,10 +18,10 @@ export function createHistory(opts: any) {
18
18
  history = {
19
19
  ...h,
20
20
  push(to, state) {
21
- h.push(patchTo(to), state);
21
+ h.push(patchTo(to, h), state);
22
22
  },
23
23
  replace(to, state) {
24
- h.replace(patchTo(to), state);
24
+ h.replace(patchTo(to, h), state);
25
25
  },
26
26
  get location() {
27
27
  return h.location;
@@ -38,13 +38,16 @@ export function createHistory(opts: any) {
38
38
  // Refs:
39
39
  // https://github.com/remix-run/history/blob/3e9dab4/packages/history/index.ts#L484
40
40
  // https://github.com/remix-run/history/blob/dev/docs/api-reference.md#to
41
- function patchTo(to: any) {
41
+ function patchTo(to: any, h: History) {
42
42
  if (typeof to === 'string') {
43
43
  return `${stripLastSlash(basename)}${to}`;
44
- } else if (typeof to === 'object' && to.pathname) {
44
+ } else if (typeof to === 'object') {
45
+
46
+ const currentPathname = h.location.pathname;
47
+
45
48
  return {
46
49
  ...to,
47
- pathname: `${stripLastSlash(basename)}${to.pathname}`,
50
+ pathname: to.pathname? `${stripLastSlash(basename)}${to.pathname}` : currentPathname,
48
51
  };
49
52
  } else {
50
53
  throw new Error(`Unexpected to: ${to}`);
package/templates/umi.tpl CHANGED
@@ -59,8 +59,14 @@ async function render() {
59
59
  ...contextOpts.historyOpts,
60
60
  }),
61
61
  basename,
62
+ callback: contextOpts.callback,
62
63
  };
63
- return renderClient(context);
64
+ const modifiedContext = pluginManager.applyPlugins({
65
+ key: 'modifyClientRenderOpts',
66
+ type: ApplyPluginsType.modify,
67
+ initialValue: context,
68
+ });
69
+ return renderClient(modifiedContext);
64
70
  },
65
71
  }))();
66
72
  }