@rsdoctor/rspack-plugin 0.0.2-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,15 @@
1
+ # Rsdoctor
2
+
3
+ Rsdoctor is a tool for diagnosing and analyzing the build process and build artifacts to help developers quickly identify and solve problems.
4
+
5
+ It also supports Webpack and Rspack builders, as well as various build frameworks, such as Rsbuild.
6
+
7
+ ## Documentation
8
+
9
+ ## Contributing
10
+
11
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/rsdoctor/blob/main/CONTRIBUTING.md).
12
+
13
+ ## License
14
+
15
+ 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 = "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;
@@ -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 @@
1
+ export * from './plugin';
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
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
+ // Annotate the CommonJS export names for ESM import in node:
20
+ 0 && (module.exports = {
21
+ ...require("./plugin")
22
+ });
@@ -0,0 +1,17 @@
1
+ import { Compiler } from '@rspack/core';
2
+ import { ModuleGraph } from '@rsdoctor/graph';
3
+ import { DoctorWebpackSDK } from '@rsdoctor/sdk';
4
+ import type { DoctorPluginInstance, DoctorPluginOptionsNormalized, DoctorRspackPluginOptions } from '@rsdoctor/core/types';
5
+ import { Linter } from '@rsdoctor/types';
6
+ export declare class RsdoctorRspackPlugin<Rules extends Linter.ExtendRuleData[]> implements DoctorPluginInstance<Compiler, Rules> {
7
+ readonly name = "RsdoctorRspackPlugin";
8
+ readonly sdk: DoctorWebpackSDK;
9
+ _bootstrapTask: Promise<unknown>;
10
+ protected browserIsOpened: boolean;
11
+ modulesGraph: ModuleGraph;
12
+ options: DoctorPluginOptionsNormalized<Rules>;
13
+ constructor(options?: DoctorRspackPluginOptions<Rules>);
14
+ apply(compiler: unknown): unknown;
15
+ done: (compiler: Compiler) => Promise<void>;
16
+ ensureModulesChunksGraphApplied(): void;
17
+ }
package/dist/plugin.js ADDED
@@ -0,0 +1,113 @@
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_fs = __toESM(require("fs"));
35
+ var import_graph = require("@rsdoctor/graph");
36
+ var import_sdk = require("@rsdoctor/sdk");
37
+ var import_build_utils = require("@rsdoctor/core/build-utils");
38
+ var import_plugins = require("@rsdoctor/core/plugins");
39
+ var import_types = require("@rsdoctor/types");
40
+ var import_path = __toESM(require("path"));
41
+ var import_common_utils = require("@rsdoctor/core/common-utils");
42
+ var import_constants = require("./constants");
43
+ class RsdoctorRspackPlugin {
44
+ constructor(options) {
45
+ this.name = import_constants.pluginTapName;
46
+ this.browserIsOpened = false;
47
+ this.done = async (compiler) => {
48
+ const json = compiler.compilation.getStats().toJson();
49
+ const { chunkGraph, moduleGraph } = await import_common_utils.TransUtils.transStats(json);
50
+ await this.sdk.bootstrap();
51
+ this.sdk.reportChunkGraph(chunkGraph);
52
+ this.sdk.reportModuleGraph(moduleGraph);
53
+ this.sdk.addClientRoutes([
54
+ import_types.Manifest.DoctorManifestClientRoutes.Overall,
55
+ import_types.Manifest.DoctorManifestClientRoutes.BundleSize,
56
+ import_types.Manifest.DoctorManifestClientRoutes.ModuleGraph
57
+ ]);
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
+ this.sdk.setOutputDir(
68
+ import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.DoctorOutputFolder}`)
69
+ );
70
+ await this.sdk.writeStore();
71
+ if (!this.options.disableClientServer) {
72
+ await this.sdk.server.openClientPage("homepage");
73
+ }
74
+ if (this.options.disableClientServer) {
75
+ await this.sdk.dispose();
76
+ }
77
+ };
78
+ this.options = (0, import_plugins.normalizeUserConfig)(options);
79
+ this.sdk = new import_sdk.DoctorWebpackSDK({
80
+ name: import_constants.pluginTapName,
81
+ root: process.cwd(),
82
+ type: import_types.SDK.ToDataType.Normal,
83
+ config: { disableTOSUpload: this.options.disableTOSUpload }
84
+ });
85
+ this.modulesGraph = new import_graph.ModuleGraph();
86
+ }
87
+ apply(compiler) {
88
+ if (!this._bootstrapTask) {
89
+ this._bootstrapTask = this.sdk.bootstrap();
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) {
101
+ new import_plugins.InternalLoaderPlugin(this).apply(compiler);
102
+ }
103
+ if (this.options.features.plugins) {
104
+ new import_plugins.InternalPluginsPlugin(this).apply(compiler);
105
+ }
106
+ }
107
+ ensureModulesChunksGraphApplied() {
108
+ }
109
+ }
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ RsdoctorRspackPlugin
113
+ });
@@ -0,0 +1,21 @@
1
+ import type { RspackPluginInstance } from '@rspack/core';
2
+ import type { DoctorWebpackPluginOptions } from '@rsdoctor/core/types';
3
+ export interface DoctorRspackPluginOptions {
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?: DoctorWebpackPluginOptions<[]>['features'];
13
+ /**
14
+ * configuration of the interceptor for webpack loaders.
15
+ * @description worked when the `features.loader === true`.
16
+ */
17
+ loaderInterceptorOptions?: DoctorWebpackPluginOptions<[]>['loaderInterceptorOptions'];
18
+ }
19
+ export interface RsdoctorRspackPluginInstance extends RspackPluginInstance {
20
+ readonly name: string;
21
+ }
@@ -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,41 @@
1
+ {
2
+ "name": "@rsdoctor/rspack-plugin",
3
+ "version": "0.0.2-beta.0",
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
+ "@rspack/core": "0.3.14",
17
+ "lodash": "^4.17.21",
18
+ "@rsdoctor/sdk": "0.0.2-beta.0",
19
+ "@rsdoctor/graph": "0.0.2-beta.0",
20
+ "@rsdoctor/core": "0.0.2-beta.0"
21
+ },
22
+ "devDependencies": {
23
+ "@types/lodash": "^4.14.200",
24
+ "@types/node": "^16",
25
+ "@types/tapable": "2.2.2",
26
+ "tslib": "2.4.1",
27
+ "typescript": "^5.2.2",
28
+ "@rsdoctor/types": "0.0.2-beta.0"
29
+ },
30
+ "publishConfig": {
31
+ "access": "public",
32
+ "provenance": true,
33
+ "registry": "https://registry.npmjs.org/"
34
+ },
35
+ "scripts": {
36
+ "dev": "npm run start",
37
+ "start": "modern build -w",
38
+ "build": "modern build",
39
+ "test": "vitest run"
40
+ }
41
+ }