@node-cli/bundlesize 4.5.0 → 4.5.1
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 +25 -13
- package/dist/config.d.ts +103 -0
- package/dist/config.js +19 -0
- package/dist/config.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +8 -4
- package/schemas/bundlesize.config.schema.json +0 -151
package/README.md
CHANGED
|
@@ -14,14 +14,16 @@
|
|
|
14
14
|
|
|
15
15
|
A configuration file must be provided via the `-c` parameter.
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### Type-Safe Configuration
|
|
18
18
|
|
|
19
|
-
For IDE autocompletion and validation, you can
|
|
19
|
+
For IDE autocompletion and validation, you can use either JSDoc type hints or the `defineConfig` helper function.
|
|
20
|
+
|
|
21
|
+
#### Using JSDoc (recommended for JavaScript configs)
|
|
20
22
|
|
|
21
23
|
```js
|
|
24
|
+
// @ts-check
|
|
25
|
+
/** @type {import('@node-cli/bundlesize').BundlesizeConfig} */
|
|
22
26
|
export default {
|
|
23
|
-
$schema:
|
|
24
|
-
"https://cdn.jsdelivr.net/npm/@node-cli/bundlesize/schemas/bundlesize.config.schema.json",
|
|
25
27
|
sizes: [
|
|
26
28
|
{
|
|
27
29
|
path: "dist/bundle.js",
|
|
@@ -31,19 +33,29 @@ export default {
|
|
|
31
33
|
};
|
|
32
34
|
```
|
|
33
35
|
|
|
34
|
-
|
|
36
|
+
#### Using defineConfig helper
|
|
35
37
|
|
|
36
|
-
|
|
37
|
-
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
**Note**: For a specific version of the schema, use:
|
|
38
|
+
```js
|
|
39
|
+
// @ts-check
|
|
40
|
+
import { defineConfig } from "@node-cli/bundlesize";
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
export default defineConfig({
|
|
43
|
+
sizes: [
|
|
44
|
+
{
|
|
45
|
+
path: "dist/bundle.js",
|
|
46
|
+
limit: "10 kB"
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
});
|
|
44
50
|
```
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
Both approaches provide:
|
|
53
|
+
|
|
54
|
+
- Autocompletion for configuration options
|
|
55
|
+
- Inline documentation for each property
|
|
56
|
+
- Type validation in your IDE
|
|
57
|
+
|
|
58
|
+
**Note**: The `// @ts-check` comment enables TypeScript checking for the file, which is required for validation errors to appear.
|
|
47
59
|
|
|
48
60
|
### Configuration Options
|
|
49
61
|
|
package/dist/config.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { FooterProperties } from "./utilities.js";
|
|
2
|
+
/**
|
|
3
|
+
* Configuration for a single file size entry.
|
|
4
|
+
*/
|
|
5
|
+
export interface SizeEntry {
|
|
6
|
+
/**
|
|
7
|
+
* Path to the file to check. Supports glob patterns.
|
|
8
|
+
* Special placeholders:
|
|
9
|
+
* - `<hash>`: matches content hashes (e.g., `bundle-<hash>.js`)
|
|
10
|
+
* - `<semver>`: matches semantic versions (e.g., `lib-<semver>.js`)
|
|
11
|
+
*/
|
|
12
|
+
path: string;
|
|
13
|
+
/**
|
|
14
|
+
* Maximum allowed size for the file (gzipped).
|
|
15
|
+
* Format: number followed by unit (B, kB, KB, MB, GB, TB, PB)
|
|
16
|
+
* @example "10 kB", "1.5 MB", "500 B"
|
|
17
|
+
*/
|
|
18
|
+
limit: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional alias for the file in reports.
|
|
21
|
+
* Useful for giving meaningful names to files with hash patterns.
|
|
22
|
+
*/
|
|
23
|
+
alias?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Configuration for a header entry (group separator in reports).
|
|
27
|
+
*/
|
|
28
|
+
export interface HeaderEntry {
|
|
29
|
+
/**
|
|
30
|
+
* Header text to display as a group separator in reports.
|
|
31
|
+
*/
|
|
32
|
+
header: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Column definition for the report table.
|
|
36
|
+
*/
|
|
37
|
+
export interface ColumnDefinition {
|
|
38
|
+
[key: string]: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Configuration for generating comparison reports.
|
|
42
|
+
*/
|
|
43
|
+
export interface ReportConfiguration {
|
|
44
|
+
/**
|
|
45
|
+
* Path to the current stats JSON file (relative to config file).
|
|
46
|
+
*/
|
|
47
|
+
current: string;
|
|
48
|
+
/**
|
|
49
|
+
* Path to the previous stats JSON file for comparison (relative to config file).
|
|
50
|
+
*/
|
|
51
|
+
previous: string;
|
|
52
|
+
/**
|
|
53
|
+
* Custom header text for the report.
|
|
54
|
+
* @default "## Bundle Size"
|
|
55
|
+
*/
|
|
56
|
+
header?: string;
|
|
57
|
+
/**
|
|
58
|
+
* Custom footer function for the report.
|
|
59
|
+
* Receives an object with limitReached, overallDiff, and totalGzipSize.
|
|
60
|
+
*/
|
|
61
|
+
footer?: (args: FooterProperties) => string;
|
|
62
|
+
/**
|
|
63
|
+
* Column definitions for the report table.
|
|
64
|
+
* @default [{ status: "Status" }, { file: "File" }, { size: "Size (Gzip)" }, { limits: "Limits" }]
|
|
65
|
+
*/
|
|
66
|
+
columns?: ColumnDefinition[];
|
|
67
|
+
/**
|
|
68
|
+
* Minimum gzip size change in bytes to consider as a change.
|
|
69
|
+
* Changes below this threshold are treated as no change.
|
|
70
|
+
* @default 0
|
|
71
|
+
*/
|
|
72
|
+
threshold?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Bundlesize configuration object.
|
|
76
|
+
*/
|
|
77
|
+
export interface BundlesizeConfig {
|
|
78
|
+
/**
|
|
79
|
+
* Array of file size entries to check.
|
|
80
|
+
* Each entry can be either a SizeEntry (file to check) or HeaderEntry (group separator).
|
|
81
|
+
*/
|
|
82
|
+
sizes?: (SizeEntry | HeaderEntry)[];
|
|
83
|
+
/**
|
|
84
|
+
* Configuration for generating comparison reports.
|
|
85
|
+
*/
|
|
86
|
+
report?: ReportConfiguration;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Helper function to define bundlesize configuration with full type support.
|
|
90
|
+
* Provides IntelliSense and type checking for configuration files.
|
|
91
|
+
*
|
|
92
|
+
* @example
|
|
93
|
+
* ```js
|
|
94
|
+
* import { defineConfig } from "@node-cli/bundlesize";
|
|
95
|
+
*
|
|
96
|
+
* export default defineConfig({
|
|
97
|
+
* sizes: [
|
|
98
|
+
* { path: "dist/bundle.js", limit: "10 kB" }
|
|
99
|
+
* ]
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare function defineConfig(config: BundlesizeConfig): BundlesizeConfig;
|
package/dist/config.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper function to define bundlesize configuration with full type support.
|
|
3
|
+
* Provides IntelliSense and type checking for configuration files.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```js
|
|
7
|
+
* import { defineConfig } from "@node-cli/bundlesize";
|
|
8
|
+
*
|
|
9
|
+
* export default defineConfig({
|
|
10
|
+
* sizes: [
|
|
11
|
+
* { path: "dist/bundle.js", limit: "10 kB" }
|
|
12
|
+
* ]
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
*/ export function defineConfig(config) {
|
|
16
|
+
return config;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/config.ts"],"sourcesContent":["import type { FooterProperties } from \"./utilities.js\";\n\n/**\n * Configuration for a single file size entry.\n */\nexport interface SizeEntry {\n\t/**\n\t * Path to the file to check. Supports glob patterns.\n\t * Special placeholders:\n\t * - `<hash>`: matches content hashes (e.g., `bundle-<hash>.js`)\n\t * - `<semver>`: matches semantic versions (e.g., `lib-<semver>.js`)\n\t */\n\tpath: string;\n\t/**\n\t * Maximum allowed size for the file (gzipped).\n\t * Format: number followed by unit (B, kB, KB, MB, GB, TB, PB)\n\t * @example \"10 kB\", \"1.5 MB\", \"500 B\"\n\t */\n\tlimit: string;\n\t/**\n\t * Optional alias for the file in reports.\n\t * Useful for giving meaningful names to files with hash patterns.\n\t */\n\talias?: string;\n}\n\n/**\n * Configuration for a header entry (group separator in reports).\n */\nexport interface HeaderEntry {\n\t/**\n\t * Header text to display as a group separator in reports.\n\t */\n\theader: string;\n}\n\n/**\n * Column definition for the report table.\n */\nexport interface ColumnDefinition {\n\t[key: string]: string;\n}\n\n/**\n * Configuration for generating comparison reports.\n */\nexport interface ReportConfiguration {\n\t/**\n\t * Path to the current stats JSON file (relative to config file).\n\t */\n\tcurrent: string;\n\t/**\n\t * Path to the previous stats JSON file for comparison (relative to config file).\n\t */\n\tprevious: string;\n\t/**\n\t * Custom header text for the report.\n\t * @default \"## Bundle Size\"\n\t */\n\theader?: string;\n\t/**\n\t * Custom footer function for the report.\n\t * Receives an object with limitReached, overallDiff, and totalGzipSize.\n\t */\n\tfooter?: (args: FooterProperties) => string;\n\t/**\n\t * Column definitions for the report table.\n\t * @default [{ status: \"Status\" }, { file: \"File\" }, { size: \"Size (Gzip)\" }, { limits: \"Limits\" }]\n\t */\n\tcolumns?: ColumnDefinition[];\n\t/**\n\t * Minimum gzip size change in bytes to consider as a change.\n\t * Changes below this threshold are treated as no change.\n\t * @default 0\n\t */\n\tthreshold?: number;\n}\n\n/**\n * Bundlesize configuration object.\n */\nexport interface BundlesizeConfig {\n\t/**\n\t * Array of file size entries to check.\n\t * Each entry can be either a SizeEntry (file to check) or HeaderEntry (group separator).\n\t */\n\tsizes?: (SizeEntry | HeaderEntry)[];\n\t/**\n\t * Configuration for generating comparison reports.\n\t */\n\treport?: ReportConfiguration;\n}\n\n/**\n * Helper function to define bundlesize configuration with full type support.\n * Provides IntelliSense and type checking for configuration files.\n *\n * @example\n * ```js\n * import { defineConfig } from \"@node-cli/bundlesize\";\n *\n * export default defineConfig({\n * sizes: [\n * { path: \"dist/bundle.js\", limit: \"10 kB\" }\n * ]\n * });\n * ```\n */\nexport function defineConfig(config: BundlesizeConfig): BundlesizeConfig {\n\treturn config;\n}\n"],"names":["defineConfig","config"],"mappings":"AA6FA;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASA,aAAaC,MAAwB;IACpD,OAAOA;AACR"}
|
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@node-cli/bundlesize",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Arno Versini",
|
|
6
6
|
"description": "Simple CLI tool that checks file(s) size and report if limits have been reached",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports":
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/config.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
10
15
|
"bin": "dist/bundlesize.js",
|
|
11
16
|
"files": [
|
|
12
17
|
"dist",
|
|
13
|
-
"schemas",
|
|
14
18
|
"README.md"
|
|
15
19
|
],
|
|
16
20
|
"node": ">=18",
|
|
@@ -46,5 +50,5 @@
|
|
|
46
50
|
"@vitest/coverage-v8": "3.2.4",
|
|
47
51
|
"vitest": "3.2.4"
|
|
48
52
|
},
|
|
49
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "b19e02fcb4745190530c693093fe87a5af5517bf"
|
|
50
54
|
}
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
3
|
-
"$id": "https://cdn.jsdelivr.net/npm/@node-cli/bundlesize/schemas/bundlesize.config.schema.json",
|
|
4
|
-
"title": "Bundlesize Configuration",
|
|
5
|
-
"description": "Configuration schema for @node-cli/bundlesize - a CLI tool that checks file(s) size and reports if limits have been reached",
|
|
6
|
-
"type": "object",
|
|
7
|
-
"properties": {
|
|
8
|
-
"$schema": {
|
|
9
|
-
"type": "string",
|
|
10
|
-
"description": "Path to the JSON Schema for this configuration file"
|
|
11
|
-
},
|
|
12
|
-
"sizes": {
|
|
13
|
-
"type": "array",
|
|
14
|
-
"description": "Array of file size entries to check",
|
|
15
|
-
"items": {
|
|
16
|
-
"oneOf": [
|
|
17
|
-
{
|
|
18
|
-
"$ref": "#/$defs/SizeEntry"
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
"$ref": "#/$defs/HeaderEntry"
|
|
22
|
-
}
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
"report": {
|
|
27
|
-
"$ref": "#/$defs/ReportConfiguration"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"additionalProperties": false,
|
|
31
|
-
"$defs": {
|
|
32
|
-
"SizeEntry": {
|
|
33
|
-
"type": "object",
|
|
34
|
-
"description": "A file size entry to check",
|
|
35
|
-
"properties": {
|
|
36
|
-
"path": {
|
|
37
|
-
"type": "string",
|
|
38
|
-
"description": "Path to the file to check. Supports glob patterns and special placeholders: <hash> for content hashes, <semver> for semantic versions"
|
|
39
|
-
},
|
|
40
|
-
"limit": {
|
|
41
|
-
"type": "string",
|
|
42
|
-
"description": "Maximum allowed size for the file (gzipped). Examples: '1.5 kB', '500 B', '2 MB'",
|
|
43
|
-
"pattern": "^[0-9]+(\\.[0-9]+)?\\s*(B|kB|KB|MB|GB|TB|PB)$"
|
|
44
|
-
},
|
|
45
|
-
"alias": {
|
|
46
|
-
"type": "string",
|
|
47
|
-
"description": "Optional alias for the file in reports. Useful when using dynamic path patterns"
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
"required": ["path", "limit"],
|
|
51
|
-
"additionalProperties": false
|
|
52
|
-
},
|
|
53
|
-
"HeaderEntry": {
|
|
54
|
-
"type": "object",
|
|
55
|
-
"description": "A header entry for grouping files in reports",
|
|
56
|
-
"properties": {
|
|
57
|
-
"header": {
|
|
58
|
-
"type": "string",
|
|
59
|
-
"description": "Header text for a group of files in the report (e.g., '### Main Bundle')"
|
|
60
|
-
}
|
|
61
|
-
},
|
|
62
|
-
"required": ["header"],
|
|
63
|
-
"additionalProperties": false
|
|
64
|
-
},
|
|
65
|
-
"ColumnDefinition": {
|
|
66
|
-
"type": "object",
|
|
67
|
-
"description": "A column definition for the report table",
|
|
68
|
-
"minProperties": 1,
|
|
69
|
-
"maxProperties": 1,
|
|
70
|
-
"additionalProperties": {
|
|
71
|
-
"type": "string",
|
|
72
|
-
"description": "Column header text"
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
"ReportConfiguration": {
|
|
76
|
-
"type": "object",
|
|
77
|
-
"description": "Configuration for generating size comparison reports",
|
|
78
|
-
"properties": {
|
|
79
|
-
"current": {
|
|
80
|
-
"type": "string",
|
|
81
|
-
"description": "Path to the current stats JSON file (relative to config file)"
|
|
82
|
-
},
|
|
83
|
-
"previous": {
|
|
84
|
-
"type": "string",
|
|
85
|
-
"description": "Path to the previous stats JSON file for comparison (relative to config file)"
|
|
86
|
-
},
|
|
87
|
-
"header": {
|
|
88
|
-
"type": "string",
|
|
89
|
-
"description": "Custom header for the report. Defaults to '## Bundle Size'"
|
|
90
|
-
},
|
|
91
|
-
"threshold": {
|
|
92
|
-
"type": "number",
|
|
93
|
-
"description": "Minimum byte difference to report as a change. Differences below this threshold are treated as no change. Defaults to 0",
|
|
94
|
-
"minimum": 0
|
|
95
|
-
},
|
|
96
|
-
"columns": {
|
|
97
|
-
"type": "array",
|
|
98
|
-
"description": "Custom column definitions for the report table. Default columns: status, file, size, limits",
|
|
99
|
-
"items": {
|
|
100
|
-
"$ref": "#/$defs/ColumnDefinition"
|
|
101
|
-
},
|
|
102
|
-
"examples": [
|
|
103
|
-
[
|
|
104
|
-
{ "status": "Status" },
|
|
105
|
-
{ "file": "File" },
|
|
106
|
-
{ "size": "Size (Gzip)" },
|
|
107
|
-
{ "limits": "Limits" }
|
|
108
|
-
]
|
|
109
|
-
]
|
|
110
|
-
}
|
|
111
|
-
},
|
|
112
|
-
"required": ["current", "previous"],
|
|
113
|
-
"additionalProperties": true
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
"examples": [
|
|
117
|
-
{
|
|
118
|
-
"sizes": [
|
|
119
|
-
{
|
|
120
|
-
"path": "dist/index.js",
|
|
121
|
-
"limit": "10 kB"
|
|
122
|
-
},
|
|
123
|
-
{
|
|
124
|
-
"path": "dist/vendor.<hash>.js",
|
|
125
|
-
"limit": "50 kB",
|
|
126
|
-
"alias": "vendor"
|
|
127
|
-
}
|
|
128
|
-
]
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
"sizes": [
|
|
132
|
-
{ "header": "### Core" },
|
|
133
|
-
{
|
|
134
|
-
"path": "dist/core.js",
|
|
135
|
-
"limit": "5 kB"
|
|
136
|
-
},
|
|
137
|
-
{ "header": "### Plugins" },
|
|
138
|
-
{
|
|
139
|
-
"path": "dist/plugins/*.js",
|
|
140
|
-
"limit": "2 kB"
|
|
141
|
-
}
|
|
142
|
-
],
|
|
143
|
-
"report": {
|
|
144
|
-
"current": "stats/current.json",
|
|
145
|
-
"previous": "stats/previous.json",
|
|
146
|
-
"header": "## Bundle Size Report",
|
|
147
|
-
"threshold": 100
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
]
|
|
151
|
-
}
|