@rsdoctor/core 1.5.11 → 2.0.0-alpha.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/dist/build-utils/build/module-graph/index.cjs +4 -18
- package/dist/build-utils/build/module-graph/index.d.cts +0 -2
- package/dist/build-utils/build/module-graph/index.d.ts +0 -2
- package/dist/build-utils/build/module-graph/index.js +0 -2
- package/dist/build-utils/build/module-graph/rspack/transform.cjs +1 -1
- package/dist/build-utils/build/module-graph/rspack/transform.js +1 -1
- package/dist/build-utils/build/module-graph/transform.cjs +2 -3
- package/dist/build-utils/build/module-graph/transform.d.cts +1 -2
- package/dist/build-utils/build/module-graph/transform.d.ts +1 -2
- package/dist/build-utils/build/module-graph/transform.js +2 -3
- package/dist/build-utils/build/utils/parseBundle.cjs +1 -1
- package/dist/build-utils/build/utils/parseBundle.js +1 -1
- package/dist/build-utils/build/utils/plugin.cjs +1 -2
- package/dist/build-utils/build/utils/plugin.js +1 -2
- package/dist/inner-plugins/constants.cjs +1 -1
- package/dist/inner-plugins/constants.d.cts +1 -1
- package/dist/inner-plugins/constants.d.ts +1 -1
- package/dist/inner-plugins/constants.js +1 -1
- package/dist/inner-plugins/plugins/bundle.cjs +1 -17
- package/dist/inner-plugins/plugins/bundle.js +1 -17
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.cjs +3 -40
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.cts +4 -6
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.ts +4 -6
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +4 -41
- package/dist/inner-plugins/plugins/errors.cjs +3 -3
- package/dist/inner-plugins/plugins/errors.d.cts +1 -1
- package/dist/inner-plugins/plugins/errors.d.ts +1 -1
- package/dist/inner-plugins/plugins/errors.js +3 -3
- package/dist/inner-plugins/plugins/index.cjs +2 -9
- package/dist/inner-plugins/plugins/index.d.cts +0 -1
- package/dist/inner-plugins/plugins/index.d.ts +0 -1
- package/dist/inner-plugins/plugins/index.js +0 -1
- package/dist/inner-plugins/plugins/loader.cjs +1 -1
- package/dist/inner-plugins/plugins/loader.js +1 -1
- package/dist/inner-plugins/plugins/plugins.cjs +1 -1
- package/dist/inner-plugins/plugins/plugins.js +1 -1
- package/dist/inner-plugins/plugins/progress.cjs +14 -16
- package/dist/inner-plugins/plugins/progress.d.cts +1 -1
- package/dist/inner-plugins/plugins/progress.d.ts +1 -1
- package/dist/inner-plugins/plugins/progress.js +14 -16
- package/dist/inner-plugins/plugins/resolver.d.cts +1 -2
- package/dist/inner-plugins/plugins/resolver.d.ts +1 -2
- package/dist/inner-plugins/plugins/rules.cjs +3 -3
- package/dist/inner-plugins/plugins/rules.js +3 -3
- package/dist/inner-plugins/utils/config.cjs +0 -1
- package/dist/inner-plugins/utils/config.d.cts +1 -1
- package/dist/inner-plugins/utils/config.d.ts +1 -1
- package/dist/inner-plugins/utils/config.js +0 -1
- package/dist/inner-plugins/utils/loader.cjs +2 -2
- package/dist/inner-plugins/utils/loader.js +2 -2
- package/dist/inner-plugins/utils/normalize-config.d.cts +3 -6
- package/dist/inner-plugins/utils/normalize-config.d.ts +3 -6
- package/dist/rules/rules/cjs-require/index.cjs +2 -2
- package/dist/rules/rules/cjs-require/index.js +2 -2
- package/dist/rules/rules/esm-resolved-to-cjs/index.cjs +91 -26
- package/dist/rules/rules/esm-resolved-to-cjs/index.js +91 -26
- package/dist/rules/rules/index.d.cts +2 -1
- package/dist/rules/rules/index.d.ts +2 -1
- package/dist/rules/rules/loader-performance-optimization/index.cjs +1 -1
- package/dist/rules/rules/loader-performance-optimization/index.js +1 -1
- package/dist/rules/rules/module-mixed-chunks/index.cjs +1 -1
- package/dist/rules/rules/module-mixed-chunks/index.js +1 -1
- package/dist/rules/rules/side-effects-only-imports/index.cjs +1 -1
- package/dist/rules/rules/side-effects-only-imports/index.js +1 -1
- package/dist/types/plugin.d.cts +2 -2
- package/dist/types/plugin.d.ts +2 -2
- package/dist/types/rules.d.cts +4 -4
- package/dist/types/rules.d.ts +4 -4
- package/package.json +9 -10
- package/dist/build-utils/build/module-graph/treeShaking.cjs +0 -106
- package/dist/build-utils/build/module-graph/treeShaking.d.cts +0 -2
- package/dist/build-utils/build/module-graph/treeShaking.d.ts +0 -2
- package/dist/build-utils/build/module-graph/treeShaking.js +0 -73
- package/dist/build-utils/build/module-graph/webpack/transform.cjs +0 -170
- package/dist/build-utils/build/module-graph/webpack/transform.d.cts +0 -16
- package/dist/build-utils/build/module-graph/webpack/transform.d.ts +0 -16
- package/dist/build-utils/build/module-graph/webpack/transform.js +0 -124
- package/dist/inner-plugins/plugins/bundleTagPlugin.cjs +0 -84
- package/dist/inner-plugins/plugins/bundleTagPlugin.d.cts +0 -6
- package/dist/inner-plugins/plugins/bundleTagPlugin.d.ts +0 -6
- package/dist/inner-plugins/plugins/bundleTagPlugin.js +0 -51
|
@@ -14,28 +14,88 @@ function normalizePathForCompare(filePath) {
|
|
|
14
14
|
const cleanPath = splitIndex === 1 / 0 ? filePath : filePath.slice(0, splitIndex);
|
|
15
15
|
return path.normalize(cleanPath);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
17
|
+
function isDefinitelyEsmFile(filePath) {
|
|
18
|
+
return '.mjs' === path.extname(normalizePathForCompare(filePath));
|
|
19
|
+
}
|
|
20
|
+
function isDeclaredEsmEntry(filePath, esmEntries, toRealPath) {
|
|
21
|
+
const realPath = toRealPath(filePath);
|
|
22
|
+
return esmEntries.some((esmEntry)=>realPath === toRealPath(esmEntry));
|
|
23
|
+
}
|
|
24
|
+
function isRecord(value) {
|
|
25
|
+
return null !== value && 'object' == typeof value && !Array.isArray(value);
|
|
26
|
+
}
|
|
27
|
+
function substituteExportPattern(target, wildcard) {
|
|
28
|
+
return target.replace(/\*/g, wildcard);
|
|
29
|
+
}
|
|
30
|
+
function toPackagePath(pkgRoot, target, wildcard) {
|
|
31
|
+
return path.resolve(pkgRoot, substituteExportPattern(target, wildcard));
|
|
32
|
+
}
|
|
33
|
+
function collectStringTargets(value, wildcard) {
|
|
34
|
+
if ('string' == typeof value) return [
|
|
35
|
+
substituteExportPattern(value, wildcard)
|
|
36
|
+
];
|
|
37
|
+
if (Array.isArray(value)) return value.flatMap((item)=>collectStringTargets(item, wildcard));
|
|
38
|
+
if (!isRecord(value)) return [];
|
|
39
|
+
return Object.values(value).flatMap((child)=>collectStringTargets(child, wildcard));
|
|
40
|
+
}
|
|
41
|
+
function collectEsmTargets(exportEntry, pkgRoot, wildcard) {
|
|
42
|
+
const entries = new Set();
|
|
43
|
+
const addTargets = (value)=>{
|
|
44
|
+
for (const target of collectStringTargets(value, wildcard))entries.add(toPackagePath(pkgRoot, target, ''));
|
|
45
|
+
};
|
|
46
|
+
const visit = (value)=>{
|
|
47
|
+
if ('string' == typeof value || Array.isArray(value)) return void addTargets(value);
|
|
48
|
+
if (!isRecord(value)) return;
|
|
49
|
+
addTargets(value['import']);
|
|
50
|
+
addTargets(value['module']);
|
|
51
|
+
for (const child of Object.values(value))if (isRecord(child) || Array.isArray(child)) visit(child);
|
|
52
|
+
};
|
|
53
|
+
visit(exportEntry);
|
|
54
|
+
return entries;
|
|
55
|
+
}
|
|
56
|
+
function hasSubpathExportKeys(exports) {
|
|
57
|
+
return Object.keys(exports).some((key)=>'.' === key || key.startsWith('./'));
|
|
58
|
+
}
|
|
59
|
+
function matchPatternExportKey(patternKey, exportKey) {
|
|
60
|
+
const wildcardIndex = patternKey.indexOf('*');
|
|
61
|
+
if (wildcardIndex < 0) return null;
|
|
62
|
+
const prefix = patternKey.slice(0, wildcardIndex);
|
|
63
|
+
const suffix = patternKey.slice(wildcardIndex + 1);
|
|
64
|
+
if (!exportKey.startsWith(prefix) || !exportKey.endsWith(suffix)) return null;
|
|
65
|
+
return exportKey.slice(prefix.length, exportKey.length - suffix.length);
|
|
66
|
+
}
|
|
67
|
+
function resolveExportEntry(exports, exportKey) {
|
|
68
|
+
if (Object.prototype.hasOwnProperty.call(exports, exportKey)) return {
|
|
69
|
+
value: exports[exportKey],
|
|
70
|
+
wildcard: ''
|
|
71
|
+
};
|
|
72
|
+
for (const [key, value] of Object.entries(exports)){
|
|
73
|
+
const wildcard = matchPatternExportKey(key, exportKey);
|
|
74
|
+
if (null !== wildcard) return {
|
|
75
|
+
value,
|
|
76
|
+
wildcard
|
|
77
|
+
};
|
|
37
78
|
}
|
|
38
|
-
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
function resolveExportEntryForKey(exportsField, exportKey) {
|
|
82
|
+
if (!isRecord(exportsField)) return null;
|
|
83
|
+
if (!hasSubpathExportKeys(exportsField)) return '.' === exportKey ? {
|
|
84
|
+
value: exportsField,
|
|
85
|
+
wildcard: ''
|
|
86
|
+
} : null;
|
|
87
|
+
return resolveExportEntry(exportsField, exportKey);
|
|
88
|
+
}
|
|
89
|
+
function extractEsmEntries(pkgJson, pkgRoot, exportKey) {
|
|
90
|
+
const { exports: exportsField, module: moduleField } = pkgJson;
|
|
91
|
+
const resolvedExport = resolveExportEntryForKey(exportsField, exportKey);
|
|
92
|
+
const entries = resolvedExport ? collectEsmTargets(resolvedExport.value, pkgRoot, resolvedExport.wildcard) : new Set();
|
|
93
|
+
if ('.' === exportKey && 'string' == typeof moduleField) entries.add(path.resolve(pkgRoot, moduleField));
|
|
94
|
+
return entries;
|
|
95
|
+
}
|
|
96
|
+
function getExportKeyFromRequest(packageName, request) {
|
|
97
|
+
if (request === packageName) return '.';
|
|
98
|
+
if (request.startsWith(`${packageName}/`)) return `.${request.slice(packageName.length)}`;
|
|
39
99
|
return null;
|
|
40
100
|
}
|
|
41
101
|
const rule = defineRule(()=>({
|
|
@@ -83,10 +143,15 @@ const rule = defineRule(()=>({
|
|
|
83
143
|
const pkg = packageGraph.getPackageByModule(dep.dependency);
|
|
84
144
|
if (!pkg?.root) continue;
|
|
85
145
|
const pkgJson = readPkgJson(pkg.root);
|
|
86
|
-
|
|
87
|
-
|
|
146
|
+
if (ruleConfig.ignore.some((p)=>pkg.name.includes(p)) || !pkgJson) continue;
|
|
147
|
+
const exportKey = getExportKeyFromRequest(pkg.name, dep.request);
|
|
148
|
+
if (!exportKey) continue;
|
|
149
|
+
const esmEntries = extractEsmEntries(pkgJson, pkg.root, exportKey);
|
|
150
|
+
if (0 === esmEntries.size) continue;
|
|
151
|
+
const esmEntryList = Array.from(esmEntries);
|
|
88
152
|
const resolvedModuleRealPath = toRealPath(dep.dependency.path);
|
|
89
|
-
if (resolvedModuleRealPath
|
|
153
|
+
if (isDefinitelyEsmFile(resolvedModuleRealPath)) continue;
|
|
154
|
+
if (isDeclaredEsmEntry(resolvedModuleRealPath, esmEntryList, toRealPath)) continue;
|
|
90
155
|
const groupKey = `${pkg.name}::${resolvedModuleRealPath}`;
|
|
91
156
|
const issuer = {
|
|
92
157
|
id: dep.module.id,
|
|
@@ -97,11 +162,11 @@ const rule = defineRule(()=>({
|
|
|
97
162
|
else groups.set(groupKey, {
|
|
98
163
|
packageName: pkg.name,
|
|
99
164
|
packageVersion: pkg.version,
|
|
100
|
-
esmEntry,
|
|
165
|
+
esmEntry: esmEntryList[0],
|
|
101
166
|
resolvedModule: {
|
|
102
167
|
id: dep.dependency.id,
|
|
103
168
|
path: dep.dependency.path,
|
|
104
|
-
|
|
169
|
+
identifier: dep.dependency.identifier
|
|
105
170
|
},
|
|
106
171
|
issuers: [
|
|
107
172
|
issuer
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Linter } from '@rsdoctor/types';
|
|
2
|
+
export declare const rules: Linter.RuleData[];
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Linter } from '@rsdoctor/types';
|
|
2
|
+
export declare const rules: Linter.RuleData[];
|
|
@@ -56,7 +56,7 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
56
56
|
const { extensions, ignore = [], threshold = 5000 } = ruleConfig;
|
|
57
57
|
if (!extensions || extensions?.length === 0) return;
|
|
58
58
|
if (0 === loader.length) return;
|
|
59
|
-
const { config } = configs.find((e)=>'
|
|
59
|
+
const { config } = configs.find((e)=>'rspack' === e.name) || {
|
|
60
60
|
config: void 0
|
|
61
61
|
};
|
|
62
62
|
if (!config) return;
|
|
@@ -29,7 +29,7 @@ const rule = defineRule(()=>({
|
|
|
29
29
|
const { extensions, ignore = [], threshold = 5000 } = ruleConfig;
|
|
30
30
|
if (!extensions || extensions?.length === 0) return;
|
|
31
31
|
if (0 === loader.length) return;
|
|
32
|
-
const { config } = configs.find((e)=>'
|
|
32
|
+
const { config } = configs.find((e)=>'rspack' === e.name) || {
|
|
33
33
|
config: void 0
|
|
34
34
|
};
|
|
35
35
|
if (!config) return;
|
|
@@ -88,7 +88,7 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
88
88
|
module: {
|
|
89
89
|
id: module.id,
|
|
90
90
|
path: module.path,
|
|
91
|
-
|
|
91
|
+
identifier: module.identifier
|
|
92
92
|
},
|
|
93
93
|
connections: sideEffectConnections.map((c)=>({
|
|
94
94
|
originModule: c.originModule ?? module.id,
|
package/dist/types/plugin.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RsdoctorPrimarySDK } from '@rsdoctor/sdk';
|
|
2
2
|
import type { Linter, Linter as LinterType, Plugin, SDK } from '@rsdoctor/types';
|
|
3
|
-
export interface RsdoctorMultiplePluginOptions<Rules extends LinterType.ExtendRuleData[] = LinterType.ExtendRuleData[]> extends Omit<Plugin.
|
|
3
|
+
export interface RsdoctorMultiplePluginOptions<Rules extends LinterType.ExtendRuleData[] = LinterType.ExtendRuleData[]> extends Omit<Plugin.RsdoctorRspackPluginOptions<Rules>, 'sdkInstance'>, Pick<ConstructorParameters<typeof RsdoctorPrimarySDK>[0], 'stage'> {
|
|
4
4
|
/**
|
|
5
5
|
* name of builder
|
|
6
6
|
*/
|
|
@@ -40,7 +40,7 @@ export interface RsdoctorRspackPluginExperiments {
|
|
|
40
40
|
export interface RsdoctorRspackPluginExperimentsNormalized {
|
|
41
41
|
enableNativePlugin?: NativePluginConfig;
|
|
42
42
|
}
|
|
43
|
-
export interface RsdoctorRspackPluginOptions<Rules extends LinterType.ExtendRuleData[]> extends Plugin.
|
|
43
|
+
export interface RsdoctorRspackPluginOptions<Rules extends LinterType.ExtendRuleData[]> extends Plugin.RsdoctorRspackPluginOptions<Rules> {
|
|
44
44
|
/**
|
|
45
45
|
* The experiments of the Rsdoctor Rspack plugin.
|
|
46
46
|
*/
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RsdoctorPrimarySDK } from '@rsdoctor/sdk';
|
|
2
2
|
import type { Linter, Linter as LinterType, Plugin, SDK } from '@rsdoctor/types';
|
|
3
|
-
export interface RsdoctorMultiplePluginOptions<Rules extends LinterType.ExtendRuleData[] = LinterType.ExtendRuleData[]> extends Omit<Plugin.
|
|
3
|
+
export interface RsdoctorMultiplePluginOptions<Rules extends LinterType.ExtendRuleData[] = LinterType.ExtendRuleData[]> extends Omit<Plugin.RsdoctorRspackPluginOptions<Rules>, 'sdkInstance'>, Pick<ConstructorParameters<typeof RsdoctorPrimarySDK>[0], 'stage'> {
|
|
4
4
|
/**
|
|
5
5
|
* name of builder
|
|
6
6
|
*/
|
|
@@ -40,7 +40,7 @@ export interface RsdoctorRspackPluginExperiments {
|
|
|
40
40
|
export interface RsdoctorRspackPluginExperimentsNormalized {
|
|
41
41
|
enableNativePlugin?: NativePluginConfig;
|
|
42
42
|
}
|
|
43
|
-
export interface RsdoctorRspackPluginOptions<Rules extends LinterType.ExtendRuleData[]> extends Plugin.
|
|
43
|
+
export interface RsdoctorRspackPluginOptions<Rules extends LinterType.ExtendRuleData[]> extends Plugin.RsdoctorRspackPluginOptions<Rules> {
|
|
44
44
|
/**
|
|
45
45
|
* The experiments of the Rsdoctor Rspack plugin.
|
|
46
46
|
*/
|
package/dist/types/rules.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RuleSetRule } from '
|
|
2
|
-
export
|
|
1
|
+
import type { RuleSetRule } from '@rspack/core';
|
|
2
|
+
export type Rule = RuleSetRule & {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* The legacy `loaders` field used by rule normalizers.
|
|
5
5
|
*/
|
|
6
6
|
loaders: RuleSetRule['use'];
|
|
7
|
-
}
|
|
7
|
+
};
|
package/dist/types/rules.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { RuleSetRule } from '
|
|
2
|
-
export
|
|
1
|
+
import type { RuleSetRule } from '@rspack/core';
|
|
2
|
+
export type Rule = RuleSetRule & {
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* The legacy `loaders` field used by rule normalizers.
|
|
5
5
|
*/
|
|
6
6
|
loaders: RuleSetRule['use'];
|
|
7
|
-
}
|
|
7
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rsdoctor/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/web-infra-dev/rsdoctor",
|
|
@@ -90,19 +90,19 @@
|
|
|
90
90
|
"@rsbuild/plugin-check-syntax": "1.6.1",
|
|
91
91
|
"@rspack/resolver": "0.2.8",
|
|
92
92
|
"es-toolkit": "^1.45.1",
|
|
93
|
-
"filesize": "^
|
|
93
|
+
"filesize": "^11.0.17",
|
|
94
94
|
"fs-extra": "^11.1.1",
|
|
95
95
|
"semver": "^7.7.4",
|
|
96
96
|
"source-map": "^0.7.6",
|
|
97
|
-
"@rsdoctor/
|
|
98
|
-
"@rsdoctor/
|
|
99
|
-
"@rsdoctor/
|
|
100
|
-
"@rsdoctor/
|
|
97
|
+
"@rsdoctor/graph": "2.0.0-alpha.0",
|
|
98
|
+
"@rsdoctor/sdk": "2.0.0-alpha.0",
|
|
99
|
+
"@rsdoctor/types": "2.0.0-alpha.0",
|
|
100
|
+
"@rsdoctor/utils": "2.0.0-alpha.0"
|
|
101
101
|
},
|
|
102
102
|
"devDependencies": {
|
|
103
|
-
"@rspack/core": "2.0.
|
|
103
|
+
"@rspack/core": "2.0.4",
|
|
104
104
|
"@types/fs-extra": "^11.0.4",
|
|
105
|
-
"@types/node": "^
|
|
105
|
+
"@types/node": "^24.12.3",
|
|
106
106
|
"@types/node-fetch": "^2.6.13",
|
|
107
107
|
"@types/semver": "^7.7.1",
|
|
108
108
|
"@types/tapable": "2.3.0",
|
|
@@ -111,8 +111,7 @@
|
|
|
111
111
|
"string-loader": "0.0.1",
|
|
112
112
|
"ts-loader": "^9.5.7",
|
|
113
113
|
"tslib": "2.8.1",
|
|
114
|
-
"typescript": "^
|
|
115
|
-
"webpack": "^5.105.4",
|
|
114
|
+
"typescript": "^6.0.3",
|
|
116
115
|
"@scripts/test-helper": "0.1.1"
|
|
117
116
|
},
|
|
118
117
|
"publishConfig": {
|
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, definition)=>{
|
|
5
|
-
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: definition[key]
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
})();
|
|
11
|
-
(()=>{
|
|
12
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
13
|
-
})();
|
|
14
|
-
(()=>{
|
|
15
|
-
__webpack_require__.r = (exports1)=>{
|
|
16
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
17
|
-
value: 'Module'
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
20
|
-
value: true
|
|
21
|
-
});
|
|
22
|
-
};
|
|
23
|
-
})();
|
|
24
|
-
var __webpack_exports__ = {};
|
|
25
|
-
__webpack_require__.r(__webpack_exports__);
|
|
26
|
-
__webpack_require__.d(__webpack_exports__, {
|
|
27
|
-
appendTreeShaking: ()=>appendTreeShaking
|
|
28
|
-
});
|
|
29
|
-
const graph_namespaceObject = require("@rsdoctor/graph");
|
|
30
|
-
const external_utils_cjs_namespaceObject = require("./utils.cjs");
|
|
31
|
-
function transformMgm(origin, webpackGraph, graph, cache) {
|
|
32
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
33
|
-
if (!module) return;
|
|
34
|
-
const mgm = new graph_namespaceObject.ModuleGraphModule(module, graph);
|
|
35
|
-
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
36
|
-
graph.addModuleGraphModule(mgm);
|
|
37
|
-
for (const info of originalMgm.exports){
|
|
38
|
-
const { name } = info;
|
|
39
|
-
const exportIdStatement = (0, external_utils_cjs_namespaceObject.getExportIdentifierStatement)(name, module) ?? graph_namespaceObject.Statement.getDefaultStatement(module);
|
|
40
|
-
const declareIdStatement = (0, external_utils_cjs_namespaceObject.getDeclarationIdentifier)(name, module);
|
|
41
|
-
const exportInfo = new graph_namespaceObject.ExportInfo(info.name, exportIdStatement);
|
|
42
|
-
if (declareIdStatement) {
|
|
43
|
-
const variable = new graph_namespaceObject.Variable(name, module, info.getUsedInfo(), declareIdStatement);
|
|
44
|
-
variable.setExportInfo(exportInfo);
|
|
45
|
-
mgm.addVariable(variable);
|
|
46
|
-
}
|
|
47
|
-
cache.set(info, exportInfo);
|
|
48
|
-
mgm.addExportInfo(exportInfo);
|
|
49
|
-
}
|
|
50
|
-
for (const dep of origin.dependencies){
|
|
51
|
-
if ('harmony import specifier' !== dep.type) continue;
|
|
52
|
-
const HISDep = dep;
|
|
53
|
-
const { name, userRequest } = HISDep;
|
|
54
|
-
const originName = HISDep.getIds(webpackGraph)[0] ?? graph_namespaceObject.SideEffect.NamespaceSymbol;
|
|
55
|
-
const importIdStatement = module.getStatement(dep.loc);
|
|
56
|
-
const importInfo = new graph_namespaceObject.SideEffect(name, module, importIdStatement, userRequest, originName);
|
|
57
|
-
mgm.addSideEffect(importInfo);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function appendExportConnection(origin, webpackGraph, graph, cache) {
|
|
61
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
62
|
-
const mgm = graph.getModuleGraphModule(module);
|
|
63
|
-
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
64
|
-
if (!mgm || !module) return;
|
|
65
|
-
for (const info of originalMgm.exports){
|
|
66
|
-
if (!info.isReexport()) continue;
|
|
67
|
-
const lastExport = graph_namespaceObject.Webpack.getLastExportInfo(info, webpackGraph);
|
|
68
|
-
const lastSdkExport = cache.get(lastExport);
|
|
69
|
-
const sdkExport = cache.get(info);
|
|
70
|
-
if (!lastSdkExport || !sdkExport) return;
|
|
71
|
-
sdkExport.setFromExport(lastSdkExport);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function appendImportConnection(origin, graph) {
|
|
75
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
76
|
-
const mgm = graph.getModuleGraphModule(module);
|
|
77
|
-
if (!mgm || !module) return;
|
|
78
|
-
for (const info of mgm.getSideEffects()){
|
|
79
|
-
const exportName = info.originName ?? info.name;
|
|
80
|
-
const resolveModule = info.fromDependency?.dependency;
|
|
81
|
-
if (!resolveModule) continue;
|
|
82
|
-
const resolveExport = graph.getModuleGraphModule(resolveModule).getExport(exportName);
|
|
83
|
-
if (resolveExport) info.setExportInfo(resolveExport);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function appendTreeShaking(moduleGraph, compilation) {
|
|
87
|
-
if (!graph_namespaceObject.ModuleGraphTrans.isWebpack5orRspack(compilation)) return moduleGraph;
|
|
88
|
-
if ('moduleGraph' in compilation) {
|
|
89
|
-
const exportData = new Map();
|
|
90
|
-
const webpackCompilation = compilation;
|
|
91
|
-
const { moduleGraph: webpackGraph } = webpackCompilation;
|
|
92
|
-
const allModules = graph_namespaceObject.Webpack.getAllModules(webpackCompilation);
|
|
93
|
-
allModules.forEach((origin)=>transformMgm(origin, webpackGraph, moduleGraph, exportData));
|
|
94
|
-
allModules.forEach((origin)=>appendExportConnection(origin, webpackGraph, moduleGraph, exportData));
|
|
95
|
-
allModules.forEach((origin)=>appendImportConnection(origin, moduleGraph));
|
|
96
|
-
exportData.clear();
|
|
97
|
-
}
|
|
98
|
-
return moduleGraph;
|
|
99
|
-
}
|
|
100
|
-
exports.appendTreeShaking = __webpack_exports__.appendTreeShaking;
|
|
101
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
102
|
-
"appendTreeShaking"
|
|
103
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
104
|
-
Object.defineProperty(exports, '__esModule', {
|
|
105
|
-
value: true
|
|
106
|
-
});
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { ExportInfo, ModuleGraphModule, ModuleGraphTrans, SideEffect, Statement, Variable, Webpack } from "@rsdoctor/graph";
|
|
3
|
-
import { getDeclarationIdentifier, getExportIdentifierStatement } from "./utils.js";
|
|
4
|
-
function transformMgm(origin, webpackGraph, graph, cache) {
|
|
5
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
6
|
-
if (!module) return;
|
|
7
|
-
const mgm = new ModuleGraphModule(module, graph);
|
|
8
|
-
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
9
|
-
graph.addModuleGraphModule(mgm);
|
|
10
|
-
for (const info of originalMgm.exports){
|
|
11
|
-
const { name } = info;
|
|
12
|
-
const exportIdStatement = getExportIdentifierStatement(name, module) ?? Statement.getDefaultStatement(module);
|
|
13
|
-
const declareIdStatement = getDeclarationIdentifier(name, module);
|
|
14
|
-
const exportInfo = new ExportInfo(info.name, exportIdStatement);
|
|
15
|
-
if (declareIdStatement) {
|
|
16
|
-
const variable = new Variable(name, module, info.getUsedInfo(), declareIdStatement);
|
|
17
|
-
variable.setExportInfo(exportInfo);
|
|
18
|
-
mgm.addVariable(variable);
|
|
19
|
-
}
|
|
20
|
-
cache.set(info, exportInfo);
|
|
21
|
-
mgm.addExportInfo(exportInfo);
|
|
22
|
-
}
|
|
23
|
-
for (const dep of origin.dependencies){
|
|
24
|
-
if ('harmony import specifier' !== dep.type) continue;
|
|
25
|
-
const HISDep = dep;
|
|
26
|
-
const { name, userRequest } = HISDep;
|
|
27
|
-
const originName = HISDep.getIds(webpackGraph)[0] ?? SideEffect.NamespaceSymbol;
|
|
28
|
-
const importIdStatement = module.getStatement(dep.loc);
|
|
29
|
-
const importInfo = new SideEffect(name, module, importIdStatement, userRequest, originName);
|
|
30
|
-
mgm.addSideEffect(importInfo);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
function appendExportConnection(origin, webpackGraph, graph, cache) {
|
|
34
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
35
|
-
const mgm = graph.getModuleGraphModule(module);
|
|
36
|
-
const originalMgm = webpackGraph.getExportsInfo(origin);
|
|
37
|
-
if (!mgm || !module) return;
|
|
38
|
-
for (const info of originalMgm.exports){
|
|
39
|
-
if (!info.isReexport()) continue;
|
|
40
|
-
const lastExport = Webpack.getLastExportInfo(info, webpackGraph);
|
|
41
|
-
const lastSdkExport = cache.get(lastExport);
|
|
42
|
-
const sdkExport = cache.get(info);
|
|
43
|
-
if (!lastSdkExport || !sdkExport) return;
|
|
44
|
-
sdkExport.setFromExport(lastSdkExport);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function appendImportConnection(origin, graph) {
|
|
48
|
-
const module = graph.getModuleByWebpackId(origin.identifier());
|
|
49
|
-
const mgm = graph.getModuleGraphModule(module);
|
|
50
|
-
if (!mgm || !module) return;
|
|
51
|
-
for (const info of mgm.getSideEffects()){
|
|
52
|
-
const exportName = info.originName ?? info.name;
|
|
53
|
-
const resolveModule = info.fromDependency?.dependency;
|
|
54
|
-
if (!resolveModule) continue;
|
|
55
|
-
const resolveExport = graph.getModuleGraphModule(resolveModule).getExport(exportName);
|
|
56
|
-
if (resolveExport) info.setExportInfo(resolveExport);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function appendTreeShaking(moduleGraph, compilation) {
|
|
60
|
-
if (!ModuleGraphTrans.isWebpack5orRspack(compilation)) return moduleGraph;
|
|
61
|
-
if ('moduleGraph' in compilation) {
|
|
62
|
-
const exportData = new Map();
|
|
63
|
-
const webpackCompilation = compilation;
|
|
64
|
-
const { moduleGraph: webpackGraph } = webpackCompilation;
|
|
65
|
-
const allModules = Webpack.getAllModules(webpackCompilation);
|
|
66
|
-
allModules.forEach((origin)=>transformMgm(origin, webpackGraph, moduleGraph, exportData));
|
|
67
|
-
allModules.forEach((origin)=>appendExportConnection(origin, webpackGraph, moduleGraph, exportData));
|
|
68
|
-
allModules.forEach((origin)=>appendImportConnection(origin, moduleGraph));
|
|
69
|
-
exportData.clear();
|
|
70
|
-
}
|
|
71
|
-
return moduleGraph;
|
|
72
|
-
}
|
|
73
|
-
export { appendTreeShaking };
|