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 CHANGED
@@ -1,12 +1,13 @@
1
1
  # tonnage
2
2
 
3
- CI-first runtime JavaScript bundle measurement with checked-in README reports.
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 within each bundle.
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
- - Run `tonnage write` to update a generated README section and `tonnage check` in CI to detect drift.
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
- Keep exact bundle size tables in a package README and fail CI when the checked-in
4
- numbers drift.
3
+ Bundle size reports for [Galley](https://www.npmjs.com/package/galley.md) documents.
5
4
 
6
- The tool bundles real public package imports with esbuild, minifies the result,
7
- and reports JavaScript bytes before and after level-9 gzip. Public-module rows
8
- retain every runtime export; recipe entry files can select named exports and
9
- tree-shake the rest. Declarations, source maps, CSS, and other assets are not
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.
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
- Add the generated-section comments to the target README, then create a config
16
- beside the package manifest. The complete configuration exhibit is in
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 in these files to represent the runtime surface a real application uses;
45
- unused package exports are tree-shaken.
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 default generated-section marker is `default`; the example uses `my-package`.
56
- The opening and closing comments use the forms
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
- Generated reports adapt to the measurements they contain. An exports-only or
106
- recipes-only report puts its table directly below the configured report heading
107
- and describes only that type of measurement. A report with both types labels the
108
- tables `Package exports` and `Usage examples` so readers can distinguish complete
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
- Every layout states the exact measurement semantics: minified and level-9 gzip
112
- JavaScript bytes, with declarations, source maps, CSS, and other assets excluded.
113
- Peer dependencies remain external, and shared modules are counted once in each
114
- bundle.
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 selected
136
- by `packageJson`; a workspace package does not need to install or declare itself
137
- as a dependency. Root and subpath imports still go through esbuild's package
138
- resolver, so the manifest's `exports` restrictions and conditions apply. Runtime
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
- ## MDX documents
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
- Use [galley.md](https://www.npmjs.com/package/galley.md) to compose a README from source examples and reports:
132
+ ## Migrating from the standalone workflow
154
133
 
155
- ```mdx
156
- import { Tonnage } from "tonnage/galley"
157
- import config from "./tonnage.config.ts"
158
- import Example from "./examples/recipes/react-app.ts" with { type: "code", lang: "ts" }
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 component resolves paths relative to the containing document. Pass `directory` to measure another package. It produces the same tables as the CLI without writing a README or requiring generated-section markers. Tonnage includes Galley as a runtime dependency; add `galley.md` directly to your project's development dependencies to run `galley write` and `galley check` when authoring documents.
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 | Minified JS | Gzip JS |
174
- | ---------------- | ----------: | --------: |
175
- | `tonnage` | 491,915 B | 153,965 B |
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/galley"
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
- Keep exact bundle size tables in a package README and fail CI when the checked-in
8
- numbers drift.
7
+ Bundle size reports for [Galley](https://www.npmjs.com/package/galley.md) documents.
9
8
 
10
- The tool bundles real public package imports with esbuild, minifies the result,
11
- and reports JavaScript bytes before and after level-9 gzip. Public-module rows
12
- retain every runtime export; recipe entry files can select named exports and
13
- tree-shake the rest. Declarations, source maps, CSS, and other assets are not
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
- ## Configure
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
- Each recipe points to a reviewable entry file such as
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
- <Recipe />
18
+ ```sh
19
+ pnpm add -D tonnage 'galley.md@^0.1.1'
20
+ ```
30
21
 
31
- The default generated-section marker is `default`; the example uses `my-package`.
32
- The opening and closing comments use the forms
33
- `tonnage:my-package:start` and `tonnage:my-package:end`.
22
+ ## Use
34
23
 
35
- ## Run
24
+ Create `README.mdx` beside your package manifest:
36
25
 
37
- Run `tonnage write` during development to update the README. Run
38
- `tonnage check` in CI to recompute the same report without writing and exit
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
- Pass a config path with `tonnage check path/to/tonnage.config.ts` or
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
- Unknown options are ignored with warnings on stderr. Warnings do not change the
49
- exit status; `check` still exits nonzero when the report is stale.
31
+ <Tonnage config={{ platform: "node" }} />
32
+ ```
50
33
 
51
- By default the tool reads `package.json`, writes `README.md`, and measures every
52
- public export except `./package.json`. Paths are resolved relative to the config
53
- file. Use `exports.include` or `exports.exclude` to select subpaths, recipe entry
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
- ### Shell completion
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
- With `tonnage` available on your shell's `PATH`, install completion for your shell:
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
- ```sh
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
- Choose the integration you use. Completion suggests commands, help options, and
70
- config paths without loading your config or measuring bundles. Installation
71
- checks the shell's prerequisites and writes to its completion directory without
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
- Run `tonnage completion bash` (or another target above) to print the integration
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
- ## Report layout
57
+ Import it explicitly in your document:
80
58
 
81
- Generated reports adapt to the measurements they contain. An exports-only or
82
- recipes-only report puts its table directly below the configured report heading
83
- and describes only that type of measurement. A report with both types labels the
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
- Every layout states the exact measurement semantics: minified and level-9 gzip
88
- JavaScript bytes, with declarations, source maps, CSS, and other assets excluded.
89
- Peer dependencies remain external, and shared modules are counted once in each
90
- bundle.
63
+ <Tonnage config={config} />
64
+ ```
91
65
 
92
- Reports use Galley's native table elements, with right-aligned byte columns and
93
- literal escaping for import names, entry paths, and recipe labels.
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
- For programmatic use, await both measurement and Markdown rendering:
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
- ```ts
98
- import {
99
- createTonnageReport,
100
- defineConfig,
101
- renderTonnageMarkdown,
102
- } from "tonnage"
79
+ <Recipe />
103
80
 
104
- const config = defineConfig({ platform: "node" })
105
- const report = await createTonnageReport(config, process.cwd())
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
- ## Package resolution and platforms
84
+ ## Report layout
110
85
 
111
- Tonnage resolves the package's own public import name from the manifest selected
112
- by `packageJson`; a workspace package does not need to install or declare itself
113
- as a dependency. Root and subpath imports still go through esbuild's package
114
- resolver, so the manifest's `exports` restrictions and conditions apply. Runtime
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
- The default `platform` is `neutral`. For packages without `exports`, Tonnage
119
- configures neutral resolution to try the `module` field and then `main`, so
120
- main-only packages and dependencies are actionable by default. With conditional
121
- `exports`, neutral does not enable the `browser` or `node` condition, so exports
122
- commonly fall through to their `default` target. Set `platform` to `browser` or
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
- ## MDX documents
97
+ ## Package resolution and platforms
128
98
 
129
- Use [galley.md](https://www.npmjs.com/package/galley.md) to compose a README from source examples and reports:
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
- ```mdx
132
- import { Tonnage } from "tonnage/galley"
133
- import config from "./tonnage.config.ts"
134
- import Example from "./examples/recipes/react-app.ts" with { type: "code", lang: "ts" }
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
- <Example />
110
+ ## Migrating from the standalone workflow
137
111
 
138
- <Tonnage config={config} />
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 component resolves paths relative to the containing document. Pass `directory` to measure another package. It produces the same tables as the CLI without writing a README or requiring generated-section markers. Tonnage includes Galley as a runtime dependency; add `galley.md` directly to your project's development dependencies to run `galley write` and `galley check` when authoring documents.
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: [".", "./galley"] } }} />
122
+ <Tonnage config={{ platform: "node", exports: { include: ["."] } }} />
package/dist/index.d.mts CHANGED
@@ -1,36 +1,37 @@
1
- import { a as TonnageMode, c as TonnageReport, i as TonnageExports, l as TonnageRow, n as BundlePlatform, o as TonnageRecipe, r as TonnageConfig, s as TonnageRecipeRow, t as BundleMeasurement, u as TonnageRunResult } from "./types-Ddtp95Z3.mjs";
2
- import "esbuild";
3
- //#region src/define-config.d.ts
4
- export declare function defineConfig(config: TonnageConfig): TonnageConfig;
5
- //#endregion
6
- //#region src/measure.d.ts
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 MeasureEntryOptions = MeasureImportsOptions;
14
- export declare function measureEntry(entry: string, options: MeasureEntryOptions): Promise<BundleMeasurement>;
15
- export declare function measureImports(imports: readonly string[], options: MeasureImportsOptions): Promise<BundleMeasurement>;
16
- //#endregion
17
- //#region src/readme.d.ts
18
- export declare function tonnageMarkers(marker?: string): {
19
- end: string;
20
- start: string;
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/report.d.ts
25
- export declare function createTonnageReport(config: TonnageConfig, configDirectory: string): Promise<TonnageReport>;
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/run.d.ts
30
- export declare function runTonnage(config: TonnageConfig, options: {
31
- configDirectory?: string;
32
- mode: TonnageMode;
33
- }): Promise<TonnageRunResult>;
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 { BundleMeasurement, BundlePlatform, MeasureEntryOptions, MeasureImportsOptions, TonnageConfig, TonnageExports, TonnageMode, TonnageRecipe, TonnageRecipeRow, TonnageReport, TonnageRow, TonnageRunResult };
36
+ export type { BundlePlatform, TonnageConfig, TonnageExports, TonnageProps, TonnageRecipe };
36
37
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/define-config.ts","../src/measure.ts","../src/readme.ts","../src/report.ts","../src/run.ts"],"mappings":";;;wBAEgB,aAAa,QAAQ,gBAAgB;;;KCKzC;EACX;EACA,WAAW;EACX;EACA;;KAGW,sBAAsB;wBAMZ,aACrB,eACA,SAAS,sBACP,QAAQ;wBAcW,eACrB,4BACA,SAAS,wBACP,QAAQ;;;wBCxCK,eAAe;EAC9B;EACA;;wBASe,uBACf,gBACA,kBACA;;;wBCUqB,oBACrB,QAAQ,eACR,0BACE,QAAQ;;wBAgEW,sBACrB,QAAQ,eACR,SAAQ,gBACN;;;wBCvFmB,WACrB,QAAQ,eACR;EACC;EACA,MAAM;IAEL,QAAQ"}
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"}