@umijs/bundler-webpack 4.0.6 → 4.0.9

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 (69) hide show
  1. package/{dist → client}/client/client.d.ts +0 -0
  2. package/client/client/client.js +295 -194
  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 -1
  8. package/dist/build.js +105 -61
  9. package/dist/cli.js +77 -69
  10. package/dist/config/_sampleFeature.js +33 -9
  11. package/dist/config/assetRules.js +45 -36
  12. package/dist/config/bundleAnalyzerPlugin.js +39 -17
  13. package/dist/config/compressPlugin.js +113 -95
  14. package/dist/config/config.d.ts +1 -0
  15. package/dist/config/config.js +204 -215
  16. package/dist/config/copyPlugin.js +59 -40
  17. package/dist/config/cssRules.js +136 -131
  18. package/dist/config/definePlugin.d.ts +1 -0
  19. package/dist/config/definePlugin.js +71 -31
  20. package/dist/config/detectDeadCode.js +120 -108
  21. package/dist/config/detectDeadCodePlugin.js +78 -63
  22. package/dist/config/fastRefreshPlugin.js +39 -20
  23. package/dist/config/forkTSCheckerPlugin.js +38 -19
  24. package/dist/config/harmonyLinkingErrorPlugin.js +48 -29
  25. package/dist/config/ignorePlugin.js +38 -14
  26. package/dist/config/javaScriptRules.js +147 -173
  27. package/dist/config/manifestPlugin.js +51 -15
  28. package/dist/config/miniCSSExtractPlugin.js +42 -22
  29. package/dist/config/nodePolyfill.js +65 -26
  30. package/dist/config/nodePrefixPlugin.js +36 -12
  31. package/dist/config/progressPlugin.js +37 -13
  32. package/dist/config/purgecssWebpackPlugin.js +41 -19
  33. package/dist/config/speedMeasureWebpackPlugin.js +41 -20
  34. package/dist/config/ssrPlugin.js +83 -63
  35. package/dist/config/svgRules.js +74 -46
  36. package/dist/constants.js +57 -22
  37. package/dist/dev.d.ts +1 -1
  38. package/dist/dev.js +170 -129
  39. package/dist/index.js +22 -20
  40. package/dist/loader/svgr.js +73 -54
  41. package/dist/loader/swc.js +110 -69
  42. package/dist/parcelCSS.js +31 -27
  43. package/dist/plugins/ProgressPlugin.js +66 -43
  44. package/dist/plugins/RuntimePublicPathPlugin.js +42 -23
  45. package/dist/plugins/_SamplePlugin.js +39 -14
  46. package/dist/requireHook.js +37 -27
  47. package/dist/schema.js +120 -95
  48. package/dist/server/server.d.ts +0 -1
  49. package/dist/server/server.js +214 -184
  50. package/dist/server/ws.d.ts +0 -2
  51. package/dist/server/ws.js +63 -38
  52. package/dist/swcPlugins/autoCSSModules.js +50 -31
  53. package/dist/swcPlugins/changeImportFromString.js +31 -9
  54. package/dist/swcPlugins/lockCoreJS.js +44 -20
  55. package/dist/types.d.ts +2 -1
  56. package/dist/types.js +61 -30
  57. package/dist/utils/browsersList.js +31 -8
  58. package/dist/utils/depMatch.js +63 -39
  59. package/dist/utils/formatWebpackMessages.js +93 -91
  60. package/dist/utils/getEsBuildTarget.js +32 -10
  61. package/package.json +12 -16
  62. package/compiled/fork-ts-checker-webpack-plugin/LICENSE +0 -21
  63. package/compiled/fork-ts-checker-webpack-plugin/fsevents.node +0 -0
  64. package/compiled/fork-ts-checker-webpack-plugin/index.js +0 -42
  65. package/compiled/fork-ts-checker-webpack-plugin/package.json +0 -1
  66. package/compiled/react-refresh/LICENSE +0 -21
  67. package/compiled/react-refresh/index.js +0 -21
  68. package/compiled/react-refresh/package.json +0 -1
  69. package/dist/client/client.js +0 -245
