Skip to content

chore(api)!: migrate from TypeScript to JavaScript#347

Open
caugner wants to merge 8 commits into
mainfrom
un-typescript
Open

chore(api)!: migrate from TypeScript to JavaScript#347
caugner wants to merge 8 commits into
mainfrom
un-typescript

Conversation

@caugner

@caugner caugner commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Description

Migrate the api/ package from TypeScript to JavaScript, keeping tsc for strict type checking via JSDoc annotations.

  • Convert index.ts/cli.ts to index.js/cli.js (ESM), using @import for external types and @typedef for derived types.
  • tsconfig.json uses allowJs/checkJs/emitDeclarationOnly to type-check the sources and emit dist/index.d.ts.
  • Run the generator with node cli.js instead of tsx, dropping the tsx dev dependency; add a files allowlist (index.js, dist/index.d.ts) plus a prepack hook so tsc always builds the shipped declarations.
  • Keep typescript-eslint for linting, adding a node env so no-undef resolves globals like URL in .js; update the lefthook ESLint glob to *.js.

Motivation

Make the sources plain JavaScript (matching the ESM updates/ workspace) while still getting strict, TypeScript-powered type checking through JSDoc, and removing the tsx runtime dependency.

Additional details

The package now ships ESM ("type": "module") instead of CommonJS — a breaking change for any require("@mdn/bcd-utils-api") consumers. The generated dist/index.d.ts is structurally identical to the previous declarations, and npm run generate produces byte-compatible output.

Related issues and pull requests

caugner added 5 commits July 16, 2026 01:16
Convert the `api/` package sources from TypeScript to JavaScript, keeping
`tsc` for strict type checking via JSDoc annotations (`@import` for
external types, `@typedef` for derived types).

- `tsconfig.json` uses `allowJs`/`checkJs`/`emitDeclarationOnly` to
  type-check the `.js` sources and emit `dist/index.d.ts`.
- Run the generator with `node cli.js` instead of `ts-node`.
- Add a `files` allowlist so the published tarball still includes the
  generated `dist/index.d.ts`, which is no longer force-included once
  `main` points outside `dist/`.
- Keep `typescript-eslint` for linting and add an `env` so `no-undef`
  resolves globals like `URL` in the `.js` sources.

The package now ships ESM (`"type": "module"`) instead of CommonJS.
# Conflicts:
#	api/package-lock.json
#	api/package.json
Guarantee `dist/index.d.ts` is present in the published tarball
regardless of build ordering, since `dist` is gitignored and `npm pack`
silently omits missing `files` entries. Also makes local `npm pack` and
`npm publish` ship the declarations.
`cli.js` is the internal generator entry, run via `npm run generate`
from a checkout; it is not referenced by `main`, `bin`, or `exports`, so
npm consumers never import it. It stays in the tsconfig `include` for
type-checking.
`no-undef` needs only the `node` env to resolve runtime globals like
`URL`; `es2024` adds no globals the sources use, and
`@typescript-eslint/parser` already parses the modern syntax.
@caugner
caugner marked this pull request as ready for review July 17, 2026 09:43
@caugner
caugner requested review from a team and mdn-bot as code owners July 17, 2026 09:43
@caugner
caugner requested a review from LeoMcA July 17, 2026 09:43
@caugner caugner changed the title refactor(api): migrate from TypeScript to JavaScript with JSDoc types chore(api)!: migrate from TypeScript to JavaScript with JSDoc types Jul 17, 2026
@caugner caugner changed the title chore(api)!: migrate from TypeScript to JavaScript with JSDoc types chore(api)!: migrate from TypeScript to JavaScript Jul 17, 2026
# Conflicts:
#	.lefthook.yml
#	package.json
@caugner
caugner marked this pull request as draft July 17, 2026 14:00
caugner added 2 commits July 17, 2026 16:41
`npm install` in a worktree derived the project name from the directory
basename and rewrote it into the lockfile. The root `package.json` has no
`name` field, so revert the leaked value.
`void` in a return union reads oddly for a function that returns a value
or nothing; `undefined` is clearer and emits an identical declaration.
@caugner
caugner marked this pull request as ready for review July 17, 2026 14:47
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.

2 participants