@rsdoctor/utils 0.0.0-next-20240620044732

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 (183) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -0
  3. package/dist/cjs/build/envinfo.js +109 -0
  4. package/dist/cjs/build/file/cache.js +67 -0
  5. package/dist/cjs/build/file/index.js +44 -0
  6. package/dist/cjs/build/file/sharding.js +84 -0
  7. package/dist/cjs/build/index.js +50 -0
  8. package/dist/cjs/build/json.js +52 -0
  9. package/dist/cjs/build/process.js +49 -0
  10. package/dist/cjs/build/server.js +127 -0
  11. package/dist/cjs/common/alerts.js +49 -0
  12. package/dist/cjs/common/algorithm.js +60 -0
  13. package/dist/cjs/common/bundle.js +56 -0
  14. package/dist/cjs/common/crypto.js +53 -0
  15. package/dist/cjs/common/data/index.js +299 -0
  16. package/dist/cjs/common/graph/assets.js +322 -0
  17. package/dist/cjs/common/graph/chunk.js +67 -0
  18. package/dist/cjs/common/graph/dependency.js +40 -0
  19. package/dist/cjs/common/graph/entrypoints.js +30 -0
  20. package/dist/cjs/common/graph/index.js +30 -0
  21. package/dist/cjs/common/graph/modules.js +98 -0
  22. package/dist/cjs/common/index.js +80 -0
  23. package/dist/cjs/common/loader.js +261 -0
  24. package/dist/cjs/common/manifest.js +72 -0
  25. package/dist/cjs/common/package.js +97 -0
  26. package/dist/cjs/common/plugin.js +86 -0
  27. package/dist/cjs/common/resolver.js +82 -0
  28. package/dist/cjs/common/rspack.js +37 -0
  29. package/dist/cjs/common/summary.js +34 -0
  30. package/dist/cjs/common/time.js +91 -0
  31. package/dist/cjs/common/url.js +46 -0
  32. package/dist/cjs/error/error.js +236 -0
  33. package/dist/cjs/error/index.js +31 -0
  34. package/dist/cjs/error/transform.js +175 -0
  35. package/dist/cjs/error/utils.js +66 -0
  36. package/dist/cjs/index.js +41 -0
  37. package/dist/cjs/logger.js +51 -0
  38. package/dist/cjs/rule-utils/document/document.js +91 -0
  39. package/dist/cjs/rule-utils/document/index.js +26 -0
  40. package/dist/cjs/rule-utils/document/server.js +42 -0
  41. package/dist/cjs/rule-utils/document/types.js +16 -0
  42. package/dist/cjs/rule-utils/index.js +24 -0
  43. package/dist/cjs/rule-utils/parser/asserts.js +156 -0
  44. package/dist/cjs/rule-utils/parser/index.js +28 -0
  45. package/dist/cjs/rule-utils/parser/parser.js +92 -0
  46. package/dist/cjs/rule-utils/parser/types.js +33 -0
  47. package/dist/cjs/rule-utils/parser/utils.js +197 -0
  48. package/dist/esm/build/envinfo.js +75 -0
  49. package/dist/esm/build/file/cache.js +30 -0
  50. package/dist/esm/build/file/index.js +7 -0
  51. package/dist/esm/build/file/sharding.js +50 -0
  52. package/dist/esm/build/index.js +12 -0
  53. package/dist/esm/build/json.js +28 -0
  54. package/dist/esm/build/process.js +24 -0
  55. package/dist/esm/build/server.js +88 -0
  56. package/dist/esm/common/alerts.js +25 -0
  57. package/dist/esm/common/algorithm.js +33 -0
  58. package/dist/esm/common/bundle.js +30 -0
  59. package/dist/esm/common/crypto.js +28 -0
  60. package/dist/esm/common/data/index.js +265 -0
  61. package/dist/esm/common/graph/assets.js +286 -0
  62. package/dist/esm/common/graph/chunk.js +38 -0
  63. package/dist/esm/common/graph/dependency.js +14 -0
  64. package/dist/esm/common/graph/entrypoints.js +6 -0
  65. package/dist/esm/common/graph/index.js +5 -0
  66. package/dist/esm/common/graph/modules.js +70 -0
  67. package/dist/esm/common/index.js +32 -0
  68. package/dist/esm/common/loader.js +225 -0
  69. package/dist/esm/common/manifest.js +46 -0
  70. package/dist/esm/common/package.js +71 -0
  71. package/dist/esm/common/plugin.js +59 -0
  72. package/dist/esm/common/resolver.js +54 -0
  73. package/dist/esm/common/rspack.js +12 -0
  74. package/dist/esm/common/summary.js +10 -0
  75. package/dist/esm/common/time.js +64 -0
  76. package/dist/esm/common/url.js +20 -0
  77. package/dist/esm/error/error.js +202 -0
  78. package/dist/esm/error/index.js +5 -0
  79. package/dist/esm/error/transform.js +141 -0
  80. package/dist/esm/error/utils.js +40 -0
  81. package/dist/esm/index.js +6 -0
  82. package/dist/esm/logger.js +15 -0
  83. package/dist/esm/rule-utils/document/document.js +67 -0
  84. package/dist/esm/rule-utils/document/index.js +3 -0
  85. package/dist/esm/rule-utils/document/server.js +17 -0
  86. package/dist/esm/rule-utils/document/types.js +0 -0
  87. package/dist/esm/rule-utils/index.js +2 -0
  88. package/dist/esm/rule-utils/parser/asserts.js +132 -0
  89. package/dist/esm/rule-utils/parser/index.js +4 -0
  90. package/dist/esm/rule-utils/parser/parser.js +58 -0
  91. package/dist/esm/rule-utils/parser/types.js +9 -0
  92. package/dist/esm/rule-utils/parser/utils.js +164 -0
  93. package/dist/type/build/envinfo.d.ts +14 -0
  94. package/dist/type/build/envinfo.d.ts.map +1 -0
  95. package/dist/type/build/file/cache.d.ts +6 -0
  96. package/dist/type/build/file/cache.d.ts.map +1 -0
  97. package/dist/type/build/file/index.d.ts +4 -0
  98. package/dist/type/build/file/index.d.ts.map +1 -0
  99. package/dist/type/build/file/sharding.d.ts +23 -0
  100. package/dist/type/build/file/sharding.d.ts.map +1 -0
  101. package/dist/type/build/index.d.ts +6 -0
  102. package/dist/type/build/index.d.ts.map +1 -0
  103. package/dist/type/build/json.d.ts +2 -0
  104. package/dist/type/build/json.d.ts.map +1 -0
  105. package/dist/type/build/process.d.ts +4 -0
  106. package/dist/type/build/process.d.ts.map +1 -0
  107. package/dist/type/build/server.d.ts +16 -0
  108. package/dist/type/build/server.d.ts.map +1 -0
  109. package/dist/type/common/alerts.d.ts +3 -0
  110. package/dist/type/common/alerts.d.ts.map +1 -0
  111. package/dist/type/common/algorithm.d.ts +5 -0
  112. package/dist/type/common/algorithm.d.ts.map +1 -0
  113. package/dist/type/common/bundle.d.ts +4 -0
  114. package/dist/type/common/bundle.d.ts.map +1 -0
  115. package/dist/type/common/crypto.d.ts +3 -0
  116. package/dist/type/common/crypto.d.ts.map +1 -0
  117. package/dist/type/common/data/index.d.ts +11 -0
  118. package/dist/type/common/data/index.d.ts.map +1 -0
  119. package/dist/type/common/graph/assets.d.ts +53 -0
  120. package/dist/type/common/graph/assets.d.ts.map +1 -0
  121. package/dist/type/common/graph/chunk.d.ts +8 -0
  122. package/dist/type/common/graph/chunk.d.ts.map +1 -0
  123. package/dist/type/common/graph/dependency.d.ts +5 -0
  124. package/dist/type/common/graph/dependency.d.ts.map +1 -0
  125. package/dist/type/common/graph/entrypoints.d.ts +3 -0
  126. package/dist/type/common/graph/entrypoints.d.ts.map +1 -0
  127. package/dist/type/common/graph/index.d.ts +6 -0
  128. package/dist/type/common/graph/index.d.ts.map +1 -0
  129. package/dist/type/common/graph/modules.d.ts +10 -0
  130. package/dist/type/common/graph/modules.d.ts.map +1 -0
  131. package/dist/type/common/index.d.ts +16 -0
  132. package/dist/type/common/index.d.ts.map +1 -0
  133. package/dist/type/common/loader.d.ts +19 -0
  134. package/dist/type/common/loader.d.ts.map +1 -0
  135. package/dist/type/common/manifest.d.ts +5 -0
  136. package/dist/type/common/manifest.d.ts.map +1 -0
  137. package/dist/type/common/package.d.ts +8 -0
  138. package/dist/type/common/package.d.ts.map +1 -0
  139. package/dist/type/common/plugin.d.ts +6 -0
  140. package/dist/type/common/plugin.d.ts.map +1 -0
  141. package/dist/type/common/resolver.d.ts +7 -0
  142. package/dist/type/common/resolver.d.ts.map +1 -0
  143. package/dist/type/common/rspack.d.ts +8 -0
  144. package/dist/type/common/rspack.d.ts.map +1 -0
  145. package/dist/type/common/summary.d.ts +7 -0
  146. package/dist/type/common/summary.d.ts.map +1 -0
  147. package/dist/type/common/time.d.ts +5 -0
  148. package/dist/type/common/time.d.ts.map +1 -0
  149. package/dist/type/common/url.d.ts +4 -0
  150. package/dist/type/common/url.d.ts.map +1 -0
  151. package/dist/type/error/error.d.ts +36 -0
  152. package/dist/type/error/error.d.ts.map +1 -0
  153. package/dist/type/error/index.d.ts +3 -0
  154. package/dist/type/error/index.d.ts.map +1 -0
  155. package/dist/type/error/transform.d.ts +4 -0
  156. package/dist/type/error/transform.d.ts.map +1 -0
  157. package/dist/type/error/utils.d.ts +5 -0
  158. package/dist/type/error/utils.d.ts.map +1 -0
  159. package/dist/type/index.d.ts +3 -0
  160. package/dist/type/index.d.ts.map +1 -0
  161. package/dist/type/logger.d.ts +8 -0
  162. package/dist/type/logger.d.ts.map +1 -0
  163. package/dist/type/rule-utils/document/document.d.ts +17 -0
  164. package/dist/type/rule-utils/document/document.d.ts.map +1 -0
  165. package/dist/type/rule-utils/document/index.d.ts +4 -0
  166. package/dist/type/rule-utils/document/index.d.ts.map +1 -0
  167. package/dist/type/rule-utils/document/server.d.ts +5 -0
  168. package/dist/type/rule-utils/document/server.d.ts.map +1 -0
  169. package/dist/type/rule-utils/document/types.d.ts +32 -0
  170. package/dist/type/rule-utils/document/types.d.ts.map +1 -0
  171. package/dist/type/rule-utils/index.d.ts +3 -0
  172. package/dist/type/rule-utils/index.d.ts.map +1 -0
  173. package/dist/type/rule-utils/parser/asserts.d.ts +82 -0
  174. package/dist/type/rule-utils/parser/asserts.d.ts.map +1 -0
  175. package/dist/type/rule-utils/parser/index.d.ts +5 -0
  176. package/dist/type/rule-utils/parser/index.d.ts.map +1 -0
  177. package/dist/type/rule-utils/parser/parser.d.ts +119 -0
  178. package/dist/type/rule-utils/parser/parser.d.ts.map +1 -0
  179. package/dist/type/rule-utils/parser/types.d.ts +31 -0
  180. package/dist/type/rule-utils/parser/types.d.ts.map +1 -0
  181. package/dist/type/rule-utils/parser/utils.d.ts +31 -0
  182. package/dist/type/rule-utils/parser/utils.d.ts.map +1 -0
  183. package/package.json +111 -0
