Skip to content

feat(api): typed options object for exec()#253

Merged
robertsLando merged 3 commits into
mainfrom
worktree-issue-242-typed-api-options
Apr 20, 2026
Merged

feat(api): typed options object for exec()#253
robertsLando merged 3 commits into
mainfrom
worktree-issue-242-typed-api-options

Conversation

@robertsLando

@robertsLando robertsLando commented Apr 20, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds a typed PkgExecOptions interface for the public exec() API while preserving the existing string[] overload for full backward compatibility.
  • Exports PkgExecOptions and PkgCompressType from the package entry point (surfaces in lib-es5/index.d.ts).
  • Documents both forms on the docs site with a field-by-field table.

Design

The options path normalizes into CLI-style argv via a small optionsToArgv() helper and then feeds the existing minimist pipeline. Defaults (bytecode, nativeBuild, signaturetrue) and validation stay in one place — zero behavior drift between the two entry forms.

PkgCompressType is derived from the existing CompressType enum via keyof typeof so the public union can't drift from the internal representation.

PkgExecOptions is kept distinct from the internal PkgOptions (which models the "pkg" section of package.json). They describe different layers — build content vs. driver knobs — and forcing shared ancestry would either leak internals (patches, dictionary, log) into the public surface or require a contrived shared base with only 2–3 fields.

Changes

File Change
lib/types.ts Add PkgExecOptions + PkgCompressType (derived from CompressType).
lib/index.ts Add optionsToArgv() + overloaded exec(); re-export types.
eslint.config.js Swap core no-redeclare@typescript-eslint/no-redeclare (core rule misfires on TS function overloads).
docs-site/guide/api.md Document the options-object form with a field table; update release-pipeline example.
test/test-50-api-options/ Smoke test covering options form, argv form (backward compat), and input validation.

Test plan

  • yarn build clean
  • yarn lint clean
  • test-50-api-options passes on host
  • test-50-api (existing programmatic-API test using argv form) still passes
  • CI green

closes #242

🤖 Generated with Claude Code

robertsLando and others added 2 commits April 20, 2026 10:21
Adds a `PkgExecOptions` interface and an overload so programmatic
consumers can drive builds with a typed object instead of a CLI-style
`string[]`. The options path normalizes into argv and feeds the existing
minimist pipeline — single source of truth for defaults and validation,
zero behavior drift between the two forms.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The options-object path now builds the parsed-argv shape directly and
hands it to the rest of exec(), instead of stringifying to CLI argv just
to have minimist parse it back. Minimist is still used for the argv
overload. Defaults and the flag schema are lifted to module-level
constants so both paths share them.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@robertsLando robertsLando requested a review from Copilot April 20, 2026 08:42
@robertsLando robertsLando changed the title feat(api): typed options object for exec() (closes #242) feat(api): typed options object for exec() Apr 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends the public Node.js API by adding a typed options-object overload for exec() while preserving the existing argv-array form for backward compatibility, and updates docs/tests accordingly.

Changes:

  • Introduces PkgExecOptions and a public PkgCompressType type for the programmatic exec() API.
  • Adds an overload + normalization helper in lib/index.ts to support both argv-array and options-object entry points.
  • Documents the new API form and adds a smoke test covering both call styles and basic validation.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/test-50-api-options/test-x-index.js Adds a minimal entry script used by the new API-options smoke test.
test/test-50-api-options/main.js Adds a smoke test for exec({ ... }), argv backward-compat, and input validation.
lib/types.ts Adds exported public types for the new exec() options-object API surface.
lib/index.ts Implements exec() overloads and options-object normalization into the existing minimist pipeline.
eslint.config.js Adjusts ESLint rules to avoid false positives with TypeScript function overloads.
docs-site/guide/api.md Documents both exec() forms and adds a field table for PkgExecOptions.

Comment thread lib/types.ts
- Narrow `targets`, `publicPackages`, `noDictionary` to `string[]` only;
  the `string | string[]` union blurred the type contract (is `'a,b'`
  one item or two?). `bakeOptions` keeps the union since CLI-style
  comma-joined bake flags are conventional.
- Drop the `compress: 'None' → undefined` special case; downstream
  already treats unset as 'None', so the passthrough is uniform with
  other fields.
- Expand test coverage: one build exercises `bakeOptions`,
  `publicPackages`, `noDictionary` at once (asserting `global.gc` is
  callable proves `bakeOptions` actually reached the binary — a typo
  in the flag name in optionsToParsed would surface as 'gc-off'); one
  build covers `compress: 'Brotli'`. Validation tests now assert on
  stable substrings and cover `exec(null)`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@robertsLando robertsLando merged commit f061f72 into main Apr 20, 2026
27 checks passed
@robertsLando robertsLando deleted the worktree-issue-242-typed-api-options branch April 20, 2026 09:15
Comment thread lib/types.ts

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file is missing in v6.18 npm package

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — fix up in #258.

robertsLando added a commit that referenced this pull request Apr 21, 2026
The `files` whitelist only shipped `lib-es5/index.d.ts`, but that file
imports from `./types`, so TypeScript consumers of the typed `exec()`
API introduced in #253 couldn't resolve the module. Switch to
`lib-es5/*.d.ts` so every generated declaration is published.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: typed options object for the Node.js API

3 participants