@rsbuild/plugin-eslint 1.1.2 → 1.2.0

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.
package/README.md CHANGED
@@ -74,6 +74,42 @@ pluginEslint({
74
74
  });
75
75
  ```
76
76
 
77
+ ### environments
78
+
79
+ Control which environments to run ESLint on when using [Rsbuild's multi-environment builds](https://rsbuild.dev/guide/advanced/environments).
80
+
81
+ - **Type:** `'all' | boolean | string[]`
82
+ - **Default:** `false`
83
+ - **Example:**
84
+
85
+ By default, ESLint only runs on the first environment to avoid running multiple times:
86
+
87
+ ```js
88
+ pluginEslint({
89
+ environments: false // (default)
90
+ });
91
+ ```
92
+
93
+ Run ESLint on all environments:
94
+
95
+ ```js
96
+ pluginEslint({
97
+ environments: 'all',
98
+ // or
99
+ environments: true,
100
+ });
101
+ ```
102
+
103
+ Run ESLint on specific environments by name:
104
+
105
+ ```js
106
+ pluginEslint({
107
+ environments: ['web', 'node'],
108
+ });
109
+ ```
110
+
111
+ This is useful when different environments have different entry points and you want to ensure all files are linted. Note that when set to `'all'` or `true`, ESLint will run separately for each environment, which may increase build time.
112
+
77
113
  ### eslintPluginOptions
78
114
 
79
115
  To modify the options of `eslint-rspack-plugin`, please refer to [eslint-rspack-plugin - README](https://github.com/rspack-contrib/eslint-rspack-plugin#readme) to learn about available options.
package/dist/index.cjs CHANGED
@@ -1,21 +1,5 @@
1
1
  "use strict";
2
- var __webpack_modules__ = {
3
- "eslint-rspack-plugin": function(module) {
4
- module.exports = import("eslint-rspack-plugin").then(function(module) {
5
- return module;
6
- });
7
- }
8
- };
9
- var __webpack_module_cache__ = {};
10
- function __webpack_require__(moduleId) {
11
- var cachedModule = __webpack_module_cache__[moduleId];
12
- if (void 0 !== cachedModule) return cachedModule.exports;
13
- var module = __webpack_module_cache__[moduleId] = {
14
- exports: {}
15
- };
16
- __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
17
- return module.exports;
18
- }
2
+ var __webpack_require__ = {};
19
3
  (()=>{
20
4
  __webpack_require__.n = (module)=>{
21
5
  var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
@@ -47,51 +31,54 @@ function __webpack_require__(moduleId) {
47
31
  };
48
32
  })();
49
33
  var __webpack_exports__ = {};
50
- (()=>{
51
- __webpack_require__.r(__webpack_exports__);
52
- __webpack_require__.d(__webpack_exports__, {
53
- pluginEslint: ()=>pluginEslint,
54
- PLUGIN_ESLINT_NAME: ()=>PLUGIN_ESLINT_NAME
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ pluginEslint: ()=>pluginEslint,
37
+ PLUGIN_ESLINT_NAME: ()=>PLUGIN_ESLINT_NAME
38
+ });
39
+ const external_node_path_namespaceObject = require("node:path");
40
+ var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
41
+ const PLUGIN_ESLINT_NAME = 'rsbuild:eslint';
42
+ const pluginEslint = (options = {})=>({
43
+ name: PLUGIN_ESLINT_NAME,
44
+ setup (api) {
45
+ const { enable = true, eslintPluginOptions, environments = false } = options;
46
+ if (!enable) return;
47
+ api.modifyBundlerChain(async (chain, { environment })=>{
48
+ const { distPath } = environment;
49
+ const shouldRun = ()=>{
50
+ if (Array.isArray(environments)) return environments.includes(environment.name);
51
+ if (true === environments || 'all' === environments) return true;
52
+ return 0 === environment.index;
53
+ };
54
+ if (!shouldRun()) return;
55
+ const ESLintPluginModule = await import("eslint-rspack-plugin");
56
+ const ESLintPlugin = ESLintPluginModule.default || ESLintPluginModule;
57
+ const defaultOptions = {
58
+ extensions: [
59
+ 'js',
60
+ 'jsx',
61
+ 'mjs',
62
+ 'cjs',
63
+ 'ts',
64
+ 'tsx',
65
+ 'mts',
66
+ 'cts'
67
+ ],
68
+ exclude: [
69
+ 'node_modules',
70
+ external_node_path_default().relative(api.context.rootPath, distPath)
71
+ ]
72
+ };
73
+ chain.plugin('eslint').use(ESLintPlugin, [
74
+ {
75
+ ...defaultOptions,
76
+ ...eslintPluginOptions
77
+ }
78
+ ]);
79
+ });
80
+ }
55
81
  });
56
- const external_node_path_namespaceObject = require("node:path");
57
- var external_node_path_default = /*#__PURE__*/ __webpack_require__.n(external_node_path_namespaceObject);
58
- const PLUGIN_ESLINT_NAME = 'rsbuild:eslint';
59
- const pluginEslint = (options = {})=>({
60
- name: PLUGIN_ESLINT_NAME,
61
- setup (api) {
62
- const { enable = true, eslintPluginOptions } = options;
63
- if (!enable) return;
64
- api.modifyBundlerChain(async (chain, { environment })=>{
65
- const { distPath } = environment;
66
- if (0 !== environment.index) return;
67
- const ESLintPluginModule = await Promise.resolve().then(__webpack_require__.bind(__webpack_require__, "eslint-rspack-plugin"));
68
- const ESLintPlugin = ESLintPluginModule.default || ESLintPluginModule;
69
- const defaultOptions = {
70
- extensions: [
71
- 'js',
72
- 'jsx',
73
- 'mjs',
74
- 'cjs',
75
- 'ts',
76
- 'tsx',
77
- 'mts',
78
- 'cts'
79
- ],
80
- exclude: [
81
- 'node_modules',
82
- external_node_path_default().relative(api.context.rootPath, distPath)
83
- ]
84
- };
85
- chain.plugin('eslint').use(ESLintPlugin, [
86
- {
87
- ...defaultOptions,
88
- ...eslintPluginOptions
89
- }
90
- ]);
91
- });
92
- }
93
- });
94
- })();
95
82
  exports.PLUGIN_ESLINT_NAME = __webpack_exports__.PLUGIN_ESLINT_NAME;
96
83
  exports.pluginEslint = __webpack_exports__.pluginEslint;
97
84
  for(var __webpack_i__ in __webpack_exports__)if (-1 === [
package/dist/index.d.ts CHANGED
@@ -11,6 +11,14 @@ export type PluginEslintOptions = {
11
11
  * @see https://github.com/rspack-contrib/eslint-rspack-plugin
12
12
  */
13
13
  eslintPluginOptions?: Options;
14
+ /**
15
+ * Control which environments to run ESLint on.
16
+ * - `false` or `undefined`: Only run on the first environment (default)
17
+ * - `true` or `'all'`: Run on all environments
18
+ * - `string[]`: Run on specific environments by name (e.g., ['web', 'node'])
19
+ * @default false
20
+ */
21
+ environments?: 'all' | boolean | string[];
14
22
  };
15
23
  export declare const PLUGIN_ESLINT_NAME = "rsbuild:eslint";
16
24
  export declare const pluginEslint: (options?: PluginEslintOptions) => RsbuildPlugin;
package/dist/index.js CHANGED
@@ -3,11 +3,16 @@ const PLUGIN_ESLINT_NAME = 'rsbuild:eslint';
3
3
  const pluginEslint = (options = {})=>({
4
4
  name: PLUGIN_ESLINT_NAME,
5
5
  setup (api) {
6
- const { enable = true, eslintPluginOptions } = options;
6
+ const { enable = true, eslintPluginOptions, environments = false } = options;
7
7
  if (!enable) return;
8
8
  api.modifyBundlerChain(async (chain, { environment })=>{
9
9
  const { distPath } = environment;
10
- if (0 !== environment.index) return;
10
+ const shouldRun = ()=>{
11
+ if (Array.isArray(environments)) return environments.includes(environment.name);
12
+ if (true === environments || 'all' === environments) return true;
13
+ return 0 === environment.index;
14
+ };
15
+ if (!shouldRun()) return;
11
16
  const ESLintPluginModule = await import("eslint-rspack-plugin");
12
17
  const ESLintPlugin = ESLintPluginModule.default || ESLintPluginModule;
13
18
  const defaultOptions = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-eslint",
3
- "version": "1.1.2",
3
+ "version": "1.2.0",
4
4
  "repository": "https://github.com/rspack-contrib/rsbuild-plugin-eslint",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -33,19 +33,19 @@
33
33
  ]
34
34
  },
35
35
  "dependencies": {
36
- "eslint-rspack-plugin": "^4.2.1"
36
+ "eslint-rspack-plugin": "^4.3.0"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@biomejs/biome": "^1.9.4",
40
- "@playwright/test": "^1.54.1",
41
- "@rsbuild/core": "^1.4.12",
42
- "@rslib/core": "^0.11.0",
43
- "@types/node": "^22.17.0",
44
- "eslint": "^9.32.0",
45
- "nano-staged": "^0.8.0",
46
- "playwright": "^1.54.1",
40
+ "@playwright/test": "^1.57.0",
41
+ "@rsbuild/core": "^1.6.10",
42
+ "@rslib/core": "^0.18.2",
43
+ "@types/node": "^24.10.1",
44
+ "eslint": "^9.39.1",
45
+ "nano-staged": "^0.9.0",
46
+ "playwright": "^1.57.0",
47
47
  "simple-git-hooks": "^2.13.1",
48
- "typescript": "^5.9.2"
48
+ "typescript": "^5.9.3"
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@rsbuild/core": "1.x",
@@ -56,7 +56,7 @@
56
56
  "optional": true
57
57
  }
58
58
  },
59
- "packageManager": "pnpm@10.14.0",
59
+ "packageManager": "pnpm@10.24.0",
60
60
  "publishConfig": {
61
61
  "access": "public",
62
62
  "registry": "https://registry.npmjs.org/"