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 CHANGED
@@ -1,14 +1,13 @@
1
1
  # tonnage
2
2
 
3
- CI-first runtime JavaScript bundle measurement with checked-in README reports.
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 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.
10
12
  - Peer dependencies stay external by default. Use explicit `external` entries only for additional dependencies intentionally supplied by consumers.
11
- - Run `tonnage write` to update a generated README section and `tonnage check` in CI to detect drift.
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
- 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.
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
- Galley is required for CLI and programmatic report rendering as well as MDX documents.
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
- Add the generated-section comments to the target README, then create a config
26
- 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
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 in these files to represent the runtime surface a real application uses;
55
- 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.
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 default generated-section marker is `default`; the example uses `my-package`.
66
- The opening and closing comments use the forms
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
- Generated reports adapt to the measurements they contain. An exports-only or
116
- recipes-only report puts its table directly below the configured report heading
117
- and describes only that type of measurement. A report with both types labels the
118
- tables `Package exports` and `Usage examples` so readers can distinguish complete
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
- For programmatic use, await both measurement and Markdown rendering:
130
-
131
- ```ts
132
- import {
133
- createTonnageReport,
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 selected
146
- by `packageJson`; a workspace package does not need to install or declare itself
147
- as a dependency. Root and subpath imports still go through esbuild's package
148
- resolver, so the manifest's `exports` restrictions and conditions apply. Runtime
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`, Tonnage
153
- configures neutral resolution to try the `module` field and then `main`, so
154
- main-only packages and dependencies are actionable by default. With conditional
155
- `exports`, neutral does not enable the `browser` or `node` condition, so exports
156
- commonly fall through to their `default` target. Set `platform` to `browser` or
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
- ## MDX documents
132
+ ## Migrating from the standalone workflow
162
133
 
163
- Use [galley.md](https://www.npmjs.com/package/galley.md) to compose a README from source examples and reports:
164
-
165
- ```mdx
166
- import { Tonnage } from "tonnage/galley"
167
- import config from "./tonnage.config.ts"
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 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 uses your installed Galley peer; 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.
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 | Minified JS | Gzip JS |
184
- | ---------------- | ----------: | -------: |
185
- | `tonnage` | 50,614 B | 18,071 B |
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/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
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
- Galley is required for CLI and programmatic report rendering as well as MDX documents.
22
+ ## Use
26
23
 
27
- ## Configure
24
+ Create `README.mdx` beside your package manifest:
28
25
 
29
- Add the generated-section comments to the target README, then create a config
30
- beside the package manifest. The complete configuration exhibit is in
31
- [examples/tonnage.config.ts](./examples/tonnage.config.ts).
32
- <Configuration />
26
+ ```mdx
27
+ import { Tonnage } from "tonnage"
33
28
 
34
- Each recipe points to a reviewable entry file such as
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
- <Recipe />
31
+ <Tonnage config={{ platform: "node" }} />
32
+ ```
40
33
 
41
- The default generated-section marker is `default`; the example uses `my-package`.
42
- The opening and closing comments use the forms
43
- `tonnage:my-package:start` and `tonnage:my-package:end`.
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
- ## Run
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
- Run `tonnage write` during development to update the README. Run
48
- `tonnage check` in CI to recompute the same report without writing and exit
49
- nonzero when the README is stale. Run `tonnage --help` to see both commands and
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
- Pass a config path with `tonnage check path/to/tonnage.config.ts` or
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
- Unknown options are ignored with warnings on stderr. Warnings do not change the
59
- exit status; `check` still exits nonzero when the report is stale.
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
- By default the tool reads `package.json`, writes `README.md`, and measures every
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
- ### Shell completion
57
+ Import it explicitly in your document:
68
58
 
69
- With `tonnage` available on your shell's `PATH`, install completion for your shell:
59
+ ```mdx
60
+ import { Tonnage } from "tonnage"
61
+ import config from "./examples/tonnage.config.ts"
70
62
 
71
- ```sh
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
- Choose the integration you use. Completion suggests commands, help options, and
80
- config paths without loading your config or measuring bundles. Installation
81
- checks the shell's prerequisites and writes to its completion directory without
82
- editing shell profiles. It reports any setup needed for your shell. If Nushell
83
- already uses Carapace, install only the Carapace integration.
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
- Run `tonnage completion bash` (or another target above) to print the integration
86
- file without installing it. The `completion` command and comline's internal
87
- completion protocol commands are reserved for shell integration.
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
- Every layout states the exact measurement semantics: minified and level-9 gzip
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
- Reports use Galley's native table elements, with right-aligned byte columns and
103
- literal escaping for import names, entry paths, and recipe labels.
81
+ The public API consists of `Tonnage`, `defineConfig`, and the `TonnageProps`,
82
+ `TonnageConfig`, `TonnageExports`, `TonnageRecipe`, and `BundlePlatform` types.
104
83
 
105
- For programmatic use, await both measurement and Markdown rendering:
84
+ ## Report layout
106
85
 
107
- ```ts
108
- import {
109
- createTonnageReport,
110
- defineConfig,
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
- const config = defineConfig({ platform: "node" })
115
- const report = await createTonnageReport(config, process.cwd())
116
- const markdown = await renderTonnageMarkdown(report, config)
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 selected
122
- by `packageJson`; a workspace package does not need to install or declare itself
123
- as a dependency. Root and subpath imports still go through esbuild's package
124
- resolver, so the manifest's `exports` restrictions and conditions apply. Runtime
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
- ## MDX documents
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
- Use [galley.md](https://www.npmjs.com/package/galley.md) to compose a README from source examples and reports:
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
- <Example />
147
-
148
- <Tonnage config={config} />
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 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 uses your installed Galley peer; 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.
152
121
 
153
- <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"}