@@ -0,0 +1,32 @@
1
+ import * as Summary from "./summary";
2
+ import * as Crypto from "./crypto";
3
+ import * as Manifest from "./manifest";
4
+ import * as Loader from "./loader";
5
+ import * as Time from "./time";
6
+ import * as Algorithm from "./algorithm";
7
+ import * as Resolver from "./resolver";
8
+ import * as Graph from "./graph";
9
+ import * as Bundle from "./bundle";
10
+ import * as Url from "./url";
11
+ import * as Plugin from "./plugin";
12
+ import * as Data from "./data";
13
+ import * as Alerts from "./alerts";
14
+ import * as Rspack from "./rspack";
15
+ import * as Package from "./package";
16
+ export {
17
+ Alerts,
18
+ Algorithm,
19
+ Bundle,
20
+ Crypto,
21
+ Data,
22
+ Graph,
23
+ Loader,
24
+ Manifest,
25
+ Package,
26
+ Plugin,
27
+ Resolver,
28
+ Rspack,
29
+ Summary,
30
+ Time,
31
+ Url
32
+ };
@@ -0,0 +1,225 @@
1
+ import { mergeIntervals } from "./algorithm";
2
+ function findLoaderTotalTiming(loaders) {
3
+ let start = Infinity;
4
+ let end = -Infinity;
5
+ for (let i = 0; i < loaders.length; i++) {
6
+ const loader = loaders[i];
7
+ if (loader.startAt <= start) {
8
+ start = loader.startAt;
9
+ }
10
+ if (loader.endAt >= end) {
11
+ end = loader.endAt;
12
+ }
13
+ }
14
+ return {
15
+ start,
16
+ end
17
+ };
18
+ }
19
+ function getLoadersCosts(filter, loaders) {
20
+ const match = {};
21
+ const others = {};
22
+ loaders.forEach((e) => {
23
+ if (filter(e)) {
24
+ if (!match[e.pid])
25
+ match[e.pid] = [];
26
+ match[e.pid].push([e.startAt, e.endAt]);
27
+ } else {
28
+ if (!others[e.pid])
29
+ others[e.pid] = [];
30
+ others[e.pid].push([e.startAt, e.endAt]);
31
+ }
32
+ });
33
+ let costs = 0;
34
+ const pids = Object.keys(match);
35
+ for (let i = 0; i < pids.length; i++) {
36
+ const pid = pids[i];
37
+ const _match = mergeIntervals(match[pid]);
38
+ const _others = mergeIntervals(others[pid] || []).filter(
39
+ ([s, e]) => _match.some((el) => s >= el[0] && e <= el[1])
40
+ );
41
+ const matchSum = _match.length ? _match.reduce((t, c) => t += c[1] - c[0], 0) : 0;
42
+ const othersSum = _others.length ? _others.reduce((t, c) => t += c[1] - c[0], 0) : 0;
43
+ costs += matchSum - othersSum;
44
+ }
45
+ return costs;
46
+ }
47
+ function getLoaderCosts(loader, loaders) {
48
+ const blocked = loaders.filter((e) => {
49
+ if (e !== loader && e.pid === loader.pid) {
50
+ if (e.startAt >= loader.startAt) {
51
+ if (e.endAt <= loader.endAt)
52
+ return true;
53
+ }
54
+ }
55
+ return false;
56
+ });
57
+ let costs = loader.endAt - loader.startAt;
58
+ if (blocked.length) {
59
+ const intervals = blocked.map((e) => [
60
+ Math.max(e.startAt, loader.startAt),
61
+ Math.min(e.endAt, loader.endAt)
62
+ ]);
63
+ mergeIntervals(intervals).forEach((e) => {
64
+ const sub = e[1] - e[0];
65
+ costs -= sub;
66
+ });
67
+ }
68
+ return costs;
69
+ }
70
+ function getLoaderNames(loaders) {
71
+ const names = /* @__PURE__ */ new Set();
72
+ loaders.forEach((e) => e.loaders.forEach((l) => names.add(l.loader)));
73
+ return [...names];
74
+ }
75
+ function getLoadersTransformData(loaders) {
76
+ const res = [];
77
+ for (let i = 0; i < loaders.length; i++) {
78
+ const item = loaders[i];
79
+ for (let j = 0; j < item.loaders.length; j++) {
80
+ const loader = item.loaders[j];
81
+ res.push(loader);
82
+ }
83
+ }
84
+ return res;
85
+ }
86
+ function getLoaderChartData(loaders) {
87
+ const res = [];
88
+ const list = getLoadersTransformData(loaders);
89
+ loaders.forEach((item) => {
90
+ item.loaders.forEach((el) => {
91
+ res.push({
92
+ loader: el.loader,
93
+ isPitch: el.isPitch,
94
+ startAt: el.startAt,
95
+ endAt: el.endAt,
96
+ pid: el.pid,
97
+ sync: el.sync,
98
+ resource: item.resource.path,
99
+ costs: getLoaderCosts(el, list)
100
+ });
101
+ });
102
+ });
103
+ return res;
104
+ }
105
+ function getLoaderFileTree(loaders) {
106
+ const list = getLoadersTransformData(loaders);
107
+ return loaders.map((data) => {
108
+ const { loaders: arr, resource } = data;
109
+ return {
110
+ path: resource.path,
111
+ loaders: arr.map((l) => {
112
+ return {
113
+ loader: l.loader,
114
+ path: l.path,
115
+ errors: l.errors,
116
+ costs: getLoaderCosts(l, list)
117
+ };
118
+ })
119
+ };
120
+ });
121
+ }
122
+ function getLoaderFileDetails(path, loaders) {
123
+ const data = loaders.find((e) => e.resource.path === path);
124
+ if (!data) {
125
+ throw new Error(`"${path}" not match any loader data`);
126
+ }
127
+ const list = getLoadersTransformData(loaders);
128
+ return {
129
+ ...data,
130
+ loaders: data.loaders.map((el) => {
131
+ return {
132
+ ...el,
133
+ costs: getLoaderCosts(el, list)
134
+ };
135
+ })
136
+ };
137
+ }
138
+ function getLoaderFolderStatistics(folder, loaders) {
139
+ const datas = loaders.filter((data) => {
140
+ const { path } = data.resource;
141
+ return path.startsWith(folder);
142
+ });
143
+ const list = getLoadersTransformData(loaders);
144
+ return datas.reduce((t, data) => {
145
+ const { loaders: loaders2 } = data;
146
+ loaders2.forEach((l) => {
147
+ const match = t.find((el) => el.loader === l.loader);
148
+ const costs = getLoaderCosts(l, list);
149
+ if (match) {
150
+ match.files++;
151
+ match.costs += costs;
152
+ } else {
153
+ t.push({
154
+ loader: l.loader,
155
+ path: l.path,
156
+ files: 1,
157
+ costs
158
+ });
159
+ }
160
+ });
161
+ return t;
162
+ }, []);
163
+ }
164
+ function getLoaderFileFirstInput(file, loaders) {
165
+ for (let i = 0; i < loaders.length; i++) {
166
+ const item = loaders[i];
167
+ if (item.resource.path === file) {
168
+ const nonPitchLoaders = item.loaders.filter((e) => !e.isPitch);
169
+ if (!nonPitchLoaders.length)
170
+ return "";
171
+ return nonPitchLoaders[0].input || "";
172
+ }
173
+ }
174
+ return "";
175
+ }
176
+ function getLoaderFileInputAndOutput(file, loader, loaderIndex, loaders) {
177
+ for (let i = 0; i < loaders.length; i++) {
178
+ const item = loaders[i];
179
+ if (item.resource.path === file) {
180
+ for (let j = 0; j < item.loaders.length; j++) {
181
+ const l = item.loaders[j];
182
+ if (l.loader === loader && l.loaderIndex === loaderIndex) {
183
+ return {
184
+ input: l.input || "",
185
+ output: l.result || ""
186
+ };
187
+ }
188
+ return {
189
+ input: "",
190
+ output: ""
191
+ };
192
+ }
193
+ }
194
+ }
195
+ return {
196
+ input: "",
197
+ output: ""
198
+ };
199
+ }
200
+ const LoaderInternalPropertyName = "__l__";
201
+ const isVue = (compiler) => {
202
+ const rules = compiler.options.module.rules;
203
+ const hasVueRule = rules.some((rule) => {
204
+ if (rule && typeof rule === "object" && rule.test instanceof RegExp && rule.test?.test(".vue")) {
205
+ return true;
206
+ }
207
+ return false;
208
+ });
209
+ return hasVueRule;
210
+ };
211
+ export {
212
+ LoaderInternalPropertyName,
213
+ findLoaderTotalTiming,
214
+ getLoaderChartData,
215
+ getLoaderCosts,
216
+ getLoaderFileDetails,
217
+ getLoaderFileFirstInput,
218
+ getLoaderFileInputAndOutput,
219
+ getLoaderFileTree,
220
+ getLoaderFolderStatistics,
221
+ getLoaderNames,
222
+ getLoadersCosts,
223
+ getLoadersTransformData,
224
+ isVue
225
+ };
@@ -0,0 +1,46 @@
1
+ import { decompressText } from "./algorithm";
2
+ import { isRemoteUrl } from "./url";
3
+ function isShardingData(data) {
4
+ if (Array.isArray(data) && data.length > 0) {
5
+ if (data.every((e) => isRemoteUrl(e))) {
6
+ return true;
7
+ }
8
+ }
9
+ return false;
10
+ }
11
+ async function fetchShardingData(shardingFiles, fetchImplement) {
12
+ const res = await Promise.all(
13
+ shardingFiles.map((url) => fetchImplement(url))
14
+ );
15
+ const strings = res.length === 0 ? [] : res.reduce((t, e) => t + e);
16
+ return typeof strings === "object" ? strings : JSON.parse(decompressText(strings));
17
+ }
18
+ async function fetchShardingFiles(data, fetchImplement, filterKeys) {
19
+ const datas = await Promise.all(
20
+ Object.keys(data).map(async (_key) => {
21
+ const key = _key;
22
+ const val = data[key];
23
+ if (filterKeys?.length && filterKeys.indexOf(key) < 0) {
24
+ return {
25
+ [key]: []
26
+ };
27
+ }
28
+ if (isShardingData(val)) {
29
+ return {
30
+ [key]: await fetchShardingData(val, fetchImplement)
31
+ };
32
+ }
33
+ return {
34
+ [key]: val
35
+ };
36
+ })
37
+ );
38
+ return datas.reduce(
39
+ (t, c) => Object.assign(t, c)
40
+ );
41
+ }
42
+ export {
43
+ fetchShardingData,
44
+ fetchShardingFiles,
45
+ isShardingData
46
+ };
@@ -0,0 +1,71 @@
1
+ import { isEmpty, last, compact } from "lodash";
2
+ const PACKAGE_PREFIX = /(?:node_modules|~)(?:\/\.pnpm)?/;
3
+ const PACKAGE_SLUG = /[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*/;
4
+ const VERSION = /@[\w|\-|_|.]+/;
5
+ const VERSION_NUMBER = "@([\\d.]+)";
6
+ const MODULE_PATH_PACKAGES = new RegExp(
7
+ [
8
+ // match dependency directory (eg: `node_modules/`, `node_modules/.pnpm/`)
9
+ `(?:${PACKAGE_PREFIX.source}/)`,
10
+ // match package name
11
+ "(?:",
12
+ // match `@organization/` or `@organization+`(pnpm)
13
+ `(?:@${PACKAGE_SLUG.source}[/|+])?`,
14
+ // match github.com+organization+
15
+ `(?:${PACKAGE_SLUG.source}\\+)*`,
16
+ // match package name
17
+ `(?:${PACKAGE_SLUG.source})`,
18
+ // match version
19
+ `(?:${VERSION.source})?`,
20
+ ")",
21
+ // Match pnpm peer dependencies (eg: package-a@version_package-b@version)
22
+ "(?:_",
23
+ `(?:@${PACKAGE_SLUG.source}[/|+])?`,
24
+ `(?:${PACKAGE_SLUG.source})`,
25
+ `(?:@${PACKAGE_SLUG.source})?`,
26
+ ")*",
27
+ "/"
28
+ ].join(""),
29
+ "g"
30
+ );
31
+ const PACKAGE_PATH_NAME = /(?:(?:node_modules|~)(?:\/\.pnpm)?\/)(?:((?:@[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*[/|+])?(?:(?:[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*\+)*)(?:[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*))(?:@[\w|\-|_|.]+)?)(?:_((?:@[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*[/|+])?(?:[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*))(?:@[a-zA-Z0-9]+(?:[-|_|.]+[a-zA-Z0-9]+)*))*\//gm;
32
+ const uniqLast = (data) => {
33
+ const res = [];
34
+ data.forEach((item, index) => {
35
+ if (!data.slice(index + 1).includes(item)) {
36
+ res.push(item);
37
+ }
38
+ });
39
+ return res;
40
+ };
41
+ const getPackageMetaFromModulePath = (modulePath) => {
42
+ const paths = modulePath.match(MODULE_PATH_PACKAGES);
43
+ if (!paths) {
44
+ return { name: "", version: "" };
45
+ }
46
+ const names = uniqLast(
47
+ paths.flatMap((packagePath) => {
48
+ const found = packagePath.matchAll(PACKAGE_PATH_NAME);
49
+ if (!found) {
50
+ return [];
51
+ }
52
+ const paksArray = compact([...found].flat());
53
+ return paksArray.slice(1).filter(Boolean).map((name2) => name2.replace(/\+/g, "/"));
54
+ })
55
+ );
56
+ if (isEmpty(names)) {
57
+ return { name: "", version: "" };
58
+ }
59
+ const name = last(names);
60
+ const pattern = new RegExp(`(.*)(${last(paths)}).*`);
61
+ const path = modulePath.replace(pattern, "$1$2").replace(/\/$/, "");
62
+ return {
63
+ name,
64
+ version: path && name ? path.match(new RegExp(`${name}${VERSION_NUMBER}`))?.flat().slice(1)?.[0] || "" : ""
65
+ };
66
+ };
67
+ export {
68
+ MODULE_PATH_PACKAGES,
69
+ PACKAGE_PATH_NAME,
70
+ getPackageMetaFromModulePath
71
+ };
@@ -0,0 +1,59 @@
1
+ function getPluginHooks(plugin) {
2
+ return Object.keys(plugin);
3
+ }
4
+ function getPluginTapNames(plugin) {
5
+ const hooks = getPluginHooks(plugin);
6
+ const tapNames = /* @__PURE__ */ new Set();
7
+ hooks.forEach((hook) => {
8
+ plugin[hook].forEach((data) => {
9
+ tapNames.add(data.tapName);
10
+ });
11
+ });
12
+ return [...tapNames];
13
+ }
14
+ function getPluginSummary(plugin) {
15
+ return {
16
+ hooks: getPluginHooks(plugin),
17
+ tapNames: getPluginTapNames(plugin)
18
+ };
19
+ }
20
+ function getPluginData(plugin, selectedHooks = [], selectedTapNames = []) {
21
+ const hooks = getPluginHooks(plugin).filter((hook) => {
22
+ if (selectedHooks.length && selectedHooks.indexOf(hook) === -1) {
23
+ return false;
24
+ }
25
+ return true;
26
+ });
27
+ if (!hooks.length)
28
+ return [];
29
+ const tapNames = getPluginTapNames(plugin);
30
+ return tapNames.reduce((total, tapName) => {
31
+ if (selectedTapNames.length && selectedTapNames.indexOf(tapName) === -1) {
32
+ return total;
33
+ }
34
+ hooks.forEach((hook) => {
35
+ const hookData = plugin[hook].filter((e) => e.tapName === tapName);
36
+ if (hookData.length === 0)
37
+ return;
38
+ total.push({
39
+ tapName,
40
+ hook,
41
+ data: hookData.map((e) => {
42
+ return {
43
+ startAt: e.startAt,
44
+ endAt: e.endAt,
45
+ costs: e.costs,
46
+ type: e.type
47
+ };
48
+ })
49
+ });
50
+ });
51
+ return total;
52
+ }, []);
53
+ }
54
+ export {
55
+ getPluginData,
56
+ getPluginHooks,
57
+ getPluginSummary,
58
+ getPluginTapNames
59
+ };
@@ -0,0 +1,54 @@
1
+ import { mergeIntervals } from "./algorithm";
2
+ function isResolveSuccessData(data) {
3
+ return Boolean(data.result);
4
+ }
5
+ function isResolveFailData(data) {
6
+ return Boolean(data.error);
7
+ }
8
+ function getResolverCosts(resolver, resolvers) {
9
+ const blocked = resolvers.filter(
10
+ (e) => e !== resolver && e.pid === resolver.pid && e.startAt >= resolver.startAt && e.endAt <= resolver.endAt
11
+ );
12
+ let costs = resolver.endAt - resolver.startAt;
13
+ if (blocked.length) {
14
+ const intervals = blocked.map((e) => [
15
+ Math.max(e.startAt, resolver.startAt),
16
+ Math.min(e.endAt, resolver.endAt)
17
+ ]);
18
+ mergeIntervals(intervals).forEach((e) => {
19
+ const sub = e[1] - e[0];
20
+ costs -= sub;
21
+ });
22
+ }
23
+ return costs;
24
+ }
25
+ function getResolverFileTree(resolver) {
26
+ return resolver.map((e) => ({ issuerPath: e.issuerPath }));
27
+ }
28
+ function getResolverFileDetails(filepath, resolvers, modules, moduleCodeMap) {
29
+ const module = modules.find((item) => item.path === filepath);
30
+ const matchResolvers = resolvers.filter((e) => e.issuerPath === filepath);
31
+ const before = module && moduleCodeMap && moduleCodeMap[module.id] ? moduleCodeMap[module.id].source : "";
32
+ const after = matchResolvers.reduce((t, c) => {
33
+ if (c.request && isResolveSuccessData(c)) {
34
+ return t.replace(new RegExp(`["']${c.request}["']`), `"${c.result}"`);
35
+ }
36
+ return t;
37
+ }, before);
38
+ return {
39
+ filepath,
40
+ before,
41
+ after,
42
+ resolvers: matchResolvers.map((e) => ({
43
+ ...e,
44
+ costs: getResolverCosts(e, resolvers)
45
+ }))
46
+ };
47
+ }
48
+ export {
49
+ getResolverCosts,
50
+ getResolverFileDetails,
51
+ getResolverFileTree,
52
+ isResolveFailData,
53
+ isResolveSuccessData
54
+ };
@@ -0,0 +1,12 @@
1
+ const RspackLoaderInternalPropertyName = "__l__";
2
+ var RspackSummaryCostsDataName = /* @__PURE__ */ ((RspackSummaryCostsDataName2) => {
3
+ RspackSummaryCostsDataName2["Bootstrap"] = "bootstrap->rspack:beforeCompile";
4
+ RspackSummaryCostsDataName2["Compile"] = "rspack:beforeCompile->afterCompile";
5
+ RspackSummaryCostsDataName2["Done"] = "rspack:afterCompile->done";
6
+ RspackSummaryCostsDataName2["Minify"] = "rspack:minify(rspack:optimizeChunkAssets)";
7
+ return RspackSummaryCostsDataName2;
8
+ })(RspackSummaryCostsDataName || {});
9
+ export {
10
+ RspackLoaderInternalPropertyName,
11
+ RspackSummaryCostsDataName
12
+ };
@@ -0,0 +1,10 @@
1
+ var SummaryCostsDataName = /* @__PURE__ */ ((SummaryCostsDataName2) => {
2
+ SummaryCostsDataName2["Bootstrap"] = "bootstrap->beforeCompile";
3
+ SummaryCostsDataName2["Compile"] = "beforeCompile->afterCompile";
4
+ SummaryCostsDataName2["Done"] = "afterCompile->done";
5
+ SummaryCostsDataName2["Minify"] = "minify(webpack4:optimizeChunkAssets|webpack5:processAssets|rspack:processAssets)";
6
+ return SummaryCostsDataName2;
7
+ })(SummaryCostsDataName || {});
8
+ export {
9
+ SummaryCostsDataName
10
+ };
@@ -0,0 +1,64 @@
1
+ import { hrtime } from "process";
2
+ function toFixedDigits(num, digits = 2) {
3
+ if (digits === 0) {
4
+ return Math.floor(num);
5
+ }
6
+ return +num.toFixed(digits);
7
+ }
8
+ function getUnit(num, type) {
9
+ let unit;
10
+ if (type === "m") {
11
+ unit = num > 1 ? "mins" : "min";
12
+ } else {
13
+ unit = num > 1 ? "hours" : "hour";
14
+ }
15
+ return unit;
16
+ }
17
+ function formatCosts(costs) {
18
+ costs = Number(costs);
19
+ if (costs >= 1e3) {
20
+ const sec = costs / 1e3;
21
+ if (sec >= 60) {
22
+ let mins = sec / 60;
23
+ if (mins >= 60) {
24
+ const hours = toFixedDigits(mins / 60, 0);
25
+ const restMins = toFixedDigits(mins % 60, 1);
26
+ const hUnit = getUnit(hours, "h");
27
+ if (restMins > 0) {
28
+ return `${hours}${hUnit} ${restMins}${getUnit(restMins, "m")}`;
29
+ }
30
+ return `${hours}${hUnit}`;
31
+ }
32
+ mins = toFixedDigits(mins, 0);
33
+ const mUnit = getUnit(mins, "m");
34
+ const restSec = toFixedDigits(sec % 60, 0);
35
+ if (restSec > 0) {
36
+ return `${mins}${mUnit} ${restSec}s`;
37
+ }
38
+ return `${mins}${mUnit}`;
39
+ }
40
+ return `${toFixedDigits(sec, 1)}s`;
41
+ }
42
+ if (costs >= 10) {
43
+ return `${+toFixedDigits(costs, 0)}ms`;
44
+ }
45
+ if (costs >= 1) {
46
+ return `${+toFixedDigits(costs, 1)}ms`;
47
+ }
48
+ let r = +toFixedDigits(costs, 2);
49
+ if (r === 0) {
50
+ r = +toFixedDigits(costs, 3);
51
+ }
52
+ return `${r}ms`;
53
+ }
54
+ function getCurrentTimestamp(start, startHRTime) {
55
+ const endHRTime = hrtime(startHRTime);
56
+ const end = start + endHRTime[0] * 1e3 + (process.env.VITEST ? Math.round(endHRTime[1] / 1e6) : endHRTime[1] / 1e6);
57
+ return end;
58
+ }
59
+ export {
60
+ formatCosts,
61
+ getCurrentTimestamp,
62
+ getUnit,
63
+ toFixedDigits
64
+ };
@@ -0,0 +1,20 @@
1
+ import { isAbsolute } from "path";
2
+ function isUrl(uri) {
3
+ return /^https?:\/\//.test(uri);
4
+ }
5
+ function isFilePath(uri) {
6
+ return isAbsolute(uri);
7
+ }
8
+ function isRemoteUrl(uri) {
9
+ if (typeof uri === "string") {
10
+ if (isUrl(uri) || isFilePath(uri)) {
11
+ return true;
12
+ }
13
+ }
14
+ return false;
15
+ }
16
+ export {
17
+ isFilePath,
18
+ isRemoteUrl,
19
+ isUrl
20
+ };