@rsdoctor/rspack-plugin 0.0.2-beta.1 → 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.
- package/dist/plugin.d.ts +14 -7
- package/dist/plugin.js +50 -11
- package/dist/types/index.d.ts +4 -4
- package/package.json +6 -6
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 {
|
|
4
|
-
import type {
|
|
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
|
|
6
|
+
export declare class RsdoctorRspackPlugin<Rules extends Linter.ExtendRuleData[]> implements RsdoctorPluginInstance<Compiler, Rules> {
|
|
7
7
|
readonly name = "RsdoctorRspackPlugin";
|
|
8
|
-
readonly sdk:
|
|
8
|
+
readonly sdk: RsdoctorWebpackSDK;
|
|
9
9
|
_bootstrapTask: Promise<unknown>;
|
|
10
10
|
protected browserIsOpened: boolean;
|
|
11
11
|
modulesGraph: ModuleGraph;
|
|
12
|
-
options:
|
|
13
|
-
constructor(options?:
|
|
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
|
-
|
|
23
|
+
getRspackConfig(compiler: Compiler, version: string): void;
|
|
17
24
|
}
|
package/dist/plugin.js
CHANGED
|
@@ -38,22 +38,27 @@ var import_build_utils = require("@rsdoctor/core/build-utils");
|
|
|
38
38
|
var import_plugins = require("@rsdoctor/core/plugins");
|
|
39
39
|
var import_types = require("@rsdoctor/types");
|
|
40
40
|
var import_path = __toESM(require("path"));
|
|
41
|
-
var import_common_utils = require("@rsdoctor/core/common-utils");
|
|
42
41
|
var import_constants = require("./constants");
|
|
42
|
+
var import_lodash = require("lodash");
|
|
43
43
|
class RsdoctorRspackPlugin {
|
|
44
44
|
constructor(options) {
|
|
45
45
|
this.name = import_constants.pluginTapName;
|
|
46
46
|
this.browserIsOpened = false;
|
|
47
47
|
this.done = async (compiler) => {
|
|
48
|
-
const json = compiler.compilation.getStats().toJson(
|
|
49
|
-
|
|
48
|
+
const json = compiler.compilation.getStats().toJson({
|
|
49
|
+
all: false,
|
|
50
|
+
version: true,
|
|
51
|
+
chunks: true,
|
|
52
|
+
modules: true,
|
|
53
|
+
chunkModules: true,
|
|
54
|
+
assets: true,
|
|
55
|
+
builtAt: true,
|
|
56
|
+
chunkRelations: true
|
|
57
|
+
});
|
|
58
|
+
this.getRspackConfig(compiler, json.rspackVersion || "");
|
|
50
59
|
await this.sdk.bootstrap();
|
|
51
|
-
this.sdk.reportChunkGraph(chunkGraph);
|
|
52
|
-
this.sdk.reportModuleGraph(moduleGraph);
|
|
53
60
|
this.sdk.addClientRoutes([
|
|
54
|
-
import_types.Manifest.
|
|
55
|
-
import_types.Manifest.DoctorManifestClientRoutes.BundleSize,
|
|
56
|
-
import_types.Manifest.DoctorManifestClientRoutes.ModuleGraph
|
|
61
|
+
import_types.Manifest.RsdoctorManifestClientRoutes.Overall
|
|
57
62
|
]);
|
|
58
63
|
const reportFilePath = await import_build_utils.Chunks.generateTileGraph(
|
|
59
64
|
json,
|
|
@@ -65,7 +70,7 @@ class RsdoctorRspackPlugin {
|
|
|
65
70
|
);
|
|
66
71
|
reportFilePath && await this.sdk.reportTileHtml(import_fs.default.readFileSync(reportFilePath, "utf-8"));
|
|
67
72
|
this.sdk.setOutputDir(
|
|
68
|
-
import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.
|
|
73
|
+
import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
|
|
69
74
|
);
|
|
70
75
|
await this.sdk.writeStore();
|
|
71
76
|
if (!this.options.disableClientServer) {
|
|
@@ -76,7 +81,7 @@ class RsdoctorRspackPlugin {
|
|
|
76
81
|
}
|
|
77
82
|
};
|
|
78
83
|
this.options = (0, import_plugins.normalizeUserConfig)(options);
|
|
79
|
-
this.sdk = new import_sdk.
|
|
84
|
+
this.sdk = new import_sdk.RsdoctorWebpackSDK({
|
|
80
85
|
name: import_constants.pluginTapName,
|
|
81
86
|
root: process.cwd(),
|
|
82
87
|
type: import_types.SDK.ToDataType.Normal,
|
|
@@ -103,8 +108,42 @@ class RsdoctorRspackPlugin {
|
|
|
103
108
|
if (this.options.features.plugins) {
|
|
104
109
|
new import_plugins.InternalPluginsPlugin(this).apply(compiler);
|
|
105
110
|
}
|
|
111
|
+
if (this.options.features.bundle) {
|
|
112
|
+
new import_plugins.InternalBundlePlugin(this).apply(compiler);
|
|
113
|
+
}
|
|
114
|
+
new import_plugins.InternalRulesPlugin(this).apply(compiler);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
|
|
118
|
+
* @param {Compiler} compiler
|
|
119
|
+
* @return {*}
|
|
120
|
+
* @memberof RsdoctorWebpackPlugin
|
|
121
|
+
*/
|
|
122
|
+
ensureModulesChunksGraphApplied(compiler) {
|
|
123
|
+
(0, import_plugins.ensureModulesChunksGraphFn)(compiler, this);
|
|
106
124
|
}
|
|
107
|
-
|
|
125
|
+
getRspackConfig(compiler, version) {
|
|
126
|
+
if (compiler.isChild())
|
|
127
|
+
return;
|
|
128
|
+
const { plugins, infrastructureLogging, ...rest } = compiler.options;
|
|
129
|
+
const _rest = (0, import_lodash.cloneDeep)(rest);
|
|
130
|
+
(0, import_plugins.makeRulesSerializable)(_rest.module.defaultRules);
|
|
131
|
+
(0, import_plugins.makeRulesSerializable)(_rest.module.rules);
|
|
132
|
+
const configuration = {
|
|
133
|
+
..._rest,
|
|
134
|
+
plugins: plugins.map((e) => e?.constructor.name)
|
|
135
|
+
};
|
|
136
|
+
this.sdk.reportConfiguration({
|
|
137
|
+
name: "rspack",
|
|
138
|
+
version: version || "unknown",
|
|
139
|
+
config: configuration
|
|
140
|
+
});
|
|
141
|
+
this.sdk.setOutputDir(
|
|
142
|
+
import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
|
|
143
|
+
);
|
|
144
|
+
if (configuration.name) {
|
|
145
|
+
this.sdk.setName(configuration.name);
|
|
146
|
+
}
|
|
108
147
|
}
|
|
109
148
|
}
|
|
110
149
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RspackPluginInstance } from '@rspack/core';
|
|
2
|
-
import type {
|
|
3
|
-
export interface
|
|
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?:
|
|
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?:
|
|
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.
|
|
3
|
+
"version": "0.0.2-beta.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@rspack/core": "0.
|
|
16
|
+
"@rspack/core": "0.5.1",
|
|
17
17
|
"lodash": "^4.17.21",
|
|
18
|
-
"@rsdoctor/
|
|
19
|
-
"@rsdoctor/
|
|
20
|
-
"@rsdoctor/graph": "0.0.2-beta.
|
|
18
|
+
"@rsdoctor/core": "0.0.2-beta.2",
|
|
19
|
+
"@rsdoctor/sdk": "0.0.2-beta.2",
|
|
20
|
+
"@rsdoctor/graph": "0.0.2-beta.2"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
23
|
"@types/lodash": "^4.14.200",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"@types/tapable": "2.2.2",
|
|
26
26
|
"tslib": "2.4.1",
|
|
27
27
|
"typescript": "^5.2.2",
|
|
28
|
-
"@rsdoctor/types": "0.0.2-beta.
|
|
28
|
+
"@rsdoctor/types": "0.0.2-beta.2"
|
|
29
29
|
},
|
|
30
30
|
"publishConfig": {
|
|
31
31
|
"access": "public",
|