@rsdoctor/rspack-plugin 0.0.2-beta.1 → 0.1.0-beta

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.
@@ -0,0 +1,4 @@
1
+ import { Compiler } from "@rspack/core";
2
+ export declare class BuiltinLoaderPlugin {
3
+ apply(compiler: Compiler): void;
4
+ }
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var builtinLoaderPlugin_exports = {};
30
+ __export(builtinLoaderPlugin_exports, {
31
+ BuiltinLoaderPlugin: () => BuiltinLoaderPlugin
32
+ });
33
+ module.exports = __toCommonJS(builtinLoaderPlugin_exports);
34
+ var import_path = __toESM(require("path"));
35
+ const BuiltinLoaderName = "builtin:swc-loader";
36
+ class BuiltinLoaderPlugin {
37
+ apply(compiler) {
38
+ compiler.hooks.beforeRun.tap(
39
+ {
40
+ name: `CustomLoaderPlugin`
41
+ },
42
+ () => {
43
+ const rules = compiler.options.module.rules;
44
+ rules.forEach((rule) => {
45
+ if (rule && typeof rule === "object" && Array.isArray(rule.use)) {
46
+ const _builtinLoaderRuleIndex = rule.use.findIndex((use) => typeof use === "object" && use.loader.includes(BuiltinLoaderName));
47
+ if (_builtinLoaderRuleIndex !== -1) {
48
+ const _builtinLoaderRule = rule.use[_builtinLoaderRuleIndex];
49
+ const options = typeof _builtinLoaderRule === "string" ? { type: "start" } : { ..._builtinLoaderRule, type: "start" };
50
+ rule.use.splice(_builtinLoaderRuleIndex, 0, { loader: import_path.default.join(__dirname, "./probeLoader.js"), options: { ...options, type: "end" } });
51
+ rule.use.splice(_builtinLoaderRuleIndex + 2, 0, { loader: import_path.default.join(__dirname, "./probeLoader.js"), options });
52
+ }
53
+ }
54
+ });
55
+ compiler.options.module.rules = rules;
56
+ }
57
+ );
58
+ }
59
+ }
60
+ // Annotate the CommonJS export names for ESM import in node:
61
+ 0 && (module.exports = {
62
+ BuiltinLoaderPlugin
63
+ });
package/dist/plugin.d.ts CHANGED
@@ -1,17 +1,24 @@
1
1
  import { Compiler } from '@rspack/core';
2
2
  import { ModuleGraph } from '@rsdoctor/graph';
