@rsdoctor/core 0.0.2-beta.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.
Files changed (139) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +15 -0
  3. package/dist/build-utils/build/chunks/assetsModules.d.ts +3 -0
  4. package/dist/build-utils/build/chunks/assetsModules.js +32 -0
  5. package/dist/build-utils/build/chunks/chunkTransform.d.ts +4 -0
  6. package/dist/build-utils/build/chunks/chunkTransform.js +31 -0
  7. package/dist/build-utils/build/chunks/generateTileGraph.d.ts +10 -0
  8. package/dist/build-utils/build/chunks/generateTileGraph.js +77 -0
  9. package/dist/build-utils/build/chunks/index.d.ts +3 -0
  10. package/dist/build-utils/build/chunks/index.js +26 -0
  11. package/dist/build-utils/build/index.d.ts +4 -0
  12. package/dist/build-utils/build/index.js +47 -0
  13. package/dist/build-utils/build/module-graph/index.d.ts +3 -0
  14. package/dist/build-utils/build/module-graph/index.js +26 -0
  15. package/dist/build-utils/build/module-graph/parser.d.ts +2 -0
  16. package/dist/build-utils/build/module-graph/parser.js +44 -0
  17. package/dist/build-utils/build/module-graph/transform.d.ts +4 -0
  18. package/dist/build-utils/build/module-graph/transform.js +37 -0
  19. package/dist/build-utils/build/module-graph/treeShaking.d.ts +3 -0
  20. package/dist/build-utils/build/module-graph/treeShaking.js +130 -0
  21. package/dist/build-utils/build/module-graph/utils.d.ts +3 -0
  22. package/dist/build-utils/build/module-graph/utils.js +113 -0
  23. package/dist/build-utils/build/module-graph/webpack/transform.d.ts +11 -0
  24. package/dist/build-utils/build/module-graph/webpack/transform.js +197 -0
  25. package/dist/build-utils/build/utils/index.d.ts +3 -0
  26. package/dist/build-utils/build/utils/index.js +26 -0
  27. package/dist/build-utils/build/utils/loader.d.ts +12 -0
  28. package/dist/build-utils/build/utils/loader.js +210 -0
  29. package/dist/build-utils/build/utils/parseBundle.d.ts +12 -0
  30. package/dist/build-utils/build/utils/parseBundle.js +277 -0
  31. package/dist/build-utils/build/utils/plugin.d.ts +5 -0
  32. package/dist/build-utils/build/utils/plugin.js +63 -0
  33. package/dist/build-utils/common/chunks/assetsContent.d.ts +4 -0
  34. package/dist/build-utils/common/chunks/assetsContent.js +34 -0
  35. package/dist/build-utils/common/chunks/assetsModules.d.ts +23 -0
  36. package/dist/build-utils/common/chunks/assetsModules.js +106 -0
  37. package/dist/build-utils/common/chunks/chunkTransform.d.ts +5 -0
  38. package/dist/build-utils/common/chunks/chunkTransform.js +73 -0
  39. package/dist/build-utils/common/chunks/index.d.ts +3 -0
  40. package/dist/build-utils/common/chunks/index.js +26 -0
  41. package/dist/build-utils/common/index.d.ts +5 -0
  42. package/dist/build-utils/common/index.js +50 -0
  43. package/dist/build-utils/common/module-graph/compatible.d.ts +9 -0
  44. package/dist/build-utils/common/module-graph/compatible.js +63 -0
  45. package/dist/build-utils/common/module-graph/index.d.ts +3 -0
  46. package/dist/build-utils/common/module-graph/index.js +26 -0
  47. package/dist/build-utils/common/module-graph/transform.d.ts +10 -0
  48. package/dist/build-utils/common/module-graph/transform.js +193 -0
  49. package/dist/build-utils/common/module-graph/utils.d.ts +17 -0
  50. package/dist/build-utils/common/module-graph/utils.js +62 -0
  51. package/dist/build-utils/common/trans-utils/index.d.ts +1 -0
  52. package/dist/build-utils/common/trans-utils/index.js +22 -0
  53. package/dist/build-utils/common/trans-utils/transStats.d.ts +6 -0
  54. package/dist/build-utils/common/trans-utils/transStats.js +35 -0
  55. package/dist/build-utils/common/webpack/compatible.d.ts +26 -0
  56. package/dist/build-utils/common/webpack/compatible.js +181 -0
  57. package/dist/build-utils/index.d.ts +2 -0
  58. package/dist/build-utils/index.js +41 -0
  59. package/dist/index.d.ts +3 -0
  60. package/dist/index.js +43 -0
  61. package/dist/inner-plugins/constants.d.ts +6 -0
  62. package/dist/inner-plugins/constants.js +52 -0
  63. package/dist/inner-plugins/index.d.ts +2 -0
  64. package/dist/inner-plugins/index.js +24 -0
  65. package/dist/inner-plugins/loaders/proxy.d.ts +4 -0
  66. package/dist/inner-plugins/loaders/proxy.js +115 -0
  67. package/dist/inner-plugins/plugins/base.d.ts +13 -0
  68. package/dist/inner-plugins/plugins/base.js +45 -0
  69. package/dist/inner-plugins/plugins/errors.d.ts +11 -0
  70. package/dist/inner-plugins/plugins/errors.js +85 -0
  71. package/dist/inner-plugins/plugins/index.d.ts +6 -0
  72. package/dist/inner-plugins/plugins/index.js +32 -0
  73. package/dist/inner-plugins/plugins/loader.d.ts +11 -0
  74. package/dist/inner-plugins/plugins/loader.js +157 -0
  75. package/dist/inner-plugins/plugins/plugins.d.ts +8 -0
  76. package/dist/inner-plugins/plugins/plugins.js +60 -0
  77. package/dist/inner-plugins/plugins/progress.d.ts +8 -0
  78. package/dist/inner-plugins/plugins/progress.js +59 -0
  79. package/dist/inner-plugins/plugins/summary.d.ts +14 -0
  80. package/dist/inner-plugins/plugins/summary.js +115 -0
  81. package/dist/inner-plugins/utils/circleDetect.d.ts +4 -0
  82. package/dist/inner-plugins/utils/circleDetect.js +42 -0
  83. package/dist/inner-plugins/utils/config.d.ts +7 -0
  84. package/dist/inner-plugins/utils/config.js +145 -0
  85. package/dist/inner-plugins/utils/index.d.ts +5 -0
  86. package/dist/inner-plugins/utils/index.js +30 -0
  87. package/dist/inner-plugins/utils/loader.d.ts +11 -0
  88. package/dist/inner-plugins/utils/loader.js +201 -0
  89. package/dist/inner-plugins/utils/plugin.d.ts +5 -0
  90. package/dist/inner-plugins/utils/plugin.js +126 -0
  91. package/dist/inner-plugins/utils/sdk.d.ts +3 -0
  92. package/dist/inner-plugins/utils/sdk.js +36 -0
  93. package/dist/rules/index.d.ts +3 -0
  94. package/dist/rules/index.js +33 -0
  95. package/dist/rules/linter.d.ts +13 -0
  96. package/dist/rules/linter.js +74 -0
  97. package/dist/rules/rule.d.ts +31 -0
  98. package/dist/rules/rule.js +140 -0
  99. package/dist/rules/rules/default-import-check/index.d.ts +4 -0
  100. package/dist/rules/rules/default-import-check/index.js +124 -0
  101. package/dist/rules/rules/default-import-check/types.d.ts +4 -0
  102. package/dist/rules/rules/default-import-check/types.js +16 -0
  103. package/dist/rules/rules/default-import-check/utils.d.ts +10 -0
  104. package/dist/rules/rules/default-import-check/utils.js +93 -0
  105. package/dist/rules/rules/duplicate-package/index.d.ts +4 -0
  106. package/dist/rules/rules/duplicate-package/index.js +71 -0
  107. package/dist/rules/rules/duplicate-package/types.d.ts +24 -0
  108. package/dist/rules/rules/duplicate-package/types.js +51 -0
  109. package/dist/rules/rules/duplicate-package/utils.d.ts +3 -0
  110. package/dist/rules/rules/duplicate-package/utils.js +89 -0
  111. package/dist/rules/rules/ecma-version-check/index.d.ts +4 -0
  112. package/dist/rules/rules/ecma-version-check/index.js +82 -0
  113. package/dist/rules/rules/ecma-version-check/types.d.ts +7 -0
  114. package/dist/rules/rules/ecma-version-check/types.js +16 -0
  115. package/dist/rules/rules/ecma-version-check/utils.d.ts +2 -0
  116. package/dist/rules/rules/ecma-version-check/utils.js +31 -0
  117. package/dist/rules/rules/index.d.ts +1 -0
  118. package/dist/rules/rules/index.js +37 -0
  119. package/dist/rules/rules/loader-performance-optimization/index.d.ts +4 -0
  120. package/dist/rules/rules/loader-performance-optimization/index.js +121 -0
  121. package/dist/rules/rules/loader-performance-optimization/types.d.ts +22 -0
  122. package/dist/rules/rules/loader-performance-optimization/types.js +16 -0
  123. package/dist/rules/rules/loader-performance-optimization/utils.d.ts +1 -0
  124. package/dist/rules/rules/loader-performance-optimization/utils.js +38 -0
  125. package/dist/rules/utils.d.ts +3 -0
  126. package/dist/rules/utils.js +44 -0
  127. package/dist/types/chunks.d.ts +11 -0
  128. package/dist/types/chunks.js +16 -0
  129. package/dist/types/index.d.ts +5 -0
  130. package/dist/types/index.js +30 -0
  131. package/dist/types/loader.d.ts +19 -0
  132. package/dist/types/loader.js +16 -0
  133. package/dist/types/plugin.d.ts +72 -0
  134. package/dist/types/plugin.js +16 -0
  135. package/dist/types/rules.d.ts +7 -0
  136. package/dist/types/rules.js +16 -0
  137. package/dist/types/webpack.d.ts +14 -0
  138. package/dist/types/webpack.js +16 -0
  139. package/package.json +87 -0
