@rsdoctor/core 2.0.0-alpha.1 → 2.0.0-alpha.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/26.js +26163 -0
- package/dist/630.js +1269 -0
- package/dist/630.js.LICENSE.txt +7 -0
- package/dist/build-utils/build/chunks/assetsModules.d.ts +7 -1
- package/dist/build-utils/build/loader/probeLoader.d.ts +7 -2
- package/dist/build-utils/build/utils/parseBundle.d.ts +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +1725 -7
- package/dist/inner-plugins/constants.d.ts +1 -1
- package/dist/inner-plugins/plugins/base.d.ts +2 -2
- package/dist/logger.d.ts +2 -2
- package/dist/probe-loader.js +2 -0
- package/dist/proxy-loader.d.ts +1 -0
- package/dist/proxy-loader.js +48 -0
- package/dist/rslib-runtime.js +28 -0
- package/dist/rspack-plugin/constants.d.ts +1 -1
- package/dist/rules/rules/ecma-version-check/htmlParserStub.d.ts +3 -0
- package/dist/rules/rules/ecma-version-check/types.d.ts +13 -2
- package/dist/sdk/server/apis/base.d.ts +1 -1
- package/dist/sdk/server/socket/api.d.ts +1 -1
- package/dist/sdk/utils/date.d.ts +1 -0
- package/dist/types/loader.d.ts +1 -1
- package/package.json +20 -113
- package/dist/build-utils/build/chunks/assetsModules.js +0 -9
- package/dist/build-utils/build/chunks/index.js +0 -3
- package/dist/build-utils/build/chunks/rspack/transform.js +0 -44
- package/dist/build-utils/build/envinfo.js +0 -60
- package/dist/build-utils/build/file/cache.js +0 -24
- package/dist/build-utils/build/file/index.js +0 -5
- package/dist/build-utils/build/file/sharding.js +0 -38
- package/dist/build-utils/build/index.js +0 -12
- package/dist/build-utils/build/json.js +0 -67
- package/dist/build-utils/build/loader/index.js +0 -3
- package/dist/build-utils/build/loader/probeLoader.js +0 -44
- package/dist/build-utils/build/loader/probeLoaderPlugin.js +0 -32
- package/dist/build-utils/build/module-graph/index.js +0 -2
- package/dist/build-utils/build/module-graph/parser.js +0 -13
- package/dist/build-utils/build/module-graph/rspack/transform.js +0 -111
- package/dist/build-utils/build/module-graph/utils.js +0 -60
- package/dist/build-utils/build/process.js +0 -18
- package/dist/build-utils/build/server.js +0 -107
- package/dist/build-utils/build/utils/index.js +0 -4
- package/dist/build-utils/build/utils/loader.js +0 -267
- package/dist/build-utils/build/utils/parseBundle.js +0 -238
- package/dist/build-utils/build/utils/plugin.js +0 -21
- package/dist/build-utils/index.js +0 -13
- package/dist/collection.d.ts +0 -1
- package/dist/collection.js +0 -2
- package/dist/common/file.js +0 -8
- package/dist/common/global-config.js +0 -33
- package/dist/common/index.d.ts +0 -4
- package/dist/common/index.js +0 -6
- package/dist/common-browser.d.ts +0 -1
- package/dist/common-browser.js +0 -2
- package/dist/error/error.js +0 -143
- package/dist/error/index.js +0 -3
- package/dist/error/transform.js +0 -138
- package/dist/error/utils.js +0 -23
- package/dist/graph/index.d.ts +0 -1
- package/dist/graph/index.js +0 -2
- package/dist/inner-plugins/constants.js +0 -19
- package/dist/inner-plugins/index.js +0 -3
- package/dist/inner-plugins/loaders/proxy.js +0 -65
- package/dist/inner-plugins/plugins/base.js +0 -20
- package/dist/inner-plugins/plugins/bundle.js +0 -63
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +0 -74
- package/dist/inner-plugins/plugins/errors.js +0 -65
- package/dist/inner-plugins/plugins/index.js +0 -11
- package/dist/inner-plugins/plugins/loader.js +0 -108
- package/dist/inner-plugins/plugins/plugins.js +0 -40
- package/dist/inner-plugins/plugins/progress.js +0 -35
- package/dist/inner-plugins/plugins/resolver.js +0 -57
- package/dist/inner-plugins/plugins/rspack.js +0 -99
- package/dist/inner-plugins/plugins/rules.js +0 -64
- package/dist/inner-plugins/plugins/sourcemapTool.js +0 -230
- package/dist/inner-plugins/plugins/summary.js +0 -92
- package/dist/inner-plugins/utils/circleDetect.js +0 -16
- package/dist/inner-plugins/utils/config.js +0 -141
- package/dist/inner-plugins/utils/index.js +0 -8
- package/dist/inner-plugins/utils/loader.js +0 -134
- package/dist/inner-plugins/utils/normalize-config.js +0 -77
- package/dist/inner-plugins/utils/openBrowser.js +0 -55
- package/dist/inner-plugins/utils/plugin-common.js +0 -94
- package/dist/inner-plugins/utils/plugin.js +0 -70
- package/dist/inner-plugins/utils/sdk.js +0 -19
- package/dist/logger.js +0 -51
- package/dist/rspack-plugin/constants.js +0 -23
- package/dist/rspack-plugin/index.js +0 -3
- package/dist/rspack-plugin/multiple.js +0 -39
- package/dist/rspack-plugin/plugin.js +0 -133
- package/dist/rule-utils/document/document.js +0 -46
- package/dist/rule-utils/document/index.js +0 -4
- package/dist/rule-utils/document/server.js +0 -13
- package/dist/rule-utils/document/types.js +0 -1
- package/dist/rule-utils/index.js +0 -3
- package/dist/rule-utils/parser/asserts.js +0 -105
- package/dist/rule-utils/parser/index.js +0 -5
- package/dist/rule-utils/parser/parser.js +0 -24
- package/dist/rule-utils/parser/types.js +0 -8
- package/dist/rule-utils/parser/utils.js +0 -106
- package/dist/rules/index.js +0 -4
- package/dist/rules/linter.js +0 -36
- package/dist/rules/rule.js +0 -101
- package/dist/rules/rules/cjs-require/index.js +0 -50
- package/dist/rules/rules/cjs-require/types.js +0 -1
- package/dist/rules/rules/cross-chunks-package/index.js +0 -41
- package/dist/rules/rules/cross-chunks-package/types.js +0 -1
- package/dist/rules/rules/cross-chunks-package/utils.js +0 -7
- package/dist/rules/rules/default-import-check/index.js +0 -83
- package/dist/rules/rules/default-import-check/types.js +0 -1
- package/dist/rules/rules/default-import-check/utils.js +0 -52
- package/dist/rules/rules/duplicate-package/index.js +0 -39
- package/dist/rules/rules/duplicate-package/types.js +0 -24
- package/dist/rules/rules/duplicate-package/utils.js +0 -38
- package/dist/rules/rules/ecma-version-check/index.js +0 -53
- package/dist/rules/rules/ecma-version-check/types.js +0 -1
- package/dist/rules/rules/ecma-version-check/utils.js +0 -6
- package/dist/rules/rules/esm-resolved-to-cjs/index.js +0 -193
- package/dist/rules/rules/esm-resolved-to-cjs/types.js +0 -1
- package/dist/rules/rules/index.js +0 -22
- package/dist/rules/rules/loader-performance-optimization/index.js +0 -86
- package/dist/rules/rules/loader-performance-optimization/types.js +0 -1
- package/dist/rules/rules/loader-performance-optimization/utils.js +0 -10
- package/dist/rules/rules/module-mixed-chunks/index.js +0 -52
- package/dist/rules/rules/module-mixed-chunks/types.js +0 -1
- package/dist/rules/rules/side-effects-only-imports/index.js +0 -81
- package/dist/rules/rules/side-effects-only-imports/types.js +0 -1
- package/dist/rules/utils.js +0 -10
- package/dist/sdk/index.js +0 -3
- package/dist/sdk/multiple/controller.js +0 -42
- package/dist/sdk/multiple/index.js +0 -3
- package/dist/sdk/multiple/primary.js +0 -64
- package/dist/sdk/multiple/server.js +0 -14
- package/dist/sdk/sdk/core.js +0 -163
- package/dist/sdk/sdk/index.js +0 -435
- package/dist/sdk/sdk/types.js +0 -1
- package/dist/sdk/server/apis/alerts.js +0 -30
- package/dist/sdk/server/apis/base.js +0 -22
- package/dist/sdk/server/apis/bundle-diff.js +0 -51
- package/dist/sdk/server/apis/data.js +0 -44
- package/dist/sdk/server/apis/fs.js +0 -28
- package/dist/sdk/server/apis/graph.js +0 -116
- package/dist/sdk/server/apis/index.js +0 -11
- package/dist/sdk/server/apis/loader.js +0 -120
- package/dist/sdk/server/apis/plugin.js +0 -39
- package/dist/sdk/server/apis/project.js +0 -59
- package/dist/sdk/server/apis/renderer.js +0 -33
- package/dist/sdk/server/apis/resolver.js +0 -38
- package/dist/sdk/server/client.js +0 -8
- package/dist/sdk/server/fakeServer.js +0 -12
- package/dist/sdk/server/index.js +0 -292
- package/dist/sdk/server/json-body.js +0 -150
- package/dist/sdk/server/router.js +0 -83
- package/dist/sdk/server/security.js +0 -47
- package/dist/sdk/server/socket/api.js +0 -22
- package/dist/sdk/server/socket/index.js +0 -166
- package/dist/sdk/server/utils.js +0 -19
- package/dist/sdk/utils/base.js +0 -22
- package/dist/sdk/utils/constant.js +0 -4
- package/dist/sdk/utils/index.js +0 -4
- package/dist/sdk/utils/openBrowser.js +0 -53
- package/dist/sdk/utils/upload.js +0 -6
- package/dist/sdk.js +0 -2
- package/dist/types/index.js +0 -4
- package/dist/types/loader.js +0 -1
- package/dist/types/plugin.js +0 -1
- package/dist/types/rules.js +0 -1
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { InternalBasePlugin } from "./base.js";
|
|
3
|
-
import { Linter } from "../../rules/index.js";
|
|
4
|
-
import { DevToolError } from "../../error/index.js";
|
|
5
|
-
import { pull } from "../../collection.js";
|
|
6
|
-
import { time, timeEnd } from "../../logger.js";
|
|
7
|
-
class InternalRulesPlugin extends InternalBasePlugin {
|
|
8
|
-
apply(compiler) {
|
|
9
|
-
time('InternalRulesPlugin.apply');
|
|
10
|
-
try {
|
|
11
|
-
compiler.hooks.done.tapPromise(this.tapPreOptions, this.done);
|
|
12
|
-
} finally{
|
|
13
|
-
timeEnd('InternalRulesPlugin.apply');
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
async lint(compilation) {
|
|
17
|
-
time('InternalRulesPlugin.lint');
|
|
18
|
-
try {
|
|
19
|
-
const options = this.options ?? {};
|
|
20
|
-
const linter = new Linter(options.linter);
|
|
21
|
-
const result = await linter.validate(this.sdk.getRuleContext({}));
|
|
22
|
-
const validateErrors = result.errors.map((err)=>DevToolError.from(err, {
|
|
23
|
-
detail: err.detail,
|
|
24
|
-
controller: {
|
|
25
|
-
noColor: true
|
|
26
|
-
}
|
|
27
|
-
}));
|
|
28
|
-
const errors = validateErrors.filter((item)=>'Error' === item.level);
|
|
29
|
-
const warnings = validateErrors.filter((item)=>'Warn' === item.level);
|
|
30
|
-
const toRspackError = (err)=>err.toError();
|
|
31
|
-
result.replace.forEach((item)=>{
|
|
32
|
-
if (Array.isArray(compilation.errors) && compilation.errors.includes(item)) pull(compilation.errors, item);
|
|
33
|
-
if (Array.isArray(compilation.warnings) && compilation.warnings.includes(item)) pull(compilation.warnings, item);
|
|
34
|
-
});
|
|
35
|
-
if (Array.isArray(compilation.errors)) errors.forEach((err)=>{
|
|
36
|
-
compilation.errors.push(toRspackError(err));
|
|
37
|
-
});
|
|
38
|
-
if (Array.isArray(compilation.warnings)) warnings.forEach((err)=>{
|
|
39
|
-
compilation.warnings.push(toRspackError(err));
|
|
40
|
-
});
|
|
41
|
-
this.sdk.reportError(validateErrors);
|
|
42
|
-
await linter.afterValidate({
|
|
43
|
-
data: this.sdk.getRuleContext({}),
|
|
44
|
-
validateResult: result,
|
|
45
|
-
hooks: {
|
|
46
|
-
afterSaveManifest: this.sdk.hooks.afterSaveManifest
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
} finally{
|
|
50
|
-
timeEnd('InternalRulesPlugin.lint');
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
constructor(...args){
|
|
54
|
-
super(...args), this.name = 'rules', this.done = async (stats)=>{
|
|
55
|
-
time('InternalRulesPlugin.done');
|
|
56
|
-
try {
|
|
57
|
-
await this.lint(stats.compilation);
|
|
58
|
-
} finally{
|
|
59
|
-
timeEnd('InternalRulesPlugin.done');
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export { InternalRulesPlugin };
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { Graph } from "../../common/index.js";
|
|
3
|
-
import { logger, time, timeEnd } from "../../logger.js";
|
|
4
|
-
import { dirname, isAbsolute, resolve } from "path";
|
|
5
|
-
import { SourceMapConsumer } from "source-map";
|
|
6
|
-
const UNASSIGNED = '[unassigned]';
|
|
7
|
-
function bindContextCache(context, namespace, cache, sourceMapDir, sourceRoot) {
|
|
8
|
-
cache = cache || new Map();
|
|
9
|
-
return (source, sourceMapFilenameRegex)=>{
|
|
10
|
-
if (cache.has(source)) return cache.get(source);
|
|
11
|
-
let resolved = UNASSIGNED;
|
|
12
|
-
if (source.startsWith('file://')) resolved = resolve(context, source.replace(/^file:\/\//, ''));
|
|
13
|
-
else if (source.startsWith('webpack://')) if (sourceMapFilenameRegex) {
|
|
14
|
-
const match = source.match(sourceMapFilenameRegex);
|
|
15
|
-
const filePath = match?.[1];
|
|
16
|
-
const hasNamespace = namespace && source.startsWith(`webpack://${namespace}`) || namespace && source.startsWith(`file://${namespace}`);
|
|
17
|
-
const baseDir = hasNamespace ? process.cwd() : context;
|
|
18
|
-
resolved = filePath ? resolve(baseDir, `./${filePath}`) : UNASSIGNED;
|
|
19
|
-
} else resolved = UNASSIGNED;
|
|
20
|
-
else if (isAbsolute(source)) resolved = source;
|
|
21
|
-
else {
|
|
22
|
-
let baseDir = context;
|
|
23
|
-
if (sourceRoot) baseDir = isAbsolute(sourceRoot) ? sourceRoot : sourceMapDir ? resolve(sourceMapDir, sourceRoot) : resolve(context, sourceRoot);
|
|
24
|
-
else if (sourceMapDir) baseDir = sourceMapDir;
|
|
25
|
-
resolved = resolve(baseDir, source);
|
|
26
|
-
}
|
|
27
|
-
cache.set(source, resolved);
|
|
28
|
-
return resolved;
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
async function collectSourceMaps(map, assetLinesCodeList, _compilation, _this, sourceMapFilenameRegex, namespace, skipSources, sourceMapPath) {
|
|
32
|
-
if (map) {
|
|
33
|
-
const consumer = await new SourceMapConsumer(map);
|
|
34
|
-
let sourceMapDir;
|
|
35
|
-
if (sourceMapPath) sourceMapDir = dirname(sourceMapPath);
|
|
36
|
-
else if (_compilation.options.output?.path) sourceMapDir = 'string' == typeof _compilation.options.output.path ? _compilation.options.output.path : void 0;
|
|
37
|
-
const sourceRoot = map.sourceRoot;
|
|
38
|
-
const getRealSourcePath = bindContextCache(_this.sdk.root || process.cwd(), namespace, _this._realSourcePathCache, sourceMapDir, sourceRoot ?? void 0);
|
|
39
|
-
const lineMappings = new Map();
|
|
40
|
-
consumer._absoluteSources = consumer._sources;
|
|
41
|
-
consumer.eachMapping((m)=>{
|
|
42
|
-
if (!lineMappings.has(m.generatedLine)) lineMappings.set(m.generatedLine, []);
|
|
43
|
-
lineMappings.get(m.generatedLine).push(m);
|
|
44
|
-
});
|
|
45
|
-
for (const [lineNum, mappings] of lineMappings.entries()){
|
|
46
|
-
mappings.sort((a, b)=>a.generatedColumn - b.generatedColumn);
|
|
47
|
-
const lineIdx = lineNum - 1;
|
|
48
|
-
if (lineIdx < 0 || lineIdx >= assetLinesCodeList.length) continue;
|
|
49
|
-
const line = assetLinesCodeList[lineIdx];
|
|
50
|
-
for(let i = 0; i < mappings.length; i++){
|
|
51
|
-
const m = mappings[i];
|
|
52
|
-
if (!m.source) continue;
|
|
53
|
-
let realSource = m.source;
|
|
54
|
-
if (realSource.includes('!')) {
|
|
55
|
-
const parts = realSource.split('!');
|
|
56
|
-
for(let j = parts.length - 1; j >= 0; j--){
|
|
57
|
-
const part = parts[j];
|
|
58
|
-
if (!part) continue;
|
|
59
|
-
const cleanPart = part.split('??')[0];
|
|
60
|
-
if (!cleanPart.startsWith('builtin:')) {
|
|
61
|
-
if (cleanPart.startsWith('/') || cleanPart.includes('\\')) {
|
|
62
|
-
realSource = cleanPart;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
if (realSource === m.source) {
|
|
68
|
-
const lastPart = parts[parts.length - 1];
|
|
69
|
-
realSource = lastPart ? lastPart.split('??')[0] : lastPart;
|
|
70
|
-
}
|
|
71
|
-
} else if (realSource.includes('??')) realSource = realSource.split('??')[0];
|
|
72
|
-
if (realSource) {
|
|
73
|
-
if ((realSource.startsWith('webpack://') || realSource.startsWith('file://')) && sourceMapFilenameRegex) realSource = getRealSourcePath(realSource, sourceMapFilenameRegex);
|
|
74
|
-
else if (!isAbsolute(realSource)) realSource = getRealSourcePath(realSource, sourceMapFilenameRegex);
|
|
75
|
-
}
|
|
76
|
-
if (!realSource || realSource === UNASSIGNED) continue;
|
|
77
|
-
if (skipSources && skipSources.has(realSource)) continue;
|
|
78
|
-
const next = mappings[i + 1];
|
|
79
|
-
const start = m.generatedColumn;
|
|
80
|
-
const end = next ? next.generatedColumn : line.length;
|
|
81
|
-
const codeSegment = line.slice(start, end);
|
|
82
|
-
const prev = _this.sourceMapSets.get(realSource) || '';
|
|
83
|
-
_this.sourceMapSets.set(realSource, prev.concat(codeSegment));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex, namespace) {
|
|
89
|
-
if ('rspack' in compilation.compiler) {
|
|
90
|
-
_this.sourceMapSets = new Map();
|
|
91
|
-
if (_this.assetsWithoutSourceMap) _this.assetsWithoutSourceMap.clear();
|
|
92
|
-
else _this.assetsWithoutSourceMap = new Set();
|
|
93
|
-
time('ensureModulesChunkGraph.afterEmit.start');
|
|
94
|
-
const assets = [
|
|
95
|
-
...compilation.getAssets()
|
|
96
|
-
];
|
|
97
|
-
const skipSources = new Set();
|
|
98
|
-
for (const asset of assets){
|
|
99
|
-
const { assetLinesCodeList, map: mapFromAsset, assetName } = parseAsset(asset, assets, 'js/css');
|
|
100
|
-
let map = mapFromAsset;
|
|
101
|
-
let sourceMapPath;
|
|
102
|
-
if (map) {
|
|
103
|
-
const outputPath = compilation.options.output?.path;
|
|
104
|
-
if (outputPath && 'string' == typeof outputPath && assetName) {
|
|
105
|
-
const mapFileName = assetName.endsWith('.map') ? assetName : `${assetName}.map`;
|
|
106
|
-
sourceMapPath = resolve(outputPath, mapFileName);
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
const sourceMapFile = asset.info.related?.sourceMap;
|
|
110
|
-
const sourceMapFileAssetName = sourceMapFile?.replace(/(\.[^.]+)(\.[^.]+)?$/, '$1');
|
|
111
|
-
if (sourceMapFile) {
|
|
112
|
-
let sourceMapAsset = assets.find((asset)=>asset.name === sourceMapFile);
|
|
113
|
-
if (!sourceMapAsset && sourceMapFileAssetName) {
|
|
114
|
-
const baseNameWithoutHash = Graph.formatAssetName(sourceMapFileAssetName, 'string' == typeof compilation.options.output.filename ? compilation.options.output.filename : void 0);
|
|
115
|
-
sourceMapAsset = assets.find((asset)=>{
|
|
116
|
-
const assetBaseName = Graph.formatAssetName(asset.name, 'string' == typeof compilation.options.output.filename ? compilation.options.output.filename : void 0);
|
|
117
|
-
return assetBaseName.includes(baseNameWithoutHash) && asset.name.endsWith('.map');
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
if (sourceMapAsset) {
|
|
121
|
-
map = JSON.parse(sourceMapAsset.source.source().toString());
|
|
122
|
-
const outputPath = compilation.options.output?.path;
|
|
123
|
-
if (outputPath && 'string' == typeof outputPath) sourceMapPath = resolve(outputPath, sourceMapAsset.name);
|
|
124
|
-
}
|
|
125
|
-
} else {
|
|
126
|
-
if (assetName && 'string' == typeof assetName && (assetName.endsWith('.js') || assetName.endsWith('.bundle') || assetName.endsWith('.css'))) _this.assetsWithoutSourceMap.add(assetName);
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
try {
|
|
131
|
-
await collectSourceMaps(map, assetLinesCodeList, compilation, _this, sourceMapFilenameRegex, namespace, skipSources, sourceMapPath);
|
|
132
|
-
} catch (e) {
|
|
133
|
-
logger.debug(e);
|
|
134
|
-
}
|
|
135
|
-
_this.sourceMapSets.forEach((_value, key)=>{
|
|
136
|
-
if (!skipSources.has(key)) skipSources.add(key);
|
|
137
|
-
});
|
|
138
|
-
}
|
|
139
|
-
timeEnd('ensureModulesChunkGraph.afterEmit.start');
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
async function handleEmitAssets(options) {
|
|
143
|
-
const { compilation, pluginInstance, sourceMapFilenameRegex, namespace } = options;
|
|
144
|
-
if (!('rspack' in compilation.compiler)) {
|
|
145
|
-
pluginInstance.sourceMapSets = new Map();
|
|
146
|
-
time('ensureModulesChunkGraph.afterEmit.start');
|
|
147
|
-
const assets = Object.values(compilation.getAssets()).map((asset, index)=>({
|
|
148
|
-
name: index.toString(),
|
|
149
|
-
source: asset,
|
|
150
|
-
info: asset.info || {}
|
|
151
|
-
}));
|
|
152
|
-
for (const asset of assets){
|
|
153
|
-
const { assetLinesCodeList, map, assetName } = parseAsset(asset, assets, 'map');
|
|
154
|
-
if (!map) continue;
|
|
155
|
-
let sourceMapPath;
|
|
156
|
-
const outputPath = compilation.options.output?.path;
|
|
157
|
-
if (outputPath && 'string' == typeof outputPath && 'string' == typeof assetName) {
|
|
158
|
-
const mapFileName = assetName.endsWith('.map') ? assetName : `${assetName}.map`;
|
|
159
|
-
sourceMapPath = resolve(outputPath, mapFileName);
|
|
160
|
-
}
|
|
161
|
-
try {
|
|
162
|
-
await collectSourceMaps(map, assetLinesCodeList, compilation, pluginInstance, sourceMapFilenameRegex, namespace, void 0, sourceMapPath);
|
|
163
|
-
} catch (e) {
|
|
164
|
-
logger.debug(e);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
timeEnd('ensureModulesChunkGraph.afterEmit.start');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
function parseAsset(asset, assets, type) {
|
|
171
|
-
const assetName = asset.source?.name || asset.name;
|
|
172
|
-
let assetContent = '';
|
|
173
|
-
let assetLinesCodeList = [];
|
|
174
|
-
let map = null;
|
|
175
|
-
try {
|
|
176
|
-
if ('map' === type && 'string' == typeof assetName && assetName.endsWith('.map') && !asset.name.includes('d.ts')) {
|
|
177
|
-
assetContent = asset.source?.source?.source?.() || '';
|
|
178
|
-
if (!assetContent) {
|
|
179
|
-
logger.debug(`Failed to get source content for asset: ${assetName}`);
|
|
180
|
-
return {
|
|
181
|
-
assetName,
|
|
182
|
-
assetContent: '',
|
|
183
|
-
assetLinesCodeList: [],
|
|
184
|
-
map: null
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
map = JSON.parse(assetContent);
|
|
188
|
-
if (!map || !map.file) {
|
|
189
|
-
logger.debug(`Failed to get source map file for asset: ${assetName}`);
|
|
190
|
-
return {
|
|
191
|
-
assetName,
|
|
192
|
-
assetContent,
|
|
193
|
-
assetLinesCodeList: [],
|
|
194
|
-
map: null
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
const bundledAsset = assets.find((asset2)=>asset2.source?.name === map?.file);
|
|
198
|
-
const bundledCode = bundledAsset?.source?.source?.source?.() || '';
|
|
199
|
-
if (!bundledCode) {
|
|
200
|
-
logger.debug(`Failed to get bundled code for asset: ${map.file}`);
|
|
201
|
-
return {
|
|
202
|
-
assetName,
|
|
203
|
-
assetContent,
|
|
204
|
-
assetLinesCodeList: [],
|
|
205
|
-
map
|
|
206
|
-
};
|
|
207
|
-
}
|
|
208
|
-
assetLinesCodeList = bundledCode.split(/\r?\n/);
|
|
209
|
-
} else if ('js/css' === type && (assetName.endsWith('.js') || assetName.endsWith('.bundle') || assetName.endsWith('.css'))) {
|
|
210
|
-
assetContent = asset.source?.source?.() || '';
|
|
211
|
-
assetLinesCodeList = assetContent.split(/\r?\n/);
|
|
212
|
-
map = asset.source?.sourceAndMap?.()?.map || null;
|
|
213
|
-
}
|
|
214
|
-
} catch (error) {
|
|
215
|
-
logger.debug(`Error parsing asset ${assetName}:`, error);
|
|
216
|
-
return {
|
|
217
|
-
assetName,
|
|
218
|
-
assetContent: '',
|
|
219
|
-
assetLinesCodeList: [],
|
|
220
|
-
map: null
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
return {
|
|
224
|
-
assetName,
|
|
225
|
-
assetContent,
|
|
226
|
-
assetLinesCodeList,
|
|
227
|
-
map
|
|
228
|
-
};
|
|
229
|
-
}
|
|
230
|
-
export { UNASSIGNED, bindContextCache, collectSourceMaps, handleAfterEmitAssets, handleEmitAssets };
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { Summary } from "../../common/index.js";
|
|
3
|
-
import { minBy, sumBy } from "../../collection.js";
|
|
4
|
-
import { InternalBasePlugin } from "./base.js";
|
|
5
|
-
import { time, timeEnd } from "../../logger.js";
|
|
6
|
-
class InternalSummaryPlugin extends InternalBasePlugin {
|
|
7
|
-
apply(compiler) {
|
|
8
|
-
time('InternalSummaryPlugin.apply');
|
|
9
|
-
try {
|
|
10
|
-
compiler.hooks.beforeCompile.tapPromise(this.tapPostOptions, this.beforeCompile);
|
|
11
|
-
compiler.hooks.afterCompile.tapPromise(this.tapPreOptions, this.afterCompile);
|
|
12
|
-
compiler.hooks.done.tapPromise(this.tapPostOptions, this.done.bind(this, compiler));
|
|
13
|
-
} finally{
|
|
14
|
-
timeEnd('InternalSummaryPlugin.apply');
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
mark(key, type) {
|
|
18
|
-
const now = Date.now();
|
|
19
|
-
switch(type){
|
|
20
|
-
case 'pre':
|
|
21
|
-
this.preTimes.set(key, now);
|
|
22
|
-
break;
|
|
23
|
-
case 'post':
|
|
24
|
-
this.postTimes.set(key, now);
|
|
25
|
-
break;
|
|
26
|
-
default:
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
report(name, start) {
|
|
31
|
-
this.times.set(name, start);
|
|
32
|
-
this.sdk.reportSummaryData({
|
|
33
|
-
costs: [
|
|
34
|
-
{
|
|
35
|
-
name,
|
|
36
|
-
startAt: start,
|
|
37
|
-
costs: Date.now() - start
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
constructor(...args){
|
|
43
|
-
super(...args), this.name = 'summary', this.times = new Map(), this.preTimes = new Map(), this.postTimes = new Map(), this.beforeCompile = async ()=>{
|
|
44
|
-
time('InternalSummaryPlugin.beforeCompile');
|
|
45
|
-
try {
|
|
46
|
-
if (!this.times.has(Summary.SummaryCostsDataName.Bootstrap)) {
|
|
47
|
-
const costs = Math.floor(1000 * process.uptime());
|
|
48
|
-
const startAt = Date.now() - costs;
|
|
49
|
-
this.report(Summary.SummaryCostsDataName.Bootstrap, startAt);
|
|
50
|
-
this.mark(Summary.SummaryCostsDataName.Bootstrap, 'post');
|
|
51
|
-
}
|
|
52
|
-
} finally{
|
|
53
|
-
timeEnd('InternalSummaryPlugin.beforeCompile');
|
|
54
|
-
}
|
|
55
|
-
}, this.afterCompile = async (compilation)=>{
|
|
56
|
-
time('InternalSummaryPlugin.afterCompile');
|
|
57
|
-
try {
|
|
58
|
-
if (!this.times.has(Summary.SummaryCostsDataName.Compile) && !compilation.compiler.isChild()) {
|
|
59
|
-
const start = this.postTimes.get(Summary.SummaryCostsDataName.Bootstrap);
|
|
60
|
-
this.report(Summary.SummaryCostsDataName.Compile, start);
|
|
61
|
-
this.mark(Summary.SummaryCostsDataName.Compile, 'post');
|
|
62
|
-
}
|
|
63
|
-
} finally{
|
|
64
|
-
timeEnd('InternalSummaryPlugin.afterCompile');
|
|
65
|
-
}
|
|
66
|
-
}, this.done = async (compiler)=>{
|
|
67
|
-
time('InternalSummaryPlugin.done');
|
|
68
|
-
try {
|
|
69
|
-
const start = this.postTimes.get(Summary.SummaryCostsDataName.Compile);
|
|
70
|
-
this.report(Summary.SummaryCostsDataName.Done, start);
|
|
71
|
-
if (false !== compiler.options.optimization.minimize) {
|
|
72
|
-
const pluginData = this.sdk.getStoreData().plugin;
|
|
73
|
-
const minifyHookData = [
|
|
74
|
-
...pluginData.processAssets || []
|
|
75
|
-
];
|
|
76
|
-
if (minifyHookData.length) this.sdk.reportSummaryData({
|
|
77
|
-
costs: [
|
|
78
|
-
{
|
|
79
|
-
name: Summary.SummaryCostsDataName.Minify,
|
|
80
|
-
startAt: minBy(minifyHookData, (e)=>e.startAt).startAt,
|
|
81
|
-
costs: sumBy(minifyHookData, (e)=>e.costs)
|
|
82
|
-
}
|
|
83
|
-
]
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
} finally{
|
|
87
|
-
timeEnd('InternalSummaryPlugin.done');
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export { InternalSummaryPlugin };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
const checkCirclePath = (obj, record, res, level, maxLevel = 3)=>{
|
|
3
|
-
const idx = record.slice(0, record.length - 1).findIndex((v)=>v.ref === obj);
|
|
4
|
-
if (-1 !== idx) {
|
|
5
|
-
const key = record.map((v)=>v.prop);
|
|
6
|
-
if (res.indexOf(key) < 0) return void res.push(key);
|
|
7
|
-
}
|
|
8
|
-
if ('object' == typeof obj && null !== obj && level < maxLevel) for (const [k, v] of Object.entries(obj))checkCirclePath(v, [
|
|
9
|
-
...record,
|
|
10
|
-
{
|
|
11
|
-
prop: k,
|
|
12
|
-
ref: v
|
|
13
|
-
}
|
|
14
|
-
], res, level + 1);
|
|
15
|
-
};
|
|
16
|
-
export { checkCirclePath };
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { SDK } from "@rsdoctor/shared/types";
|
|
3
|
-
import { chalk, logger } from "../../logger.js";
|
|
4
|
-
import assert from "assert";
|
|
5
|
-
import { convertReportCodeTypeObject, processModeConfigurations } from "./normalize-config.js";
|
|
6
|
-
function defaultBoolean(v, dft) {
|
|
7
|
-
return 'boolean' == typeof v ? v : dft;
|
|
8
|
-
}
|
|
9
|
-
function getDefaultOutput() {
|
|
10
|
-
return {
|
|
11
|
-
mode: void 0,
|
|
12
|
-
reportCodeType: {
|
|
13
|
-
noModuleSource: false,
|
|
14
|
-
noAssetsAndModuleSource: false,
|
|
15
|
-
noCode: false
|
|
16
|
-
},
|
|
17
|
-
options: void 0,
|
|
18
|
-
reportDir: '',
|
|
19
|
-
compressData: void 0
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function getDefaultSupports() {
|
|
23
|
-
return {
|
|
24
|
-
parseBundle: true,
|
|
25
|
-
gzip: true
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function isJsonOutputEnv(value) {
|
|
29
|
-
return 'json' === value;
|
|
30
|
-
}
|
|
31
|
-
function normalizeFeatures(features, mode) {
|
|
32
|
-
if (Array.isArray(features)) return {
|
|
33
|
-
loader: features.includes('loader'),
|
|
34
|
-
plugins: features.includes('plugins'),
|
|
35
|
-
resolver: features.includes('resolver'),
|
|
36
|
-
bundle: features.includes('bundle'),
|
|
37
|
-
treeShaking: features.includes('treeShaking'),
|
|
38
|
-
lite: features.includes('lite') || mode === SDK.IMode[SDK.IMode.lite]
|
|
39
|
-
};
|
|
40
|
-
return {
|
|
41
|
-
loader: defaultBoolean(features.loader, true),
|
|
42
|
-
plugins: defaultBoolean(features.plugins, true),
|
|
43
|
-
resolver: defaultBoolean(features.resolver, false),
|
|
44
|
-
bundle: defaultBoolean(features.bundle, true),
|
|
45
|
-
treeShaking: defaultBoolean(features.treeShaking, false),
|
|
46
|
-
lite: defaultBoolean(features.lite, false) || mode === SDK.IMode[SDK.IMode.lite]
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function normalizeLinter(linter) {
|
|
50
|
-
return {
|
|
51
|
-
rules: {},
|
|
52
|
-
extends: [],
|
|
53
|
-
level: 'Error',
|
|
54
|
-
...linter
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
function isValidMode(mode) {
|
|
58
|
-
return 'string' == typeof mode && [
|
|
59
|
-
'brief',
|
|
60
|
-
'normal',
|
|
61
|
-
'lite'
|
|
62
|
-
].includes(mode);
|
|
63
|
-
}
|
|
64
|
-
function normalizeUserConfig(config = {}) {
|
|
65
|
-
const userOutput = config.output;
|
|
66
|
-
const defaultOutput = getDefaultOutput();
|
|
67
|
-
const outputConfig = isJsonOutputEnv(process.env.RSDOCTOR_OUTPUT) ? {
|
|
68
|
-
reportDir: userOutput?.reportDir,
|
|
69
|
-
compressData: userOutput?.compressData,
|
|
70
|
-
mode: 'brief',
|
|
71
|
-
options: {
|
|
72
|
-
type: [
|
|
73
|
-
'json'
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
} : userOutput ?? defaultOutput;
|
|
77
|
-
const normalizedConfig = {
|
|
78
|
-
...config,
|
|
79
|
-
output: outputConfig
|
|
80
|
-
};
|
|
81
|
-
const { linter = {}, features = {}, loaderInterceptorOptions = {}, disableClientServer: userDisableClientServer = false, sdkInstance, innerClientPath = '', output = outputConfig, supports: userSupports = {}, port, server: userServer = {}, printLog = {
|
|
82
|
-
serverUrls: true
|
|
83
|
-
}, mode, brief } = normalizedConfig;
|
|
84
|
-
const supports = {
|
|
85
|
-
...getDefaultSupports(),
|
|
86
|
-
...userSupports
|
|
87
|
-
};
|
|
88
|
-
const disableClientServer = 'true' === process.env.RSTEST ? false : process.env.CI ? true : userDisableClientServer;
|
|
89
|
-
assert('object' == typeof linter);
|
|
90
|
-
assert('object' == typeof features || Array.isArray(features));
|
|
91
|
-
assert('object' == typeof loaderInterceptorOptions);
|
|
92
|
-
assert('boolean' == typeof disableClientServer);
|
|
93
|
-
assert(void 0 === port || 'number' == typeof port);
|
|
94
|
-
assert('object' == typeof userServer && null !== userServer);
|
|
95
|
-
const server = {
|
|
96
|
-
...userServer
|
|
97
|
-
};
|
|
98
|
-
assert(void 0 === server.port || 'number' == typeof server.port);
|
|
99
|
-
if (void 0 === server.port && void 0 !== port) server.port = port;
|
|
100
|
-
let finalMode = ('mode' in output && isValidMode(output.mode) ? 'lite' === output.mode ? SDK.IMode[SDK.IMode.normal] : output.mode : void 0) || mode || SDK.IMode[SDK.IMode.normal];
|
|
101
|
-
if (mode) logger.info(chalk.yellow("The 'mode' configuration will be deprecated in a future version. Please use 'output.mode' instead."));
|
|
102
|
-
const _features = normalizeFeatures(features, finalMode);
|
|
103
|
-
const _linter = normalizeLinter(linter);
|
|
104
|
-
if (_features.lite || finalMode === SDK.IMode[SDK.IMode.lite]) logger.info(chalk.yellow("Lite features will be deprecated in a future version. Please use 'output: { reportCodeType: { noAssetsAndModuleSource: true }}' instead."));
|
|
105
|
-
const { finalBrief, finalNormalOptions } = processModeConfigurations(finalMode, output, brief);
|
|
106
|
-
if (_features.lite && finalMode !== SDK.IMode[SDK.IMode.brief]) finalMode = SDK.IMode[SDK.IMode.lite];
|
|
107
|
-
const reportCodeType = output.reportCodeType ? normalizeReportType(output.reportCodeType, finalMode) : normalizeReportType(getDefaultOutput().reportCodeType, finalMode);
|
|
108
|
-
const res = {
|
|
109
|
-
linter: _linter,
|
|
110
|
-
features: _features,
|
|
111
|
-
loaderInterceptorOptions: {
|
|
112
|
-
skipLoaders: Array.isArray(loaderInterceptorOptions.skipLoaders) ? loaderInterceptorOptions.skipLoaders : []
|
|
113
|
-
},
|
|
114
|
-
disableClientServer,
|
|
115
|
-
sdkInstance,
|
|
116
|
-
output: {
|
|
117
|
-
mode: finalMode,
|
|
118
|
-
options: 'brief' === finalMode ? finalBrief : finalNormalOptions,
|
|
119
|
-
reportCodeType,
|
|
120
|
-
reportDir: output.reportDir || ''
|
|
121
|
-
},
|
|
122
|
-
innerClientPath,
|
|
123
|
-
supports,
|
|
124
|
-
port,
|
|
125
|
-
server,
|
|
126
|
-
printLog
|
|
127
|
-
};
|
|
128
|
-
if (void 0 !== output.compressData) logger.info(chalk.yellow("The 'compressData' configuration will be deprecated in a future version."));
|
|
129
|
-
return res;
|
|
130
|
-
}
|
|
131
|
-
const normalizeReportType = (reportCodeType, mode)=>{
|
|
132
|
-
const convertedReportCodeType = 'object' == typeof reportCodeType ? convertReportCodeTypeObject(reportCodeType) : reportCodeType;
|
|
133
|
-
if ('noCode' === convertedReportCodeType) return SDK.ToDataType.NoCode;
|
|
134
|
-
if (mode === SDK.IMode[SDK.IMode.brief]) return SDK.ToDataType.NoCode;
|
|
135
|
-
if (mode === SDK.IMode[SDK.IMode.lite]) return SDK.ToDataType.NoSourceAndAssets;
|
|
136
|
-
if ('noAssetsAndModuleSource' === convertedReportCodeType) return SDK.ToDataType.NoSourceAndAssets;
|
|
137
|
-
if ('noModuleSource' === convertedReportCodeType) return SDK.ToDataType.NoSource;
|
|
138
|
-
return SDK.ToDataType.Normal;
|
|
139
|
-
};
|
|
140
|
-
const normalizeRspackUserOptions = normalizeUserConfig;
|
|
141
|
-
export { normalizeReportType, normalizeRspackUserOptions, normalizeUserConfig };
|