@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.
Files changed (167) hide show
  1. package/dist/26.js +26163 -0
  2. package/dist/630.js +1269 -0
  3. package/dist/630.js.LICENSE.txt +7 -0
  4. package/dist/build-utils/build/chunks/assetsModules.d.ts +7 -1
  5. package/dist/build-utils/build/loader/probeLoader.d.ts +7 -2
  6. package/dist/build-utils/build/utils/parseBundle.d.ts +1 -1
  7. package/dist/index.d.ts +5 -5
  8. package/dist/index.js +1725 -7
  9. package/dist/inner-plugins/constants.d.ts +1 -1
  10. package/dist/inner-plugins/plugins/base.d.ts +2 -2
  11. package/dist/logger.d.ts +2 -2
  12. package/dist/probe-loader.js +2 -0
  13. package/dist/proxy-loader.d.ts +1 -0
  14. package/dist/proxy-loader.js +48 -0
  15. package/dist/rslib-runtime.js +28 -0
  16. package/dist/rspack-plugin/constants.d.ts +1 -1
  17. package/dist/rules/rules/ecma-version-check/htmlParserStub.d.ts +3 -0
  18. package/dist/rules/rules/ecma-version-check/types.d.ts +13 -2
  19. package/dist/sdk/server/apis/base.d.ts +1 -1
  20. package/dist/sdk/server/socket/api.d.ts +1 -1
  21. package/dist/sdk/utils/date.d.ts +1 -0
  22. package/dist/types/loader.d.ts +1 -1
  23. package/package.json +20 -113
  24. package/dist/build-utils/build/chunks/assetsModules.js +0 -9
  25. package/dist/build-utils/build/chunks/index.js +0 -3
  26. package/dist/build-utils/build/chunks/rspack/transform.js +0 -44
  27. package/dist/build-utils/build/envinfo.js +0 -60
  28. package/dist/build-utils/build/file/cache.js +0 -24
  29. package/dist/build-utils/build/file/index.js +0 -5
  30. package/dist/build-utils/build/file/sharding.js +0 -38
  31. package/dist/build-utils/build/index.js +0 -12
  32. package/dist/build-utils/build/json.js +0 -67
  33. package/dist/build-utils/build/loader/index.js +0 -3
  34. package/dist/build-utils/build/loader/probeLoader.js +0 -44
  35. package/dist/build-utils/build/loader/probeLoaderPlugin.js +0 -32
  36. package/dist/build-utils/build/module-graph/index.js +0 -2
  37. package/dist/build-utils/build/module-graph/parser.js +0 -13
  38. package/dist/build-utils/build/module-graph/rspack/transform.js +0 -111
  39. package/dist/build-utils/build/module-graph/utils.js +0 -60
  40. package/dist/build-utils/build/process.js +0 -18
  41. package/dist/build-utils/build/server.js +0 -107
  42. package/dist/build-utils/build/utils/index.js +0 -4
  43. package/dist/build-utils/build/utils/loader.js +0 -267
  44. package/dist/build-utils/build/utils/parseBundle.js +0 -238
  45. package/dist/build-utils/build/utils/plugin.js +0 -21
  46. package/dist/build-utils/index.js +0 -13
  47. package/dist/collection.d.ts +0 -1
  48. package/dist/collection.js +0 -2
  49. package/dist/common/file.js +0 -8
  50. package/dist/common/global-config.js +0 -33
  51. package/dist/common/index.d.ts +0 -4
  52. package/dist/common/index.js +0 -6
  53. package/dist/common-browser.d.ts +0 -1
  54. package/dist/common-browser.js +0 -2
  55. package/dist/error/error.js +0 -143
  56. package/dist/error/index.js +0 -3
  57. package/dist/error/transform.js +0 -138
  58. package/dist/error/utils.js +0 -23
  59. package/dist/graph/index.d.ts +0 -1
  60. package/dist/graph/index.js +0 -2
  61. package/dist/inner-plugins/constants.js +0 -19
  62. package/dist/inner-plugins/index.js +0 -3
  63. package/dist/inner-plugins/loaders/proxy.js +0 -65
  64. package/dist/inner-plugins/plugins/base.js +0 -20
  65. package/dist/inner-plugins/plugins/bundle.js +0 -63
  66. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +0 -74
  67. package/dist/inner-plugins/plugins/errors.js +0 -65
  68. package/dist/inner-plugins/plugins/index.js +0 -11
  69. package/dist/inner-plugins/plugins/loader.js +0 -108
  70. package/dist/inner-plugins/plugins/plugins.js +0 -40
  71. package/dist/inner-plugins/plugins/progress.js +0 -35
  72. package/dist/inner-plugins/plugins/resolver.js +0 -57
  73. package/dist/inner-plugins/plugins/rspack.js +0 -99
  74. package/dist/inner-plugins/plugins/rules.js +0 -64
  75. package/dist/inner-plugins/plugins/sourcemapTool.js +0 -230
  76. package/dist/inner-plugins/plugins/summary.js +0 -92
  77. package/dist/inner-plugins/utils/circleDetect.js +0 -16
  78. package/dist/inner-plugins/utils/config.js +0 -141
  79. package/dist/inner-plugins/utils/index.js +0 -8
  80. package/dist/inner-plugins/utils/loader.js +0 -134
  81. package/dist/inner-plugins/utils/normalize-config.js +0 -77
  82. package/dist/inner-plugins/utils/openBrowser.js +0 -55
  83. package/dist/inner-plugins/utils/plugin-common.js +0 -94
  84. package/dist/inner-plugins/utils/plugin.js +0 -70
  85. package/dist/inner-plugins/utils/sdk.js +0 -19
  86. package/dist/logger.js +0 -51
  87. package/dist/rspack-plugin/constants.js +0 -23
  88. package/dist/rspack-plugin/index.js +0 -3
  89. package/dist/rspack-plugin/multiple.js +0 -39
  90. package/dist/rspack-plugin/plugin.js +0 -133
  91. package/dist/rule-utils/document/document.js +0 -46
  92. package/dist/rule-utils/document/index.js +0 -4
  93. package/dist/rule-utils/document/server.js +0 -13
  94. package/dist/rule-utils/document/types.js +0 -1
  95. package/dist/rule-utils/index.js +0 -3
  96. package/dist/rule-utils/parser/asserts.js +0 -105
  97. package/dist/rule-utils/parser/index.js +0 -5
  98. package/dist/rule-utils/parser/parser.js +0 -24
  99. package/dist/rule-utils/parser/types.js +0 -8
  100. package/dist/rule-utils/parser/utils.js +0 -106
  101. package/dist/rules/index.js +0 -4
  102. package/dist/rules/linter.js +0 -36
  103. package/dist/rules/rule.js +0 -101
  104. package/dist/rules/rules/cjs-require/index.js +0 -50
  105. package/dist/rules/rules/cjs-require/types.js +0 -1
  106. package/dist/rules/rules/cross-chunks-package/index.js +0 -41
  107. package/dist/rules/rules/cross-chunks-package/types.js +0 -1
  108. package/dist/rules/rules/cross-chunks-package/utils.js +0 -7
  109. package/dist/rules/rules/default-import-check/index.js +0 -83
  110. package/dist/rules/rules/default-import-check/types.js +0 -1
  111. package/dist/rules/rules/default-import-check/utils.js +0 -52
  112. package/dist/rules/rules/duplicate-package/index.js +0 -39
  113. package/dist/rules/rules/duplicate-package/types.js +0 -24
  114. package/dist/rules/rules/duplicate-package/utils.js +0 -38
  115. package/dist/rules/rules/ecma-version-check/index.js +0 -53
  116. package/dist/rules/rules/ecma-version-check/types.js +0 -1
  117. package/dist/rules/rules/ecma-version-check/utils.js +0 -6
  118. package/dist/rules/rules/esm-resolved-to-cjs/index.js +0 -193
  119. package/dist/rules/rules/esm-resolved-to-cjs/types.js +0 -1
  120. package/dist/rules/rules/index.js +0 -22
  121. package/dist/rules/rules/loader-performance-optimization/index.js +0 -86
  122. package/dist/rules/rules/loader-performance-optimization/types.js +0 -1
  123. package/dist/rules/rules/loader-performance-optimization/utils.js +0 -10
  124. package/dist/rules/rules/module-mixed-chunks/index.js +0 -52
  125. package/dist/rules/rules/module-mixed-chunks/types.js +0 -1
  126. package/dist/rules/rules/side-effects-only-imports/index.js +0 -81
  127. package/dist/rules/rules/side-effects-only-imports/types.js +0 -1
  128. package/dist/rules/utils.js +0 -10
  129. package/dist/sdk/index.js +0 -3
  130. package/dist/sdk/multiple/controller.js +0 -42
  131. package/dist/sdk/multiple/index.js +0 -3
  132. package/dist/sdk/multiple/primary.js +0 -64
  133. package/dist/sdk/multiple/server.js +0 -14
  134. package/dist/sdk/sdk/core.js +0 -163
  135. package/dist/sdk/sdk/index.js +0 -435
  136. package/dist/sdk/sdk/types.js +0 -1
  137. package/dist/sdk/server/apis/alerts.js +0 -30
  138. package/dist/sdk/server/apis/base.js +0 -22
  139. package/dist/sdk/server/apis/bundle-diff.js +0 -51
  140. package/dist/sdk/server/apis/data.js +0 -44
  141. package/dist/sdk/server/apis/fs.js +0 -28
  142. package/dist/sdk/server/apis/graph.js +0 -116
  143. package/dist/sdk/server/apis/index.js +0 -11
  144. package/dist/sdk/server/apis/loader.js +0 -120
  145. package/dist/sdk/server/apis/plugin.js +0 -39
  146. package/dist/sdk/server/apis/project.js +0 -59
  147. package/dist/sdk/server/apis/renderer.js +0 -33
  148. package/dist/sdk/server/apis/resolver.js +0 -38
  149. package/dist/sdk/server/client.js +0 -8
  150. package/dist/sdk/server/fakeServer.js +0 -12
  151. package/dist/sdk/server/index.js +0 -292
  152. package/dist/sdk/server/json-body.js +0 -150
  153. package/dist/sdk/server/router.js +0 -83
  154. package/dist/sdk/server/security.js +0 -47
  155. package/dist/sdk/server/socket/api.js +0 -22
  156. package/dist/sdk/server/socket/index.js +0 -166
  157. package/dist/sdk/server/utils.js +0 -19
  158. package/dist/sdk/utils/base.js +0 -22
  159. package/dist/sdk/utils/constant.js +0 -4
  160. package/dist/sdk/utils/index.js +0 -4
  161. package/dist/sdk/utils/openBrowser.js +0 -53
  162. package/dist/sdk/utils/upload.js +0 -6
  163. package/dist/sdk.js +0 -2
  164. package/dist/types/index.js +0 -4
  165. package/dist/types/loader.js +0 -1
  166. package/dist/types/plugin.js +0 -1
  167. package/dist/types/rules.js +0 -1