@@ -1,137 +1,142 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addCSSRules = void 0;
4
- const utils_1 = require("@umijs/utils");
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;
35
+ };
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
+ // cssRules.ts
40
+ var cssRules_exports = {};
41
+ __export(cssRules_exports, {
42
+ addCSSRules: () => addCSSRules
43
+ });
44
+ module.exports = __toCommonJS(cssRules_exports);
45
+ var import_utils = require("@umijs/utils");
5
46
  async function addCSSRules(opts) {
6
- const { config, userConfig } = opts;
7
- const rulesConfig = [
8
- { name: 'css', test: /\.css(\?.*)?$/ },
9
- {
10
- name: 'less',
11
- test: /\.less(\?.*)?$/,
12
- loader: require.resolve('@umijs/bundler-webpack/compiled/less-loader'),
13
- loaderOptions: {
14
- implementation: require.resolve('@umijs/bundler-utils/compiled/less'),
15
- lessOptions: {
16
- modifyVars: userConfig.theme,
17
- javascriptEnabled: true,
18
- ...userConfig.lessLoader,
19
- },
20
- },
21
- },
22
- {
23
- name: 'sass',
24
- test: /\.(sass|scss)(\?.*)?$/,
25
- loader: require.resolve('@umijs/bundler-webpack/compiled/sass-loader'),
26
- loaderOptions: userConfig.sassLoader || {},
47
+ const { config, userConfig } = opts;
48
+ const rulesConfig = [
49
+ { name: "css", test: /\.css(\?.*)?$/ },
50
+ {
51
+ name: "less",
52
+ test: /\.less(\?.*)?$/,
53
+ loader: require.resolve("@umijs/bundler-webpack/compiled/less-loader"),
54
+ loaderOptions: {
55
+ implementation: require.resolve("@umijs/bundler-utils/compiled/less"),
56
+ lessOptions: __spreadValues({
57
+ modifyVars: userConfig.theme,
58
+ javascriptEnabled: true
59
+ }, userConfig.lessLoader)
60
+ }
61
+ },
62
+ {
63
+ name: "sass",
64
+ test: /\.(sass|scss)(\?.*)?$/,
65
+ loader: require.resolve("@umijs/bundler-webpack/compiled/sass-loader"),
66
+ loaderOptions: userConfig.sassLoader || {}
67
+ }
68
+ ];
69
+ for (const { name, test, loader, loaderOptions } of rulesConfig) {
70
+ const rule = config.module.rule(name);
71
+ const nestRulesConfig = [
72
+ userConfig.autoCSSModules && {
73
+ rule: rule.test(test).oneOf("css-modules").resourceQuery(/modules/),
74
+ isCSSModules: true
75
+ },
76
+ {
77
+ rule: rule.test(test).oneOf("css").sideEffects(true),
78
+ isCSSModules: false
79
+ }
80
+ ].filter(Boolean);
81
+ for (const { rule: rule2, isCSSModules } of nestRulesConfig) {
82
+ if (userConfig.styleLoader) {
83
+ rule2.use("style-loader").loader(require.resolve("@umijs/bundler-webpack/compiled/style-loader")).options(__spreadValues({ base: 0, esModule: true }, userConfig.styleLoader));
84
+ } else {
85
+ rule2.use("mini-css-extract-plugin").loader(require.resolve("@umijs/bundler-webpack/compiled/mini-css-extract-plugin/loader")).options({
86
+ publicPath: "./",
87
+ emit: true,
88
+ esModule: true
89
+ });
90
+ }
91
+ rule2.use("css-loader").loader(require.resolve("css-loader")).options(__spreadValues(__spreadValues({
92
+ importLoaders: 1,
93
+ esModule: true,
94
+ url: {
95
+ filter: (url) => {
96
+ if (url.startsWith("/"))
97
+ return false;
98
+ return true;
99
+ }
27
100
  },
28
- ];
29
- for (const { name, test, loader, loaderOptions } of rulesConfig) {
30
- const rule = config.module.rule(name);
31
- const nestRulesConfig = [
32
- userConfig.autoCSSModules && {
33
- rule: rule
34
- .test(test)
35
- .oneOf('css-modules')
36
- .resourceQuery(/modules/),
37
- isCSSModules: true,
38
- },
39
- {
40
- rule: rule.test(test).oneOf('css').sideEffects(true),
41
- isCSSModules: false,
42
- },
43
- ].filter(Boolean);
44
- // @ts-ignore
45
- for (const { rule, isCSSModules } of nestRulesConfig) {
46
- if (userConfig.styleLoader) {
47
- rule
48
- .use('style-loader')
49
- .loader(require.resolve('@umijs/bundler-webpack/compiled/style-loader'))
50
- .options({ base: 0, esModule: true, ...userConfig.styleLoader });
51
- }
52
- else {
53
- rule
54
- .use('mini-css-extract-plugin')
55
- .loader(require.resolve('@umijs/bundler-webpack/compiled/mini-css-extract-plugin/loader'))
56
- .options({
57
- publicPath: './',
58
- emit: true,
59
- esModule: true,
60
- });
61
- }
62
- rule
63
- .use('css-loader')
64
- .loader(require.resolve('css-loader'))
65
- .options({
66
- importLoaders: 1,
67
- esModule: true,
68
- url: {
69
- filter: (url) => {
70
- // Don't parse absolute URLs
71
- // ref: https://github.com/webpack-contrib/css-loader#url
72
- if (url.startsWith('/'))
73
- return false;
74
- return true;
75
- },
76
- },
77
- import: true,
78
- ...(isCSSModules
79
- ? {
80
- modules: {
81
- localIdentName: '[local]___[hash:base64:5]',
82
- ...userConfig.cssLoaderModules,
83
- // If SSR is enabled, we need to handling the css modules name hashing
84
- // and save the class names mapping into opts.cssModulesMapping
85
- // so the esbuild can use it to generate the correct name for the server side
86
- getLocalIdent: userConfig.ssr &&
87
- ((context, localIdentName, localName, opt) => {
88
- const classIdent = ((0, utils_1.winPath)(context.resourcePath).replace((0, utils_1.winPath)(ensureLastSlash(opt.context)), '') +
89
- '@' +
90
- localName).trim();
91
- let hash = Buffer.from(classIdent)
92
- .toString('base64')
93
- .replace(/=/g, '');
94
- hash = hash.substring(hash.length - 5);
95
- const result = localIdentName
96
- .replace(/\[local]/g, localName)
97
- .replace(/\[hash[^\[]*?]/g, hash);
98
- return result;
99
- }),
100
- },
101
- }
102
- : {}),
103
- ...userConfig.cssLoader,
104
- });
105
- rule
106
- .use('postcss-loader')
107
- .loader(require.resolve('@umijs/bundler-webpack/compiled/postcss-loader'))
108
- .options({
109
- postcssOptions: {
110
- ident: 'postcss',
111
- plugins: [
112
- require('@umijs/bundler-webpack/compiled/postcss-flexbugs-fixes'),
113
- require('postcss-preset-env')({
114
- browsers: opts.browsers,
115
- autoprefixer: {
116
- flexbox: 'no-2009',
117
- ...userConfig.autoprefixer,
118
- },
119
- stage: 3,
120
- }),
121
- ].concat(userConfig.extraPostCSSPlugins || []),
122
- ...userConfig.postcssLoader,
123
- },
124
- });
125
- if (loader) {
126
- rule
127
- .use(loader)
128
- .loader(typeof loader === 'string' ? require.resolve(loader) : loader)
129
- .options(loaderOptions || {});
130
- }
131
- }
101
+ import: true
102
+ }, isCSSModules ? {
103
+ modules: __spreadProps(__spreadValues({
104
+ localIdentName: "[local]___[hash:base64:5]"
105
+ }, userConfig.cssLoaderModules), {
106
+ getLocalIdent: userConfig.ssr && ((context, localIdentName, localName, opt) => {
107
+ const classIdent = ((0, import_utils.winPath)(context.resourcePath).replace((0, import_utils.winPath)(ensureLastSlash(opt.context)), "") + "@" + localName).trim();
108
+ let hash = Buffer.from(classIdent).toString("base64").replace(/=/g, "");
109
+ hash = hash.substring(hash.length - 5);
110
+ const result = localIdentName.replace(/\[local]/g, localName).replace(/\[hash[^\[]*?]/g, hash);
111
+ return result;
112
+ })
113
+ })
114
+ } : {}), userConfig.cssLoader));
115
+ rule2.use("postcss-loader").loader(require.resolve("@umijs/bundler-webpack/compiled/postcss-loader")).options({
116
+ postcssOptions: __spreadValues({
117
+ ident: "postcss",
118
+ plugins: [
119
+ require("@umijs/bundler-webpack/compiled/postcss-flexbugs-fixes"),
120
+ require("postcss-preset-env")({
121
+ browsers: opts.browsers,
122
+ autoprefixer: __spreadValues({
123
+ flexbox: "no-2009"
124
+ }, userConfig.autoprefixer),
125
+ stage: 3
126
+ })
127
+ ].concat(userConfig.extraPostCSSPlugins || [])
128
+ }, userConfig.postcssLoader)
129
+ });
130
+ if (loader) {
131
+ rule2.use(loader).loader(typeof loader === "string" ? require.resolve(loader) : loader).options(loaderOptions || {});
132
+ }
132
133
  }
134
+ }
133
135
  }
134
- exports.addCSSRules = addCSSRules;
135
136
  function ensureLastSlash(path) {
136
- return path.endsWith('/') ? path : path + '/';
137
+ return path.endsWith("/") ? path : path + "/";
137
138
  }
139
+ // Annotate the CommonJS export names for ESM import in node:
140
+ 0 && (module.exports = {
141
+ addCSSRules
142
+ });
@@ -8,6 +8,7 @@ interface IOpts {
8
8
  }
9
9
  export declare function resolveDefine(opts: {
10
10
  define: any;
11
+ publicPath?: string;
11
12
  }): {
12
13
  'process.env': Record<string, any>;
13
14
  };
@@ -1,37 +1,77 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.addDefinePlugin = exports.resolveDefine = void 0;
4
- const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
5
- const prefixRE = /^UMI_APP_/;
6
- const ENV_SHOULD_PASS = ['NODE_ENV', 'HMR', 'SOCKET_SERVER', 'ERROR_OVERLAY'];
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, { get: all[name], enumerable: true });
22
+ };
23
+ var __copyProps = (to, from, except, desc) => {
24
+ if (from && typeof from === "object" || typeof from === "function") {
25
+ for (let key of __getOwnPropNames(from))
26
+ if (!__hasOwnProp.call(to, key) && key !== except)
27
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
28
+ }
29
+ return to;
30
+ };
31
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
+
33
+ // definePlugin.ts
34
+ var definePlugin_exports = {};
35
+ __export(definePlugin_exports, {
36
+ addDefinePlugin: () => addDefinePlugin,
37
+ resolveDefine: () => resolveDefine
38
+ });
39
+ module.exports = __toCommonJS(definePlugin_exports);
40
+ var import_webpack = require("@umijs/bundler-webpack/compiled/webpack");
41
+ var prefixRE = /^UMI_APP_/;
42
+ var ENV_SHOULD_PASS = ["NODE_ENV", "HMR", "SOCKET_SERVER", "ERROR_OVERLAY"];
7
43
  function resolveDefine(opts) {
8
- const env = {};
9
- Object.keys(process.env).forEach((key) => {
10
- if (prefixRE.test(key) || ENV_SHOULD_PASS.includes(key)) {
11
- env[key] = process.env[key];
12
- }
13
- });
14
- for (const key in env) {
15
- env[key] = JSON.stringify(env[key]);
44
+ const env = {};
45
+ Object.keys(process.env).forEach((key) => {
46
+ if (prefixRE.test(key) || ENV_SHOULD_PASS.includes(key)) {
47
+ env[key] = process.env[key];
16
48
  }
17
- const define = {};
18
- if (opts.define) {
19
- for (const key in opts.define) {
20
- define[key] = JSON.stringify(opts.define[key]);
21
- }
49
+ });
50
+ env.PUBLIC_PATH = opts.publicPath || "/";
51
+ for (const key in env) {
52
+ env[key] = JSON.stringify(env[key]);
53
+ }
54
+ const define = {};
55
+ if (opts.define) {
56
+ for (const key in opts.define) {
57
+ define[key] = JSON.stringify(opts.define[key]);
22
58
  }
23
- return {
24
- 'process.env': env,
25
- ...define,
26
- };
59
+ }
60
+ return __spreadValues({
61
+ "process.env": env
62
+ }, define);
27
63
  }
28
- exports.resolveDefine = resolveDefine;
29
64
  async function addDefinePlugin(opts) {
30
- const { config, userConfig } = opts;
31
- config.plugin('define').use(webpack_1.DefinePlugin, [
32
- resolveDefine({
33
- define: userConfig.define || {},
34
- }),
35
- ]);
65
+ const { config, userConfig } = opts;
66
+ config.plugin("define").use(import_webpack.DefinePlugin, [
67
+ resolveDefine({
68
+ define: userConfig.define || {},
69
+ publicPath: userConfig.publicPath
70
+ })
71
+ ]);
36
72
  }
37
- exports.addDefinePlugin = addDefinePlugin;
73
+ // Annotate the CommonJS export names for ESM import in node:
74
+ 0 && (module.exports = {
75
+ addDefinePlugin,
76
+ resolveDefine
77
+ });
@@ -1,120 +1,132 @@
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.disabledFolders = void 0;
7
- const webpack_1 = require("@umijs/bundler-webpack/compiled/webpack");
8
- const utils_1 = require("@umijs/utils");
9
- const path_1 = __importDefault(require("path"));
10
- exports.disabledFolders = [
11
- 'node_modules',
12
- '.umi',
13
- '.umi-production',
14
- 'dist',
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
+ // detectDeadCode.ts
23
+ var detectDeadCode_exports = {};
24
+ __export(detectDeadCode_exports, {
25
+ default: () => detectDeadCode_default,
26
+ disabledFolders: () => disabledFolders
27
+ });
28
+ module.exports = __toCommonJS(detectDeadCode_exports);
29
+ var import_webpack = require("@umijs/bundler-webpack/compiled/webpack");
30
+ var import_utils = require("@umijs/utils");
31
+ var import_path = __toESM(require("path"));
32
+ var disabledFolders = [
33
+ "node_modules",
34
+ ".umi",
35
+ ".umi-production",
36
+ "dist"
15
37
  ];
16
- const detectDeadCode = (compilation, options) => {
17
- const assets = getWebpackAssets(compilation);
18
- const compiledFilesDictionary = convertFilesToDict(assets);
19
- const includedFiles = getPattern(options)
20
- .map((pattern) => utils_1.glob.sync(pattern))
21
- .flat();
22
- const unusedFiles = options.detectUnusedFiles
23
- ? includedFiles.filter((file) => !compiledFilesDictionary[file])
24
- : [];
25
- const unusedExportMap = options.detectUnusedExport
26
- ? getUnusedExportMap(convertFilesToDict(includedFiles), compilation)
27
- : {};
28
- logUnusedFiles(unusedFiles);
29
- logUnusedExportMap(unusedExportMap);
30
- const hasUnusedThings = unusedFiles.length || Object.keys(unusedExportMap).length;
31
- if (hasUnusedThings && options.failOnHint) {
32
- process.exit(2);
33
- }
38
+ var detectDeadCode = (compilation, options) => {
39
+ const assets = getWebpackAssets(compilation);
40
+ const compiledFilesDictionary = convertFilesToDict(assets);
41
+ const includedFiles = getPattern(options).map((pattern) => import_utils.glob.sync(pattern)).flat();
42
+ const unusedFiles = options.detectUnusedFiles ? includedFiles.filter((file) => !compiledFilesDictionary[file]) : [];
43
+ const unusedExportMap = options.detectUnusedExport ? getUnusedExportMap(convertFilesToDict(includedFiles), compilation) : {};
44
+ logUnusedFiles(unusedFiles);
45
+ logUnusedExportMap(unusedExportMap);
46
+ const hasUnusedThings = unusedFiles.length || Object.keys(unusedExportMap).length;
47
+ if (hasUnusedThings && options.failOnHint) {
48
+ process.exit(2);
49
+ }
34
50
  };
35
- const getPattern = (options) => {
36
- return options.patterns
37
- .map((pattern) => path_1.default.resolve(options.context || '', pattern))
38
- .concat(options.exclude.map((pattern) => path_1.default.resolve(options.context || '', `!${pattern}`)))
39
- .map(convertToUnixPath);
51
+ var getPattern = (options) => {
52
+ return options.patterns.map((pattern) => import_path.default.resolve(options.context || "", pattern)).concat(options.exclude.map((pattern) => import_path.default.resolve(options.context || "", `!${pattern}`))).map(convertToUnixPath);
40
53
  };
41
- const getUnusedExportMap = (includedFileMap, compilation) => {
42
- const unusedExportMap = {};
43
- compilation.chunks.forEach((chunk) => {
44
- compilation.chunkGraph.getChunkModules(chunk).forEach((module) => {
45
- outputUnusedExportMap(compilation, chunk, module, includedFileMap, unusedExportMap);
46
- });
54
+ var getUnusedExportMap = (includedFileMap, compilation) => {
55
+ const unusedExportMap = {};
56
+ compilation.chunks.forEach((chunk) => {
57
+ compilation.chunkGraph.getChunkModules(chunk).forEach((module2) => {
58
+ outputUnusedExportMap(compilation, chunk, module2, includedFileMap, unusedExportMap);
47
59
  });
48
- return unusedExportMap;
60
+ });
61
+ return unusedExportMap;
49
62
  };
50
- const outputUnusedExportMap = (compilation, chunk, module, includedFileMap, unusedExportMap) => {
51
- if (!(module instanceof webpack_1.NormalModule) || !module.resource) {
52
- return;
53
- }
54
- const path = convertToUnixPath(module.resource);
55
- if (!/^((?!(node_modules)).)*$/.test(path))
56
- return;
57
- const providedExports = compilation.chunkGraph.moduleGraph.getProvidedExports(module);
58
- const usedExports = compilation.chunkGraph.moduleGraph.getUsedExports(module, chunk.runtime);
59
- if (usedExports !== true &&
60
- providedExports !== true &&
61
- includedFileMap[path]) {
62
- if (usedExports === false) {
63
- if (providedExports === null || providedExports === void 0 ? void 0 : providedExports.length) {
64
- unusedExportMap[path] = providedExports;
65
- }
66
- }
67
- else if (providedExports instanceof Array) {
68
- const unusedExports = providedExports.filter((item) => usedExports && !usedExports.has(item));
69
- if (unusedExports.length) {
70
- unusedExportMap[path] = unusedExports;
71
- }
72
- }
63
+ var outputUnusedExportMap = (compilation, chunk, module2, includedFileMap, unusedExportMap) => {
64
+ if (!(module2 instanceof import_webpack.NormalModule) || !module2.resource) {
65
+ return;
66
+ }
67
+ const path2 = convertToUnixPath(module2.resource);
68
+ if (!/^((?!(node_modules)).)*$/.test(path2))
69
+ return;
70
+ const providedExports = compilation.chunkGraph.moduleGraph.getProvidedExports(module2);
71
+ const usedExports = compilation.chunkGraph.moduleGraph.getUsedExports(module2, chunk.runtime);
72
+ if (usedExports !== true && providedExports !== true && includedFileMap[path2]) {
73
+ if (usedExports === false) {
74
+ if (providedExports == null ? void 0 : providedExports.length) {
75
+ unusedExportMap[path2] = providedExports;
76
+ }
77
+ } else if (providedExports instanceof Array) {
78
+ const unusedExports = providedExports.filter((item) => usedExports && !usedExports.has(item));
79
+ if (unusedExports.length) {
80
+ unusedExportMap[path2] = unusedExports;
81
+ }
73
82
  }
83
+ }
74
84
  };
75
- const logUnusedExportMap = (unusedExportMap) => {
76
- if (!Object.keys(unusedExportMap).length) {
77
- return;
78
- }
79
- let numberOfUnusedExport = 0;
80
- let logStr = '';
81
- Object.keys(unusedExportMap).forEach((filePath, fileIndex) => {
82
- const unusedExports = unusedExportMap[filePath];
83
- logStr += [
84
- `\n${fileIndex + 1}. `,
85
- utils_1.chalk.yellow(`${filePath}\n`),
86
- ' >>> ',
87
- utils_1.chalk.yellow(`${unusedExports.join(', ')}`),
88
- ].join('');
89
- numberOfUnusedExport += unusedExports.length;
90
- });
91
- console.log(utils_1.chalk.yellow.bold('\nWarning:'), utils_1.chalk.yellow(`There are ${numberOfUnusedExport} unused exports in ${Object.keys(unusedExportMap).length} files:`), logStr, utils_1.chalk.red.bold('\nPlease be careful if you want to remove them (¬º-°)¬.\n'));
85
+ var logUnusedExportMap = (unusedExportMap) => {
86
+ if (!Object.keys(unusedExportMap).length) {
87
+ return;
88
+ }
89
+ let numberOfUnusedExport = 0;
90
+ let logStr = "";
91
+ Object.keys(unusedExportMap).forEach((filePath, fileIndex) => {
92
+ const unusedExports = unusedExportMap[filePath];
93
+ logStr += [
94
+ `
95
+ ${fileIndex + 1}. `,
96
+ import_utils.chalk.yellow(`${filePath}
97
+ `),
98
+ " >>> ",
99
+ import_utils.chalk.yellow(`${unusedExports.join(", ")}`)
100
+ ].join("");
101
+ numberOfUnusedExport += unusedExports.length;
102
+ });
103
+ console.log(import_utils.chalk.yellow.bold("\nWarning:"), import_utils.chalk.yellow(`There are ${numberOfUnusedExport} unused exports in ${Object.keys(unusedExportMap).length} files:`), logStr, import_utils.chalk.red.bold("\nPlease be careful if you want to remove them (\xAC\xBA-\xB0)\xAC.\n"));
92
104
  };
93
- const getWebpackAssets = (compilation) => {
94
- const outputPath = compilation.getPath(compilation.compiler.outputPath);
95
- const assets = [
96
- ...Array.from(compilation.fileDependencies),
97
- ...compilation
98
- .getAssets()
99
- .map((asset) => path_1.default.join(outputPath, asset.name)),
100
- ];
101
- return assets;
105
+ var getWebpackAssets = (compilation) => {
106
+ const outputPath = compilation.getPath(compilation.compiler.outputPath);
107
+ const assets = [
108
+ ...Array.from(compilation.fileDependencies),
109
+ ...compilation.getAssets().map((asset) => import_path.default.join(outputPath, asset.name))
110
+ ];
111
+ return assets;
102
112
  };
103
- const convertFilesToDict = (assets) => {
104
- return assets
105
- .filter((file) => Boolean(file) &&
106
- exports.disabledFolders.every((disabledPath) => !file.includes(disabledPath)))
107
- .reduce((fileDictionary, file) => {
108
- const unixFile = convertToUnixPath(file);
109
- fileDictionary[unixFile] = true;
110
- return fileDictionary;
111
- }, {});
113
+ var convertFilesToDict = (assets) => {
114
+ return assets.filter((file) => Boolean(file) && disabledFolders.every((disabledPath) => !file.includes(disabledPath))).reduce((fileDictionary, file) => {
115
+ const unixFile = convertToUnixPath(file);
116
+ fileDictionary[unixFile] = true;
117
+ return fileDictionary;
118
+ }, {});
112
119
  };
113
- const logUnusedFiles = (unusedFiles) => {
114
- if (!(unusedFiles === null || unusedFiles === void 0 ? void 0 : unusedFiles.length)) {
115
- return;
116
- }
117
- console.log(utils_1.chalk.yellow.bold('\nWarning:'), utils_1.chalk.yellow(`There are ${unusedFiles.length} unused files:`), ...unusedFiles.map((file, index) => `\n${index + 1}. ${utils_1.chalk.yellow(file)}`), utils_1.chalk.red.bold('\nPlease be careful if you want to remove them (¬º-°)¬.\n'));
120
+ var logUnusedFiles = (unusedFiles) => {
121
+ if (!(unusedFiles == null ? void 0 : unusedFiles.length)) {
122
+ return;
123
+ }
124
+ console.log(import_utils.chalk.yellow.bold("\nWarning:"), import_utils.chalk.yellow(`There are ${unusedFiles.length} unused files:`), ...unusedFiles.map((file, index) => `
125
+ ${index + 1}. ${import_utils.chalk.yellow(file)}`), import_utils.chalk.red.bold("\nPlease be careful if you want to remove them (\xAC\xBA-\xB0)\xAC.\n"));
118
126
  };
119
- const convertToUnixPath = (path) => path.replace(/\\+/g, '/');
120
- exports.default = detectDeadCode;
127
+ var convertToUnixPath = (path2) => path2.replace(/\\+/g, "/");
128
+ var detectDeadCode_default = detectDeadCode;
129
+ // Annotate the CommonJS export names for ESM import in node:
130
+ 0 && (module.exports = {
131
+ disabledFolders
132
+ });