@umijs/bundler-webpack 4.0.0-canary.20220718.1 → 4.0.0-canary.20220727.1

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.
Files changed (154) hide show
  1. package/client/client/client.d.ts +1 -0
  2. package/client/client/client.js +172 -192
  3. package/client/constants.d.ts +15 -0
  4. package/client/constants.js +28 -19
  5. package/client/utils/formatWebpackMessages.d.ts +12 -0
  6. package/client/utils/formatWebpackMessages.js +68 -86
  7. package/dist/build.d.ts +1 -2
  8. package/dist/build.js +105 -68
  9. package/dist/cli.d.ts +0 -1
  10. package/dist/cli.js +77 -69
  11. package/dist/config/_sampleFeature.d.ts +0 -1
  12. package/dist/config/_sampleFeature.js +33 -9
  13. package/dist/config/assetRules.d.ts +0 -1
  14. package/dist/config/assetRules.js +45 -36
  15. package/dist/config/bundleAnalyzerPlugin.d.ts +0 -1
  16. package/dist/config/bundleAnalyzerPlugin.js +39 -17
  17. package/dist/config/compressPlugin.d.ts +0 -1
  18. package/dist/config/compressPlugin.js +113 -95
  19. package/dist/config/config.d.ts +1 -1
  20. package/dist/config/config.js +204 -218
  21. package/dist/config/copyPlugin.d.ts +0 -1
  22. package/dist/config/copyPlugin.js +59 -40
  23. package/dist/config/cssRules.d.ts +0 -1
  24. package/dist/config/cssRules.js +136 -131
  25. package/dist/config/definePlugin.d.ts +0 -1
  26. package/dist/config/definePlugin.js +71 -35
  27. package/dist/config/detectDeadCode.d.ts +0 -1
  28. package/dist/config/detectDeadCode.js +120 -108
  29. package/dist/config/detectDeadCodePlugin.d.ts +0 -1
  30. package/dist/config/detectDeadCodePlugin.js +78 -63
  31. package/dist/config/fastRefreshPlugin.d.ts +0 -1
  32. package/dist/config/fastRefreshPlugin.js +39 -20
  33. package/dist/config/forkTSCheckerPlugin.d.ts +0 -1
  34. package/dist/config/forkTSCheckerPlugin.js +38 -18
  35. package/dist/config/harmonyLinkingErrorPlugin.d.ts +0 -1
  36. package/dist/config/harmonyLinkingErrorPlugin.js +48 -29
  37. package/dist/config/ignorePlugin.d.ts +0 -1
  38. package/dist/config/ignorePlugin.js +38 -14
  39. package/dist/config/javaScriptRules.d.ts +0 -1
  40. package/dist/config/javaScriptRules.js +147 -175
  41. package/dist/config/manifestPlugin.d.ts +0 -1
  42. package/dist/config/manifestPlugin.js +51 -15
  43. package/dist/config/miniCSSExtractPlugin.d.ts +0 -1
  44. package/dist/config/miniCSSExtractPlugin.js +42 -22
  45. package/dist/config/nodePolyfill.d.ts +0 -1
  46. package/dist/config/nodePolyfill.js +65 -26
  47. package/dist/config/nodePrefixPlugin.d.ts +0 -1
  48. package/dist/config/nodePrefixPlugin.js +36 -12
  49. package/dist/config/progressPlugin.d.ts +0 -1
  50. package/dist/config/progressPlugin.js +37 -13
  51. package/dist/config/purgecssWebpackPlugin.d.ts +0 -1
  52. package/dist/config/purgecssWebpackPlugin.js +41 -19
  53. package/dist/config/speedMeasureWebpackPlugin.d.ts +0 -1
  54. package/dist/config/speedMeasureWebpackPlugin.js +41 -20
  55. package/dist/config/ssrPlugin.d.ts +0 -1
  56. package/dist/config/ssrPlugin.js +83 -63
  57. package/dist/config/svgRules.d.ts +0 -1
  58. package/dist/config/svgRules.js +74 -46
  59. package/dist/constants.d.ts +0 -1
  60. package/dist/constants.js +57 -22
  61. package/dist/dev.d.ts +1 -2
  62. package/dist/dev.js +170 -135
  63. package/dist/index.d.ts +0 -1
  64. package/dist/index.js +22 -20
  65. package/dist/loader/svgr.d.ts +0 -1
  66. package/dist/loader/svgr.js +73 -54
  67. package/dist/loader/swc.d.ts +0 -1
  68. package/dist/loader/swc.js +110 -69
  69. package/dist/parcelCSS.d.ts +0 -1
  70. package/dist/parcelCSS.js +31 -27
  71. package/dist/plugins/ProgressPlugin.d.ts +0 -1
  72. package/dist/plugins/ProgressPlugin.js +66 -43
  73. package/dist/plugins/RuntimePublicPathPlugin.d.ts +0 -1
  74. package/dist/plugins/RuntimePublicPathPlugin.js +42 -25
  75. package/dist/plugins/_SamplePlugin.d.ts +0 -1
  76. package/dist/plugins/_SamplePlugin.js +39 -14
  77. package/dist/requireHook.d.ts +0 -1
  78. package/dist/requireHook.js +37 -27
  79. package/dist/schema.d.ts +0 -1
  80. package/dist/schema.js +120 -97
  81. package/dist/server/server.d.ts +0 -2
  82. package/dist/server/server.js +214 -184
  83. package/dist/server/ws.d.ts +0 -3
  84. package/dist/server/ws.js +63 -38
  85. package/dist/swcPlugins/autoCSSModules.d.ts +0 -1
  86. package/dist/swcPlugins/autoCSSModules.js +50 -31
  87. package/dist/swcPlugins/changeImportFromString.d.ts +0 -1
  88. package/dist/swcPlugins/changeImportFromString.js +31 -9
  89. package/dist/swcPlugins/lockCoreJS.d.ts +0 -1
  90. package/dist/swcPlugins/lockCoreJS.js +44 -20
  91. package/dist/types.d.ts +2 -2
  92. package/dist/types.js +61 -30
  93. package/dist/utils/browsersList.d.ts +0 -1
  94. package/dist/utils/browsersList.js +31 -8
  95. package/dist/utils/depMatch.d.ts +0 -1
  96. package/dist/utils/depMatch.js +63 -39
  97. package/dist/utils/formatWebpackMessages.d.ts +0 -1
  98. package/dist/utils/formatWebpackMessages.js +93 -91
  99. package/dist/utils/getEsBuildTarget.d.ts +0 -1
  100. package/dist/utils/getEsBuildTarget.js +32 -10
  101. package/package.json +10 -15
  102. package/compiled/react-refresh/LICENSE +0 -21
  103. package/compiled/react-refresh/index.js +0 -21
  104. package/compiled/react-refresh/package.json +0 -1
  105. package/dist/build.d.ts.map +0 -1
  106. package/dist/cli.d.ts.map +0 -1
  107. package/dist/client/client.d.ts +0 -2
  108. package/dist/client/client.d.ts.map +0 -1
  109. package/dist/client/client.js +0 -245
  110. package/dist/config/_sampleFeature.d.ts.map +0 -1
  111. package/dist/config/assetRules.d.ts.map +0 -1
  112. package/dist/config/bundleAnalyzerPlugin.d.ts.map +0 -1
  113. package/dist/config/compressPlugin.d.ts.map +0 -1
  114. package/dist/config/config.d.ts.map +0 -1
  115. package/dist/config/copyPlugin.d.ts.map +0 -1
  116. package/dist/config/cssRules.d.ts.map +0 -1
  117. package/dist/config/definePlugin.d.ts.map +0 -1
  118. package/dist/config/detectDeadCode.d.ts.map +0 -1
  119. package/dist/config/detectDeadCodePlugin.d.ts.map +0 -1
  120. package/dist/config/fastRefreshPlugin.d.ts.map +0 -1
  121. package/dist/config/forkTSCheckerPlugin.d.ts.map +0 -1
  122. package/dist/config/harmonyLinkingErrorPlugin.d.ts.map +0 -1
  123. package/dist/config/ignorePlugin.d.ts.map +0 -1
  124. package/dist/config/javaScriptRules.d.ts.map +0 -1
  125. package/dist/config/manifestPlugin.d.ts.map +0 -1
  126. package/dist/config/miniCSSExtractPlugin.d.ts.map +0 -1
  127. package/dist/config/nodePolyfill.d.ts.map +0 -1
  128. package/dist/config/nodePrefixPlugin.d.ts.map +0 -1
  129. package/dist/config/progressPlugin.d.ts.map +0 -1
  130. package/dist/config/purgecssWebpackPlugin.d.ts.map +0 -1
  131. package/dist/config/speedMeasureWebpackPlugin.d.ts.map +0 -1
  132. package/dist/config/ssrPlugin.d.ts.map +0 -1
  133. package/dist/config/svgRules.d.ts.map +0 -1
  134. package/dist/constants.d.ts.map +0 -1
  135. package/dist/dev.d.ts.map +0 -1
  136. package/dist/index.d.ts.map +0 -1
  137. package/dist/loader/svgr.d.ts.map +0 -1
  138. package/dist/loader/swc.d.ts.map +0 -1
  139. package/dist/parcelCSS.d.ts.map +0 -1
  140. package/dist/plugins/ProgressPlugin.d.ts.map +0 -1
  141. package/dist/plugins/RuntimePublicPathPlugin.d.ts.map +0 -1
  142. package/dist/plugins/_SamplePlugin.d.ts.map +0 -1
  143. package/dist/requireHook.d.ts.map +0 -1
  144. package/dist/schema.d.ts.map +0 -1
  145. package/dist/server/server.d.ts.map +0 -1
  146. package/dist/server/ws.d.ts.map +0 -1
  147. package/dist/swcPlugins/autoCSSModules.d.ts.map +0 -1
  148. package/dist/swcPlugins/changeImportFromString.d.ts.map +0 -1
  149. package/dist/swcPlugins/lockCoreJS.d.ts.map +0 -1
  150. package/dist/types.d.ts.map +0 -1
  151. package/dist/utils/browsersList.d.ts.map +0 -1
  152. package/dist/utils/depMatch.d.ts.map +0 -1
  153. package/dist/utils/formatWebpackMessages.d.ts.map +0 -1
  154. package/dist/utils/getEsBuildTarget.d.ts.map +0 -1
