bundle-cop-vercel-plugin 0.1.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/README.md +56 -0
- package/dist/index.cjs +655 -0
- package/dist/index.d.cts +109 -0
- package/dist/index.d.ts +109 -0
- package/dist/index.js +616 -0
- package/next-adapter.cjs +9 -0
- package/package.json +70 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
type ReportModule = {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
issuerPath?: string[];
|
|
5
|
+
culpritFile?: string;
|
|
6
|
+
chain?: string[];
|
|
7
|
+
suggestion?: string | null;
|
|
8
|
+
};
|
|
9
|
+
type ReportChunk = {
|
|
10
|
+
name: string;
|
|
11
|
+
size: number;
|
|
12
|
+
route?: string;
|
|
13
|
+
};
|
|
14
|
+
type BundleReport = {
|
|
15
|
+
version: 1;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
commitSha: string | null;
|
|
18
|
+
totalBytes: number;
|
|
19
|
+
modules: ReportModule[];
|
|
20
|
+
chunks: ReportChunk[];
|
|
21
|
+
budgetResults?: BudgetResult[];
|
|
22
|
+
};
|
|
23
|
+
type BudgetRule = {
|
|
24
|
+
path: string;
|
|
25
|
+
maxSize: string;
|
|
26
|
+
enforce: 'warn' | 'error';
|
|
27
|
+
};
|
|
28
|
+
type BundleCopConfig = {
|
|
29
|
+
budgets?: BudgetRule[];
|
|
30
|
+
ignore?: string[];
|
|
31
|
+
githubComment?: boolean;
|
|
32
|
+
suggestions?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type BudgetResult = {
|
|
35
|
+
path: string;
|
|
36
|
+
maxBytes: number;
|
|
37
|
+
actualBytes: number;
|
|
38
|
+
enforce: 'warn' | 'error';
|
|
39
|
+
exceeded: boolean;
|
|
40
|
+
};
|
|
41
|
+
type IssuerEntry = {
|
|
42
|
+
name?: string;
|
|
43
|
+
path?: string;
|
|
44
|
+
};
|
|
45
|
+
type WebpackModuleLike = {
|
|
46
|
+
name: string;
|
|
47
|
+
size?: number;
|
|
48
|
+
gzipSize?: number;
|
|
49
|
+
issuerPath?: IssuerEntry[] | string[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Walk issuerPath backwards until the first file outside node_modules / .next.
|
|
54
|
+
*/
|
|
55
|
+
declare function findCulprit(module: WebpackModuleLike): {
|
|
56
|
+
culpritFile: string;
|
|
57
|
+
chain: string[];
|
|
58
|
+
};
|
|
59
|
+
declare function suggestAlternative(moduleName: string): string | null;
|
|
60
|
+
|
|
61
|
+
declare function parseSize(input: string): number;
|
|
62
|
+
declare function loadConfig(projectDir: string): BundleCopConfig;
|
|
63
|
+
declare function checkBudgets(report: BundleReport, config: BundleCopConfig): BudgetResult[];
|
|
64
|
+
declare function formatBytes(bytes: number): string;
|
|
65
|
+
|
|
66
|
+
type ParseOptions = {
|
|
67
|
+
nextDir: string;
|
|
68
|
+
projectDir?: string;
|
|
69
|
+
commitSha?: string | null;
|
|
70
|
+
withSuggestions?: boolean;
|
|
71
|
+
};
|
|
72
|
+
declare function parseStats(options: ParseOptions): Promise<BundleReport>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Find a `.next` directory, preferring `preferredDir` then walking ancestors / children.
|
|
76
|
+
* Handles Turborepo layouts like `apps/web/.next`.
|
|
77
|
+
*/
|
|
78
|
+
declare function findNextDir(startDir: string, preferredDir?: string): string | null;
|
|
79
|
+
|
|
80
|
+
type ModifyConfigCtx = {
|
|
81
|
+
phase: string;
|
|
82
|
+
nextVersion: string;
|
|
83
|
+
projectDir?: string;
|
|
84
|
+
};
|
|
85
|
+
type OnBuildCompleteCtx = {
|
|
86
|
+
projectDir: string;
|
|
87
|
+
repoRoot: string;
|
|
88
|
+
distDir: string;
|
|
89
|
+
buildId: string;
|
|
90
|
+
nextVersion: string;
|
|
91
|
+
config?: unknown;
|
|
92
|
+
outputs?: unknown;
|
|
93
|
+
routing?: unknown;
|
|
94
|
+
};
|
|
95
|
+
declare function runBundleCop(ctx: {
|
|
96
|
+
projectDir: string;
|
|
97
|
+
distDir?: string;
|
|
98
|
+
}): Promise<BundleReport>;
|
|
99
|
+
/**
|
|
100
|
+
* Next.js Adapter for Bundle Cop.
|
|
101
|
+
* Configure via: adapterPath: require.resolve('bundle-cop-vercel-plugin/adapter')
|
|
102
|
+
*/
|
|
103
|
+
declare const adapter: {
|
|
104
|
+
name: string;
|
|
105
|
+
modifyConfig(config: Record<string, unknown>, ctx: ModifyConfigCtx): Promise<Record<string, unknown>>;
|
|
106
|
+
onBuildComplete(ctx: OnBuildCompleteCtx): Promise<void>;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export { type BudgetResult, type BundleCopConfig, type BundleReport, type ReportChunk, type ReportModule, adapter, checkBudgets, adapter as default, findCulprit, findNextDir, formatBytes, loadConfig, parseSize, parseStats, runBundleCop, suggestAlternative };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
type ReportModule = {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
issuerPath?: string[];
|
|
5
|
+
culpritFile?: string;
|
|
6
|
+
chain?: string[];
|
|
7
|
+
suggestion?: string | null;
|
|
8
|
+
};
|
|
9
|
+
type ReportChunk = {
|
|
10
|
+
name: string;
|
|
11
|
+
size: number;
|
|
12
|
+
route?: string;
|
|
13
|
+
};
|
|
14
|
+
type BundleReport = {
|
|
15
|
+
version: 1;
|
|
16
|
+
createdAt: string;
|
|
17
|
+
commitSha: string | null;
|
|
18
|
+
totalBytes: number;
|
|
19
|
+
modules: ReportModule[];
|
|
20
|
+
chunks: ReportChunk[];
|
|
21
|
+
budgetResults?: BudgetResult[];
|
|
22
|
+
};
|
|
23
|
+
type BudgetRule = {
|
|
24
|
+
path: string;
|
|
25
|
+
maxSize: string;
|
|
26
|
+
enforce: 'warn' | 'error';
|
|
27
|
+
};
|
|
28
|
+
type BundleCopConfig = {
|
|
29
|
+
budgets?: BudgetRule[];
|
|
30
|
+
ignore?: string[];
|
|
31
|
+
githubComment?: boolean;
|
|
32
|
+
suggestions?: boolean;
|
|
33
|
+
};
|
|
34
|
+
type BudgetResult = {
|
|
35
|
+
path: string;
|
|
36
|
+
maxBytes: number;
|
|
37
|
+
actualBytes: number;
|
|
38
|
+
enforce: 'warn' | 'error';
|
|
39
|
+
exceeded: boolean;
|
|
40
|
+
};
|
|
41
|
+
type IssuerEntry = {
|
|
42
|
+
name?: string;
|
|
43
|
+
path?: string;
|
|
44
|
+
};
|
|
45
|
+
type WebpackModuleLike = {
|
|
46
|
+
name: string;
|
|
47
|
+
size?: number;
|
|
48
|
+
gzipSize?: number;
|
|
49
|
+
issuerPath?: IssuerEntry[] | string[];
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Walk issuerPath backwards until the first file outside node_modules / .next.
|
|
54
|
+
*/
|
|
55
|
+
declare function findCulprit(module: WebpackModuleLike): {
|
|
56
|
+
culpritFile: string;
|
|
57
|
+
chain: string[];
|
|
58
|
+
};
|
|
59
|
+
declare function suggestAlternative(moduleName: string): string | null;
|
|
60
|
+
|
|
61
|
+
declare function parseSize(input: string): number;
|
|
62
|
+
declare function loadConfig(projectDir: string): BundleCopConfig;
|
|
63
|
+
declare function checkBudgets(report: BundleReport, config: BundleCopConfig): BudgetResult[];
|
|
64
|
+
declare function formatBytes(bytes: number): string;
|
|
65
|
+
|
|
66
|
+
type ParseOptions = {
|
|
67
|
+
nextDir: string;
|
|
68
|
+
projectDir?: string;
|
|
69
|
+
commitSha?: string | null;
|
|
70
|
+
withSuggestions?: boolean;
|
|
71
|
+
};
|
|
72
|
+
declare function parseStats(options: ParseOptions): Promise<BundleReport>;
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Find a `.next` directory, preferring `preferredDir` then walking ancestors / children.
|
|
76
|
+
* Handles Turborepo layouts like `apps/web/.next`.
|
|
77
|
+
*/
|
|
78
|
+
declare function findNextDir(startDir: string, preferredDir?: string): string | null;
|
|
79
|
+
|
|
80
|
+
type ModifyConfigCtx = {
|
|
81
|
+
phase: string;
|
|
82
|
+
nextVersion: string;
|
|
83
|
+
projectDir?: string;
|
|
84
|
+
};
|
|
85
|
+
type OnBuildCompleteCtx = {
|
|
86
|
+
projectDir: string;
|
|
87
|
+
repoRoot: string;
|
|
88
|
+
distDir: string;
|
|
89
|
+
buildId: string;
|
|
90
|
+
nextVersion: string;
|
|
91
|
+
config?: unknown;
|
|
92
|
+
outputs?: unknown;
|
|
93
|
+
routing?: unknown;
|
|
94
|
+
};
|
|
95
|
+
declare function runBundleCop(ctx: {
|
|
96
|
+
projectDir: string;
|
|
97
|
+
distDir?: string;
|
|
98
|
+
}): Promise<BundleReport>;
|
|
99
|
+
/**
|
|
100
|
+
* Next.js Adapter for Bundle Cop.
|
|
101
|
+
* Configure via: adapterPath: require.resolve('bundle-cop-vercel-plugin/adapter')
|
|
102
|
+
*/
|
|
103
|
+
declare const adapter: {
|
|
104
|
+
name: string;
|
|
105
|
+
modifyConfig(config: Record<string, unknown>, ctx: ModifyConfigCtx): Promise<Record<string, unknown>>;
|
|
106
|
+
onBuildComplete(ctx: OnBuildCompleteCtx): Promise<void>;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export { type BudgetResult, type BundleCopConfig, type BundleReport, type ReportChunk, type ReportModule, adapter, checkBudgets, adapter as default, findCulprit, findNextDir, formatBytes, loadConfig, parseSize, parseStats, runBundleCop, suggestAlternative };
|