@rsdoctor/core 1.5.11 → 2.0.0-alpha.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 (81) hide show
  1. package/dist/build-utils/build/module-graph/index.cjs +4 -18
  2. package/dist/build-utils/build/module-graph/index.d.cts +0 -2
  3. package/dist/build-utils/build/module-graph/index.d.ts +0 -2
  4. package/dist/build-utils/build/module-graph/index.js +0 -2
  5. package/dist/build-utils/build/module-graph/rspack/transform.cjs +1 -1
  6. package/dist/build-utils/build/module-graph/rspack/transform.js +1 -1
  7. package/dist/build-utils/build/module-graph/transform.cjs +2 -3
  8. package/dist/build-utils/build/module-graph/transform.d.cts +1 -2
  9. package/dist/build-utils/build/module-graph/transform.d.ts +1 -2
  10. package/dist/build-utils/build/module-graph/transform.js +2 -3
  11. package/dist/build-utils/build/utils/parseBundle.cjs +1 -1
  12. package/dist/build-utils/build/utils/parseBundle.js +1 -1
  13. package/dist/build-utils/build/utils/plugin.cjs +1 -2
  14. package/dist/build-utils/build/utils/plugin.js +1 -2
  15. package/dist/inner-plugins/constants.cjs +1 -1
  16. package/dist/inner-plugins/constants.d.cts +1 -1
  17. package/dist/inner-plugins/constants.d.ts +1 -1
  18. package/dist/inner-plugins/constants.js +1 -1
  19. package/dist/inner-plugins/plugins/bundle.cjs +1 -17
  20. package/dist/inner-plugins/plugins/bundle.js +1 -17
  21. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.cjs +3 -40
  22. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.cts +4 -6
  23. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.ts +4 -6
  24. package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +4 -41
  25. package/dist/inner-plugins/plugins/errors.cjs +3 -3
  26. package/dist/inner-plugins/plugins/errors.d.cts +1 -1
  27. package/dist/inner-plugins/plugins/errors.d.ts +1 -1
  28. package/dist/inner-plugins/plugins/errors.js +3 -3
  29. package/dist/inner-plugins/plugins/index.cjs +2 -9
  30. package/dist/inner-plugins/plugins/index.d.cts +0 -1
  31. package/dist/inner-plugins/plugins/index.d.ts +0 -1
  32. package/dist/inner-plugins/plugins/index.js +0 -1
  33. package/dist/inner-plugins/plugins/loader.cjs +1 -1
  34. package/dist/inner-plugins/plugins/loader.js +1 -1
  35. package/dist/inner-plugins/plugins/plugins.cjs +1 -1
  36. package/dist/inner-plugins/plugins/plugins.js +1 -1
  37. package/dist/inner-plugins/plugins/progress.cjs +14 -16
  38. package/dist/inner-plugins/plugins/progress.d.cts +1 -1
  39. package/dist/inner-plugins/plugins/progress.d.ts +1 -1
  40. package/dist/inner-plugins/plugins/progress.js +14 -16
  41. package/dist/inner-plugins/plugins/resolver.d.cts +1 -2
  42. package/dist/inner-plugins/plugins/resolver.d.ts +1 -2
  43. package/dist/inner-plugins/plugins/rules.cjs +3 -3
  44. package/dist/inner-plugins/plugins/rules.js +3 -3
  45. package/dist/inner-plugins/utils/config.cjs +0 -1
  46. package/dist/inner-plugins/utils/config.d.cts +1 -1
  47. package/dist/inner-plugins/utils/config.d.ts +1 -1
  48. package/dist/inner-plugins/utils/config.js +0 -1
  49. package/dist/inner-plugins/utils/loader.cjs +2 -2
  50. package/dist/inner-plugins/utils/loader.js +2 -2
  51. package/dist/inner-plugins/utils/normalize-config.d.cts +3 -6
  52. package/dist/inner-plugins/utils/normalize-config.d.ts +3 -6
  53. package/dist/rules/rules/cjs-require/index.cjs +2 -2
  54. package/dist/rules/rules/cjs-require/index.js +2 -2
  55. package/dist/rules/rules/esm-resolved-to-cjs/index.cjs +91 -26
  56. package/dist/rules/rules/esm-resolved-to-cjs/index.js +91 -26
  57. package/dist/rules/rules/index.d.cts +2 -1
  58. package/dist/rules/rules/index.d.ts +2 -1
  59. package/dist/rules/rules/loader-performance-optimization/index.cjs +1 -1
  60. package/dist/rules/rules/loader-performance-optimization/index.js +1 -1
  61. package/dist/rules/rules/module-mixed-chunks/index.cjs +1 -1
  62. package/dist/rules/rules/module-mixed-chunks/index.js +1 -1
  63. package/dist/rules/rules/side-effects-only-imports/index.cjs +1 -1
  64. package/dist/rules/rules/side-effects-only-imports/index.js +1 -1
  65. package/dist/types/plugin.d.cts +2 -2
  66. package/dist/types/plugin.d.ts +2 -2
  67. package/dist/types/rules.d.cts +4 -4
  68. package/dist/types/rules.d.ts +4 -4
  69. package/package.json +9 -10
  70. package/dist/build-utils/build/module-graph/treeShaking.cjs +0 -106
  71. package/dist/build-utils/build/module-graph/treeShaking.d.cts +0 -2
  72. package/dist/build-utils/build/module-graph/treeShaking.d.ts +0 -2
  73. package/dist/build-utils/build/module-graph/treeShaking.js +0 -73
  74. package/dist/build-utils/build/module-graph/webpack/transform.cjs +0 -170
  75. package/dist/build-utils/build/module-graph/webpack/transform.d.cts +0 -16
  76. package/dist/build-utils/build/module-graph/webpack/transform.d.ts +0 -16
  77. package/dist/build-utils/build/module-graph/webpack/transform.js +0 -124
  78. package/dist/inner-plugins/plugins/bundleTagPlugin.cjs +0 -84
  79. package/dist/inner-plugins/plugins/bundleTagPlugin.d.cts +0 -6
  80. package/dist/inner-plugins/plugins/bundleTagPlugin.d.ts +0 -6
  81. package/dist/inner-plugins/plugins/bundleTagPlugin.js +0 -51
