Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jiti

Package Overview
Dependencies
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jiti - npm Package Compare versions

Comparing version 2.0.0-rc.1 to 2.0.0

27

lib/types.d.ts

@@ -12,2 +12,7 @@ export declare function createJiti(id: string, userOptions?: JitiOptions): Jiti;

/**
* Resolved options
*/
options: JitiOptions;
/**
* ESM import a module with additional Typescript and ESM compatibility.

@@ -20,2 +25,3 @@ */

*/
esmResolve(id: string, parentURL?: string): string;
esmResolve<T extends JitiResolveOptions = JitiResolveOptions>(

@@ -149,2 +155,11 @@ id: string,

tryNative?: boolean;
/**
* Enable JSX support Enable JSX support using [`@babel/plugin-transform-react-jsx`](https://babeljs.io/docs/babel-plugin-transform-react-jsx).
*
* @default false
*
* You can also use `JITI_JSX=1` environment variable to enable JSX support.
*/
jsx?: boolean | JSXOptions;
}

@@ -169,2 +184,3 @@

async: boolean;
jsx?: boolean | JSXOptions;
[key: string]: any;

@@ -183,1 +199,12 @@ }

}
/** Reference: https://babeljs.io/docs/babel-plugin-transform-react-jsx#options */
export interface JSXOptions {
throwIfNamespace?: boolean;
runtime?: "classic" | "automatic";
importSource?: string;
pragma?: string;
pragmaFrag?: string;
useBuiltIns?: boolean;
useSpread?: boolean;
}

24

package.json
{
"name": "jiti",
"version": "2.0.0-rc.1",
"version": "2.0.0",
"description": "Runtime typescript and ESM support for Node.js",

@@ -44,7 +44,7 @@ "repository": "unjs/jiti",

"dev": "pnpm clean && pnpm webpack --watch",
"jiti": "JITI_DEBUG=1 lib/jiti-cli.mjs",
"jiti": "JITI_DEBUG=1 JITI_JSX=1 lib/jiti-cli.mjs",
"lint": "eslint . && prettier -c src lib test stubs",
"lint:fix": "eslint --fix . && prettier -w src lib test stubs",
"prepack": "pnpm build",
"release": "pnpm build && pnpm test && changelogen --release --prerelease --push --publish --publishTag 2x",
"release": "pnpm build && pnpm test && changelogen --release --push --publish",
"test": "pnpm lint && pnpm test:types && vitest run --coverage && pnpm test:node-register && pnpm test:bun && pnpm test:native",

@@ -56,3 +56,3 @@ "test:bun": "bun --bun test test/bun",

"test:native:node": "node --test --experimental-strip-types test/native/node.test.ts",
"test:node-register": "node --test test/node-register.test.mjs",
"test:node-register": "JITI_JSX=1 node --test test/node-register.test.mjs",
"test:types": "tsc --noEmit"

@@ -69,3 +69,5 @@ },

"@babel/plugin-syntax-import-assertions": "^7.25.6",
"@babel/plugin-syntax-jsx": "^7.24.7",
"@babel/plugin-transform-export-namespace-from": "^7.24.7",
"@babel/plugin-transform-react-jsx": "^7.25.2",
"@babel/plugin-transform-typescript": "^7.25.2",

@@ -85,8 +87,7 @@ "@babel/preset-typescript": "^7.24.7",

"babel-plugin-parameter-decorator": "^1.0.16",
"babel-plugin-transform-typescript-metadata": "^0.3.2",
"changelogen": "^0.5.5",
"changelogen": "^0.5.7",
"config": "^3.3.12",
"destr": "^2.0.3",
"escape-string-regexp": "^5.0.0",
"eslint": "^9.10.0",
"eslint": "^9.11.0",
"eslint-config-unjs": "^0.3.2",

@@ -96,6 +97,12 @@ "estree-walker": "^3.0.3",

"mlly": "^1.7.1",
"nano-jsx": "^0.1.0",
"pathe": "^1.1.2",
"pkg-types": "^1.2.0",
"preact": "^10.24.1",
"preact-render-to-string": "^6.5.11",
"prettier": "^3.3.3",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"reflect-metadata": "^0.2.2",
"solid-js": "^1.9.1",
"std-env": "^3.7.0",

@@ -107,2 +114,3 @@ "terser-webpack-plugin": "^5.3.10",

"vitest": "^2.1.1",
"vue": "^3.5.8",
"webpack": "^5.94.0",

@@ -114,3 +122,3 @@ "webpack-bundle-analyzer": "^4.10.2",

},
"packageManager": "pnpm@9.10.0"
"packageManager": "pnpm@9.11.0"
}

@@ -11,46 +11,22 @@ # jiti