@@ -1,196 +1,226 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
9
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
10
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
+ var __spreadValues = (a, b) => {
13
+ for (var prop in b || (b = {}))
14
+ if (__hasOwnProp.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ if (__getOwnPropSymbols)
17
+ for (var prop of __getOwnPropSymbols(b)) {
18
+ if (__propIsEnum.call(b, prop))
19
+ __defNormalProp(a, prop, b[prop]);
20
+ }
21
+ return a;
22
+ };
23
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
+ var __export = (target, all) => {
25
+ for (var name in all)
26
+ __defProp(target, name, { get: all[name], enumerable: true });
27
+ };
28
+ var __copyProps = (to, from, except, desc) => {
29
+ if (from && typeof from === "object" || typeof from === "function") {
30
+ for (let key of __getOwnPropNames(from))
31
+ if (!__hasOwnProp.call(to, key) && key !== except)
32
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
33
+ }
34
+ return to;
4
35
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createServer = void 0;
7
- const bundler_utils_1 = require("@umijs/bundler-utils");
8
- const express_1 = __importDefault(require("@umijs/bundler-utils/compiled/express"));
9
- const http_proxy_middleware_1 = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
10
- const webpack_1 = __importDefault(require("@umijs/bundler-webpack/compiled/webpack"));
11
- const utils_1 = require("@umijs/utils");
12
- const cors_1 = __importDefault(require("cors"));
13
- const fs_1 = require("fs");
14
- const http_1 = __importDefault(require("http"));
15
- const path_1 = require("path");
16
- const constants_1 = require("../constants");
17
- const ws_1 = require("./ws");
36
+ 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));
37
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
38
+
39
+ // server.ts
40
+ var server_exports = {};
41
+ __export(server_exports, {
42
+ createServer: () => createServer
43
+ });
44
+ module.exports = __toCommonJS(server_exports);
45
+ var import_bundler_utils = require("@umijs/bundler-utils");
46
+ var import_express = __toESM(require("@umijs/bundler-utils/compiled/express"));
47
+ var import_http_proxy_middleware = require("@umijs/bundler-webpack/compiled/http-proxy-middleware");
48
+ var import_webpack = __toESM(require("@umijs/bundler-webpack/compiled/webpack"));
49
+ var import_utils = require("@umijs/utils");
50
+ var import_assert = __toESM(require("assert"));
51
+ var import_cors = __toESM(require("cors"));
52
+ var import_fs = require("fs");
53
+ var import_http = __toESM(require("http"));
54
+ var import_path = require("path");
55
+ var import_constants = require("../constants");
56
+ var import_ws = require("./ws");
18
57
  async function createServer(opts) {
19
- const { webpackConfig, userConfig } = opts;
20
- const { proxy } = userConfig;
21
- const app = (0, express_1.default)();
22
- // cros
23
- app.use((0, cors_1.default)({
24
- origin: true,
25
- methods: ['GET', 'HEAD', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS'],
26
- credentials: true,
27
- }));
28
- // compression
29
- app.use(require('@umijs/bundler-webpack/compiled/compression')());
30
- // debug all js file
31
- app.use((req, res, next) => {
32
- const file = req.path;
33
- const filePath = (0, path_1.join)(opts.cwd, file);
34
- const ext = (0, path_1.extname)(filePath);
35
- if (ext === '.js' && (0, fs_1.existsSync)(filePath)) {
36
- utils_1.logger.info('[dev]', `${file} is responded with ${filePath}, remove it to use original file`);
37
- res.sendFile(filePath);
38
- }
39
- else {
40
- next();
41
- }
42
- });
43
- // before middlewares
44
- (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
45
- // webpack dev middleware
46
- const configs = Array.isArray(webpackConfig)
47
- ? webpackConfig
48
- : [webpackConfig];
49
- const progresses = [];
50
- if (opts.onProgress) {
51
- configs.forEach((config) => {
52
- const progress = {
53
- percent: 0,
54
- status: 'waiting',
55
- };
56
- progresses.push(progress);
57
- config.plugins.push(new webpack_1.default.ProgressPlugin((percent, msg) => {
58
- progress.percent = percent;
59
- progress.status = msg;
60
- opts.onProgress({ progresses });
61
- }));
62
- });
58
+ const { webpackConfig, userConfig } = opts;
59
+ const { proxy } = userConfig;
60
+ const app = (0, import_express.default)();
61
+ app.use((0, import_cors.default)({
62
+ origin: true,
63
+ methods: ["GET", "HEAD", "PUT", "POST", "PATCH", "DELETE", "OPTIONS"],
64
+ credentials: true
65
+ }));
66
+ app.use(require("@umijs/bundler-webpack/compiled/compression")());
67
+ app.use((req, res, next) => {
68
+ const file = req.path;
69
+ const filePath = (0, import_path.join)(opts.cwd, file);
70
+ const ext = (0, import_path.extname)(filePath);
71
+ if (ext === ".js" && (0, import_fs.existsSync)(filePath)) {
72
+ import_utils.logger.info("[dev]", `${file} is responded with ${filePath}, remove it to use original file`);
73
+ res.sendFile(filePath);
74
+ } else {
75
+ next();
63
76
  }
64
- const compiler = (0, webpack_1.default)(configs);
65
- const webpackDevMiddleware = require('@umijs/bundler-webpack/compiled/webpack-dev-middleware');
66
- const compilerMiddleware = webpackDevMiddleware(compiler, {
67
- publicPath: userConfig.publicPath || '/',
68
- writeToDisk: userConfig.writeToDisk,
69
- stats: 'none',
70
- // watchOptions: { ignored }
77
+ });
78
+ (opts.beforeMiddlewares || []).forEach((m) => app.use(m));
79
+ const configs = Array.isArray(webpackConfig) ? webpackConfig : [webpackConfig];
80
+ const progresses = [];
81
+ if (opts.onProgress) {
82
+ configs.forEach((config) => {
83
+ const progress = {
84
+ percent: 0,
85
+ status: "waiting"
86
+ };
87
+ progresses.push(progress);
88
+ config.plugins.push(new import_webpack.default.ProgressPlugin((percent, msg) => {
89
+ progress.percent = percent;
90
+ progress.status = msg;
91
+ opts.onProgress({ progresses });
92
+ }));
71
93
  });
72
- app.use(compilerMiddleware);
73
- // hmr hooks
74
- let stats;
75
- let isFirstCompile = true;
76
- compiler.compilers.forEach(addHooks);
77
- function addHooks(compiler) {
78
- compiler.hooks.invalid.tap('server', () => {
79
- sendMessage(constants_1.MESSAGE_TYPE.invalid);
80
- });
81
- compiler.hooks.done.tap('server', (_stats) => {
82
- var _a;
83
- stats = _stats;
84
- sendStats(getStats(stats));
85
- (_a = opts.onDevCompileDone) === null || _a === void 0 ? void 0 : _a.call(opts, {
86
- stats,
87
- isFirstCompile,
88
- time: stats.endTime - stats.startTime,
89
- });
90
- isFirstCompile = false;
91
- });
92
- }
93
- function sendStats(stats, force, sender) {
94
- const shouldEmit = !force &&
95
- stats &&
96
- (!stats.errors || stats.errors.length === 0) &&
97
- (!stats.warnings || stats.warnings.length === 0) &&
98
- stats.assets &&
99
- stats.assets.every((asset) => !asset.emitted);
100
- if (shouldEmit) {
101
- sendMessage(constants_1.MESSAGE_TYPE.stillOk, null, sender);
102
- return;
103
- }
104
- sendMessage(constants_1.MESSAGE_TYPE.hash, stats.hash, sender);
105
- if ((stats.errors && stats.errors.length > 0) ||
106
- (stats.warnings && stats.warnings.length > 0)) {
107
- if (stats.warnings && stats.warnings.length > 0) {
108
- sendMessage(constants_1.MESSAGE_TYPE.warnings, stats.warnings, sender);
109
- }
110
- if (stats.errors && stats.errors.length > 0) {
111
- sendMessage(constants_1.MESSAGE_TYPE.errors, stats.errors, sender);
112
- }
113
- }
114
- else {
115
- sendMessage(constants_1.MESSAGE_TYPE.ok, null, sender);
116
- }
117
- }
118
- function getStats(stats) {
119
- return stats.toJson({
120
- all: false,
121
- hash: true,
122
- assets: true,
123
- warnings: true,
124
- errors: true,
125
- errorDetails: false,
126
- });
127
- }
128
- function sendMessage(type, data, sender) {
129
- (sender || ws).send(JSON.stringify({ type, data }));
94
+ }
95
+ const compiler = (0, import_webpack.default)(configs);
96
+ const webpackDevMiddleware = require("@umijs/bundler-webpack/compiled/webpack-dev-middleware");
97
+ const compilerMiddleware = webpackDevMiddleware(compiler, {
98
+ publicPath: userConfig.publicPath || "/",
99
+ writeToDisk: userConfig.writeToDisk,
100
+ stats: "none"
101
+ });
102
+ app.use(compilerMiddleware);
103
+ let stats;
104
+ let isFirstCompile = true;
105
+ compiler.compilers.forEach(addHooks);
106
+ function addHooks(compiler2) {
107
+ compiler2.hooks.invalid.tap("server", () => {
108
+ sendMessage(import_constants.MESSAGE_TYPE.invalid);
109
+ });
110
+ compiler2.hooks.done.tap("server", (_stats) => {
111
+ var _a;
112
+ stats = _stats;
113
+ sendStats(getStats(stats));
114
+ (_a = opts.onDevCompileDone) == null ? void 0 : _a.call(opts, {
115
+ stats,
116
+ isFirstCompile,
117
+ time: stats.endTime - stats.startTime
118
+ });
119
+ isFirstCompile = false;
120
+ });
121
+ }
122
+ function sendStats(stats2, force, sender) {
123
+ const shouldEmit = !force && stats2 && (!stats2.errors || stats2.errors.length === 0) && (!stats2.warnings || stats2.warnings.length === 0) && stats2.assets && stats2.assets.every((asset) => !asset.emitted);
124
+ if (shouldEmit) {
125
+ sendMessage(import_constants.MESSAGE_TYPE.stillOk, null, sender);
126
+ return;
130
127
  }
131
- // mock
132
- // proxy
133
- if (proxy) {
134
- Object.keys(proxy).forEach((key) => {
135
- const proxyConfig = proxy[key];
136
- const target = proxyConfig.target;
137
- if (target) {
138
- app.use(key, (0, http_proxy_middleware_1.createProxyMiddleware)(key, {
139
- ...proxy[key],
140
- // Add x-real-url in response header
141
- onProxyRes(proxyRes, req, res) {
142
- var _a, _b;
143
- proxyRes.headers['x-real-url'] =
144
- ((_a = new URL(req.url || '', target)) === null || _a === void 0 ? void 0 : _a.href) || '';
145
- (_b = proxyConfig.onProxyRes) === null || _b === void 0 ? void 0 : _b.call(proxyConfig, proxyRes, req, res);
146
- },
147
- }));
148
- }
149
- });
128
+ sendMessage(import_constants.MESSAGE_TYPE.hash, stats2.hash, sender);
129
+ if (stats2.errors && stats2.errors.length > 0 || stats2.warnings && stats2.warnings.length > 0) {
130
+ if (stats2.warnings && stats2.warnings.length > 0) {
131
+ sendMessage(import_constants.MESSAGE_TYPE.warnings, stats2.warnings, sender);
132
+ }
133
+ if (stats2.errors && stats2.errors.length > 0) {
134
+ sendMessage(import_constants.MESSAGE_TYPE.errors, stats2.errors, sender);
135
+ }
136
+ } else {
137
+ sendMessage(import_constants.MESSAGE_TYPE.ok, null, sender);
150
138
  }
151
- // after middlewares
152
- (opts.afterMiddlewares || []).forEach((m) => {
153
- // TODO: FIXME
154
- app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
139
+ }
140
+ function getStats(stats2) {
141
+ return stats2.toJson({
142
+ all: false,
143
+ hash: true,
144
+ assets: true,
145
+ warnings: true,
146
+ errors: true,
147
+ errorDetails: false
155
148
  });
156
- // history fallback
157
- app.use(require('@umijs/bundler-webpack/compiled/connect-history-api-fallback')({
158
- index: '/',
159
- }));
160
- // hmr reconnect ping
161
- app.use('/__umi_ping', (_, res) => {
162
- res.end('pong');
149
+ }
150
+ function sendMessage(type, data, sender) {
151
+ (sender || ws).send(JSON.stringify({ type, data }));
152
+ }
153
+ if (proxy) {
154
+ const proxyArr = Array.isArray(proxy) ? proxy : proxy.target ? [proxy] : Object.keys(proxy).map((key) => {
155
+ return __spreadProps(__spreadValues({}, proxy[key]), {
156
+ context: key
157
+ });
163
158
  });
164
- // index.html
165
- // TODO: remove me
166
- app.get('/', (_req, res, next) => {
167
- res.set('Content-Type', 'text/html');
168
- const htmlPath = (0, path_1.join)(opts.cwd, 'index.html');
169
- if ((0, fs_1.existsSync)(htmlPath)) {
170
- (0, fs_1.createReadStream)(htmlPath).on('error', next).pipe(res);
171
- }
172
- else {
173
- next();
159
+ proxyArr.forEach((proxy2) => {
160
+ let middleware;
161
+ if (proxy2.target) {
162
+ (0, import_assert.default)(typeof proxy2.target === "string", "proxy.target must be string");
163
+ (0, import_assert.default)(proxy2.context, "proxy.context must be supplied");
164
+ middleware = (0, import_http_proxy_middleware.createProxyMiddleware)(proxy2.context, __spreadProps(__spreadValues({}, proxy2), {
165
+ onProxyRes(proxyRes, req, res) {
166
+ var _a, _b;
167
+ proxyRes.headers["x-real-url"] = ((_a = new URL(req.url || "", proxy2.target)) == null ? void 0 : _a.href) || "";
168
+ (_b = proxy2.onProxyRes) == null ? void 0 : _b.call(proxy2, proxyRes, req, res);
169
+ }
170
+ }));
171
+ }
172
+ app.use((req, res, next) => {
173
+ const bypassUrl = typeof proxy2.bypass === "function" ? proxy2.bypass(req, res, proxy2) : null;
174
+ if (typeof bypassUrl === "string") {
175
+ req.url = bypassUrl;
176
+ return next();
177
+ } else if (bypassUrl === false) {
178
+ return res.end(404);
179
+ } else if ((bypassUrl === null || bypassUrl === void 0) && middleware) {
180
+ return middleware(req, res, next);
181
+ } else {
182
+ next();
174
183
  }
184
+ });
175
185
  });
176
- const server = userConfig.https
177
- ? await (0, bundler_utils_1.createHttpsServer)(app, userConfig.https)
178
- : http_1.default.createServer(app);
179
- if (!server) {
180
- return null;
186
+ }
187
+ (opts.afterMiddlewares || []).forEach((m) => {
188
+ app.use(m.toString().includes(`{ compiler }`) ? m({ compiler }) : m);
189
+ });
190
+ app.use(require("@umijs/bundler-webpack/compiled/connect-history-api-fallback")({
191
+ index: "/"
192
+ }));
193
+ app.use("/__umi_ping", (_, res) => {
194
+ res.end("pong");
195
+ });
196
+ app.get("/", (_req, res, next) => {
197
+ res.set("Content-Type", "text/html");
198
+ const htmlPath = (0, import_path.join)(opts.cwd, "index.html");
199
+ if ((0, import_fs.existsSync)(htmlPath)) {
200
+ (0, import_fs.createReadStream)(htmlPath).on("error", next).pipe(res);
201
+ } else {
202
+ next();
181
203
  }
182
- const ws = (0, ws_1.createWebSocketServer)(server);
183
- ws.wss.on('connection', (socket) => {
184
- if (stats) {
185
- sendStats(getStats(stats), false, socket);
186
- }
187
- });
188
- const protocol = userConfig.https ? 'https:' : 'http:';
189
- const port = opts.port || 8000;
190
- server.listen(port, () => {
191
- const host = opts.host && opts.host !== '0.0.0.0' ? opts.host : 'localhost';
192
- utils_1.logger.ready(`App listening at ${utils_1.chalk.green(`${protocol}//${host}:${port}`)}`);
193
- });
194
- return server;
204
+ });
205
+ const server = userConfig.https ? await (0, import_bundler_utils.createHttpsServer)(app, userConfig.https) : import_http.default.createServer(app);
206
+ if (!server) {
207
+ return null;
208
+ }
209
+ const ws = (0, import_ws.createWebSocketServer)(server);
210
+ ws.wss.on("connection", (socket) => {
211
+ if (stats) {
212
+ sendStats(getStats(stats), false, socket);
213
+ }
214
+ });
215
+ const protocol = userConfig.https ? "https:" : "http:";
216
+ const port = opts.port || 8e3;
217
+ server.listen(port, () => {
218
+ const host = opts.host && opts.host !== "0.0.0.0" ? opts.host : "localhost";
219
+ import_utils.logger.ready(`App listening at ${import_utils.chalk.green(`${protocol}//${host}:${port}`)}`);
220
+ });
221
+ return server;
195
222
  }
196
- exports.createServer = createServer;
223
+ // Annotate the CommonJS export names for ESM import in node:
224
+ 0 && (module.exports = {
225
+ createServer
226
+ });
@@ -1,6 +1,4 @@
1
1
  /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="node" />
4
2
  import type { SpdyServer as Server } from '@umijs/bundler-utils';
5
3
  import { Server as HttpServer } from 'http';
6
4
  import { Http2Server } from 'http2';
@@ -11,4 +9,3 @@ export declare function createWebSocketServer(server: HttpServer | HttpsServer |
11
9
  wss: WebSocket.Server;
12
10
  close(): void;
13
11
  };
14
- //# sourceMappingURL=ws.d.ts.map
package/dist/server/ws.js CHANGED
@@ -1,42 +1,67 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 });
4
10
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.createWebSocketServer = void 0;
7
- const utils_1 = require("@umijs/utils");
8
- const ws_1 = __importDefault(require("../../compiled/ws"));
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
+ // ws.ts
23
+ var ws_exports = {};
24
+ __export(ws_exports, {
25
+ createWebSocketServer: () => createWebSocketServer
26
+ });
27
+ module.exports = __toCommonJS(ws_exports);
28
+ var import_utils = require("@umijs/utils");
29
+ var import_ws = __toESM(require("../../compiled/ws"));
9
30
  function createWebSocketServer(server) {
10
- const wss = new ws_1.default.Server({
11
- noServer: true,
12
- });
13
- server.on('upgrade', (req, socket, head) => {
14
- if (req.headers['sec-websocket-protocol'] === 'webpack-hmr') {
15
- wss.handleUpgrade(req, socket, head, (ws) => {
16
- wss.emit('connection', ws, req);
17
- });
18
- }
19
- });
20
- wss.on('connection', (socket) => {
21
- socket.send(JSON.stringify({ type: 'connected' }));
22
- });
23
- wss.on('error', (e) => {
24
- if (e.code !== 'EADDRINUSE') {
25
- console.error(utils_1.chalk.red(`WebSocket server error:\n${e.stack || e.message}`));
31
+ const wss = new import_ws.default.Server({
32
+ noServer: true
33
+ });
34
+ server.on("upgrade", (req, socket, head) => {
35
+ if (req.headers["sec-websocket-protocol"] === "webpack-hmr") {
36
+ wss.handleUpgrade(req, socket, head, (ws) => {
37
+ wss.emit("connection", ws, req);
38
+ });
39
+ }
40
+ });
41
+ wss.on("connection", (socket) => {
42
+ socket.send(JSON.stringify({ type: "connected" }));
43
+ });
44
+ wss.on("error", (e) => {
45
+ if (e.code !== "EADDRINUSE") {
46
+ console.error(import_utils.chalk.red(`WebSocket server error:
47
+ ${e.stack || e.message}`));
48
+ }
49
+ });
50
+ return {
51
+ send(message) {
52
+ wss.clients.forEach((client) => {
53
+ if (client.readyState === import_ws.default.OPEN) {
54
+ client.send(message);
26
55
  }
27
- });
28
- return {
29
- send(message) {
30
- wss.clients.forEach((client) => {
31
- if (client.readyState === ws_1.default.OPEN) {
32
- client.send(message);
33
- }
34
- });
35
- },
36
- wss,
37
- close() {
38
- wss.close();
39
- },
40
- };
56
+ });
57
+ },
58
+ wss,
59
+ close() {
60
+ wss.close();
61
+ }
62
+ };
41
63
  }
42
- exports.createWebSocketServer = createWebSocketServer;
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ createWebSocketServer
67
+ });
@@ -11,4 +11,3 @@ declare class AutoCSSModule extends Visitor {
11
11
  visitImportDeclaration(expression: ImportDeclaration): ImportDeclaration;
12
12
  }
13
13
  export default AutoCSSModule;
14
- //# sourceMappingURL=autoCSSModules.d.ts.map
@@ -1,34 +1,53 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
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 });
4
10
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const Visitor_1 = __importDefault(require("@swc/core/Visitor"));
7
- const utils_1 = require("@umijs/utils");
8
- const changeImportFromString_1 = require("./changeImportFromString");
9
- class AutoCSSModule extends Visitor_1.default {
10
- visitTsType(expression) {
11
- return expression;
12
- }
13
- /**
14
- * call path:
15
- * visitProgram -> visitModule -> visitModuleItems -> visitModuleItem -> visitImportDeclaration
16
- * @see https://github.com/swc-project/swc/blob/main/node-swc/src/Visitor.ts#L189
17
- */
18
- visitModuleItem(n) {
19
- if (n.type === 'ImportDeclaration') {
20
- return this.visitImportDeclaration(n);
21
- }
22
- return n;
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
+ // autoCSSModules.ts
23
+ var autoCSSModules_exports = {};
24
+ __export(autoCSSModules_exports, {
25
+ default: () => autoCSSModules_default
26
+ });
27
+ module.exports = __toCommonJS(autoCSSModules_exports);
28
+ var import_Visitor = __toESM(require("@swc/core/Visitor"));
29
+ var import_utils = require("@umijs/utils");
30
+ var import_changeImportFromString = require("./changeImportFromString");
31
+ var AutoCSSModule = class extends import_Visitor.default {
32
+ visitTsType(expression) {
33
+ return expression;
34
+ }
35
+ visitModuleItem(n) {
36
+ if (n.type === "ImportDeclaration") {
37
+ return this.visitImportDeclaration(n);
23
38
  }
24
- visitImportDeclaration(expression) {
25
- const { specifiers, source } = expression;
26
- const { value } = source;
27
- if (specifiers.length && (0, utils_1.isStyleFile)({ filename: value })) {
28
- const newImportFrom = `${value}?modules`;
29
- (0, changeImportFromString_1.changeImportFromString)(expression, newImportFrom);
30
- }
31
- return expression;
39
+ return n;
40
+ }
41
+ visitImportDeclaration(expression) {
42
+ const { specifiers, source } = expression;
43
+ const { value } = source;
44
+ if (specifiers.length && (0, import_utils.isStyleFile)({ filename: value })) {
45
+ const newImportFrom = `${value}?modules`;
46
+ (0, import_changeImportFromString.changeImportFromString)(expression, newImportFrom);
32
47
  }
33
- }
34
- exports.default = AutoCSSModule;
48
+ return expression;
49
+ }
50
+ };
51
+ var autoCSSModules_default = AutoCSSModule;
52
+ // Annotate the CommonJS export names for ESM import in node:
53
+ 0 && (module.exports = {});
@@ -1,3 +1,2 @@
1
1
  import type { ImportDeclaration } from '@swc/core';
2
2
  export declare const changeImportFromString: (e: ImportDeclaration, v: string) => void;
3
- //# sourceMappingURL=changeImportFromString.d.ts.map