@savvy-web/bundler 0.10.0 → 0.11.1

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 CHANGED
@@ -228,6 +228,26 @@ const config = defineBuild({
228
228
 
229
229
  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.
230
230
 
231
+ ## Plugins
232
+
233
+ Pass your own tsdown/rolldown plugins with the `plugins` field. They are forwarded to every tsdown pass the build performs — the JavaScript pass, the bundled-declaration pass, the per-module declarations pass and each `looseFiles` pass — so a plugin's `resolveId`/`load` hooks are available everywhere your source is compiled. The use case is build-time codegen and virtual modules: a plugin can serve a module that exists only at build time, and any of your sources can `import` it.
234
+
235
+ ```ts
236
+ import { defineBuild } from "@savvy-web/bundler";
237
+ import { PnpmConfigPlugin } from "pnpm-config-builder";
238
+
239
+ const config = defineBuild({
240
+ plugins: [PnpmConfigPlugin()],
241
+ bundleNodeModules: true,
242
+ looseFiles: {
243
+ "pnpmfile.mjs": "./src/pnpmfile.ts",
244
+ "pnpmfile.cjs": "./src/pnpmfile.ts",
245
+ },
246
+ });
247
+ ```
248
+
249
+ Because the plugins run on the `looseFiles` pass too, a `pnpmfile` source can `import` a virtual module the plugin resolves — here a config-dependency plugin serves the module the pnpmfile needs, and the pnpmfile lands at the package root as a self-contained bundle. Plugins are a rolldown concept; the supplied plugin objects are passed through to tsdown untouched.
250
+
231
251
  ## Minified output
232
252
 
233
253
  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:
@@ -289,6 +309,7 @@ const config = defineBuild({
289
309
  - **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.
290
310
  - **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; partition-only `platform`, `css` and `outSubdir` fields also let an entry build for the browser with CSS modules into its own sub-package.
291
311
  - **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.
312
+ - **Custom plugins** — `plugins` forwards your own rolldown plugins to every tsdown pass, including the `looseFiles` pass, so build-time codegen and virtual modules resolve everywhere your source is compiled.
292
313
  - **Readable prod output** — prod output is unminified by default to keep stack traces legible and pass security scanners; `minify` opts back in.
293
314
  - **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`.
294
315
  - **Build-time constants** — the package version is injected as `process.env.__PACKAGE_VERSION__`, and the `define` field adds your own verbatim compile-time replacements.
@@ -299,7 +320,7 @@ const config = defineBuild({
299
320
 
300
321
  ## API
301
322
 
302
- - `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.
323
+ - `defineBuild(input)` — normalizes a build config (`externals`, `bundle`, `bundleNodeModules`, `bundledPackages`, `dtsExternals`, `minify`, `devManifest`, `transform`, `output`, `meta`, `jsx`, `exe`, `format`, `overrides`, `looseFiles`, `define`, `plugins`), 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.
303
324
  - `runBuild(config, options)` — the orchestrator. Parses `--target`/`--watch`/`--verbose` from `options.argv`, reads `package.json` at `options.cwd`, derives entries, drives the build for the selected target and renders a report. `--verbose` expands the report to a per-file table; the report is quiet by default. Every IO dependency on `options` is injectable for tests.
304
325
  - `parseArgs(argv)` — the argument parser behind `runBuild`, exported for embedding.
305
326
 
package/config.js CHANGED
@@ -24,7 +24,8 @@ function defineBuild(input = {}) {
24
24
  format: input.format,
25
25
  overrides: input.overrides,
26
26
  looseFiles: input.looseFiles,
27
- define: input.define
27
+ define: input.define,
28
+ plugins: input.plugins
28
29
  };
29
30
  }
30
31
  /** Parse the build CLI argv into the normalized target/flags shape. @public */
package/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { BuildFormat, BuildPlatform, BuildReport, BuildTargetGroupsOptions, CssOptions, ExeConfig, GenerateMetaOptions, Json, JsxConfig, LooseFiles, MetaOptions, MetaResult, NextVersions, PublishTargets, RenderedOutput, RunExeBuildOptions, TargetGroupRef, TargetResolution, TsconfigJsx, defaultManifestTransform } from "@savvy-web/tsdown-plugins";
2
+ import { Plugin, Plugin as Plugin$1 } from "rolldown";
2
3
 
3
4
  //#region src/config.d.ts
4
5
  /** @public */
@@ -125,6 +126,14 @@ interface BuildConfigInput {
125
126
  * `process.env.__PACKAGE_VERSION__` define; a user key of the same name wins.
126
127
  */
127
128
  readonly define?: Record<string, string> | undefined;
129
+ /**
130
+ * Custom tsdown/rolldown plugins forwarded to EVERY tsdown run the build
131
+ * performs — the JS pass, the dts pass, the per-module declarations pass, and
132
+ * each looseFiles pass. Use for build-time codegen / virtual modules (e.g. a
133
+ * pnpm config-dependency plugin). Plugins run after the builder's internal
134
+ * interop plugins and before its metrics instrumentation.
135
+ */
136
+ readonly plugins?: ReadonlyArray<Plugin$1> | undefined;
128
137
  }
129
138
  /** @public */
130
139
  interface BuildConfig {
@@ -172,6 +181,8 @@ interface BuildConfig {
172
181
  readonly looseFiles?: LooseFiles | undefined;
173
182
  /** Compile-time global replacements forwarded to the build `define` (merged with the auto-version). */
174
183
  readonly define?: Record<string, string> | undefined;
184
+ /** Custom tsdown/rolldown plugins forwarded to every tsdown run (JS, dts, per-module declarations, looseFiles). */
185
+ readonly plugins?: ReadonlyArray<Plugin$1> | undefined;
175
186
  }
176
187
  /**
177
188
  * Normalize + validate a defineBuild config. Pure when imported; self-runs when entry (see run.ts).
@@ -235,5 +246,5 @@ interface RunOptions {
235
246
  /** Run a build from a normalized config. Pure orchestration; all IO injectable. @public */
236
247
  declare function runBuild(config: BuildConfig, options: RunOptions): Promise<void>;
237
248
  //#endregion
238
- export { type BuildConfig, type BuildConfigInput, type BuildEntryOverride, type OutputConfig, type ParsedArgs, type RunOptions, defaultManifestTransform, defineBuild, parseArgs, runBuild };
249
+ export { type BuildConfig, type BuildConfigInput, type BuildEntryOverride, type OutputConfig, type ParsedArgs, type Plugin, type RunOptions, defaultManifestTransform, defineBuild, parseArgs, runBuild };
239
250
  //# sourceMappingURL=index.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@savvy-web/bundler",
3
- "version": "0.10.0",
3
+ "version": "0.11.1",
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",
@@ -29,9 +29,10 @@
29
29
  "./package.json": "./package.json"
30
30
  },
31
31
  "dependencies": {
32
- "@savvy-web/tsdown-plugins": "0.10.0",
32
+ "@savvy-web/tsdown-plugins": "0.11.0",
33
33
  "@tsdown/exe": "^0.22.1",
34
34
  "effect": "^3.21.4",
35
+ "rolldown": "^1.1.3",
35
36
  "tsdown": "^0.22.3"
36
37
  },
37
38
  "peerDependencies": {
package/run.js CHANGED
@@ -224,6 +224,7 @@ async function runBuild(config, options) {
224
224
  ...dualExports !== void 0 ? { dualExports } : {},
225
225
  ...subdirExports.size > 0 ? { subdirExports } : {},
226
226
  ...looseFiles !== void 0 ? { looseFiles } : {},
227
+ ...config.plugins !== void 0 ? { extraPlugins: config.plugins } : {},
227
228
  ...exeRewrite !== void 0 ? { exeRewrite } : {},
228
229
  ...target === "prod" ? { emitDeclarations: true } : {},
229
230
  collector,