@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,134 +0,0 @@
1
- import "node:module";
2
- import { omit } from "../../collection.js";
3
- import path from "path";
4
- import { logger } from "../../logger.js";
5
- import { Fetch, Loader, Lodash, Time } from "../../common/index.js";
6
- import { SDK } from "@rsdoctor/shared/types";
7
- import { DevToolError } from "../../error/index.js";
8
- import { getSDK } from "./sdk.js";
9
- import { checkCirclePath } from "./circleDetect.js";
10
- import { Utils } from "../../build-utils/build/index.js";
11
- import { isESMLoader, parseQuery } from "../../build-utils/build/utils/index.js";
12
- function getInternalLoaderOptions(loaderContext) {
13
- const options = loaderContext.getOptions();
14
- return options[Loader.LoaderInternalPropertyName];
15
- }
16
- function getLoaderOptionsWithoutInternalKeys(loaderContext) {
17
- const options = loaderContext.getOptions();
18
- const circlePaths = [];
19
- const loaderOptions = omit(options, [
20
- Loader.LoaderInternalPropertyName
21
- ]);
22
- checkCirclePath(loaderOptions, [], circlePaths, 0);
23
- if (circlePaths.length > 0) circlePaths.forEach((_path)=>{
24
- if (_path?.length > 0 && '[Circular]' !== loaderOptions[_path[0]]) loaderOptions[_path[0]] = '[Circular]';
25
- });
26
- return loaderOptions;
27
- }
28
- function getOriginLoaderModule(loaderContext) {
29
- const { loader, cwd } = getInternalLoaderOptions(loaderContext);
30
- return Utils.loadLoaderModule(loader, cwd);
31
- }
32
- function shouldSkipLoader(loaderContext) {
33
- const { skipLoaders, cwd, loader } = getInternalLoaderOptions(loaderContext) || {};
34
- if (!loader) return true;
35
- if (Array.isArray(skipLoaders) && skipLoaders.length) {
36
- if (skipLoaders.includes(loader)) return true;
37
- const loaderName = Utils.extractLoaderName(loader, cwd);
38
- if (skipLoaders.includes(loaderName)) return true;
39
- }
40
- return false;
41
- }
42
- function interceptLoader(rules, loaderPath, options, loaderResolver, cwd = process.cwd()) {
43
- const resolve = (target)=>{
44
- try {
45
- const result = loaderResolver.resolveSync({}, cwd, target);
46
- if (result) return result;
47
- } catch {}
48
- return target;
49
- };
50
- return Utils.mapEachRules(rules, (rule)=>{
51
- if (rule.loader?.startsWith('builtin:') || rule.loader?.endsWith('.mjs') || isESMLoader(rule)) return rule;
52
- const opts = {
53
- ...'options' in rule ? 'string' == typeof rule.options ? JSON.parse(rule.options) : rule.options : {}
54
- };
55
- opts[Loader.LoaderInternalPropertyName] = rule.loader && /proxy\.(js|cjs)/.test(rule.loader) && 'options' in rule && 'object' == typeof rule.options ? rule.options[Loader.LoaderInternalPropertyName] : {
56
- ...options,
57
- hasOptions: 'options' in rule && Boolean(rule.options),
58
- loader: 'loader' in rule ? resolve(rule.loader) : ''
59
- };
60
- return {
61
- ...rule,
62
- loader: loaderPath,
63
- options: opts
64
- };
65
- });
66
- }
67
- async function reportLoader(ctx, start, startHRTime, isPitch, sync, code, err, res, sourceMap) {
68
- const end = Time.getCurrentTimestamp(start, startHRTime);
69
- const { loader, host } = getInternalLoaderOptions(ctx);
70
- const loaderData = [
71
- {
72
- resource: {
73
- path: ctx._module?.layer ? `${ctx.resourcePath}[${ctx._module.layer}]` : ctx.resourcePath,
74
- query: parseQuery(ctx.resourceQuery || '?'),
75
- queryRaw: ctx.resourceQuery,
76
- ext: path.extname(ctx.resourcePath).slice(1),
77
- ...ctx._module?.layer ? {
78
- layer: ctx._module.layer
79
- } : {}
80
- },
81
- loaders: [
82
- {
83
- loader: Utils.extractLoaderName(loader),
84
- loaderIndex: ctx.loaderIndex,
85
- path: loader,
86
- input: code,
87
- result: 'string' == typeof res || Buffer.isBuffer(res) ? res.toString() : res,
88
- startAt: start,
89
- endAt: end,
90
- options: getLoaderOptionsWithoutInternalKeys(ctx),
91
- isPitch,
92
- sync,
93
- errors: err ? [
94
- new DevToolError(code, err.message, {
95
- controller: {
96
- noStack: false,
97
- noColor: true
98
- },
99
- stack: err.stack
100
- })
101
- ] : [],
102
- pid: process.pid,
103
- ppid: process.ppid
104
- }
105
- ]
106
- }
107
- ];
108
- const data = sourceMap ? Lodash.isString(sourceMap) ? JSON.parse(sourceMap) : sourceMap : {};
109
- const sourceMapData = {
110
- version: data.version ?? -1,
111
- sources: data.sources ?? [],
112
- names: data.names ?? [],
113
- sourceRoot: data.sourceRoot,
114
- sourcesContent: data.sourcesContent,
115
- mappings: data.mappings,
116
- file: loaderData[0].resource.path
117
- };
118
- const sdk = getSDK(ctx._compilation?.name);
119
- if (sdk?.reportLoader && !('parent' in sdk && sdk.parent)) {
120
- sdk.reportLoader(loaderData);
121
- sdk.reportSourceMap(sourceMapData);
122
- return loaderData;
123
- }
124
- await Promise.all([
125
- Fetch.postJSON(`${host}${SDK.ServerAPI.API.ReportLoader}`, loaderData, 8888).catch((err)=>{
126
- logger.debug(`${err.message}`, '[RspackPlugin.ReportLoader][error]');
127
- }),
128
- Fetch.postJSON(`${host}${SDK.ServerAPI.API.ReportSourceMap}`, sourceMapData, 8888).catch((err)=>{
129
- logger.debug(`${err.message}`, '[RspackPlugin.ReportSourceMap][error]');
130
- })
131
- ]);
132
- return loaderData;
133
- }
134
- export { getInternalLoaderOptions, getLoaderOptionsWithoutInternalKeys, getOriginLoaderModule, interceptLoader, reportLoader, shouldSkipLoader };
@@ -1,77 +0,0 @@
1
- import "node:module";
2
- function processModeConfigurations(finalMode, output, brief) {
3
- let finalBrief = {};
4
- let finalNormalOptions = {};
5
- if ('brief' === finalMode) finalBrief = processBriefHtmlModeConfig(output, brief);
6
- else if ('normal' === finalMode) finalNormalOptions = {};
7
- return {
8
- finalBrief,
9
- finalNormalOptions
10
- };
11
- }
12
- function processBriefHtmlModeConfig(output, brief) {
13
- let htmlOptions = {
14
- reportHtmlName: void 0,
15
- writeDataJson: false
16
- };
17
- let jsonOptions = {};
18
- const briefOptions = output?.options || {};
19
- if ('type' in briefOptions && briefOptions.type?.includes('json')) jsonOptions = briefOptions.jsonOptions || {
20
- fileName: 'rsdoctor-data.json',
21
- sections: {
22
- moduleGraph: true,
23
- chunkGraph: true,
24
- rules: true
25
- }
26
- };
27
- if ('type' in briefOptions && briefOptions.type?.includes('html') || !briefOptions.type) {
28
- const outputBriefOptions = briefOptions?.htmlOptions;
29
- const outputBrief = brief;
30
- htmlOptions = {
31
- reportHtmlName: outputBriefOptions?.reportHtmlName || outputBrief?.reportHtmlName || void 0,
32
- writeDataJson: outputBriefOptions?.writeDataJson || outputBrief?.writeDataJson || false
33
- };
34
- }
35
- return {
36
- type: output.options?.type || [
37
- 'html'
38
- ],
39
- htmlOptions,
40
- jsonOptions
41
- };
42
- }
43
- function convertReportCodeTypeObject(reportCodeType) {
44
- if (!reportCodeType) return;
45
- if (reportCodeType.noCode) return 'noCode';
46
- if (reportCodeType.noAssetsAndModuleSource) return 'noAssetsAndModuleSource';
47
- if (reportCodeType.noModuleSource) return 'noModuleSource';
48
- }
49
- function makeRuleSetSerializable(item) {
50
- if (!item) return;
51
- if (item instanceof RegExp) item.toJSON = item.toString;
52
- else if (Array.isArray(item)) item.forEach((i)=>makeRuleSetSerializable(i));
53
- else if ('object' == typeof item) {
54
- makeRuleSetSerializable(item.and);
55
- makeRuleSetSerializable(item.or);
56
- makeRuleSetSerializable(item.not);
57
- }
58
- }
59
- function makeRulesSerializable(rules) {
60
- if (!Array.isArray(rules)) return;
61
- if (!rules.length) return;
62
- rules.forEach((rule)=>{
63
- if (!rule) return;
64
- makeRuleSetSerializable(rule.test);
65
- makeRuleSetSerializable(rule.resourceQuery);
66
- makeRuleSetSerializable(rule.resource);
67
- makeRuleSetSerializable(rule.resourceFragment);
68
- makeRuleSetSerializable(rule.scheme);
69
- makeRuleSetSerializable(rule.issuer);
70
- if ('issuerLayer' in rule) makeRuleSetSerializable(rule.issuerLayer);
71
- makeRuleSetSerializable(rule.include);
72
- makeRuleSetSerializable(rule.exclude);
73
- if (rule.oneOf) makeRulesSerializable(rule.oneOf);
74
- if ('rules' in rule && rule.rules) makeRulesSerializable(rule.rules);
75
- });
76
- }
77
- export { convertReportCodeTypeObject, makeRuleSetSerializable, makeRulesSerializable, processBriefHtmlModeConfig, processModeConfigurations };
@@ -1,55 +0,0 @@
1
- import "node:module";
2
- import { exec } from "node:child_process";
3
- import { dirname, join } from "node:path";
4
- import { promisify } from "node:util";
5
- import { fileURLToPath } from "node:url";
6
- import { logger } from "../../logger.js";
7
- const execAsync = promisify(exec);
8
- const openBrowser_dirname = dirname(fileURLToPath(import.meta.url));
9
- const supportedChromiumBrowsers = [
10
- 'Google Chrome Canary',
11
- 'Google Chrome Dev',
12
- 'Google Chrome Beta',
13
- 'Google Chrome',
14
- 'Microsoft Edge',
15
- 'Brave Browser',
16
- 'Vivaldi',
17
- 'Chromium'
18
- ];
19
- const getTargetBrowser = async ()=>{
20
- let targetBrowser = process.env.BROWSER;
21
- if (!targetBrowser || !supportedChromiumBrowsers.includes(targetBrowser)) {
22
- const { stdout: ps } = await execAsync('ps cax');
23
- targetBrowser = supportedChromiumBrowsers.find((b)=>ps.includes(b));
24
- }
25
- return targetBrowser;
26
- };
27
- const openWithDefaultBrowser = async (url)=>{
28
- try {
29
- const { default: open } = await import("open");
30
- await open(url);
31
- return true;
32
- } catch (err) {
33
- logger.error('Failed to open Rsdoctor URL.');
34
- logger.error(err);
35
- return false;
36
- }
37
- };
38
- async function openBrowser(url, needEncodeURI = true) {
39
- const shouldTryOpenChromeWithAppleScript = 'darwin' === process.platform;
40
- if (shouldTryOpenChromeWithAppleScript) try {
41
- const targetBrowser = await getTargetBrowser();
42
- if (targetBrowser) {
43
- await execAsync(`osascript openChrome.applescript "${needEncodeURI ? encodeURI(url) : url}" "${targetBrowser}"`, {
44
- cwd: join(openBrowser_dirname, '../../../static')
45
- });
46
- return true;
47
- }
48
- logger.debug('Failed to find the target browser.');
49
- } catch (err) {
50
- logger.debug("Failed to open Rsdoctor URL with apple script.");
51
- logger.debug(err);
52
- }
53
- return openWithDefaultBrowser(url);
54
- }
55
- export { openBrowser };
@@ -1,94 +0,0 @@
1
- import "node:module";
2
- import { makeRulesSerializable } from "../index.js";
3
- import { SDK } from "@rsdoctor/shared/types";
4
- import { chalk } from "../../logger.js";
5
- import path from "path";
6
- import { openBrowser } from "./openBrowser.js";
7
- function safeCloneDeep(value, visited = new WeakMap()) {
8
- if (null == value) return value;
9
- if ('object' != typeof value) return value;
10
- if (value instanceof Date) return new Date(value.getTime());
11
- if (value instanceof RegExp) return new RegExp(value.source, value.flags);
12
- if (visited.has(value)) return visited.get(value);
13
- if (Array.isArray(value)) {
14
- const len = value.length;
15
- const cloned = new Array(len);
16
- visited.set(value, cloned);
17
- for(let i = 0; i < len; i++)cloned[i] = safeCloneDeep(value[i], visited);
18
- return cloned;
19
- }
20
- const cloned = {};
21
- visited.set(value, cloned);
22
- const ownPropertyNames = Object.getOwnPropertyNames(value);
23
- const ownSymbols = Object.getOwnPropertySymbols(value);
24
- const enumerableKeys = Object.keys(value);
25
- const enumerableKeysSet = new Set(enumerableKeys);
26
- const obj = value;
27
- for(let i = 0; i < enumerableKeys.length; i++){
28
- const key = enumerableKeys[i];
29
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
30
- if (!descriptor || !descriptor.get || descriptor.set) try {
31
- const propValue = obj[key];
32
- cloned[key] = safeCloneDeep(propValue, visited);
33
- } catch {
34
- continue;
35
- }
36
- }
37
- for(let i = 0; i < ownPropertyNames.length; i++){
38
- const key = ownPropertyNames[i];
39
- if (enumerableKeysSet.has(key)) continue;
40
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
41
- if (descriptor) {
42
- if (!descriptor.get || descriptor.set) {
43
- if (void 0 !== descriptor.set) try {
44
- const propValue = obj[key];
45
- cloned[key] = safeCloneDeep(propValue, visited);
46
- } catch {
47
- continue;
48
- }
49
- }
50
- }
51
- }
52
- for(let i = 0; i < ownSymbols.length; i++){
53
- const key = ownSymbols[i];
54
- const descriptor = Object.getOwnPropertyDescriptor(value, key);
55
- if (descriptor) {
56
- if (!descriptor.get || descriptor.set) {
57
- if (descriptor.enumerable || void 0 !== descriptor.set) try {
58
- const propValue = obj[key];
59
- cloned[key] = safeCloneDeep(propValue, visited);
60
- } catch {
61
- continue;
62
- }
63
- }
64
- }
65
- }
66
- return cloned;
67
- }
68
- function processCompilerConfig(config) {
69
- const { plugins, infrastructureLogging: _infrastructureLogging, ...rest } = config;
70
- const _rest = safeCloneDeep(rest);
71
- if (_rest.module?.defaultRules) makeRulesSerializable(_rest.module.defaultRules);
72
- if (_rest.module?.rules) makeRulesSerializable(_rest.module.rules);
73
- return {
74
- ..._rest,
75
- plugins: plugins.map((e)=>e?.constructor.name)
76
- };
77
- }
78
- async function handleBriefModeReport(sdk, options, disableClientServer) {
79
- if (!disableClientServer && options.output.mode === SDK.IMode[SDK.IMode.brief]) {
80
- const outputTypes = options.output.options?.type || [];
81
- const isJsonOnly = Array.isArray(outputTypes) && 1 === outputTypes.length && 'json' === outputTypes[0];
82
- if (isJsonOnly) {
83
- const jsonFileName = options.output.options?.jsonOptions?.fileName || 'rsdoctor-data.json';
84
- const jsonFilePath = path.resolve(sdk.outputDir, jsonFileName);
85
- console.log(`${chalk.green('[RSDOCTOR] generated JSON data')}: ${jsonFilePath}`);
86
- } else {
87
- const htmlOptions = 'htmlOptions' in options.output.options && options.output.options.htmlOptions || void 0;
88
- const outputFilePath = path.resolve(sdk.outputDir, htmlOptions?.reportHtmlName || 'rsdoctor-report.html');
89
- console.log(`${chalk.green('[RSDOCTOR] generated brief report')}: ${outputFilePath}`);
90
- openBrowser(`file:///${outputFilePath}`);
91
- }
92
- }
93
- }
94
- export { handleBriefModeReport, processCompilerConfig, safeCloneDeep };
@@ -1,70 +0,0 @@
1
- import "node:module";
2
- import { DevToolError } from "../../error/index.js";
3
- function reportPluginData(sdk, hook, tapName, start, type, _res, err) {
4
- const end = Date.now();
5
- sdk.reportPlugin({
6
- [hook]: [
7
- {
8
- tapName,
9
- costs: end - start,
10
- startAt: start,
11
- endAt: end,
12
- type,
13
- result: null,
14
- error: err ? [
15
- new DevToolError(`${tapName} ${hook} Error`, err.message, {
16
- controller: {
17
- noStack: false,
18
- noColor: true
19
- },
20
- stack: err.stack
21
- })
22
- ] : []
23
- }
24
- ]
25
- });
26
- }
27
- function interceptPluginHook(sdk, name, hook) {
28
- if (!hook?.intercept) return;
29
- hook.intercept({
30
- register (tap) {
31
- const o = tap.fn;
32
- if ('sync' === tap.type) tap.fn = function(...args) {
33
- const start = Date.now();
34
- try {
35
- const res = o.apply(this, args);
36
- reportPluginData(sdk, name, tap.name, start, tap.type, res);
37
- return res;
38
- } catch (error) {
39
- reportPluginData(sdk, name, tap.name, start, tap.type, null, error);
40
- throw error;
41
- }
42
- };
43
- else if ('async' === tap.type) tap.fn = async function(...args) {
44
- const start = Date.now();
45
- try {
46
- const res = await o.apply(this, args);
47
- reportPluginData(sdk, name, tap.name, start, tap.type, res);
48
- return res;
49
- } catch (error) {
50
- reportPluginData(sdk, name, tap.name, start, tap.type, null, error);
51
- throw error;
52
- }
53
- };
54
- else if ('promise' === tap.type) tap.fn = function(...args) {
55
- const start = Date.now();
56
- const isChild = args?.[0]?.compiler?.isChild();
57
- return o.apply(this, args).then((res)=>{
58
- if (isChild) return res;
59
- reportPluginData(sdk, name, tap.name, start, tap.type, res);
60
- return res;
61
- }).catch((error)=>{
62
- reportPluginData(sdk, name, tap.name, start, tap.type, null, error);
63
- throw error;
64
- });
65
- };
66
- return tap;
67
- }
68
- });
69
- }
70
- export { interceptPluginHook, reportPluginData };
@@ -1,19 +0,0 @@
1
- import "node:module";
2
- const globalKey = '__rsdoctor_sdks__';
3
- function setSDK(t) {
4
- if (!globalThis.__rsdoctor_sdks__) globalThis.__rsdoctor_sdks__ = [];
5
- globalThis.__rsdoctor_sdks__.push(t);
6
- globalThis.__rsdoctor_sdk__ = t;
7
- }
8
- function getSDK(builderName) {
9
- const sdks = globalThis[globalKey] || [];
10
- let sdk = globalThis['__rsdoctor_sdk__'];
11
- if (sdk && sdk.name !== builderName) sdk = builderName ? sdks.find((s)=>s.name === builderName) || sdk : sdk;
12
- if (sdk && builderName && 'parent' in sdk) {
13
- const parent = sdk.parent;
14
- const slaveSDK = parent?.slaves.find((_sdk)=>_sdk.name === builderName);
15
- return slaveSDK || sdk;
16
- }
17
- return sdk;
18
- }
19
- export { getSDK, setSDK };
package/dist/logger.js DELETED
@@ -1,51 +0,0 @@
1
- import "node:module";
2
- import picocolors from "picocolors";
3
- import { createLogger, logger } from "rslog";
4
- import { Constants } from "@rsdoctor/shared/types";
5
- function debug(getMsg, prefix = '') {
6
- if (!process.env.DEBUG) return;
7
- logger.level = 'verbose';
8
- logger.debug(`${prefix} ${getMsg()}`);
9
- }
10
- const rsdoctorLogger = createLogger();
11
- rsdoctorLogger.override({
12
- log: (message)=>{
13
- console.log(`${picocolors.green('[RSDOCTOR LOG]')} ${message}`);
14
- },
15
- info: (message)=>{
16
- console.log(`${picocolors.yellow('[RSDOCTOR INFO]')} ${message}`);
17
- },
18
- warn: (message)=>{
19
- console.warn(`${picocolors.yellow('[RSDOCTOR WARN]')} ${message}`);
20
- },
21
- start: (message)=>{
22
- console.log(`${picocolors.green('[RSDOCTOR START]')} ${message}`);
23
- },
24
- ready: (message)=>{
25
- console.log(`${picocolors.green('[RSDOCTOR READY]')} ${message}`);
26
- },
27
- error: (message)=>{
28
- console.error(`${picocolors.red('[RSDOCTOR ERROR]')} ${message}`);
29
- },
30
- success: (message)=>{
31
- console.error(`${picocolors.green('[RSDOCTOR SUCCESS]')} ${message}`);
32
- },
33
- debug: (message)=>{
34
- if (process.env.DEBUG) console.log(`${picocolors.blue('[RSDOCTOR DEBUG]')} ${message}`);
35
- }
36
- });
37
- const _timers = new Map();
38
- function time(label) {
39
- if (process.env.DEBUG !== Constants.RsdoctorProcessEnvDebugKey) return;
40
- if (_timers.has(label)) return;
41
- _timers.set(label, Date.now());
42
- }
43
- function timeEnd(label) {
44
- if (process.env.DEBUG !== Constants.RsdoctorProcessEnvDebugKey) return;
45
- const start = _timers.get(label);
46
- if (null == start) return void logger.debug(`Timer '${label}' does not exist.`);
47
- const duration = Date.now() - start;
48
- logger.debug(`Timer '${label}' ended: ${duration}ms`);
49
- _timers.delete(label);
50
- }
51
- export { debug, picocolors as chalk, rsdoctorLogger as logger, time, timeEnd };
@@ -1,23 +0,0 @@
1
- import "node:module";
2
- import { createRequire } from "node:module";
3
- const constants_require = createRequire(import.meta.url);
4
- const packageJson = constants_require('../../package.json');
5
- const pluginTapName = 'RsdoctorRspackPlugin';
6
- const pluginTapPostOptions = {
7
- name: pluginTapName,
8
- stage: 999
9
- };
10
- const pluginTapPreOptions = {
11
- name: pluginTapName,
12
- stage: -999
13
- };
14
- const internalPluginTapPreOptions = (namespace)=>({
15
- name: `${pluginTapName}:${namespace}`,
16
- stage: -998
17
- });
18
- const internalPluginTapPostOptions = (namespace)=>({
19
- name: `${pluginTapName}:${namespace}`,
20
- stage: 1000
21
- });
22
- const pkg = packageJson;
23
- export { internalPluginTapPostOptions, internalPluginTapPreOptions, pkg, pluginTapName, pluginTapPostOptions, pluginTapPreOptions };
@@ -1,3 +0,0 @@
1
- import "node:module";
2
- export * from "./plugin.js";
3
- export * from "./multiple.js";
@@ -1,39 +0,0 @@
1
- import "node:module";
2
- import { RsdoctorSDKController } from "../sdk.js";
3
- import { SDK } from "@rsdoctor/shared/types";
4
- import { normalizeUserConfig } from "../inner-plugins/index.js";
5
- import { RsdoctorRspackPlugin } from "./plugin.js";
6
- let globalController;
7
- class RsdoctorRspackMultiplePlugin extends RsdoctorRspackPlugin {
8
- apply(compiler) {
9
- if ('dependencies' in compiler.options) this.sdk.dependencies = compiler.options.dependencies;
10
- super.apply(compiler);
11
- }
12
- constructor(options = {}){
13
- const controller = (()=>{
14
- if (globalController) return globalController;
15
- const controller = new RsdoctorSDKController();
16
- globalController = controller;
17
- return controller;
18
- })();
19
- const normallizedOptions = normalizeUserConfig(options);
20
- const instance = controller.createSlave({
21
- name: options.name || 'Builder',
22
- stage: options.stage,
23
- extraConfig: {
24
- innerClientPath: normallizedOptions.innerClientPath,
25
- printLog: normallizedOptions.printLog,
26
- server: normallizedOptions.server,
27
- mode: normallizedOptions.output.mode ? normallizedOptions.output.mode : void 0,
28
- brief: normallizedOptions.output.mode === SDK.IMode[SDK.IMode.brief] ? normallizedOptions.output.options || void 0 : void 0
29
- },
30
- type: normallizedOptions.output.reportCodeType
31
- });
32
- super({
33
- ...options,
34
- sdkInstance: instance
35
- });
36
- this.controller = controller;
37
- }
38
- }
39
- export { RsdoctorRspackMultiplePlugin };