@rsdoctor/core 1.5.8 → 1.5.10
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/chunks/assetsModules.d.cts +17 -0
- package/dist/build-utils/build/chunks/chunkTransform.d.cts +4 -0
- package/dist/build-utils/build/chunks/index.d.cts +3 -0
- package/dist/build-utils/build/chunks/rspack/transform.d.cts +13 -0
- package/dist/build-utils/build/index.d.cts +5 -0
- package/dist/build-utils/build/loader/index.d.cts +2 -0
- package/dist/build-utils/build/loader/probeLoader.d.cts +4 -0
- package/dist/build-utils/build/loader/probeLoaderPlugin.d.cts +5 -0
- package/dist/build-utils/build/module-graph/index.d.cts +4 -0
- package/dist/build-utils/build/module-graph/parser.d.cts +2 -0
- package/dist/build-utils/build/module-graph/rspack/transform.d.cts +26 -0
- package/dist/build-utils/build/module-graph/transform.d.cts +4 -0
- package/dist/build-utils/build/module-graph/treeShaking.d.cts +2 -0
- package/dist/build-utils/build/module-graph/utils.d.cts +3 -0
- package/dist/build-utils/build/module-graph/webpack/transform.cjs +1 -1
- package/dist/build-utils/build/module-graph/webpack/transform.d.cts +16 -0
- package/dist/build-utils/build/module-graph/webpack/transform.js +1 -1
- package/dist/build-utils/build/utils/index.d.cts +3 -0
- package/dist/build-utils/build/utils/loader.cjs +3 -4
- package/dist/build-utils/build/utils/loader.d.cts +20 -0
- package/dist/build-utils/build/utils/loader.js +3 -4
- package/dist/build-utils/build/utils/parseBundle.d.cts +12 -0
- package/dist/build-utils/build/utils/plugin.d.cts +5 -0
- package/dist/build-utils/index.d.cts +1 -0
- package/dist/index.d.cts +3 -0
- package/dist/inner-plugins/constants.d.cts +6 -0
- package/dist/inner-plugins/index.d.cts +2 -0
- package/dist/inner-plugins/loaders/proxy.cjs +10 -4
- package/dist/inner-plugins/loaders/proxy.d.cts +7 -0
- package/dist/inner-plugins/loaders/proxy.js +10 -4
- package/dist/inner-plugins/plugins/base.d.cts +12 -0
- package/dist/inner-plugins/plugins/bundle.d.cts +15 -0
- package/dist/inner-plugins/plugins/bundleTagPlugin.cjs +3 -3
- package/dist/inner-plugins/plugins/bundleTagPlugin.d.cts +6 -0
- package/dist/inner-plugins/plugins/bundleTagPlugin.js +3 -3
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.cjs +3 -3
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.d.cts +36 -0
- package/dist/inner-plugins/plugins/ensureModulesChunkGraph.js +3 -3
- package/dist/inner-plugins/plugins/errors.d.cts +11 -0
- package/dist/inner-plugins/plugins/index.d.cts +11 -0
- package/dist/inner-plugins/plugins/loader.d.cts +10 -0
- package/dist/inner-plugins/plugins/plugins.d.cts +8 -0
- package/dist/inner-plugins/plugins/progress.d.cts +8 -0
- package/dist/inner-plugins/plugins/resolver.d.cts +13 -0
- package/dist/inner-plugins/plugins/rspack.d.cts +4 -0
- package/dist/inner-plugins/plugins/rules.d.cts +8 -0
- package/dist/inner-plugins/plugins/sourcemapTool.cjs +2 -2
- package/dist/inner-plugins/plugins/sourcemapTool.d.cts +52 -0
- package/dist/inner-plugins/plugins/sourcemapTool.js +2 -2
- package/dist/inner-plugins/plugins/summary.cjs +1 -1
- package/dist/inner-plugins/plugins/summary.d.cts +14 -0
- package/dist/inner-plugins/plugins/summary.js +1 -1
- package/dist/inner-plugins/utils/circleDetect.d.cts +4 -0
- package/dist/inner-plugins/utils/config.d.cts +5 -0
- package/dist/inner-plugins/utils/index.d.cts +9 -0
- package/dist/inner-plugins/utils/loader.d.cts +13 -0
- package/dist/inner-plugins/utils/normalize-config.d.cts +40 -0
- package/dist/inner-plugins/utils/plugin-common.d.cts +11 -0
- package/dist/inner-plugins/utils/plugin.cjs +7 -7
- package/dist/inner-plugins/utils/plugin.d.cts +4 -0
- package/dist/inner-plugins/utils/plugin.js +7 -7
- package/dist/inner-plugins/utils/sdk.d.cts +8 -0
- package/dist/rules/index.d.cts +3 -0
- package/dist/rules/linter.d.cts +9 -0
- package/dist/rules/rule.cjs +1 -1
- package/dist/rules/rule.d.cts +27 -0
- package/dist/rules/rule.js +1 -1
- package/dist/rules/rules/cjs-require/index.d.cts +4 -0
- package/dist/rules/rules/cjs-require/types.d.cts +7 -0
- package/dist/rules/rules/cross-chunks-package/index.d.cts +4 -0
- package/dist/rules/rules/cross-chunks-package/types.d.cts +3 -0
- package/dist/rules/rules/cross-chunks-package/utils.d.cts +1 -0
- package/dist/rules/rules/default-import-check/index.d.cts +4 -0
- package/dist/rules/rules/default-import-check/types.d.cts +4 -0
- package/dist/rules/rules/default-import-check/utils.d.cts +10 -0
- package/dist/rules/rules/duplicate-package/index.d.cts +4 -0
- package/dist/rules/rules/duplicate-package/types.d.cts +24 -0
- package/dist/rules/rules/duplicate-package/utils.d.cts +3 -0
- package/dist/rules/rules/ecma-version-check/index.d.cts +4 -0
- package/dist/rules/rules/ecma-version-check/types.d.cts +3 -0
- package/dist/rules/rules/ecma-version-check/utils.d.cts +2 -0
- package/dist/rules/rules/esm-resolved-to-cjs/index.cjs +30 -2
- package/dist/rules/rules/esm-resolved-to-cjs/index.d.cts +4 -0
- package/dist/rules/rules/esm-resolved-to-cjs/index.js +30 -2
- package/dist/rules/rules/esm-resolved-to-cjs/types.d.cts +8 -0
- package/dist/rules/rules/index.d.cts +1 -0
- package/dist/rules/rules/loader-performance-optimization/index.d.cts +4 -0
- package/dist/rules/rules/loader-performance-optimization/types.d.cts +22 -0
- package/dist/rules/rules/loader-performance-optimization/utils.d.cts +1 -0
- package/dist/rules/rules/module-mixed-chunks/index.d.cts +4 -0
- package/dist/rules/rules/module-mixed-chunks/types.d.cts +3 -0
- package/dist/rules/rules/side-effects-only-imports/index.d.cts +4 -0
- package/dist/rules/rules/side-effects-only-imports/types.d.cts +9 -0
- package/dist/rules/utils.d.cts +3 -0
- package/dist/types/chunks.d.cts +6 -0
- package/dist/types/index.d.cts +4 -0
- package/dist/types/loader.d.cts +19 -0
- package/dist/types/plugin.d.cts +51 -0
- package/dist/types/rules.d.cts +7 -0
- package/package.json +46 -21
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { RsdoctorPluginInstance } from '../../types';
|
|
2
|
+
import { Linter, Plugin } from '@rsdoctor/types';
|
|
3
|
+
export declare const UNASSIGNED = "[unassigned]";
|
|
4
|
+
/**
|
|
5
|
+
* Options for handling source map assets.
|
|
6
|
+
* @param compilation - The current compilation object.
|
|
7
|
+
* @param pluginInstance - The Rsdoctor plugin instance.
|
|
8
|
+
* @param sourceMapFilenameRegex - Regex to extract file paths from source map sources.
|
|
9
|
+
* @param namespace - Optional namespace for resolving sources.
|
|
10
|
+
*/
|
|
11
|
+
interface SourceMapAssetOptions {
|
|
12
|
+
compilation: Plugin.BaseCompilation;
|
|
13
|
+
pluginInstance: RsdoctorPluginInstance<Plugin.BaseCompiler, Linter.ExtendRuleData<any, string>[]>;
|
|
14
|
+
sourceMapFilenameRegex: RegExp;
|
|
15
|
+
namespace?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Binds a context cache to a source path resolver.
|
|
19
|
+
* @param context - The base context directory.
|
|
20
|
+
* @param namespace - Optional namespace for resolving sources.
|
|
21
|
+
* @param cache - The cache map to store resolved paths.
|
|
22
|
+
* @param sourceMapDir - The directory containing source maps.
|
|
23
|
+
* @param sourceRoot - The source root directory.
|
|
24
|
+
* @returns A function that resolves source paths based on the given context.
|
|
25
|
+
*/
|
|
26
|
+
export declare function bindContextCache(context: string, namespace?: string, cache?: Map<string, string>, sourceMapDir?: string, sourceRoot?: string): (source: string, sourceMapFilenameRegex?: RegExp) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Collects and processes source map information for a given asset.
|
|
29
|
+
* Groups mappings by line, sorts them, and reconstructs the original source code segments.
|
|
30
|
+
* @param map - The raw source map object.
|
|
31
|
+
* @param assetLinesCodeList - The code lines of the asset.
|
|
32
|
+
* @param _compilation - The current compilation object.
|
|
33
|
+
* @param _this - The Rsdoctor plugin instance.
|
|
34
|
+
* @param sourceMapFilenameRegex - Regex to extract file paths from source map sources.
|
|
35
|
+
* @param namespace - Optional namespace for resolving sources.
|
|
36
|
+
*/
|
|
37
|
+
export declare function collectSourceMaps(map: any, assetLinesCodeList: string[], _compilation: Plugin.BaseCompilation, _this: RsdoctorPluginInstance<Plugin.BaseCompiler, Linter.ExtendRuleData[]>, sourceMapFilenameRegex?: RegExp, namespace?: string, skipSources?: Set<string>, sourceMapPath?: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Handles the afterEmit event for assets to collect source map information.
|
|
40
|
+
* @param compilation - The current compilation object.
|
|
41
|
+
* @param _this - The Rsdoctor plugin instance.
|
|
42
|
+
* @param sourceMapFilenameRegex - Regex to extract file paths from source map sources.
|
|
43
|
+
* @param namespace - Optional namespace for resolving sources.
|
|
44
|
+
*/
|
|
45
|
+
export declare function handleAfterEmitAssets(compilation: Plugin.BaseCompilation, _this: RsdoctorPluginInstance<Plugin.BaseCompiler, Linter.ExtendRuleData<any, string>[]>, sourceMapFilenameRegex?: RegExp, namespace?: string): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Handles the emit event for assets to collect source map information.
|
|
48
|
+
* @param options - The options for handling source map assets.
|
|
49
|
+
* @returns A promise that resolves when the source map information is collected.
|
|
50
|
+
*/
|
|
51
|
+
export declare function handleEmitAssets(options: SourceMapAssetOptions): Promise<void>;
|
|
52
|
+
export {};
|
|
@@ -106,8 +106,8 @@ async function handleAfterEmitAssets(compilation, _this, sourceMapFilenameRegex,
|
|
|
106
106
|
sourceMapPath = resolve(outputPath, mapFileName);
|
|
107
107
|
}
|
|
108
108
|
} else {
|
|
109
|
-
|
|
110
|
-
|
|
109
|
+
const sourceMapFile = asset.info.related?.sourceMap;
|
|
110
|
+
const sourceMapFileAssetName = sourceMapFile?.replace(/(\.[^.]+)(\.[^.]+)?$/, '$1');
|
|
111
111
|
if (sourceMapFile) {
|
|
112
112
|
let sourceMapAsset = assets.find((asset)=>asset.name === sourceMapFile);
|
|
113
113
|
if (!sourceMapAsset && sourceMapFileAssetName) {
|
|
@@ -100,7 +100,7 @@ class InternalSummaryPlugin extends external_base_cjs_namespaceObject.InternalBa
|
|
|
100
100
|
const minifyHookData = [
|
|
101
101
|
...pluginData.processAssets || []
|
|
102
102
|
];
|
|
103
|
-
minifyHookData.length
|
|
103
|
+
if (minifyHookData.length) this.sdk.reportSummaryData({
|
|
104
104
|
costs: [
|
|
105
105
|
{
|
|
106
106
|
name: common_namespaceObject.Summary.SummaryCostsDataName.Minify,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Plugin } from '@rsdoctor/types';
|
|
2
|
+
import { InternalBasePlugin } from './base';
|
|
3
|
+
export declare class InternalSummaryPlugin<T extends Plugin.BaseCompiler> extends InternalBasePlugin<T> {
|
|
4
|
+
readonly name = "summary";
|
|
5
|
+
private times;
|
|
6
|
+
private preTimes;
|
|
7
|
+
private postTimes;
|
|
8
|
+
apply(compiler: T): void;
|
|
9
|
+
private mark;
|
|
10
|
+
beforeCompile: () => Promise<void>;
|
|
11
|
+
afterCompile: (compilation: Plugin.BaseCompilation) => Promise<void>;
|
|
12
|
+
done: (compiler: T) => Promise<void>;
|
|
13
|
+
private report;
|
|
14
|
+
}
|
|
@@ -73,7 +73,7 @@ class InternalSummaryPlugin extends InternalBasePlugin {
|
|
|
73
73
|
const minifyHookData = [
|
|
74
74
|
...pluginData.processAssets || []
|
|
75
75
|
];
|
|
76
|
-
minifyHookData.length
|
|
76
|
+
if (minifyHookData.length) this.sdk.reportSummaryData({
|
|
77
77
|
costs: [
|
|
78
78
|
{
|
|
79
79
|
name: Summary.SummaryCostsDataName.Minify,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { RsdoctorRspackPluginOptions, RsdoctorRspackPluginOptionsNormalized } from '../../types';
|
|
2
|
+
import { Linter, Plugin, SDK } from '@rsdoctor/types';
|
|
3
|
+
export declare function normalizeUserConfig<Rules extends Linter.ExtendRuleData[]>(config?: Plugin.RsdoctorWebpackPluginOptions<Rules>): Plugin.RsdoctorPluginOptionsNormalized<Rules>;
|
|
4
|
+
export declare const normalizeReportType: (reportCodeType: Plugin.IReportCodeType | Plugin.NewReportCodeType, mode: keyof typeof SDK.IMode) => SDK.ToDataType;
|
|
5
|
+
export declare function normalizeRspackUserOptions<Rules extends Linter.ExtendRuleData[]>(options: RsdoctorRspackPluginOptions<Rules>): RsdoctorRspackPluginOptionsNormalized<Rules>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './loader';
|
|
2
|
+
export * from './plugin';
|
|
3
|
+
export * from './sdk';
|
|
4
|
+
export * from './config';
|
|
5
|
+
export * from './circleDetect';
|
|
6
|
+
export * from './plugin-common';
|
|
7
|
+
export * from './normalize-config';
|
|
8
|
+
export * from './plugin-common';
|
|
9
|
+
export * from './normalize-config';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Loader } from '@rsdoctor/utils/common';
|
|
2
|
+
import { SDK, Plugin } from '@rsdoctor/types';
|
|
3
|
+
import { ProxyLoaderInternalOptions, ProxyLoaderOptions } from '../../types';
|
|
4
|
+
import { Utils as BuildUtils } from '../../build-utils/build';
|
|
5
|
+
export declare function getInternalLoaderOptions(loaderContext: Plugin.LoaderContext<ProxyLoaderOptions>): ProxyLoaderInternalOptions;
|
|
6
|
+
export declare function getLoaderOptionsWithoutInternalKeys(loaderContext: Plugin.LoaderContext<ProxyLoaderOptions>): Omit<ProxyLoaderOptions, typeof Loader.LoaderInternalPropertyName>;
|
|
7
|
+
export declare function getOriginLoaderModule(loaderContext: Plugin.LoaderContext<ProxyLoaderOptions>): ReturnType<typeof BuildUtils.loadLoaderModule>;
|
|
8
|
+
export declare function shouldSkipLoader(loaderContext: Plugin.LoaderContext<ProxyLoaderOptions>): boolean;
|
|
9
|
+
export type CompatibleResolve = Omit<Plugin.Configuration['resolve'], 'mainFields'> & {
|
|
10
|
+
mainFields?: string[];
|
|
11
|
+
};
|
|
12
|
+
export declare function interceptLoader<T extends Plugin.BuildRuleSetRule>(rules: T[], loaderPath: string, options: Omit<ProxyLoaderInternalOptions, 'loader' | 'hasOptions'>, cwd?: string, resolveLoader?: CompatibleResolve): T[];
|
|
13
|
+
export declare function reportLoader(ctx: Plugin.LoaderContext<ProxyLoaderOptions>, start: number, startHRTime: [number, number], isPitch: boolean, sync: boolean, code: string, err: Error | null | undefined, res: string | Buffer | null, sourceMap?: Plugin.SourceMapInput): Promise<SDK.LoaderData>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Config, Plugin, SDK } from '@rsdoctor/types';
|
|
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
|
+
/**
|
|
5
|
+
* Process mode-specific configurations with priority logic
|
|
6
|
+
*/
|
|
7
|
+
export declare function processModeConfigurations(finalMode: keyof typeof SDK.IMode, output: Config.IOutput<'brief' | 'normal'>, brief: Config.BriefConfig | undefined): {
|
|
8
|
+
finalBrief: {};
|
|
9
|
+
finalNormalOptions: Config.NormalModeOptions;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Process brief mode configuration with priority logic
|
|
13
|
+
* Priority: output.options.briefOptions > output.brief > default
|
|
14
|
+
*/
|
|
15
|
+
export declare function processBriefHtmlModeConfig(output: Config.BriefModeConfig, brief: Config.BriefConfig | undefined): Config.BriefModeOptions;
|
|
16
|
+
/**
|
|
17
|
+
* Convert reportCodeType object to NewReportCodeType enum value
|
|
18
|
+
*/
|
|
19
|
+
export declare function convertReportCodeTypeObject(reportCodeType: any): Config.NewReportCodeType | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* This function recursively processes rule set conditions to ensure they can be
|
|
22
|
+
* properly serialized to JSON.
|
|
23
|
+
*
|
|
24
|
+
* @param item - The rule set condition to make serializable. Can be:
|
|
25
|
+
* - RspackRuleSetCondition: Rspack-specific rule conditions
|
|
26
|
+
* - WebpackRuleSetConditionAbsolute: Webpack absolute rule conditions
|
|
27
|
+
* - WebpackRuleSetCondition: Webpack rule conditions
|
|
28
|
+
* - void: Undefined or null values
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const condition = /\.js$/;
|
|
33
|
+
* JSON.stringify(condition); // Error: Converting circular structure to JSON
|
|
34
|
+
*
|
|
35
|
+
* makeRuleSetSerializable(condition);
|
|
36
|
+
* JSON.stringify(condition); // '"/\\.js$/"'
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function makeRuleSetSerializable(item: RspackRuleSetCondition | WebpackRuleSetConditionAbsolute | WebpackRuleSetCondition | void): void;
|
|
40
|
+
export declare function makeRulesSerializable(rules: Plugin.RuleSetRule[] | RspackRuleSetRule['oneOf'] | WebpackRuleSetRule['oneOf']): void;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Configuration } from '@rspack/core';
|
|
2
|
+
/**
|
|
3
|
+
* Safe cloneDeep implementation that skips read-only properties (getters without setters)
|
|
4
|
+
* to avoid errors when cloning objects like AppContext that have read-only properties
|
|
5
|
+
*/
|
|
6
|
+
export declare function safeCloneDeep<T>(value: T, visited?: WeakMap<WeakKey, any>): T;
|
|
7
|
+
/**
|
|
8
|
+
* Process compiler configuration to make it serializable
|
|
9
|
+
*/
|
|
10
|
+
export declare function processCompilerConfig(config: any): Configuration;
|
|
11
|
+
export declare function handleBriefModeReport(sdk: any, options: any, disableClientServer: boolean): Promise<void>;
|
|
@@ -57,10 +57,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
57
57
|
hook.intercept({
|
|
58
58
|
register (tap) {
|
|
59
59
|
const o = tap.fn;
|
|
60
|
-
if ('sync' === tap.type) tap.fn = function() {
|
|
60
|
+
if ('sync' === tap.type) tap.fn = function(...args) {
|
|
61
61
|
const start = Date.now();
|
|
62
62
|
try {
|
|
63
|
-
const res = o.apply(this,
|
|
63
|
+
const res = o.apply(this, args);
|
|
64
64
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
65
65
|
return res;
|
|
66
66
|
} catch (error) {
|
|
@@ -68,10 +68,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
68
68
|
throw error;
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
|
-
else if ('async' === tap.type) tap.fn = async function() {
|
|
71
|
+
else if ('async' === tap.type) tap.fn = async function(...args) {
|
|
72
72
|
const start = Date.now();
|
|
73
73
|
try {
|
|
74
|
-
const res = await o.apply(this,
|
|
74
|
+
const res = await o.apply(this, args);
|
|
75
75
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
76
76
|
return res;
|
|
77
77
|
} catch (error) {
|
|
@@ -79,10 +79,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
79
79
|
throw error;
|
|
80
80
|
}
|
|
81
81
|
};
|
|
82
|
-
else if ('promise' === tap.type) tap.fn = function() {
|
|
82
|
+
else if ('promise' === tap.type) tap.fn = function(...args) {
|
|
83
83
|
const start = Date.now();
|
|
84
|
-
const isChild =
|
|
85
|
-
return o.apply(this,
|
|
84
|
+
const isChild = args?.[0]?.compiler?.isChild();
|
|
85
|
+
return o.apply(this, args).then((res)=>{
|
|
86
86
|
if (isChild) return res;
|
|
87
87
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
88
88
|
return res;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SDK } from '@rsdoctor/types';
|
|
2
|
+
import { IHook } from '../../build-utils/build/utils';
|
|
3
|
+
export declare function reportPluginData(sdk: SDK.RsdoctorBuilderSDKInstance, hook: string, tapName: string, start: number, type: SDK.PluginHookData['type'], _res: unknown, err?: Error): void;
|
|
4
|
+
export declare function interceptPluginHook(sdk: SDK.RsdoctorBuilderSDKInstance, name: string, hook: IHook): void;
|
|
@@ -29,10 +29,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
29
29
|
hook.intercept({
|
|
30
30
|
register (tap) {
|
|
31
31
|
const o = tap.fn;
|
|
32
|
-
if ('sync' === tap.type) tap.fn = function() {
|
|
32
|
+
if ('sync' === tap.type) tap.fn = function(...args) {
|
|
33
33
|
const start = Date.now();
|
|
34
34
|
try {
|
|
35
|
-
const res = o.apply(this,
|
|
35
|
+
const res = o.apply(this, args);
|
|
36
36
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
37
37
|
return res;
|
|
38
38
|
} catch (error) {
|
|
@@ -40,10 +40,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
40
40
|
throw error;
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
|
-
else if ('async' === tap.type) tap.fn = async function() {
|
|
43
|
+
else if ('async' === tap.type) tap.fn = async function(...args) {
|
|
44
44
|
const start = Date.now();
|
|
45
45
|
try {
|
|
46
|
-
const res = await o.apply(this,
|
|
46
|
+
const res = await o.apply(this, args);
|
|
47
47
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
48
48
|
return res;
|
|
49
49
|
} catch (error) {
|
|
@@ -51,10 +51,10 @@ function interceptPluginHook(sdk, name, hook) {
|
|
|
51
51
|
throw error;
|
|
52
52
|
}
|
|
53
53
|
};
|
|
54
|
-
else if ('promise' === tap.type) tap.fn = function() {
|
|
54
|
+
else if ('promise' === tap.type) tap.fn = function(...args) {
|
|
55
55
|
const start = Date.now();
|
|
56
|
-
const isChild =
|
|
57
|
-
return o.apply(this,
|
|
56
|
+
const isChild = args?.[0]?.compiler?.isChild();
|
|
57
|
+
return o.apply(this, args).then((res)=>{
|
|
58
58
|
if (isChild) return res;
|
|
59
59
|
reportPluginData(sdk, name, tap.name, start, tap.type, res);
|
|
60
60
|
return res;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RsdoctorPrimarySDK } from '@rsdoctor/sdk';
|
|
2
|
+
import { SDK } from '@rsdoctor/types';
|
|
3
|
+
declare global {
|
|
4
|
+
var __rsdoctor_sdks__: SDK.RsdoctorBuilderSDKInstance[] | undefined;
|
|
5
|
+
var __rsdoctor_sdk__: SDK.RsdoctorBuilderSDKInstance | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare function setSDK(t: SDK.RsdoctorBuilderSDKInstance): void;
|
|
8
|
+
export declare function getSDK(builderName?: string): RsdoctorPrimarySDK | SDK.RsdoctorBuilderSDKInstance | undefined;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Linter as LinterType, SDK } from '@rsdoctor/types';
|
|
2
|
+
export { LinterType };
|
|
3
|
+
export declare class Linter<Rules extends LinterType.ExtendRuleData[]> {
|
|
4
|
+
private rules;
|
|
5
|
+
constructor({ rules, extends: extendRules, level, }?: LinterType.Options<Rules>);
|
|
6
|
+
private getRules;
|
|
7
|
+
validate(context: SDK.RuntimeContext): Promise<LinterType.ValidateResult>;
|
|
8
|
+
afterValidate(context: LinterType.InternalRuleCheckerContextForCheckEnd): Promise<void>;
|
|
9
|
+
}
|
package/dist/rules/rule.cjs
CHANGED
|
@@ -84,7 +84,7 @@ class Rule {
|
|
|
84
84
|
const replace = [];
|
|
85
85
|
const report = (data, remove)=>{
|
|
86
86
|
if (remove) replace.push(remove);
|
|
87
|
-
|
|
87
|
+
const severity = data.severity ? (0, external_utils_cjs_namespaceObject.toSeverity)(data.severity, this.severity) : this.severity;
|
|
88
88
|
const error = {
|
|
89
89
|
...data,
|
|
90
90
|
code: this.code,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Linter, SDK, Rule as RuleTypes } from '@rsdoctor/types';
|
|
2
|
+
import { LinterType } from './linter';
|
|
3
|
+
type DefaultRuleConfig = Linter.DefaultRuleConfig;
|
|
4
|
+
export declare class Rule<Config = DefaultRuleConfig> implements Linter.RuleMeta<Config> {
|
|
5
|
+
static from<C>(data: Linter.ExtendRuleData<C>): Rule<C>;
|
|
6
|
+
readonly meta: Linter.RuleMeta<Config>;
|
|
7
|
+
private check;
|
|
8
|
+
/**
|
|
9
|
+
* execute when check end
|
|
10
|
+
*/
|
|
11
|
+
private onCheckEnd;
|
|
12
|
+
private _severity;
|
|
13
|
+
private _config?;
|
|
14
|
+
constructor(data: Linter.RuleData<Config>);
|
|
15
|
+
get code(): RuleTypes.RuleMessageCode;
|
|
16
|
+
get title(): string;
|
|
17
|
+
get severity(): Linter.Severity;
|
|
18
|
+
get config(): Config | undefined;
|
|
19
|
+
get category(): "compile" | "bundle" | RuleTypes.RuleMessageCategory | "emo";
|
|
20
|
+
setOption(opt: Linter.RuleConfigItem): void;
|
|
21
|
+
match(level: Linter.Severity): boolean;
|
|
22
|
+
validate(context: SDK.RuntimeContext): Promise<Linter.ValidateResult>;
|
|
23
|
+
afterValidate({ hooks, validateResult, data, }: LinterType.InternalRuleCheckerContextForCheckEnd<Config>): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export declare function defineRule<Title extends Linter.DefaultRuleTitle, T = Linter.DefaultRuleConfig>(ruleCreator: Linter.ExtendRuleConstructor<Title, T>): Linter.ExtendRuleData<T, Title>;
|
|
26
|
+
export declare function defineRule<Title extends Linter.DefaultRuleTitle, T = Linter.DefaultRuleConfig>(ruleCreator: Linter.RuleConstructor<Title, T>): Linter.RuleData<T, Title>;
|
|
27
|
+
export {};
|
package/dist/rules/rule.js
CHANGED
|
@@ -56,7 +56,7 @@ class rule_Rule {
|
|
|
56
56
|
const replace = [];
|
|
57
57
|
const report = (data, remove)=>{
|
|
58
58
|
if (remove) replace.push(remove);
|
|
59
|
-
|
|
59
|
+
const severity = data.severity ? toSeverity(data.severity, this.severity) : this.severity;
|
|
60
60
|
const error = {
|
|
61
61
|
...data,
|
|
62
62
|
code: this.code,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getErrorMsgForDupPckChunks(chunks: string[], pkgName: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Node, Range } from '@rsdoctor/utils/ruleUtils';
|
|
2
|
+
import type { SDK, Linter } from '@rsdoctor/types';
|
|
3
|
+
export declare function getDefaultImportByRequest(node: Node.Program, request: string): Node.ImportDeclaration | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Determine that it contains the same left value assignment expression in the enumeration.
|
|
6
|
+
*/
|
|
7
|
+
export declare function hasSameLeftInAssignStatement(node: Node.Program, compare: Node.SyntaxNode[]): Node.Pattern | undefined;
|
|
8
|
+
export declare function importDeclarationToString(node: Node.ImportDeclaration): string;
|
|
9
|
+
export declare function getFixData(module: SDK.ModuleInstance, node: Node.ImportDeclaration, originalRange: Range): Linter.FixData;
|
|
10
|
+
export declare function getSourceRangeFromTransformedOffset(module: SDK.ModuleInstance, node: Node.SyntaxNode): Linter.ReportDocument | undefined;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare enum CheckVersion {
|
|
2
|
+
null = 0,
|
|
3
|
+
prerelease = 1,
|
|
4
|
+
prepatch = 16,
|
|
5
|
+
patch = 256,
|
|
6
|
+
preminor = 4096,
|
|
7
|
+
minor = 65536,
|
|
8
|
+
premajor = 1048576,
|
|
9
|
+
major = 16777216
|
|
10
|
+
}
|
|
11
|
+
export declare enum CheckVersionMap {
|
|
12
|
+
null = 0,
|
|
13
|
+
prerelease = 1,
|
|
14
|
+
prepatch = 17,
|
|
15
|
+
patch = 273,
|
|
16
|
+
preminor = 4369,
|
|
17
|
+
minor = 69905,
|
|
18
|
+
premajor = 1118481,
|
|
19
|
+
major = 17895697
|
|
20
|
+
}
|
|
21
|
+
export interface Config {
|
|
22
|
+
checkVersion: keyof typeof CheckVersion;
|
|
23
|
+
ignore: string[];
|
|
24
|
+
}
|
|
@@ -42,6 +42,16 @@ var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_na
|
|
|
42
42
|
const types_namespaceObject = require("@rsdoctor/types");
|
|
43
43
|
const external_rule_cjs_namespaceObject = require("../../rule.cjs");
|
|
44
44
|
const title = 'esm-resolved-to-cjs';
|
|
45
|
+
function normalizePathForCompare(filePath) {
|
|
46
|
+
const queryIndex = filePath.indexOf('?');
|
|
47
|
+
const hashIndex = filePath.indexOf('#');
|
|
48
|
+
const splitIndex = [
|
|
49
|
+
queryIndex,
|
|
50
|
+
hashIndex
|
|
51
|
+
].filter((index)=>index >= 0).reduce((min, index)=>Math.min(min, index), 1 / 0);
|
|
52
|
+
const cleanPath = splitIndex === 1 / 0 ? filePath : filePath.slice(0, splitIndex);
|
|
53
|
+
return external_path_default().normalize(cleanPath);
|
|
54
|
+
}
|
|
45
55
|
function extractEsmEntry(pkgJson, pkgRoot) {
|
|
46
56
|
const { exports: exportsField, module: moduleField } = pkgJson;
|
|
47
57
|
if (null !== exportsField && 'object' == typeof exportsField) {
|
|
@@ -78,6 +88,7 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
78
88
|
},
|
|
79
89
|
check ({ moduleGraph, packageGraph, report, ruleConfig }) {
|
|
80
90
|
const pkgJsonCache = new Map();
|
|
91
|
+
const realPathCache = new Map();
|
|
81
92
|
const readPkgJson = (pkgRoot)=>{
|
|
82
93
|
if (pkgJsonCache.has(pkgRoot)) return pkgJsonCache.get(pkgRoot);
|
|
83
94
|
try {
|
|
@@ -90,14 +101,31 @@ const rule = (0, external_rule_cjs_namespaceObject.defineRule)(()=>({
|
|
|
90
101
|
return null;
|
|
91
102
|
}
|
|
92
103
|
};
|
|
104
|
+
const toRealPath = (filePath)=>{
|
|
105
|
+
const normalized = normalizePathForCompare(filePath);
|
|
106
|
+
if (realPathCache.has(normalized)) return realPathCache.get(normalized);
|
|
107
|
+
try {
|
|
108
|
+
const realPath = 'function' == typeof external_fs_default().realpathSync.native ? external_fs_default().realpathSync.native(normalized) : external_fs_default().realpathSync(normalized);
|
|
109
|
+
const normalizedRealPath = external_path_default().normalize(realPath);
|
|
110
|
+
realPathCache.set(normalized, normalizedRealPath);
|
|
111
|
+
return normalizedRealPath;
|
|
112
|
+
} catch {
|
|
113
|
+
realPathCache.set(normalized, normalized);
|
|
114
|
+
return normalized;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
93
117
|
const groups = new Map();
|
|
94
118
|
const inNodeModules = /[/\\]node_modules[/\\]/;
|
|
95
119
|
for (const dep of moduleGraph.getDependencies()){
|
|
96
120
|
if (dep.kind !== types_namespaceObject.SDK.DependencyKind.ImportStatement || inNodeModules.test(dep.module.path) || !inNodeModules.test(dep.dependency.path) || dep.dependency.meta.strictHarmonyModule || ruleConfig.ignore.some((p)=>dep.request.includes(p))) continue;
|
|
97
121
|
const pkg = packageGraph.getPackageByModule(dep.dependency);
|
|
98
|
-
|
|
122
|
+
if (!pkg?.root) continue;
|
|
123
|
+
const pkgJson = readPkgJson(pkg.root);
|
|
124
|
+
const esmEntry = !ruleConfig.ignore.some((p)=>pkg.name.includes(p)) && pkgJson && extractEsmEntry(pkgJson, pkg.root);
|
|
99
125
|
if (!esmEntry) continue;
|
|
100
|
-
const
|
|
126
|
+
const resolvedModuleRealPath = toRealPath(dep.dependency.path);
|
|
127
|
+
if (resolvedModuleRealPath === toRealPath(esmEntry)) continue;
|
|
128
|
+
const groupKey = `${pkg.name}::${resolvedModuleRealPath}`;
|
|
101
129
|
const issuer = {
|
|
102
130
|
id: dep.module.id,
|
|
103
131
|
path: dep.module.path,
|
|
@@ -4,6 +4,16 @@ import path from "path";
|
|
|
4
4
|
import { Linter, SDK } from "@rsdoctor/types";
|
|
5
5
|
import { defineRule } from "../../rule.js";
|
|
6
6
|
const title = 'esm-resolved-to-cjs';
|
|
7
|
+
function normalizePathForCompare(filePath) {
|
|
8
|
+
const queryIndex = filePath.indexOf('?');
|
|
9
|
+
const hashIndex = filePath.indexOf('#');
|
|
10
|
+
const splitIndex = [
|
|
11
|
+
queryIndex,
|
|
12
|
+
hashIndex
|
|
13
|
+
].filter((index)=>index >= 0).reduce((min, index)=>Math.min(min, index), 1 / 0);
|
|
14
|
+
const cleanPath = splitIndex === 1 / 0 ? filePath : filePath.slice(0, splitIndex);
|
|
15
|
+
return path.normalize(cleanPath);
|
|
16
|
+
}
|
|
7
17
|
function extractEsmEntry(pkgJson, pkgRoot) {
|
|
8
18
|
const { exports: exportsField, module: moduleField } = pkgJson;
|
|
9
19
|
if (null !== exportsField && 'object' == typeof exportsField) {
|
|
@@ -40,6 +50,7 @@ const rule = defineRule(()=>({
|
|
|
40
50
|
},
|
|
41
51
|
check ({ moduleGraph, packageGraph, report, ruleConfig }) {
|
|
42
52
|
const pkgJsonCache = new Map();
|
|
53
|
+
const realPathCache = new Map();
|
|
43
54
|
const readPkgJson = (pkgRoot)=>{
|
|
44
55
|
if (pkgJsonCache.has(pkgRoot)) return pkgJsonCache.get(pkgRoot);
|
|
45
56
|
try {
|
|
@@ -52,14 +63,31 @@ const rule = defineRule(()=>({
|
|
|
52
63
|
return null;
|
|
53
64
|
}
|
|
54
65
|
};
|
|
66
|
+
const toRealPath = (filePath)=>{
|
|
67
|
+
const normalized = normalizePathForCompare(filePath);
|
|
68
|
+
if (realPathCache.has(normalized)) return realPathCache.get(normalized);
|
|
69
|
+
try {
|
|
70
|
+
const realPath = 'function' == typeof fs.realpathSync.native ? fs.realpathSync.native(normalized) : fs.realpathSync(normalized);
|
|
71
|
+
const normalizedRealPath = path.normalize(realPath);
|
|
72
|
+
realPathCache.set(normalized, normalizedRealPath);
|
|
73
|
+
return normalizedRealPath;
|
|
74
|
+
} catch {
|
|
75
|
+
realPathCache.set(normalized, normalized);
|
|
76
|
+
return normalized;
|
|
77
|
+
}
|
|
78
|
+
};
|
|
55
79
|
const groups = new Map();
|
|
56
80
|
const inNodeModules = /[/\\]node_modules[/\\]/;
|
|
57
81
|
for (const dep of moduleGraph.getDependencies()){
|
|
58
82
|
if (dep.kind !== SDK.DependencyKind.ImportStatement || inNodeModules.test(dep.module.path) || !inNodeModules.test(dep.dependency.path) || dep.dependency.meta.strictHarmonyModule || ruleConfig.ignore.some((p)=>dep.request.includes(p))) continue;
|
|
59
83
|
const pkg = packageGraph.getPackageByModule(dep.dependency);
|
|
60
|
-
|
|
84
|
+
if (!pkg?.root) continue;
|
|
85
|
+
const pkgJson = readPkgJson(pkg.root);
|
|
86
|
+
const esmEntry = !ruleConfig.ignore.some((p)=>pkg.name.includes(p)) && pkgJson && extractEsmEntry(pkgJson, pkg.root);
|
|
61
87
|
if (!esmEntry) continue;
|
|
62
|
-
const
|
|
88
|
+
const resolvedModuleRealPath = toRealPath(dep.dependency.path);
|
|
89
|
+
if (resolvedModuleRealPath === toRealPath(esmEntry)) continue;
|
|
90
|
+
const groupKey = `${pkg.name}::${resolvedModuleRealPath}`;
|
|
63
91
|
const issuer = {
|
|
64
92
|
id: dep.module.id,
|
|
65
93
|
path: dep.module.path,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const rules: (import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./duplicate-package").Config, "duplicate-package"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./default-import-check").Config, "default-import-check"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./loader-performance-optimization").Config, "loader-performance-optimization"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./ecma-version-check").Config, "ecma-version-check"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./cross-chunks-package").Config, "cross-chunks-package"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./module-mixed-chunks").Config, "module-mixed-chunks"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./side-effects-only-imports").Config, "tree-shaking-side-effects-only"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./cjs-require").Config, "cjs-require"> | import("node_modules/@rsdoctor/types/dist/linter").RuleData<import("./esm-resolved-to-cjs").Config, "esm-resolved-to-cjs">)[];
|