@rsdoctor/webpack-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,42 @@
1
+ # Rsdoctor plugin
2
+
3
+ This Rsdoctor plugin is an analysis plugin for the Webpack 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 `Webpack` repo to open Rsdoctor, [Quik Start](https://rsdoctor.dev/guide/start/quick-start).
15
+
16
+ Initialize the RsdoctorWebpackPlugin plugin in the [plugins](https://webpack.js.org/configuration/plugins/#plugins) section of the `webpack.config.js` file, as shown below:
17
+
18
+ ```js title="webpack.config.js"
19
+ const { RsdoctorWebpackPlugin } = require('@rsdoctor/webpack-plugin');
20
+
21
+ module.exports = {
22
+ // ...
23
+ plugins: [
24
+ process.env.RSDOCTOR &&
25
+ new RsdoctorWebpackPlugin({
26
+ // options
27
+ }),
28
+ ].filter(Boolean),
29
+ };
30
+ ```
31
+
32
+ ## Documentation
33
+
34
+ https://rsdoctor.dev/
35
+
36
+ ## Contributing
37
+
38
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/rsdoctor/blob/main/CONTRIBUTING.md).
39
+
40
+ ## License
41
+
42
+ Rsdoctor is [MIT licensed](https://github.com/web-infra-dev/rsdoctor/blob/main/LICENSE).
@@ -0,0 +1,7 @@
1
+ import type { Tap } from 'tapable';
2
+ export declare const pluginTapName = "RsdoctorWebpackPlugin";
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
+ //# 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,0BAA0B,CAAC;AAErD,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"}
@@ -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 constants_exports = {};
20
+ __export(constants_exports, {
21
+ internalPluginTapPostOptions: () => internalPluginTapPostOptions,
22
+ internalPluginTapPreOptions: () => internalPluginTapPreOptions,
23
+ pluginTapName: () => pluginTapName,
24
+ pluginTapPostOptions: () => pluginTapPostOptions,
25
+ pluginTapPreOptions: () => pluginTapPreOptions
26
+ });
27
+ module.exports = __toCommonJS(constants_exports);
28
+ const pluginTapName = "RsdoctorWebpackPlugin";
29
+ const pluginTapPostOptions = {
30
+ name: pluginTapName,
31
+ stage: 999
32
+ };
33
+ const pluginTapPreOptions = {
34
+ name: pluginTapName,
35
+ stage: -999
36
+ };
37
+ const internalPluginTapPreOptions = (namespace) => ({
38
+ name: `${pluginTapName}:${namespace}`,
39
+ stage: -998
40
+ });
41
+ const internalPluginTapPostOptions = (namespace) => ({
42
+ name: `${pluginTapName}:${namespace}`,
43
+ stage: 1e3
44
+ });
45
+ // Annotate the CommonJS export names for ESM import in node:
46
+ 0 && (module.exports = {
47
+ internalPluginTapPostOptions,
48
+ internalPluginTapPreOptions,
49
+ pluginTapName,
50
+ pluginTapPostOptions,
51
+ pluginTapPreOptions
52
+ });
@@ -0,0 +1,4 @@
1
+ export * from './plugin';
2
+ export * from './multiple';
3
+ export { defineRule, LinterType } from '@rsdoctor/core/rules';
4
+ //# 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;AAE3B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ LinterType: () => import_rules.LinterType,
23
+ defineRule: () => import_rules.defineRule
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ __reExport(src_exports, require("./plugin"), module.exports);
27
+ __reExport(src_exports, require("./multiple"), module.exports);
28
+ var import_rules = require("@rsdoctor/core/rules");
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ LinterType,
32
+ defineRule,
33
+ ...require("./plugin"),
34
+ ...require("./multiple")
35
+ });
@@ -0,0 +1,8 @@
1
+ import type { Linter } from '@rsdoctor/types';
2
+ import type { RsdoctorMultiplePluginOptions } from '@rsdoctor/core';
3
+ import { RsdoctorWebpackPlugin } from './plugin';
4
+ export declare class RsdoctorWebpackMultiplePlugin<Rules extends Linter.ExtendRuleData[]> extends RsdoctorWebpackPlugin<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,qBAAqB,EAAE,MAAM,UAAU,CAAC;AAIjD,qBAAa,6BAA6B,CACxC,KAAK,SAAS,MAAM,CAAC,cAAc,EAAE,CACrC,SAAQ,qBAAqB,CAAC,KAAK,CAAC;IAEpC,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
+ RsdoctorWebpackMultiplePlugin: () => RsdoctorWebpackMultiplePlugin
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 RsdoctorWebpackMultiplePlugin extends import_plugin.RsdoctorWebpackPlugin {
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
+ RsdoctorWebpackMultiplePlugin
52
+ });
@@ -0,0 +1,28 @@
1
+ import type { RsdoctorPluginInstance, RsdoctorPluginOptionsNormalized, RsdoctorWebpackPluginOptions } from '@rsdoctor/core/types';
2
+ import { ChunkGraph, ModuleGraph } from '@rsdoctor/graph';
3
+ import { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
4
+ import { Linter } from '@rsdoctor/types';
5
+ import type { 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
+ modulesGraph: ModuleGraph;
11
+ private outsideInstance;
12
+ _bootstrapTask: Promise<unknown>;
13
+ protected browserIsOpened: boolean;
14
+ chunkGraph: ChunkGraph;
15
+ constructor(options?: RsdoctorWebpackPluginOptions<Rules>);
16
+ apply(compiler: unknown): unknown;
17
+ afterPlugins: (compiler: Compiler) => void;
18
+ beforeRun: (compiler: Compiler) => Promise<void>;
19
+ /**
20
+ * @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
21
+ * @param {Compiler} compiler
22
+ * @return {*}
23
+ * @memberof RsdoctorWebpackPlugin
24
+ */
25
+ ensureModulesChunksGraphApplied(compiler: Compiler): void;
26
+ done: () => Promise<void>;
27
+ }
28
+ //# 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,EACV,sBAAsB,EACtB,+BAA+B,EAC/B,4BAA4B,EAC7B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAa,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAKpD,OAAO,KAAK,EAAE,QAAQ,EAA8B,MAAM,SAAS,CAAC;AAOpE,qBAAa,qBAAqB,CAAC,KAAK,SAAS,MAAM,CAAC,cAAc,EAAE,CACtE,YAAW,sBAAsB,CAAC,QAAQ,EAAE,KAAK,CAAC;IAElD,SAAgB,IAAI,2BAAiB;IAErC,SAAgB,OAAO,EAAE,+BAA+B,CAAC,KAAK,CAAC,CAAC;IAEhE,SAAgB,GAAG,EAAE,kBAAkB,CAAC;IAEjC,YAAY,EAAE,WAAW,CAAC;IAEjC,OAAO,CAAC,eAAe,CAAS;IAEzB,cAAc,EAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzC,SAAS,CAAC,eAAe,UAAS;IAE3B,UAAU,EAAE,UAAU,CAAC;gBAElB,OAAO,CAAC,EAAE,4BAA4B,CAAC,KAAK,CAAC;IAkBzD,KAAK,CAAC,QAAQ,EAAE,OAAO,GAAG,OAAO;IAuD1B,YAAY,aAAc,QAAQ,KAAG,IAAI,CAiC9C;IAEK,SAAS,aAAoB,QAAQ,KAAG,QAAQ,IAAI,CAAC,CAS1D;IAEF;;;;;OAKG;IACI,+BAA+B,CAAC,QAAQ,EAAE,QAAQ;IAIlD,IAAI,QAAa,QAAQ,IAAI,CAAC,CAYnC;CACH"}
package/dist/plugin.js ADDED
@@ -0,0 +1,160 @@
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
+ RsdoctorWebpackPlugin: () => RsdoctorWebpackPlugin
32
+ });
33
+ module.exports = __toCommonJS(plugin_exports);
34
+ var import_plugins = require("@rsdoctor/core/plugins");
35
+ var import_graph = require("@rsdoctor/graph");
36
+ var import_sdk = require("@rsdoctor/sdk");
37
+ var import_types = require("@rsdoctor/types");
38
+ var import_build = require("@rsdoctor/utils/build");
39
+ var import_logger = require("@rsdoctor/utils/logger");
40
+ var import_lodash = require("lodash");
41
+ var import_path = __toESM(require("path"));
42
+ var import_constants = require("./constants");
43
+ var import_resolver = require("./plugins/resolver");
44
+ var import_plugins2 = require("@rsdoctor/core/plugins");
45
+ var import_common = require("@rsdoctor/utils/common");
46
+ class RsdoctorWebpackPlugin {
47
+ constructor(options) {
48
+ this.name = import_constants.pluginTapName;
49
+ this.outsideInstance = false;
50
+ this.browserIsOpened = false;
51
+ this.afterPlugins = (compiler) => {
52
+ if (compiler.isChild())
53
+ return;
54
+ const { plugins, infrastructureLogging, ...rest } = compiler.options;
55
+ const _rest = (0, import_lodash.cloneDeep)(rest);
56
+ (0, import_plugins.makeRulesSerializable)(_rest.module.defaultRules);
57
+ (0, import_plugins.makeRulesSerializable)(_rest.module.rules);
58
+ const configuration = {
59
+ ..._rest,
60
+ plugins: plugins.map((e) => e?.constructor.name)
61
+ };
62
+ const rspackVersion = compiler.webpack?.rspackVersion;
63
+ const webpackVersion = compiler.webpack?.version;
64
+ this.sdk.reportConfiguration({
65
+ name: rspackVersion ? "rspack" : "webpack",
66
+ version: rspackVersion || webpackVersion || "unknown",
67
+ config: configuration
68
+ });
69
+ this.sdk.setOutputDir(
70
+ import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
71
+ );
72
+ if (configuration.name) {
73
+ this.sdk.setName(configuration.name);
74
+ }
75
+ };
76
+ this.beforeRun = async (compiler) => {
77
+ if (compiler.isChild())
78
+ return;
79
+ await this._bootstrapTask.then(() => {
80
+ if (!this.options.disableClientServer && !this.browserIsOpened) {
81
+ this.browserIsOpened = true;
82
+ this.sdk.server.openClientPage();
83
+ }
84
+ });
85
+ };
86
+ this.done = async () => {
87
+ try {
88
+ this.sdk.server.broadcast();
89
+ (0, import_logger.debug)(import_build.Process.getMemoryUsageMessage, "[Before Write Manifest]");
90
+ await this.sdk.writeStore();
91
+ (0, import_logger.debug)(import_build.Process.getMemoryUsageMessage, "[After Write Manifest]");
92
+ if (this.options.disableClientServer) {
93
+ await this.sdk.dispose();
94
+ (0, import_logger.debug)(import_build.Process.getMemoryUsageMessage, "[After SDK Dispose]");
95
+ }
96
+ } catch (e) {
97
+ }
98
+ };
99
+ this.options = (0, import_plugins.normalizeUserConfig)(options);
100
+ this.sdk = this.options.sdkInstance ?? new import_sdk.RsdoctorWebpackSDK({
101
+ port: this.options.port,
102
+ name: import_constants.pluginTapName,
103
+ root: process.cwd(),
104
+ type: this.options.reportCodeType,
105
+ config: { disableTOSUpload: this.options.disableTOSUpload },
106
+ innerClientPath: this.options.innerClientPath
107
+ });
108
+ this.outsideInstance = Boolean(this.options.sdkInstance);
109
+ this.modulesGraph = new import_graph.ModuleGraph();
110
+ this.chunkGraph = new import_graph.ChunkGraph();
111
+ }
112
+ apply(compiler) {
113
+ if (!this._bootstrapTask) {
114
+ this._bootstrapTask = this.sdk.bootstrap();
115
+ }
116
+ if (!this.outsideInstance) {
117
+ (0, import_plugins.setSDK)(this.sdk);
118
+ }
119
+ new import_plugins.InternalSummaryPlugin(this).apply(compiler);
120
+ if (this.options.features.loader && !import_common.Loader.isVue(compiler)) {
121
+ new import_plugins.InternalLoaderPlugin(this).apply(compiler);
122
+ }
123
+ if (this.options.features.resolver) {
124
+ new import_resolver.InternalResolverPlugin(this).apply(compiler);
125
+ }
126
+ if (this.options.features.plugins) {
127
+ new import_plugins.InternalPluginsPlugin(this).apply(compiler);
128
+ }
129
+ if (this.options.features.bundle) {
130
+ new import_plugins.InternalBundlePlugin(this).apply(compiler);
131
+ new import_plugins.InternalBundleTagPlugin(this).apply(compiler);
132
+ }
133
+ new import_plugins.InternalErrorReporterPlugin(this).apply(compiler);
134
+ new import_plugins.InternalRulesPlugin(this).apply(compiler);
135
+ new import_plugins.InternalProgressPlugin(this).apply(compiler);
136
+ compiler.hooks.afterPlugins.tap(import_constants.pluginTapPostOptions, this.afterPlugins);
137
+ compiler.hooks.watchRun.tapPromise(import_constants.pluginTapPostOptions, this.beforeRun);
138
+ compiler.hooks.beforeRun.tapPromise(import_constants.pluginTapPostOptions, this.beforeRun);
139
+ compiler.hooks.done.tapPromise(
140
+ {
141
+ ...import_constants.pluginTapPostOptions,
142
+ stage: import_constants.pluginTapPostOptions.stage + 100
143
+ },
144
+ this.done.bind(this)
145
+ );
146
+ }
147
+ /**
148
+ * @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
149
+ * @param {Compiler} compiler
150
+ * @return {*}
151
+ * @memberof RsdoctorWebpackPlugin
152
+ */
153
+ ensureModulesChunksGraphApplied(compiler) {
154
+ (0, import_plugins2.ensureModulesChunksGraphFn)(compiler, this);
155
+ }
156
+ }
157
+ // Annotate the CommonJS export names for ESM import in node:
158
+ 0 && (module.exports = {
159
+ RsdoctorWebpackPlugin
160
+ });
@@ -0,0 +1,39 @@
1
+ import { InternalBasePlugin } from '@rsdoctor/core/plugins';
2
+ import { RsdoctorWebpackSDK } from '@rsdoctor/sdk';
3
+ import { SDK } from '@rsdoctor/types';
4
+ import type { Compiler, ResolvePluginInstance, Resolver } from 'webpack';
5
+ interface RsdoctorResolverPluginOptions {
6
+ }
7
+ interface ResolveRequestContext {
8
+ issuer: string;
9
+ }
10
+ interface ResolveRequestWithContext {
11
+ [key: string]: unknown;
12
+ context: ResolveRequestContext;
13
+ }
14
+ export declare class RsdoctorResolverPlugin implements ResolvePluginInstance {
15
+ protected options: RsdoctorResolverPluginOptions;
16
+ protected sdk: RsdoctorWebpackSDK;
17
+ protected tapOptions: {
18
+ name: string;
19
+ };
20
+ protected contextMap: Map<string, [number, [number, number]]>;
21
+ constructor(options: RsdoctorResolverPluginOptions, sdk: RsdoctorWebpackSDK);
22
+ protected getResolverData(context: ResolveRequestContext, params: {
23
+ request: string;
24
+ query?: string;
25
+ result?: string;
26
+ error?: Error;
27
+ stacks?: SDK.ResolveStackData[];
28
+ }): SDK.PathResolverData | undefined;
29
+ protected getResolveStackData(request: ResolveRequestWithContext, path: string, name?: string): SDK.ResolveStackData;
30
+ protected getResolveRequest(request: string | undefined, ctx?: Parameters<Resolver['resolve']>[3]): string;
31
+ apply(resolver: Resolver): void;
32
+ }
33
+ export declare class InternalResolverPlugin extends InternalBasePlugin<Compiler> {
34
+ readonly name = "resolver";
35
+ apply(compiler: Compiler): void;
36
+ afterPlugins: (compiler: Compiler) => void;
37
+ }
38
+ export {};
39
+ //# sourceMappingURL=resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../src/plugins/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAY,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,KAAK,EAAE,QAAQ,EAAE,qBAAqB,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEzE,UAAU,6BAA6B;CAAG;AAE1C,UAAU,qBAAqB;IAC7B,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,UAAU,yBAAyB;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,qBAAqB,CAAC;CAChC;AAED,qBAAa,sBAAuB,YAAW,qBAAqB;IAQhE,SAAS,CAAC,OAAO,EAAE,6BAA6B;IAChD,SAAS,CAAC,GAAG,EAAE,kBAAkB;IARnC,SAAS,CAAC,UAAU;;MAElB;IAEF,SAAS,CAAC,UAAU,0CAAiD;gBAGzD,OAAO,EAAE,6BAA6B,EACtC,GAAG,EAAE,kBAAkB;IAGnC,SAAS,CAAC,eAAe,CACvB,OAAO,EAAE,qBAAqB,EAC9B,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,KAAK,CAAC,EAAE,KAAK,CAAC;QACd,MAAM,CAAC,EAAE,GAAG,CAAC,gBAAgB,EAAE,CAAC;KACjC;IAiCH,SAAS,CAAC,mBAAmB,CAC3B,OAAO,EAAE,yBAAyB,EAClC,IAAI,EAAE,MAAM,EACZ,IAAI,SAAc;IA2BpB,SAAS,CAAC,iBAAiB,CACzB,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,GAAG,CAAC,EAAE,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;IAwB1C,KAAK,CAAC,QAAQ,EAAE,QAAQ;CA4DzB;AAED,qBAAa,sBAAuB,SAAQ,kBAAkB,CAAC,QAAQ,CAAC;IACtE,SAAgB,IAAI,cAAc;IAE3B,KAAK,CAAC,QAAQ,EAAE,QAAQ;IAMxB,YAAY,aAAc,QAAQ,UAYvC;CACH"}
@@ -0,0 +1,177 @@
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 resolver_exports = {};
30
+ __export(resolver_exports, {
31
+ InternalResolverPlugin: () => InternalResolverPlugin,
32
+ RsdoctorResolverPlugin: () => RsdoctorResolverPlugin
33
+ });
34
+ module.exports = __toCommonJS(resolver_exports);
35
+ var import_plugins = require("@rsdoctor/core/plugins");
36
+ var import_types = require("@rsdoctor/types");
37
+ var import_common = require("@rsdoctor/utils/common");
38
+ var import_path = __toESM(require("path"));
39
+ class RsdoctorResolverPlugin {
40
+ constructor(options, sdk) {
41
+ this.options = options;
42
+ this.sdk = sdk;
43
+ this.tapOptions = {
44
+ name: "RsdoctorResolverPlugin"
45
+ };
46
+ this.contextMap = /* @__PURE__ */ new Map();
47
+ }
48
+ getResolverData(context, params) {
49
+ const ctx = this.contextMap.get(context.issuer);
50
+ if (!ctx)
51
+ return;
52
+ const { request, query, result, error, stacks } = params;
53
+ const [start, startHRTime] = ctx;
54
+ const data = {
55
+ isEntry: Boolean(context.issuer),
56
+ issuerPath: context.issuer || "",
57
+ request,
58
+ startAt: start,
59
+ endAt: import_common.Time.getCurrentTimestamp(start, startHRTime),
60
+ pid: process.pid,
61
+ ppid: process.ppid
62
+ };
63
+ if (query) {
64
+ data.query = query;
65
+ }
66
+ if (result) {
67
+ data.result = result;
68
+ }
69
+ if (error) {
70
+ data.error = error;
71
+ data.stacks = stacks || [];
72
+ }
73
+ return data;
74
+ }
75
+ getResolveStackData(request, path2, name = "anonymous") {
76
+ const data = {
77
+ name,
78
+ // issuerPath: request.context.issuer,
79
+ path: path2
80
+ };
81
+ const keys = [
82
+ "request",
83
+ "query",
84
+ "fragment",
85
+ "file",
86
+ "module",
87
+ "directory",
88
+ "internal"
89
+ ];
90
+ keys.forEach((key) => {
91
+ if (request[key]) {
92
+ data[key] = request[key];
93
+ }
94
+ });
95
+ return data;
96
+ }
97
+ getResolveRequest(request, ctx) {
98
+ if (request)
99
+ return request;
100
+ if (ctx?.stack) {
101
+ const [target] = [...ctx.stack].map((e) => e.split(" ").map((e2) => e2.trim())).filter((e) => e.length > 2);
102
+ if (target) {
103
+ return target[target.length - 1];
104
+ }
105
+ }
106
+ return "";
107
+ }
108
+ apply(resolver) {
109
+ resolver.hooks.result.tap(this.tapOptions, (request, rsctx) => {
110
+ const { context } = request;
111
+ const ctx = this.contextMap.get(context.issuer);
112
+ if (ctx) {
113
+ const data = this.getResolverData(context, {
114
+ request: this.getResolveRequest(request.request, rsctx),
115
+ query: request.query,
116
+ result: request.path
117
+ });
118
+ data && this.sdk.reportResolver([data]);
119
+ }
120
+ });
121
+ resolver.hooks.noResolve.tap(this.tapOptions, (request, error) => {
122
+ const { context } = request;
123
+ if (context.issuer) {
124
+ const resolvedPaths = new Set(
125
+ error.details.split("\n").map((e) => e.trim().split(" ")[0]).filter((e) => import_path.default.isAbsolute(e))
126
+ );
127
+ if (resolvedPaths.size) {
128
+ if (this.contextMap.has(context.issuer)) {
129
+ const stacks = [...resolvedPaths].map(
130
+ (e) => this.getResolveStackData(
131
+ request,
132
+ e,
133
+ "noResolve"
134
+ )
135
+ );
136
+ const data = this.getResolverData(context, {
137
+ request: this.getResolveRequest(request.request),
138
+ query: request.query,
139
+ error,
140
+ stacks
141
+ });
142
+ data && this.sdk.reportResolver([data]);
143
+ }
144
+ }
145
+ }
146
+ });
147
+ resolver.hooks.resolveStep.tap(this.tapOptions, (_, request) => {
148
+ const { context } = request;
149
+ if (context.issuer && !this.contextMap.has(context.issuer)) {
150
+ this.contextMap.set(context.issuer, [Date.now(), process.hrtime()]);
151
+ }
152
+ });
153
+ }
154
+ }
155
+ class InternalResolverPlugin extends import_plugins.InternalBasePlugin {
156
+ constructor() {
157
+ super(...arguments);
158
+ this.name = "resolver";
159
+ this.afterPlugins = (compiler) => {
160
+ if (compiler.isChild())
161
+ return;
162
+ compiler.options.resolve.plugins = (compiler.options.resolve.plugins ?? []).concat(new RsdoctorResolverPlugin({}, this.sdk));
163
+ this.sdk.addClientRoutes([
164
+ import_types.Manifest.RsdoctorManifestClientRoutes.ModuleResolve
165
+ ]);
166
+ };
167
+ }
168
+ apply(compiler) {
169
+ this.scheduler.ensureModulesChunksGraphApplied(compiler);
170
+ compiler.hooks.afterPlugins.tap(this.tapPostOptions, this.afterPlugins);
171
+ }
172
+ }
173
+ // Annotate the CommonJS export names for ESM import in node:
174
+ 0 && (module.exports = {
175
+ InternalResolverPlugin,
176
+ RsdoctorResolverPlugin
177
+ });
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@rsdoctor/webpack-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/webpack-plugin"
8
+ },
9
+ "license": "MIT",
10
+ "main": "dist/index.js",
11
+ "types": "dist/index.d.ts",
12
+ "files": [
13
+ "dist"
14
+ ],
15
+ "dependencies": {
16
+ "fs-extra": "^11.1.1",
17
+ "lodash": "^4.17.21",
18
+ "@rsdoctor/core": "0.0.0-next-20240620044732",
19
+ "@rsdoctor/sdk": "0.0.0-next-20240620044732",
20
+ "@rsdoctor/utils": "0.0.0-next-20240620044732",
21
+ "@rsdoctor/graph": "0.0.0-next-20240620044732",
22
+ "@rsdoctor/types": "0.0.0-next-20240620044732"
23
+ },
24
+ "devDependencies": {
25
+ "webpack": "^5.89.0",
26
+ "@types/fs-extra": "^11.0.2",
27
+ "@types/lodash": "^4.17.0",
28
+ "@types/node": "^16",
29
+ "@types/tapable": "2.2.2",
30
+ "@types/webpack": "5.28.0",
31
+ "tslib": "2.4.1",
32
+ "typescript": "^5.2.2"
33
+ },
34
+ "peerDependencies": {
35
+ "webpack": "5.x"
36
+ },
37
+ "publishConfig": {
38
+ "access": "public",
39
+ "provenance": true,
40
+ "registry": "https://registry.npmjs.org/"
41
+ },
42
+ "scripts": {
43
+ "dev": "npm run start",
44
+ "build": "modern build",
45
+ "start": "modern build -w",
46
+ "test": "vitest run"
47
+ }
48
+ }