@rsdoctor/webpack-plugin 0.0.2-beta.0 → 0.0.2-beta.2

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.
@@ -1,5 +1,5 @@
1
1
  import type { Tap } from 'tapable';
2
- export declare const pluginTapName = "DoctorWebpackPlugin";
2
+ export declare const pluginTapName = "RsdoctorWebpackPlugin";
3
3
  export declare const pluginTapPostOptions: Tap;
4
4
  export declare const pluginTapPreOptions: Tap;
5
5
  export declare const internalPluginTapPreOptions: (namespace: string) => Tap;
package/dist/constants.js CHANGED
@@ -25,7 +25,7 @@ __export(constants_exports, {
25
25
  pluginTapPreOptions: () => pluginTapPreOptions
26
26
  });
27
27
  module.exports = __toCommonJS(constants_exports);
28
- const pluginTapName = "DoctorWebpackPlugin";
28
+ const pluginTapName = "RsdoctorWebpackPlugin";
29
29
  const pluginTapPostOptions = {
30
30
  name: pluginTapName,
31
31
  stage: 999
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export * from './plugin';
2
2
  export * from './multiple';
3
- export * from './plugins/bundle';
4
3
  export { defineRule, LinterType } from '@rsdoctor/core/rules';
package/dist/index.js CHANGED
@@ -25,13 +25,11 @@ __export(src_exports, {
25
25
  module.exports = __toCommonJS(src_exports);
26
26
  __reExport(src_exports, require("./plugin"), module.exports);
27
27
  __reExport(src_exports, require("./multiple"), module.exports);
28
- __reExport(src_exports, require("./plugins/bundle"), module.exports);
29
28
  var import_rules = require("@rsdoctor/core/rules");
30
29
  // Annotate the CommonJS export names for ESM import in node:
31
30
  0 && (module.exports = {
32
31
  LinterType,
33
32
  defineRule,
34
33
  ...require("./plugin"),
35
- ...require("./multiple"),
36
- ...require("./plugins/bundle")
34
+ ...require("./multiple")
37
35
  });
@@ -1,7 +1,7 @@
1
1
  import { Linter } from '@rsdoctor/types';
2
- import type { DoctorWebpackMultiplePluginOptions } from '@rsdoctor/core';
2
+ import type { RsdoctorWebpackMultiplePluginOptions } from '@rsdoctor/core';
3
3
  import { RsdoctorWebpackPlugin } from './plugin';
4
4
  export declare class RsdoctorWebpackMultiplePlugin<Rules extends Linter.ExtendRuleData[]> extends RsdoctorWebpackPlugin<Rules> {
5
5
  private controller;
6
- constructor(options?: DoctorWebpackMultiplePluginOptions<Rules>);
6
+ constructor(options?: RsdoctorWebpackMultiplePluginOptions<Rules>);
7
7
  }
package/dist/multiple.js CHANGED
@@ -30,7 +30,7 @@ class RsdoctorWebpackMultiplePlugin extends import_plugin.RsdoctorWebpackPlugin
30
30
  if (globalController) {
31
31
  return globalController;
32
32
  }
33
- const controller2 = new import_sdk.DoctorSDKController();
33
+ const controller2 = new import_sdk.RsdoctorSDKController();
34
34
  globalController = controller2;
35
35
  return controller2;
36
36
  })();
package/dist/plugin.d.ts CHANGED
@@ -1,38 +1,27 @@
1
- import type { DoctorPluginInstance, DoctorPluginOptionsNormalized, DoctorWebpackPluginOptions } from '@rsdoctor/core/types';
1
+ import type { RsdoctorPluginInstance, RsdoctorPluginOptionsNormalized, RsdoctorWebpackPluginOptions } from '@rsdoctor/core/types';
2
2
  import { ChunkGraph, ModuleGraph } from '@rsdoctor/graph';
3
- import { DoctorWebpackSDK } from '@rsdoctor/sdk';
3
+ import { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
4
4
  import { Linter } from '@rsdoctor/types';
5
- import { Compiler, StatsCompilation } from 'webpack';
6
- export declare class RsdoctorWebpackPlugin<Rules extends Linter.ExtendRuleData[]> implements DoctorPluginInstance<Compiler, Rules> {
7
- readonly name = "DoctorWebpackPlugin";
8
- readonly options: DoctorPluginOptionsNormalized<Rules>;
9
- readonly sdk: DoctorWebpackSDK;
5
+ import { Compiler } from 'webpack';
6
+ export declare class RsdoctorWebpackPlugin<Rules extends Linter.ExtendRuleData[]> implements RsdoctorPluginInstance<Compiler, Rules> {
7
+ readonly name = "RsdoctorWebpackPlugin";
8
+ readonly options: RsdoctorPluginOptionsNormalized<Rules>;
9
+ readonly sdk: RsdoctorWebpackSDK;
10
10
  modulesGraph: ModuleGraph;
11
11
  private outsideInstance;
12
12
  _bootstrapTask: Promise<unknown>;
13
13
  protected browserIsOpened: boolean;
14
14
  chunkGraph: ChunkGraph;
15
- constructor(options?: DoctorWebpackPluginOptions<Rules>);
15
+ constructor(options?: RsdoctorWebpackPluginOptions<Rules>);
16
16
  apply(compiler: unknown): unknown;
17
17
  afterPlugins: (compiler: Compiler) => void;
18
18
  beforeRun: (compiler: Compiler) => Promise<void>;
19
- private _modulesGraphApplied;
20
19
  /**
21
20
  * @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
22
21
  * @param {Compiler} compiler
23
22
  * @return {*}
24
- * @memberof DoctorWebpackPlugin
23
+ * @memberof RsdoctorWebpackPlugin
25
24
  */
26
25
  ensureModulesChunksGraphApplied(compiler: Compiler): void;
27
26
  done: () => Promise<void>;
28
- /**
29
- * @protected
30
- * @description This function to get module parsed code and size;
31
- * @param {Compiler} compiler
32
- * @param {StatsCompilation} stats
33
- * @param {ModuleGraph} moduleGraph
34
- * @return {*}
35
- * @memberof DoctorWebpackPlugin
36
- */
37
- protected getModulesInfosByStats(compiler: Compiler, stats: StatsCompilation, moduleGraph: ModuleGraph): Promise<void>;
38
27
  }
package/dist/plugin.js CHANGED
@@ -31,21 +31,17 @@ __export(plugin_exports, {
31
31
  RsdoctorWebpackPlugin: () => RsdoctorWebpackPlugin
32
32
  });
33
33
  module.exports = __toCommonJS(plugin_exports);
34
- var import_build_utils = require("@rsdoctor/core/build-utils");
35
- var import_common_utils = require("@rsdoctor/core/common-utils");
36
34
  var import_plugins = require("@rsdoctor/core/plugins");
37
35
  var import_graph = require("@rsdoctor/graph");
38
36
  var import_sdk = require("@rsdoctor/sdk");
39
37
  var import_types = require("@rsdoctor/types");
40
38
  var import_build = require("@rsdoctor/utils/build");
41
39
  var import_logger = require("@rsdoctor/utils/logger");
42
- var import_fs_extra = __toESM(require("fs-extra"));
43
40
  var import_lodash = require("lodash");
44
41
  var import_path = __toESM(require("path"));
45
42
  var import_constants = require("./constants");
46
- var import_bundle = require("./plugins/bundle");
47
43
  var import_resolver = require("./plugins/resolver");
48
- var import_rules = require("./plugins/rules");
44
+ var import_plugins2 = require("@rsdoctor/core/plugins");
49
45
  class RsdoctorWebpackPlugin {
50
46
  constructor(options) {
51
47
  this.name = import_constants.pluginTapName;
@@ -68,7 +64,7 @@ class RsdoctorWebpackPlugin {
68
64
  config: configuration
69
65
  });
70
66
  this.sdk.setOutputDir(
71
- import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.DoctorOutputFolder}`)
67
+ import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
72
68
  );
73
69
  if (configuration.name) {
74
70
  this.sdk.setName(configuration.name);
@@ -84,7 +80,6 @@ class RsdoctorWebpackPlugin {
84
80
  }
85
81
  });
86
82
  };
87
- this._modulesGraphApplied = false;
88
83
  this.done = async () => {
89
84
  try {
90
85
  this.sdk.server.broadcast();
@@ -99,7 +94,7 @@ class RsdoctorWebpackPlugin {
99
94
  }
100
95
  };
101
96
  this.options = (0, import_plugins.normalizeUserConfig)(options);
102
- this.sdk = this.options.sdkInstance ?? new import_sdk.DoctorWebpackSDK({
97
+ this.sdk = this.options.sdkInstance ?? new import_sdk.RsdoctorWebpackSDK({
103
98
  name: import_constants.pluginTapName,
104
99
  root: process.cwd(),
105
100
  type: this.options.reportCodeType,
@@ -127,10 +122,10 @@ class RsdoctorWebpackPlugin {
127
122
  new import_plugins.InternalPluginsPlugin(this).apply(compiler);
128
123
  }
129
124
  if (this.options.features.bundle) {
130
- new import_bundle.InternalBundlePlugin(this).apply(compiler);
125
+ new import_plugins.InternalBundlePlugin(this).apply(compiler);
131
126
  }
132
127
  new import_plugins.InternalErrorReporterPlugin(this).apply(compiler);
133
- new import_rules.InternalRulesPlugin(this).apply(compiler);
128
+ new import_plugins.InternalRulesPlugin(this).apply(compiler);
134
129
  new import_plugins.InternalProgressPlugin(this).apply(compiler);
135
130
  compiler.hooks.afterPlugins.tap(import_constants.pluginTapPostOptions, this.afterPlugins);
136
131
  compiler.hooks.watchRun.tapPromise(import_constants.pluginTapPostOptions, this.beforeRun);
@@ -147,103 +142,10 @@ class RsdoctorWebpackPlugin {
147
142
  * @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
148
143
  * @param {Compiler} compiler
149
144
  * @return {*}
150
- * @memberof DoctorWebpackPlugin
145
+ * @memberof RsdoctorWebpackPlugin
151
146
  */
152
147
  ensureModulesChunksGraphApplied(compiler) {
153
- if (this._modulesGraphApplied)
154
- return;
155
- this._modulesGraphApplied = true;
156
- const context = {
157
- astCache: /* @__PURE__ */ new Map(),
158
- packagePathMap: /* @__PURE__ */ new Map(),
159
- getSourceMap: (file) => {
160
- return this.sdk.getSourceMap(file);
161
- }
162
- };
163
- compiler.hooks.normalModuleFactory.tap(
164
- (0, import_constants.internalPluginTapPostOptions)("moduleGraph"),
165
- (factory) => {
166
- const record = (parser) => {
167
- parser.hooks.program.tap(import_constants.pluginTapPreOptions, (ast) => {
168
- context.astCache.set(parser.state.current, ast);
169
- });
170
- };
171
- factory.hooks.parser.for("javascript/auto").tap(import_constants.pluginTapPostOptions, record);
172
- factory.hooks.parser.for("javascript/dynamic").tap(import_constants.pluginTapPostOptions, record);
173
- factory.hooks.parser.for("javascript/esm").tap(import_constants.pluginTapPostOptions, record);
174
- }
175
- );
176
- compiler.hooks.done.tapPromise(
177
- (0, import_constants.internalPluginTapPreOptions)("moduleGraph"),
178
- async (stats) => {
179
- const statsJson = stats.toJson();
180
- (0, import_logger.debug)(import_build.Process.getMemoryUsageMessage, "[Before Generate ModuleGraph]");
181
- this.chunkGraph = import_build_utils.Chunks.chunkTransform(/* @__PURE__ */ new Map(), statsJson);
182
- this.modulesGraph = await import_build_utils.ModuleGraph.getModuleGraphByStats(
183
- stats.compilation,
184
- statsJson,
185
- process.cwd(),
186
- this.chunkGraph,
187
- this.options.features,
188
- context
189
- );
190
- (0, import_logger.debug)(import_build.Process.getMemoryUsageMessage, "[After Generate ModuleGraph]");
191
- if (this.options.features.treeShaking) {
192
- this.modulesGraph = import_build_utils.ModuleGraph.appendTreeShaking(
193
- this.modulesGraph,
194
- stats.compilation
195
- );
196
- this.sdk.addClientRoutes([
197
- import_types.Manifest.DoctorManifestClientRoutes.TreeShaking
198
- ]);
199
- (0, import_logger.debug)(
200
- import_build.Process.getMemoryUsageMessage,
201
- "[After AppendTreeShaking to ModuleGraph]"
202
- );
203
- }
204
- await this.getModulesInfosByStats(
205
- compiler,
206
- statsJson,
207
- this.modulesGraph
208
- );
209
- (0, import_logger.debug)(import_build.Process.getMemoryUsageMessage, "[After Transform ModuleGraph]");
210
- this.modulesGraph && await this.sdk.reportModuleGraph(this.modulesGraph);
211
- await this.sdk.reportChunkGraph(this.chunkGraph);
212
- const reportFilePath = await import_build_utils.Chunks.generateTileGraph(
213
- statsJson,
214
- {
215
- reportFilename: import_build_utils.Chunks.TileGraphReportName,
216
- reportTitle: "bundle-analyzer"
217
- },
218
- compiler.outputPath
219
- );
220
- reportFilePath && await this.sdk.reportTileHtml(
221
- import_fs_extra.default.readFileSync(reportFilePath, "utf-8")
222
- );
223
- }
224
- );
225
- }
226
- /**
227
- * @protected
228
- * @description This function to get module parsed code and size;
229
- * @param {Compiler} compiler
230
- * @param {StatsCompilation} stats
231
- * @param {ModuleGraph} moduleGraph
232
- * @return {*}
233
- * @memberof DoctorWebpackPlugin
234
- */
235
- async getModulesInfosByStats(compiler, stats, moduleGraph) {
236
- if (!moduleGraph) {
237
- return;
238
- }
239
- try {
240
- const parsedModulesData = await import_build_utils.Chunks.getAssetsModulesData(
241
- stats,
242
- compiler.outputPath
243
- ) || {};
244
- import_common_utils.Chunks.transformAssetsModulesData(parsedModulesData, moduleGraph);
245
- } catch (e) {
246
- }
148
+ (0, import_plugins2.ensureModulesChunksGraphFn)(compiler, this);
247
149
  }
248
150
  }
249
151
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,8 +1,8 @@
1
1
  import { InternalBasePlugin } from '@rsdoctor/core/plugins';
2
- import { DoctorWebpackSDK } from '@rsdoctor/sdk';
2
+ import { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
3
3
  import { SDK } from '@rsdoctor/types';
4
4
  import type { Compiler, ResolvePluginInstance, Resolver } from 'webpack';
5
- interface DoctorResolverPluginOptions {}
5
+ interface RsdoctorResolverPluginOptions {}
6
6
  interface ResolveRequestContext {
7
7
  issuer: string;
8
8
  }
@@ -10,14 +10,14 @@ interface ResolveRequestWithContext {
10
10
  [key: string]: unknown;
11
11
  context: ResolveRequestContext;
12
12
  }
13
- export declare class DoctorResolverPlugin implements ResolvePluginInstance {
14
- protected options: DoctorResolverPluginOptions;
15
- protected sdk: DoctorWebpackSDK;
13
+ export declare class RsdoctorResolverPlugin implements ResolvePluginInstance {
14
+ protected options: RsdoctorResolverPluginOptions;
15
+ protected sdk: RsdoctorWebpackSDK;
16
16
  protected tapOptions: {
17
17
  name: string;
18
18
  };
19
19
  protected contextMap: Map<string, [number, [number, number]]>;
20
- constructor(options: DoctorResolverPluginOptions, sdk: DoctorWebpackSDK);
20
+ constructor(options: RsdoctorResolverPluginOptions, sdk: RsdoctorWebpackSDK);
21
21
  protected getResolverData(context: ResolveRequestContext, params: {
22
22
  request: string;
23
23
  query?: string;
@@ -28,20 +28,20 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var resolver_exports = {};
30
30
  __export(resolver_exports, {
31
- DoctorResolverPlugin: () => DoctorResolverPlugin,
32
- InternalResolverPlugin: () => InternalResolverPlugin
31
+ InternalResolverPlugin: () => InternalResolverPlugin,
32
+ RsdoctorResolverPlugin: () => RsdoctorResolverPlugin
33
33
  });
34
34
  module.exports = __toCommonJS(resolver_exports);
35
35
  var import_plugins = require("@rsdoctor/core/plugins");
36
36
  var import_types = require("@rsdoctor/types");
37
37
  var import_common = require("@rsdoctor/utils/common");
38
38
  var import_path = __toESM(require("path"));
39
- class DoctorResolverPlugin {
39
+ class RsdoctorResolverPlugin {
40
40
  constructor(options, sdk) {
41
41
  this.options = options;
42
42
  this.sdk = sdk;
43
43
  this.tapOptions = {
44
- name: "DoctorResolverPlugin"
44
+ name: "RsdoctorResolverPlugin"
45
45
  };
46
46
  this.contextMap = /* @__PURE__ */ new Map();
47
47
  }
@@ -159,9 +159,9 @@ class InternalResolverPlugin extends import_plugins.InternalBasePlugin {
159
159
  this.afterPlugins = (compiler) => {
160
160
  if (compiler.isChild())
161
161
  return;
162
- compiler.options.resolve.plugins = (compiler.options.resolve.plugins ?? []).concat(new DoctorResolverPlugin({}, this.sdk));
162
+ compiler.options.resolve.plugins = (compiler.options.resolve.plugins ?? []).concat(new RsdoctorResolverPlugin({}, this.sdk));
163
163
  this.sdk.addClientRoutes([
164
- import_types.Manifest.DoctorManifestClientRoutes.ModuleResolve
164
+ import_types.Manifest.RsdoctorManifestClientRoutes.ModuleResolve
165
165
  ]);
166
166
  };
167
167
  }
@@ -172,6 +172,6 @@ class InternalResolverPlugin extends import_plugins.InternalBasePlugin {
172
172
  }
173
173
  // Annotate the CommonJS export names for ESM import in node:
174
174
  0 && (module.exports = {
175
- DoctorResolverPlugin,
176
- InternalResolverPlugin
175
+ InternalResolverPlugin,
176
+ RsdoctorResolverPlugin
177
177
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/webpack-plugin",
3
- "version": "0.0.2-beta.0",
3
+ "version": "0.0.2-beta.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -16,10 +16,10 @@
16
16
  "fs-extra": "^11.1.1",
17
17
  "lodash": "^4.17.21",
18
18
  "webpack": "^5.89.0",
19
- "@rsdoctor/core": "0.0.2-beta.0",
20
- "@rsdoctor/sdk": "0.0.2-beta.0",
21
- "@rsdoctor/graph": "0.0.2-beta.0",
22
- "@rsdoctor/utils": "0.0.2-beta.0"
19
+ "@rsdoctor/core": "0.0.2-beta.2",
20
+ "@rsdoctor/sdk": "0.0.2-beta.2",
21
+ "@rsdoctor/utils": "0.0.2-beta.2",
22
+ "@rsdoctor/graph": "0.0.2-beta.2"
23
23
  },
24
24
  "devDependencies": {
25
25
  "@types/fs-extra": "^11.0.2",
@@ -29,7 +29,7 @@
29
29
  "@types/webpack": "5.28.0",
30
30
  "tslib": "2.4.1",
31
31
  "typescript": "^5.2.2",
32
- "@rsdoctor/types": "0.0.2-beta.0"
32
+ "@rsdoctor/types": "0.0.2-beta.2"
33
33
  },
34
34
  "publishConfig": {
35
35
  "access": "public",
@@ -1,14 +0,0 @@
1
- import { InternalBasePlugin } from '@rsdoctor/core/plugins';
2
- import type { Compilation, Compiler } from 'webpack';
3
- export declare class InternalBundlePlugin<T extends Compiler> extends InternalBasePlugin<T> {
4
- readonly name = "bundle";
5
- map: Map<string, {
6
- content: string;
7
- }>;
8
- apply(compiler: T): void;
9
- ensureAssetContent(name: string): {
10
- content: string;
11
- };
12
- thisCompilation: (compilation: Compilation) => void;
13
- done: () => Promise<void>;
14
- }
@@ -1,80 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var bundle_exports = {};
20
- __export(bundle_exports, {
21
- InternalBundlePlugin: () => InternalBundlePlugin
22
- });
23
- module.exports = __toCommonJS(bundle_exports);
24
- var import_common_utils = require("@rsdoctor/core/common-utils");
25
- var import_plugins = require("@rsdoctor/core/plugins");
26
- var import_types = require("@rsdoctor/types");
27
- class InternalBundlePlugin extends import_plugins.InternalBasePlugin {
28
- constructor() {
29
- super(...arguments);
30
- this.name = "bundle";
31
- this.map = /* @__PURE__ */ new Map();
32
- this.thisCompilation = (compilation) => {
33
- if (compilation.hooks.processAssets && compilation.hooks.afterOptimizeAssets) {
34
- compilation.hooks.afterOptimizeAssets.tap(
35
- this.tapPostOptions,
36
- (assets) => {
37
- Object.keys(assets).forEach((file) => {
38
- const v = this.ensureAssetContent(file);
39
- v.content = assets[file].source().toString();
40
- });
41
- }
42
- );
43
- } else {
44
- compilation.hooks.afterOptimizeChunkAssets.tap(
45
- this.tapPostOptions,
46
- (chunks) => {
47
- [...chunks].reduce((t, chunk) => t.concat([...chunk.files]), []).forEach((file) => {
48
- const v = this.ensureAssetContent(file);
49
- v.content = compilation.assets[file].source().toString();
50
- });
51
- }
52
- );
53
- }
54
- };
55
- this.done = async () => {
56
- import_common_utils.Chunks.assetsContents(this.map, this.scheduler.chunkGraph);
57
- this.sdk.addClientRoutes([
58
- import_types.Manifest.DoctorManifestClientRoutes.ModuleGraph,
59
- import_types.Manifest.DoctorManifestClientRoutes.BundleSize
60
- ]);
61
- };
62
- }
63
- apply(compiler) {
64
- this.scheduler.ensureModulesChunksGraphApplied(compiler);
65
- compiler.hooks.compilation.tap(this.tapPostOptions, this.thisCompilation);
66
- compiler.hooks.done.tapPromise(this.tapPreOptions, this.done.bind(this));
67
- }
68
- ensureAssetContent(name) {
69
- const asset = this.map.get(name);
70
- if (asset)
71
- return asset;
72
- const v = { content: "" };
73
- this.map.set(name, v);
74
- return v;
75
- }
76
- }
77
- // Annotate the CommonJS export names for ESM import in node:
78
- 0 && (module.exports = {
79
- InternalBundlePlugin
80
- });
@@ -1,8 +0,0 @@
1
- import { InternalBasePlugin } from '@rsdoctor/core/plugins';
2
- import type { Compilation, Compiler, Stats } from 'webpack';
3
- export declare class InternalRulesPlugin extends InternalBasePlugin<Compiler> {
4
- readonly name = "rules";
5
- apply(compiler: Compiler): void;
6
- done: (stats: Stats) => Promise<void>;
7
- protected lint(compilation: Compilation): Promise<void>;
8
- }
@@ -1,85 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var rules_exports = {};
20
- __export(rules_exports, {
21
- InternalRulesPlugin: () => InternalRulesPlugin
22
- });
23
- module.exports = __toCommonJS(rules_exports);
24
- var import_plugins = require("@rsdoctor/core/plugins");
25
- var import_rules = require("@rsdoctor/core/rules");
26
- var import_error = require("@rsdoctor/utils/error");
27
- var import_lodash = require("lodash");
28
- class InternalRulesPlugin extends import_plugins.InternalBasePlugin {
29
- constructor() {
30
- super(...arguments);
31
- this.name = "rules";
32
- this.done = async (stats) => {
33
- await this.lint(stats.compilation);
34
- };
35
- }
36
- apply(compiler) {
37
- compiler.hooks.done.tapPromise(this.tapPreOptions, this.done);
38
- }
39
- async lint(compilation) {
40
- const options = this.options ?? {};
41
- const linter = new import_rules.Linter(options.linter);
42
- const result = await linter.validate(this.sdk.getRuleContext({}));
43
- const validateErrors = result.errors.map(
44
- (err) => import_error.DevToolError.from(err, {
45
- detail: err.detail,
46
- controller: {
47
- noColor: true
48
- }
49
- })
50
- );
51
- const errors = validateErrors.filter((item) => item.level === "Error");
52
- const warnings = validateErrors.filter((item) => item.level === "Warn");
53
- const toWebpackError = (err) => err.toError();
54
- result.replace.forEach((item) => {
55
- if ((0, import_lodash.isArray)(compilation.errors) && compilation.errors.includes(item)) {
56
- (0, import_lodash.pull)(compilation.errors, item);
57
- }
58
- if ((0, import_lodash.isArray)(compilation.warnings) && compilation.warnings.includes(item)) {
59
- (0, import_lodash.pull)(compilation.warnings, item);
60
- }
61
- });
62
- if ((0, import_lodash.isArray)(compilation.errors)) {
63
- errors.forEach((err) => {
64
- compilation.warnings.push(toWebpackError(err));
65
- });
66
- }
67
- if ((0, import_lodash.isArray)(compilation.warnings)) {
68
- warnings.forEach((err) => {
69
- compilation.warnings.push(toWebpackError(err));
70
- });
71
- }
72
- this.sdk.reportError(validateErrors);
73
- await linter.afterValidate({
74
- data: this.sdk.getRuleContext({}),
75
- validateResult: result,
76
- hooks: {
77
- afterSaveManifest: this.sdk.hooks.afterSaveManifest
78
- }
79
- });
80
- }
81
- }
82
- // Annotate the CommonJS export names for ESM import in node:
83
- 0 && (module.exports = {
84
- InternalRulesPlugin
85
- });