@savvy-web/bundler 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/README.md +18 -1
- package/config.js +1 -0
- package/index.d.ts +11 -1
- package/package.json +2 -2
- package/run.js +6 -3
package/README.md
CHANGED
|
@@ -202,6 +202,22 @@ const config = defineBuild({
|
|
|
202
202
|
|
|
203
203
|
Each override carries the same `format`, `bundle`, `externals`, `bundleNodeModules`, `bundledPackages` and `dtsExternals` fields as the base config. An override does not inherit the base `externals` — list what that partition needs. The build errors if an override names an export path the package does not declare.
|
|
204
204
|
|
|
205
|
+
## Loose files
|
|
206
|
+
|
|
207
|
+
Every output above lands at a path the package's `exports` map addresses. Some files have to sit at a fixed name the runtime resolves by convention, outside that graph — a pnpm config dependency, for one, forbids runtime `dependencies` and resolves its `pnpmfile.mjs`/`pnpmfile.cjs` by filename at the package root. Use `looseFiles` to emit a standalone bundled file at a literal output path, with no exports entry, no declaration and no api-model:
|
|
208
|
+
|
|
209
|
+
```ts
|
|
210
|
+
const config = defineBuild({
|
|
211
|
+
bundleNodeModules: true,
|
|
212
|
+
looseFiles: {
|
|
213
|
+
"pnpmfile.mjs": "./src/pnpmfile.ts",
|
|
214
|
+
"pnpmfile.cjs": "./src/pnpmfile.ts",
|
|
215
|
+
},
|
|
216
|
+
});
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
Each key is the literal output filename written into the package root; each value is a source path (a bare string) or a `{ source, format }` object. The format is inferred from the key extension — `.mjs` is ESM, `.cjs` is CJS — so the example above bundles the one source into both an ESM and a CJS file from a single config. A `.js` key is format-ambiguous and needs an explicit `format`. Pair `looseFiles` with `bundleNodeModules` so each file is self-contained, since a config dependency cannot resolve runtime `dependencies` of its own.
|
|
220
|
+
|
|
205
221
|
## Minified output
|
|
206
222
|
|
|
207
223
|
Prod output is not minified by default. This builder targets Node libraries, where readable output matters more than bundle size — minified code degrades stack traces and trips some security scanners. Set `minify` to opt back in:
|
|
@@ -262,6 +278,7 @@ const config = defineBuild({
|
|
|
262
278
|
- **Dual-format output** — esm-only by default; set `format` to `["esm", "cjs"]` for a require-able CJS output with default-export interop, `.d.cts` declarations and dual `import`/`require` export conditions.
|
|
263
279
|
- **Dependency bundling** — declared dependencies stay external by default; `bundle`, `bundleNodeModules`, `bundledPackages` and `dtsExternals` force-inline specific packages or all node_modules into the output, inline select declarations into the `.d.ts` or hold a package out of the declaration bundle when its types cannot be inlined.
|
|
264
280
|
- **Per-entry overrides** — `overrides` pins a subset of export entries to their own format and bundling, so one entry can ship dual-format CJS in an otherwise ESM-only package without changing the rest.
|
|
281
|
+
- **Loose files** — `looseFiles` emits standalone bundled files at literal output paths outside the exports/declaration/api-model graph, with the format inferred from the key extension; pair with `bundleNodeModules` for self-contained pnpm config-dependency pnpmfiles.
|
|
265
282
|
- **Readable prod output** — prod output is unminified by default to keep stack traces legible and pass security scanners; `minify` opts back in.
|
|
266
283
|
- **Default manifest stripping** — the published `package.json` drops build- and dev-only fields automatically; a custom `transform` replaces the default and can re-apply it via `defaultManifestTransform`.
|
|
267
284
|
- **Build-time constants** — the package version is injected as `process.env.__PACKAGE_VERSION__`, and the `define` field adds your own verbatim compile-time replacements.
|
|
@@ -272,7 +289,7 @@ const config = defineBuild({
|
|
|
272
289
|
|
|
273
290
|
## API
|
|
274
291
|
|
|
275
|
-
- `defineBuild(input)` — normalizes a build config (`externals`, `bundle`, `bundleNodeModules`, `bundledPackages`, `dtsExternals`, `minify`, `devManifest`, `transform`, `output`, `meta`, `jsx`, `exe`, `format`, `overrides`, `define`), applying defaults. The `format` field controls the output module formats forwarded to tsdown (esm-only by default; add `"cjs"` for a dual-format esm+cjs build). `minify` defaults to false, `transform` defaults to a manifest stripper, and `overrides` pins a subset of entries to their own format and bundling. Pure; it does not run the build.
|
|
292
|
+
- `defineBuild(input)` — normalizes a build config (`externals`, `bundle`, `bundleNodeModules`, `bundledPackages`, `dtsExternals`, `minify`, `devManifest`, `transform`, `output`, `meta`, `jsx`, `exe`, `format`, `overrides`, `looseFiles`, `define`), applying defaults. The `format` field controls the output module formats forwarded to tsdown (esm-only by default; add `"cjs"` for a dual-format esm+cjs build). `minify` defaults to false, `transform` defaults to a manifest stripper, and `overrides` pins a subset of entries to their own format and bundling. Pure; it does not run the build.
|
|
276
293
|
- `runBuild(config, options)` — the orchestrator. Parses `--target`/`--watch` from `options.argv`, reads `package.json` at `options.cwd`, derives entries, drives the build for the selected target and renders a report. Every IO dependency on `options` is injectable for tests.
|
|
277
294
|
- `parseArgs(argv)` — the argument parser behind `runBuild`, exported for embedding.
|
|
278
295
|
|
package/config.js
CHANGED
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BuildFormat, BuildTargetGroupsOptions, ExeConfig, GenerateMetaOptions, Json, JsxConfig, MetaOptions, MetaResult, PublishTargets, RenderedOutput, RunExeBuildOptions, TargetGroupRef, TargetResolution, TsconfigJsx, defaultManifestTransform } from "@savvy-web/tsdown-plugins";
|
|
1
|
+
import { BuildFormat, BuildTargetGroupsOptions, ExeConfig, GenerateMetaOptions, Json, JsxConfig, LooseFiles, MetaOptions, MetaResult, PublishTargets, RenderedOutput, RunExeBuildOptions, TargetGroupRef, TargetResolution, TsconfigJsx, defaultManifestTransform } from "@savvy-web/tsdown-plugins";
|
|
2
2
|
|
|
3
3
|
//#region src/config.d.ts
|
|
4
4
|
interface BuildEntryOverride {
|
|
@@ -96,6 +96,14 @@ interface BuildConfigInput {
|
|
|
96
96
|
* an otherwise ESM-only package (e.g. silk's `./changesets/markdownlint`).
|
|
97
97
|
*/
|
|
98
98
|
readonly overrides?: ReadonlyArray<BuildEntryOverride> | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* Standalone bundled output files emitted at literal paths (e.g. pnpm config-dependency
|
|
101
|
+
* pnpmfiles), outside the exports/dts/meta graph. Keys are literal output filenames; values
|
|
102
|
+
* are a source path (bare string) or `{ source, format }`. Format is inferred from a
|
|
103
|
+
* `.mjs`/`.cjs` key and required for an ambiguous `.js` key. Pair with `bundleNodeModules`
|
|
104
|
+
* to make each file self-contained.
|
|
105
|
+
*/
|
|
106
|
+
readonly looseFiles?: LooseFiles | undefined;
|
|
99
107
|
/**
|
|
100
108
|
* Compile-time global replacements forwarded to the tsdown/rolldown build `define`.
|
|
101
109
|
* Values are inserted VERBATIM, so string literals must be quoted:
|
|
@@ -145,6 +153,8 @@ interface BuildConfig {
|
|
|
145
153
|
/** Output module formats forwarded to the tsdown build (esm-only by default; add "cjs" for dual-format). */
|
|
146
154
|
readonly format?: ReadonlyArray<BuildFormat> | undefined;
|
|
147
155
|
readonly overrides?: ReadonlyArray<BuildEntryOverride> | undefined;
|
|
156
|
+
/** Standalone bundled output files emitted at literal paths, outside the exports/dts/meta graph. */
|
|
157
|
+
readonly looseFiles?: LooseFiles | undefined;
|
|
148
158
|
/** Compile-time global replacements forwarded to the build `define` (merged with the auto-version). */
|
|
149
159
|
readonly define?: Record<string, string> | undefined;
|
|
150
160
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@savvy-web/bundler",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Zero-config tsdown-based bundler for Silk Suite TypeScript packages",
|
|
6
6
|
"homepage": "https://github.com/savvy-web/systems/tree/main/packages/bundler",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"./package.json": "./package.json"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@savvy-web/tsdown-plugins": "0.
|
|
31
|
+
"@savvy-web/tsdown-plugins": "0.4.0",
|
|
32
32
|
"@tsdown/exe": "^0.22.1",
|
|
33
33
|
"tsdown": "^0.22.2"
|
|
34
34
|
},
|
package/run.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseArgs } from "./config.js";
|
|
2
|
-
import { ConfigValidator, ConfigValidatorLive, ReportPipelineLive, buildTargetGroups, createEntryName, generateMeta, normalizeExeOptions, normalizeMetaOptions, packageJsonEntries, readTsconfigJsx, removeDeclarationMaps, renderReport, resolveJsxConfig, resolveTargets, runExeBuild, writeResolvedTsconfig, writeTargetsBinding } from "@savvy-web/tsdown-plugins";
|
|
2
|
+
import { ConfigValidator, ConfigValidatorLive, ReportPipelineLive, buildTargetGroups, createEntryName, generateMeta, normalizeExeOptions, normalizeLooseFiles, normalizeMetaOptions, packageJsonEntries, readTsconfigJsx, removeDeclarationMaps, renderReport, resolveJsxConfig, resolveTargets, runExeBuild, writeResolvedTsconfig, writeTargetsBinding } from "@savvy-web/tsdown-plugins";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { Effect } from "effect";
|
|
@@ -73,7 +73,8 @@ async function runBuild(config, options) {
|
|
|
73
73
|
...publishTargets !== void 0 ? { targets: publishTargets } : {},
|
|
74
74
|
...config.exe !== void 0 ? { exe: config.exe } : {},
|
|
75
75
|
osCpu: osCpuForValidate,
|
|
76
|
-
...config.meta !== void 0 && config.meta !== false ? { meta: config.meta } : {}
|
|
76
|
+
...config.meta !== void 0 && config.meta !== false ? { meta: config.meta } : {},
|
|
77
|
+
...config.looseFiles !== void 0 ? { looseFiles: config.looseFiles } : {}
|
|
77
78
|
})).pipe(Effect.provide(ConfigValidatorLive)));
|
|
78
79
|
if (target === "meta") {
|
|
79
80
|
if (config.meta === false) {
|
|
@@ -160,6 +161,7 @@ async function runBuild(config, options) {
|
|
|
160
161
|
baseEntries = onlyBase;
|
|
161
162
|
dualExports = dualExportKeys;
|
|
162
163
|
}
|
|
164
|
+
const looseFiles = config.looseFiles !== void 0 ? normalizeLooseFiles(config.looseFiles) : void 0;
|
|
163
165
|
const startMs = Date.now();
|
|
164
166
|
const { groups, resolution } = target === "dev" ? {
|
|
165
167
|
groups: [{
|
|
@@ -186,7 +188,8 @@ async function runBuild(config, options) {
|
|
|
186
188
|
...config.format !== void 0 ? { format: config.format } : {},
|
|
187
189
|
...config.define !== void 0 ? { define: config.define } : {},
|
|
188
190
|
...overridePartitions.length > 0 ? { overrides: overridePartitions } : {},
|
|
189
|
-
...dualExports !== void 0 ? { dualExports } : {}
|
|
191
|
+
...dualExports !== void 0 ? { dualExports } : {},
|
|
192
|
+
...looseFiles !== void 0 ? { looseFiles } : {}
|
|
190
193
|
});
|
|
191
194
|
if (target === "prod" && resolution !== void 0) writeBinding(cwd, resolution);
|
|
192
195
|
if (target === "prod" && config.meta !== false) {
|