@rsdoctor/types 0.0.2-beta.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/LICENSE +21 -0
- package/README.md +15 -0
- package/dist/babel.d.ts +13 -0
- package/dist/babel.js +2 -0
- package/dist/client.d.ts +108 -0
- package/dist/client.js +29 -0
- package/dist/common.d.ts +26 -0
- package/dist/common.js +2 -0
- package/dist/constants.d.ts +16 -0
- package/dist/constants.js +36 -0
- package/dist/emo.d.ts +28 -0
- package/dist/emo.js +9 -0
- package/dist/error.d.ts +137 -0
- package/dist/error.js +10 -0
- package/dist/esbuild.d.ts +30 -0
- package/dist/esbuild.js +2 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +40 -0
- package/dist/linter/diagnostic.d.ts +45 -0
- package/dist/linter/diagnostic.js +5 -0
- package/dist/linter/index.d.ts +2 -0
- package/dist/linter/index.js +18 -0
- package/dist/linter/rule.d.ts +107 -0
- package/dist/linter/rule.js +2 -0
- package/dist/logger.d.ts +34 -0
- package/dist/logger.js +15 -0
- package/dist/manifest.d.ts +55 -0
- package/dist/manifest.js +17 -0
- package/dist/modules.d.ts +7 -0
- package/dist/modules.js +2 -0
- package/dist/plugin/baseCompiler.d.ts +20 -0
- package/dist/plugin/baseCompiler.js +2 -0
- package/dist/plugin/baseLoader.d.ts +71 -0
- package/dist/plugin/baseLoader.js +2 -0
- package/dist/plugin/baseStats.d.ts +114 -0
- package/dist/plugin/baseStats.js +2 -0
- package/dist/plugin/index.d.ts +4 -0
- package/dist/plugin/index.js +20 -0
- package/dist/plugin/plugin.d.ts +32 -0
- package/dist/plugin/plugin.js +2 -0
- package/dist/rule/code/E1001.d.ts +3 -0
- package/dist/rule/code/E1001.js +31 -0
- package/dist/rule/code/E1002.d.ts +3 -0
- package/dist/rule/code/E1002.js +31 -0
- package/dist/rule/code/E1003.d.ts +3 -0
- package/dist/rule/code/E1003.js +39 -0
- package/dist/rule/code/E1004.d.ts +3 -0
- package/dist/rule/code/E1004.js +15 -0
- package/dist/rule/code/index.d.ts +23 -0
- package/dist/rule/code/index.js +51 -0
- package/dist/rule/code/type.d.ts +27 -0
- package/dist/rule/code/type.js +23 -0
- package/dist/rule/data.d.ts +132 -0
- package/dist/rule/data.js +2 -0
- package/dist/rule/index.d.ts +2 -0
- package/dist/rule/index.js +18 -0
- package/dist/sdk/chunk.d.ts +125 -0
- package/dist/sdk/chunk.js +2 -0
- package/dist/sdk/config.d.ts +8 -0
- package/dist/sdk/config.js +2 -0
- package/dist/sdk/context.d.ts +23 -0
- package/dist/sdk/context.js +2 -0
- package/dist/sdk/envinfo.d.ts +19 -0
- package/dist/sdk/envinfo.js +2 -0
- package/dist/sdk/hooks.d.ts +13 -0
- package/dist/sdk/hooks.js +2 -0
- package/dist/sdk/index.d.ts +16 -0
- package/dist/sdk/index.js +32 -0
- package/dist/sdk/instance.d.ts +149 -0
- package/dist/sdk/instance.js +2 -0
- package/dist/sdk/loader.d.ts +64 -0
- package/dist/sdk/loader.js +2 -0
- package/dist/sdk/module.d.ts +303 -0
- package/dist/sdk/module.js +28 -0
- package/dist/sdk/package.d.ts +113 -0
- package/dist/sdk/package.js +2 -0
- package/dist/sdk/plugin.d.ts +21 -0
- package/dist/sdk/plugin.js +2 -0
- package/dist/sdk/process.d.ts +10 -0
- package/dist/sdk/process.js +2 -0
- package/dist/sdk/resolver.d.ts +52 -0
- package/dist/sdk/resolver.js +2 -0
- package/dist/sdk/result.d.ts +41 -0
- package/dist/sdk/result.js +2 -0
- package/dist/sdk/server/apis/alerts.d.ts +26 -0
- package/dist/sdk/server/apis/alerts.js +3 -0
- package/dist/sdk/server/apis/graph.d.ts +41 -0
- package/dist/sdk/server/apis/graph.js +3 -0
- package/dist/sdk/server/apis/index.d.ts +128 -0
- package/dist/sdk/server/apis/index.js +72 -0
- package/dist/sdk/server/apis/loader.d.ts +46 -0
- package/dist/sdk/server/apis/loader.js +3 -0
- package/dist/sdk/server/apis/pagination.d.ts +11 -0
- package/dist/sdk/server/apis/pagination.js +2 -0
- package/dist/sdk/server/apis/plugin.d.ts +19 -0
- package/dist/sdk/server/apis/plugin.js +3 -0
- package/dist/sdk/server/apis/project.d.ts +16 -0
- package/dist/sdk/server/apis/project.js +3 -0
- package/dist/sdk/server/apis/resolver.d.ts +18 -0
- package/dist/sdk/server/apis/resolver.js +3 -0
- package/dist/sdk/server/index.d.ts +23 -0
- package/dist/sdk/server/index.js +27 -0
- package/dist/sdk/statement.d.ts +177 -0
- package/dist/sdk/statement.js +147 -0
- package/dist/sdk/summary.d.ts +18 -0
- package/dist/sdk/summary.js +2 -0
- package/dist/sdk/treeShaking.d.ts +152 -0
- package/dist/sdk/treeShaking.js +2 -0
- package/dist/thirdparty.d.ts +2 -0
- package/dist/thirdparty.js +2 -0
- package/package.json +39 -0
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import type { ArrayToUnion, UnionToTuple } from '../common';
|
|
2
|
+
import type { ErrorLevel as Severity } from '../error';
|
|
3
|
+
import type { Hooks, RuntimeContext } from '../sdk';
|
|
4
|
+
import type { ReportData, Diagnostic } from './diagnostic';
|
|
5
|
+
import type { RuleMessage } from '../rule';
|
|
6
|
+
/** Error level */
|
|
7
|
+
export type SeverityString = keyof typeof Severity;
|
|
8
|
+
/** Error level */
|
|
9
|
+
export type SeverityInput = SeverityString | 'off' | 'on';
|
|
10
|
+
/** Rule configuration */
|
|
11
|
+
export type DefaultRuleConfig = any;
|
|
12
|
+
export type DefaultRuleTitle = string;
|
|
13
|
+
/** Rule check context */
|
|
14
|
+
export interface RuleCheckerContext<Config = DefaultRuleConfig> extends RuntimeContext {
|
|
15
|
+
ruleConfig: Config;
|
|
16
|
+
/**
|
|
17
|
+
* Report an error
|
|
18
|
+
* @param {any} error - error data
|
|
19
|
+
* @param {any} replacer - replace the original error
|
|
20
|
+
*/
|
|
21
|
+
report(error: ReportData, replacer?: any): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* we shouldn't report any errors when the rule check end, so remove the report function on the context.
|
|
25
|
+
*/
|
|
26
|
+
export interface RuleCheckerContextForCheckEnd<Config = DefaultRuleConfig> {
|
|
27
|
+
/**
|
|
28
|
+
* data of the rule.
|
|
29
|
+
*/
|
|
30
|
+
data: Omit<RuleCheckerContext<Config>, 'report'>;
|
|
31
|
+
/**
|
|
32
|
+
* the validate result for `all` rules.
|
|
33
|
+
*/
|
|
34
|
+
validateResult: ValidateResult;
|
|
35
|
+
/**
|
|
36
|
+
* sdk hooks for rule context when check end.
|
|
37
|
+
*
|
|
38
|
+
* rules checking always run after builder compile done, so it must be a part of SDK.Hooks.
|
|
39
|
+
*/
|
|
40
|
+
hooks: Pick<Hooks, 'afterSaveManifest'>;
|
|
41
|
+
}
|
|
42
|
+
export interface InternalRuleCheckerContextForCheckEnd<Config = DefaultRuleConfig> extends Omit<RuleCheckerContextForCheckEnd<Config>, 'data'> {
|
|
43
|
+
data: Omit<RuleCheckerContext<Config>, 'report' | 'ruleConfig'>;
|
|
44
|
+
}
|
|
45
|
+
export type CheckCallback<Config = DefaultRuleConfig> = (context: RuleCheckerContext<Config>) => void | Promise<void>;
|
|
46
|
+
export type OnCheckEndCallback<Config = DefaultRuleConfig> = (context: RuleCheckerContextForCheckEnd<Config>) => void | Promise<void>;
|
|
47
|
+
/** Rule Metadata */
|
|
48
|
+
export interface RuleMeta<Config = DefaultRuleConfig, Title extends DefaultRuleTitle = DefaultRuleTitle> extends Pick<RuleMessage, 'code' | 'category'> {
|
|
49
|
+
title: Title;
|
|
50
|
+
severity: Severity;
|
|
51
|
+
/** Detailed document link */
|
|
52
|
+
referenceUrl?: string;
|
|
53
|
+
/** Default configuration */
|
|
54
|
+
defaultConfig?: Config;
|
|
55
|
+
}
|
|
56
|
+
export interface BaseRuleData<Config> {
|
|
57
|
+
check: CheckCallback<Config>;
|
|
58
|
+
/**
|
|
59
|
+
* execute when all rules check end.
|
|
60
|
+
*/
|
|
61
|
+
onCheckEnd?: OnCheckEndCallback<Config>;
|
|
62
|
+
}
|
|
63
|
+
/** Rule Data */
|
|
64
|
+
export interface RuleData<Config = DefaultRuleConfig, Title extends DefaultRuleTitle = DefaultRuleTitle> extends BaseRuleData<Config> {
|
|
65
|
+
meta: RuleMeta<Config, Title>;
|
|
66
|
+
}
|
|
67
|
+
/** External Rule Metadata */
|
|
68
|
+
export interface ExtendRuleMeta<Config = DefaultRuleConfig, Title extends DefaultRuleTitle = DefaultRuleTitle> extends Omit<RuleMeta<Config, Title>, 'severity' | 'code'> {
|
|
69
|
+
severity: SeverityString;
|
|
70
|
+
}
|
|
71
|
+
/** External rule data */
|
|
72
|
+
export interface ExtendRuleData<Config = DefaultRuleConfig, Title extends DefaultRuleTitle = DefaultRuleTitle> extends BaseRuleData<Config> {
|
|
73
|
+
meta: ExtendRuleMeta<Config, Title>;
|
|
74
|
+
}
|
|
75
|
+
/** rule constructor */
|
|
76
|
+
export type RuleConstructor<Title extends DefaultRuleTitle, Config = DefaultRuleConfig> = () => RuleData<Config, Title>;
|
|
77
|
+
/** External rule constructor */
|
|
78
|
+
export type ExtendRuleConstructor<Title extends DefaultRuleTitle, Config = DefaultRuleConfig> = () => ExtendRuleData<Config, Title>;
|
|
79
|
+
/** Rule configuration */
|
|
80
|
+
export type RulesMap = Record<string, RuleConfigItem>;
|
|
81
|
+
/** Single rule configuration */
|
|
82
|
+
export type RuleConfigItem<T = unknown> = SeverityInput | [SeverityInput, T];
|
|
83
|
+
/** Verification result */
|
|
84
|
+
export interface ValidateResult {
|
|
85
|
+
errors: Diagnostic[];
|
|
86
|
+
replace: any[];
|
|
87
|
+
}
|
|
88
|
+
/** Verifier options */
|
|
89
|
+
export interface Options<Extends extends ExtendRuleData[] = [], InternalRules extends RuleData[] = [], _Extends = UnionToTuple<ArrayToUnion<[...Extends]>>> {
|
|
90
|
+
rules?: InferRulesConfig<_Extends extends ExtendRuleData[] ? _Extends : Extends> & InferRulesConfig<InternalRules>;
|
|
91
|
+
level?: SeverityString;
|
|
92
|
+
extends?: Extends;
|
|
93
|
+
}
|
|
94
|
+
type InferRuleTitle<T extends ExtendRuleData | RuleData> = T['meta']['title'] extends `${infer R}` ? R : string;
|
|
95
|
+
type InferRulesTitles<T extends (ExtendRuleData | RuleData)[]> = ArrayToUnion<{
|
|
96
|
+
[K in keyof T]: InferRuleTitle<T[K]>;
|
|
97
|
+
}>;
|
|
98
|
+
type InferRuleConfigByTitle<T extends (ExtendRuleData | RuleData)[], Title extends string> = {
|
|
99
|
+
[K in keyof T]: InferRuleTitle<T[K]> extends Title ? InferRuleConfig<T[K]> : never;
|
|
100
|
+
}[number];
|
|
101
|
+
export type InferRuleConfig<T> = T extends ExtendRuleData<infer P1> ? P1 : T extends RuleData<infer P2> ? P2 : any;
|
|
102
|
+
export type InferRulesConfig<T extends (ExtendRuleData | RuleData)[]> = {
|
|
103
|
+
[K in InferRulesTitles<T>]?: RuleConfigItem<InferRuleConfigByTitle<T, K>>;
|
|
104
|
+
} & {
|
|
105
|
+
[key: string]: RuleConfigItem;
|
|
106
|
+
};
|
|
107
|
+
export {};
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare enum LogLevel {
|
|
2
|
+
Silent = 0,
|
|
3
|
+
Error = 1,
|
|
4
|
+
Warning = 2,
|
|
5
|
+
Info = 3,
|
|
6
|
+
Debug = 4,
|
|
7
|
+
Verbose = 5
|
|
8
|
+
}
|
|
9
|
+
export type LogLevelName = keyof typeof LogLevel;
|
|
10
|
+
export interface LoggerOptions {
|
|
11
|
+
/**
|
|
12
|
+
* Default is `info`.
|
|
13
|
+
*/
|
|
14
|
+
level?: LogLevelName;
|
|
15
|
+
/**
|
|
16
|
+
* Default is `false`.
|
|
17
|
+
*/
|
|
18
|
+
timestamp?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Default is empty string
|
|
21
|
+
*/
|
|
22
|
+
prefix?: string;
|
|
23
|
+
}
|
|
24
|
+
type Label = string;
|
|
25
|
+
export declare abstract class LoggerInstance {
|
|
26
|
+
abstract timesLog: Map<Label, number>;
|
|
27
|
+
abstract info(...msg: string[]): void;
|
|
28
|
+
abstract warn(...msg: string[]): void;
|
|
29
|
+
abstract error(...msg: string[]): void;
|
|
30
|
+
abstract debug(...msg: string[]): void;
|
|
31
|
+
abstract time(label: Label): void;
|
|
32
|
+
abstract timeEnd(label: Label): void;
|
|
33
|
+
}
|
|
34
|
+
export {};
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LoggerInstance = exports.LogLevel = void 0;
|
|
4
|
+
var LogLevel;
|
|
5
|
+
(function (LogLevel) {
|
|
6
|
+
LogLevel[LogLevel["Silent"] = 0] = "Silent";
|
|
7
|
+
LogLevel[LogLevel["Error"] = 1] = "Error";
|
|
8
|
+
LogLevel[LogLevel["Warning"] = 2] = "Warning";
|
|
9
|
+
LogLevel[LogLevel["Info"] = 3] = "Info";
|
|
10
|
+
LogLevel[LogLevel["Debug"] = 4] = "Debug";
|
|
11
|
+
LogLevel[LogLevel["Verbose"] = 5] = "Verbose";
|
|
12
|
+
})(LogLevel || (exports.LogLevel = LogLevel = {}));
|
|
13
|
+
class LoggerInstance {
|
|
14
|
+
}
|
|
15
|
+
exports.LoggerInstance = LoggerInstance;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { PlainObject, ObjectPropertyNames } from './common';
|
|
2
|
+
import { StoreData } from './sdk';
|
|
3
|
+
export interface DoctorManifest {
|
|
4
|
+
client: DoctorManifestClient;
|
|
5
|
+
data: DoctorManifestData;
|
|
6
|
+
/** current build name */
|
|
7
|
+
name?: string;
|
|
8
|
+
/**
|
|
9
|
+
* multiple build info
|
|
10
|
+
*/
|
|
11
|
+
series?: DoctorManifestSeriesData[];
|
|
12
|
+
}
|
|
13
|
+
export interface DoctorManifestSeriesData {
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
stage: number;
|
|
17
|
+
origin?: string;
|
|
18
|
+
}
|
|
19
|
+
export interface DoctorManifestWithShardingFiles extends Omit<DoctorManifest, 'data'> {
|
|
20
|
+
data: Record<keyof DoctorManifestData, string[] | string>;
|
|
21
|
+
/**
|
|
22
|
+
* local server will proxy the manifest content and inject `__LOCAL__SERVER__: true`
|
|
23
|
+
*/
|
|
24
|
+
__LOCAL__SERVER__?: boolean;
|
|
25
|
+
__SOCKET__URL__?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface DoctorManifestClient {
|
|
28
|
+
enableRoutes: DoctorManifestClientRoutes[];
|
|
29
|
+
}
|
|
30
|
+
export interface DoctorManifestData extends StoreData {
|
|
31
|
+
}
|
|
32
|
+
export declare enum DoctorManifestClientRoutes {
|
|
33
|
+
Overall = "Overall",
|
|
34
|
+
WebpackLoaders = "Compile.WebpackLoaders",
|
|
35
|
+
ModuleResolve = "Compile.ModuleResolve",
|
|
36
|
+
WebpackPlugins = "Compile.WebpackPlugins",
|
|
37
|
+
BundleSize = "Bundle.BundleSize",
|
|
38
|
+
ModuleGraph = "Bundle.ModuleGraph",
|
|
39
|
+
TreeShaking = "Bundle.TreeShaking"
|
|
40
|
+
}
|
|
41
|
+
export declare enum DoctorManifestClientConstant {
|
|
42
|
+
WindowPropertyForManifestUrl = "__DEVTOOLS_MANIFEST_URL__"
|
|
43
|
+
}
|
|
44
|
+
export type DoctorManifestObjectKeys = NonNullable<ObjectPropertyNames<DoctorManifestData>>;
|
|
45
|
+
export type DoctorManifestRootKeys = keyof DoctorManifestData;
|
|
46
|
+
export type DoctorManifestMappingKeys = {
|
|
47
|
+
[K in DoctorManifestObjectKeys]: DoctorManifestData[K] extends PlainObject ? DoctorManifestData[K] extends Array<unknown> ? never : string extends keyof DoctorManifestData[K] ? never : keyof DoctorManifestData[K] extends string ? `${K}.${keyof DoctorManifestData[K]}` : never : never;
|
|
48
|
+
}[DoctorManifestObjectKeys] | DoctorManifestRootKeys;
|
|
49
|
+
export type InferManifestDataValue<T> = T extends `${infer Scope}.${infer Child}` ? Scope extends DoctorManifestObjectKeys ? Child extends keyof DoctorManifestData[Scope] ? DoctorManifestData[Scope][Child] : never : never : T extends DoctorManifestRootKeys ? DoctorManifestData[T] : never;
|
|
50
|
+
export interface ManifestDataLoader {
|
|
51
|
+
loadManifest(): Promise<DoctorManifest | DoctorManifestWithShardingFiles>;
|
|
52
|
+
loadData: {
|
|
53
|
+
<T extends DoctorManifestMappingKeys>(key: T): Promise<void | InferManifestDataValue<T>>;
|
|
54
|
+
};
|
|
55
|
+
}
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DoctorManifestClientConstant = exports.DoctorManifestClientRoutes = void 0;
|
|
4
|
+
var DoctorManifestClientRoutes;
|
|
5
|
+
(function (DoctorManifestClientRoutes) {
|
|
6
|
+
DoctorManifestClientRoutes["Overall"] = "Overall";
|
|
7
|
+
DoctorManifestClientRoutes["WebpackLoaders"] = "Compile.WebpackLoaders";
|
|
8
|
+
DoctorManifestClientRoutes["ModuleResolve"] = "Compile.ModuleResolve";
|
|
9
|
+
DoctorManifestClientRoutes["WebpackPlugins"] = "Compile.WebpackPlugins";
|
|
10
|
+
DoctorManifestClientRoutes["BundleSize"] = "Bundle.BundleSize";
|
|
11
|
+
DoctorManifestClientRoutes["ModuleGraph"] = "Bundle.ModuleGraph";
|
|
12
|
+
DoctorManifestClientRoutes["TreeShaking"] = "Bundle.TreeShaking";
|
|
13
|
+
})(DoctorManifestClientRoutes || (exports.DoctorManifestClientRoutes = DoctorManifestClientRoutes = {}));
|
|
14
|
+
var DoctorManifestClientConstant;
|
|
15
|
+
(function (DoctorManifestClientConstant) {
|
|
16
|
+
DoctorManifestClientConstant["WindowPropertyForManifestUrl"] = "__DEVTOOLS_MANIFEST_URL__";
|
|
17
|
+
})(DoctorManifestClientConstant || (exports.DoctorManifestClientConstant = DoctorManifestClientConstant = {}));
|
package/dist/modules.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Compiler, Compilation, Stats, StatsError, RuleSetRule } from 'webpack';
|
|
2
|
+
import type { Compiler as RspackCompiler, Compilation as RspackCompilation, Stats as RspackStats, RuleSetRule as RspackRuleSetRule, RuleSetRules } from '@rspack/core';
|
|
3
|
+
export type BaseCompiler = (Compiler | RspackCompiler) & {
|
|
4
|
+
webpack: any;
|
|
5
|
+
};
|
|
6
|
+
export type BaseCompilation = RspackCompilation | Compilation;
|
|
7
|
+
export type BaseStats = Stats | RspackStats;
|
|
8
|
+
export interface JsStatsError {
|
|
9
|
+
message: string;
|
|
10
|
+
formatted: string;
|
|
11
|
+
title: string;
|
|
12
|
+
}
|
|
13
|
+
export interface JsStatsWarning {
|
|
14
|
+
message: string;
|
|
15
|
+
formatted: string;
|
|
16
|
+
}
|
|
17
|
+
export type BuildError = JsStatsError | StatsError;
|
|
18
|
+
export type BuildWarning = JsStatsWarning | StatsError;
|
|
19
|
+
export type BuildRuleSetRules = (RuleSetRule | '...')[] | RuleSetRules;
|
|
20
|
+
export type BuildRuleSetRule = RuleSetRule | RspackRuleSetRule;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import type { RuleSetRule as WebpackRuleSetRule, Configuration as WebpackConfiguration } from 'webpack';
|
|
3
|
+
import type { Configuration as RspackConfiguration, RuleSetRule as RspackRuleSetRule } from '@rspack/core';
|
|
4
|
+
export interface SourceMap {
|
|
5
|
+
version: number;
|
|
6
|
+
sources: string[];
|
|
7
|
+
mappings: string;
|
|
8
|
+
file?: string;
|
|
9
|
+
sourceRoot?: string;
|
|
10
|
+
sourcesContent?: string[];
|
|
11
|
+
names?: string[];
|
|
12
|
+
}
|
|
13
|
+
export type RuleSetRule = RspackRuleSetRule | WebpackRuleSetRule;
|
|
14
|
+
export type Configuration = WebpackConfiguration | RspackConfiguration;
|
|
15
|
+
declare interface AdditionalData {
|
|
16
|
+
[index: string]: any;
|
|
17
|
+
webpackAST: object;
|
|
18
|
+
}
|
|
19
|
+
export interface LoaderDefinitionFunction<OptionsType = {}, ContextAdditions = {}> {
|
|
20
|
+
(this: LoaderContext<OptionsType> & ContextAdditions, content: string, sourceMap?: string | SourceMap): string | void | Buffer | Promise<string | Buffer>;
|
|
21
|
+
}
|
|
22
|
+
export interface LoaderContext<OptionsType = {}> {
|
|
23
|
+
getOptions(schema?: any): OptionsType;
|
|
24
|
+
/**
|
|
25
|
+
* Make this loader result cacheable. By default it's cacheable.
|
|
26
|
+
* A cacheable loader must have a deterministic result, when inputs and dependencies haven't changed.
|
|
27
|
+
* This means the loader shouldn't have other dependencies than specified with this.addDependency.
|
|
28
|
+
* Most loaders are deterministic and cacheable.
|
|
29
|
+
*/
|
|
30
|
+
cacheable(flag?: boolean): void;
|
|
31
|
+
callback: (err?: null | Error, content?: string | Buffer, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => void;
|
|
32
|
+
/**
|
|
33
|
+
* The resource path.
|
|
34
|
+
* In the example: "/abc/resource.js"
|
|
35
|
+
*/
|
|
36
|
+
resourcePath: string;
|
|
37
|
+
query: string | OptionsType;
|
|
38
|
+
/**
|
|
39
|
+
* The resource query string.
|
|
40
|
+
* Example: "?query"
|
|
41
|
+
*/
|
|
42
|
+
resourceQuery: string;
|
|
43
|
+
/**
|
|
44
|
+
* The resource fragment.
|
|
45
|
+
* Example: "#frag"
|
|
46
|
+
*/
|
|
47
|
+
resourceFragment: string;
|
|
48
|
+
/**
|
|
49
|
+
* The resource inclusive query and fragment.
|
|
50
|
+
* Example: "/abc/resource.js?query#frag"
|
|
51
|
+
*/
|
|
52
|
+
resource: string;
|
|
53
|
+
async(): (err?: Error | null, content?: string | Buffer, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => void;
|
|
54
|
+
/**
|
|
55
|
+
* Target of compilation.
|
|
56
|
+
* Example: "web"
|
|
57
|
+
*/
|
|
58
|
+
target: string;
|
|
59
|
+
loaderIndex: number;
|
|
60
|
+
}
|
|
61
|
+
export declare interface PitchLoaderDefinitionFunction<OptionsType = {}, ContextAdditions = {}> {
|
|
62
|
+
(this: LoaderContext<OptionsType> & ContextAdditions, remainingRequest: string, previousRequest: string, data: object): string | void | Buffer | Promise<string | Buffer>;
|
|
63
|
+
}
|
|
64
|
+
export interface RspackPitchLoaderDefinitionFunction<OptionsType = {}, ContextAdditions = {}> {
|
|
65
|
+
(this: LoaderContext<OptionsType> & ContextAdditions, remainingRequest: string, previousRequest: string, data: object): string | void | Buffer | Promise<string | Buffer>;
|
|
66
|
+
}
|
|
67
|
+
export type LoaderDefinition<T, R> = LoaderDefinitionFunction<T, R> & {
|
|
68
|
+
raw?: false;
|
|
69
|
+
pitch?: PitchLoaderDefinitionFunction<T> | RspackPitchLoaderDefinitionFunction<T>;
|
|
70
|
+
};
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
interface StatsOptionsObj {
|
|
3
|
+
all?: boolean;
|
|
4
|
+
preset?: 'normal' | 'none' | 'verbose' | 'errors-only' | 'errors-warnings';
|
|
5
|
+
assets?: boolean;
|
|
6
|
+
chunks?: boolean;
|
|
7
|
+
modules?: boolean;
|
|
8
|
+
entrypoints?: boolean;
|
|
9
|
+
warnings?: boolean;
|
|
10
|
+
warningsCount?: boolean;
|
|
11
|
+
errors?: boolean;
|
|
12
|
+
errorsCount?: boolean;
|
|
13
|
+
colors?: boolean;
|
|
14
|
+
/** Rspack not support below opts */
|
|
15
|
+
cachedAssets?: boolean;
|
|
16
|
+
groupAssetsByInfo?: boolean;
|
|
17
|
+
groupAssetsByPath?: boolean;
|
|
18
|
+
groupAssetsByChunk?: boolean;
|
|
19
|
+
groupAssetsByExtension?: boolean;
|
|
20
|
+
groupAssetsByEmitStatus?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/** webpack not support boolean or string */
|
|
23
|
+
type StatsOptions = StatsOptionsObj;
|
|
24
|
+
interface StatsAssetInfo {
|
|
25
|
+
development?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export interface StatsAsset {
|
|
28
|
+
type: string;
|
|
29
|
+
name: string;
|
|
30
|
+
size: number;
|
|
31
|
+
chunks?: (string | number)[];
|
|
32
|
+
chunkNames?: Array<string | number>;
|
|
33
|
+
info: StatsAssetInfo;
|
|
34
|
+
}
|
|
35
|
+
interface StatsError {
|
|
36
|
+
message: string;
|
|
37
|
+
formatted?: string;
|
|
38
|
+
}
|
|
39
|
+
export interface StatsModule {
|
|
40
|
+
type?: string;
|
|
41
|
+
moduleType?: string;
|
|
42
|
+
identifier?: string;
|
|
43
|
+
name?: string;
|
|
44
|
+
id?: string | number;
|
|
45
|
+
chunks?: Array<string | number>;
|
|
46
|
+
size?: number;
|
|
47
|
+
issuer?: string;
|
|
48
|
+
issuerName?: string;
|
|
49
|
+
assets?: Array<string | number>;
|
|
50
|
+
reasons?: Array<StatsModuleReason>;
|
|
51
|
+
source?: string | Buffer;
|
|
52
|
+
nameForCondition?: string;
|
|
53
|
+
depth?: number | string;
|
|
54
|
+
loc?: string;
|
|
55
|
+
modules?: StatsModule[];
|
|
56
|
+
}
|
|
57
|
+
export interface StatsModuleReason {
|
|
58
|
+
moduleIdentifier?: string;
|
|
59
|
+
moduleName?: string;
|
|
60
|
+
moduleId?: string | number;
|
|
61
|
+
type?: string;
|
|
62
|
+
userRequest?: string;
|
|
63
|
+
children?: StatsModuleReason[];
|
|
64
|
+
loc?: string;
|
|
65
|
+
}
|
|
66
|
+
export interface JSStatsChunkGroup {
|
|
67
|
+
name?: string;
|
|
68
|
+
assets?: {
|
|
69
|
+
name: string;
|
|
70
|
+
size?: number;
|
|
71
|
+
}[];
|
|
72
|
+
chunks?: (string | number)[];
|
|
73
|
+
assetsSize?: number;
|
|
74
|
+
}
|
|
75
|
+
export type StatsChunkGroup = JSStatsChunkGroup;
|
|
76
|
+
export interface StatsCompilation {
|
|
77
|
+
version?: string;
|
|
78
|
+
/** rspack version */
|
|
79
|
+
name?: string;
|
|
80
|
+
hash?: string;
|
|
81
|
+
time?: number;
|
|
82
|
+
builtAt?: number;
|
|
83
|
+
publicPath?: string;
|
|
84
|
+
assetsByChunkName?: Record<string, string[]>;
|
|
85
|
+
filteredModules?: number;
|
|
86
|
+
assets?: Array<StatsAsset>;
|
|
87
|
+
modules?: Array<StatsModule>;
|
|
88
|
+
chunks?: Array<StatsChunk>;
|
|
89
|
+
entrypoints?: Record<string, StatsChunkGroup>;
|
|
90
|
+
children?: StatsCompilation[];
|
|
91
|
+
errors?: Array<StatsError>;
|
|
92
|
+
errorsCount?: number;
|
|
93
|
+
warnings?: Array<StatsError>;
|
|
94
|
+
warningsCount?: number;
|
|
95
|
+
outputPath?: string;
|
|
96
|
+
}
|
|
97
|
+
interface StatsChunk {
|
|
98
|
+
type?: string;
|
|
99
|
+
files?: Array<string>;
|
|
100
|
+
id?: string | number;
|
|
101
|
+
entry: boolean;
|
|
102
|
+
initial: boolean;
|
|
103
|
+
names?: Array<string>;
|
|
104
|
+
size: number;
|
|
105
|
+
modules?: Array<StatsModule>;
|
|
106
|
+
}
|
|
107
|
+
export declare class Stats {
|
|
108
|
+
constructor(statsJson: any);
|
|
109
|
+
hasErrors(): boolean;
|
|
110
|
+
hasWarnings(): boolean;
|
|
111
|
+
toJson(opts?: StatsOptions): StatsCompilation;
|
|
112
|
+
toString(opts?: StatsOptions): string;
|
|
113
|
+
}
|
|
114
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./baseCompiler"), exports);
|
|
18
|
+
__exportStar(require("./baseStats"), exports);
|
|
19
|
+
__exportStar(require("./plugin"), exports);
|
|
20
|
+
__exportStar(require("./baseLoader"), exports);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export interface DoctorWebpackPluginFeatures {
|
|
2
|
+
/**
|
|
3
|
+
* turn off it if you need not to analyze the executions of webpack loaders.
|
|
4
|
+
* @default true
|
|
5
|
+
*/
|
|
6
|
+
loader?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* turn off it if you need not to analyze the executions of webpack plugins.
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
plugins?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* turn off it if you need not to analyze the executions of resolver.
|
|
14
|
+
* @default false
|
|
15
|
+
*/
|
|
16
|
+
resolver?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* turn off it if you need not to analyze the output bundle.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
bundle?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* turn off it if you need not to analyze the result of tree shaking.
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
treeShaking?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* turn on it if you just use lite mode. This mode do not have source codes.
|
|
29
|
+
* @default false
|
|
30
|
+
*/
|
|
31
|
+
lite?: boolean;
|
|
32
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.message = exports.code = void 0;
|
|
4
|
+
exports.code = 'E1001';
|
|
5
|
+
exports.message = {
|
|
6
|
+
code: exports.code,
|
|
7
|
+
title: 'Duplicate Packages',
|
|
8
|
+
type: 'markdown',
|
|
9
|
+
category: 'bundle',
|
|
10
|
+
description: `
|
|
11
|
+
#### Description
|
|
12
|
+
|
|
13
|
+
there is a same name package which bundled more than one version in your application.
|
|
14
|
+
|
|
15
|
+
it is not good to the bundle size of your application.
|
|
16
|
+
|
|
17
|
+
#### General Solution
|
|
18
|
+
|
|
19
|
+
add an entry in \`resolve.alias\` which will configure Webpack to route any package references to a single specified path.
|
|
20
|
+
|
|
21
|
+
For example, if \`lodash\` is duplicated in your bundle, the following configuration would render all Lodash imports to always refer to the \`lodash\` instance found at \`./node_modules/lodash\`:
|
|
22
|
+
|
|
23
|
+
\`\`\`js
|
|
24
|
+
{
|
|
25
|
+
alias: {
|
|
26
|
+
lodash: path.resolve(__dirname, 'node_modules/lodash')
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
\`\`\`
|
|
30
|
+
`,
|
|
31
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.message = exports.code = void 0;
|
|
4
|
+
exports.code = 'E1002';
|
|
5
|
+
exports.message = {
|
|
6
|
+
code: exports.code,
|
|
7
|
+
title: 'Default Import Check',
|
|
8
|
+
type: 'markdown',
|
|
9
|
+
category: 'compile',
|
|
10
|
+
description: `
|
|
11
|
+
#### Description
|
|
12
|
+
|
|
13
|
+
Usually webpack will automatically compatible different modules that has different types, but in a special case, the operation of compatibility will fail.
|
|
14
|
+
That is, when you use \`Default Import\` to import a cjs module, and this cjs module do not have the compatible statement, such as \`exports.default = \`.
|
|
15
|
+
|
|
16
|
+
#### General Solution
|
|
17
|
+
|
|
18
|
+
1. for cjs module, write a \`exports.default = \` statement for default export.
|
|
19
|
+
2. use \`Namespace Import\` for import the cjs module.
|
|
20
|
+
|
|
21
|
+
For example, for the package \`htmlparser2@7.2.0\`:
|
|
22
|
+
|
|
23
|
+
\`\`\`ts
|
|
24
|
+
// you should use this
|
|
25
|
+
import * as Parser from 'htmlparser2';
|
|
26
|
+
|
|
27
|
+
// can not use this
|
|
28
|
+
import Parser from 'htmlparser2';
|
|
29
|
+
\`\`\`
|
|
30
|
+
`,
|
|
31
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.message = exports.code = void 0;
|
|
4
|
+
exports.code = 'E1003';
|
|
5
|
+
exports.message = {
|
|
6
|
+
code: exports.code,
|
|
7
|
+
title: 'Loader Performance Optimization',
|
|
8
|
+
type: 'markdown',
|
|
9
|
+
category: 'compile',
|
|
10
|
+
description: `
|
|
11
|
+
#### Description
|
|
12
|
+
|
|
13
|
+
Usually the slow compile of most projects is due to the slow execution of the loaders.
|
|
14
|
+
|
|
15
|
+
And the loaders always pre-process many unnecessary files, such as \`node_modules files\` and \`already compiled files\`.
|
|
16
|
+
|
|
17
|
+
#### General Solution
|
|
18
|
+
|
|
19
|
+
Set \`exclude\` to the \`module.rules\` of webpack configuration for target loader.
|
|
20
|
+
|
|
21
|
+
For example, if \`node_modules/lodash\` is processed by the \`babel-loader\` that make the compile slowly:
|
|
22
|
+
|
|
23
|
+
\`\`\`
|
|
24
|
+
{
|
|
25
|
+
module: {
|
|
26
|
+
rules: [
|
|
27
|
+
{
|
|
28
|
+
test: /\\.js$/,
|
|
29
|
+
use: 'babel-loader',
|
|
30
|
+
exclude: [
|
|
31
|
+
/node_modules\\/lodash/
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
\`\`\`
|
|
38
|
+
`,
|
|
39
|
+
};
|