@umijs/preset-umi 4.0.26 → 4.0.28

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.
@@ -147,15 +147,29 @@ umi build --clean
147
147
  });
148
148
  const { vite } = api.args;
149
149
  const markupArgs = await (0, import_getMarkupArgs.getMarkupArgs)({ api });
150
- const markup = await (0, import_server.getMarkup)({
150
+ const finalMarkUpArgs = {
151
151
  ...markupArgs,
152
152
  styles: markupArgs.styles.concat(api.config.vite ? [] : assetsMap["umi.css"] || []),
153
153
  scripts: (api.config.vite ? [] : assetsMap["umi.js"] || []).concat(markupArgs.scripts),
154
154
  esmScript: !!opts.config.esm || vite,
155
155
  path: "/"
156
+ };
157
+ const htmlFiles = await api.applyPlugins({
158
+ key: "modifyExportHTMLFiles",
159
+ initialValue: [
160
+ {
161
+ path: "index.html",
162
+ content: await (0, import_server.getMarkup)(finalMarkUpArgs)
163
+ }
164
+ ],
165
+ args: { markupArgs: finalMarkUpArgs, getMarkup: import_server.getMarkup }
166
+ });
167
+ htmlFiles.forEach(({ path, content }) => {
168
+ const absPath = (0, import_path.resolve)(api.paths.absOutputPath, path);
169
+ import_utils.fsExtra.mkdirpSync((0, import_path.dirname)(absPath));
170
+ (0, import_fs.writeFileSync)(absPath, content, "utf-8");
171
+ import_utils.logger.event(`Build ${path}`);
156
172
  });
157
- (0, import_fs.writeFileSync)((0, import_path.join)(api.paths.absOutputPath, "index.html"), markup, "utf-8");
158
- import_utils.logger.event("Build index.html");
159
173
  }
160
174
  await api.applyPlugins({
161
175
  key: "onBuildHtmlComplete",
@@ -24,10 +24,11 @@ var import_path = require("path");
24
24
  var import_worker_threads = require("worker_threads");
25
25
  var import_depBuilder = require("./depBuilder");
26
26
  var import_getConfig = require("./getConfig");
27
- (0, import_utils.setNoDeprecation)();
28
27
  if (import_worker_threads.isMainThread) {
29
28
  throw Error("MFSU-eager builder can only be called in a worker thread");
30
29
  }
30
+ (0, import_utils.setNoDeprecation)();
31
+ setupWorkerEnv();
31
32
  var bundlerWebpackPath = (0, import_path.dirname)(require.resolve("@umijs/bundler-webpack"));
32
33
  var bufferedRequest = [];
33
34
  async function start() {
@@ -106,3 +107,7 @@ function makeArray(a) {
106
107
  return a;
107
108
  return [a];
108
109
  }
110
+ function setupWorkerEnv() {
111
+ process.env.DID_YOU_KNOW = "none";
112
+ process.env.IS_UMI_BUILD_WORKER = "true";
113
+ }
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
2
  import type { IncomingMessage } from 'http';
4
3
  import type { IRoute } from '../../types';
5
4
  declare class UmiApiRequest {
@@ -0,0 +1,3 @@
1
+ import type { IApi } from '../../types';
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;
@@ -0,0 +1,106 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/features/exportStatic/exportStatic.ts
23
+ var exportStatic_exports = {};
24
+ __export(exportStatic_exports, {
25
+ default: () => exportStatic_default
26
+ });
27
+ module.exports = __toCommonJS(exportStatic_exports);
28
+ var import_path = require("path");
29
+ var import_server = require("@umijs/server");
30
+ var import_utils = require("@umijs/utils");
31
+ var import_assert = __toESM(require("assert"));
32
+ var IS_WIN = process.platform === "win32";
33
+ function getExportHtmlData(routes) {
34
+ const map = /* @__PURE__ */ new Map();
35
+ Object.values(routes).forEach((route) => {
36
+ if (!route.isLayout && (!IS_WIN || !route.path.includes("/:")) && !route.path.includes("*")) {
37
+ const file = (0, import_path.join)(".", route.absPath, "index.html");
38
+ map.set(file, {
39
+ route: {
40
+ path: route.absPath,
41
+ redirect: route.redirect
42
+ },
43
+ file
44
+ });
45
+ }
46
+ });
47
+ return Array.from(map.values());
48
+ }
49
+ var exportStatic_default = (api) => {
50
+ api.describe({
51
+ config: {
52
+ schema: (Joi) => Joi.object()
53
+ },
54
+ enableBy: api.EnableBy.config
55
+ });
56
+ api.onCheck(() => {
57
+ (0, import_assert.default)(!api.config.mpa, "`exportStatic` is not supported in `mpa` mode.");
58
+ });
59
+ api.modifyExportHTMLFiles(async (_defaultFiles, opts) => {
60
+ const { publicPath } = api.config;
61
+ const htmlData = getExportHtmlData(api.appData.routes);
62
+ const htmlFiles = [];
63
+ for (const { file } of htmlData) {
64
+ let { markupArgs } = opts;
65
+ if (publicPath.startsWith(".")) {
66
+ (0, import_assert.default)(api.config.runtimePublicPath, "`runtimePublicPath` should be enable when `publicPath` is relative!");
67
+ const rltPrefix = (0, import_path.relative)((0, import_path.dirname)(file), ".");
68
+ if (rltPrefix) {
69
+ const picked = import_utils.lodash.clone(import_utils.lodash.pick(markupArgs, [
70
+ "favicons",
71
+ "links",
72
+ "styles",
73
+ "headScripts",
74
+ "scripts"
75
+ ]));
76
+ picked.favicons.forEach((item, i) => {
77
+ if (item.startsWith(publicPath)) {
78
+ picked.favicons[i] = (0, import_utils.winPath)((0, import_path.join)(rltPrefix, item));
79
+ }
80
+ });
81
+ picked.links.forEach((link) => {
82
+ var _a;
83
+ if ((_a = link.href) == null ? void 0 : _a.startsWith(publicPath)) {
84
+ link.href = (0, import_utils.winPath)((0, import_path.join)(rltPrefix, link.href));
85
+ }
86
+ });
87
+ [picked.headScripts, picked.scripts, picked.styles].forEach((group) => {
88
+ group.forEach((script, i) => {
89
+ var _a;
90
+ if (typeof script === "string" && script.startsWith(publicPath)) {
91
+ group[i] = (0, import_utils.winPath)((0, import_path.join)(rltPrefix, script));
92
+ } else if (typeof script === "object" && ((_a = script.src) == null ? void 0 : _a.startsWith(publicPath))) {
93
+ script.src = (0, import_utils.winPath)((0, import_path.join)(rltPrefix, script.src));
94
+ }
95
+ });
96
+ });
97
+ markupArgs = Object.assign({}, markupArgs, picked);
98
+ }
99
+ }
100
+ htmlFiles.push({ path: file, content: await (0, import_server.getMarkup)(markupArgs) });
101
+ }
102
+ return htmlFiles;
103
+ });
104
+ };
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {});
@@ -36,16 +36,16 @@ var overrides_default = (api) => {
36
36
  memo.extraPostCSSPlugins ?? (memo.extraPostCSSPlugins = []);
37
37
  memo.extraPostCSSPlugins.push([
38
38
  require("postcss-prefix-selector")({
39
- prefix: "#fake",
40
- transform(_p, selector, _ps, filePath) {
39
+ prefix: "body",
40
+ transform(_p, selector, prefixedSelector, filePath) {
41
41
  const isOverridesFile = (0, import_utils.winPath)(api.appData.overridesCSS[0]) === (0, import_utils.winPath)(filePath);
42
- if (isOverridesFile && !new RegExp(`^#${api.config.mountElementId}([:[\\s]|$)`).test(selector)) {
42
+ if (isOverridesFile) {
43
43
  if (selector === "html") {
44
44
  return `html:first-child`;
45
- } else if (selector === "body") {
46
- return `* + body`;
45
+ } else if (/^body([\s+~>[:]|$)/.test(selector)) {
46
+ return `* + ${selector}`;
47
47
  }
48
- return `#${api.config.mountElementId} ${selector}`;
48
+ return prefixedSelector;
49
49
  }
50
50
  return selector;
51
51
  }
package/dist/index.js CHANGED
@@ -39,6 +39,7 @@ var src_default = () => {
39
39
  require.resolve("./features/depsOnDemand/depsOnDemand"),
40
40
  require.resolve("./features/devTool/devTool"),
41
41
  require.resolve("./features/esmi/esmi"),
42
+ require.resolve("./features/exportStatic/exportStatic"),
42
43
  require.resolve("./features/favicons/favicons"),
43
44
  require.resolve("./features/mock/mock"),
44
45
  require.resolve("./features/mpa/mpa"),
@@ -37,7 +37,8 @@ var AutoUpdateSrcCodeCache = class {
37
37
  this.listeners = [];
38
38
  this.ignores = [
39
39
  "**/*.d.ts",
40
- "**/*.test.{js,ts,jsx,tsx}",
40
+ "**/*.{test,spec}.{js,ts,jsx,tsx}",
41
+ "**/cypress/**",
41
42
  "**/.umi-production/**",
42
43
  "**/.umi-test/**",
43
44
  "**/node_modules/**",
@@ -69,6 +69,7 @@ var registerMethods_default = (api) => {
69
69
  "modifyEntry",
70
70
  "modifyHTMLFavicon",
71
71
  "modifyHTML",
72
+ "modifyExportHTMLFiles",
72
73
  "modifyWebpackConfig",
73
74
  "modifyViteConfig",
74
75
  "modifyRendererPath",
package/dist/types.d.ts CHANGED
@@ -4,8 +4,10 @@ import type WebpackChain from '@umijs/bundler-webpack/compiled/webpack-5-chain';
4
4
  import type { IConfig } from '@umijs/bundler-webpack/dist/types';
5
5
  import type { IAdd, IEvent, IModify, IRoute as ICoreRoute, IServicePluginAPI, PluginAPI } from '@umijs/core';
6
6
  import { Env } from '@umijs/core';
7
+ import type { getMarkup } from '@umijs/server';
7
8
  import type { CheerioAPI } from '@umijs/utils/compiled/cheerio';
8
9
  import type { InlineConfig as ViteInlineConfig } from 'vite';
10
+ import type { getMarkupArgs } from './commands/dev/getMarkupArgs';
9
11
  import type CodeFrameError from './features/transform/CodeFrameError';
10
12
  export { UmiApiRequest, UmiApiResponse } from './features/apiRoute';
11
13
  export { webpack, IConfig };
@@ -91,6 +93,13 @@ export declare type IApi = PluginAPI & IServicePluginAPI & {
91
93
  };
92
94
  modifyBabelPresetOpts: IModify<any, null>;
93
95
  modifyEntry: IModify<Record<string, string>, null>;
96
+ modifyExportHTMLFiles: IModify<{
97
+ content: string;
98
+ path: string;
99
+ }[], {
100
+ getMarkup: typeof getMarkup;
101
+ markupArgs: Awaited<ReturnType<typeof getMarkupArgs>>;
102
+ }>;
94
103
  modifyHTML: IModify<CheerioAPI, {
95
104
  path: string;
96
105
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/preset-umi",
3
- "version": "4.0.26",
3
+ "version": "4.0.28",
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.26",
29
- "@umijs/babel-preset-umi": "4.0.26",
30
- "@umijs/bundler-utils": "4.0.26",
31
- "@umijs/bundler-vite": "4.0.26",
32
- "@umijs/bundler-webpack": "4.0.26",
33
- "@umijs/core": "4.0.26",
28
+ "@umijs/ast": "4.0.28",
29
+ "@umijs/babel-preset-umi": "4.0.28",
30
+ "@umijs/bundler-utils": "4.0.28",
31
+ "@umijs/bundler-vite": "4.0.28",
32
+ "@umijs/bundler-webpack": "4.0.28",
33
+ "@umijs/core": "4.0.28",
34
34
  "@umijs/did-you-know": "^1.0.0",
35
35
  "@umijs/history": "5.3.1",
36
- "@umijs/mfsu": "4.0.26",
37
- "@umijs/plugin-run": "4.0.26",
38
- "@umijs/renderer-react": "4.0.26",
39
- "@umijs/server": "4.0.26",
40
- "@umijs/utils": "4.0.26",
36
+ "@umijs/mfsu": "4.0.28",
37
+ "@umijs/plugin-run": "4.0.28",
38
+ "@umijs/renderer-react": "4.0.28",
39
+ "@umijs/server": "4.0.28",
40
+ "@umijs/utils": "4.0.28",
41
41
  "click-to-react-component": "^1.0.8",
42
42
  "core-js": "3.22.4",
43
43
  "current-script-polyfill": "1.0.0",