3
- import { DoctorWebpackSDK } from '@rsdoctor/sdk';
4
- import type { DoctorPluginInstance, DoctorPluginOptionsNormalized, DoctorRspackPluginOptions } from '@rsdoctor/core/types';
3
+ import { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
4
+ import type { RsdoctorPluginInstance, RsdoctorPluginOptionsNormalized, RsdoctorRspackPluginOptions } from '@rsdoctor/core/types';
5
5
  import { Linter } from '@rsdoctor/types';
6
- export declare class RsdoctorRspackPlugin<Rules extends Linter.ExtendRuleData[]> implements DoctorPluginInstance<Compiler, Rules> {
6
+ export declare class RsdoctorRspackPlugin<Rules extends Linter.ExtendRuleData[]> implements RsdoctorPluginInstance<Compiler, Rules> {
7
7
  readonly name = "RsdoctorRspackPlugin";
8
- readonly sdk: DoctorWebpackSDK;
8
+ readonly sdk: RsdoctorWebpackSDK;
9
9
  _bootstrapTask: Promise<unknown>;
10
10
  protected browserIsOpened: boolean;
11
11
  modulesGraph: ModuleGraph;
12
- options: DoctorPluginOptionsNormalized<Rules>;
13
- constructor(options?: DoctorRspackPluginOptions<Rules>);
12
+ options: RsdoctorPluginOptionsNormalized<Rules>;
13
+ constructor(options?: RsdoctorRspackPluginOptions<Rules>);
14
14
  apply(compiler: unknown): unknown;
15
+ /**
16
+ * @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
17
+ * @param {Compiler} compiler
18
+ * @return {*}
19
+ * @memberof RsdoctorWebpackPlugin
20
+ */
21
+ ensureModulesChunksGraphApplied(compiler: Compiler): void;
15
22
  done: (compiler: Compiler) => Promise<void>;
16
- ensureModulesChunksGraphApplied(): void;
23
+ getRspackConfig(compiler: Compiler, version: string): void;
17
24
  }
package/dist/plugin.js CHANGED
@@ -31,41 +31,36 @@ __export(plugin_exports, {
31
31
  RsdoctorRspackPlugin: () => RsdoctorRspackPlugin
32
32
  });
33
33
  module.exports = __toCommonJS(plugin_exports);
34
- var import_fs = __toESM(require("fs"));
35
34
  var import_graph = require("@rsdoctor/graph");
36
35
  var import_sdk = require("@rsdoctor/sdk");
37
- var import_build_utils = require("@rsdoctor/core/build-utils");
38
36
  var import_plugins = require("@rsdoctor/core/plugins");
39
37
  var import_types = require("@rsdoctor/types");
40
38
  var import_path = __toESM(require("path"));
41
- var import_common_utils = require("@rsdoctor/core/common-utils");
42
39
  var import_constants = require("./constants");
40
+ var import_lodash = require("lodash");
41
+ var import_builtinLoaderPlugin = require("./builtinLoaderPlugin");
43
42
  class RsdoctorRspackPlugin {
44
43
  constructor(options) {
45
44
  this.name = import_constants.pluginTapName;
46
45
  this.browserIsOpened = false;
47
46
  this.done = async (compiler) => {
48
- const json = compiler.compilation.getStats().toJson();
49
- const { chunkGraph, moduleGraph } = await import_common_utils.TransUtils.transStats(json);
47
+ const json = compiler.compilation.getStats().toJson({
48
+ all: false,
49
+ version: true,
50
+ chunks: true,
51
+ modules: true,
52
+ chunkModules: true,
53
+ assets: true,
54
+ builtAt: true,
55
+ chunkRelations: true
56
+ });
57
+ this.getRspackConfig(compiler, json.rspackVersion || "");
50
58
  await this.sdk.bootstrap();
51
- this.sdk.reportChunkGraph(chunkGraph);
52
- this.sdk.reportModuleGraph(moduleGraph);
53
59
  this.sdk.addClientRoutes([
54
- import_types.Manifest.DoctorManifestClientRoutes.Overall,
55
- import_types.Manifest.DoctorManifestClientRoutes.BundleSize,
56
- import_types.Manifest.DoctorManifestClientRoutes.ModuleGraph
60
+ import_types.Manifest.RsdoctorManifestClientRoutes.Overall
57
61
  ]);
58
- const reportFilePath = await import_build_utils.Chunks.generateTileGraph(
59
- json,
60
- {
61
- reportFilename: import_build_utils.Chunks.TileGraphReportName,
62
- reportTitle: "webpack-bundle-analyzer"
63
- },
64
- compiler.outputPath
65
- );
66
- reportFilePath && await this.sdk.reportTileHtml(import_fs.default.readFileSync(reportFilePath, "utf-8"));
67
62
  this.sdk.setOutputDir(
68
- import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.DoctorOutputFolder}`)
63
+ import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
69
64
  );
70
65
  await this.sdk.writeStore();
71
66
  if (!this.options.disableClientServer) {
@@ -76,7 +71,7 @@ class RsdoctorRspackPlugin {
76
71
  }
77
72
  };
78
73
  this.options = (0, import_plugins.normalizeUserConfig)(options);
79
- this.sdk = new import_sdk.DoctorWebpackSDK({
74
+ this.sdk = new import_sdk.RsdoctorWebpackSDK({
80
75
  name: import_constants.pluginTapName,
81
76
  root: process.cwd(),
82
77
  type: import_types.SDK.ToDataType.Normal,
@@ -103,8 +98,43 @@ class RsdoctorRspackPlugin {
103
98
  if (this.options.features.plugins) {
104
99
  new import_plugins.InternalPluginsPlugin(this).apply(compiler);
105
100
  }
101
+ if (this.options.features.bundle) {
102
+ new import_plugins.InternalBundlePlugin(this).apply(compiler);
103
+ }
104
+ new import_plugins.InternalRulesPlugin(this).apply(compiler);
105
+ new import_builtinLoaderPlugin.BuiltinLoaderPlugin().apply(compiler);
106
106
  }
107
- ensureModulesChunksGraphApplied() {
107
+ /**
108
+ * @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
109
+ * @param {Compiler} compiler
110
+ * @return {*}
111
+ * @memberof RsdoctorWebpackPlugin
112
+ */
113
+ ensureModulesChunksGraphApplied(compiler) {
114
+ (0, import_plugins.ensureModulesChunksGraphFn)(compiler, this);
115
+ }
116
+ getRspackConfig(compiler, version) {
117
+ if (compiler.isChild())
118
+ return;
119
+ const { plugins, infrastructureLogging, ...rest } = compiler.options;
120
+ const _rest = (0, import_lodash.cloneDeep)(rest);
121
+ (0, import_plugins.makeRulesSerializable)(_rest.module.defaultRules);
122
+ (0, import_plugins.makeRulesSerializable)(_rest.module.rules);
123
+ const configuration = {
124
+ ..._rest,
125
+ plugins: plugins.map((e) => e?.constructor.name)
126
+ };
127
+ this.sdk.reportConfiguration({
128
+ name: "rspack",
129
+ version: version || "unknown",
130
+ config: configuration
131
+ });
132
+ this.sdk.setOutputDir(
133
+ import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
134
+ );
135
+ if (configuration.name) {
136
+ this.sdk.setName(configuration.name);
137
+ }
108
138
  }
109
139
  }
110
140
  // Annotate the CommonJS export names for ESM import in node:
@@ -0,0 +1,4 @@
1
+ import { Plugin } from '@rsdoctor/types';
2
+ import { LoaderDefinitionFunction } from "@rspack/core";
3
+ declare const loaderModule: Plugin.LoaderDefinition<Parameters<LoaderDefinitionFunction>, {}>;
4
+ export default loaderModule;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var probeLoader_exports = {};
30
+ __export(probeLoader_exports, {
31
+ default: () => probeLoader_default
32
+ });
33
+ module.exports = __toCommonJS(probeLoader_exports);
34
+ var import_plugins = require("@rsdoctor/core/plugins");
35
+ var import_loader_utils = require("loader-utils");
36
+ var import_lodash = require("lodash");
37
+ var import_path = __toESM(require("path"));
38
+ const loaderModule = function(...args) {
39
+ const time = Date.now();
40
+ const code = args[0];
41
+ const sdk = (0, import_plugins.getSDK)();
42
+ const _options = this.getOptions();
43
+ const loaderData = {
44
+ resource: {
45
+ path: this.resourcePath,
46
+ query: (0, import_loader_utils.parseQuery)(this.resourceQuery || "?"),
47
+ queryRaw: this.resourceQuery,
48
+ ext: import_path.default.extname(this.resourcePath).slice(1)
49
+ },
50
+ loaders: [
51
+ {
52
+ loader: _options.loader,
53
+ loaderIndex: this.loaderIndex,
54
+ path: _options.loader,
55
+ input: _options.type === "start" ? code : null,
56
+ result: _options.type === "end" ? code : null,
57
+ startAt: _options.type === "start" ? time : 0,
58
+ endAt: _options.type === "end" ? time : 0,
59
+ options: (0, import_lodash.omit)(_options.options, "type"),
60
+ isPitch: false,
61
+ sync: false,
62
+ errors: [],
63
+ pid: process.pid,
64
+ ppid: process.ppid
65
+ }
66
+ ]
67
+ };
68
+ sdk.reportLoaderStartOrEnd(loaderData);
69
+ this.callback(null, ...args);
70
+ };
71
+ var probeLoader_default = loaderModule;
@@ -1,6 +1,6 @@
1
1
  import type { RspackPluginInstance } from '@rspack/core';
2
- import type { DoctorWebpackPluginOptions } from '@rsdoctor/core/types';
3
- export interface DoctorRspackPluginOptions {
2
+ import type { RsdoctorWebpackPluginOptions } from '@rsdoctor/core/types';
3
+ export interface RsdoctorRspackPluginOptions {
4
4
  /**
5
5
  * turn on it if you don't need to see profile in browser.
6
6
  * @default false
@@ -9,12 +9,12 @@ export interface DoctorRspackPluginOptions {
9
9
  /**
10
10
  * the switch for the Rsdoctor features.
11
11
  */
12
- features?: DoctorWebpackPluginOptions<[]>['features'];
12
+ features?: RsdoctorWebpackPluginOptions<[]>['features'];
13
13
  /**
14
14
  * configuration of the interceptor for webpack loaders.
15
15
  * @description worked when the `features.loader === true`.
16
16
  */
17
- loaderInterceptorOptions?: DoctorWebpackPluginOptions<[]>['loaderInterceptorOptions'];
17
+ loaderInterceptorOptions?: RsdoctorWebpackPluginOptions<[]>['loaderInterceptorOptions'];
18
18
  }
19
19
  export interface RsdoctorRspackPluginInstance extends RspackPluginInstance {
20
20
  readonly name: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsdoctor/rspack-plugin",
3
- "version": "0.0.2-beta.1",
3
+ "version": "0.1.0-beta",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/rsdoctor",
@@ -13,19 +13,21 @@
13
13
  "dist"
14
14
  ],
15
15
  "dependencies": {
16
- "@rspack/core": "0.3.14",
16
+ "@rspack/core": "0.5.1",
17
+ "loader-utils": "^2.0.4",
17
18
  "lodash": "^4.17.21",
18
- "@rsdoctor/sdk": "0.0.2-beta.1",
19
- "@rsdoctor/core": "0.0.2-beta.1",
20
- "@rsdoctor/graph": "0.0.2-beta.1"
19
+ "@rsdoctor/core": "0.1.0-beta",
20
+ "@rsdoctor/graph": "0.1.0-beta",
21
+ "@rsdoctor/sdk": "0.1.0-beta"
21
22
  },
22
23
  "devDependencies": {
24
+ "@types/loader-utils": "^2.0.5",
23
25
  "@types/lodash": "^4.14.200",
24
26
  "@types/node": "^16",
25
27
  "@types/tapable": "2.2.2",
26
28
  "tslib": "2.4.1",
27
29
  "typescript": "^5.2.2",
28
- "@rsdoctor/types": "0.0.2-beta.1"
30
+ "@rsdoctor/types": "0.1.0-beta"
29
31
  },
30
32
  "publishConfig": {
31
33
  "access": "public",