Socket
Socket
Sign inDemoInstall

jiti

Package Overview
Dependencies
Maintainers
0
Versions
88
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 1.21.6 to 2.0.0-beta.1

dist/cache.d.ts

5

bin/jiti.js

@@ -8,3 +8,2 @@ #!/usr/bin/env node

if (!script) {
console.error("Usage: jiti <path> [...arguments]");

@@ -17,2 +16,4 @@ process.exit(1);

const resolved = (process.argv[1] = jiti.resolve(resolve(pwd, script)));
jiti(resolved);
jiti.import(resolved).catch(console.error);

25

dist/jiti.d.ts

@@ -1,22 +0,3 @@

/// <reference types="node" />
/// <reference types="node" />
import { Module } from "module";
import { TransformOptions, JITIOptions, JITIImportOptions } from "./types";
export type { JITIOptions, TransformOptions } from "./types";
type Require = typeof require;
type Module = typeof module;
type ModuleCache = Record<string, Module>;
export type EvalModuleOptions = Partial<{
id: string;
filename: string;
ext: string;
cache: ModuleCache;
}>;
export interface JITI extends Require {
transform: (opts: TransformOptions) => string;
register: () => () => void;
evalModule: (source: string, options?: EvalModuleOptions) => unknown;
/** @experimental Behavior of `jiti.import` might change in the future. */
import: (id: string, importOptions: JITIImportOptions) => Promise<unknown>;
}
export default function createJITI(_filename: string, opts?: JITIOptions, parentModule?: Module, parentCache?: ModuleCache): JITI;
import type { JITI, JITIOptions, Context } from "./types";
export type { JITI, JITIOptions, TransformOptions } from "./types";
export default function createJITI(filename: string, userOptions?: JITIOptions, _internal?: Pick<Context, "parentModule" | "parentCache" | "nativeImport" | "onError">): JITI;
import type { PluginObj } from "@babel/core";
export declare function TransformImportMetaPlugin(_ctx: any, opts: {
filename?: string;
}): PluginObj<import("@babel/core").PluginPass>;
}): PluginObj;

@@ -5,2 +5,2 @@ /**

import type { PluginObj } from "@babel/core";
export declare function importMetaEnvPlugin({ template, types }: any): PluginObj<import("@babel/core").PluginPass>;
export declare function importMetaEnvPlugin({ template, types }: any): PluginObj;

@@ -0,1 +1,34 @@

export type ModuleCache = Record<string, NodeModule>;
export type EvalModuleOptions = Partial<{
id: string;
filename: string;
ext: string;
cache: ModuleCache;
async: boolean;
}>;
export interface JITI extends NodeRequire {
transform: (opts: TransformOptions) => string;
register: () => () => void;
evalModule: (source: string, options?: EvalModuleOptions) => unknown;
/** @experimental Behavior of `jiti.import` might change in the future. */
import: (id: string) => Promise<unknown>;
}
type ESMImport = (id: string) => Promise<any>;
export interface Context {
filename: string;
url: URL;
userOptions: JITIOptions;
parentModule?: NodeModule;
parentCache?: ModuleCache;
nativeImport?: ESMImport;
onError?: (error: Error) => void;
opts: JITIOptions;
nativeModules: string[];
transformModules: string[];
isNativeRe: RegExp;
isTransformRe: RegExp;
alias?: Record<string, string>;
additionalExts: string[];
nativeRequire: NodeRequire;
}
export type TransformOptions = {

@@ -6,3 +39,3 @@ source: string;

retainLines?: boolean;
legacy?: boolean;
async: boolean;
[key: string]: any;

@@ -22,6 +55,3 @@ };

interopDefault?: boolean;
esmResolve?: boolean;
cacheVersion?: string;
onError?: (error: Error) => void;
legacy?: boolean;
extensions?: string[];

