Skip to content

Rename errgo.ts to result.ts and move assets/ to ESM - #42

Merged
andreogle merged 1 commit into
mainfrom
rename-result-esm-migration
Aug 11, 2026
Merged

Rename errgo.ts to result.ts and move assets/ to ESM#42
andreogle merged 1 commit into
mainfrom
rename-result-esm-migration

Conversation

@andreogle

Copy link
Copy Markdown
Owner

The vendored errgo.ts name said nothing about what the module does. Every export in it is about the Result<T, E> tuple, and its siblings in assets/js/ are named as nouns-by-concern (theme, dates, routes, sentry), so result.ts fits both. Upstream still calls the package errgo; only the local filename differs, and CLAUDE.md records that.

While updating the test:unit script for the rename it was hardcoded to a single file, so it now globs js/**/*.test.ts. The glob is scoped to js/ rather than relying on bare node --test discovery, which today only skips the Playwright suite because those files happen to end in .spec.ts.

That script also carried --disable-warning=MODULE_TYPELESS_PACKAGE_JSON, suppressing a warning Node emits once per test file because assets/ had no "type" field. Rather than keep suppressing it, assets/ is now "type": "module" and the five CommonJS build scripts are explicitly .cjs. This removes the reparse overhead, makes the module system of each file explicit, and defuses the trap where Node's own warning text tells you to add "type": "module" without mentioning it breaks all five scripts.

Two things the move required:

  • watch-ssr-pages resolved the generator via path.join at runtime, so the .cjs rename had to be reflected there or the dev watcher would have silently stopped regenerating the page registry.
  • e2e/global-setup.ts used __dirname, which does not exist in ESM. Playwright loads it as ESM under "type": "module", so global setup threw ReferenceError and would have failed the entire e2e suite. It now uses import.meta.dirname.

Verified: mix precommit, 21/21 Playwright e2e, full mix assets.deploy (exercising upload-sourcemaps and compress-assets), both dev watchers regenerating, and priv/ssr.js still loading as CommonJS.

The vendored `errgo.ts` name said nothing about what the module does.
Every export in it is about the `Result<T, E>` tuple, and its siblings in
assets/js/ are named as nouns-by-concern (theme, dates, routes, sentry),
so `result.ts` fits both. Upstream still calls the package `errgo`; only
the local filename differs, and CLAUDE.md records that.

While updating the `test:unit` script for the rename it was hardcoded to
a single file, so it now globs `js/**/*.test.ts`. The glob is scoped to
js/ rather than relying on bare `node --test` discovery, which today only
skips the Playwright suite because those files happen to end in .spec.ts.

That script also carried --disable-warning=MODULE_TYPELESS_PACKAGE_JSON,
suppressing a warning Node emits once per test file because assets/ had
no "type" field. Rather than keep suppressing it, assets/ is now
"type": "module" and the five CommonJS build scripts are explicitly .cjs.
This removes the reparse overhead, makes the module system of each file
explicit, and defuses the trap where Node's own warning text tells you to
add "type": "module" without mentioning it breaks all five scripts.

Two things the move required:

  * watch-ssr-pages resolved the generator via path.join at runtime, so
    the .cjs rename had to be reflected there or the dev watcher would
    have silently stopped regenerating the page registry.
  * e2e/global-setup.ts used __dirname, which does not exist in ESM.
    Playwright loads it as ESM under "type": "module", so global setup
    threw ReferenceError and would have failed the entire e2e suite.
    It now uses import.meta.dirname.

Verified: mix precommit, 21/21 Playwright e2e, full mix assets.deploy
(exercising upload-sourcemaps and compress-assets), both dev watchers
regenerating, and priv/ssr.js still loading as CommonJS.
@andreogle
andreogle merged commit ba62001 into main Aug 11, 2026
5 checks passed
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