@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.
- package/dist/build-utils/build/module-graph/index.cjs +4 -18
- package/dist/build-utils/build/module-graph/index.d.cts +0 -2
- package/dist/build-utils/build/module-graph/index.d.ts +0 -2
- package/dist/build-utils/build/module-graph/index.js +0 -2
- package/dist/build-utils/build/module-graph/rspack/transform.cjs +1 -1
- package/dist/build-utils/build/module-graph/rspack/transform.js +1 -1
- package/dist/build-utils/build/module-graph/transform.cjs +2 -3
- package/dist/build-utils/build/module-graph/transform.d.cts +1 -2
- package/dist/build-utils/build/module-graph/transform.d.ts +1 -2
- package/dist/build-utils/build/module-graph/transform.js +2 -3
- package/dist/build-utils/build/utils/parseBundle.cjs +1 -1
- package/dist/build-utils/build/utils/parseBundle.js +1 -1
- package/dist/build-utils/build/utils/plugin.cjs +1 -2
- package/dist/build-utils/build/utils/plugin.js +1 -2
- package/dist/inner-plugins/constants.cjs +1 -1
- package/dist/inner-plugins/constants.d.cts +1 -1
- package/dist/inner-plugins/constants.d.ts +1 -1
- package/dist/inner-plugins/constants.js +1 -1
- package/dist/inner-plugins/plugins/bundle.cjs +1 -17
- package/dist/inner-plugins/plugins/bundle.js +1 -17
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.cjs +3 -40
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.cts +4 -6
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.ts +4 -6
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +4 -41
- package/dist/inner-plugins/plugins/errors.cjs +3 -3
- package/dist/inner-plugins/plugins/errors.d.cts +1 -1
- package/dist/inner-plugins/plugins/errors.d.ts +1 -1
- package/dist/inner-plugins/plugins/errors.js +3 -3
- package/dist/inner-plugins/plugins/index.cjs +2 -9
- package/dist/inner-plugins/plugins/index.d.cts +0 -1
- package/dist/inner-plugins/plugins/index.d.ts +0 -1
- package/dist/inner-plugins/plugins/index.js +0 -1
- package/dist/inner-plugins/plugins/loader.cjs +1 -1
- package/dist/inner-plugins/plugins/loader.js +1 -1
- package/dist/inner-plugins/plugins/plugins.cjs +1 -1
- package/dist/inner-plugins/plugins/plugins.js +1 -1
- package/dist/inner-plugins/plugins/progress.cjs +14 -16
- package/dist/inner-plugins/plugins/progress.d.cts +1 -1
- package/dist/inner-plugins/plugins/progress.d.ts +1 -1
- package/dist/inner-plugins/plugins/progress.js +14 -16
- package/dist/inner-plugins/plugins/resolver.d.cts +1 -2
- package/dist/inner-plugins/plugins/resolver.d.ts +1 -2
- package/dist/inner-plugins/plugins/rules.cjs +3 -3
- package/dist/inner-plugins/plugins/rules.js +3 -3
- package/dist/inner-plugins/utils/config.cjs +0 -1
- package/dist/inner-plugins/utils/config.d.cts +1 -1
- package/dist/inner-plugins/utils/config.d.ts +1 -1
- package/dist/inner-plugins/utils/config.js +0 -1
- package/dist/inner-plugins/utils/loader.cjs +2 -2
- package/dist/inner-plugins/utils/loader.js +2 -2
- package/dist/inner-plugins/utils/normalize-config.d.cts +3 -6
- package/dist/inner-plugins/utils/normalize-config.d.ts +3 -6
- package/dist/rules/rules/cjs-require/index.cjs +2 -2
- package/dist/rules/rules/cjs-require/index.js +2 -2
- package/dist/rules/rules/esm-resolved-to-cjs/index.cjs +91 -26
- package/dist/rules/rules/esm-resolved-to-cjs/index.js +91 -26
- package/dist/rules/rules/index.d.cts +2 -1
- package/dist/rules/rules/index.d.ts +2 -1
- package/dist/rules/rules/loader-performance-optimization/index.cjs +1 -1
- package/dist/rules/rules/loader-performance-optimization/index.js +1 -1
- package/dist/rules/rules/module-mixed-chunks/index.cjs +1 -1
- package/dist/rules/rules/module-mixed-chunks/index.js +1 -1
- package/dist/rules/rules/side-effects-only-imports/index.cjs +1 -1
- package/dist/rules/rules/side-effects-only-imports/index.js +1 -1
- package/dist/types/plugin.d.cts +2 -2
- package/dist/types/plugin.d.ts +2 -2
- package/dist/types/rules.d.cts +4 -4
- package/dist/types/rules.d.ts +4 -4
- package/package.json +9 -10
- package/dist/build-utils/build/module-graph/treeShaking.cjs +0 -106
- package/dist/build-utils/build/module-graph/treeShaking.d.cts +0 -2
- package/dist/build-utils/build/module-graph/treeShaking.d.ts +0 -2
- package/dist/build-utils/build/module-graph/treeShaking.js +0 -73
- package/dist/build-utils/build/module-graph/webpack/transform.cjs +0 -170
- package/dist/build-utils/build/module-graph/webpack/transform.d.cts +0 -16
- package/dist/build-utils/build/module-graph/webpack/transform.d.ts +0 -16
- package/dist/build-utils/build/module-graph/webpack/transform.js +0 -124
- package/dist/inner-plugins/plugins/bundleTagPlugin.cjs +0 -84
- package/dist/inner-plugins/plugins/bundleTagPlugin.d.cts +0 -6
- package/dist/inner-plugins/plugins/bundleTagPlugin.d.ts +0 -6
- package/dist/inner-plugins/plugins/bundleTagPlugin.js +0 -51
|
@@ -148,7 +148,7 @@ class InternalLoaderPlugin extends external_base_cjs_namespaceObject.InternalBas
|
|
|
148
148
|
if (compiler.isChild()) return;
|
|
149
149
|
compiler.options.module.rules = this.getInterceptRules(compiler, compiler.options.module.rules);
|
|
150
150
|
this.sdk.addClientRoutes([
|
|
151
|
-
types_namespaceObject.Manifest.RsdoctorManifestClientRoutes.
|
|
151
|
+
types_namespaceObject.Manifest.RsdoctorManifestClientRoutes.Loaders
|
|
152
152
|
]);
|
|
153
153
|
} finally{
|
|
154
154
|
(0, logger_namespaceObject.timeEnd)('InternalLoaderPlugin.afterPlugins');
|
|
@@ -109,7 +109,7 @@ class InternalLoaderPlugin extends InternalBasePlugin {
|
|
|
109
109
|
if (compiler.isChild()) return;
|
|
110
110
|
compiler.options.module.rules = this.getInterceptRules(compiler, compiler.options.module.rules);
|
|
111
111
|
this.sdk.addClientRoutes([
|
|
112
|
-
Manifest.RsdoctorManifestClientRoutes.
|
|
112
|
+
Manifest.RsdoctorManifestClientRoutes.Loaders
|
|
113
113
|
]);
|
|
114
114
|
} finally{
|
|
115
115
|
timeEnd('InternalLoaderPlugin.afterPlugins');
|
|
@@ -48,7 +48,7 @@ class InternalPluginsPlugin extends external_base_cjs_namespaceObject.InternalBa
|
|
|
48
48
|
if (compiler.isChild()) return;
|
|
49
49
|
index_cjs_namespaceObject.Utils.interceptCompilerHooks(compiler, (name, hook)=>(0, external_utils_index_cjs_namespaceObject.interceptPluginHook)(this.sdk, name, hook));
|
|
50
50
|
this.sdk.addClientRoutes([
|
|
51
|
-
types_namespaceObject.Manifest.RsdoctorManifestClientRoutes.
|
|
51
|
+
types_namespaceObject.Manifest.RsdoctorManifestClientRoutes.Plugins
|
|
52
52
|
]);
|
|
53
53
|
} finally{
|
|
54
54
|
(0, logger_namespaceObject.timeEnd)('InternalPluginsPlugin.afterPlugins');
|
|
@@ -21,7 +21,7 @@ class InternalPluginsPlugin extends InternalBasePlugin {
|
|
|
21
21
|
if (compiler.isChild()) return;
|
|
22
22
|
Utils.interceptCompilerHooks(compiler, (name, hook)=>interceptPluginHook(this.sdk, name, hook));
|
|
23
23
|
this.sdk.addClientRoutes([
|
|
24
|
-
Manifest.RsdoctorManifestClientRoutes.
|
|
24
|
+
Manifest.RsdoctorManifestClientRoutes.Plugins
|
|
25
25
|
]);
|
|
26
26
|
} finally{
|
|
27
27
|
timeEnd('InternalPluginsPlugin.afterPlugins');
|
|
@@ -33,22 +33,20 @@ class InternalProgressPlugin extends external_base_cjs_namespaceObject.InternalB
|
|
|
33
33
|
apply(compiler) {
|
|
34
34
|
const { sdk, currentProgress } = this;
|
|
35
35
|
if (compiler.webpack && compiler.webpack.ProgressPlugin) {
|
|
36
|
-
const progress = new compiler.webpack.ProgressPlugin({
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
logger_namespaceObject.logger.debug(e);
|
|
51
|
-
}
|
|
36
|
+
const progress = new compiler.webpack.ProgressPlugin((percentage, msg)=>{
|
|
37
|
+
currentProgress.percentage = percentage;
|
|
38
|
+
currentProgress.message = msg || '';
|
|
39
|
+
const api = types_namespaceObject.SDK.ServerAPI.APIExtends.GetCompileProgress;
|
|
40
|
+
try {
|
|
41
|
+
sdk.server.sendAPIDataToClient(api, {
|
|
42
|
+
req: {
|
|
43
|
+
api,
|
|
44
|
+
body: void 0
|
|
45
|
+
},
|
|
46
|
+
res: currentProgress
|
|
47
|
+
});
|
|
48
|
+
} catch (e) {
|
|
49
|
+
logger_namespaceObject.logger.debug(e);
|
|
52
50
|
}
|
|
53
51
|
});
|
|
54
52
|
progress.apply(compiler);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SDK } from '@rsdoctor/types';
|
|
2
2
|
import type { Plugin } from '@rsdoctor/types';
|
|
3
3
|
import { InternalBasePlugin } from './base';
|
|
4
|
-
export declare class InternalProgressPlugin<T extends Plugin.BaseCompilerType<'
|
|
4
|
+
export declare class InternalProgressPlugin<T extends Plugin.BaseCompilerType<'rspack'>> extends InternalBasePlugin<T> {
|
|
5
5
|
readonly name = "progress";
|
|
6
6
|
protected currentProgress: SDK.ServerAPI.InferResponseType<SDK.ServerAPI.APIExtends.GetCompileProgress>;
|
|
7
7
|
apply(compiler: T): void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SDK } from '@rsdoctor/types';
|
|
2
2
|
import type { Plugin } from '@rsdoctor/types';
|
|
3
3
|
import { InternalBasePlugin } from './base.js';
|
|
4
|
-
export declare class InternalProgressPlugin<T extends Plugin.BaseCompilerType<'
|
|
4
|
+
export declare class InternalProgressPlugin<T extends Plugin.BaseCompilerType<'rspack'>> extends InternalBasePlugin<T> {
|
|
5
5
|
readonly name = "progress";
|
|
6
6
|
protected currentProgress: SDK.ServerAPI.InferResponseType<SDK.ServerAPI.APIExtends.GetCompileProgress>;
|
|
7
7
|
apply(compiler: T): void;
|
|
@@ -6,22 +6,20 @@ class InternalProgressPlugin extends InternalBasePlugin {
|
|
|
6
6
|
apply(compiler) {
|
|
7
7
|
const { sdk, currentProgress } = this;
|
|
8
8
|
if (compiler.webpack && compiler.webpack.ProgressPlugin) {
|
|
9
|
-
const progress = new compiler.webpack.ProgressPlugin({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
logger.debug(e);
|
|
24
|
-
}
|
|
9
|
+
const progress = new compiler.webpack.ProgressPlugin((percentage, msg)=>{
|
|
10
|
+
currentProgress.percentage = percentage;
|
|
11
|
+
currentProgress.message = msg || '';
|
|
12
|
+
const api = SDK.ServerAPI.APIExtends.GetCompileProgress;
|
|
13
|
+
try {
|
|
14
|
+
sdk.server.sendAPIDataToClient(api, {
|
|
15
|
+
req: {
|
|
16
|
+
api,
|
|
17
|
+
body: void 0
|
|
18
|
+
},
|
|
19
|
+
res: currentProgress
|
|
20
|
+
});
|
|
21
|
+
} catch (e) {
|
|
22
|
+
logger.debug(e);
|
|
25
23
|
}
|
|
26
24
|
});
|
|
27
25
|
progress.apply(compiler);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Plugin } from '@rsdoctor/types';
|
|
2
2
|
import { InternalBasePlugin } from './base';
|
|
3
|
-
import type { Compiler as WebpackCompiler } from 'webpack';
|
|
4
3
|
export declare class InternalResolverPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
|
|
5
4
|
readonly name = "resolver";
|
|
6
5
|
protected resolveDataMap: Map<string, {
|
|
@@ -9,5 +8,5 @@ export declare class InternalResolverPlugin<T extends Plugin.BaseCompiler> exten
|
|
|
9
8
|
request: string;
|
|
10
9
|
}>;
|
|
11
10
|
apply(compiler: T): void;
|
|
12
|
-
protected handleNormalModuleFactory: (normalModuleFactory: Plugin.RspackNormalModuleFactory
|
|
11
|
+
protected handleNormalModuleFactory: (normalModuleFactory: Plugin.RspackNormalModuleFactory) => void;
|
|
13
12
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Plugin } from '@rsdoctor/types';
|
|
2
2
|
import { InternalBasePlugin } from './base.js';
|
|
3
|
-
import type { Compiler as WebpackCompiler } from 'webpack';
|
|
4
3
|
export declare class InternalResolverPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
|
|
5
4
|
readonly name = "resolver";
|
|
6
5
|
protected resolveDataMap: Map<string, {
|
|
@@ -9,5 +8,5 @@ export declare class InternalResolverPlugin<T extends Plugin.BaseCompiler> exten
|
|
|
9
8
|
request: string;
|
|
10
9
|
}>;
|
|
11
10
|
apply(compiler: T): void;
|
|
12
|
-
protected handleNormalModuleFactory: (normalModuleFactory: Plugin.RspackNormalModuleFactory
|
|
11
|
+
protected handleNormalModuleFactory: (normalModuleFactory: Plugin.RspackNormalModuleFactory) => void;
|
|
13
12
|
}
|
|
@@ -54,16 +54,16 @@ class InternalRulesPlugin extends external_base_cjs_namespaceObject.InternalBase
|
|
|
54
54
|
}));
|
|
55
55
|
const errors = validateErrors.filter((item)=>'Error' === item.level);
|
|
56
56
|
const warnings = validateErrors.filter((item)=>'Warn' === item.level);
|
|
57
|
-
const
|
|
57
|
+
const toRspackError = (err)=>err.toError();
|
|
58
58
|
result.replace.forEach((item)=>{
|
|
59
59
|
if (Array.isArray(compilation.errors) && compilation.errors.includes(item)) (0, compat_namespaceObject.pull)(compilation.errors, item);
|
|
60
60
|
if (Array.isArray(compilation.warnings) && compilation.warnings.includes(item)) (0, compat_namespaceObject.pull)(compilation.warnings, item);
|
|
61
61
|
});
|
|
62
62
|
if (Array.isArray(compilation.errors)) errors.forEach((err)=>{
|
|
63
|
-
compilation.
|
|
63
|
+
compilation.errors.push(toRspackError(err));
|
|
64
64
|
});
|
|
65
65
|
if (Array.isArray(compilation.warnings)) warnings.forEach((err)=>{
|
|
66
|
-
compilation.warnings.push(
|
|
66
|
+
compilation.warnings.push(toRspackError(err));
|
|
67
67
|
});
|
|
68
68
|
this.sdk.reportError(validateErrors);
|
|
69
69
|
await linter.afterValidate({
|
|
@@ -27,16 +27,16 @@ class InternalRulesPlugin extends InternalBasePlugin {
|
|
|
27
27
|
}));
|
|
28
28
|
const errors = validateErrors.filter((item)=>'Error' === item.level);
|
|
29
29
|
const warnings = validateErrors.filter((item)=>'Warn' === item.level);
|
|
30
|
-
const
|
|
30
|
+
const toRspackError = (err)=>err.toError();
|
|
31
31
|
result.replace.forEach((item)=>{
|
|
32
32
|
if (Array.isArray(compilation.errors) && compilation.errors.includes(item)) pull(compilation.errors, item);
|
|
33
33
|
if (Array.isArray(compilation.warnings) && compilation.warnings.includes(item)) pull(compilation.warnings, item);
|
|
34
34
|
});
|
|
35
35
|
if (Array.isArray(compilation.errors)) errors.forEach((err)=>{
|
|
36
|
-
compilation.
|
|
36
|
+
compilation.errors.push(toRspackError(err));
|
|
37
37
|
});
|
|
38
38
|
if (Array.isArray(compilation.warnings)) warnings.forEach((err)=>{
|
|
39
|
-
compilation.warnings.push(
|
|
39
|
+
compilation.warnings.push(toRspackError(err));
|
|
40
40
|
});
|
|
41
41
|
this.sdk.reportError(validateErrors);
|
|
42
42
|
await linter.afterValidate({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RsdoctorRspackPluginOptions, RsdoctorRspackPluginOptionsNormalized } from '../../types';
|
|
2
2
|
import { Linter, Plugin, SDK } from '@rsdoctor/types';
|
|
3
|
-
export declare function normalizeUserConfig<Rules extends Linter.ExtendRuleData[]>(config?: Plugin.
|
|
3
|
+
export declare function normalizeUserConfig<Rules extends Linter.ExtendRuleData[]>(config?: Plugin.RsdoctorRspackPluginOptions<Rules>): Plugin.RsdoctorPluginOptionsNormalized<Rules>;
|
|
4
4
|
export declare const normalizeReportType: (reportCodeType: Plugin.IReportCodeType | Plugin.NewReportCodeType, mode: keyof typeof SDK.IMode) => SDK.ToDataType;
|
|
5
5
|
export declare function normalizeRspackUserOptions<Rules extends Linter.ExtendRuleData[]>(options: RsdoctorRspackPluginOptions<Rules>): RsdoctorRspackPluginOptionsNormalized<Rules>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RsdoctorRspackPluginOptions, RsdoctorRspackPluginOptionsNormalized } from '../../types/index.js';
|
|
2
2
|
import { Linter, Plugin, SDK } from '@rsdoctor/types';
|
|
3
|
-
export declare function normalizeUserConfig<Rules extends Linter.ExtendRuleData[]>(config?: Plugin.
|
|
3
|
+
export declare function normalizeUserConfig<Rules extends Linter.ExtendRuleData[]>(config?: Plugin.RsdoctorRspackPluginOptions<Rules>): Plugin.RsdoctorPluginOptionsNormalized<Rules>;
|
|
4
4
|
export declare const normalizeReportType: (reportCodeType: Plugin.IReportCodeType | Plugin.NewReportCodeType, mode: keyof typeof SDK.IMode) => SDK.ToDataType;
|
|
5
5
|
export declare function normalizeRspackUserOptions<Rules extends Linter.ExtendRuleData[]>(options: RsdoctorRspackPluginOptions<Rules>): RsdoctorRspackPluginOptionsNormalized<Rules>;
|
|
@@ -191,10 +191,10 @@ async function reportLoader(ctx, start, startHRTime, isPitch, sync, code, err, r
|
|
|
191
191
|
}
|
|
192
192
|
await Promise.all([
|
|
193
193
|
common_namespaceObject.Fetch.postJSON(`${host}${types_namespaceObject.SDK.ServerAPI.API.ReportLoader}`, loaderData, 8888).catch((err)=>{
|
|
194
|
-
logger_namespaceObject.logger.debug(`${err.message}`, '[
|
|
194
|
+
logger_namespaceObject.logger.debug(`${err.message}`, '[RspackPlugin.ReportLoader][error]');
|
|
195
195
|
}),
|
|
196
196
|
common_namespaceObject.Fetch.postJSON(`${host}${types_namespaceObject.SDK.ServerAPI.API.ReportSourceMap}`, sourceMapData, 8888).catch((err)=>{
|
|
197
|
-
logger_namespaceObject.logger.debug(`${err.message}`, '[
|
|
197
|
+
logger_namespaceObject.logger.debug(`${err.message}`, '[RspackPlugin.ReportSourceMap][error]');
|
|
198
198
|
})
|
|
199
199
|
]);
|
|
200
200
|
return loaderData;
|
|
@@ -149,10 +149,10 @@ async function reportLoader(ctx, start, startHRTime, isPitch, sync, code, err, r
|
|
|
149
149
|
}
|
|
150
150
|
await Promise.all([
|
|
151
151
|
Fetch.postJSON(`${host}${SDK.ServerAPI.API.ReportLoader}`, loaderData, 8888).catch((err)=>{
|
|
152
|
-
logger.debug(`${err.message}`, '[
|
|
152
|
+
logger.debug(`${err.message}`, '[RspackPlugin.ReportLoader][error]');
|
|
153
153
|
}),
|
|
154
154
|
Fetch.postJSON(`${host}${SDK.ServerAPI.API.ReportSourceMap}`, sourceMapData, 8888).catch((err)=>{
|
|
155
|
-
logger.debug(`${err.message}`, '[
|
|
155
|
+
logger.debug(`${err.message}`, '[RspackPlugin.ReportSourceMap][error]');
|
|
156
156
|
})
|
|
157
157
|
]);
|
|
158
158
|
return loaderData;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Config, Plugin, SDK } from '@rsdoctor/types';
|
|
2
2
|
import type { RuleSetCondition as RspackRuleSetCondition, RuleSetRule as RspackRuleSetRule } from '@rspack/core';
|
|
3
|
-
import { RuleSetCondition as WebpackRuleSetCondition, RuleSetConditionAbsolute as WebpackRuleSetConditionAbsolute, RuleSetRule as WebpackRuleSetRule } from 'webpack';
|
|
4
3
|
/**
|
|
5
4
|
* Process mode-specific configurations with priority logic
|
|
6
5
|
*/
|
|
@@ -22,9 +21,7 @@ export declare function convertReportCodeTypeObject(reportCodeType: any): Config
|
|
|
22
21
|
* properly serialized to JSON.
|
|
23
22
|
*
|
|
24
23
|
* @param item - The rule set condition to make serializable. Can be:
|
|
25
|
-
* - RspackRuleSetCondition: Rspack
|
|
26
|
-
* - WebpackRuleSetConditionAbsolute: Webpack absolute rule conditions
|
|
27
|
-
* - WebpackRuleSetCondition: Webpack rule conditions
|
|
24
|
+
* - RspackRuleSetCondition: Rspack rule conditions
|
|
28
25
|
* - void: Undefined or null values
|
|
29
26
|
*
|
|
30
27
|
* @example
|
|
@@ -36,5 +33,5 @@ export declare function convertReportCodeTypeObject(reportCodeType: any): Config
|
|
|
36
33
|
* JSON.stringify(condition); // '"/\\.js$/"'
|
|
37
34
|
* ```
|
|
38
35
|
*/
|
|
39
|
-
export declare function makeRuleSetSerializable(item: RspackRuleSetCondition |
|
|
40
|
-
export declare function makeRulesSerializable(rules: Plugin.RuleSetRule[] | RspackRuleSetRule['oneOf']
|
|
36
|
+
export declare function makeRuleSetSerializable(item: RspackRuleSetCondition | void): void;
|
|
37
|
+
export declare function makeRulesSerializable(rules: Plugin.RuleSetRule[] | RspackRuleSetRule['oneOf']): void;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Config, Plugin, SDK } from '@rsdoctor/types';
|
|
2
2
|
import type { RuleSetCondition as RspackRuleSetCondition, RuleSetRule as RspackRuleSetRule } from '@rspack/core';
|
|
3
|
-
import { RuleSetCondition as WebpackRuleSetCondition, RuleSetConditionAbsolute as WebpackRuleSetConditionAbsolute, RuleSetRule as WebpackRuleSetRule } from 'webpack';
|
|
4
3
|
/**
|
|
5
4
|
* Process mode-specific configurations with priority logic
|
|
6
5
|
*/
|
|
@@ -22,9 +21,7 @@ export declare function convertReportCodeTypeObject(reportCodeType: any): Config
|
|
|
22
21
|
* properly serialized to JSON.
|
|
23
22
|
*
|
|
24
23
|
* @param item - The rule set condition to make serializable. Can be:
|
|
25
|
-
* - RspackRuleSetCondition: Rspack
|
|
26
|
-
* - WebpackRuleSetConditionAbsolute: Webpack absolute rule conditions
|
|
27
|
-
* - WebpackRuleSetCondition: Webpack rule conditions
|
|
24
|
+
* - RspackRuleSetCondition: Rspack rule conditions
|
|
28
25
|
* - void: Undefined or null values
|
|
29
26
|
*
|
|
30
27
|
* @example
|
|
@@ -36,5 +33,5 @@ export declare function convertReportCodeTypeObject(reportCodeType: any): Config
|
|
|
36
33
|
* JSON.stringify(condition); // '"/\\.js$/"'
|
|
37
34
|
* ```
|
|
38
35
|
*/
|
|
39
|
-
export declare function makeRuleSetSerializable(item: RspackRuleSetCondition |
|
|
40
|
-
export declare function makeRulesSerializable(rules: Plugin.RuleSetRule[] | RspackRuleSetRule['oneOf']
|
|
36
|
+
export declare function makeRuleSetSerializable(item: RspackRuleSetCondition | void): void;
|
|
37
|
+
export declare function makeRulesSerializable(rules: Plugin.RuleSetRule[] | RspackRuleSetRule['oneOf']): void;
|
|
@@ -57,12 +57,12 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
57
57
|
issuerModule: {
|
|
58
58
|
id: dep.module.id,
|
|
59
59
|
path: dep.module.path,
|
|
60
|
-
|
|
60
|
+
identifier: dep.module.identifier
|
|
61
61
|
},
|
|
62
62
|
requiredModule: {
|
|
63
63
|
id: requiredModule.id,
|
|
64
64
|
path: requiredModule.path,
|
|
65
|
-
|
|
65
|
+
identifier: requiredModule.identifier
|
|
66
66
|
},
|
|
67
67
|
request: dep.request
|
|
68
68
|
};
|
|
@@ -30,12 +30,12 @@ const rule = defineRule(()=>({
|
|
|
30
30
|
issuerModule: {
|
|
31
31
|
id: dep.module.id,
|
|
32
32
|
path: dep.module.path,
|
|
33
|
-
|
|
33
|
+
identifier: dep.module.identifier
|
|
34
34
|
},
|
|
35
35
|
requiredModule: {
|
|
36
36
|
id: requiredModule.id,
|
|
37
37
|
path: requiredModule.path,
|
|
38
|
-
|
|
38
|
+
identifier: requiredModule.identifier
|
|
39
39
|
},
|
|
40
40
|
request: dep.request
|
|
41
41
|
};
|
|
@@ -52,28 +52,88 @@ function normalizePathForCompare(filePath) {
|
|
|
52
52
|
const cleanPath = splitIndex === 1 / 0 ? filePath : filePath.slice(0, splitIndex);
|
|
53
53
|
return external_path_default().normalize(cleanPath);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
55
|
+
function isDefinitelyEsmFile(filePath) {
|
|
56
|
+
return '.mjs' === external_path_default().extname(normalizePathForCompare(filePath));
|
|
57
|
+
}
|
|
58
|
+
function isDeclaredEsmEntry(filePath, esmEntries, toRealPath) {
|
|
59
|
+
const realPath = toRealPath(filePath);
|
|
60
|
+
return esmEntries.some((esmEntry)=>realPath === toRealPath(esmEntry));
|
|
61
|
+
}
|
|
62
|
+
function isRecord(value) {
|
|
63
|
+
return null !== value && 'object' == typeof value && !Array.isArray(value);
|
|
64
|
+
}
|
|
65
|
+
function substituteExportPattern(target, wildcard) {
|
|
66
|
+
return target.replace(/\*/g, wildcard);
|
|
67
|
+
}
|
|
68
|
+
function toPackagePath(pkgRoot, target, wildcard) {
|
|
69
|
+
return external_path_default().resolve(pkgRoot, substituteExportPattern(target, wildcard));
|
|
70
|
+
}
|
|
71
|
+
function collectStringTargets(value, wildcard) {
|
|
72
|
+
if ('string' == typeof value) return [
|
|
73
|
+
substituteExportPattern(value, wildcard)
|
|
74
|
+
];
|
|
75
|
+
if (Array.isArray(value)) return value.flatMap((item)=>collectStringTargets(item, wildcard));
|
|
76
|
+
if (!isRecord(value)) return [];
|
|
77
|
+
return Object.values(value).flatMap((child)=>collectStringTargets(child, wildcard));
|
|
78
|
+
}
|
|
79
|
+
function collectEsmTargets(exportEntry, pkgRoot, wildcard) {
|
|
80
|
+
const entries = new Set();
|
|
81
|
+
const addTargets = (value)=>{
|
|
82
|
+
for (const target of collectStringTargets(value, wildcard))entries.add(toPackagePath(pkgRoot, target, ''));
|
|
83
|
+
};
|
|
84
|
+
const visit = (value)=>{
|
|
85
|
+
if ('string' == typeof value || Array.isArray(value)) return void addTargets(value);
|
|
86
|
+
if (!isRecord(value)) return;
|
|
87
|
+
addTargets(value['import']);
|
|
88
|
+
addTargets(value['module']);
|
|
89
|
+
for (const child of Object.values(value))if (isRecord(child) || Array.isArray(child)) visit(child);
|
|
90
|
+
};
|
|
91
|
+
visit(exportEntry);
|
|
92
|
+
return entries;
|
|
93
|
+
}
|
|
94
|
+
function hasSubpathExportKeys(exports1) {
|
|
95
|
+
return Object.keys(exports1).some((key)=>'.' === key || key.startsWith('./'));
|
|
96
|
+
}
|
|
97
|
+
function matchPatternExportKey(patternKey, exportKey) {
|
|
98
|
+
const wildcardIndex = patternKey.indexOf('*');
|
|
99
|
+
if (wildcardIndex < 0) return null;
|
|
100
|
+
const prefix = patternKey.slice(0, wildcardIndex);
|
|
101
|
+
const suffix = patternKey.slice(wildcardIndex + 1);
|
|
102
|
+
if (!exportKey.startsWith(prefix) || !exportKey.endsWith(suffix)) return null;
|
|
103
|
+
return exportKey.slice(prefix.length, exportKey.length - suffix.length);
|
|
104
|
+
}
|
|
105
|
+
function resolveExportEntry(exports1, exportKey) {
|
|
106
|
+
if (Object.prototype.hasOwnProperty.call(exports1, exportKey)) return {
|
|
107
|
+
value: exports1[exportKey],
|
|
108
|
+
wildcard: ''
|
|
109
|
+
};
|
|
110
|
+
for (const [key, value] of Object.entries(exports1)){
|
|
111
|
+
const wildcard = matchPatternExportKey(key, exportKey);
|
|
112
|
+
if (null !== wildcard) return {
|
|
113
|
+
value,
|
|
114
|
+
wildcard
|
|
115
|
+
};
|
|
75
116
|
}
|
|
76
|
-
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
function resolveExportEntryForKey(exportsField, exportKey) {
|
|
120
|
+
if (!isRecord(exportsField)) return null;
|
|
121
|
+
if (!hasSubpathExportKeys(exportsField)) return '.' === exportKey ? {
|
|
122
|
+
value: exportsField,
|
|
123
|
+
wildcard: ''
|
|
124
|
+
} : null;
|
|
125
|
+
return resolveExportEntry(exportsField, exportKey);
|
|
126
|
+
}
|
|
127
|
+
function extractEsmEntries(pkgJson, pkgRoot, exportKey) {
|
|
128
|
+
const { exports: exportsField, module: moduleField } = pkgJson;
|
|
129
|
+
const resolvedExport = resolveExportEntryForKey(exportsField, exportKey);
|
|
130
|
+
const entries = resolvedExport ? collectEsmTargets(resolvedExport.value, pkgRoot, resolvedExport.wildcard) : new Set();
|
|
131
|
+
if ('.' === exportKey && 'string' == typeof moduleField) entries.add(external_path_default().resolve(pkgRoot, moduleField));
|
|
132
|
+
return entries;
|
|
133
|
+
}
|
|
134
|
+
function getExportKeyFromRequest(packageName, request) {
|
|
135
|
+
if (request === packageName) return '.';
|
|
136
|
+
if (request.startsWith(`${packageName}/`)) return `.${request.slice(packageName.length)}`;
|
|
77
137
|
return null;
|
|
78
138
|
}
|
|
79
139
|
const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
@@ -121,10 +181,15 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
121
181
|
const pkg = packageGraph.getPackageByModule(dep.dependency);
|
|
122
182
|
if (!pkg?.root) continue;
|
|
123
183
|
const pkgJson = readPkgJson(pkg.root);
|
|
124
|
-
|
|
125
|
-
|
|
184
|
+
if (ruleConfig.ignore.some((p)=>pkg.name.includes(p)) || !pkgJson) continue;
|
|
185
|
+
const exportKey = getExportKeyFromRequest(pkg.name, dep.request);
|
|
186
|
+
if (!exportKey) continue;
|
|
187
|
+
const esmEntries = extractEsmEntries(pkgJson, pkg.root, exportKey);
|
|
188
|
+
if (0 === esmEntries.size) continue;
|
|
189
|
+
const esmEntryList = Array.from(esmEntries);
|
|
126
190
|
const resolvedModuleRealPath = toRealPath(dep.dependency.path);
|
|
127
|
-
if (resolvedModuleRealPath
|
|
191
|
+
if (isDefinitelyEsmFile(resolvedModuleRealPath)) continue;
|
|
192
|
+
if (isDeclaredEsmEntry(resolvedModuleRealPath, esmEntryList, toRealPath)) continue;
|
|
128
193
|
const groupKey = `${pkg.name}::${resolvedModuleRealPath}`;
|
|
129
194
|
const issuer = {
|
|
130
195
|
id: dep.module.id,
|
|
@@ -135,11 +200,11 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
135
200
|
else groups.set(groupKey, {
|
|
136
201
|
packageName: pkg.name,
|
|
137
202
|
packageVersion: pkg.version,
|
|
138
|
-
esmEntry,
|
|
203
|
+
esmEntry: esmEntryList[0],
|
|
139
204
|
resolvedModule: {
|
|
140
205
|
id: dep.dependency.id,
|
|
141
206
|
path: dep.dependency.path,
|
|
142
|
-
|
|
207
|
+
identifier: dep.dependency.identifier
|
|
143
208
|
},
|
|
144
209
|
issuers: [
|
|
145
210
|
issuer
|