@umijs/bundler-webpack 4.0.0-canary.20220425.1 → 4.0.0-canary.20220427.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;
@@ -55,6 +55,7 @@ function getConfig(opts) {
55
55
  babelPreset: opts.babelPreset,
56
56
  extraBabelPlugins: opts.extraBabelPlugins || [],
57
57
  extraBabelPresets: opts.extraBabelPresets || [],
58
+ extraBabelIncludes: opts.extraBabelIncludes || [],
58
59
  extraEsbuildLoaderHandler: opts.extraEsbuildLoaderHandler || [],
59
60
  browsers: (0, browsersList_1.getBrowsersList)({
60
61
  targets: userConfig.targets,
@@ -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(),
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.1",
3
+ "version": "4.0.0-canary.20220427.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,10 +35,10 @@
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.1",
39
- "@umijs/bundler-utils": "4.0.0-canary.20220425.1",
40
- "@umijs/mfsu": "4.0.0-canary.20220425.1",
41
- "@umijs/utils": "4.0.0-canary.20220425.1",
38
+ "@umijs/babel-preset-umi": "4.0.0-canary.20220427.1",
39
+ "@umijs/bundler-utils": "4.0.0-canary.20220427.1",
40
+ "@umijs/mfsu": "4.0.0-canary.20220427.1",
41
+ "@umijs/utils": "4.0.0-canary.20220427.1",
42
42
  "css-loader": "6.7.1",
43
43
  "es5-imcompatible-versions": "^0.1.73",
44
44
  "jest-worker": "27.5.1",