Skip to content

v2.0.0

Compare
Choose a tag to compare
@pi0 pi0 released this 25 Sep 18:22
· 50 commits to main since this release

🌟 Highlights

πŸ”₯ Native ESM

jiti v2 now natively supports ESM import and resolution with new API await jiti.import(id) and jiti.esmResolve(id). This allows top-level await and native+faster importing of ES-only modules with increased compatibility

βš›οΈ JSX Support

You can now directly import .jsx/.tsx files with jiti! See examples with nano-js, preact, React and Vue. This feature is opt-in for now (using jsx: true or JITI_JSX=true). Jiti is considering a smarter lib detection for wider support before enabling JSX support by default.

πŸ“¦ Dual format package exports

jiti package exports are now in a dual (ESM/CJS) format for better importing of jiti in ESM contexts.

🎈 jiti/native

As native ESM and Typescript support is being increased across runtimes, a new export in jiti allows easing up the transition by giving the same API of jiti but instead only depending on runtime import.meta.resolve and dynamic import() support. This is possible by making an alias for jiti to jiti/native.

🚚 ESM Loader

You can globally register jiti using Node.js global hooks (experimental).

CLI:

# Instead of `npx jiti index.ts`
node --import jiti/register index.ts

Programmatic:

import "jiti/register";
// or
await import("jiti/register");

πŸ” Better inspection

You can inspect what jiti internals using debug option or JITI_DEBUG=1 environment variable. The output is now more readable and with colors to easily find slow imports.

jiti will also use node_modules/.cache/jiti directory instead of temp dir (if node_modules exists) to store caches for easier local inspections.

image

⬆️ Migration

Upgrade jiti dependency to ^2.0.0 in package.json

Use new createJiti named export :

ESM:

--- import createJiti from "jiti"
+++ import { createJiti } from "jiti"
const jiti = createJiti(import.meta.url)

CommonJS:

--- const createJiti = require("jiti")
+++ const { createJiti } = require("jiti")
const jiti = createJiti(__filename)

Migrate from CommonJS to ESM API: (highly recommended!)

Importing modules:

--- const mood = jiti('mod')
+++ const mood = await jiti.import('mod')

Resolving modules:

--- const path = jiti.resolve('mod')
+++ const path = jiti.esmResolve('mod')

❀️ Thank you!

This release wasn't possible without valuable ecosystem feedback and contributors. With the trust of users with astonishing 60M+ monthly downloads, i hope jiti v2 can help speed up the ecosystem transition to ESM and Typescript.


Changes since v1

compare changes

πŸš€ Enhancements

  • top-level await support (#239)
  • Native ESM support (#259)
  • Add experimental ESM loader support (#266)
  • Allow try and other resolve options for jiti.esmResolve (#268)
  • Allow configure interopDefault using JITI_INTEROP_DEFAULT env (1c080a1)
  • jiti/native subpath (#289) (#294) (#293)
  • Handle data: imports (#299)
  • Support opt-in JSX (#200)
  • Eval ESM modules with fallback loader (#300)
  • Support import.meta.resolve (#301)

πŸ“¦ Build

  • Overhaul package exports (#262)
  • Fix type resolution issue (#269)

πŸ”₯ Performance

  • Reduce overhead of jiti sub-instances (#265)
  • Use native createRequire (69da3c5)

🩹 Fixes

  • Use distinct cache paths for async mode (6e8ec7a)
  • Resolve with ESM conditions in async context (#264)
  • cache: Prefer node_modules/.cache if exists (832f206)
  • Use native ESM import for built-ins (54d6b4a)
  • Respect interopDefault in babel transform (485b4e9)
  • Split cache based on interopDefault (f820a15)
  • Remove extention from cache path (50b1b3a)
  • Properly resolve .mts/.cts with .mjs/.cjs imports (a5aefad)
  • resolve: Make sure parentURL is a dir (d224e84)
  • Handle global URL instance mismatch (#298)
  • Optional access to Reflect.metadata for typescript decorators (#165)
  • Only pass paths option to native require.resolve (50e4280)

πŸ’… Refactors

  • Split option normalization (#172)
  • Split logic (#240)
  • Remove legacy Node.js syntax polyfills (#260)
  • 3rd arg to createJiti is optional (60a23e3)
  • Upgrade cache version to 8 (99224ae)
  • Use more clear fsCache and moduleCache options (#263)
  • Use ESM imports for babel plugins (22e259f)
  • Improve debug logging (463a8a3)
  • Rename importResolve to esmResolve (aac88e6)
  • Improve env handling (ee4489d)
  • Use import/require in debug logs (934a5bb)
  • Improve internal babel types (#271)
  • Rename experimentalBun option to tryNative (#295)
  • Make jiti.esmResolve consistent with import.meta.resolve (#303)

πŸ“– Documentation

  • Update bundlephobia link (#179)
  • Add example for inline JITI_ALIAS (a53715a)