@@ -34,5 +64,2 @@ transformOptions?: Omit<TransformOptions, "source">;

};
export interface JITIImportOptions {
/** @internal */
_import?: () => Promise<any>;
}
export {};
import type { PackageJson } from "pkg-types";
export declare function getCacheDir(): string;
import { Context } from "./types";
export declare function isDir(filename: string): boolean;
export declare function isWritable(filename: string): boolean;
export declare function md5(content: string, len?: number): string;
export declare function detectLegacySyntax(code: string): RegExpMatchArray | null;
export declare function isObject(val: any): boolean;
export declare function readNearestPackageJSON(path: string): PackageJson | undefined;
export declare function wrapModule(source: string, opts?: {
async?: boolean;
}): string;
export declare function debug(ctx: Context, ...args: string[]): void;
export declare function jitiInteropDefault(ctx: Context, mod: any): any;
export declare function normalizeWindowsImportId(id: string): string;

@@ -5,7 +5,5 @@ function onError(err) {

module.exports = function jiti(filename, opts) {
const jiti = require("../dist/jiti");
module.exports = function createJiti(filename, opts = {}) {
const _createJITI = require("../dist/jiti");
opts = { onError, ...opts };
if (!opts.transform) {

@@ -15,3 +13,8 @@ opts.transform = require("../dist/babel");

return jiti(filename, opts);
const nativeImport = (id) => import(id);
return _createJITI(filename, opts, {
onError,
nativeImport,
});
};
{
"name": "jiti",
"version": "1.21.6",
"version": "2.0.0-beta.1",
"description": "Runtime typescript and ESM support for Node.js",
"repository": "unjs/jiti",
"license": "MIT",
"exports": {
".": {
"types": "./dist/jiti.d.ts",
"default": "./lib/index.js"
}
},
"main": "./lib/index.js",
"types": "dist/jiti.d.ts",
"bin": "bin/jiti.js",
"types": "./dist/jiti.d.ts",
"bin": {
"jiti": "bin/jiti.js"
},
"files": [

@@ -23,3 +31,3 @@ "lib",

"lint:fix": "eslint --fix . && prettier -w src lib test stubs",
"release": "pnpm build && pnpm test && changelogen --release --push && npm publish",
"release": "pnpm build && pnpm test && changelogen --release --prerelease --push --publish --publishTag 2x",
"test": "pnpm lint && vitest run --coverage && pnpm test:bun",

@@ -30,2 +38,5 @@ "test:bun": "bun --bun test test/bun"

"@babel/core": "^7.24.7",
"@babel/helper-module-transforms": "^7.24.7",
"@babel/helper-plugin-utils": "^7.24.7",
"@babel/helper-simple-access": "^7.24.7",
"@babel/plugin-proposal-decorators": "^7.24.7",

@@ -35,5 +46,2 @@ "@babel/plugin-syntax-class-properties": "^7.12.13",

"@babel/plugin-transform-export-namespace-from": "^7.24.7",
"@babel/plugin-transform-modules-commonjs": "^7.24.7",
"@babel/plugin-transform-nullish-coalescing-operator": "^7.24.7",
"@babel/plugin-transform-optional-chaining": "^7.24.7",
"@babel/plugin-transform-typescript": "^7.24.7",

@@ -45,3 +53,3 @@ "@babel/preset-typescript": "^7.24.7",

"@types/babel__template": "^7.4.4",
"@types/node": "^20.14.2",
"@types/node": "^20.14.9",
"@types/object-hash": "^3.0.6",

@@ -51,16 +59,15 @@ "@types/resolve": "^1.20.6",

"@vitest/coverage-v8": "^1.6.0",
"acorn": "^8.11.3",
"babel-plugin-dynamic-import-node": "^2.3.3",
"acorn": "^8.12.0",
"babel-plugin-parameter-decorator": "^1.0.16",
"babel-plugin-transform-typescript-metadata": "^0.3.2",
"changelogen": "^0.5.5",
"config": "^3.3.11",
"config": "^3.3.12",
"create-require": "^1.1.1",
"destr": "^2.0.3",
"escape-string-regexp": "^5.0.0",
"eslint": "^9.4.0",
"eslint": "^9.5.0",
"eslint-config-unjs": "^0.3.2",
"esm": "^3.2.25",
"estree-walker": "^3.0.3",
"execa": "^9.1.0",
"execa": "^9.3.0",
"fast-glob": "^3.3.2",

@@ -72,3 +79,3 @@ "mlly": "^1.7.1",

"pkg-types": "^1.1.1",
"prettier": "^3.3.1",
"prettier": "^3.3.2",
"reflect-metadata": "^0.2.1",

@@ -80,9 +87,10 @@ "semver": "^7.6.2",

"tslib": "^2.6.3",
"typescript": "^5.4.5",
"vite": "^5.2.12",
"typescript": "^5.5.2",
"vite": "^5.3.1",
"vitest": "^1.6.0",
"webpack": "^5.91.0",
"webpack": "^5.92.1",
"webpack-bundle-analyzer": "^4.10.2",
"webpack-cli": "^5.1.4"
},
"packageManager": "pnpm@9.2.0"
"packageManager": "pnpm@9.4.0"
}

@@ -8,6 +8,6 @@ # jiti

Runtime Typescript and ESM support for Node.js.
Just-in-Time Typescript and ESM support for Node.js.
> [!IMPORTANT]
> This is the support branch for jiti v1. Check out [jiti/main](https://github.com/unjs/jiti/tree/main) for the latest version and [unjs/jiti#174](https://github.com/unjs/jiti/issues/174) for the roadmap.
> 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.

@@ -18,10 +18,26 @@ ## Features

- Seamless interoperability between ESM and CommonJS
- Synchronous API to replace `require`
- Synchronous API to replace `require()`
- Asynchronous API to replace `import()`
- Super slim and zero dependency
- Smart syntax detection to avoid extra transforms
- CommonJS cache integration
- Filesystem transpile hard cache
- V8 compile cache
- Custom resolve alias
- Node.js native require cache integration
- Filesystem transpile with hard disk caches
- Custom resolve aliases
## Used by
- [Nitro](https://nitro.unjs.io/) and [UnJS](https://unjs.io/) ecosystem
- [Nuxt](https://nuxt.com/)
- [Docusaurus](https://docusaurus.io/)
- [UnoCSS](https://unocss.dev/)
- [Tailwindcss 3.x](https://tailwindcss.com/)
- [PostCSS loader](https://github.com/webpack-contrib/postcss-loader)
- [Slidev](https://sli.dev/)
- [FormKit](https://formkit.com/)
- [Knip](https://knip.dev/)
- [Histoire](https://histoire.dev/)
- [...55M+ npm monthly downloads](https://www.npmjs.com/package/jiti)
- [...5M+ public repositories](https://github.com/unjs/jiti/network/dependents)
- [ add yours ]
## Usage

@@ -34,3 +50,7 @@

// CommonJS mode
jiti("./path/to/file.ts");
// ESM mode
await jiti.import("./path/to/file.ts");
```

@@ -84,10 +104,2 @@

### `esmResolve`
- Type: Boolean | String
- Default: `false`
- Environment Variable: `JITI_ESM_RESOLVE`
Using esm resolution algorithm to support `import` condition.
### `transform`

@@ -166,4 +178,4 @@

[bundle-src]: https://img.shields.io/bundlephobia/minzip/jiti?style=flat&colorA=18181B&colorB=F0DB4F
[bundle-href]: https://bundlephobia.com/result?p=h3
[bundle-href]: https://bundlephobia.com/result?p=jiti
[license-src]: https://img.shields.io/github/license/unjs/jiti.svg?style=flat&colorA=18181B&colorB=F0DB4F
[license-href]: https://github.com/unjs/jiti/blob/main/LICENSE

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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