Skip to content

Reduce public API surface and implement API Extractor#30

Merged
TwitchBronBron merged 2 commits into
masterfrom
typedef-public-api-surface
Jun 29, 2026
Merged

Reduce public API surface and implement API Extractor#30
TwitchBronBron merged 2 commits into
masterfrom
typedef-public-api-surface

Conversation

@TwitchBronBron

Copy link
Copy Markdown
Member

What

Introduces API Extractor to generate a trimmed, public-only dist/index.d.ts and a committed API report (api/logger.api.md) that CI gates against.

Before this PR, typings were a raw export * from './Logger', which leaked internal symbols (LogLevelPriority, LogLevelColor, chalk) into the published surface. Now every export is explicitly tagged and the shipped .d.ts contains only what we mean to expose.

API surface

  • @public (shipped): Logger, logger, createLogger, LoggerOptions, LogLevel, LogLevelNumeric, LogLevelPriority, LogMessage, MessageHandler, Transport, ConsoleTransport, QueuedTransport, FileTransport
  • @internal (stripped from shipped typings, kept for unit tests): chalk, LogLevelColor

How it's wired

  • npm run build now runs tsc then api:build-and-validate (fails on untagged exports or report drift).
  • npm run api:build-and-update accepts an intentional API change by rewriting api/logger.api.md.
  • src/apiExtractor.spec.ts runs the same gate in-process so it's covered by the normal test run.
  • declarationMap: true so consumers get go-to-definition into source.

Consumer verification

Checked the actual downstream consumers in the local monorepo checkouts against the new trimmed surface:

  • brighterscript — clean. Uses only Logger, LogLevelNumeric, LogMessage, LogLevel, default logger, and the public getLogLevelNumeric() / getLogLevelText() methods.
  • roku-debug — re-exports and uses LogLevelPriority (LogLevelPriority[logger.logLevel] to convert a level to its numeric form for roku-deploy). To avoid breaking it, LogLevelPriority is kept @public. (Note: logger.getLogLevelNumeric() is the public method that does the same thing, so roku-debug could migrate later — but no forced break here.)
  • ropm, roku-report-analyzer — clean (logger, Logger, LogLevel).

Notes for the reviewer

  • The committed api/logger.api.md was regenerated from a clean full build; an earlier draft of it had been generated from a partial build and was missing the @internal chalk/LogLevelColor entries (would have failed CI on a fresh checkout). That's corrected.
  • 105 tests passing, 100% coverage, lint clean, npm run build green.

🤖 Generated with Claude Code

TwitchBronBron and others added 2 commits June 29, 2026 09:05
Adds an API Extractor pass to the build that rolls the per-file `.d.ts`
files into a single trimmed `dist/index.d.ts` containing only `@public`
symbols, and commits an `api/logger.api.md` report that CI gates against
to catch accidental public-API drift.

Every exported symbol is now explicitly classified:
- @public: Logger, logger, createLogger, LoggerOptions, LogLevel,
  LogLevelNumeric, LogLevelPriority, LogMessage, MessageHandler,
  Transport, ConsoleTransport, QueuedTransport, FileTransport
- @internal (stripped from shipped typings, kept for unit tests):
  chalk, LogLevelColor

`LogLevelPriority` is kept @public because roku-debug consumes it to
convert a LogLevel to its numeric form.

Verified consumers (brighterscript, roku-debug, ropm, roku-report-analyzer)
only reference @public symbols against the new trimmed surface.

Also enables declarationMap so consumers get go-to-definition into source.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…aps)

Switch the `files` allow-list to ship only the runtime `.js` plus the
single trimmed `dist/index.d.ts` rollup. The per-file declarations
(Logger.d.ts, transports/*.d.ts, util.d.ts, Stopwatch.d.ts) and all
source maps are no longer published, so consumers can only resolve types
through the package root `@rokucommunity/logger` — there's no deep-import
escape hatch around the trimmed public surface.

This only affects the published tarball (24 files/80kB -> 11 files/47kB).
The local build is unchanged: tsc still emits every per-file .d.ts to
dist/, so API Extractor and the drift test work exactly as before, and
`npm link` consumers still see the full on-disk dist. declarationMap stays
enabled for link-time go-to-source navigation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@TwitchBronBron TwitchBronBron changed the title feat: Generate trimmed public typedefs via API Extractor Reduce public API surface and implement API Extractor Jun 29, 2026
@TwitchBronBron TwitchBronBron merged commit cb12831 into master Jun 29, 2026
8 checks passed
@TwitchBronBron TwitchBronBron deleted the typedef-public-api-surface branch June 29, 2026 13:41
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.

1 participant