@rsdoctor/core 0.1.0 → 0.1.1
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/README.md
CHANGED
|
@@ -1,11 +1,18 @@
|
|
|
1
|
-
# Rsdoctor
|
|
1
|
+
# Rsdoctor Core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This is the core package of Rsdoctor, providing core tools and analysis capabilities for Rsdoctor plugins.
|
|
4
4
|
|
|
5
|
-
|
|
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.
|
|
6
11
|
|
|
7
12
|
## Documentation
|
|
8
13
|
|
|
14
|
+
https://rsdoctor.dev/
|
|
15
|
+
|
|
9
16
|
## Contributing
|
|
10
17
|
|
|
11
18
|
Please read the [Contributing Guide](https://github.com/web-infra-dev/rsdoctor/blob/main/CONTRIBUTING.md).
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Common, Plugin } from '@rsdoctor/types';
|
|
3
3
|
import { SourceMapInput as WebpackSourceMapInput } from '../../../types';
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function parsePathQueryFragment(str: string): {
|
|
5
|
+
path: string;
|
|
6
|
+
query: string;
|
|
7
|
+
fragment: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function loadLoaderModule(loaderPath: string, cwd?: string): {
|
|
5
10
|
default: Plugin.LoaderDefinition<Common.PlainObject, {}>;
|
|
6
11
|
pitch: Plugin.PitchLoaderDefinitionFunction;
|
|
7
12
|
raw: boolean | void;
|
|
@@ -9,4 +14,5 @@ export declare function loadLoaderModule(p: string, cwd?: string): {
|
|
|
9
14
|
export declare function getLoaderOptions<T>(loaderContext: Plugin.LoaderContext<T>): T;
|
|
10
15
|
export declare function extractLoaderName(loaderPath: string, cwd?: string): string;
|
|
11
16
|
export declare function mapEachRules<T extends Plugin.BuildRuleSetRule>(rules: T[], callback: (rule: T) => T): T[];
|
|
17
|
+
export declare function changeBuiltinLoader<T extends Plugin.BuildRuleSetRule>(rules: T[], loaderName: string, appendRules: (rule: T, index: number) => T): T[];
|
|
12
18
|
export declare function createLoaderContextTrap(this: Plugin.LoaderContext<Common.PlainObject>, final: (err: Error | null | undefined, res: string | Buffer | null, sourceMap?: WebpackSourceMapInput) => void): Plugin.LoaderContext<Common.PlainObject<any>>;
|
|
@@ -28,19 +28,31 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var loader_exports = {};
|
|
30
30
|
__export(loader_exports, {
|
|
31
|
+
changeBuiltinLoader: () => changeBuiltinLoader,
|
|
31
32
|
createLoaderContextTrap: () => createLoaderContextTrap,
|
|
32
33
|
extractLoaderName: () => extractLoaderName,
|
|
33
34
|
getLoaderOptions: () => getLoaderOptions,
|
|
34
35
|
loadLoaderModule: () => loadLoaderModule,
|
|
35
|
-
mapEachRules: () => mapEachRules
|
|
36
|
+
mapEachRules: () => mapEachRules,
|
|
37
|
+
parsePathQueryFragment: () => parsePathQueryFragment
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(loader_exports);
|
|
38
40
|
var import_loader_utils = require("loader-utils");
|
|
39
41
|
var import_path = __toESM(require("path"));
|
|
40
42
|
var import_lodash = require("lodash");
|
|
41
43
|
var import_common = require("@rsdoctor/utils/common");
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\0.|[^?#\0])*)(\?(?:\0.|[^#\0])*)?(#.*)?$/;
|
|
45
|
+
function parsePathQueryFragment(str) {
|
|
46
|
+
const match = PATH_QUERY_FRAGMENT_REGEXP.exec(str);
|
|
47
|
+
return {
|
|
48
|
+
path: match?.[1].replace(/\0(.)/g, "$1") || "",
|
|
49
|
+
query: match?.[2] ? match[2].replace(/\0(.)/g, "$1") : "",
|
|
50
|
+
fragment: match?.[3] || ""
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function loadLoaderModule(loaderPath, cwd = process.cwd()) {
|
|
54
|
+
const cleanLoaderPath = parsePathQueryFragment(loaderPath).path;
|
|
55
|
+
const mod = process.env.DOCTOR_TEST ? require(import_path.default.resolve(cwd, cleanLoaderPath)) : require(require.resolve(cleanLoaderPath, {
|
|
44
56
|
paths: [cwd, import_path.default.resolve(cwd, "node_modules")]
|
|
45
57
|
}));
|
|
46
58
|
const isESM = mod.__esModule && typeof mod.default === "function";
|
|
@@ -104,6 +116,17 @@ function mapEachRules(rules, callback) {
|
|
|
104
116
|
)
|
|
105
117
|
};
|
|
106
118
|
}
|
|
119
|
+
if (typeof rule.use === "function") {
|
|
120
|
+
const funcUse = rule.use;
|
|
121
|
+
const newRule = {
|
|
122
|
+
...rule,
|
|
123
|
+
use: (...args) => {
|
|
124
|
+
const rules2 = funcUse.apply(null, args);
|
|
125
|
+
return mapEachRules(rules2, callback);
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
return newRule;
|
|
129
|
+
}
|
|
107
130
|
if (Array.isArray(rule.use)) {
|
|
108
131
|
return {
|
|
109
132
|
...rule,
|
|
@@ -130,6 +153,68 @@ function mapEachRules(rules, callback) {
|
|
|
130
153
|
return rule;
|
|
131
154
|
});
|
|
132
155
|
}
|
|
156
|
+
function getLoaderNameMatch(_r, loaderName) {
|
|
157
|
+
return typeof _r === "object" && typeof _r?.loader === "string" && _r.loader === loaderName || typeof _r === "string" && _r === loaderName;
|
|
158
|
+
}
|
|
159
|
+
function changeBuiltinLoader(rules, loaderName, appendRules) {
|
|
160
|
+
return rules.map((rule) => {
|
|
161
|
+
if (!rule || typeof rule === "string")
|
|
162
|
+
return rule;
|
|
163
|
+
if (getLoaderNameMatch(rule, loaderName)) {
|
|
164
|
+
const _rule = {
|
|
165
|
+
...rule,
|
|
166
|
+
use: [
|
|
167
|
+
{
|
|
168
|
+
loader: rule.loader,
|
|
169
|
+
options: rule.options
|
|
170
|
+
}
|
|
171
|
+
],
|
|
172
|
+
loader: void 0,
|
|
173
|
+
options: void 0
|
|
174
|
+
};
|
|
175
|
+
return appendRules(_rule, 0);
|
|
176
|
+
}
|
|
177
|
+
if (rule.use) {
|
|
178
|
+
if (Array.isArray(rule.use)) {
|
|
179
|
+
const _index = (0, import_lodash.findIndex)(
|
|
180
|
+
rule.use,
|
|
181
|
+
(_r) => getLoaderNameMatch(_r, loaderName)
|
|
182
|
+
);
|
|
183
|
+
if (_index > -1) {
|
|
184
|
+
return appendRules(rule, _index);
|
|
185
|
+
}
|
|
186
|
+
} else if (typeof rule.use === "object" && !Array.isArray(rule.use) && typeof rule.use !== "function") {
|
|
187
|
+
rule.use = [
|
|
188
|
+
{
|
|
189
|
+
...rule.use
|
|
190
|
+
}
|
|
191
|
+
];
|
|
192
|
+
return appendRules(rule, 0);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if ("oneOf" in rule && rule.oneOf) {
|
|
196
|
+
return {
|
|
197
|
+
...rule,
|
|
198
|
+
oneOf: changeBuiltinLoader(
|
|
199
|
+
rule.oneOf,
|
|
200
|
+
loaderName,
|
|
201
|
+
appendRules
|
|
202
|
+
)
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
if ("rules" in rule && rule.rules) {
|
|
206
|
+
return {
|
|
207
|
+
...rule,
|
|
208
|
+
rules: changeBuiltinLoader(
|
|
209
|
+
rule.rules,
|
|
210
|
+
loaderName,
|
|
211
|
+
appendRules
|
|
212
|
+
)
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
return rule;
|
|
216
|
+
});
|
|
217
|
+
}
|
|
133
218
|
function createLoaderContextTrap(final) {
|
|
134
219
|
const cb = this.callback;
|
|
135
220
|
let callback = (...args) => {
|
|
@@ -168,7 +253,9 @@ function createLoaderContextTrap(final) {
|
|
|
168
253
|
if (options.hasOptions) {
|
|
169
254
|
return (0, import_lodash.omit)(target.query, [import_common.Loader.LoaderInternalPropertyName]);
|
|
170
255
|
}
|
|
171
|
-
|
|
256
|
+
const innerLoaderPath = options?.loader;
|
|
257
|
+
const loaderQuery = parsePathQueryFragment(innerLoaderPath).query;
|
|
258
|
+
return loaderQuery;
|
|
172
259
|
}
|
|
173
260
|
}
|
|
174
261
|
return Reflect.get(target, key, receiver);
|
|
@@ -199,9 +286,11 @@ function createLoaderContextTrap(final) {
|
|
|
199
286
|
}
|
|
200
287
|
// Annotate the CommonJS export names for ESM import in node:
|
|
201
288
|
0 && (module.exports = {
|
|
289
|
+
changeBuiltinLoader,
|
|
202
290
|
createLoaderContextTrap,
|
|
203
291
|
extractLoaderName,
|
|
204
292
|
getLoaderOptions,
|
|
205
293
|
loadLoaderModule,
|
|
206
|
-
mapEachRules
|
|
294
|
+
mapEachRules,
|
|
295
|
+
parsePathQueryFragment
|
|
207
296
|
});
|
|
@@ -36,7 +36,6 @@ var import_lodash = require("lodash");
|
|
|
36
36
|
var import_path = __toESM(require("path"));
|
|
37
37
|
var import_logger = require("@rsdoctor/utils/logger");
|
|
38
38
|
var import_module_graph = require("../module-graph");
|
|
39
|
-
const logger = (0, import_logger.createLogger)();
|
|
40
39
|
async function getAssetsModulesData(bundleStats, bundleDir, opts) {
|
|
41
40
|
const { parseBundle = () => ({}) } = opts || {};
|
|
42
41
|
if ((0, import_lodash.isEmpty)(bundleStats.assets) && !(0, import_lodash.isEmpty)(bundleStats.children)) {
|
|
@@ -72,7 +71,7 @@ async function getAssetsModulesData(bundleStats, bundleDir, opts) {
|
|
|
72
71
|
} catch (err) {
|
|
73
72
|
const { code = "", message } = err;
|
|
74
73
|
const msg = code === "ENOENT" ? "no such file" : message;
|
|
75
|
-
process.env.DEVTOOLS_NODE_DEV === "1" && logger.warn(`Error parsing bundle asset "${assetFile}": ${msg}`);
|
|
74
|
+
process.env.DEVTOOLS_NODE_DEV === "1" && import_logger.logger.warn(`Error parsing bundle asset "${assetFile}": ${msg}`);
|
|
76
75
|
continue;
|
|
77
76
|
}
|
|
78
77
|
bundlesSources[statAsset.name] = (0, import_lodash.pick)(bundleInfo, "src", "runtimeSrc");
|
|
@@ -81,7 +80,7 @@ async function getAssetsModulesData(bundleStats, bundleDir, opts) {
|
|
|
81
80
|
if ((0, import_lodash.isEmpty)(bundlesSources)) {
|
|
82
81
|
bundlesSources = null;
|
|
83
82
|
parsedModules = null;
|
|
84
|
-
process.env.DEVTOOLS_DEV && logger.warn(
|
|
83
|
+
process.env.DEVTOOLS_DEV && import_logger.logger.warn(
|
|
85
84
|
"\nNo bundles were parsed. Analyzer will show only original module sizes from stats file.\n"
|
|
86
85
|
);
|
|
87
86
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"semver": "^7.5.4",
|
|
52
52
|
"source-map": "^0.7.4",
|
|
53
53
|
"webpack-bundle-analyzer": "^4.9.1",
|
|
54
|
-
"@rsdoctor/
|
|
55
|
-
"@rsdoctor/
|
|
56
|
-
"@rsdoctor/
|
|
57
|
-
"@rsdoctor/utils": "0.1.
|
|
54
|
+
"@rsdoctor/sdk": "0.1.1",
|
|
55
|
+
"@rsdoctor/graph": "0.1.1",
|
|
56
|
+
"@rsdoctor/types": "0.1.1",
|
|
57
|
+
"@rsdoctor/utils": "0.1.1"
|
|
58
58
|
},
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@types/bytes": "3.1.1",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"tslib": "2.4.1",
|
|
74
74
|
"typescript": "^5.2.2",
|
|
75
75
|
"webpack": "^5.89.0",
|
|
76
|
-
"@rsdoctor/test-helper": "0.1.
|
|
76
|
+
"@rsdoctor/test-helper": "0.1.1"
|
|
77
77
|
},
|
|
78
78
|
"publishConfig": {
|
|
79
79
|
"access": "public",
|