@@ -1,19 +0,0 @@
1
- import "node:module";
2
- const pluginTapName = 'RsdoctorRspackPlugin';
3
- const pluginTapPostOptions = {
4
- name: pluginTapName,
5
- stage: 999
6
- };
7
- const pluginTapPreOptions = {
8
- name: pluginTapName,
9
- stage: -999
10
- };
11
- const internalPluginTapPreOptions = (namespace)=>({
12
- name: `${pluginTapName}:${namespace}`,
13
- stage: -998
14
- });
15
- const internalPluginTapPostOptions = (namespace)=>({
16
- name: `${pluginTapName}:${namespace}`,
17
- stage: 1000
18
- });
19
- export { internalPluginTapPostOptions, internalPluginTapPreOptions, pluginTapName, pluginTapPostOptions, pluginTapPreOptions };
@@ -1,3 +0,0 @@
1
- import "node:module";
2
- export * from "./plugins/index.js";
3
- export * from "./utils/index.js";
@@ -1,65 +0,0 @@
1
- import "node:module";
2
- import { Utils } from "../../build-utils/build/index.js";
3
- import { getOriginLoaderModule, reportLoader, shouldSkipLoader } from "../utils/index.js";
4
- const loaderModule = function(...args) {
5
- if (shouldSkipLoader(this)) return void this.callback(null, ...args);
6
- this.cacheable(false);
7
- const mod = getOriginLoaderModule(this);
8
- if (mod.default) {
9
- if (false === mod.raw && Buffer.isBuffer(args[0])) args[0] = args[0].toString();
10
- let start = 0;
11
- let startHRTime = [
12
- 0,
13
- 0
14
- ];
15
- const trap = Utils.createLoaderContextTrap.call(this, (err, res, sourceMap)=>{
16
- reportLoader(this, start, startHRTime, false, false, args[0].toString(), err, res, sourceMap);
17
- });
18
- start = Date.now();
19
- startHRTime = process.hrtime();
20
- try {
21
- const result = mod.default.apply(trap, args);
22
- if (result) {
23
- if (!(result instanceof Promise)) reportLoader(this, start, startHRTime, false, true, args[0].toString(), null, result);
24
- }
25
- return result || '';
26
- } catch (error) {
27
- reportLoader(this, start, startHRTime, false, true, args[0].toString(), error, null);
28
- throw error;
29
- }
30
- }
31
- this.callback(null, ...args);
32
- };
33
- const pitch = function() {
34
- if (shouldSkipLoader(this)) return;
35
- this.cacheable(false);
36
- const mod = getOriginLoaderModule(this);
37
- if (mod.pitch && 'function' == typeof mod.pitch) {
38
- let start = 0;
39
- let startHRTime = [
40
- 0,
41
- 0
42
- ];
43
- const trap = Utils.createLoaderContextTrap.call(this, (err, res)=>{
44
- reportLoader(this, start, startHRTime, true, false, err ? 'Loader Pitch Async Error' : '', err, res);
45
- });
46
- start = Date.now();
47
- startHRTime = process.hrtime();
48
- try {
49
- const res = mod.pitch.apply(trap, arguments);
50
- if (res) {
51
- if (!(res instanceof Promise)) reportLoader(this, start, startHRTime, true, true, '', null, res);
52
- }
53
- return res;
54
- } catch (error) {
55
- reportLoader(this, start, startHRTime, true, true, 'Loader Pitch Sync Error', error, null);
56
- throw error;
57
- }
58
- }
59
- };
60
- loaderModule.raw = true;
61
- loaderModule.pitch = pitch;
62
- const raw = true;
63
- const proxy = loaderModule;
64
- export default proxy;
65
- export { pitch, raw };
@@ -1,20 +0,0 @@
1
- import "node:module";
2
- import { internalPluginTapPostOptions, internalPluginTapPreOptions } from "../constants.js";
3
- class InternalBasePlugin {
4
- get options() {
5
- return this.scheduler.options;
6
- }
7
- get sdk() {
8
- return this.scheduler.sdk;
9
- }
10
- get tapPostOptions() {
11
- return internalPluginTapPostOptions(this.name);
12
- }
13
- get tapPreOptions() {
14
- return internalPluginTapPreOptions(this.name);
15
- }
16
- constructor(scheduler){
17
- this.scheduler = scheduler;
18
- }
19
- }
20
- export { InternalBasePlugin };
@@ -1,63 +0,0 @@
1
- import "node:module";
2
- import { Manifest } from "@rsdoctor/shared/types";
3
- import { InternalBasePlugin } from "./base.js";
4
- import { Chunks } from "../../graph/index.js";
5
- import { logger, time, timeEnd } from "../../logger.js";
6
- class InternalBundlePlugin extends InternalBasePlugin {
7
- apply(compiler) {
8
- time('InternalBundlePlugin.apply');
9
- try {
10
- this.scheduler.ensureModulesChunksGraphApplied(compiler);
11
- this.changeDevtoolModuleFilename(compiler);
12
- compiler.hooks.compilation.tap(this.tapPostOptions, this.thisCompilation);
13
- compiler.hooks.done.tapPromise(this.tapPreOptions, this.done.bind(this));
14
- } finally{
15
- timeEnd('InternalBundlePlugin.apply');
16
- }
17
- }
18
- changeDevtoolModuleFilename(compiler) {
19
- const devtool = compiler.options.devtool;
20
- if (devtool) {
21
- if (!compiler.options.output) compiler.options.output = {};
22
- compiler.options.output.devtoolModuleFilenameTemplate = '[absolute-resource-path]';
23
- logger.warn("output.devtoolModuleFilenameTemplate has been changed to [absolute-resource-path], this is for bundle analysis.");
24
- if ('string' == typeof devtool && devtool.includes('source-map')) compiler.options.output.devtoolFallbackModuleFilenameTemplate = ()=>'[absolute-resource-path]';
25
- }
26
- }
27
- ensureAssetContent(name) {
28
- const asset = this.map.get(name);
29
- if (asset) return asset;
30
- const v = {
31
- content: ''
32
- };
33
- this.map.set(name, v);
34
- return v;
35
- }
36
- constructor(...args){
37
- super(...args), this.name = 'bundle', this.map = new Map(), this.thisCompilation = (compilation)=>{
38
- time('InternalBundlePlugin.thisCompilation');
39
- try {
40
- if (compilation.hooks.processAssets) compilation.hooks.afterProcessAssets.tap(this.tapPostOptions, (assets)=>{
41
- Object.keys(assets).forEach((file)=>{
42
- const v = this.ensureAssetContent(file);
43
- v.content = assets[file].source().toString();
44
- });
45
- });
46
- } finally{
47
- timeEnd('InternalBundlePlugin.thisCompilation');
48
- }
49
- }, this.done = async ()=>{
50
- time('InternalBundlePlugin.done');
51
- try {
52
- if (this.scheduler.chunkGraph) Chunks.assetsContents(this.map, this.scheduler.chunkGraph, this.scheduler.options?.supports);
53
- this.sdk.addClientRoutes([
54
- Manifest.RsdoctorManifestClientRoutes.ModuleGraph,
55
- Manifest.RsdoctorManifestClientRoutes.BundleSize
56
- ]);
57
- } finally{
58
- timeEnd('InternalBundlePlugin.done');
59
- }
60
- };
61
- }
62
- }
63
- export { InternalBundlePlugin };
@@ -1,74 +0,0 @@
1
- import "node:module";
2
- import { chalk, logger } from "../../logger.js";
3
- import { Chunks } from "../../build-utils/build/index.js";
4
- import { internalPluginTapPreOptions, pluginTapPostOptions } from "../constants.js";
5
- import { applyRspackNativePlugin, getRspackNativePlugin } from "./rspack.js";
6
- import { handleAfterEmitAssets } from "./sourcemapTool.js";
7
- let hasConsole = false;
8
- const ensureModulesChunksGraphFn = (compiler, _this)=>{
9
- if (_this._modulesGraphApplied) return;
10
- const RsdoctorRspackPlugin = getRspackNativePlugin(compiler);
11
- _this._modulesGraphApplied = true;
12
- const nativeGraphState = applyRspackNativePlugin(compiler, _this, RsdoctorRspackPlugin);
13
- if (!_this._realSourcePathCache) _this._realSourcePathCache = new Map();
14
- compiler.hooks.done.tapPromise(internalPluginTapPreOptions('moduleGraph'), async ()=>{
15
- await doneHandler(_this, compiler, nativeGraphState);
16
- });
17
- compiler.hooks.compilation.tap({
18
- ...pluginTapPostOptions,
19
- name: 'RsdoctorSourceMapCollector'
20
- }, (compilation)=>{
21
- if (compilation.hooks.processAssets) compilation.hooks.processAssets.tapPromise({
22
- name: 'RsdoctorSourceMapCollector',
23
- stage: 2400
24
- }, async ()=>{
25
- if (!ensureDevtools(compiler)) return;
26
- const { namespace, sourceMapFilenameRegex } = calculateNamespaceAndRegex(compiler);
27
- await handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex, namespace);
28
- });
29
- });
30
- };
31
- async function doneHandler(_this, compiler, nativeGraphState) {
32
- if (!nativeGraphState.chunkGraph || !_this.chunkGraph) throw new Error('[RsdoctorRspackPlugin] The Rspack native plugin did not provide chunk graph data.');
33
- if (!nativeGraphState.moduleGraph) throw new Error('[RsdoctorRspackPlugin] The Rspack native plugin did not provide module graph data.');
34
- const shouldParseBundle = false !== _this.options.supports.parseBundle;
35
- await getModulesInfos(compiler, _this.modulesGraph, _this.chunkGraph, shouldParseBundle, _this.sourceMapSets, _this.assetsWithoutSourceMap);
36
- logger.debug('reportModuleGraph start');
37
- await _this.sdk.reportModuleGraph(_this.modulesGraph);
38
- logger.debug('reportModuleGraph done');
39
- logger.debug('reportChunkGraph start');
40
- await _this.sdk.reportChunkGraph(_this.chunkGraph);
41
- logger.debug('reportChunkGraph done');
42
- if (_this.options.supports.generateTileGraph) logger.warn(chalk.yellow('The option generateTileGraph is deprecated. Treemap (i.e. Tile Graph) is now supported by default.'));
43
- logger.debug('doneHandler done');
44
- }
45
- const ensureDevtools = (compiler)=>{
46
- const devtool = compiler.options.devtool;
47
- if ('string' == typeof devtool && /eval/i.test(devtool)) {
48
- if (!hasConsole) logger.warn('SourceMap with eval is not supported. Please use other sourcemap options.');
49
- hasConsole = true;
50
- return false;
51
- }
52
- return true;
53
- };
54
- async function getModulesInfos(compiler, moduleGraph, chunkGraph, parseBundle, sourceMapSets, assetsWithoutSourceMap) {
55
- if (!moduleGraph) return;
56
- try {
57
- await Chunks.getAssetsModulesData(moduleGraph, chunkGraph, compiler.outputPath, sourceMapSets, parseBundle, assetsWithoutSourceMap);
58
- } catch {}
59
- }
60
- function escapeRegExp(str) {
61
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
62
- }
63
- function calculateNamespaceAndRegex(compiler) {
64
- let namespace = compiler.options.output.devtoolNamespace || compiler.options.output.library?.name || '[^/]+/';
65
- if (Array.isArray(namespace)) namespace = namespace[0];
66
- else if ('object' == typeof namespace && 'name' in namespace) namespace = namespace.name;
67
- const safeNamespace = escapeRegExp(namespace);
68
- const sourceMapFilenameRegex = new RegExp(`(?:webpack://)?(?:${safeNamespace})?([^?]*)`);
69
- return {
70
- namespace: namespace,
71
- sourceMapFilenameRegex
72
- };
73
- }
74
- export { calculateNamespaceAndRegex, ensureDevtools, ensureModulesChunksGraphFn };
@@ -1,65 +0,0 @@
1
- import "node:module";
2
- import { Rule } from "@rsdoctor/shared/types";
3
- import { InternalBasePlugin } from "./base.js";
4
- import { DevToolError } from "../../error/index.js";
5
- import { time, timeEnd } from "../../logger.js";
6
- class InternalErrorReporterPlugin extends InternalBasePlugin {
7
- apply(compiler) {
8
- time('InternalErrorReporterPlugin.apply');
9
- try {
10
- compiler.hooks.done.tapPromise(this.tapPreOptions, this.done);
11
- } finally{
12
- timeEnd('InternalErrorReporterPlugin.apply');
13
- }
14
- }
15
- handleBundlerError(err, category, level) {
16
- return DevToolError.from(err, {
17
- category,
18
- code: Rule.RuleMessageCodeEnumerated.Overlay,
19
- controller: {
20
- noStack: false
21
- },
22
- detail: {
23
- stack: 'stack' in err ? err.stack : err.message
24
- },
25
- level
26
- });
27
- }
28
- async reportWarnings(warnings) {
29
- time('InternalErrorReporterPlugin.reportWarnings');
30
- try {
31
- const arr = warnings.map((warning)=>this.handleBundlerError(warning, Rule.RuleMessageCategory.Compile, 'Warn'));
32
- this.sdk.reportError(arr);
33
- } finally{
34
- timeEnd('InternalErrorReporterPlugin.reportWarnings');
35
- }
36
- }
37
- async reportErrors(errors) {
38
- time('InternalErrorReporterPlugin.reportErrors');
39
- try {
40
- const arr = errors.map((err)=>this.handleBundlerError(err, Rule.RuleMessageCategory.Bundle, 'Error'));
41
- this.sdk.reportError(arr);
42
- } finally{
43
- timeEnd('InternalErrorReporterPlugin.reportErrors');
44
- }
45
- }
46
- constructor(...args){
47
- super(...args), this.name = 'error-reporter', this.done = async (stats)=>{
48
- time('InternalErrorReporterPlugin.done');
49
- try {
50
- const tasks = [];
51
- const statsData = stats.toJson({
52
- all: false,
53
- errors: true,
54
- warnings: true
55
- });
56
- if (stats.hasErrors()) tasks.push(this.reportErrors(statsData.errors || []));
57
- if (stats.hasWarnings()) tasks.push(this.reportWarnings(statsData.warnings || []));
58
- await Promise.all(tasks);
59
- } finally{
60
- timeEnd('InternalErrorReporterPlugin.done');
61
- }
62
- };
63
- }
64
- }
65
- export { InternalErrorReporterPlugin };
@@ -1,11 +0,0 @@
1
- import "node:module";
2
- export * from "./loader.js";
3
- export * from "./plugins.js";
4
- export * from "./errors.js";
5
- export * from "./progress.js";
6
- export * from "./summary.js";
7
- export * from "./base.js";
8
- export * from "./bundle.js";
9
- export * from "./ensureModulesChunkGraph.js";
10
- export * from "./rules.js";
11
- export * from "./resolver.js";
@@ -1,108 +0,0 @@
1
- import "node:module";
2
- import { Manifest } from "@rsdoctor/shared/types";
3
- import { Loader } from "../../common/index.js";
4
- import { isEqual, omit } from "../../collection.js";
5
- import { interceptLoader } from "../utils/index.js";
6
- import { InternalBasePlugin } from "./base.js";
7
- import { time, timeEnd } from "../../logger.js";
8
- import { fileURLToPath } from "url";
9
- import { safeCloneDeep } from "../utils/plugin-common.js";
10
- class InternalLoaderPlugin extends InternalBasePlugin {
11
- apply(compiler) {
12
- time('InternalLoaderPlugin.apply');
13
- try {
14
- compiler.hooks.afterPlugins.tap(this.tapPostOptions, this.afterPlugins.bind(this, compiler));
15
- compiler.hooks.compilation.tap(this.tapPreOptions, (compilation)=>this.compilation(compiler, compilation));
16
- } finally{
17
- timeEnd('InternalLoaderPlugin.apply');
18
- }
19
- }
20
- compilation(compiler, compilation) {
21
- time('InternalLoaderPlugin.compilation');
22
- try {
23
- if (compiler.isChild()) return;
24
- const wrapper = (callback)=>(loaderContext, module)=>{
25
- const proxyLoaders = module?.loaders || loaderContext?.loaders || [];
26
- const originLoaders = proxyLoaders.map((loader)=>{
27
- const rawOptions = loader.options;
28
- const opts = 'object' == typeof rawOptions && null !== rawOptions ? rawOptions : {};
29
- if (opts[Loader.LoaderInternalPropertyName]) return {
30
- ...loader,
31
- loader: opts[Loader.LoaderInternalPropertyName].loader,
32
- options: omit(opts, Loader.LoaderInternalPropertyName)
33
- };
34
- return loader;
35
- });
36
- const newLoaders = safeCloneDeep(originLoaders);
37
- if ('object' == typeof compiler.options.cache && 'version' in compiler.options.cache && 'string' == typeof compiler.options.cache.version && compiler.options.cache.version.indexOf('next/dist/build') > -1) callback(loaderContext, module || {});
38
- else {
39
- const proxyModule = new Proxy(module || {}, {
40
- get (target, p, receiver) {
41
- if ('loaders' === p) return newLoaders;
42
- return Reflect.get(target, p, receiver);
43
- },
44
- set (target, p, newValue, receiver) {
45
- const _newValue = safeCloneDeep(newValue);
46
- if ('loaders' === p) {
47
- if (Array.isArray(_newValue)) {
48
- newLoaders.length = 0;
49
- _newValue.forEach((e)=>{
50
- newLoaders.push(e);
51
- });
52
- }
53
- }
54
- return Reflect.set(target, p, _newValue, receiver);
55
- },
56
- deleteProperty (target, p) {
57
- return Reflect.deleteProperty(target, p);
58
- }
59
- });
60
- callback(loaderContext, proxyModule);
61
- }
62
- if (!isEqual(originLoaders, newLoaders)) {
63
- const rules = this.getInterceptRules(compiler, newLoaders.map((e)=>({
64
- loader: e.loader,
65
- options: e.options ?? void 0
66
- })));
67
- module.loaders = rules.map((e, i)=>({
68
- ...newLoaders[i],
69
- loader: e.loader,
70
- options: e.options
71
- }));
72
- }
73
- };
74
- const interceptor = {
75
- register (tap) {
76
- const originFn = tap.fn;
77
- if ('function' == typeof originFn) tap.fn = wrapper(originFn);
78
- return tap;
79
- }
80
- };
81
- compiler.webpack.NormalModule.getCompilationHooks(compilation).loader.intercept(interceptor);
82
- } finally{
83
- timeEnd('InternalLoaderPlugin.compilation');
84
- }
85
- }
86
- getInterceptRules(compiler, rules) {
87
- return interceptLoader(rules, this.internalLoaderPath, {
88
- cwd: compiler.context || process.cwd(),
89
- host: this.sdk.server.origin,
90
- skipLoaders: this.options.loaderInterceptorOptions.skipLoaders
91
- }, compiler.resolverFactory.get('loader', compiler.options.resolveLoader), this.sdk.root);
92
- }
93
- constructor(...args){
94
- super(...args), this.name = 'loader', this.internalLoaderPath = fileURLToPath(new URL('../loaders/proxy.js', import.meta.url)), this.afterPlugins = (compiler)=>{
95
- time('InternalLoaderPlugin.afterPlugins');
96
- try {
97
- if (compiler.isChild()) return;
98
- compiler.options.module.rules = this.getInterceptRules(compiler, compiler.options.module.rules);
99
- this.sdk.addClientRoutes([
100
- Manifest.RsdoctorManifestClientRoutes.Loaders
101
- ]);
102
- } finally{
103
- timeEnd('InternalLoaderPlugin.afterPlugins');
104
- }
105
- };
106
- }
107
- }
108
- export { InternalLoaderPlugin };
@@ -1,40 +0,0 @@
1
- import "node:module";
2
- import { Manifest } from "@rsdoctor/shared/types";
3
- import { Utils } from "../../build-utils/build/index.js";
4
- import { interceptPluginHook } from "../utils/index.js";
5
- import { InternalBasePlugin } from "./base.js";
6
- import { time, timeEnd } from "../../logger.js";
7
- class InternalPluginsPlugin extends InternalBasePlugin {
8
- apply(compiler) {
9
- time('InternalPluginsPlugin.apply');
10
- try {
11
- compiler.hooks.afterPlugins.tap(this.tapPostOptions, this.afterPlugins.bind(this, compiler));
12
- compiler.hooks.compilation.tap(this.tapPostOptions, this.compilation);
13
- } finally{
14
- timeEnd('InternalPluginsPlugin.apply');
15
- }
16
- }
17
- constructor(...args){
18
- super(...args), this.name = 'plugins', this.afterPlugins = (compiler)=>{
19
- time('InternalPluginsPlugin.afterPlugins');
20
- try {
21
- if (compiler.isChild()) return;
22
- Utils.interceptCompilerHooks(compiler, (name, hook)=>interceptPluginHook(this.sdk, name, hook));
23
- this.sdk.addClientRoutes([
24
- Manifest.RsdoctorManifestClientRoutes.Plugins
25
- ]);
26
- } finally{
27
- timeEnd('InternalPluginsPlugin.afterPlugins');
28
- }
29
- }, this.compilation = (compilation)=>{
30
- time('InternalPluginsPlugin.compilation');
31
- try {
32
- if (compilation.compiler.isChild()) return;
33
- Utils.interceptCompilationHooks(compilation, (name, hook)=>interceptPluginHook(this.sdk, name, hook));
34
- } finally{
35
- timeEnd('InternalPluginsPlugin.compilation');
36
- }
37
- };
38
- }
39
- }
40
- export { InternalPluginsPlugin };
@@ -1,35 +0,0 @@
1
- import "node:module";
2
- import { SDK } from "@rsdoctor/shared/types";
3
- import { InternalBasePlugin } from "./base.js";
4
- import { logger } from "../../logger.js";
5
- class InternalProgressPlugin extends InternalBasePlugin {
6
- apply(compiler) {
7
- const { sdk, currentProgress } = this;
8
- if (compiler.webpack && compiler.webpack.ProgressPlugin) {
9
- const progress = new compiler.webpack.ProgressPlugin((percentage, msg)=>{
10
- currentProgress.percentage = percentage;
11
- currentProgress.message = msg || '';
12
- const api = SDK.ServerAPI.APIExtends.GetCompileProgress;
13
- try {
14
- sdk.server.sendAPIDataToClient(api, {
15
- req: {
16
- api,
17
- body: void 0
18
- },
19
- res: currentProgress
20
- });
21
- } catch (e) {
22
- logger.debug(e);
23
- }
24
- });
25
- progress.apply(compiler);
26
- }
27
- }
28
- constructor(...args){
29
- super(...args), this.name = 'progress', this.currentProgress = {
30
- percentage: 100,
31
- message: ''
32
- };
33
- }
34
- }
35
- export { InternalProgressPlugin };
@@ -1,57 +0,0 @@
1
- import "node:module";
2
- import { Manifest } from "@rsdoctor/shared/types";
3
- import { Time } from "../../common/index.js";
4
- import { InternalBasePlugin } from "./base.js";
5
- class InternalResolverPlugin extends InternalBasePlugin {
6
- apply(compiler) {
7
- this.scheduler.ensureModulesChunksGraphApplied(compiler);
8
- compiler.hooks.normalModuleFactory.tap(this.tapPostOptions, this.handleNormalModuleFactory);
9
- this.sdk.addClientRoutes([
10
- Manifest.RsdoctorManifestClientRoutes.ModuleResolve
11
- ]);
12
- }
13
- constructor(...args){
14
- super(...args), this.name = 'resolver', this.resolveDataMap = new Map(), this.handleNormalModuleFactory = (normalModuleFactory)=>{
15
- normalModuleFactory.hooks.beforeResolve.tap(this.tapPostOptions, (resolveData)=>{
16
- if (!resolveData) return;
17
- const issuer = resolveData.contextInfo?.issuer || resolveData.context || '';
18
- const request = resolveData.request;
19
- if (issuer && request) {
20
- const key = `${issuer}::${request}`;
21
- this.resolveDataMap.set(key, {
22
- startAt: Date.now(),
23
- startHRTime: process.hrtime(),
24
- request
25
- });
26
- }
27
- });
28
- normalModuleFactory.hooks.afterResolve.tap(this.tapPostOptions, (resolveData)=>{
29
- if (!resolveData) return;
30
- const issuer = resolveData.contextInfo?.issuer || resolveData.context || '';
31
- const request = resolveData.request;
32
- const result = resolveData.createData?.resource || resolveData.resourceResolveData?.path;
33
- if (issuer && request) {
34
- const key = `${issuer}::${request}`;
35
- const startData = this.resolveDataMap.get(key);
36
- if (startData) {
37
- const data = {
38
- isEntry: Boolean(issuer),
39
- issuerPath: issuer,
40
- request: startData.request,
41
- startAt: startData.startAt,
42
- endAt: Time.getCurrentTimestamp(startData.startAt, startData.startHRTime),
43
- result: result || '',
44
- pid: process.pid,
45
- ppid: process.ppid
46
- };
47
- this.sdk.reportResolver([
48
- data
49
- ]);
50
- this.resolveDataMap.delete(key);
51
- }
52
- }
53
- });
54
- };
55
- }
56
- }
57
- export { InternalResolverPlugin };
@@ -1,99 +0,0 @@
1
- import "node:module";
2
- import { ChunkGraph } from "../../graph/index.js";
3
- import { Chunks, ModuleGraph } from "../../build-utils/build/index.js";
4
- import { internalPluginTapPreOptions } from "../constants.js";
5
- import { logger } from "../../logger.js";
6
- function getRspackNativePlugin(compiler) {
7
- const RsdoctorRspackPlugin = compiler.webpack.experiments?.RsdoctorPlugin;
8
- if (!RsdoctorRspackPlugin) throw new Error('[RsdoctorRspackPlugin] The current Rspack version does not provide experiments.RsdoctorPlugin. Please upgrade Rspack.');
9
- return RsdoctorRspackPlugin;
10
- }
11
- function applyRspackNativePlugin(compiler, plugin, RsdoctorRspackPlugin) {
12
- const state = {
13
- chunkGraph: false,
14
- moduleGraph: false
15
- };
16
- logger.debug('[RspackNativePlugin] Apply hooks');
17
- compiler.hooks.compilation.tap('RsdoctorRspackPlugin', (compilation)=>{
18
- state.chunkGraph = false;
19
- state.moduleGraph = false;
20
- const hooks = RsdoctorRspackPlugin.getCompilationHooks(compilation);
21
- const cached = {};
22
- const dependOn = {
23
- chunkGraphData: [],
24
- moduleGraphData: [
25
- 'chunkGraphData'
26
- ],
27
- assetPatchData: [
28
- 'chunkGraphData'
29
- ],
30
- moduleIdsPatchData: [
31
- 'moduleGraphData'
32
- ],
33
- moduleSourcesPatchData: [
34
- 'moduleGraphData'
35
- ]
36
- };
37
- const consumer = {
38
- chunkGraphData: (data)=>{
39
- plugin.chunkGraph = new ChunkGraph();
40
- Chunks.patchNativeChunkGraph(plugin.chunkGraph, data);
41
- state.chunkGraph = true;
42
- },
43
- moduleGraphData: (data)=>{
44
- ModuleGraph.patchNativeModuleGraph(plugin.modulesGraph, plugin.chunkGraph, data);
45
- state.moduleGraph = true;
46
- },
47
- moduleIdsPatchData: (data)=>{
48
- ModuleGraph.patchNativeModuleIds(plugin.modulesGraph, data);
49
- },
50
- moduleSourcesPatchData: (data)=>{
51
- ModuleGraph.patchNativeModuleSources(plugin.modulesGraph, data);
52
- if (plugin.options.features.treeShaking) ModuleGraph.extractSideEffectCodes(plugin.modulesGraph);
53
- },
54
- assetPatchData: (data)=>{
55
- Chunks.patchNativeAssets(plugin.chunkGraph, data);
56
- }
57
- };
58
- const tryConsumeData = (key, data)=>{
59
- if (true === cached[key]) return;
60
- cached[key] = data;
61
- while(true){
62
- let hasConsumed = false;
63
- for (const [_task, deps] of Object.entries(dependOn)){
64
- const task = _task;
65
- if (true === cached[task] || void 0 === cached[task]) continue;
66
- const prepared = deps.every((dep)=>true === cached[dep]);
67
- if (prepared) {
68
- consumer[task](cached[task]);
69
- cached[task] = true;
70
- hasConsumed = true;
71
- }
72
- }
73
- if (!hasConsumed) break;
74
- }
75
- };
76
- hooks.chunkGraph.tap(internalPluginTapPreOptions('nativeChunkGraph'), (rawChunkGraph)=>{
77
- logger.debug('[RspackNativePlugin] Called chunkGraph hook');
78
- tryConsumeData('chunkGraphData', rawChunkGraph);
79
- });
80
- hooks.moduleGraph.tap(internalPluginTapPreOptions('nativeModuleGraph'), (rawModuleGraph)=>{
81
- logger.debug('[RspackNativePlugin] Called moduleGraph hook');
82
- tryConsumeData('moduleGraphData', rawModuleGraph);
83
- });
84
- hooks.moduleIds.tap(internalPluginTapPreOptions('nativeSourcePatch'), (rawModuleIdsPatch)=>{
85
- logger.debug('[RspackNativePlugin] Called moduleIds hook');
86
- tryConsumeData('moduleIdsPatchData', rawModuleIdsPatch);
87
- });
88
- hooks.moduleSources.tap(internalPluginTapPreOptions('nativeModuleSourcesPatch'), (rawModuleSourcesPatch)=>{
89
- logger.debug('[RspackNativePlugin] Called moduleSources hook');
90
- tryConsumeData('moduleSourcesPatchData', rawModuleSourcesPatch);
91
- });
92
- hooks.assets.tap(internalPluginTapPreOptions('nativeAssetPatch'), (rawAssetPatch)=>{
93
- logger.debug('[RspackNativePlugin] Called assets hook');
94
- tryConsumeData('assetPatchData', rawAssetPatch);
95
- });
96
- });
97
- return state;
98
- }
99
- export { applyRspackNativePlugin, getRspackNativePlugin };