@@ -1,170 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.n = (module)=>{
5
- var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
- __webpack_require__.d(getter, {
7
- a: getter
8
- });
9
- return getter;
10
- };
11
- })();
12
- (()=>{
13
- __webpack_require__.d = (exports1, definition)=>{
14
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
- enumerable: true,
16
- get: definition[key]
17
- });
18
- };
19
- })();
20
- (()=>{
21
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
- })();
23
- (()=>{
24
- __webpack_require__.r = (exports1)=>{
25
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
- value: 'Module'
27
- });
28
- Object.defineProperty(exports1, '__esModule', {
29
- value: true
30
- });
31
- };
32
- })();
33
- var __webpack_exports__ = {};
34
- __webpack_require__.r(__webpack_exports__);
35
- __webpack_require__.d(__webpack_exports__, {
36
- appendModuleGraphByCompilation: ()=>appendModuleGraphByCompilation,
37
- getModuleExportsType: ()=>getModuleExportsType
38
- });
39
- const external_node_fs_namespaceObject = require("node:fs");
40
- var external_node_fs_default = /*#__PURE__*/ __webpack_require__.n(external_node_fs_namespaceObject);
41
- const graph_namespaceObject = require("@rsdoctor/graph");
42
- const external_parser_cjs_namespaceObject = require("../parser.cjs");
43
- const compat_namespaceObject = require("es-toolkit/compat");
44
- const logger_namespaceObject = require("@rsdoctor/utils/logger");
45
- async function readFile(target, wbFs) {
46
- if (wbFs?.fs?.readFile) {
47
- const result = new Promise((resolve, reject)=>{
48
- wbFs.fs.readFile(target, (err, content)=>{
49
- if (err) return void reject(err);
50
- content ? resolve(Buffer.from(content)) : resolve();
51
- });
52
- }).catch(()=>{});
53
- if (result) return result;
54
- }
55
- try {
56
- return await external_node_fs_default().promises.readFile(target);
57
- } catch {
58
- logger_namespaceObject.logger.debug(`readFile error: ${target}`);
59
- return;
60
- }
61
- }
62
- function getModuleExportsType(module, moduleGraph, strict = false) {
63
- if (moduleGraph && 'getExportsType' in module) return module.getExportsType(moduleGraph, strict);
64
- return strict ? 'default-with-named' : 'dynamic';
65
- }
66
- function appendDependency(webpackDep, module, webpackGraph, graph) {
67
- const resolvedWebpackModule = webpackGraph?.getResolvedModule ? webpackGraph.getResolvedModule(webpackDep) : void 0;
68
- if (!resolvedWebpackModule) return;
69
- const rawRequest = graph_namespaceObject.Webpack.getWebpackDependencyRequest(webpackDep, resolvedWebpackModule);
70
- const resolveRequest = graph_namespaceObject.Webpack.getWebpackModulePath(resolvedWebpackModule);
71
- const request = rawRequest ?? resolveRequest;
72
- if (!module.getDependencyByRequest(request)) {
73
- const depLayer = resolvedWebpackModule.layer || void 0;
74
- const depModule = graph.getModuleByFile(resolveRequest, depLayer)[0];
75
- if (depModule) {
76
- const dep = module.addDependency(request, depModule, graph_namespaceObject.ModuleGraphTrans.getImportKind(webpackDep));
77
- if (dep) graph.addDependency(dep);
78
- }
79
- }
80
- const dependency = module.getDependencyByRequest(request);
81
- if (dependency) {
82
- dependency.setBuildMeta({
83
- exportsType: getModuleExportsType(resolvedWebpackModule, webpackGraph, module.meta.strictHarmonyModule)
84
- });
85
- const statement = graph_namespaceObject.Webpack.getDependencyPosition(webpackDep, module, false);
86
- if (statement) dependency.addStatement(statement);
87
- dependency.statements.forEach((state)=>{
88
- state.position.source = state.module.getSourceRange(state.position.transformed);
89
- });
90
- }
91
- }
92
- function getModuleSource(modulePath, wbFs, sourceMap) {
93
- if (sourceMap) try {
94
- const contentFromSourceMap = sourceMap.sourceContentFor(modulePath);
95
- if (contentFromSourceMap) return Buffer.from(contentFromSourceMap);
96
- } catch (e) {
97
- logger_namespaceObject.logger.debug(`getModuleSource error: ${e}`);
98
- }
99
- return readFile(modulePath, wbFs);
100
- }
101
- async function appendModuleData(origin, webpackGraph, graph, wbFs, features, context) {
102
- const module = graph.getModuleByWebpackId(graph_namespaceObject.Webpack.getWebpackModuleId(origin));
103
- if (!origin || !module) return;
104
- const { getSourceMap, astCache, packagePathMap } = context ?? {};
105
- try {
106
- const sourceMap = await getSourceMap?.(module.path);
107
- const source = await getModuleSource(module.path, wbFs, sourceMap) ?? Buffer.from('');
108
- if (sourceMap) module.setSourceMap(sourceMap);
109
- if (astCache?.has(origin)) {
110
- const program = astCache.get(origin);
111
- module.setProgram(program);
112
- module.meta.hasSetEsModuleStatement = (0, external_parser_cjs_namespaceObject.hasSetEsModuleStatement)(program);
113
- }
114
- const transformed = graph_namespaceObject.Webpack.isExternalModule(origin) ? '' : module.getSource().transformed.length > 0 ? module.getSource().transformed : (0, compat_namespaceObject.isFunction)(origin?.originalSource) ? origin.originalSource()?.source()?.toString() ?? '' : '';
115
- const transformedSize = graph_namespaceObject.Webpack.isExternalModule(origin) ? 0 : module.getSize().transformedSize > 0 ? module.getSize().transformedSize : Buffer.from(transformed).byteLength;
116
- module.setSource({
117
- transformed,
118
- source: source.toString()
119
- });
120
- module.setSize({
121
- transformedSize,
122
- sourceSize: source.byteLength
123
- });
124
- let packageData;
125
- if (packagePathMap && origin.resourceResolveData) {
126
- let { descriptionFileRoot: root } = origin.resourceResolveData;
127
- const { descriptionFileData: data } = origin.resourceResolveData;
128
- if (root && data && data.name && data.version) {
129
- if (packagePathMap.has(root)) root = packagePathMap.get(root);
130
- else {
131
- const realpath = await external_node_fs_default().promises.realpath(root, {
132
- encoding: 'utf-8'
133
- });
134
- root = realpath;
135
- packagePathMap.set(root, realpath);
136
- }
137
- packageData = {
138
- ...origin.resourceResolveData.descriptionFileData,
139
- root
140
- };
141
- }
142
- }
143
- module.meta.strictHarmonyModule = origin.buildMeta?.strictHarmonyModule ?? false;
144
- module.meta.packageData = packageData;
145
- if (!features?.lite && origin?.dependencies) Array.from(origin.dependencies).filter((item)=>graph_namespaceObject.ModuleGraphTrans.isImportDependency(item)).concat(origin.blocks.reduce((ans, item)=>ans.concat(item.dependencies), [])).forEach((dep)=>appendDependency(dep, module, webpackGraph, graph));
146
- } catch (e) {
147
- console.error(`module ${module.path} transform has error:`, e);
148
- }
149
- }
150
- async function appendModuleGraphByCompilation(compilation, graph, features, context) {
151
- try {
152
- const webpackCompilation = compilation;
153
- const { moduleGraph: webpackGraph, fileSystemInfo } = webpackCompilation;
154
- const allModules = graph_namespaceObject.Webpack.getAllModules(webpackCompilation);
155
- await Promise.all(allModules.map((module)=>appendModuleData(module, webpackGraph, graph, fileSystemInfo, features, context)));
156
- graph_namespaceObject.ModuleGraphTrans.removeNoImportStyle(graph);
157
- return graph;
158
- } catch {
159
- return graph;
160
- }
161
- }
162
- exports.appendModuleGraphByCompilation = __webpack_exports__.appendModuleGraphByCompilation;
163
- exports.getModuleExportsType = __webpack_exports__.getModuleExportsType;
164
- for(var __rspack_i in __webpack_exports__)if (-1 === [
165
- "appendModuleGraphByCompilation",
166
- "getModuleExportsType"
167
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
168
- Object.defineProperty(exports, '__esModule', {
169
- value: true
170
- });
@@ -1,16 +0,0 @@
1
- import type { SourceMapConsumer } from 'source-map';
2
- import * as Webpack from 'webpack';
3
- import * as Rspack from '@rspack/core';
4
- import { Node } from '@rsdoctor/utils/ruleUtils';
5
- import { Plugin, SDK } from '@rsdoctor/types';
6
- export interface TransformContext {
7
- astCache?: Map<Webpack.NormalModule, Node.Program>;
8
- packagePathMap?: Map<string, string>;
9
- getSourceMap?(module: string): Promise<SourceMapConsumer | undefined>;
10
- }
11
- /**
12
- * Get the type of dependencies between modules.
13
- * This property can determine what runtime webpack has added to the modules.
14
- */
15
- export declare function getModuleExportsType(module: Webpack.NormalModule | Rspack.NormalModule, moduleGraph?: Webpack.ModuleGraph, strict?: boolean): SDK.DependencyBuildMeta['exportsType'];
16
- export declare function appendModuleGraphByCompilation(compilation: Plugin.BaseCompilation, graph: SDK.ModuleGraphInstance, features?: Plugin.RsdoctorWebpackPluginFeatures, context?: TransformContext): Promise<SDK.ModuleGraphInstance>;
@@ -1,16 +0,0 @@
1
- import type { SourceMapConsumer } from 'source-map';
2
- import * as Webpack from 'webpack';
3
- import * as Rspack from '@rspack/core';
4
- import { Node } from '@rsdoctor/utils/ruleUtils';
5
- import { Plugin, SDK } from '@rsdoctor/types';
6
- export interface TransformContext {
7
- astCache?: Map<Webpack.NormalModule, Node.Program>;
8
- packagePathMap?: Map<string, string>;
9
- getSourceMap?(module: string): Promise<SourceMapConsumer | undefined>;
10
- }
11
- /**
12
- * Get the type of dependencies between modules.
13
- * This property can determine what runtime webpack has added to the modules.
14
- */
15
- export declare function getModuleExportsType(module: Webpack.NormalModule | Rspack.NormalModule, moduleGraph?: Webpack.ModuleGraph, strict?: boolean): SDK.DependencyBuildMeta['exportsType'];
16
- export declare function appendModuleGraphByCompilation(compilation: Plugin.BaseCompilation, graph: SDK.ModuleGraphInstance, features?: Plugin.RsdoctorWebpackPluginFeatures, context?: TransformContext): Promise<SDK.ModuleGraphInstance>;
@@ -1,124 +0,0 @@
1
- import "node:module";
2
- import node_fs from "node:fs";
3
- import { ModuleGraphTrans, Webpack } from "@rsdoctor/graph";
4
- import { hasSetEsModuleStatement } from "../parser.js";
5
- import { isFunction } from "es-toolkit/compat";
6
- import { logger } from "@rsdoctor/utils/logger";
7
- async function readFile(target, wbFs) {
8
- if (wbFs?.fs?.readFile) {
9
- const result = new Promise((resolve, reject)=>{
10
- wbFs.fs.readFile(target, (err, content)=>{
11
- if (err) return void reject(err);
12
- content ? resolve(Buffer.from(content)) : resolve();
13
- });
14
- }).catch(()=>{});
15
- if (result) return result;
16
- }
17
- try {
18
- return await node_fs.promises.readFile(target);
19
- } catch {
20
- logger.debug(`readFile error: ${target}`);
21
- return;
22
- }
23
- }
24
- function getModuleExportsType(module, moduleGraph, strict = false) {
25
- if (moduleGraph && 'getExportsType' in module) return module.getExportsType(moduleGraph, strict);
26
- return strict ? 'default-with-named' : 'dynamic';
27
- }
28
- function appendDependency(webpackDep, module, webpackGraph, graph) {
29
- const resolvedWebpackModule = webpackGraph?.getResolvedModule ? webpackGraph.getResolvedModule(webpackDep) : void 0;
30
- if (!resolvedWebpackModule) return;
31
- const rawRequest = Webpack.getWebpackDependencyRequest(webpackDep, resolvedWebpackModule);
32
- const resolveRequest = Webpack.getWebpackModulePath(resolvedWebpackModule);
33
- const request = rawRequest ?? resolveRequest;
34
- if (!module.getDependencyByRequest(request)) {
35
- const depLayer = resolvedWebpackModule.layer || void 0;
36
- const depModule = graph.getModuleByFile(resolveRequest, depLayer)[0];
37
- if (depModule) {
38
- const dep = module.addDependency(request, depModule, ModuleGraphTrans.getImportKind(webpackDep));
39
- if (dep) graph.addDependency(dep);
40
- }
41
- }
42
- const dependency = module.getDependencyByRequest(request);
43
- if (dependency) {
44
- dependency.setBuildMeta({
45
- exportsType: getModuleExportsType(resolvedWebpackModule, webpackGraph, module.meta.strictHarmonyModule)
46
- });
47
- const statement = Webpack.getDependencyPosition(webpackDep, module, false);
48
- if (statement) dependency.addStatement(statement);
49
- dependency.statements.forEach((state)=>{
50
- state.position.source = state.module.getSourceRange(state.position.transformed);
51
- });
52
- }
53
- }
54
- function getModuleSource(modulePath, wbFs, sourceMap) {
55
- if (sourceMap) try {
56
- const contentFromSourceMap = sourceMap.sourceContentFor(modulePath);
57
- if (contentFromSourceMap) return Buffer.from(contentFromSourceMap);
58
- } catch (e) {
59
- logger.debug(`getModuleSource error: ${e}`);
60
- }
61
- return readFile(modulePath, wbFs);
62
- }
63
- async function appendModuleData(origin, webpackGraph, graph, wbFs, features, context) {
64
- const module = graph.getModuleByWebpackId(Webpack.getWebpackModuleId(origin));
65
- if (!origin || !module) return;
66
- const { getSourceMap, astCache, packagePathMap } = context ?? {};
67
- try {
68
- const sourceMap = await getSourceMap?.(module.path);
69
- const source = await getModuleSource(module.path, wbFs, sourceMap) ?? Buffer.from('');
70
- if (sourceMap) module.setSourceMap(sourceMap);
71
- if (astCache?.has(origin)) {
72
- const program = astCache.get(origin);
73
- module.setProgram(program);
74
- module.meta.hasSetEsModuleStatement = hasSetEsModuleStatement(program);
75
- }
76
- const transformed = Webpack.isExternalModule(origin) ? '' : module.getSource().transformed.length > 0 ? module.getSource().transformed : isFunction(origin?.originalSource) ? origin.originalSource()?.source()?.toString() ?? '' : '';
77
- const transformedSize = Webpack.isExternalModule(origin) ? 0 : module.getSize().transformedSize > 0 ? module.getSize().transformedSize : Buffer.from(transformed).byteLength;
78
- module.setSource({
79
- transformed,
80
- source: source.toString()
81
- });
82
- module.setSize({
83
- transformedSize,
84
- sourceSize: source.byteLength
85
- });
86
- let packageData;
87
- if (packagePathMap && origin.resourceResolveData) {
88
- let { descriptionFileRoot: root } = origin.resourceResolveData;
89
- const { descriptionFileData: data } = origin.resourceResolveData;
90
- if (root && data && data.name && data.version) {
91
- if (packagePathMap.has(root)) root = packagePathMap.get(root);
92
- else {
93
- const realpath = await node_fs.promises.realpath(root, {
94
- encoding: 'utf-8'
95
- });
96
- root = realpath;
97
- packagePathMap.set(root, realpath);
98
- }
99
- packageData = {
100
- ...origin.resourceResolveData.descriptionFileData,
101
- root
102
- };
103
- }
104
- }
105
- module.meta.strictHarmonyModule = origin.buildMeta?.strictHarmonyModule ?? false;
106
- module.meta.packageData = packageData;
107
- if (!features?.lite && origin?.dependencies) Array.from(origin.dependencies).filter((item)=>ModuleGraphTrans.isImportDependency(item)).concat(origin.blocks.reduce((ans, item)=>ans.concat(item.dependencies), [])).forEach((dep)=>appendDependency(dep, module, webpackGraph, graph));
108
- } catch (e) {
109
- console.error(`module ${module.path} transform has error:`, e);
110
- }
111
- }
112
- async function appendModuleGraphByCompilation(compilation, graph, features, context) {
113
- try {
114
- const webpackCompilation = compilation;
115
- const { moduleGraph: webpackGraph, fileSystemInfo } = webpackCompilation;
116
- const allModules = Webpack.getAllModules(webpackCompilation);
117
- await Promise.all(allModules.map((module)=>appendModuleData(module, webpackGraph, graph, fileSystemInfo, features, context)));
118
- ModuleGraphTrans.removeNoImportStyle(graph);
119
- return graph;
120
- } catch {
121
- return graph;
122
- }
123
- }
124
- export { appendModuleGraphByCompilation, getModuleExportsType };
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __webpack_require__ = {};
3
- (()=>{
4
- __webpack_require__.d = (exports1, definition)=>{
5
- for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
- enumerable: true,
7
- get: definition[key]
8
- });
9
- };
10
- })();
11
- (()=>{
12
- __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
- })();
14
- (()=>{
15
- __webpack_require__.r = (exports1)=>{
16
- if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
- value: 'Module'
18
- });
19
- Object.defineProperty(exports1, '__esModule', {
20
- value: true
21
- });
22
- };
23
- })();
24
- var __webpack_exports__ = {};
25
- __webpack_require__.r(__webpack_exports__);
26
- __webpack_require__.d(__webpack_exports__, {
27
- InternalBundleTagPlugin: ()=>InternalBundleTagPlugin
28
- });
29
- const external_path_namespaceObject = require("path");
30
- const external_base_cjs_namespaceObject = require("./base.cjs");
31
- const logger_namespaceObject = require("@rsdoctor/utils/logger");
32
- class InternalBundleTagPlugin extends external_base_cjs_namespaceObject.InternalBasePlugin {
33
- apply(compiler) {
34
- (0, logger_namespaceObject.time)('InternalBundleTagPlugin.apply');
35
- try {
36
- const supportBannerPlugin = this.options.supports?.banner;
37
- compiler.hooks.compilation.tap('RsdoctorTagBannerPlugin', (compilation)=>{
38
- compilation.hooks.processAssets.tapPromise({
39
- name: 'RsdoctorTagBannerPlugin',
40
- stage: -2000
41
- }, async ()=>{
42
- if (true !== supportBannerPlugin || 'rspack' in compiler) return;
43
- logger_namespaceObject.logger.info(logger_namespaceObject.chalk.magenta("Rsdoctor's `supports.banner` option is enabled, this is for debugging only. Do not use it for production."));
44
- const minimizers = compiler.options.optimization?.minimizer || [];
45
- const terserPlugin = minimizers.find((plugin)=>plugin?.constructor?.name === 'TerserPlugin');
46
- const swcPlugin = minimizers.find((plugin)=>plugin?.constructor?.name === 'SwcJsMinimizerRspackPlugin');
47
- const hasTerserPlugin = !!terserPlugin;
48
- const hasSwcJsMinimizer = !!swcPlugin;
49
- if (hasTerserPlugin || hasSwcJsMinimizer) {
50
- const terserDropConsole = terserPlugin?.options?.minimizer?.options?.compress?.drop_console;
51
- const swcDropConsole = swcPlugin?._args?.[0]?.minimizerOptions?.compress?.drop_console;
52
- if (true === terserDropConsole || true === swcDropConsole) logger_namespaceObject.logger.warn(logger_namespaceObject.chalk.yellow('Warning: BannerPlugin detected in project. Please disable drop_console option in TerserPlugin or SwcJsMinimizerRspackPlugin to enable Rsdoctor analysis for BannerPlugin.'));
53
- }
54
- const chunks = compilation.chunks;
55
- for (const chunk of chunks)for (const file of chunk.files){
56
- if (!file || '.js' !== (0, external_path_namespaceObject.extname)(file)) continue;
57
- const { ConcatSource } = compiler.webpack.sources;
58
- compilation.updateAsset(file, (old)=>{
59
- const concatSource = new ConcatSource();
60
- const header = "\n console.log('RSDOCTOR_START::');\n";
61
- const footer = "\n console.log('RSDOCTOR_END::');\n";
62
- concatSource.add(header);
63
- concatSource.add(old);
64
- concatSource.add(footer);
65
- return concatSource;
66
- }, ()=>{});
67
- }
68
- });
69
- });
70
- } finally{
71
- (0, logger_namespaceObject.timeEnd)('InternalBundleTagPlugin.apply');
72
- }
73
- }
74
- constructor(...args){
75
- super(...args), this.name = 'bundleTag';
76
- }
77
- }
78
- exports.InternalBundleTagPlugin = __webpack_exports__.InternalBundleTagPlugin;
79
- for(var __rspack_i in __webpack_exports__)if (-1 === [
80
- "InternalBundleTagPlugin"
81
- ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
82
- Object.defineProperty(exports, '__esModule', {
83
- value: true
84
- });
@@ -1,6 +0,0 @@
1
- import { Plugin } from '@rsdoctor/types';
2
- import { InternalBasePlugin } from './base';
3
- export declare class InternalBundleTagPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
4
- readonly name = "bundleTag";
5
- apply(compiler: Plugin.BaseCompiler): void;
6
- }
@@ -1,6 +0,0 @@
1
- import { Plugin } from '@rsdoctor/types';
2
- import { InternalBasePlugin } from './base.js';
3
- export declare class InternalBundleTagPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
4
- readonly name = "bundleTag";
5
- apply(compiler: Plugin.BaseCompiler): void;
6
- }
@@ -1,51 +0,0 @@
1
- import "node:module";
2
- import { extname } from "path";
3
- import { InternalBasePlugin } from "./base.js";
4
- import { chalk, logger, time, timeEnd } from "@rsdoctor/utils/logger";
5
- class InternalBundleTagPlugin extends InternalBasePlugin {
6
- apply(compiler) {
7
- time('InternalBundleTagPlugin.apply');
8
- try {
9
- const supportBannerPlugin = this.options.supports?.banner;
10
- compiler.hooks.compilation.tap('RsdoctorTagBannerPlugin', (compilation)=>{
11
- compilation.hooks.processAssets.tapPromise({
12
- name: 'RsdoctorTagBannerPlugin',
13
- stage: -2000
14
- }, async ()=>{
15
- if (true !== supportBannerPlugin || 'rspack' in compiler) return;
16
- logger.info(chalk.magenta("Rsdoctor's `supports.banner` option is enabled, this is for debugging only. Do not use it for production."));
17
- const minimizers = compiler.options.optimization?.minimizer || [];
18
- const terserPlugin = minimizers.find((plugin)=>plugin?.constructor?.name === 'TerserPlugin');
19
- const swcPlugin = minimizers.find((plugin)=>plugin?.constructor?.name === 'SwcJsMinimizerRspackPlugin');
20
- const hasTerserPlugin = !!terserPlugin;
21
- const hasSwcJsMinimizer = !!swcPlugin;
22
- if (hasTerserPlugin || hasSwcJsMinimizer) {
23
- const terserDropConsole = terserPlugin?.options?.minimizer?.options?.compress?.drop_console;
24
- const swcDropConsole = swcPlugin?._args?.[0]?.minimizerOptions?.compress?.drop_console;
25
- if (true === terserDropConsole || true === swcDropConsole) logger.warn(chalk.yellow('Warning: BannerPlugin detected in project. Please disable drop_console option in TerserPlugin or SwcJsMinimizerRspackPlugin to enable Rsdoctor analysis for BannerPlugin.'));
26
- }
27
- const chunks = compilation.chunks;
28
- for (const chunk of chunks)for (const file of chunk.files){
29
- if (!file || '.js' !== extname(file)) continue;
30
- const { ConcatSource } = compiler.webpack.sources;
31
- compilation.updateAsset(file, (old)=>{
32
- const concatSource = new ConcatSource();
33
- const header = "\n console.log('RSDOCTOR_START::');\n";
34
- const footer = "\n console.log('RSDOCTOR_END::');\n";
35
- concatSource.add(header);
36
- concatSource.add(old);
37
- concatSource.add(footer);
38
- return concatSource;
39
- }, ()=>{});
40
- }
41
- });
42
- });
43
- } finally{
44
- timeEnd('InternalBundleTagPlugin.apply');
45
- }
46
- }
47
- constructor(...args){
48
- super(...args), this.name = 'bundleTag';
49
- }
50
- }
51
- export { InternalBundleTagPlugin };