tonnage 0.2.0 → 0.4.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/AGENTS.md +7 -6
- package/CHANGELOG.md +12 -0
- package/README.md +93 -117
- package/README.mdx +85 -106
- package/dist/index.d.mts +31 -30
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +226 -3
- package/dist/index.mjs.map +1 -1
- package/examples/tonnage.config.ts +0 -1
- package/package.json +13 -15
- package/src/index.ts +2 -11
- package/src/report-content.ts +1 -1
- package/src/report.ts +0 -15
- package/src/types.ts +0 -10
- package/dist/cli.mjs +0 -113
- package/dist/cli.mjs.map +0 -1
- package/dist/galley.d.mts +0 -12
- package/dist/galley.d.mts.map +0 -1
- package/dist/galley.mjs +0 -12
- package/dist/galley.mjs.map +0 -1
- package/dist/report-B3HrJ4UQ.mjs +0 -237
- package/dist/report-B3HrJ4UQ.mjs.map +0 -1
- package/dist/run-BJN1MXRf.mjs +0 -44
- package/dist/run-BJN1MXRf.mjs.map +0 -1
- package/dist/types-Ddtp95Z3.d.mts +0 -49
- package/dist/types-Ddtp95Z3.d.mts.map +0 -1
- package/src/cli.ts +0 -96
- package/src/command-line.ts +0 -70
- package/src/readme.ts +0 -48
- package/src/run.ts +0 -28
package/AGENTS.md
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
# tonnage
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Runtime JavaScript bundle measurement for Galley documents.
|
|
4
4
|
|
|
5
|
+
- Install `galley.md@^0.1.1` alongside tonnage. Galley is a required peer.
|
|
6
|
+
- Import `Tonnage` from `tonnage` in an MDX document. Pass measurement options through `config`, using `defineConfig` for reusable configurations if desired.
|
|
7
|
+
- Paths default to the containing document's directory. Set `directory` to measure another package; relative overrides resolve from the document. Resolve `packageJson` from that directory and recipe entries from the selected manifest's directory. Imported configuration files do not change these bases.
|
|
8
|
+
- Run `galley write` to generate Markdown and `galley check` in CI to detect missing or stale output. Maintain the MDX source and commit the generated Markdown.
|
|
5
9
|
- Tonnage measures emitted minified JavaScript and level-9 gzip bytes. Do not include declarations, source maps, CSS, or other assets in those figures.
|
|
6
10
|
- Public-module rows retain the complete runtime export surface. Recipe rows use reviewable entry files and tree-shake unused exports.
|
|
7
|
-
- Treat each recipe as one realistic runtime boundary. Keep server and client recipes separate, and count shared modules once
|
|
11
|
+
- Treat each recipe as one realistic runtime boundary. Keep server and client recipes separate, and count shared modules once per bundle.
|
|
8
12
|
- Peer dependencies stay external by default. Use explicit `external` entries only for additional dependencies intentionally supplied by consumers.
|
|
9
|
-
-
|
|
10
|
-
- Keep marker names stable and use the `tonnage:<name>:start` and `tonnage:<name>:end` comment forms.
|
|
11
|
-
- For a galley.md document, import `Tonnage` from `tonnage/galley`. Its config paths default to the containing document's directory. The component measures and renders a report without writing a README or requiring section markers.
|
|
12
|
-
- Await `renderTonnageMarkdown(report, config)` when using the programmatic API. CLI reports and document components share Galley's table rendering, escaping literal text and aligning byte columns to the right.
|
|
13
|
+
- The component returns Galley elements without writing files. Its tables escape literal text and align byte columns to the right.
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# tonnage
|
|
2
2
|
|
|
3
|
+
## 0.4.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- fffad43: Make tonnage a Galley component package: import Tonnage from tonnage and use galley write/check to generate and validate README files from MDX. Remove the tonnage executable and shell completion, tonnage/galley subpath, marker-based README editing, marker/readme config fields, and standalone measurement, report, and rendering exports. Keep defineConfig and component configuration types; migrate existing README content to README.mdx and replace generated-section markers with a Tonnage component.
|
|
8
|
+
|
|
9
|
+
## 0.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 02567f0: Make galley.md ^0.1.1 a required peer dependency so consumers control the Galley version used by report rendering and MDX components. Install a compatible galley.md version alongside tonnage, including for standalone CLI use.
|
|
14
|
+
|
|
3
15
|
## 0.2.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,19 +1,51 @@
|
|
|
1
1
|
# tonnage
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
numbers drift.
|
|
3
|
+
Bundle size reports for [Galley](https://www.npmjs.com/package/galley.md) documents.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
and reports JavaScript bytes before and after level-9 gzip.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
Tonnage bundles real public package imports with esbuild, minifies the result,
|
|
6
|
+
and reports JavaScript bytes before and after level-9 gzip. Embed its component
|
|
7
|
+
in a README source document, then use Galley to generate Markdown and detect
|
|
8
|
+
stale reports in CI.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
Install tonnage and its required Galley peer:
|
|
13
|
+
|
|
14
|
+
```sh
|
|
15
|
+
pnpm add -D tonnage 'galley.md@^0.1.1'
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Use
|
|
19
|
+
|
|
20
|
+
Create `README.mdx` beside your package manifest:
|
|
21
|
+
|
|
22
|
+
```mdx
|
|
23
|
+
import { Tonnage } from "tonnage"
|
|
24
|
+
|
|
25
|
+
# My package
|
|
26
|
+
|
|
27
|
+
<Tonnage config={{ platform: "node" }} />
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Run `galley write` to generate `README.md`. Run `galley check` in CI to evaluate
|
|
31
|
+
the document again and exit nonzero if its output is missing or stale. Keep the
|
|
32
|
+
MDX source and generated Markdown in version control.
|
|
33
|
+
|
|
34
|
+
The component defaults to measuring every public export except `./package.json`.
|
|
35
|
+
Paths resolve relative to the containing document. To measure another package,
|
|
36
|
+
pass `directory`, such as `<Tonnage directory="../my-package" />`; relative
|
|
37
|
+
values resolve from the document's directory. The `packageJson` path resolves
|
|
38
|
+
from that measurement directory; recipe entry paths resolve from the selected
|
|
39
|
+
manifest's directory.
|
|
40
|
+
|
|
41
|
+
Galley owns document evaluation and output files. See its
|
|
42
|
+
[user guide](https://github.com/jeremybanka/galley#readme) for document composition
|
|
43
|
+
and command options.
|
|
12
44
|
|
|
13
45
|
## Configure
|
|
14
46
|
|
|
15
|
-
|
|
16
|
-
|
|
47
|
+
Pass configuration inline or import a reusable configuration using `defineConfig`.
|
|
48
|
+
The complete configuration exhibit is in
|
|
17
49
|
[examples/tonnage.config.ts](./examples/tonnage.config.ts).
|
|
18
50
|
|
|
19
51
|
```ts
|
|
@@ -24,7 +56,6 @@ const config: TonnageConfig = defineConfig({
|
|
|
24
56
|
exports: {
|
|
25
57
|
exclude: [`./package.json`],
|
|
26
58
|
},
|
|
27
|
-
marker: `my-package`,
|
|
28
59
|
recipes: [
|
|
29
60
|
{
|
|
30
61
|
entry: `examples/recipes/react-app.ts`,
|
|
@@ -39,10 +70,27 @@ export default config
|
|
|
39
70
|
|
|
40
71
|
```
|
|
41
72
|
|
|
73
|
+
Import it explicitly in your document:
|
|
74
|
+
|
|
75
|
+
```mdx
|
|
76
|
+
import { Tonnage } from "tonnage"
|
|
77
|
+
import config from "./examples/tonnage.config.ts"
|
|
78
|
+
|
|
79
|
+
<Tonnage config={config} />
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Importing configuration from another folder does not change path resolution.
|
|
83
|
+
Set `packageJson` to
|
|
84
|
+
select a manifest, `exports.include` or `exports.exclude` to select subpaths,
|
|
85
|
+
and `exports: false` to report only recipes. Use `heading` to customize the report
|
|
86
|
+
heading and `target` to set esbuild's JavaScript target. Use `external` for
|
|
87
|
+
additional imports intentionally supplied by consumers; peer dependencies are
|
|
88
|
+
already external.
|
|
89
|
+
|
|
42
90
|
Each recipe points to a reviewable entry file such as
|
|
43
91
|
[examples/recipes/react-app.ts](./examples/recipes/react-app.ts). Use named
|
|
44
|
-
imports
|
|
45
|
-
|
|
92
|
+
imports to represent the runtime surface a real application uses; unused package
|
|
93
|
+
exports are tree-shaken. Keep server and client recipes separate.
|
|
46
94
|
|
|
47
95
|
```ts
|
|
48
96
|
// @exhibit-region start recipe
|
|
@@ -52,117 +100,46 @@ export { useO } from "my-package/react"
|
|
|
52
100
|
|
|
53
101
|
```
|
|
54
102
|
|
|
55
|
-
The
|
|
56
|
-
|
|
57
|
-
`tonnage:my-package:start` and `tonnage:my-package:end`.
|
|
58
|
-
|
|
59
|
-
## Run
|
|
60
|
-
|
|
61
|
-
Run `tonnage write` during development to update the README. Run
|
|
62
|
-
`tonnage check` in CI to recompute the same report without writing and exit
|
|
63
|
-
nonzero when the README is stale. Run `tonnage --help` to see both commands and
|
|
64
|
-
their optional config-path arguments.
|
|
65
|
-
|
|
66
|
-
Pass a config path with `tonnage check path/to/tonnage.config.ts` or
|
|
67
|
-
`tonnage write path/to/tonnage.config.ts`. Otherwise, Tonnage looks in the current
|
|
68
|
-
directory for `tonnage.config.ts`, then `tonnage.config.mjs`, then
|
|
69
|
-
`tonnage.config.js`. Config modules may use top-level `await`. Missing configs
|
|
70
|
-
are errors. Use `--` before a config path that starts with a dash.
|
|
71
|
-
|
|
72
|
-
Unknown options are ignored with warnings on stderr. Warnings do not change the
|
|
73
|
-
exit status; `check` still exits nonzero when the report is stale.
|
|
74
|
-
|
|
75
|
-
By default the tool reads `package.json`, writes `README.md`, and measures every
|
|
76
|
-
public export except `./package.json`. Paths are resolved relative to the config
|
|
77
|
-
file. Use `exports.include` or `exports.exclude` to select subpaths, recipe entry
|
|
78
|
-
files to describe realistic runtime boundaries, and `external` for non-peer
|
|
79
|
-
imports that the package intentionally leaves to its consumers.
|
|
80
|
-
|
|
81
|
-
### Shell completion
|
|
82
|
-
|
|
83
|
-
With `tonnage` available on your shell's `PATH`, install completion for your shell:
|
|
84
|
-
|
|
85
|
-
```sh
|
|
86
|
-
tonnage completion install bash
|
|
87
|
-
tonnage completion install zsh
|
|
88
|
-
tonnage completion install fish
|
|
89
|
-
tonnage completion install nushell
|
|
90
|
-
tonnage completion install carapace
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
Choose the integration you use. Completion suggests commands, help options, and
|
|
94
|
-
config paths without loading your config or measuring bundles. Installation
|
|
95
|
-
checks the shell's prerequisites and writes to its completion directory without
|
|
96
|
-
editing shell profiles. It reports any setup needed for your shell. If Nushell
|
|
97
|
-
already uses Carapace, install only the Carapace integration.
|
|
98
|
-
|
|
99
|
-
Run `tonnage completion bash` (or another target above) to print the integration
|
|
100
|
-
file without installing it. The `completion` command and comline's internal
|
|
101
|
-
completion protocol commands are reserved for shell integration.
|
|
103
|
+
The public API consists of `Tonnage`, `defineConfig`, and the `TonnageProps`,
|
|
104
|
+
`TonnageConfig`, `TonnageExports`, `TonnageRecipe`, and `BundlePlatform` types.
|
|
102
105
|
|
|
103
106
|
## Report layout
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
tables `Package exports` and `Usage examples
|
|
109
|
-
runtime export surfaces from tree-shaken recipe bundles.
|
|
108
|
+
Public-module rows retain the complete runtime export surface. Recipe rows
|
|
109
|
+
bundle their entry files and tree-shake unused exports. Exports-only and
|
|
110
|
+
recipes-only reports put their table directly below the report heading; a report
|
|
111
|
+
with both labels its tables `Package exports` and `Usage examples`.
|
|
110
112
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
Reports use Galley's native table elements, with right-aligned byte columns and
|
|
117
|
-
literal escaping for import names, entry paths, and recipe labels.
|
|
118
|
-
|
|
119
|
-
For programmatic use, await both measurement and Markdown rendering:
|
|
120
|
-
|
|
121
|
-
```ts
|
|
122
|
-
import {
|
|
123
|
-
createTonnageReport,
|
|
124
|
-
defineConfig,
|
|
125
|
-
renderTonnageMarkdown,
|
|
126
|
-
} from "tonnage"
|
|
127
|
-
|
|
128
|
-
const config = defineConfig({ platform: "node" })
|
|
129
|
-
const report = await createTonnageReport(config, process.cwd())
|
|
130
|
-
const markdown = await renderTonnageMarkdown(report, config)
|
|
131
|
-
```
|
|
113
|
+
Sizes count minified JavaScript and level-9 gzip bytes. Declarations, source
|
|
114
|
+
maps, CSS, and other assets are excluded. Peer dependencies stay external, and
|
|
115
|
+
shared modules are counted once per bundle. Reports use Galley's native table
|
|
116
|
+
elements, with right-aligned byte columns and literal escaping for import names,
|
|
117
|
+
entry paths, and recipe labels.
|
|
132
118
|
|
|
133
119
|
## Package resolution and platforms
|
|
134
120
|
|
|
135
|
-
Tonnage resolves the package's own public import name from the manifest
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
dependencies resolve from the measured package, while its peer dependencies stay
|
|
140
|
-
external.
|
|
141
|
-
|
|
142
|
-
The default `platform` is `neutral`. For packages without `exports`, Tonnage
|
|
143
|
-
configures neutral resolution to try the `module` field and then `main`, so
|
|
144
|
-
main-only packages and dependencies are actionable by default. With conditional
|
|
145
|
-
`exports`, neutral does not enable the `browser` or `node` condition, so exports
|
|
146
|
-
commonly fall through to their `default` target. Set `platform` to `browser` or
|
|
147
|
-
`node` when that runtime is what you want to measure; those choices retain
|
|
148
|
-
esbuild's native export conditions and main-field behavior. A recipe's
|
|
149
|
-
`platform` overrides the report-wide setting for that recipe.
|
|
121
|
+
Tonnage resolves the package's own public import name from the selected manifest;
|
|
122
|
+
a workspace package does not need to install itself as a dependency. Root and
|
|
123
|
+
subpath imports go through esbuild's package resolver, so export restrictions
|
|
124
|
+
and conditions apply. Runtime dependencies resolve from the measured package.
|
|
150
125
|
|
|
151
|
-
|
|
126
|
+
The default `platform` is `neutral`. For packages without `exports`, neutral
|
|
127
|
+
resolution tries `module` and then `main`. With conditional `exports`, neutral
|
|
128
|
+
does not enable the `browser` or `node` condition, so exports commonly fall
|
|
129
|
+
through to `default`. Set `platform` to `browser` or `node` for those runtimes;
|
|
130
|
+
a recipe's `platform` overrides the report-wide setting.
|
|
152
131
|
|
|
153
|
-
|
|
132
|
+
## Migrating from the standalone workflow
|
|
154
133
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
<Example />
|
|
161
|
-
|
|
162
|
-
<Tonnage config={config} />
|
|
163
|
-
```
|
|
134
|
+
Move your maintained README content to `README.mdx` and replace generated-section
|
|
135
|
+
markers with `<Tonnage config={config} />`. Remove `marker` and `readme` from the
|
|
136
|
+
configuration. Import `Tonnage` from `tonnage` instead of `tonnage/galley`, and
|
|
137
|
+
replace `tonnage write` / `tonnage check` scripts with `galley write` /
|
|
138
|
+
`galley check`. Galley generates the entire README from its MDX source.
|
|
164
139
|
|
|
165
|
-
The
|
|
140
|
+
The tonnage executable, shell completion, standalone measurement/report APIs,
|
|
141
|
+
and Markdown section-editing helpers have been removed. Reusable configurations
|
|
142
|
+
can continue to use `defineConfig`; render reports through the component.
|
|
166
143
|
|
|
167
144
|
## Bundle size
|
|
168
145
|
|
|
@@ -170,9 +147,8 @@ Package export sizes include complete runtime export surfaces.
|
|
|
170
147
|
|
|
171
148
|
Sizes are exact minified and level-9 gzip JavaScript byte counts. Declarations, source maps, CSS, and other assets are excluded. Peer dependencies stay external, and shared modules are counted once per bundle.
|
|
172
149
|
|
|
173
|
-
| Import
|
|
174
|
-
|
|
|
175
|
-
| `tonnage`
|
|
176
|
-
| `tonnage/galley` | 484,581 B | 151,561 B |
|
|
150
|
+
| Import | Minified JS | Gzip JS |
|
|
151
|
+
| --------- | ----------: | -------: |
|
|
152
|
+
| `tonnage` | 49,281 B | 17,561 B |
|
|
177
153
|
|
|
178
154
|
Report maintained with [tonnage](https://github.com/jeremybanka/tonnage).
|
package/README.mdx
CHANGED
|
@@ -1,143 +1,122 @@
|
|
|
1
|
-
import { Tonnage } from "tonnage
|
|
1
|
+
import { Tonnage } from "tonnage"
|
|
2
2
|
import Configuration from "./examples/tonnage.config.ts" with { type: "code", lang: "ts" }
|
|
3
3
|
import Recipe from "./examples/recipes/react-app.ts" with { type: "code", lang: "ts" }
|
|
4
4
|
|
|
5
5
|
# tonnage
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
numbers drift.
|
|
7
|
+
Bundle size reports for [Galley](https://www.npmjs.com/package/galley.md) documents.
|
|
9
8
|
|
|
10
|
-
|
|
11
|
-
and reports JavaScript bytes before and after level-9 gzip.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
counted. Peer dependencies stay external, and shared modules are counted once
|
|
15
|
-
per bundle.
|
|
9
|
+
Tonnage bundles real public package imports with esbuild, minifies the result,
|
|
10
|
+
and reports JavaScript bytes before and after level-9 gzip. Embed its component
|
|
11
|
+
in a README source document, then use Galley to generate Markdown and detect
|
|
12
|
+
stale reports in CI.
|
|
16
13
|
|
|
17
|
-
##
|
|
18
|
-
|
|
19
|
-
Add the generated-section comments to the target README, then create a config
|
|
20
|
-
beside the package manifest. The complete configuration exhibit is in
|
|
21
|
-
[examples/tonnage.config.ts](./examples/tonnage.config.ts).
|
|
22
|
-
<Configuration />
|
|
14
|
+
## Install
|
|
23
15
|
|
|
24
|
-
|
|
25
|
-
[examples/recipes/react-app.ts](./examples/recipes/react-app.ts). Use named
|
|
26
|
-
imports in these files to represent the runtime surface a real application uses;
|
|
27
|
-
unused package exports are tree-shaken.
|
|
16
|
+
Install tonnage and its required Galley peer:
|
|
28
17
|
|
|
29
|
-
|
|
18
|
+
```sh
|
|
19
|
+
pnpm add -D tonnage 'galley.md@^0.1.1'
|
|
20
|
+
```
|
|
30
21
|
|
|
31
|
-
|
|
32
|
-
The opening and closing comments use the forms
|
|
33
|
-
`tonnage:my-package:start` and `tonnage:my-package:end`.
|
|
22
|
+
## Use
|
|
34
23
|
|
|
35
|
-
|
|
24
|
+
Create `README.mdx` beside your package manifest:
|
|
36
25
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
nonzero when the README is stale. Run `tonnage --help` to see both commands and
|
|
40
|
-
their optional config-path arguments.
|
|
26
|
+
```mdx
|
|
27
|
+
import { Tonnage } from "tonnage"
|
|
41
28
|
|
|
42
|
-
|
|
43
|
-
`tonnage write path/to/tonnage.config.ts`. Otherwise, Tonnage looks in the current
|
|
44
|
-
directory for `tonnage.config.ts`, then `tonnage.config.mjs`, then
|
|
45
|
-
`tonnage.config.js`. Config modules may use top-level `await`. Missing configs
|
|
46
|
-
are errors. Use `--` before a config path that starts with a dash.
|
|
29
|
+
# My package
|
|
47
30
|
|
|
48
|
-
|
|
49
|
-
|
|
31
|
+
<Tonnage config={{ platform: "node" }} />
|
|
32
|
+
```
|
|
50
33
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
files to describe realistic runtime boundaries, and `external` for non-peer
|
|
55
|
-
imports that the package intentionally leaves to its consumers.
|
|
34
|
+
Run `galley write` to generate `README.md`. Run `galley check` in CI to evaluate
|
|
35
|
+
the document again and exit nonzero if its output is missing or stale. Keep the
|
|
36
|
+
MDX source and generated Markdown in version control.
|
|
56
37
|
|
|
57
|
-
|
|
38
|
+
The component defaults to measuring every public export except `./package.json`.
|
|
39
|
+
Paths resolve relative to the containing document. To measure another package,
|
|
40
|
+
pass `directory`, such as `<Tonnage directory="../my-package" />`; relative
|
|
41
|
+
values resolve from the document's directory. The `packageJson` path resolves
|
|
42
|
+
from that measurement directory; recipe entry paths resolve from the selected
|
|
43
|
+
manifest's directory.
|
|
58
44
|
|
|
59
|
-
|
|
45
|
+
Galley owns document evaluation and output files. See its
|
|
46
|
+
[user guide](https://github.com/jeremybanka/galley#readme) for document composition
|
|
47
|
+
and command options.
|
|
60
48
|
|
|
61
|
-
|
|
62
|
-
tonnage completion install bash
|
|
63
|
-
tonnage completion install zsh
|
|
64
|
-
tonnage completion install fish
|
|
65
|
-
tonnage completion install nushell
|
|
66
|
-
tonnage completion install carapace
|
|
67
|
-
```
|
|
49
|
+
## Configure
|
|
68
50
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
editing shell profiles. It reports any setup needed for your shell. If Nushell
|
|
73
|
-
already uses Carapace, install only the Carapace integration.
|
|
51
|
+
Pass configuration inline or import a reusable configuration using `defineConfig`.
|
|
52
|
+
The complete configuration exhibit is in
|
|
53
|
+
[examples/tonnage.config.ts](./examples/tonnage.config.ts).
|
|
74
54
|
|
|
75
|
-
|
|
76
|
-
file without installing it. The `completion` command and comline's internal
|
|
77
|
-
completion protocol commands are reserved for shell integration.
|
|
55
|
+
<Configuration />
|
|
78
56
|
|
|
79
|
-
|
|
57
|
+
Import it explicitly in your document:
|
|
80
58
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
tables `Package exports` and `Usage examples` so readers can distinguish complete
|
|
85
|
-
runtime export surfaces from tree-shaken recipe bundles.
|
|
59
|
+
```mdx
|
|
60
|
+
import { Tonnage } from "tonnage"
|
|
61
|
+
import config from "./examples/tonnage.config.ts"
|
|
86
62
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
Peer dependencies remain external, and shared modules are counted once in each
|
|
90
|
-
bundle.
|
|
63
|
+
<Tonnage config={config} />
|
|
64
|
+
```
|
|
91
65
|
|
|
92
|
-
|
|
93
|
-
|
|
66
|
+
Importing configuration from another folder does not change path resolution.
|
|
67
|
+
Set `packageJson` to
|
|
68
|
+
select a manifest, `exports.include` or `exports.exclude` to select subpaths,
|
|
69
|
+
and `exports: false` to report only recipes. Use `heading` to customize the report
|
|
70
|
+
heading and `target` to set esbuild's JavaScript target. Use `external` for
|
|
71
|
+
additional imports intentionally supplied by consumers; peer dependencies are
|
|
72
|
+
already external.
|
|
94
73
|
|
|
95
|
-
|
|
74
|
+
Each recipe points to a reviewable entry file such as
|
|
75
|
+
[examples/recipes/react-app.ts](./examples/recipes/react-app.ts). Use named
|
|
76
|
+
imports to represent the runtime surface a real application uses; unused package
|
|
77
|
+
exports are tree-shaken. Keep server and client recipes separate.
|
|
96
78
|
|
|
97
|
-
|
|
98
|
-
import {
|
|
99
|
-
createTonnageReport,
|
|
100
|
-
defineConfig,
|
|
101
|
-
renderTonnageMarkdown,
|
|
102
|
-
} from "tonnage"
|
|
79
|
+
<Recipe />
|
|
103
80
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const markdown = await renderTonnageMarkdown(report, config)
|
|
107
|
-
```
|
|
81
|
+
The public API consists of `Tonnage`, `defineConfig`, and the `TonnageProps`,
|
|
82
|
+
`TonnageConfig`, `TonnageExports`, `TonnageRecipe`, and `BundlePlatform` types.
|
|
108
83
|
|
|
109
|
-
##
|
|
84
|
+
## Report layout
|
|
110
85
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
dependencies resolve from the measured package, while its peer dependencies stay
|
|
116
|
-
external.
|
|
86
|
+
Public-module rows retain the complete runtime export surface. Recipe rows
|
|
87
|
+
bundle their entry files and tree-shake unused exports. Exports-only and
|
|
88
|
+
recipes-only reports put their table directly below the report heading; a report
|
|
89
|
+
with both labels its tables `Package exports` and `Usage examples`.
|
|
117
90
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
`node` when that runtime is what you want to measure; those choices retain
|
|
124
|
-
esbuild's native export conditions and main-field behavior. A recipe's
|
|
125
|
-
`platform` overrides the report-wide setting for that recipe.
|
|
91
|
+
Sizes count minified JavaScript and level-9 gzip bytes. Declarations, source
|
|
92
|
+
maps, CSS, and other assets are excluded. Peer dependencies stay external, and
|
|
93
|
+
shared modules are counted once per bundle. Reports use Galley's native table
|
|
94
|
+
elements, with right-aligned byte columns and literal escaping for import names,
|
|
95
|
+
entry paths, and recipe labels.
|
|
126
96
|
|
|
127
|
-
##
|
|
97
|
+
## Package resolution and platforms
|
|
128
98
|
|
|
129
|
-
|
|
99
|
+
Tonnage resolves the package's own public import name from the selected manifest;
|
|
100
|
+
a workspace package does not need to install itself as a dependency. Root and
|
|
101
|
+
subpath imports go through esbuild's package resolver, so export restrictions
|
|
102
|
+
and conditions apply. Runtime dependencies resolve from the measured package.
|
|
130
103
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
104
|
+
The default `platform` is `neutral`. For packages without `exports`, neutral
|
|
105
|
+
resolution tries `module` and then `main`. With conditional `exports`, neutral
|
|
106
|
+
does not enable the `browser` or `node` condition, so exports commonly fall
|
|
107
|
+
through to `default`. Set `platform` to `browser` or `node` for those runtimes;
|
|
108
|
+
a recipe's `platform` overrides the report-wide setting.
|
|
135
109
|
|
|
136
|
-
|
|
110
|
+
## Migrating from the standalone workflow
|
|
137
111
|
|
|
138
|
-
|
|
139
|
-
|
|
112
|
+
Move your maintained README content to `README.mdx` and replace generated-section
|
|
113
|
+
markers with `<Tonnage config={config} />`. Remove `marker` and `readme` from the
|
|
114
|
+
configuration. Import `Tonnage` from `tonnage` instead of `tonnage/galley`, and
|
|
115
|
+
replace `tonnage write` / `tonnage check` scripts with `galley write` /
|
|
116
|
+
`galley check`. Galley generates the entire README from its MDX source.
|
|
140
117
|
|
|
141
|
-
The
|
|
118
|
+
The tonnage executable, shell completion, standalone measurement/report APIs,
|
|
119
|
+
and Markdown section-editing helpers have been removed. Reusable configurations
|
|
120
|
+
can continue to use `defineConfig`; render reports through the component.
|
|
142
121
|
|
|
143
|
-
<Tonnage config={{ platform: "node", exports: { include: ["."
|
|
122
|
+
<Tonnage config={{ platform: "node", exports: { include: ["."] } }} />
|
package/dist/index.d.mts
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
type MeasureImportsOptions = {
|
|
8
|
-
external?: readonly string[] | undefined;
|
|
9
|
-
platform?: BundlePlatform | undefined;
|
|
10
|
-
resolveDirectory: string;
|
|
11
|
-
target?: string | undefined;
|
|
1
|
+
import { DocumentContext, Element } from "galley.md";
|
|
2
|
+
//#region src/types.d.ts
|
|
3
|
+
type BundlePlatform = `browser` | `neutral` | `node`;
|
|
4
|
+
type TonnageExports = {
|
|
5
|
+
exclude?: readonly string[];
|
|
6
|
+
include?: readonly string[];
|
|
12
7
|
};
|
|
13
|
-
type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
type TonnageRecipe = {
|
|
9
|
+
entry: string;
|
|
10
|
+
external?: readonly string[];
|
|
11
|
+
name: string;
|
|
12
|
+
platform?: BundlePlatform;
|
|
13
|
+
};
|
|
14
|
+
type TonnageConfig = {
|
|
15
|
+
exports?: boolean | TonnageExports;
|
|
16
|
+
external?: readonly string[];
|
|
17
|
+
heading?: string;
|
|
18
|
+
packageJson?: string;
|
|
19
|
+
platform?: BundlePlatform;
|
|
20
|
+
recipes?: readonly TonnageRecipe[];
|
|
21
|
+
target?: string;
|
|
21
22
|
};
|
|
22
|
-
export declare function updateGeneratedSection(readme: string, markdown: string, marker?: string): string;
|
|
23
23
|
//#endregion
|
|
24
|
-
//#region src/
|
|
25
|
-
export declare function
|
|
26
|
-
/** Serialize a report with the same Galley elements used by the document component. */
|
|
27
|
-
export declare function renderTonnageMarkdown(report: TonnageReport, config?: TonnageConfig): Promise<string>;
|
|
24
|
+
//#region src/define-config.d.ts
|
|
25
|
+
export declare function defineConfig(config: TonnageConfig): TonnageConfig;
|
|
28
26
|
//#endregion
|
|
29
|
-
//#region src/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
//#region src/galley.d.ts
|
|
28
|
+
type TonnageProps = {
|
|
29
|
+
config?: TonnageConfig;
|
|
30
|
+
/** Override the document directory when measuring a different package. */
|
|
31
|
+
directory?: string;
|
|
32
|
+
};
|
|
33
|
+
/** Measure bundles and include the report in a galley.md document. */
|
|
34
|
+
export declare function Tonnage({ config, directory }: TonnageProps, context: DocumentContext): Promise<Element[]>;
|
|
34
35
|
//#endregion
|
|
35
|
-
export type {
|
|
36
|
+
export type { BundlePlatform, TonnageConfig, TonnageExports, TonnageProps, TonnageRecipe };
|
|
36
37
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/types.ts","../src/define-config.ts","../src/galley.ts"],"mappings":";;KAAY;KAEA;EACX;EACA;;KAGW;EACX;EACA;EACA;EACA,WAAW;;KAGA;EACX,oBAAoB;EACpB;EACA;EACA;EACA,WAAW;EACX,mBAAmB;EACnB;;;;wBCnBe,aAAa,QAAQ,gBAAgB;;;KCMzC;EACX,SAAS;;EAET;;;wBAIqB,UACnB,QAAa,aAAa,cAC5B,SAAS,kBACP,QAAQ"}
|