@umijs/bundler-webpack 4.0.69 → 4.0.70

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.
@@ -47,6 +47,7 @@ var import_compressPlugin = require("./compressPlugin");
47
47
  var import_copyPlugin = require("./copyPlugin");
48
48
  var import_cssRules = require("./cssRules");
49
49
  var import_definePlugin = require("./definePlugin");
50
+ var import_detectCssModulesInDependence = require("./detectCssModulesInDependence");
50
51
  var import_detectDeadCodePlugin = require("./detectDeadCodePlugin");
51
52
  var import_fastRefreshPlugin = require("./fastRefreshPlugin");
52
53
  var import_forkTSCheckerPlugin = require("./forkTSCheckerPlugin");
@@ -147,6 +148,7 @@ async function getConfig(opts) {
147
148
  await (0, import_ssrPlugin.default)(applyOpts);
148
149
  await (0, import_compressPlugin.addCompressPlugin)(applyOpts);
149
150
  await (0, import_harmonyLinkingErrorPlugin.addHarmonyLinkingErrorPlugin)(applyOpts);
151
+ await (0, import_detectCssModulesInDependence.addDependenceCssModulesDetector)(applyOpts);
150
152
  if (userConfig.runtimePublicPath) {
151
153
  config.plugin("runtimePublicPath").use(import_RuntimePublicPathPlugin.RuntimePublicPathPlugin);
152
154
  }
@@ -0,0 +1,10 @@
1
+ import Config from '@umijs/bundler-webpack/compiled/webpack-5-chain';
2
+ import { IConfig } from '../types';
3
+ interface IOpts {
4
+ userConfig: IConfig;
5
+ config: Config;
6
+ cwd: string;
7
+ extraBabelIncludes: Array<string | RegExp>;
8
+ }
9
+ export declare function addDependenceCssModulesDetector(opts: IOpts): Promise<void>;
10
+ export {};
@@ -0,0 +1,151 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/config/detectCssModulesInDependence.ts
20
+ var detectCssModulesInDependence_exports = {};
21
+ __export(detectCssModulesInDependence_exports, {
22
+ addDependenceCssModulesDetector: () => addDependenceCssModulesDetector
23
+ });
24
+ module.exports = __toCommonJS(detectCssModulesInDependence_exports);
25
+ var import_utils = require("@umijs/utils");
26
+ var import_path = require("path");
27
+ async function addDependenceCssModulesDetector(opts) {
28
+ const { config, cwd, userConfig } = opts;
29
+ if (!userConfig.checkDepCssModules)
30
+ return;
31
+ const matchers = opts.extraBabelIncludes.map(function(p) {
32
+ if (import_utils.lodash.isRegExp(p)) {
33
+ return p;
34
+ }
35
+ let absPath;
36
+ if ((0, import_path.isAbsolute)(p)) {
37
+ absPath = p;
38
+ }
39
+ try {
40
+ if (p.startsWith("./")) {
41
+ absPath = require.resolve(p, { paths: [cwd] });
42
+ }
43
+ absPath = (0, import_path.dirname)(
44
+ import_utils.resolve.sync(`${p}/package.json`, {
45
+ basedir: cwd,
46
+ // same behavior as webpack, to ensure `include` paths matched
47
+ // ref: https://webpack.js.org/configuration/resolve/#resolvesymlinks
48
+ preserveSymlinks: false
49
+ })
50
+ );
51
+ return toRegExp(absPath);
52
+ } catch (e) {
53
+ if (e.code === "MODULE_NOT_FOUND") {
54
+ throw new Error("Cannot resolve extraBabelIncludes: " + p, {
55
+ cause: e
56
+ });
57
+ }
58
+ throw e;
59
+ }
60
+ });
61
+ config.plugin("dep-css-modules-detector").use(DetectCSsModulePlugin, [matchers]);
62
+ }
63
+ var _DetectCSsModulePlugin = class {
64
+ constructor(skipMatcher = []) {
65
+ this.skipMatcher = skipMatcher;
66
+ }
67
+ isCallRequireStyle(statement) {
68
+ if (
69
+ // var x= require(...) ?
70
+ statement.type === "CallExpression" && statement.callee.type === "Identifier" && statement.callee.name === "require" && // var x = require('xxxxx')
71
+ statement.arguments.length === 1 && statement.arguments[0].type === "Literal"
72
+ ) {
73
+ const requireArg = statement.arguments[0].value;
74
+ if (requireArg.endsWith(".less") || requireArg.endsWith(".css")) {
75
+ return true;
76
+ }
77
+ }
78
+ return false;
79
+ }
80
+ apply(compiler) {
81
+ compiler.hooks.normalModuleFactory.tap(
82
+ _DetectCSsModulePlugin.PLUGIN_NAME,
83
+ (factory) => {
84
+ factory.hooks.parser.for("javascript/auto").tap("lessDetector", (parser) => {
85
+ parser.hooks.import.tap(
86
+ "lessDetector",
87
+ (statement, source) => {
88
+ var _a, _b;
89
+ const specifiers = statement.specifiers.length;
90
+ if (specifiers > 0 && (source.endsWith(".less") || source.endsWith(".css")) && this.isJSModule(parser)) {
91
+ this.throwError((_b = (_a = parser.state) == null ? void 0 : _a.module) == null ? void 0 : _b.resource, compiler);
92
+ }
93
+ }
94
+ );
95
+ parser.hooks.program.tap(
96
+ _DetectCSsModulePlugin.PLUGIN_NAME,
97
+ (program) => {
98
+ var _a, _b, _c, _d;
99
+ if (this.isJSModule(parser)) {
100
+ for (const statement of program.body) {
101
+ if (statement.type === "AssignmentExpression" && // x= require("x.less") or var x = require(".css") ?
102
+ this.isCallRequireStyle(statement.right)) {
103
+ this.throwError((_b = (_a = parser.state) == null ? void 0 : _a.module) == null ? void 0 : _b.resource, compiler);
104
+ }
105
+ if (statement.type === "VariableDeclarator" && // var x= require("x.less") or var x = require(".css") ?
106
+ this.isCallRequireStyle(statement.init)) {
107
+ this.throwError((_d = (_c = parser.state) == null ? void 0 : _c.module) == null ? void 0 : _d.resource, compiler);
108
+ }
109
+ }
110
+ }
111
+ }
112
+ );
113
+ });
114
+ }
115
+ );
116
+ }
117
+ isJSModule(parser) {
118
+ var _a, _b;
119
+ let res = (_b = (_a = parser.state) == null ? void 0 : _a.module) == null ? void 0 : _b.resource;
120
+ if (res) {
121
+ if (this.skipMatcher.some((r) => r.test(res))) {
122
+ return false;
123
+ }
124
+ return res.indexOf("node_modules") >= 0 && (res.endsWith(".js") || res.endsWith(".jsx"));
125
+ }
126
+ return false;
127
+ }
128
+ throwError(file, c) {
129
+ const logger = c.getInfrastructureLogger(_DetectCSsModulePlugin.PLUGIN_NAME) || console;
130
+ logger.error(import_utils.chalk.red(`Dependence file ${file} contains css module`));
131
+ logger.error(
132
+ import_utils.chalk.red(
133
+ `Please add the package's name in 'babelExtraIncludes' or use non-css module in dependence`
134
+ )
135
+ );
136
+ throw Error(_DetectCSsModulePlugin.ERROR_NAME);
137
+ }
138
+ };
139
+ var DetectCSsModulePlugin = _DetectCSsModulePlugin;
140
+ DetectCSsModulePlugin.PLUGIN_NAME = "depCssModulesDetector";
141
+ DetectCSsModulePlugin.ERROR_NAME = "USE CSS-MODULES IN NODE_MODULES";
142
+ var toRegExp = (test) => {
143
+ if (typeof test === "string") {
144
+ return new RegExp("^" + test.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
145
+ }
146
+ return test;
147
+ };
148
+ // Annotate the CommonJS export names for ESM import in node:
149
+ 0 && (module.exports = {
150
+ addDependenceCssModulesDetector
151
+ });
package/dist/dev.js CHANGED
@@ -157,7 +157,7 @@ async function setup(opts) {
157
157
  rootDir: opts.rootDir,
158
158
  env: import_types.Env.development,
159
159
  entry: opts.entry,
160
- userConfig: opts.config,
160
+ userConfig: { ...opts.config, forkTSChecker: false },
161
161
  disableCopy: true,
162
162
  hash: true,
163
163
  staticPathPrefix: import_mfsu.MF_DEP_PREFIX,
package/dist/schema.js CHANGED
@@ -58,6 +58,7 @@ function getSchemas() {
58
58
  babelLoaderCustomize: ({ zod }) => zod.string(),
59
59
  cacheDirectoryPath: ({ zod }) => zod.string(),
60
60
  chainWebpack: ({ zod }) => zod.function(),
61
+ checkDepCssModules: ({ zod }) => zod.boolean().default(false),
61
62
  copy: ({ zod }) => zod.array(
62
63
  zod.union([
63
64
  zod.object({
package/dist/types.d.ts CHANGED
@@ -125,6 +125,7 @@ export interface IConfig {
125
125
  babelLoaderCustomize?: string;
126
126
  analyze?: BundleAnalyzerPlugin.Options;
127
127
  esbuildMinifyIIFE?: boolean;
128
+ checkDepCssModules?: boolean;
128
129
  [key: string]: any;
129
130
  }
130
131
  export interface ISrcTranspilerOpts {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/bundler-webpack",
3
- "version": "4.0.69",
3
+ "version": "4.0.70",
4
4
  "description": "@umijs/bundler-webpack",
5
5
  "homepage": "https://github.com/umijs/umi/tree/master/packages/bundler-webpack#readme",
6
6
  "bugs": "https://github.com/umijs/umi/issues",
@@ -38,10 +38,10 @@
38
38
  "postcss-preset-env": "7.5.0",
39
39
  "react-error-overlay": "6.0.9",
40
40
  "react-refresh": "0.14.0",
41
- "@umijs/babel-preset-umi": "4.0.69",
42
- "@umijs/bundler-utils": "4.0.69",
43
- "@umijs/mfsu": "4.0.69",
44
- "@umijs/utils": "4.0.69"
41
+ "@umijs/bundler-utils": "4.0.70",
42
+ "@umijs/babel-preset-umi": "4.0.70",
43
+ "@umijs/mfsu": "4.0.70",
44
+ "@umijs/utils": "4.0.70"
45
45
  },
46
46
  "devDependencies": {
47
47
  "@swc/core": "1.3.24",