@rsdoctor/rspack-plugin 0.0.2-beta.2 → 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.
- package/dist/builtinLoaderPlugin.d.ts +4 -0
- package/dist/builtinLoaderPlugin.js +63 -0
- package/dist/plugin.js +2 -11
- package/dist/probeLoader.d.ts +4 -0
- package/dist/probeLoader.js +71 -0
- package/package.json +7 -5
|
@@ -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.js
CHANGED
|
@@ -31,15 +31,14 @@ __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
39
|
var import_constants = require("./constants");
|
|
42
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;
|
|
@@ -60,15 +59,6 @@ class RsdoctorRspackPlugin {
|
|
|
60
59
|
this.sdk.addClientRoutes([
|
|
61
60
|
import_types.Manifest.RsdoctorManifestClientRoutes.Overall
|
|
62
61
|
]);
|
|
63
|
-
const reportFilePath = await import_build_utils.Chunks.generateTileGraph(
|
|
64
|
-
json,
|
|
65
|
-
{
|
|
66
|
-
reportFilename: import_build_utils.Chunks.TileGraphReportName,
|
|
67
|
-
reportTitle: "webpack-bundle-analyzer"
|
|
68
|
-
},
|
|
69
|
-
compiler.outputPath
|
|
70
|
-
);
|
|
71
|
-
reportFilePath && await this.sdk.reportTileHtml(import_fs.default.readFileSync(reportFilePath, "utf-8"));
|
|
72
62
|
this.sdk.setOutputDir(
|
|
73
63
|
import_path.default.resolve(compiler.outputPath, `./${import_types.Constants.RsdoctorOutputFolder}`)
|
|
74
64
|
);
|
|
@@ -112,6 +102,7 @@ class RsdoctorRspackPlugin {
|
|
|
112
102
|
new import_plugins.InternalBundlePlugin(this).apply(compiler);
|
|
113
103
|
}
|
|
114
104
|
new import_plugins.InternalRulesPlugin(this).apply(compiler);
|
|
105
|
+
new import_builtinLoaderPlugin.BuiltinLoaderPlugin().apply(compiler);
|
|
115
106
|
}
|
|
116
107
|
/**
|
|
117
108
|
* @description Generate ModuleGraph and ChunkGraph from stats and webpack module apis;
|
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/rspack-plugin",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0-beta",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -14,18 +14,20 @@
|
|
|
14
14
|
],
|
|
15
15
|
"dependencies": {
|
|
16
16
|
"@rspack/core": "0.5.1",
|
|
17
|
+
"loader-utils": "^2.0.4",
|
|
17
18
|
"lodash": "^4.17.21",
|
|
18
|
-
"@rsdoctor/core": "0.0
|
|
19
|
-
"@rsdoctor/
|
|
20
|
-
"@rsdoctor/
|
|
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
|
|
30
|
+
"@rsdoctor/types": "0.1.0-beta"
|
|
29
31
|
},
|
|
30
32
|
"publishConfig": {
|
|
31
33
|
"access": "public",
|