tonnage 0.3.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 -8
- package/CHANGELOG.md +6 -0
- package/README.md +84 -118
- package/README.mdx +78 -109
- 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 +5 -13
- 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,14 +1,13 @@
|
|
|
1
1
|
# tonnage
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
- Install `galley.md@^0.1.1` alongside tonnage. It is a required peer for CLI rendering, the programmatic API, and MDX components.
|
|
3
|
+
Runtime JavaScript bundle measurement for Galley documents.
|
|
6
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.
|
|
7
9
|
- Tonnage measures emitted minified JavaScript and level-9 gzip bytes. Do not include declarations, source maps, CSS, or other assets in those figures.
|
|
8
10
|
- Public-module rows retain the complete runtime export surface. Recipe rows use reviewable entry files and tree-shake unused exports.
|
|
9
|
-
- 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.
|
|
10
12
|
- Peer dependencies stay external by default. Use explicit `external` entries only for additional dependencies intentionally supplied by consumers.
|
|
11
|
-
-
|
|
12
|
-
- Keep marker names stable and use the `tonnage:<name>:start` and `tonnage:<name>:end` comment forms.
|
|
13
|
-
- 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.
|
|
14
|
-
- 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,11 @@
|
|
|
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
|
+
|
|
3
9
|
## 0.3.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
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
|
-
counted. Peer dependencies stay external, and shared modules are counted once
|
|
11
|
-
per bundle.
|
|
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.
|
|
12
9
|
|
|
13
10
|
## Install
|
|
14
11
|
|
|
@@ -18,12 +15,37 @@ Install tonnage and its required Galley peer:
|
|
|
18
15
|
pnpm add -D tonnage 'galley.md@^0.1.1'
|
|
19
16
|
```
|
|
20
17
|
|
|
21
|
-
|
|
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.
|
|
22
44
|
|
|
23
45
|
## Configure
|
|
24
46
|
|
|
25
|
-
|
|
26
|
-
|
|
47
|
+
Pass configuration inline or import a reusable configuration using `defineConfig`.
|
|
48
|
+
The complete configuration exhibit is in
|
|
27
49
|
[examples/tonnage.config.ts](./examples/tonnage.config.ts).
|
|
28
50
|
|
|
29
51
|
```ts
|
|
@@ -34,7 +56,6 @@ const config: TonnageConfig = defineConfig({
|
|
|
34
56
|
exports: {
|
|
35
57
|
exclude: [`./package.json`],
|
|
36
58
|
},
|
|
37
|
-
marker: `my-package`,
|
|
38
59
|
recipes: [
|
|
39
60
|
{
|
|
40
61
|
entry: `examples/recipes/react-app.ts`,
|
|
@@ -49,10 +70,27 @@ export default config
|
|
|
49
70
|
|
|
50
71
|
```
|
|
51
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
|
+
|
|
52
90
|
Each recipe points to a reviewable entry file such as
|
|
53
91
|
[examples/recipes/react-app.ts](./examples/recipes/react-app.ts). Use named
|
|
54
|
-
imports
|
|
55
|
-
|
|
92
|
+
imports to represent the runtime surface a real application uses; unused package
|
|
93
|
+
exports are tree-shaken. Keep server and client recipes separate.
|
|
56
94
|
|
|
57
95
|
```ts
|
|
58
96
|
// @exhibit-region start recipe
|
|
@@ -62,117 +100,46 @@ export { useO } from "my-package/react"
|
|
|
62
100
|
|
|
63
101
|
```
|
|
64
102
|
|
|
65
|
-
The
|
|
66
|
-
|
|
67
|
-
`tonnage:my-package:start` and `tonnage:my-package:end`.
|
|
68
|
-
|
|
69
|
-
## Run
|
|
70
|
-
|
|
71
|
-
Run `tonnage write` during development to update the README. Run
|
|
72
|
-
`tonnage check` in CI to recompute the same report without writing and exit
|
|
73
|
-
nonzero when the README is stale. Run `tonnage --help` to see both commands and
|
|
74
|
-
their optional config-path arguments.
|
|
75
|
-
|
|
76
|
-
Pass a config path with `tonnage check path/to/tonnage.config.ts` or
|
|
77
|
-
`tonnage write path/to/tonnage.config.ts`. Otherwise, Tonnage looks in the current
|
|
78
|
-
directory for `tonnage.config.ts`, then `tonnage.config.mjs`, then
|
|
79
|
-
`tonnage.config.js`. Config modules may use top-level `await`. Missing configs
|
|
80
|
-
are errors. Use `--` before a config path that starts with a dash.
|
|
81
|
-
|
|
82
|
-
Unknown options are ignored with warnings on stderr. Warnings do not change the
|
|
83
|
-
exit status; `check` still exits nonzero when the report is stale.
|
|
84
|
-
|
|
85
|
-
By default the tool reads `package.json`, writes `README.md`, and measures every
|
|
86
|
-
public export except `./package.json`. Paths are resolved relative to the config
|
|
87
|
-
file. Use `exports.include` or `exports.exclude` to select subpaths, recipe entry
|
|
88
|
-
files to describe realistic runtime boundaries, and `external` for non-peer
|
|
89
|
-
imports that the package intentionally leaves to its consumers.
|
|
90
|
-
|
|
91
|
-
### Shell completion
|
|
92
|
-
|
|
93
|
-
With `tonnage` available on your shell's `PATH`, install completion for your shell:
|
|
94
|
-
|
|
95
|
-
```sh
|
|
96
|
-
tonnage completion install bash
|
|
97
|
-
tonnage completion install zsh
|
|
98
|
-
tonnage completion install fish
|
|
99
|
-
tonnage completion install nushell
|
|
100
|
-
tonnage completion install carapace
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Choose the integration you use. Completion suggests commands, help options, and
|
|
104
|
-
config paths without loading your config or measuring bundles. Installation
|
|
105
|
-
checks the shell's prerequisites and writes to its completion directory without
|
|
106
|
-
editing shell profiles. It reports any setup needed for your shell. If Nushell
|
|
107
|
-
already uses Carapace, install only the Carapace integration.
|
|
108
|
-
|
|
109
|
-
Run `tonnage completion bash` (or another target above) to print the integration
|
|
110
|
-
file without installing it. The `completion` command and comline's internal
|
|
111
|
-
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.
|
|
112
105
|
|
|
113
106
|
## Report layout
|
|
114
107
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
tables `Package exports` and `Usage examples
|
|
119
|
-
runtime export surfaces from tree-shaken recipe bundles.
|
|
120
|
-
|
|
121
|
-
Every layout states the exact measurement semantics: minified and level-9 gzip
|
|
122
|
-
JavaScript bytes, with declarations, source maps, CSS, and other assets excluded.
|
|
123
|
-
Peer dependencies remain external, and shared modules are counted once in each
|
|
124
|
-
bundle.
|
|
125
|
-
|
|
126
|
-
Reports use Galley's native table elements, with right-aligned byte columns and
|
|
127
|
-
literal escaping for import names, entry paths, and recipe labels.
|
|
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`.
|
|
128
112
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
import
|
|
133
|
-
|
|
134
|
-
defineConfig,
|
|
135
|
-
renderTonnageMarkdown,
|
|
136
|
-
} from "tonnage"
|
|
137
|
-
|
|
138
|
-
const config = defineConfig({ platform: "node" })
|
|
139
|
-
const report = await createTonnageReport(config, process.cwd())
|
|
140
|
-
const markdown = await renderTonnageMarkdown(report, config)
|
|
141
|
-
```
|
|
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.
|
|
142
118
|
|
|
143
119
|
## Package resolution and platforms
|
|
144
120
|
|
|
145
|
-
Tonnage resolves the package's own public import name from the manifest
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
dependencies resolve from the measured package, while its peer dependencies stay
|
|
150
|
-
external.
|
|
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.
|
|
151
125
|
|
|
152
|
-
The default `platform` is `neutral`. For packages without `exports`,
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
`node` when that runtime is what you want to measure; those choices retain
|
|
158
|
-
esbuild's native export conditions and main-field behavior. A recipe's
|
|
159
|
-
`platform` overrides the report-wide setting for that recipe.
|
|
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.
|
|
160
131
|
|
|
161
|
-
##
|
|
132
|
+
## Migrating from the standalone workflow
|
|
162
133
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
import Example from "./examples/recipes/react-app.ts" with { type: "code", lang: "ts" }
|
|
169
|
-
|
|
170
|
-
<Example />
|
|
171
|
-
|
|
172
|
-
<Tonnage config={config} />
|
|
173
|
-
```
|
|
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.
|
|
174
139
|
|
|
175
|
-
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.
|
|
176
143
|
|
|
177
144
|
## Bundle size
|
|
178
145
|
|
|
@@ -180,9 +147,8 @@ Package export sizes include complete runtime export surfaces.
|
|
|
180
147
|
|
|
181
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.
|
|
182
149
|
|
|
183
|
-
| Import
|
|
184
|
-
|
|
|
185
|
-
| `tonnage`
|
|
186
|
-
| `tonnage/galley` | 49,315 B | 17,579 B |
|
|
150
|
+
| Import | Minified JS | Gzip JS |
|
|
151
|
+
| --------- | ----------: | -------: |
|
|
152
|
+
| `tonnage` | 49,281 B | 17,561 B |
|
|
187
153
|
|
|
188
154
|
Report maintained with [tonnage](https://github.com/jeremybanka/tonnage).
|
package/README.mdx
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
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
14
|
## Install
|
|
18
15
|
|
|
@@ -22,132 +19,104 @@ Install tonnage and its required Galley peer:
|
|
|
22
19
|
pnpm add -D tonnage 'galley.md@^0.1.1'
|
|
23
20
|
```
|
|
24
21
|
|
|
25
|
-
|
|
22
|
+
## Use
|
|
26
23
|
|
|
27
|
-
|
|
24
|
+
Create `README.mdx` beside your package manifest:
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
[examples/tonnage.config.ts](./examples/tonnage.config.ts).
|
|
32
|
-
<Configuration />
|
|
26
|
+
```mdx
|
|
27
|
+
import { Tonnage } from "tonnage"
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
[examples/recipes/react-app.ts](./examples/recipes/react-app.ts). Use named
|
|
36
|
-
imports in these files to represent the runtime surface a real application uses;
|
|
37
|
-
unused package exports are tree-shaken.
|
|
29
|
+
# My package
|
|
38
30
|
|
|
39
|
-
<
|
|
31
|
+
<Tonnage config={{ platform: "node" }} />
|
|
32
|
+
```
|
|
40
33
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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.
|
|
44
37
|
|
|
45
|
-
|
|
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.
|
|
46
44
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
their optional config-path arguments.
|
|
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.
|
|
51
48
|
|
|
52
|
-
|
|
53
|
-
`tonnage write path/to/tonnage.config.ts`. Otherwise, Tonnage looks in the current
|
|
54
|
-
directory for `tonnage.config.ts`, then `tonnage.config.mjs`, then
|
|
55
|
-
`tonnage.config.js`. Config modules may use top-level `await`. Missing configs
|
|
56
|
-
are errors. Use `--` before a config path that starts with a dash.
|
|
49
|
+
## Configure
|
|
57
50
|
|
|
58
|
-
|
|
59
|
-
|
|
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).
|
|
60
54
|
|
|
61
|
-
|
|
62
|
-
public export except `./package.json`. Paths are resolved relative to the config
|
|
63
|
-
file. Use `exports.include` or `exports.exclude` to select subpaths, recipe entry
|
|
64
|
-
files to describe realistic runtime boundaries, and `external` for non-peer
|
|
65
|
-
imports that the package intentionally leaves to its consumers.
|
|
55
|
+
<Configuration />
|
|
66
56
|
|
|
67
|
-
|
|
57
|
+
Import it explicitly in your document:
|
|
68
58
|
|
|
69
|
-
|
|
59
|
+
```mdx
|
|
60
|
+
import { Tonnage } from "tonnage"
|
|
61
|
+
import config from "./examples/tonnage.config.ts"
|
|
70
62
|
|
|
71
|
-
|
|
72
|
-
tonnage completion install bash
|
|
73
|
-
tonnage completion install zsh
|
|
74
|
-
tonnage completion install fish
|
|
75
|
-
tonnage completion install nushell
|
|
76
|
-
tonnage completion install carapace
|
|
63
|
+
<Tonnage config={config} />
|
|
77
64
|
```
|
|
78
65
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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.
|
|
84
73
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
## Report layout
|
|
90
|
-
|
|
91
|
-
Generated reports adapt to the measurements they contain. An exports-only or
|
|
92
|
-
recipes-only report puts its table directly below the configured report heading
|
|
93
|
-
and describes only that type of measurement. A report with both types labels the
|
|
94
|
-
tables `Package exports` and `Usage examples` so readers can distinguish complete
|
|
95
|
-
runtime export surfaces from tree-shaken recipe bundles.
|
|
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
|
-
JavaScript bytes, with declarations, source maps, CSS, and other assets excluded.
|
|
99
|
-
Peer dependencies remain external, and shared modules are counted once in each
|
|
100
|
-
bundle.
|
|
79
|
+
<Recipe />
|
|
101
80
|
|
|
102
|
-
|
|
103
|
-
|
|
81
|
+
The public API consists of `Tonnage`, `defineConfig`, and the `TonnageProps`,
|
|
82
|
+
`TonnageConfig`, `TonnageExports`, `TonnageRecipe`, and `BundlePlatform` types.
|
|
104
83
|
|
|
105
|
-
|
|
84
|
+
## Report layout
|
|
106
85
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
renderTonnageMarkdown,
|
|
112
|
-
} from "tonnage"
|
|
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`.
|
|
113
90
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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.
|
|
118
96
|
|
|
119
97
|
## Package resolution and platforms
|
|
120
98
|
|
|
121
|
-
Tonnage resolves the package's own public import name from the manifest
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
dependencies resolve from the measured package, while its peer dependencies stay
|
|
126
|
-
external.
|
|
127
|
-
|
|
128
|
-
The default `platform` is `neutral`. For packages without `exports`, Tonnage
|
|
129
|
-
configures neutral resolution to try the `module` field and then `main`, so
|
|
130
|
-
main-only packages and dependencies are actionable by default. With conditional
|
|
131
|
-
`exports`, neutral does not enable the `browser` or `node` condition, so exports
|
|
132
|
-
commonly fall through to their `default` target. Set `platform` to `browser` or
|
|
133
|
-
`node` when that runtime is what you want to measure; those choices retain
|
|
134
|
-
esbuild's native export conditions and main-field behavior. A recipe's
|
|
135
|
-
`platform` overrides the report-wide setting for that recipe.
|
|
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.
|
|
136
103
|
|
|
137
|
-
|
|
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.
|
|
138
109
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
```mdx
|
|
142
|
-
import { Tonnage } from "tonnage/galley"
|
|
143
|
-
import config from "./tonnage.config.ts"
|
|
144
|
-
import Example from "./examples/recipes/react-app.ts" with { type: "code", lang: "ts" }
|
|
110
|
+
## Migrating from the standalone workflow
|
|
145
111
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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.
|
|
150
117
|
|
|
151
|
-
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.
|
|
152
121
|
|
|
153
|
-
<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"}
|