Skip to content

ESM build, test environment polyfills, and dependency bumps (v4.4.26)

Choose a tag to compare

released this 16 Aug 03:22
· 55 commits to working since this release

This release aligns the package with an ESM-first build output, simplifies test and TypeScript configurations, and updates several Fjell dependencies and dev tools. The primary goals were: produce ES2022 ESM artifacts and declaration files, provide Node-friendly test globals (fetch/FormData/Blob/File) for vitest, and tidy package metadata and build/test scripts. The changes affect packaging/exports, test setup, TypeScript emission settings, vitest configuration, and dependency pins.

New features

  • ESM exports mapping

    • package.json now exposes an ESM-style module entry and an exports mapping that points to ./dist/index.js and ./dist/index.d.ts for types. This replaces previous main, browser, and type fields and clarifies ESM consumption.
  • Test environment polyfills for Node

    • tests/setup.ts now polyfills fetch and FormData using undici and node:buffer (Blob, File). The test bootstrap enables vitest-fetch-mock to mock fetch requests in tests.

Improvements

  • Packaging and build output

    • TypeScript is configured to emit compiled artefacts into dist/ (outDir), generate declaration files (declaration: true), and produce source maps (sourceMap: true). Target and module are set to es2022 to produce modern ESM output.
    • The repository now uses an explicit module export plus exports mapping to make ESM entrypoints and type declarations explicit to consumers.
  • Dependency updates and pinning

    • Fjell runtime dependencies were bumped to newer patch versions in package.json: @fjell/core, @fjell/http-api, @fjell/logging, and @fjell/registry moved to newer patch/minor targets (examples in commits: ^4.4.35, ^4.4.35, ^4.4.43, ^4.4.31). These changes bring the package in line with other Fjell packages and the current release train.
    • Development dependencies were reorganized: jsdom and @types/node were removed (no longer required for the Node-based test setup); undici and vitest-fetch-mock were added to support fetch polyfills and fetch mocking in Node tests.
    • Runtime dependency deepmerge remains declared.
  • Simplified TypeScript configuration

    • Removed several previously set compiler options such as rootDir, esModuleInterop, and explicit moduleResolution settings to simplify the compilerOptions block.
    • include continues to target ./src/**/*.ts while exclude was expanded to ignore node_modules, ./examples/**/*, ./tests/**/*, and ./dist/**/* so that emitted artifacts and test sources are not compiled into library output.
  • Vitest configuration simplification

    • vitest.config.ts now declares triple-slash reference types for vitest, enables globals: true, and uses a consistent defineConfig export. Several explicit options were removed (environment, setupFiles, include, testTimeout, verbose coverage provider settings) to rely on simpler defaults and the new Node-friendly test setup.
  • Tests and logging mock removal

    • The previous large global mock of @fjell/logging was removed from tests/setup.ts. Tests now rely on real logging modules (with the runtime dependency bumps) or test-local mocks.

Bug fixes / correctness

  • Ensure package.json ends with newline and clean up formatting

    • package.json and other package metadata files were tidied for consistent file endings and ordering.
  • Test runtime correctness in Node

    • By polyfilling global fetch/FormData/Blob/File and enabling vitest-fetch-mock, tests that previously required a JSDOM environment or manual mocking should run reliably under a Node test environment.

Developer experience and testing

  • Node-native test globals

    • Tests can run under Node without JSDOM using undici to provide fetch and node:buffer for Blob/File. This avoids keeping jsdom as a devDependency and reduces reliance on browser-like test environments for server-oriented code.
  • Fetch mocking

    • vitest-fetch-mock is enabled in tests/setup.ts; fetchMocker.enableMocks() is called during test bootstrap so tests can stub network interactions consistently.
  • Simplified vitest defaults

    • Removing explicit environment and setupFiles from vitest config reflects the move to Node globals and consolidated setup in tests/setup.ts. globals: true is enabled so tests can use vitest globals without import.

Files and components affected

  • package.json

    • Replaced main/browser/type with module and an exports mapping pointing to ./dist/index.js plus types entry at ./dist/index.d.ts.
    • Updated Fjell dependencies to newer patch/minor ranges and reorganized devDependencies (removed jsdom, @types/node; added undici, vitest-fetch-mock).
    • Scripts preserved and tidied; newlines and ordering normalized.
  • tests/setup.ts

    • Added Node polyfills: import { fetch, FormData } from 'undici' and import { Blob, File } from 'node:buffer'.
    • Removed the previous global mock for @fjell/logging.
    • Added createFetchMock from vitest-fetch-mock and enabled mocks with the Vitest vi instance.
  • tsconfig.json

    • Enabled sourceMap, outDir: dist, declaration: true, and set target/module to es2022.
    • Removed some legacy or more-specific compiler flags and expanded exclude entries so build focuses on src output only.
  • vitest.config.ts

    • Added triple-slash reference types /// <reference types="vitest" /> and used globals: true.
    • Removed many explicit coverage and environment options to defer to simpler configuration and test setup.

Breaking changes / things to watch for

  • ESM-only entrypoints

    • The project now targets ESM (es2022) and exposes a module entry with an exports map. Consumers using CommonJS require() against this package may need to update imports to ESM (import) or use compatible interop tooling. The previous main/CommonJS entry and browser field were removed.
  • DevDependency changes affecting local test setup

    • jsdom and @types/node were removed from devDependencies. If local development workflows relied on JSDOM-specific globals or TypeScript Node typings provided only by @types/node, developers may need to install those dependencies locally or adapt to the Node-based test setup now provided.
  • Removed global logging mock from tests

    • Tests that depended on the prior global stub for @fjell/logging must provide local mocks or rely on the now-updated logging dependency behavior.

Migration notes

  • Running tests locally

    • No extra vitest setupFiles are required: tests/setup.ts registers Node globals and enables fetch mocking. Ensure undici and vitest-fetch-mock are installed (they are declared in devDependencies after this change).
  • Build and publish

    • TypeScript now emits JS and declaration files into dist/. Consumers should import from the package as an ESM module. CI and publish steps that previously relied on main/CommonJS behavior should be validated against the new exports layout.

Related commit summary

  • Bumped package version to 4.4.26 and began next dev cycle entries in package.json.
  • Reworked package.json fields to use ESM module + exports, updated Fjell dependencies, and reorganized devDependencies.
  • Added Node fetch/FormData/Blob/File polyfills and enabled vitest fetch mocking in tests/setup.ts; removed the large @fjell/logging global mock.
  • Simplified tsconfig.json to emit artifacts to dist and set modern ES target/module options; expanded excludes to avoid compiling tests/examples/dist.
  • Simplified vitest.config.ts, enabled globals, and added triple-slash vitest type references.

If you rely on CommonJS consumers, JSDOM-based tests, or the prior global logging test stub, review test and consumer code and adapt imports or install missing devDependencies as needed. For further detail, inspect the changed files: package.json, tsconfig.json, vitest.config.ts, and tests/setup.ts.