@rsdoctor/rspack-plugin 0.0.0-next-20240620044732

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Rsdoctor plugin
2
+
3
+ This Rsdoctor plugin is an analysis plugin for the Rspack builder.
4
+
5
+ ## features
6
+
7
+ - Rsdoctor is a one-stop tool for diagnosing and analyzing the build process and build artifacts.
8
+ - Rsdoctor is a tool that supports Webpack and Rspack build analysis.
9
+ - Rsdoctor is an analysis tool that can display the time-consuming and behavioral details of the compilation.
10
+ - Rsdoctor is a tool that provides bundle Diff and other anti-degradation capabilities simultaneously.
11
+
12
+ ## Note
13
+
14
+ This plugin is used by the `Rspack` repo to open Rsdoctor, [Quik Start](https://rsdoctor.dev/guide/start/quick-start).
15
+
16
+ Initialize the RsdoctorRspackPlugin in the [plugins](https://www.rspack.dev/config/plugins.html#plugins) of `rspack.config.js`:
17
+
18
+ ```js title="rspack.config.js"
19
+ const { RsdoctorRspackPlugin } = require('@rsdoctor/rspack-plugin');
20
+
21
+ module.exports = {
22
+ // ...
23
+ plugins: [
24
+ // Only register the plugin when RSDOCTOR is true, as the plugin will increase the build time.
25
+ process.env.RSDOCTOR &&
26
+ new RsdoctorRspackPlugin({
27
+ // plugin options
28
+ }),
29
+ ].filter(Boolean),
30
+ };
31
+ ```
32
+
33
+ ## Documentation
34
+
35
+ https://rsdoctor.dev/
36
+
37
+ ## Contributing
38
+
39
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/rsdoctor/blob/main/CONTRIBUTING.md).
40
+
41
+ ## License
42
+
43
+ Rsdoctor is [MIT licensed](https://github.com/web-infra-dev/rsdoctor/blob/main/LICENSE).
@@ -0,0 +1,8 @@
1
+ import type { Tap } from 'tapable';
2
+ export declare const pluginTapName = "RsdoctorRspackPlugin";
3
+ export declare const pluginTapPostOptions: Tap;
4
+ export declare const pluginTapPreOptions: Tap;
5
+ export declare const internalPluginTapPreOptions: (namespace: string) => Tap;
6
+ export declare const internalPluginTapPostOptions: (namespace: string) => Tap;
7
+ export declare const pkg: any;
8
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAEnC,eAAO,MAAM,aAAa,yBAAyB,CAAC;AAEpD,eAAO,MAAM,oBAAoB,EAAE,GAGlC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,GAGjC,CAAC;AAEF,eAAO,MAAM,2BAA2B,cAAe,MAAM,KAAG,GAG9D,CAAC;AAEH,eAAO,MAAM,4BAA4B,cAAe,MAAM,KAAG,GAG/D,CAAC;AAEH,eAAO,MAAM,GAAG,KAA6B,CAAC"}
@@ -0,0 +1,55 @@
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 constants_exports = {};
20
+ __export(constants_exports, {
21
+ internalPluginTapPostOptions: () => internalPluginTapPostOptions,
22
+ internalPluginTapPreOptions: () => internalPluginTapPreOptions,
23
+ pkg: () => pkg,
24
+ pluginTapName: () => pluginTapName,
25
+ pluginTapPostOptions: () => pluginTapPostOptions,
26
+ pluginTapPreOptions: () => pluginTapPreOptions
27
+ });
28
+ module.exports = __toCommonJS(constants_exports);
29
+ const pluginTapName = "RsdoctorRspackPlugin";
30
+ const pluginTapPostOptions = {
31
+ name: pluginTapName,
32
+ stage: 999
33
+ };
34
+ const pluginTapPreOptions = {
35
+ name: pluginTapName,
36
+ stage: -999
37
+ };
38
+ const internalPluginTapPreOptions = (namespace) => ({
39
+ name: `${pluginTapName}:${namespace}`,
40
+ stage: -998
41
+ });
42
+ const internalPluginTapPostOptions = (namespace) => ({
43
+ name: `${pluginTapName}:${namespace}`,
44
+ stage: 1e3
45
+ });
46
+ const pkg = require("../package.json");
47
+ // Annotate the CommonJS export names for ESM import in node:
48
+ 0 && (module.exports = {
49
+ internalPluginTapPostOptions,
50
+ internalPluginTapPreOptions,
51
+ pkg,
52
+ pluginTapName,
53
+ pluginTapPostOptions,
54
+ pluginTapPreOptions
55
+ });
@@ -0,0 +1,3 @@
1
+ export * from './plugin';
2
+ export * from './multiple';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var src_exports = {};
17
+ module.exports = __toCommonJS(src_exports);
18
+ __reExport(src_exports, require("./plugin"), module.exports);
19
+ __reExport(src_exports, require("./multiple"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./plugin"),
23
+ ...require("./multiple")
24
+ });
@@ -0,0 +1,8 @@
1
+ import type { Linter } from '@rsdoctor/types';
2
+ import type { RsdoctorMultiplePluginOptions } from '@rsdoctor/core';
3
+ import { RsdoctorRspackPlugin } from './plugin';
4
+ export declare class RsdoctorRspackMultiplePlugin<Rules extends Linter.ExtendRuleData[]> extends RsdoctorRspackPlugin<Rules> {
5
+ private controller;
6
+ constructor(options?: RsdoctorMultiplePluginOptions<Rules>);
7
+ }
8
+ //# sourceMappingURL=multiple.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiple.d.ts","sourceRoot":"","sources":["../src/multiple.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAEpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAIhD,qBAAa,4BAA4B,CACvC,KAAK,SAAS,MAAM,CAAC,cAAc,EAAE,CACrC,SAAQ,oBAAoB,CAAC,KAAK,CAAC;IAEnC,OAAO,CAAC,UAAU,CAAwB;gBAE9B,OAAO,GAAE,6BAA6B,CAAC,KAAK,CAAM;CAuB/D"}
@@ -0,0 +1,52 @@
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 multiple_exports = {};
20
+ __export(multiple_exports, {
21
+ RsdoctorRspackMultiplePlugin: () => RsdoctorRspackMultiplePlugin
22
+ });
23
+ module.exports = __toCommonJS(multiple_exports);
24
+ var import_sdk = require("@rsdoctor/sdk");
25
+ var import_plugin = require("./plugin");
26
+ let globalController;
27
+ class RsdoctorRspackMultiplePlugin extends import_plugin.RsdoctorRspackPlugin {
28
+ constructor(options = {}) {
29
+ const controller = (() => {
30
+ if (globalController) {
31
+ return globalController;
32
+ }
33
+ const controller2 = new import_sdk.RsdoctorSDKController();
34
+ globalController = controller2;
35
+ return controller2;
36
+ })();
37
+ const instance = controller.createSlave({
38
+ name: options.name || "Builder",
39
+ stage: options.stage,
40
+ extraConfig: { disableTOSUpload: options.disableTOSUpload || false }
41
+ });
42
+ super({
43
+ ...options,
44
+ sdkInstance: instance
45
+ });
46
+ this.controller = controller;
47
+ }
48
+ }
49
+ // Annotate the CommonJS export names for ESM import in node:
50
+ 0 && (module.exports = {
51
+ RsdoctorRspackMultiplePlugin
52
+ });
@@ -0,0 +1,26 @@
1
+ import type { Compiler } from '@rspack/core';
2
+ import { ModuleGraph } from '@rsdoctor/graph';
3
+ import { RsdoctorSlaveSDK, RsdoctorWebpackSDK } from '@rsdoctor/sdk';
4
+ import type { RsdoctorPluginInstance, RsdoctorPluginOptionsNormalized, RsdoctorRspackPluginOptions } from '@rsdoctor/core';
5
+ import { Linter } from '@rsdoctor/types';
6
+ export declare class RsdoctorRspackPlugin<Rules extends Linter.ExtendRuleData[]> implements RsdoctorPluginInstance<Compiler, Rules> {
7
+ readonly name = "RsdoctorRspackPlugin";
8
+ readonly sdk: RsdoctorWebpackSDK | RsdoctorSlaveSDK;
9
+ _bootstrapTask: Promise<unknown>;
10
+ protected browserIsOpened: boolean;
11
+ modulesGraph: ModuleGraph;
12
+ options: RsdoctorPluginOptionsNormalized<Rules>;
13
+ outsideInstance: boolean;
14
+ constructor(options?: RsdoctorRspackPluginOptions<Rules>);
15
+ apply(compiler: unknown): unknown;
16
+ /**
17
+ * @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
18
+ * @param {Compiler} compiler
19
+ * @return {*}
20
+ * @memberof RsdoctorWebpackPlugin
21
+ */
22
+ ensureModulesChunksGraphApplied(compiler: Compiler): void;
23
+ done: (compiler: Compiler) => Promise<void>;
24
+ getRspackConfig(compiler: Compiler): void;
25
+ }
26
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAA8B,MAAM,cAAc,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAcrE,OAAO,KAAK,EACV,sBAAsB,EACtB,+BAA+B,EAC/B,2BAA2B,EAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAa,MAAM,EAA4B,MAAM,iBAAiB,CAAC;AAO9E,qBAAa,oBAAoB,CAAC,KAAK,SAAS,MAAM,CAAC,cAAc,EAAE,CACrE,YAAW,sBAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC;IAElD,SAAgB,IAAI,0BAAiB;IAErC,SAAgB,GAAG,EAAE,kBAAkB,GAAG,gBAAgB,CAAC;IAEpD,cAAc,EAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzC,SAAS,CAAC,eAAe,UAAS;IAE3B,YAAY,EAAE,WAAW,CAAC;IAE1B,OAAO,EAAE,+BAA+B,CAAC,KAAK,CAAC,CAAC;IAEhD,eAAe,EAAE,OAAO,CAAC;gBAEpB,OAAO,CAAC,EAAE,2BAA2B,CAAC,KAAK,CAAC;IAiBxD,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO;IA+CjC;;;;;OAKG;IACI,+BAA+B,CAAC,QAAQ,EAAE,QAAQ;IAIlD,IAAI,aAAoB,QAAQ,KAAG,QAAQ,IAAI,CAAC,CA6BrD;IAEK,eAAe,CAAC,QAAQ,EAAE,QAAQ;CA2B1C"}
package/dist/plugin.js ADDED
@@ -0,0 +1,149 @@
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 plugin_exports = {};
30
+ __export(plugin_exports, {
31
+ RsdoctorRspackPlugin: () => RsdoctorRspackPlugin
32
+ });
33
+ module.exports = __toCommonJS(plugin_exports);
34
+ var import_graph = require("@rsdoctor/graph");
35
+ var import_sdk = require("@rsdoctor/sdk");
36
+ var import_plugins = require("@rsdoctor/core/plugins");
37
+ var import_types = require("@rsdoctor/types");
38
+ var import_path = __toESM(require("path"));
39
+ var import_constants = require("./constants");
40
+ var import_lodash = require("lodash");
41
+ var import_probeLoaderPlugin = require("./probeLoaderPlugin");
42
+ var import_common = require("@rsdoctor/utils/common");
43
+ class RsdoctorRspackPlugin {
44
+ constructor(options) {
45
+ this.name = import_constants.pluginTapName;
46
+ this.browserIsOpened = false;
47
+ this.done = async (compiler) => {
48
+ this.getRspackConfig(compiler);
49
+ await this.sdk.bootstrap();
50
+ this.sdk.addClientRoutes([
51
+ import_types.Manifest.RsdoctorManifestClientRoutes.Overall
52
+ ]);
53
+ if (this.outsideInstance && "parent" in this.sdk) {
54
+ this.sdk.parent.master.setOutputDir(
55
+ import_path.default.resolve(
56
+ compiler.outputPath,
57
+ `./${import_types.Constants.RsdoctorOutputFolder}`
58
+ )
59
+ );
60
+ }
61
+ this.sdk.setOutputDir(
62
+ import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
63
+ );
64
+ await this.sdk.writeStore();
65
+ if (!this.options.disableClientServer) {
66
+ await this.sdk.server.openClientPage("homepage");
67
+ }
68
+ if (this.options.disableClientServer) {
69
+ await this.sdk.dispose();
70
+ }
71
+ };
72
+ this.options = (0, import_plugins.normalizeUserConfig)(options);
73
+ this.sdk = this.options.sdkInstance ?? new import_sdk.RsdoctorWebpackSDK({
74
+ port: this.options.port,
75
+ name: import_constants.pluginTapName,
76
+ root: process.cwd(),
77
+ type: this.options.reportCodeType,
78
+ config: { disableTOSUpload: this.options.disableTOSUpload },
79
+ innerClientPath: this.options.innerClientPath
80
+ });
81
+ this.outsideInstance = Boolean(this.options.sdkInstance);
82
+ this.modulesGraph = new import_graph.ModuleGraph();
83
+ }
84
+ apply(compiler) {
85
+ if (!this._bootstrapTask) {
86
+ this._bootstrapTask = this.sdk.bootstrap();
87
+ }
88
+ if (compiler.options.name) {
89
+ this.sdk.setName(compiler.options.name);
90
+ }
91
+ (0, import_plugins.setSDK)(this.sdk);
92
+ compiler.hooks.done.tapPromise(
93
+ {
94
+ ...import_constants.pluginTapPostOptions,
95
+ stage: import_constants.pluginTapPostOptions.stage + 100
96
+ },
97
+ this.done.bind(this, compiler)
98
+ );
99
+ new import_plugins.InternalSummaryPlugin(this).apply(compiler);
100
+ if (this.options.features.loader && !import_common.Loader.isVue(compiler)) {
101
+ new import_probeLoaderPlugin.ProbeLoaderPlugin().apply(compiler);
102
+ new import_plugins.InternalLoaderPlugin(this).apply(compiler);
103
+ }
104
+ if (this.options.features.plugins) {
105
+ new import_plugins.InternalPluginsPlugin(this).apply(compiler);
106
+ }
107
+ if (this.options.features.bundle) {
108
+ new import_plugins.InternalBundlePlugin(this).apply(compiler);
109
+ new import_plugins.InternalBundleTagPlugin(this).apply(compiler);
110
+ }
111
+ new import_plugins.InternalRulesPlugin(this).apply(compiler);
112
+ new import_plugins.InternalErrorReporterPlugin(this).apply(compiler);
113
+ }
114
+ /**
115
+ * @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
116
+ * @param {Compiler} compiler
117
+ * @return {*}
118
+ * @memberof RsdoctorWebpackPlugin
119
+ */
120
+ ensureModulesChunksGraphApplied(compiler) {
121
+ (0, import_plugins.ensureModulesChunksGraphFn)(compiler, this);
122
+ }
123
+ getRspackConfig(compiler) {
124
+ if (compiler.isChild())
125
+ return;
126
+ const { plugins, infrastructureLogging, ...rest } = compiler.options;
127
+ const _rest = (0, import_lodash.cloneDeep)(rest);
128
+ (0, import_plugins.makeRulesSerializable)(_rest.module.defaultRules);
129
+ (0, import_plugins.makeRulesSerializable)(_rest.module.rules);
130
+ const configuration = {
131
+ ..._rest,
132
+ plugins: plugins.map((e) => e?.constructor.name)
133
+ };
134
+ const rspackVersion = compiler.webpack?.rspackVersion;
135
+ const webpackVersion = compiler.webpack?.version;
136
+ this.sdk.reportConfiguration({
137
+ name: rspackVersion ? "rspack" : "webpack",
138
+ version: rspackVersion || webpackVersion || "unknown",
139
+ config: configuration
140
+ });
141
+ this.sdk.setOutputDir(
142
+ import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
143
+ );
144
+ }
145
+ }
146
+ // Annotate the CommonJS export names for ESM import in node:
147
+ 0 && (module.exports = {
148
+ RsdoctorRspackPlugin
149
+ });
@@ -0,0 +1,5 @@
1
+ import { Plugin } from '@rsdoctor/types';
2
+ import type { LoaderDefinitionFunction } from '@rspack/core';
3
+ declare const loaderModule: Plugin.LoaderDefinition<Parameters<LoaderDefinitionFunction>, {}>;
4
+ export default loaderModule;
5
+ //# sourceMappingURL=probeLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probeLoader.d.ts","sourceRoot":"","sources":["../src/probeLoader.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAO,MAAM,iBAAiB,CAAC;AAC9C,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAK7D,QAAA,MAAM,YAAY,EAAE,MAAM,CAAC,gBAAgB,CACzC,UAAU,CAAC,wBAAwB,CAAC,EACpC,EAAE,CAwCH,CAAC;AAEF,eAAe,YAAY,CAAC"}
@@ -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 _options = this.getOptions();
42
+ const sdk = (0, import_plugins.getSDK)(_options.builderName);
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;
@@ -0,0 +1,6 @@
1
+ import type { Compiler } from '@rspack/core';
2
+ export declare class ProbeLoaderPlugin {
3
+ apply(compiler: Compiler): void;
4
+ private addProbeLoader;
5
+ }
6
+ //# sourceMappingURL=probeLoaderPlugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"probeLoaderPlugin.d.ts","sourceRoot":"","sources":["../src/probeLoaderPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAS7C,qBAAa,iBAAiB;IAC5B,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAoBxB,OAAO,CAAC,cAAc;CA0CvB"}
@@ -0,0 +1,98 @@
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 probeLoaderPlugin_exports = {};
30
+ __export(probeLoaderPlugin_exports, {
31
+ ProbeLoaderPlugin: () => ProbeLoaderPlugin
32
+ });
33
+ module.exports = __toCommonJS(probeLoaderPlugin_exports);
34
+ var import_build_utils = require("@rsdoctor/core/build-utils");
35
+ var import_path = __toESM(require("path"));
36
+ const BuiltinLoaderName = "builtin:swc-loader";
37
+ const ESMLoaderFile = ".mjs";
38
+ class ProbeLoaderPlugin {
39
+ apply(compiler) {
40
+ compiler.hooks.beforeRun.tap(
41
+ {
42
+ name: "ProbeLoaderPlugin"
43
+ },
44
+ () => {
45
+ this.addProbeLoader(compiler);
46
+ }
47
+ );
48
+ compiler.hooks.watchRun.tap(
49
+ {
50
+ name: "ProbeLoaderPlugin"
51
+ },
52
+ () => {
53
+ this.addProbeLoader(compiler);
54
+ }
55
+ );
56
+ }
57
+ addProbeLoader(compiler) {
58
+ const rules = compiler.options.module.rules;
59
+ const appendRule = (rule, index) => {
60
+ if ("use" in rule && Array.isArray(rule.use)) {
61
+ const _builtinRule = rule.use[index];
62
+ const _options = typeof _builtinRule.options === "string" ? {} : { ..._builtinRule };
63
+ rule.use.splice(index, 0, {
64
+ loader: import_path.default.join(__dirname, "./probeLoader.js"),
65
+ options: {
66
+ ..._options,
67
+ type: "end",
68
+ builderName: compiler.options.name
69
+ }
70
+ });
71
+ rule.use.splice(index + 2, 0, {
72
+ loader: import_path.default.join(__dirname, "./probeLoader.js"),
73
+ options: {
74
+ ..._options,
75
+ type: "start",
76
+ builderName: compiler.options.name
77
+ }
78
+ });
79
+ }
80
+ return rule;
81
+ };
82
+ compiler.options.module.rules = import_build_utils.Utils.addProbeLoader2Rules(
83
+ rules,
84
+ BuiltinLoaderName,
85
+ appendRule
86
+ );
87
+ compiler.options.module.rules = import_build_utils.Utils.addProbeLoader2Rules(
88
+ rules,
89
+ ESMLoaderFile,
90
+ appendRule,
91
+ false
92
+ );
93
+ }
94
+ }
95
+ // Annotate the CommonJS export names for ESM import in node:
96
+ 0 && (module.exports = {
97
+ ProbeLoaderPlugin
98
+ });
@@ -0,0 +1,23 @@
1
+ import type { RspackPluginInstance } from '@rspack/core';
2
+ import type { RsdoctorWebpackPluginOptions } from '@rsdoctor/core/types';
3
+ export interface RsdoctorRspackPluginOptions {
4
+ /**
5
+ * turn on it if you don't need to see profile in browser.
6
+ * @default false
7
+ */
8
+ disableClientServer?: boolean;
9
+ /**
10
+ * the switch for the Rsdoctor features.
11
+ */
12
+ features?: RsdoctorWebpackPluginOptions<[]>['features'];
13
+ /**
14
+ * configuration of the interceptor for webpack loaders.
15
+ * @description worked when the `features.loader === true`.
16
+ */
17
+ loaderInterceptorOptions?: RsdoctorWebpackPluginOptions<[
18
+ ]>['loaderInterceptorOptions'];
19
+ }
20
+ export interface RsdoctorRspackPluginInstance extends RspackPluginInstance {
21
+ readonly name: string;
22
+ }
23
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACzD,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAC;AAEzE,MAAM,WAAW,2BAA2B;IAC1C;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B;;OAEG;IACH,QAAQ,CAAC,EAAE,4BAA4B,CAAC,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;IACxD;;;OAGG;IACH,wBAAwB,CAAC,EAAE,4BAA4B,CACrD;KAAE,CACH,CAAC,0BAA0B,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,4BACf,SAAQ,oBAAoB;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB"}
@@ -0,0 +1,16 @@
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 __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@rsdoctor/rspack-plugin",
3
+ "version": "0.0.0-next-20240620044732",
4
+ "repository": {
5
+ "type": "git",
6
+ "url": "https://github.com/web-infra-dev/rsdoctor",
7
+ "directory": "packages/rspack-plugin"
8
+ },
9
+ "license": "MIT",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "loader-utils": "^2.0.4",
17
+ "lodash": "^4.17.21",
18
+ "@rsdoctor/core": "0.0.0-next-20240620044732",
19
+ "@rsdoctor/graph": "0.0.0-next-20240620044732",
20
+ "@rsdoctor/sdk": "0.0.0-next-20240620044732",
21
+ "@rsdoctor/utils": "0.0.0-next-20240620044732",
22
+ "@rsdoctor/types": "0.0.0-next-20240620044732"
23
+ },
24
+ "devDependencies": {
25
+ "@rspack/core": "0.6.5",
26
+ "@types/loader-utils": "^2.0.5",
27
+ "@types/lodash": "^4.17.0",
28
+ "@types/node": "^16",
29
+ "@types/tapable": "2.2.2",
30
+ "tslib": "2.4.1",
31
+ "typescript": "^5.2.2"
32
+ },
33
+ "peerDependencies": {
34
+ "@rspack/core": "0.x"
35
+ },
36
+ "publishConfig": {
37
+ "access": "public",
38
+ "provenance": true,
39
+ "registry": "https://registry.npmjs.org/"
40
+ },
41
+ "scripts": {
42
+ "dev": "npm run start",
43
+ "start": "modern build -w",
44
+ "build": "modern build",
45
+ "test": "vitest run"
46
+ }
47
+ }