@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,32 @@
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 plugins_exports = {};
17
+ module.exports = __toCommonJS(plugins_exports);
18
+ __reExport(plugins_exports, require("./loader"), module.exports);
19
+ __reExport(plugins_exports, require("./plugins"), module.exports);
20
+ __reExport(plugins_exports, require("./errors"), module.exports);
21
+ __reExport(plugins_exports, require("./progress"), module.exports);
22
+ __reExport(plugins_exports, require("./summary"), module.exports);
23
+ __reExport(plugins_exports, require("./base"), module.exports);
24
+ // Annotate the CommonJS export names for ESM import in node:
25
+ 0 && (module.exports = {
26
+ ...require("./loader"),
27
+ ...require("./plugins"),
28
+ ...require("./errors"),
29
+ ...require("./progress"),
30
+ ...require("./summary"),
31
+ ...require("./base")
32
+ });
@@ -0,0 +1,11 @@
1
+ import { Plugin } from '@rsdoctor/types';
2
+ import { RuleSetRule } from 'webpack';
3
+ import { InternalBasePlugin } from './base';
4
+ export declare class InternalLoaderPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
5
+ readonly name = "loader";
6
+ readonly internalLoaderPath: string;
7
+ apply(compiler: T): void;
8
+ afterPlugins: (compiler: Plugin.BaseCompiler) => void;
9
+ compilation(compiler: Plugin.BaseCompiler, compilation: Plugin.BaseCompilation): void;
10
+ getInterceptRules(compiler: Plugin.BaseCompiler, rules: RuleSetRule[]): RuleSetRule[];
11
+ }
@@ -0,0 +1,157 @@
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 loader_exports = {};
30
+ __export(loader_exports, {
31
+ InternalLoaderPlugin: () => InternalLoaderPlugin
32
+ });
33
+ module.exports = __toCommonJS(loader_exports);
34
+ var import_types = require("@rsdoctor/types");
35
+ var import_common = require("@rsdoctor/utils/common");
36
+ var import_lodash = require("lodash");
37
+ var import_utils = require("../utils");
38
+ var import_base = require("./base");
39
+ class InternalLoaderPlugin extends import_base.InternalBasePlugin {
40
+ constructor() {
41
+ super(...arguments);
42
+ this.name = "loader";
43
+ this.internalLoaderPath = require.resolve("../loaders/proxy");
44
+ this.afterPlugins = (compiler) => {
45
+ if (compiler.isChild())
46
+ return;
47
+ compiler.options.module.rules = this.getInterceptRules(
48
+ compiler,
49
+ compiler.options.module.rules
50
+ );
51
+ this.sdk.addClientRoutes([
52
+ import_types.Manifest.DoctorManifestClientRoutes.WebpackLoaders
53
+ ]);
54
+ };
55
+ }
56
+ apply(compiler) {
57
+ compiler.hooks.afterPlugins.tap(this.tapPostOptions, this.afterPlugins);
58
+ compiler.hooks.compilation.tap(
59
+ this.tapPreOptions,
60
+ this.compilation.bind(this, compiler)
61
+ );
62
+ }
63
+ compilation(compiler, compilation) {
64
+ if (compiler.isChild())
65
+ return;
66
+ const wrapper = (callback) => (loaderContext, module2) => {
67
+ const proxyLoaders = module2.loaders || [];
68
+ const originLoaders = proxyLoaders.map((loader) => {
69
+ const opts = loader.options || {};
70
+ if (opts[import_common.Loader.LoaderInternalPropertyName]) {
71
+ return {
72
+ ...loader,
73
+ loader: opts[import_common.Loader.LoaderInternalPropertyName].loader,
74
+ options: (0, import_lodash.omit)(opts, import_common.Loader.LoaderInternalPropertyName)
75
+ };
76
+ }
77
+ return loader;
78
+ });
79
+ const newLoaders = (0, import_lodash.cloneDeep)(originLoaders);
80
+ const proxyModule = new Proxy(module2, {
81
+ get(target, p, receiver) {
82
+ if (p === "loaders")
83
+ return newLoaders;
84
+ return Reflect.get(target, p, receiver);
85
+ },
86
+ set(target, p, newValue, receiver) {
87
+ const _newValue = (0, import_lodash.cloneDeep)(newValue);
88
+ if (p === "loaders") {
89
+ if (Array.isArray(_newValue)) {
90
+ newLoaders.length = 0;
91
+ _newValue.forEach((e) => {
92
+ newLoaders.push(e);
93
+ });
94
+ }
95
+ }
96
+ return Reflect.set(target, p, _newValue, receiver);
97
+ },
98
+ deleteProperty(target, p) {
99
+ return Reflect.deleteProperty(target, p);
100
+ }
101
+ });
102
+ callback(loaderContext, proxyModule);
103
+ if (!(0, import_lodash.isEqual)(originLoaders, newLoaders)) {
104
+ const rules = this.getInterceptRules(
105
+ compiler,
106
+ newLoaders.map((e) => {
107
+ return {
108
+ loader: e.loader,
109
+ options: e.options
110
+ };
111
+ })
112
+ );
113
+ module2.loaders = rules.map((e, i) => {
114
+ return {
115
+ ...newLoaders[i],
116
+ loader: e.loader,
117
+ options: e.options
118
+ };
119
+ });
120
+ }
121
+ };
122
+ const interceptor = {
123
+ register(tap) {
124
+ const originFn = tap.fn;
125
+ if (typeof originFn === "function") {
126
+ tap.fn = wrapper(originFn);
127
+ }
128
+ return tap;
129
+ }
130
+ };
131
+ if (compiler.webpack && compiler.webpack.NormalModule && compiler.webpack.NormalModule.getCompilationHooks) {
132
+ compiler.webpack.NormalModule.getCompilationHooks(
133
+ compilation
134
+ ).loader.intercept(interceptor);
135
+ } else if ("normalModuleLoader" in compilation.hooks) {
136
+ "normalModuleLoader" in compilation.hooks && compilation.hooks.normalModuleLoader.intercept(interceptor);
137
+ }
138
+ }
139
+ getInterceptRules(compiler, rules) {
140
+ return (0, import_utils.interceptLoader)(
141
+ rules,
142
+ this.internalLoaderPath,
143
+ {
144
+ cwd: compiler.context || process.cwd(),
145
+ host: this.sdk.server.origin,
146
+ skipLoaders: this.options.loaderInterceptorOptions.skipLoaders
147
+ // not implement
148
+ },
149
+ this.sdk.root,
150
+ "resolveLoader" in compiler.options ? compiler.options.resolveLoader : {}
151
+ );
152
+ }
153
+ }
154
+ // Annotate the CommonJS export names for ESM import in node:
155
+ 0 && (module.exports = {
156
+ InternalLoaderPlugin
157
+ });
@@ -0,0 +1,8 @@
1
+ import { Plugin } from '@rsdoctor/types';
2
+ import { InternalBasePlugin } from './base';
3
+ export declare class InternalPluginsPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
4
+ readonly name = "plugins";
5
+ apply(compiler: T): void;
6
+ afterPlugins: (compiler: Plugin.BaseCompiler) => void;
7
+ compilation: (compilation: Plugin.BaseCompilation) => void;
8
+ }
@@ -0,0 +1,60 @@
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 plugins_exports = {};
20
+ __export(plugins_exports, {
21
+ InternalPluginsPlugin: () => InternalPluginsPlugin
22
+ });
23
+ module.exports = __toCommonJS(plugins_exports);
24
+ var import_types = require("@rsdoctor/types");
25
+ var import_build = require("../../build-utils/build");
26
+ var import_utils = require("../utils");
27
+ var import_base = require("./base");
28
+ class InternalPluginsPlugin extends import_base.InternalBasePlugin {
29
+ constructor() {
30
+ super(...arguments);
31
+ this.name = "plugins";
32
+ this.afterPlugins = (compiler) => {
33
+ if (compiler.isChild())
34
+ return;
35
+ import_build.Utils.interceptCompilerHooks(
36
+ compiler,
37
+ (name, hook) => (0, import_utils.interceptPluginHook)(this.sdk, name, hook)
38
+ );
39
+ this.sdk.addClientRoutes([
40
+ import_types.Manifest.DoctorManifestClientRoutes.WebpackPlugins
41
+ ]);
42
+ };
43
+ this.compilation = (compilation) => {
44
+ if (compilation.compiler.isChild())
45
+ return;
46
+ import_build.Utils.interceptCompilationHooks(
47
+ compilation,
48
+ (name, hook) => (0, import_utils.interceptPluginHook)(this.sdk, name, hook)
49
+ );
50
+ };
51
+ }
52
+ apply(compiler) {
53
+ compiler.hooks.afterPlugins.tap(this.tapPostOptions, this.afterPlugins);
54
+ compiler.hooks.compilation.tap(this.tapPostOptions, this.compilation);
55
+ }
56
+ }
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ InternalPluginsPlugin
60
+ });
@@ -0,0 +1,8 @@
1
+ import { SDK } from '@rsdoctor/types';
2
+ import type { Plugin } from '@rsdoctor/types';
3
+ import { InternalBasePlugin } from './base';
4
+ export declare class InternalProgressPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
5
+ readonly name = "progress";
6
+ protected currentProgress: SDK.ServerAPI.InferResponseType<SDK.ServerAPI.APIExtends.GetCompileProgess>;
7
+ apply(compiler: T): void;
8
+ }
@@ -0,0 +1,59 @@
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 progress_exports = {};
20
+ __export(progress_exports, {
21
+ InternalProgressPlugin: () => InternalProgressPlugin
22
+ });
23
+ module.exports = __toCommonJS(progress_exports);
24
+ var import_types = require("@rsdoctor/types");
25
+ var import_base = require("./base");
26
+ class InternalProgressPlugin extends import_base.InternalBasePlugin {
27
+ constructor() {
28
+ super(...arguments);
29
+ this.name = "progress";
30
+ this.currentProgress = {
31
+ percentage: 100,
32
+ message: ""
33
+ };
34
+ }
35
+ apply(compiler) {
36
+ const { sdk, currentProgress } = this;
37
+ if (compiler.webpack && compiler.webpack.ProgressPlugin) {
38
+ const progress = new compiler.webpack.ProgressPlugin({
39
+ handler(percentage, msg) {
40
+ currentProgress.percentage = percentage;
41
+ currentProgress.message = msg || "";
42
+ const api = import_types.SDK.ServerAPI.APIExtends.GetCompileProgess;
43
+ sdk.server.sendAPIDataToClient(api, {
44
+ req: {
45
+ api,
46
+ body: void 0
47
+ },
48
+ res: currentProgress
49
+ });
50
+ }
51
+ });
52
+ progress.apply(compiler);
53
+ }
54
+ }
55
+ }
56
+ // Annotate the CommonJS export names for ESM import in node:
57
+ 0 && (module.exports = {
58
+ InternalProgressPlugin
59
+ });
@@ -0,0 +1,14 @@
1
+ import type { Plugin } from '@rsdoctor/types';
2
+ import { InternalBasePlugin } from './base';
3
+ export declare class InternalSummaryPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
4
+ readonly name = "summary";
5
+ private times;
6
+ private preTimes;
7
+ private postTimes;
8
+ apply(compiler: Plugin.BaseCompiler): void;
9
+ private mark;
10
+ beforeCompile: () => Promise<void>;
11
+ afterCompile: (compilation: Plugin.BaseCompilation) => Promise<void>;
12
+ done: (compiler: Plugin.BaseCompiler) => Promise<void>;
13
+ private report;
14
+ }
@@ -0,0 +1,115 @@
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 summary_exports = {};
20
+ __export(summary_exports, {
21
+ InternalSummaryPlugin: () => InternalSummaryPlugin
22
+ });
23
+ module.exports = __toCommonJS(summary_exports);
24
+ var import_common = require("@rsdoctor/utils/common");
25
+ var import_lodash = require("lodash");
26
+ var import_base = require("./base");
27
+ class InternalSummaryPlugin extends import_base.InternalBasePlugin {
28
+ constructor() {
29
+ super(...arguments);
30
+ this.name = "summary";
31
+ this.times = /* @__PURE__ */ new Map();
32
+ this.preTimes = /* @__PURE__ */ new Map();
33
+ this.postTimes = /* @__PURE__ */ new Map();
34
+ this.beforeCompile = async () => {
35
+ if (!this.times.has(import_common.Summary.SummaryCostsDataName.Bootstrap)) {
36
+ const costs = Math.floor(process.uptime() * 1e3);
37
+ const startAt = Date.now() - costs;
38
+ this.report(import_common.Summary.SummaryCostsDataName.Bootstrap, startAt);
39
+ this.mark(import_common.Summary.SummaryCostsDataName.Bootstrap, "post");
40
+ }
41
+ };
42
+ this.afterCompile = async (compilation) => {
43
+ if (!this.times.has(import_common.Summary.SummaryCostsDataName.Compile) && !compilation.compiler.isChild()) {
44
+ const start = this.postTimes.get(import_common.Summary.SummaryCostsDataName.Bootstrap);
45
+ this.report(import_common.Summary.SummaryCostsDataName.Compile, start);
46
+ this.mark(import_common.Summary.SummaryCostsDataName.Compile, "post");
47
+ }
48
+ };
49
+ this.done = async (compiler) => {
50
+ const start = this.postTimes.get(import_common.Summary.SummaryCostsDataName.Compile);
51
+ this.report(import_common.Summary.SummaryCostsDataName.Done, start);
52
+ if (compiler.options.optimization.minimize !== false) {
53
+ const pluginData = this.sdk.getStoreData().plugin;
54
+ const minifyHookData = [
55
+ ...pluginData.optimizeChunkAssets || [],
56
+ // webpack4
57
+ ...pluginData.processAssets || []
58
+ // webpack5
59
+ ];
60
+ minifyHookData.length && this.sdk.reportSummaryData({
61
+ costs: [
62
+ {
63
+ name: import_common.Summary.SummaryCostsDataName.Minify,
64
+ startAt: (0, import_lodash.minBy)(minifyHookData, (e) => e.startAt).startAt,
65
+ costs: (0, import_lodash.sumBy)(minifyHookData, (e) => e.costs)
66
+ }
67
+ ]
68
+ });
69
+ }
70
+ };
71
+ }
72
+ apply(compiler) {
73
+ compiler.hooks.beforeCompile.tapPromise(
74
+ this.tapPostOptions,
75
+ this.beforeCompile
76
+ );
77
+ compiler.hooks.afterCompile.tapPromise(
78
+ this.tapPreOptions,
79
+ this.afterCompile
80
+ );
81
+ compiler.hooks.done.tapPromise(
82
+ this.tapPostOptions,
83
+ this.done.bind(this, compiler)
84
+ );
85
+ }
86
+ mark(key, type) {
87
+ const now = Date.now();
88
+ switch (type) {
89
+ case "pre":
90
+ this.preTimes.set(key, now);
91
+ break;
92
+ case "post":
93
+ this.postTimes.set(key, now);
94
+ break;
95
+ default:
96
+ break;
97
+ }
98
+ }
99
+ report(name, start) {
100
+ this.times.set(name, start);
101
+ this.sdk.reportSummaryData({
102
+ costs: [
103
+ {
104
+ name,
105
+ startAt: start,
106
+ costs: Date.now() - start
107
+ }
108
+ ]
109
+ });
110
+ }
111
+ }
112
+ // Annotate the CommonJS export names for ESM import in node:
113
+ 0 && (module.exports = {
114
+ InternalSummaryPlugin
115
+ });
@@ -0,0 +1,4 @@
1
+ export declare const checkCirclePath: (obj: any, record: {
2
+ prop: string;
3
+ ref: unknown;
4
+ }[], res: string[][], level: number, maxLevel?: number) => void;
@@ -0,0 +1,42 @@
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 circleDetect_exports = {};
20
+ __export(circleDetect_exports, {
21
+ checkCirclePath: () => checkCirclePath
22
+ });
23
+ module.exports = __toCommonJS(circleDetect_exports);
24
+ const checkCirclePath = (obj, record, res, level, maxLevel = 3) => {
25
+ const idx = record.slice(0, record.length - 1).findIndex((v) => v.ref === obj);
26
+ if (idx !== -1) {
27
+ const key = record.map((v) => v.prop);
28
+ if (res.indexOf(key) < 0) {
29
+ res.push(key);
30
+ return;
31
+ }
32
+ }
33
+ if (typeof obj === "object" && obj !== null && level < maxLevel) {
34
+ for (const [k, v] of Object.entries(obj)) {
35
+ checkCirclePath(v, [...record, { prop: k, ref: v }], res, level + 1);
36
+ }
37
+ }
38
+ };
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ checkCirclePath
42
+ });
@@ -0,0 +1,7 @@
1
+ import { Linter, Plugin } from '@rsdoctor/types';
2
+ import { RuleSetCondition as RspackRuleSetCondition } from '@rspack/core';
3
+ import { RuleSetCondition, RuleSetConditionAbsolute, RuleSetRule } from 'webpack';
4
+ import { DoctorWebpackPluginOptions, DoctorPluginOptionsNormalized } from "../../types";
5
+ export declare function normalizeUserConfig<Rules extends Linter.ExtendRuleData[]>(config?: DoctorWebpackPluginOptions<Rules>): DoctorPluginOptionsNormalized<Rules>;
6
+ export declare function makeRuleSetSerializable(item: RuleSetConditionAbsolute | RuleSetCondition | RspackRuleSetCondition | void): void;
7
+ export declare function makeRulesSerializable(rules: Plugin.RuleSetRule[] | RuleSetRule['oneOf']): void;
@@ -0,0 +1,145 @@
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 config_exports = {};
30
+ __export(config_exports, {
31
+ makeRuleSetSerializable: () => makeRuleSetSerializable,
32
+ makeRulesSerializable: () => makeRulesSerializable,
33
+ normalizeUserConfig: () => normalizeUserConfig
34
+ });
35
+ module.exports = __toCommonJS(config_exports);
36
+ var import_types = require("@rsdoctor/types");
37
+ var import_assert = __toESM(require("assert"));
38
+ function defaultBoolean(v, dft) {
39
+ return typeof v === "boolean" ? v : dft;
40
+ }
41
+ function normalizeUserConfig(config = {}) {
42
+ const {
43
+ linter = {},
44
+ features = {},
45
+ loaderInterceptorOptions = {},
46
+ disableClientServer = false,
47
+ sdkInstance,
48
+ reportCodeType = { noModuleSource: false, noAssetsAndModuleSource: false },
49
+ disableTOSUpload = false
50
+ } = config;
51
+ (0, import_assert.default)(linter && typeof linter === "object");
52
+ (0, import_assert.default)(features && typeof features === "object");
53
+ (0, import_assert.default)(
54
+ loaderInterceptorOptions && typeof loaderInterceptorOptions === "object"
55
+ );
56
+ (0, import_assert.default)(typeof disableClientServer === "boolean");
57
+ const _features = Array.isArray(
58
+ features
59
+ ) ? {
60
+ loader: features.includes("loader"),
61
+ plugins: features.includes("plugins"),
62
+ resolver: features.includes("resolver"),
63
+ bundle: features.includes("bundle"),
64
+ treeShaking: features.includes("treeShaking"),
65
+ lite: features.includes("lite")
66
+ } : {
67
+ loader: defaultBoolean(features.loader, true),
68
+ plugins: defaultBoolean(features.plugins, true),
69
+ resolver: defaultBoolean(features.resolver, false),
70
+ bundle: defaultBoolean(features.bundle, true),
71
+ treeShaking: defaultBoolean(features.treeShaking, false),
72
+ lite: defaultBoolean(features.lite, false)
73
+ };
74
+ const _linter = {
75
+ rules: {},
76
+ extends: [],
77
+ level: "Error",
78
+ ...linter
79
+ };
80
+ const res = {
81
+ linter: _linter,
82
+ features: _features,
83
+ loaderInterceptorOptions: {
84
+ skipLoaders: Array.isArray(loaderInterceptorOptions.skipLoaders) ? loaderInterceptorOptions.skipLoaders : []
85
+ },
86
+ disableClientServer,
87
+ sdkInstance,
88
+ /**
89
+ * Data storage is divided into three types:
90
+ * The first type: normal mode, all codes are saved.
91
+ * The second type: lite is the same as reportCodeType.noModuleSource, which lacks module source code.
92
+ * The third type: reportCodeType.noAssetsAndModuleSource means there is no module source code nor the packaged product code.
93
+ *
94
+ * */
95
+ reportCodeType: reportCodeType ? reportCodeType.noModuleSource ? import_types.SDK.ToDataType.Lite : reportCodeType.noAssetsAndModuleSource ? import_types.SDK.ToDataType.LiteAndNoAsset : import_types.SDK.ToDataType.Normal : _features.lite ? import_types.SDK.ToDataType.Lite : import_types.SDK.ToDataType.Normal,
96
+ disableTOSUpload
97
+ };
98
+ return res;
99
+ }
100
+ function makeRuleSetSerializable(item) {
101
+ if (!item)
102
+ return;
103
+ if (item instanceof RegExp) {
104
+ item.toJSON = item.toString;
105
+ } else if (Array.isArray(item)) {
106
+ item.forEach((i) => makeRuleSetSerializable(i));
107
+ } else if (typeof item === "object") {
108
+ makeRuleSetSerializable(item.and);
109
+ makeRuleSetSerializable(item.or);
110
+ makeRuleSetSerializable(item.not);
111
+ }
112
+ }
113
+ function makeRulesSerializable(rules) {
114
+ if (!Array.isArray(rules))
115
+ return;
116
+ if (!rules.length)
117
+ return;
118
+ rules.forEach((rule) => {
119
+ if (!rule)
120
+ return;
121
+ makeRuleSetSerializable(rule.test);
122
+ makeRuleSetSerializable(rule.resourceQuery);
123
+ makeRuleSetSerializable(rule.resource);
124
+ makeRuleSetSerializable(rule.resourceFragment);
125
+ makeRuleSetSerializable(rule.scheme);
126
+ makeRuleSetSerializable(rule.issuer);
127
+ if ("issuerLayer" in rule) {
128
+ makeRuleSetSerializable(rule.issuerLayer);
129
+ }
130
+ makeRuleSetSerializable(rule.include);
131
+ makeRuleSetSerializable(rule.exclude);
132
+ if (rule.oneOf) {
133
+ makeRulesSerializable(rule.oneOf);
134
+ }
135
+ if ("rules" in rule && rule.rules) {
136
+ makeRulesSerializable(rule.rules);
137
+ }
138
+ });
139
+ }
140
+ // Annotate the CommonJS export names for ESM import in node:
141
+ 0 && (module.exports = {
142
+ makeRuleSetSerializable,
143
+ makeRulesSerializable,
144
+ normalizeUserConfig
145
+ });
@@ -0,0 +1,5 @@
1
+ export * from './loader';
2
+ export * from './plugin';
3
+ export * from './sdk';
4
+ export * from './config';
5
+ export * from './circleDetect';