@@ -0,0 +1,277 @@
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 parseBundle_exports = {};
30
+ __export(parseBundle_exports, {
31
+ parseBundle: () => parseBundle
32
+ });
33
+ module.exports = __toCommonJS(parseBundle_exports);
34
+ var import_fs = __toESM(require("fs"));
35
+ var import_lodash = require("lodash");
36
+ var import_bytes = __toESM(require("bytes"));
37
+ var import_ruleUtils = require("@rsdoctor/utils/ruleUtils");
38
+ var import_path = require("path");
39
+ const parseBundle = (bundlePath, modulesData) => {
40
+ if (bundlePath.indexOf(".worker.") > 0) {
41
+ return {};
42
+ }
43
+ if ((0, import_path.extname)(bundlePath) !== ".js") {
44
+ return {};
45
+ }
46
+ const content = import_fs.default.readFileSync(bundlePath, "utf8");
47
+ const ast = import_ruleUtils.parser.internal.parse(content, {
48
+ sourceType: "script",
49
+ ecmaVersion: "latest"
50
+ });
51
+ const walkState = {
52
+ locations: null,
53
+ expressionStatementDepth: 0
54
+ };
55
+ import_ruleUtils.parser.walk.recursive(ast, walkState, {
56
+ ExpressionStatement(node, state, c) {
57
+ if (state.locations)
58
+ return;
59
+ state.expressionStatementDepth++;
60
+ if (
61
+ // Webpack 5 stores modules in the the top-level IIFE
62
+ state.expressionStatementDepth === 1 && // ast?.range?.includes(node) &&
63
+ isIIFE(node)
64
+ ) {
65
+ const fn = getIIFECallExpression(node);
66
+ if (
67
+ // It should not contain neither arguments
68
+ fn.arguments.length === 0 && // ...nor parameters
69
+ fn.callee.params.length === 0
70
+ ) {
71
+ const firstVariableDeclaration = fn.callee.body.body.find(
72
+ (node2) => node2.type === "VariableDeclaration"
73
+ );
74
+ if (firstVariableDeclaration) {
75
+ for (const declaration of firstVariableDeclaration.declarations) {
76
+ if (declaration.init) {
77
+ state.locations = getModulesLocations(declaration.init);
78
+ if (state.locations) {
79
+ break;
80
+ }
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ if (!state.locations) {
87
+ c(node.expression, state);
88
+ }
89
+ state.expressionStatementDepth--;
90
+ },
91
+ AssignmentExpression(node, state) {
92
+ if (state.locations)
93
+ return;
94
+ const { left, right } = node;
95
+ if (left && left.object && left.object.name === "exports" && left.property && left.property.name === "modules" && isModulesHash(right)) {
96
+ state.locations = getModulesLocations(right);
97
+ }
98
+ },
99
+ CallExpression(node, state, c) {
100
+ if (state.locations)
101
+ return;
102
+ const args = node.arguments;
103
+ if (node.callee.type === "FunctionExpression" && !node.callee.id && args.length === 1 && isSimpleModulesList(args[0])) {
104
+ state.locations = getModulesLocations(args[0]);
105
+ return;
106
+ }
107
+ if (node.callee.type === "Identifier" && mayBeAsyncChunkArguments(args) && isModulesList(args[1])) {
108
+ state.locations = getModulesLocations(args[1]);
109
+ return;
110
+ }
111
+ if (isAsyncChunkPushExpression(node)) {
112
+ state.locations = getModulesLocations(args[0].elements[1]);
113
+ return;
114
+ }
115
+ if (isAsyncWebWorkerChunkExpression(node)) {
116
+ state.locations = getModulesLocations(args[1]);
117
+ return;
118
+ }
119
+ args.forEach((arg) => c(arg, state));
120
+ }
121
+ });
122
+ let modules;
123
+ if (walkState.locations) {
124
+ modules = (0, import_lodash.mapValues)(
125
+ walkState.locations,
126
+ (loc) => content.slice(loc.start, loc.end)
127
+ );
128
+ } else {
129
+ modules = {};
130
+ }
131
+ const modulesObj = {};
132
+ for (const module2 in modules) {
133
+ if (!module2) {
134
+ return {};
135
+ }
136
+ const moduleContent = modules[module2];
137
+ const size = moduleContent && Buffer.byteLength(moduleContent);
138
+ const _filterModules = (0, import_lodash.find)(modulesData, {
139
+ id: Number(module2)
140
+ });
141
+ const identifier = _filterModules?.identifier || (0, import_lodash.find)(modulesData, { id: module2 })?.identifier || "";
142
+ modulesObj[identifier] = {
143
+ size,
144
+ sizeConvert: (0, import_bytes.default)(size || 0),
145
+ content: moduleContent
146
+ };
147
+ }
148
+ return {
149
+ modules: modulesObj,
150
+ src: content,
151
+ runtimeSrc: getBundleRuntime(content, walkState.locations)
152
+ };
153
+ };
154
+ function getBundleRuntime(content, modulesLocations) {
155
+ const sortedLocations = Object.values(modulesLocations || {}).sort(
156
+ (a, b) => a.start - b.start
157
+ );
158
+ let result = "";
159
+ let lastIndex = 0;
160
+ for (const { start, end } of sortedLocations) {
161
+ result += content.slice(lastIndex, start);
162
+ lastIndex = end;
163
+ }
164
+ return result + content.slice(lastIndex, content.length);
165
+ }
166
+ function isIIFE(node) {
167
+ return node.type === "ExpressionStatement" && (node.expression.type === "CallExpression" || node.expression.type === "UnaryExpression" && node.expression.argument.type === "CallExpression");
168
+ }
169
+ function getIIFECallExpression(node) {
170
+ if (node.expression.type === "UnaryExpression") {
171
+ return node.expression.argument;
172
+ }
173
+ return node.expression;
174
+ }
175
+ function isModulesList(node) {
176
+ return isSimpleModulesList(node) || // Modules are contained in expression `Array([minimum ID]).concat([<module>, <module>, ...])`
177
+ isOptimizedModulesArray(node);
178
+ }
179
+ function isSimpleModulesList(node) {
180
+ return (
181
+ // Modules are contained in hash. Keys are module ids.
182
+ isModulesHash(node) || // Modules are contained in array. Indexes are module ids.
183
+ isModulesArray(node)
184
+ );
185
+ }
186
+ function isModulesHash(node) {
187
+ return node.type === "ObjectExpression" && node.properties.map((node2) => node2.value).every(isModuleWrapper);
188
+ }
189
+ function isModulesArray(node) {
190
+ return node.type === "ArrayExpression" && node.elements.every(
191
+ (elem) => (
192
+ // Some of array items may be skipped because there is no module with such id
193
+ !elem || isModuleWrapper(elem)
194
+ )
195
+ );
196
+ }
197
+ function isOptimizedModulesArray(node) {
198
+ return node.type === "CallExpression" && node.callee.type === "MemberExpression" && // Make sure the object called is `Array(<some number>)`
199
+ node.callee.object.type === "CallExpression" && node.callee.object.callee.type === "Identifier" && node.callee.object.callee.name === "Array" && node.callee.object.arguments.length === 1 && isNumericId(node.callee.object.arguments[0]) && // Make sure the property X called for `Array(<some number>).X` is `concat`
200
+ node.callee.property.type === "Identifier" && node.callee.property.name === "concat" && // Make sure exactly one array is passed in to `concat`
201
+ node.arguments.length === 1 && isModulesArray(node.arguments[0]);
202
+ }
203
+ function isModuleWrapper(node) {
204
+ return (
205
+ // It's an anonymous function expression that wraps module
206
+ (node.type === "FunctionExpression" || node.type === "ArrowFunctionExpression") && !node.id || // If `DedupePlugin` is used it can be an ID of duplicated module...
207
+ isModuleId(node) || // or an array of shape [<module_id>, ...args]
208
+ node.type === "ArrayExpression" && node.elements.length > 1 && isModuleId(node.elements[0])
209
+ );
210
+ }
211
+ function isModuleId(node) {
212
+ return node.type === "Literal" && (isNumericId(node) || typeof node.value === "string");
213
+ }
214
+ function isNumericId(node) {
215
+ return node.type === "Literal" && Number.isInteger(node.value) && node.value >= 0;
216
+ }
217
+ function isChunkIds(node) {
218
+ return node.type === "ArrayExpression" && node.elements.every(isModuleId);
219
+ }
220
+ function isAsyncChunkPushExpression(node) {
221
+ const { callee, arguments: args } = node;
222
+ return callee.type === "MemberExpression" && callee.property.name === "push" && callee.object.type === "AssignmentExpression" && args.length === 1 && args[0].type === "ArrayExpression" && mayBeAsyncChunkArguments(args[0].elements) && isModulesList(args[0].elements[1]);
223
+ }
224
+ function mayBeAsyncChunkArguments(args) {
225
+ return args.length >= 2 && isChunkIds(args[0]);
226
+ }
227
+ function isAsyncWebWorkerChunkExpression(node) {
228
+ const { callee, type, arguments: args } = node;
229
+ return type === "CallExpression" && callee.type === "MemberExpression" && args.length === 2 && isChunkIds(args[0]) && isModulesList(args[1]);
230
+ }
231
+ function getModulesLocations(node) {
232
+ if (node.type === "ObjectExpression") {
233
+ const modulesNodes = node.properties;
234
+ return modulesNodes.reduce(
235
+ (result, moduleNode) => {
236
+ const moduleId = moduleNode.key.name || moduleNode.key.value;
237
+ result[moduleId] = getModuleLocation(moduleNode.value);
238
+ return result;
239
+ },
240
+ {}
241
+ );
242
+ }
243
+ const isOptimizedArray = node.type === "CallExpression";
244
+ if (node.type === "ArrayExpression" || isOptimizedArray) {
245
+ const minId = isOptimizedArray ? (
246
+ // Get the [minId] value from the Array() call first argument literal value
247
+ node.callee.object.arguments[0].value
248
+ ) : (
249
+ // `0` for simple array
250
+ 0
251
+ );
252
+ const modulesNodes = isOptimizedArray ? (
253
+ // The modules reside in the `concat()` function call arguments
254
+ node.arguments[0].elements
255
+ ) : node.elements;
256
+ return modulesNodes.reduce(
257
+ (result, moduleNode, i) => {
258
+ if (moduleNode) {
259
+ result[i + minId] = getModuleLocation(moduleNode);
260
+ }
261
+ return result;
262
+ },
263
+ {}
264
+ );
265
+ }
266
+ return {};
267
+ }
268
+ function getModuleLocation(node) {
269
+ return {
270
+ start: node.start,
271
+ end: node.end
272
+ };
273
+ }
274
+ // Annotate the CommonJS export names for ESM import in node:
275
+ 0 && (module.exports = {
276
+ parseBundle
277
+ });
@@ -0,0 +1,5 @@
1
+ import type { Hook } from 'tapable';
2
+ import { Plugin } from '@rsdoctor/types';
3
+ export declare function shouldInterceptPluginHook<T extends Hook<any, any>>(hook: T): boolean;
4
+ export declare function interceptCompilerHooks(compiler: Plugin.BaseCompiler, interceptor: (name: string, hook: Hook<any, any>, scope: 'compiler') => void): void;
5
+ export declare function interceptCompilationHooks(compilation: Plugin.BaseCompilation, interceptor: (name: string, hook: Hook<any, any>, scope: 'compilation') => void): void;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var plugin_exports = {};
20
+ __export(plugin_exports, {
21
+ interceptCompilationHooks: () => interceptCompilationHooks,
22
+ interceptCompilerHooks: () => interceptCompilerHooks,
23
+ shouldInterceptPluginHook: () => shouldInterceptPluginHook
24
+ });
25
+ module.exports = __toCommonJS(plugin_exports);
26
+ var import_compatible = require("../../common/module-graph/compatible");
27
+ function shouldInterceptPluginHook(hook) {
28
+ if (hook._fakeHook) {
29
+ return false;
30
+ }
31
+ if (typeof hook.isUsed === "function") {
32
+ return hook.isUsed();
33
+ }
34
+ if (hook._map && hook._map.size === 0) {
35
+ return false;
36
+ }
37
+ return true;
38
+ }
39
+ function interceptCompilerHooks(compiler, interceptor) {
40
+ Object.keys(compiler.hooks).forEach((hook) => {
41
+ const v = compiler.hooks[hook];
42
+ if (shouldInterceptPluginHook(v)) {
43
+ interceptor(hook, v, "compiler");
44
+ }
45
+ });
46
+ }
47
+ function interceptCompilationHooks(compilation, interceptor) {
48
+ Object.keys(compilation.hooks).forEach((hook) => {
49
+ if (hook === "normalModuleLoader" && (0, import_compatible.isWebpack5orRspack)(compilation)) {
50
+ return;
51
+ }
52
+ const v = compilation.hooks[hook];
53
+ if (shouldInterceptPluginHook(v)) {
54
+ interceptor(hook, v, "compilation");
55
+ }
56
+ });
57
+ }
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ interceptCompilationHooks,
61
+ interceptCompilerHooks,
62
+ shouldInterceptPluginHook
63
+ });
@@ -0,0 +1,4 @@
1
+ import { ChunkGraph } from '@rsdoctor/graph';
2
+ export declare function assetsContents(assetMap: Map<string, {
3
+ content: string;
4
+ }>, chunkGraph: ChunkGraph): void;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var assetsContent_exports = {};
20
+ __export(assetsContent_exports, {
21
+ assetsContents: () => assetsContents
22
+ });
23
+ module.exports = __toCommonJS(assetsContent_exports);
24
+ function assetsContents(assetMap, chunkGraph) {
25
+ const assets = chunkGraph.getAssets();
26
+ assets.forEach((asset) => {
27
+ const { content = "" } = assetMap.get(asset.path) || {};
28
+ asset.content = content;
29
+ });
30
+ }
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ assetsContents
34
+ });
@@ -0,0 +1,23 @@
1
+ import { Plugin } from '@rsdoctor/types';
2
+ import type { ModuleGraph } from '@rsdoctor/graph';
3
+ import { ParseBundle } from "../../../types";
4
+ export type ParsedModuleSizeData = {
5
+ [x: string]: {
6
+ size: number;
7
+ sizeConvert: string;
8
+ content: string;
9
+ };
10
+ };
11
+ /**
12
+ * The following code is modified based on
13
+ * https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/8a3d3f0f40010f2b41ccd28519eda5a44e13da3e/src/analyzer.js#L20
14
+ *
15
+ * MIT Licensed
16
+ * Author th0r
17
+ * Copyright JS Foundation and other contributors.
18
+ * https://github.com/webpack-contrib/webpack-bundle-analyzer/blob/44bd8d0f9aa3b098e271af220096ea70cc44bc9e/LICENSE
19
+ */
20
+ export declare function getAssetsModulesData(bundleStats: Plugin.StatsCompilation, bundleDir: string, opts: {
21
+ parseBundle?: ParseBundle;
22
+ }): Promise<ParsedModuleSizeData | null>;
23
+ export declare function transformAssetsModulesData(parsedModulesData: ParsedModuleSizeData, moduleGraph: ModuleGraph): void;
@@ -0,0 +1,106 @@
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 assetsModules_exports = {};
30
+ __export(assetsModules_exports, {
31
+ getAssetsModulesData: () => getAssetsModulesData,
32
+ transformAssetsModulesData: () => transformAssetsModulesData
33
+ });
34
+ module.exports = __toCommonJS(assetsModules_exports);
35
+ var import_lodash = require("lodash");
36
+ var import_path = __toESM(require("path"));
37
+ var import_logger = require("@rsdoctor/utils/logger");
38
+ var import_module_graph = require("../module-graph");
39
+ const logger = (0, import_logger.createLogger)();
40
+ async function getAssetsModulesData(bundleStats, bundleDir, opts) {
41
+ const { parseBundle = () => ({}) } = opts || {};
42
+ if ((0, import_lodash.isEmpty)(bundleStats.assets) && !(0, import_lodash.isEmpty)(bundleStats.children)) {
43
+ const { children } = bundleStats;
44
+ const _bundleStats = children?.[0];
45
+ if (!children) {
46
+ return {};
47
+ }
48
+ for (let i = 1; i < children.length; i++) {
49
+ children[i]?.assets?.forEach((asset) => {
50
+ _bundleStats?.assets?.push(asset);
51
+ });
52
+ }
53
+ } else if (!(0, import_lodash.isEmpty)(bundleStats.children)) {
54
+ bundleStats?.children?.forEach((child) => {
55
+ child?.assets?.forEach((asset) => {
56
+ bundleStats?.assets?.push(asset);
57
+ });
58
+ });
59
+ }
60
+ let bundlesSources = null;
61
+ let parsedModules = null;
62
+ if (bundleDir && bundleStats?.assets) {
63
+ bundlesSources = {};
64
+ parsedModules = {};
65
+ for (const statAsset of bundleStats?.assets) {
66
+ const assetFile = import_path.default.join(bundleDir, statAsset.name);
67
+ let bundleInfo;
68
+ const collectedModules = [];
69
+ (0, import_module_graph.getModulesFromArray)(bundleStats.modules ?? [], collectedModules);
70
+ try {
71
+ bundleInfo = await parseBundle(assetFile, collectedModules);
72
+ } catch (err) {
73
+ const { code = "", message } = err;
74
+ const msg = code === "ENOENT" ? "no such file" : message;
75
+ process.env.DEVTOOLS_NODE_DEV === "1" && logger.warn(`Error parsing bundle asset "${assetFile}": ${msg}`);
76
+ continue;
77
+ }
78
+ bundlesSources[statAsset.name] = (0, import_lodash.pick)(bundleInfo, "src", "runtimeSrc");
79
+ Object.assign(parsedModules, bundleInfo?.modules || {});
80
+ }
81
+ if ((0, import_lodash.isEmpty)(bundlesSources)) {
82
+ bundlesSources = null;
83
+ parsedModules = null;
84
+ process.env.DEVTOOLS_DEV && logger.warn(
85
+ "\nNo bundles were parsed. Analyzer will show only original module sizes from stats file.\n"
86
+ );
87
+ }
88
+ }
89
+ return parsedModules;
90
+ }
91
+ function transformAssetsModulesData(parsedModulesData, moduleGraph) {
92
+ if (!moduleGraph)
93
+ return;
94
+ Object.entries(parsedModulesData).forEach(([moduleId, parsedData]) => {
95
+ const module2 = moduleGraph.getModuleByWebpackId(moduleId ?? "");
96
+ module2?.setSize({
97
+ parsedSize: parsedData?.size
98
+ });
99
+ module2?.setSource({ parsedSource: parsedData?.content || "" });
100
+ });
101
+ }
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ getAssetsModulesData,
105
+ transformAssetsModulesData
106
+ });
@@ -0,0 +1,5 @@
1
+ import { ChunkGraph } from '@rsdoctor/graph';
2
+ import { Plugin } from '@rsdoctor/types';
3
+ export declare function chunkTransform(assetMap: Map<string, {
4
+ content: string;
5
+ }>, bundleStats: Plugin.StatsCompilation): ChunkGraph;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var chunkTransform_exports = {};
20
+ __export(chunkTransform_exports, {
21
+ chunkTransform: () => chunkTransform
22
+ });
23
+ module.exports = __toCommonJS(chunkTransform_exports);
24
+ var import_graph = require("@rsdoctor/graph");
25
+ var import_lodash = require("lodash");
26
+ const FILTER_ASSETS_TYPE = "assets by status";
27
+ function chunkTransform(assetMap, bundleStats) {
28
+ const chunkGraph = new import_graph.ChunkGraph();
29
+ (0, import_lodash.forEach)(bundleStats.chunks, (_chunk) => {
30
+ const parsedSize = 0;
31
+ const chunk = new import_graph.Chunk(
32
+ String(_chunk.id),
33
+ _chunk.names?.join("") || _chunk.files?.join("| ") || "",
34
+ _chunk.size,
35
+ _chunk.initial,
36
+ _chunk.entry
37
+ );
38
+ chunk.setParsedSize(parsedSize);
39
+ chunkGraph.addChunk(chunk);
40
+ });
41
+ (0, import_lodash.forEach)(bundleStats.assets, (_asset) => {
42
+ if (_asset.type === FILTER_ASSETS_TYPE) {
43
+ return;
44
+ }
45
+ const chunks = _asset.chunks?.map((ck) => {
46
+ const chunk = chunkGraph.getChunkById(String(ck));
47
+ return chunk;
48
+ }).filter((chunk) => !!chunk) || [];
49
+ const { content = "" } = assetMap.get(_asset.name) || {};
50
+ const asset = new import_graph.Asset(_asset.name, _asset.size, chunks, content);
51
+ chunks.forEach((chunk) => chunk?.addAsset(asset));
52
+ chunkGraph.addAsset(asset);
53
+ });
54
+ (0, import_lodash.forEach)(bundleStats.entrypoints, (_entrypoint, key) => {
55
+ const entrypoint = new import_graph.EntryPoint(_entrypoint.name || key);
56
+ (0, import_lodash.forEach)(_entrypoint.chunks, (chunkId) => {
57
+ const ck = chunkGraph.getChunkById(`${chunkId}`);
58
+ if (ck)
59
+ entrypoint.addChunk(ck);
60
+ });
61
+ (0, import_lodash.forEach)(_entrypoint.assets, (_asset) => {
62
+ const asset = chunkGraph.getAssetByPath(_asset.name);
63
+ if (asset)
64
+ entrypoint.addAsset(asset);
65
+ });
66
+ chunkGraph.addEntryPoint(entrypoint);
67
+ });
68
+ return chunkGraph;
69
+ }
70
+ // Annotate the CommonJS export names for ESM import in node:
71
+ 0 && (module.exports = {
72
+ chunkTransform
73
+ });
@@ -0,0 +1,3 @@
1
+ export * from './assetsModules';
2
+ export * from './chunkTransform';
3
+ export * from './assetsContent';
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+ var chunks_exports = {};
17
+ module.exports = __toCommonJS(chunks_exports);
18
+ __reExport(chunks_exports, require("./assetsModules"), module.exports);
19
+ __reExport(chunks_exports, require("./chunkTransform"), module.exports);
20
+ __reExport(chunks_exports, require("./assetsContent"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("./assetsModules"),
24
+ ...require("./chunkTransform"),
25
+ ...require("./assetsContent")
26
+ });
@@ -0,0 +1,5 @@
1
+ export * as Chunks from './chunks';
2
+ export * as Types from '../../types';
3
+ export * as ModuleGraph from './module-graph';
4
+ export * as TransUtils from './trans-utils';
5
+ export * as Webpack from './webpack/compatible';