@umijs/bundler-webpack 4.0.0-canary.20220425.2 → 4.0.0-canary.20220428.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.
@@ -13,21 +13,29 @@ import * as ErrorOverlay from 'react-error-overlay';
13
13
  import { MESSAGE_TYPE } from '../constants';
14
14
  import { formatWebpackMessages } from '../utils/formatWebpackMessages';
15
15
  console.log('[webpack] connecting...');
16
- function getSocketHost() {
17
- let l = location;
16
+ function getHost() {
18
17
  if (process.env.SOCKET_SERVER) {
19
- l = new URL(process.env.SOCKET_SERVER);
18
+ return new URL(process.env.SOCKET_SERVER);
20
19
  }
21
- const host = l.host;
22
- const isHttps = l.protocol === 'https:';
20
+ return location;
21
+ }
22
+ function getSocketUrl() {
23
+ let h = getHost();
24
+ const host = h.host;
25
+ const isHttps = h.protocol === 'https:';
23
26
  return `${isHttps ? 'wss' : 'ws'}://${host}`;
24
27
  }
28
+ function getPingUrl() {
29
+ const h = getHost();
30
+ return `${h.protocol}//${h.host}/__umi_ping`;
31
+ }
25
32
  let pingTimer = null;
26
33
  let isFirstCompilation = true;
27
34
  let mostRecentCompilationHash = null;
28
35
  let hasCompileErrors = false;
29
36
  let hadRuntimeError = false;
30
- const socket = new WebSocket(getSocketHost(), 'webpack-hmr');
37
+ const pingUrl = getPingUrl();
38
+ const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
31
39
  socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
32
40
  data = JSON.parse(data);
33
41
  if (data.type === 'connected') {
@@ -45,7 +53,7 @@ function waitForSuccessfulPing(ms = 1000) {
45
53
  // eslint-disable-next-line no-constant-condition
46
54
  while (true) {
47
55
  try {
48
- yield fetch(`/__umi_ping`);
56
+ yield fetch(pingUrl);
49
57
  break;
50
58
  }
51
59
  catch (e) {
package/dist/build.js CHANGED
@@ -35,6 +35,7 @@ function build(opts) {
35
35
  ...(opts.beforeBabelPresets || []),
36
36
  ...(opts.extraBabelPresets || []),
37
37
  ],
38
+ extraBabelIncludes: opts.config.extraBabelIncludes,
38
39
  chainWebpack: opts.chainWebpack,
39
40
  modifyWebpackConfig: opts.modifyWebpackConfig,
40
41
  cache: opts.cache,
@@ -41,21 +41,29 @@ const ErrorOverlay = __importStar(require("react-error-overlay"));
41
41
  const constants_1 = require("../constants");
42
42
  const formatWebpackMessages_1 = require("../utils/formatWebpackMessages");
43
43
  console.log('[webpack] connecting...');
44
- function getSocketHost() {
45
- let l = location;
44
+ function getHost() {
46
45
  if (process.env.SOCKET_SERVER) {
47
- l = new URL(process.env.SOCKET_SERVER);
46
+ return new URL(process.env.SOCKET_SERVER);
48
47
  }
49
- const host = l.host;
50
- const isHttps = l.protocol === 'https:';
48
+ return location;
49
+ }
50
+ function getSocketUrl() {
51
+ let h = getHost();
52
+ const host = h.host;
53
+ const isHttps = h.protocol === 'https:';
51
54
  return `${isHttps ? 'wss' : 'ws'}://${host}`;
52
55
  }
56
+ function getPingUrl() {
57
+ const h = getHost();
58
+ return `${h.protocol}//${h.host}/__umi_ping`;
59
+ }
53
60
  let pingTimer = null;
54
61
  let isFirstCompilation = true;
55
62
  let mostRecentCompilationHash = null;
56
63
  let hasCompileErrors = false;
57
64
  let hadRuntimeError = false;
58
- const socket = new WebSocket(getSocketHost(), 'webpack-hmr');
65
+ const pingUrl = getPingUrl();
66
+ const socket = new WebSocket(getSocketUrl(), 'webpack-hmr');
59
67
  socket.addEventListener('message', ({ data }) => __awaiter(void 0, void 0, void 0, function* () {
60
68
  data = JSON.parse(data);
61
69
  if (data.type === 'connected') {
@@ -73,7 +81,7 @@ function waitForSuccessfulPing(ms = 1000) {
73
81
  // eslint-disable-next-line no-constant-condition
74
82
  while (true) {
75
83
  try {
76
- yield fetch(`/__umi_ping`);
84
+ yield fetch(pingUrl);
77
85
  break;
78
86
  }
79
87
  catch (e) {
@@ -7,6 +7,7 @@ export interface IOpts {
7
7
  entry: Record<string, string>;
8
8
  extraBabelPresets?: any[];
9
9
  extraBabelPlugins?: any[];
10
+ extraBabelIncludes?: string[];
10
11
  extraEsbuildLoaderHandler?: any[];
11
12
  babelPreset?: any;
12
13
  chainWebpack?: Function;
@@ -35,7 +35,6 @@ const javaScriptRules_1 = require("./javaScriptRules");
35
35
  const manifestPlugin_1 = require("./manifestPlugin");
36
36
  const miniCSSExtractPlugin_1 = require("./miniCSSExtractPlugin");
37
37
  const nodePolyfill_1 = require("./nodePolyfill");
38
- const nodePrefixPlugin_1 = require("./nodePrefixPlugin");
39
38
  const progressPlugin_1 = require("./progressPlugin");
40
39
  const speedMeasureWebpackPlugin_1 = require("./speedMeasureWebpackPlugin");
41
40
  const svgRules_1 = require("./svgRules");
@@ -55,6 +54,7 @@ function getConfig(opts) {
55
54
  babelPreset: opts.babelPreset,
56
55
  extraBabelPlugins: opts.extraBabelPlugins || [],
57
56
  extraBabelPresets: opts.extraBabelPresets || [],
57
+ extraBabelIncludes: opts.extraBabelIncludes || [],
58
58
  extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
59
59
  browsers: (0, browsersList_1.getBrowsersList)({
60
60
  targets: userConfig.targets,
@@ -155,7 +155,8 @@ function getConfig(opts) {
155
155
  // handle HarmonyLinkingError
156
156
  yield (0, harmonyLinkingErrorPlugin_1.addHarmonyLinkingErrorPlugin)(applyOpts);
157
157
  // remove node: prefix
158
- yield (0, nodePrefixPlugin_1.addNodePrefixPlugin)(applyOpts);
158
+ // disable for performance
159
+ // await addNodePrefixPlugin(applyOpts);
159
160
  // runtimePublicPath
160
161
  if (userConfig.runtimePublicPath) {
161
162
  config.plugin('runtimePublicPath').use(RuntimePublicPathPlugin_1.RuntimePublicPathPlugin);
@@ -7,6 +7,7 @@ interface IOpts {
7
7
  env: Env;
8
8
  extraBabelPlugins: any[];
9
9
  extraBabelPresets: any[];
10
+ extraBabelIncludes: string[];
10
11
  extraEsbuildLoaderHandler: any[];
11
12
  babelPreset: any;
12
13
  name?: string;
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.addJavaScriptRules = void 0;
13
13
  const mfsu_1 = require("@umijs/mfsu");
14
14
  const utils_1 = require("@umijs/utils");
15
+ const path_1 = require("path");
15
16
  const webpack_1 = require("../../compiled/webpack");
16
17
  const constants_1 = require("../constants");
17
18
  const types_1 = require("../types");
@@ -40,18 +41,41 @@ function addJavaScriptRules(opts) {
40
41
  config.module
41
42
  .rule('extra-src')
42
43
  .test(/\.(js|mjs)$/)
43
- .include.add((path) => {
44
- try {
45
- // do src transform for bundler-webpack/client/client/client.js
46
- if (path.includes('client/client/client'))
47
- return true;
48
- return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
49
- }
50
- catch (e) {
51
- console.error(utils_1.chalk.red(e));
52
- throw e;
53
- }
54
- })
44
+ .include.add([
45
+ // support extraBabelIncludes
46
+ ...opts.extraBabelIncludes.map((p) => {
47
+ // handle absolute path
48
+ if ((0, path_1.isAbsolute)(p)) {
49
+ return p;
50
+ }
51
+ // resolve npm package name
52
+ try {
53
+ if (p.startsWith('./')) {
54
+ return require.resolve(p, { paths: [cwd] });
55
+ }
56
+ return (0, path_1.dirname)(require.resolve(`${p}/package.json`, { paths: [cwd] }));
57
+ }
58
+ catch (e) {
59
+ if (e.code === 'MODULE_NOT_FOUND') {
60
+ throw new Error('Cannot resolve extraBabelIncludes: ' + p);
61
+ }
62
+ throw e;
63
+ }
64
+ }),
65
+ // support es5ImcompatibleVersions
66
+ (path) => {
67
+ try {
68
+ // do src transform for bundler-webpack/client/client/client.js
69
+ if (path.includes('client/client/client'))
70
+ return true;
71
+ return (0, depMatch_1.isMatch)({ path, pkgs: depPkgs });
72
+ }
73
+ catch (e) {
74
+ console.error(utils_1.chalk.red(e));
75
+ throw e;
76
+ }
77
+ },
78
+ ])
55
79
  .end(),
56
80
  ];
57
81
  if (userConfig.mdx) {
package/dist/dev.js CHANGED
@@ -81,6 +81,7 @@ function dev(opts) {
81
81
  ...(opts.beforeBabelPresets || []),
82
82
  ...(opts.extraBabelPresets || []),
83
83
  ],
84
+ extraBabelIncludes: opts.config.extraBabelIncludes,
84
85
  extraEsbuildLoaderHandler: (mfsu === null || mfsu === void 0 ? void 0 : mfsu.getEsbuildLoaderHandler()) || [],
85
86
  chainWebpack: opts.chainWebpack,
86
87
  modifyWebpackConfig: opts.modifyWebpackConfig,
package/dist/schema.js CHANGED
@@ -40,6 +40,7 @@ function getSchemas() {
40
40
  devtool: (Joi) => Joi.alternatives().try(Joi.string().regex(DEVTOOL_REGEX), Joi.boolean()),
41
41
  esm: (Joi) => Joi.object(),
42
42
  externals: (Joi) => Joi.alternatives().try(Joi.object(), Joi.string(), Joi.func()),
43
+ extraBabelIncludes: (Joi) => Joi.array().items(Joi.string()),
43
44
  extraBabelPlugins: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
44
45
  extraBabelPresets: (Joi) => Joi.array().items(Joi.alternatives().try(Joi.string(), Joi.array())),
45
46
  extraPostCSSPlugins: (Joi) => Joi.array(),
@@ -1,5 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  import { RequestListener } from 'http';
3
- import https from 'https';
4
3
  import { HttpsParams } from '../types';
5
- export declare function createHttpsServer(app: RequestListener, httpsConfig: HttpsParams): Promise<https.Server>;
4
+ export declare function createHttpsServer(app: RequestListener, httpsConfig: HttpsParams): Promise<import("https").Server>;
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.createHttpsServer = void 0;
16
16
  const utils_1 = require("@umijs/utils");
17
17
  const fs_1 = require("fs");
18
- const https_1 = __importDefault(require("https"));
19
18
  const path_1 = require("path");
19
+ const spdy_1 = __importDefault(require("spdy"));
20
20
  const defaultHttpsHosts = ['localhost', '127.0.0.1'];
21
21
  function createHttpsServer(app, httpsConfig) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
@@ -64,10 +64,11 @@ function createHttpsServer(app, httpsConfig) {
64
64
  ]);
65
65
  }
66
66
  // Create server
67
- return https_1.default.createServer({
67
+ const http2Service = spdy_1.default.createServer({
68
68
  key: (0, fs_1.readFileSync)(key, 'utf-8'),
69
69
  cert: (0, fs_1.readFileSync)(cert, 'utf-8'),
70
70
  }, app);
71
+ return http2Service;
71
72
  });
72
73
  }
73
74
  exports.createHttpsServer = createHttpsServer;
@@ -1,8 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  import { Server as HttpServer } from 'http';
3
+ import { Http2Server } from 'http2';
3
4
  import { Server as HttpsServer } from 'https';
5
+ import { Server } from 'spdy';
4
6
  import WebSocket from '../../compiled/ws';
5
- export declare function createWebSocketServer(server: HttpServer | HttpsServer): {
7
+ export declare function createWebSocketServer(server: HttpServer | HttpsServer | Http2Server | Server): {
6
8
  send(message: string): void;
7
9
  wss: WebSocket.Server;
8
10
  close(): void;
package/dist/types.d.ts CHANGED
@@ -75,6 +75,7 @@ export interface IConfig {
75
75
  };
76
76
  extraBabelPlugins?: IBabelPlugin[];
77
77
  extraBabelPresets?: IBabelPlugin[];
78
+ extraBabelIncludes?: string[];
78
79
  extraPostCSSPlugins?: any[];
79
80
  hash?: boolean;
80
81
  ignoreMomentLocale?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.0-canary.20220425.2",
3
+ "version": "4.0.0-canary.20220428.1",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/bundler-webpack#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -35,20 +35,22 @@
35
35
  "@svgr/plugin-jsx": "^6.2.1",
36
36
  "@svgr/plugin-svgo": "^6.2.0",
37
37
  "@types/hapi__joi": "17.1.8",
38
- "@umijs/babel-preset-umi": "4.0.0-canary.20220425.2",
39
- "@umijs/bundler-utils": "4.0.0-canary.20220425.2",
40
- "@umijs/mfsu": "4.0.0-canary.20220425.2",
41
- "@umijs/utils": "4.0.0-canary.20220425.2",
38
+ "@umijs/babel-preset-umi": "4.0.0-canary.20220428.1",
39
+ "@umijs/bundler-utils": "4.0.0-canary.20220428.1",
40
+ "@umijs/mfsu": "4.0.0-canary.20220428.1",
41
+ "@umijs/utils": "4.0.0-canary.20220428.1",
42
42
  "css-loader": "6.7.1",
43
43
  "es5-imcompatible-versions": "^0.1.73",
44
44
  "jest-worker": "27.5.1",
45
45
  "node-libs-browser": "2.2.1",
46
46
  "postcss": "^8.4.12",
47
47
  "postcss-preset-env": "7.4.3",
48
- "react-error-overlay": "6.0.9"
48
+ "react-error-overlay": "6.0.9",
49
+ "spdy": "^4.0.2"
49
50
  },
50
51
  "devDependencies": {
51
52
  "@swc/core": "1.2.165",
53
+ "@types/spdy": "^3.4.5",
52
54
  "@types/webpack-sources": "3.2.0",
53
55
  "@types/ws": "8.5.3",
54
56
  "autoprefixer": "10.4.4",