Just-in-Time Typescript and ESM support for Node.js.
> This is the active development branch. Check out [jiti/v1](https://github.com/unjs/jiti/tree/v1) for legacy v1 docs and code.
> [!IMPORTANT]
> This is the development branch for jiti v2. Check out [jiti/v1](https://github.com/unjs/jiti/tree/v1) for latest stable docs and [unjs/jiti#174](https://github.com/unjs/jiti/issues/174) for the v2 roadmap.
## 🌟 Used in
[Docusaurus](https://docusaurus.io/), [ESLint](https://github.com/eslint/eslint), [FormKit](https://formkit.com/), [Histoire](https://histoire.dev/), [Knip](https://knip.dev/), [Nitro](https://nitro.unjs.io/), [Nuxt](https://nuxt.com/), [PostCSS loader](https://github.com/webpack-contrib/postcss-loader), [Rsbuild](https://rsbuild.dev/), [Size Limit](https://github.com/ai/size-limit), [Slidev](https://sli.dev/), [Tailwindcss](https://tailwindcss.com/), [Tokenami](https://github.com/tokenami/tokenami), [UnoCSS](https://unocss.dev/), [WXT](https://wxt.dev/), [Winglang](https://www.winglang.io/), [Graphql code generator](https://the-guild.dev/graphql/codegen), [Lingui](https://lingui.dev/), [Scaffdog](https://scaff.dog/), [Storybook](https://storybook.js.org), [...UnJS ecosystem](https://unjs.io/), [...60M+ npm monthly downloads](https://npm.chart.dev/jiti), [...6M+ public repositories](https://github.com/unjs/jiti/network/dependents).
## ✅ Features
- Seamless Typescript and ESM syntax support
- Seamless Typescript and ESM syntax support for Node.js
- Seamless interoperability between ESM and CommonJS
- Synchronous API to replace `require()`
- Asynchronous API to replace `import()`
- ESM Loader support
- Super slim and zero dependency
- Custom resolve aliases
- Smart syntax detection to avoid extra transforms
- Node.js native require cache integration
- Filesystem transpile with hard disk caches
- Custom resolve aliases
- ESM Loader support
- JSX support (opt-in)
## 🌟 Used by
- [Docusaurus](https://docusaurus.io/)
- [FormKit](https://formkit.com/)
- [Histoire](https://histoire.dev/)
- [Knip](https://knip.dev/)
- [Nitro](https://nitro.unjs.io/)
- [Nuxt](https://nuxt.com/)
- [PostCSS loader](https://github.com/webpack-contrib/postcss-loader)
- [Rsbuild](https://rsbuild.dev/)
- [Size Limit](https://github.com/ai/size-limit)
- [Slidev](https://sli.dev/)
- [Tailwindcss](https://tailwindcss.com/)
- [Tokenami](https://github.com/tokenami/tokenami)
- [UnoCSS](https://unocss.dev/)
- [WXT](https://wxt.dev/)
- [Winglang](https://www.winglang.io/)
- [Graphql code generator](https://the-guild.dev/graphql/codegen)
- [Lingui](https://lingui.dev/)
- [Scaffdog](https://scaff.dog/)
- [Storybook](https://storybook.js.org)
- [...UnJS ecosystem](https://unjs.io/)
- [...58M+ npm monthly downloads](https://www.npmjs.com/package/jiti)
- [...5.5M+ public repositories](https://github.com/unjs/jiti/network/dependents)
- [ pr welcome add yours ]
## 💡 Usage

@@ -64,6 +40,2 @@

npx jiti ./index.ts
# or
jiti ./index.ts
```

@@ -73,5 +45,5 @@

Initialize a jiti instance:
```js
// --- Initialize ---
// ESM

@@ -84,5 +56,7 @@ import { createJiti } from "jiti";

const jiti = createJiti(__filename);
```
// --- ESM Compatible APIs ---
Import (async) and resolve with ESM compatibility:
```js
// jiti.import() acts like import() with Typescript support

@@ -93,5 +67,7 @@ await jiti.import("./path/to/file.ts");

const resolvedPath = jiti.esmResolve("./src");
```
// --- CJS Compatible APIs ---
CommonJS (sync - legacy):
```js
// jiti() acts like require() with Typescript and (non async) ESM support

@@ -112,6 +88,4 @@ jiti("./path/to/file.ts");

You can globally register jiti using [global hooks](https://nodejs.org/api/module.html#initialize).
You can globally register jiti using [global hooks](https://nodejs.org/api/module.html#initialize). (important: Requires Node.js > 20)
**Note:** This is an experimental approach and only tested to work on Node.js > 20. I don't recommend it and unless you have to, please prefer explicit method.
```js

@@ -127,2 +101,6 @@ import "jiti/register";

## 🎈 `jiti/native`
You can alias `jiti` to `jiti/native` to directly depend on runtime's [`import.meta.resolve`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import.meta/resolve) and dynamic [`import()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import) support. This allows easing up the ecosystem transition to runtime native support by giving the same API of jiti.
## ⚙️ Options

@@ -158,5 +136,5 @@

Disabling allows editing code and importing same module multiple times.
Disabling allows editing code and importing the same module multiple times.
When enabled, jiti integrates with Node.js native CommonJS cache store.
When enabled, jiti integrates with Node.js native CommonJS cache-store.

@@ -184,3 +162,3 @@ ### `transform`

Return the `.default` export of a module at the top-level.
Return the `.default` export of a module at the top level.

@@ -193,4 +171,6 @@ ### `alias`

Custom alias map used to resolve ids.
You can also pass an object to the environment variable for inline config. Example: `JITI_ALIAS='{"~/*": "./src/*"}' jiti ...`.
Custom alias map used to resolve IDs.
### `nativeModules`

@@ -202,3 +182,3 @@

List of modules (within `node_modules`) to always use native require for them.
List of modules (within `node_modules`) to always use native `require()` for them.

@@ -225,2 +205,12 @@ ### `transformModules`

### `jsx`
- Type: Boolean | {options}
- Default: `false`
- Environment Variable: `JITI_JSX`
Enable JSX support using [`@babel/plugin-transform-react-jsx`](https://babeljs.io/docs/babel-plugin-transform-react-jsx).
See [`test/fixtures/jsx`](./test/fixtures/jsx) for framework integration examples.
## Development

@@ -227,0 +217,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc