This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+76
View File
@@ -0,0 +1,76 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [0.1.11](https://github.com/nuxt-contrib/jiti/compare/v0.1.10...v0.1.11) (2020-06-19)
### Features
* interopDefault ([44117ef](https://github.com/nuxt-contrib/jiti/commit/44117ef88f712b37bfe0a72181b76fa1a3f374c1))
### [0.1.10](https://github.com/nuxt-contrib/jiti/compare/v0.1.9...v0.1.10) (2020-06-19)
### Bug Fixes
* always ensure isDir for filename ([6b343a4](https://github.com/nuxt-contrib/jiti/commit/6b343a4fb9d7fe63628f53647d443d98b92217b6))
### [0.1.9](https://github.com/nuxt-contrib/jiti/compare/v0.1.8...v0.1.9) (2020-06-12)
### Bug Fixes
* typo in main field ([#4](https://github.com/nuxt-contrib/jiti/issues/4)) ([c57ea02](https://github.com/nuxt-contrib/jiti/commit/c57ea023635825cc929b3581b5d60c58d35a6e7a))
### [0.1.8](https://github.com/nuxt-contrib/jiti/compare/v0.1.7...v0.1.8) (2020-06-12)
### Bug Fixes
* use fake file for default _filename ([05d721f](https://github.com/nuxt-contrib/jiti/commit/05d721faa6426cb0b2d0e1262059de4c9eb4015c))
* **types:** allow passing undefined filename ([#2](https://github.com/nuxt-contrib/jiti/issues/2)) ([9136f15](https://github.com/nuxt-contrib/jiti/commit/9136f15dd3f9e56e192945e849a9db6c4df6bccd))
### [0.1.7](https://github.com/nuxt-contrib/jiti/compare/v0.1.6...v0.1.7) (2020-06-11)
### Bug Fixes
* **pkg:** add repository field ([639c02f](https://github.com/nuxt-contrib/jiti/commit/639c02fb4e7f0a117b25e968e44e3b664c4eb7d9))
### [0.1.6](https://github.com/nuxt-contrib/jiti/compare/v0.1.5...v0.1.6) (2020-06-11)
### Features
* cache support ([65c2de2](https://github.com/nuxt-contrib/jiti/commit/65c2de207147793d984d871f495af55e75b58768))
### [0.1.5](https://github.com/nuxt-contrib/jiti/compare/v0.1.4...v0.1.5) (2020-06-11)
### Features
* allow passign debug as jiti options ([8da2310](https://github.com/nuxt-contrib/jiti/commit/8da2310c6b27a2b0fac2276d462c65b0c6f2b0a8))
* build and stack-trace improvements ([71780ab](https://github.com/nuxt-contrib/jiti/commit/71780ab15d8cb843323c3edcc3e55a2a5928e72e))
* improve babel transpile and debug ([f3042dc](https://github.com/nuxt-contrib/jiti/commit/f3042dcf116b309090de552d27cd8103bc7f1001))
### [0.1.4](https://github.com/nuxt-contrib/jiti/compare/v0.1.3...v0.1.4) (2020-06-11)
### Features
* improve babel options ([ae4dc58](https://github.com/nuxt-contrib/jiti/commit/ae4dc58ab994419489c4599c04c3444a34ba6215))
### Bug Fixes
* multiline syntax detection ([46f830b](https://github.com/nuxt-contrib/jiti/commit/46f830b7333b4ed9d5377cae9afe967c96dac071))
### [0.1.3](https://github.com/nuxt-contrib/jiti/compare/v0.1.2...v0.1.3) (2020-06-07)
### [0.1.2](https://github.com/nuxt-contrib/jiti/compare/v0.1.1...v0.1.2) (2020-06-07)
### Features
* improve build system and stability ([5c3ee63](https://github.com/nuxt-contrib/jiti/commit/5c3ee63bc32c0609f32605cfb2b472afdff97648))
+139
View File
@@ -0,0 +1,139 @@
# jiti
> Runtime typescript and ESM support for Node.js (CommonJS)
[![version][npm-v-src]][npm-v-href]
[![downloads][npm-d-src]][npm-d-href]
[![size][size-src]][size-href]
## Features
- Stable typescript and esm syntax support
- Provide sync interface to replace require
- Super slim and zero dependency
- Syntax detect to avoid extra transform
- CommonJS cache integration
- Filesystem transpile cache + V8 compile cache
## Usage
```js
const jiti = require('jiti')(__filename)
jiti('./path/to/file.ts')
```
You can also pass options as second argument:
```js
const jiti = require('jiti')(__filename, { debug: true })
```
## Options
### `debug`
- Type: Boolean
- Default: `false`
Enable debug to see which files are transpiled
### `cache`
- Type: Boolean
- Default: `true`
Use transpile cache
### `cacheDir`
- Type: String
- Default: `node_modules/.cache/jiti` or `{TMP_DIR}/node-jiti`
Cache directroy (only effective if `cache` is `true`)
### `transform`
- Type: Function
- Default: Babel (lazy loaded)
Transform function. See [src/babel](./src/babel.ts) for more details
## Compared to Alternatives
### [`standard-things/esm`](https://github.com/standard-things/esm)
- `+` Much more stable thanks to babel
- `+` Less low level operations
- `+` Typescript support
- `-` Slower (without cache)
### [`babel-register`](https://babeljs.io/docs/en/babel-register)
- `+` Smaller install size (~1M vs ~11M with same plugins)
- `+` Configured out of the box
- `+` Smart syntax detect to avoid unnecessary trnaspilation
- `+` Does not ignores `node_modules`. ESM everywhere yay!
- `+` Embeddable
### [`esbuild`](https://github.com/evanw/esbuild)
- `+` No native dependency
- `+` More stable thanks to babel
- `-` Slower
- `+` Embeddable
### `ts-node`
- `+` Support both esm and typescript
- `/` No typechecking support / Faster
- `+` Smart syntax detect to avoid unnecessary transpilation
### Native ESM Support (MJS)
- It is not (yet) landed as a stable feature
- No typescript support
- Limitted to `.mjs` files with different executation context (no `__filename`, `require`, etc)
### Bundlers (`rollup`, `webpack`, `snowpack`, etc)
Meanwhile it would be much better making an optimized bundle to deploy to production or as npm package, using bundler setup and watching is frustrating during project development that's where `jiti` (or similar tools like `ts-node`) would be more convenient.
**Note:** However currently only babel transform is supported, configurable transform support is in the roadmap so using `esbuild` or other solutions would be possible.
## Development
- Clone Repo
- Run `yarn`
- Run `yarn build`
- Run `yarn dev`
- Run `node ./test/jiti.js`
## Roadmap
- [x] Basic working
- [x] Syntax detect and fallback to CJS require
- [x] Improve project build system
- [x] File system cache
- [x] Configurable transform
- [ ] Add tests
- [ ] Support `node -r jiti`
- [ ] esbuild support
## License
MIT. Made with 💖
<!-- Refs -->
[npm-v-src]: https://img.shields.io/npm/v/jiti?style=flat-square
[npm-v-href]: https://npmjs.com/package/jiti
[npm-d-src]: https://img.shields.io/npm/dm/jiti?style=flat-square
[npm-d-href]: https://npmjs.com/package/jiti
[github-actions-src]: https://img.shields.io/github/workflow/status/nuxt-contrib/jiti/ci/master?style=flat-square
[github-actions-href]: https://github.com/nuxt-contrib/jiti/actions?query=workflow%3Aci
[size-src]: https://packagephobia.now.sh/badge?p=jiti
[size-href]: https://packagephobia.now.sh/result?p=jiti
+2
View File
@@ -0,0 +1,2 @@
import { TransformOptions } from './types';
export default function transform(opts: TransformOptions): string;
+2136
View File
File diff suppressed because one or more lines are too long
+10
View File
@@ -0,0 +1,10 @@
/// <reference types="node" />
import 'v8-compile-cache';
import { TransformOptions } from './types';
export declare type JITIOptions = {
transform?: (opts: TransformOptions) => string;
debug?: boolean;
cache?: boolean;
cacheDir?: string;
};
export default function createJITI(_filename?: string, opts?: JITIOptions): NodeRequire;
+2
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
/*!*/
+5
View File
@@ -0,0 +1,5 @@
export declare type TransformOptions = {
source: string;
filename?: string;
ts?: Boolean;
};
+2
View File
@@ -0,0 +1,2 @@
export declare function isDir(filename: string): boolean;
export declare function interopDefault(ex: any): any;
+2
View File
File diff suppressed because one or more lines are too long
+1
View File
@@ -0,0 +1 @@
/*!*/
Generated Vendored
+12
View File
@@ -0,0 +1,12 @@
module.exports = function (filename, opts) {
require('./dist/v8cache')
const jiti = require('./dist/jiti')
opts = { ...opts }
if (!opts.transform) {
opts.transform = require('./dist/babel')
}
return jiti(filename, opts)
}
+81
View File
@@ -0,0 +1,81 @@
{
"_args": [
[
"jiti@0.1.11",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_from": "jiti@0.1.11",
"_id": "jiti@0.1.11",
"_inBundle": false,
"_integrity": "sha512-zSPegl+ageMLSYcq1uAZa6V56pX2GbNl/eU3Or7PFHu10a2YhLAXj5fnHJGd6cHZTalSR8zXGH8WmyuyufMhLA==",
"_location": "/jiti",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "jiti@0.1.11",
"name": "jiti",
"escapedName": "jiti",
"rawSpec": "0.1.11",
"saveSpec": null,
"fetchSpec": "0.1.11"
},
"_requiredBy": [
"/@nuxt/config",
"/@nuxt/telemetry"
],
"_resolved": "https://registry.npmjs.org/jiti/-/jiti-0.1.11.tgz",
"_spec": "0.1.11",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"bugs": {
"url": "https://github.com/nuxt-contrib/jiti/issues"
},
"description": "Runtime typescript and ESM support for Node.js (CommonJS)",
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/plugin-transform-modules-commonjs": "^7.10.1",
"@babel/plugin-transform-typescript": "^7.10.1",
"@babel/preset-typescript": "^7.10.1",
"@nuxtjs/eslint-config-typescript": "^2.0.0",
"@types/babel__core": "^7.1.8",
"@types/mkdirp": "^1.0.1",
"@types/node": "^14.0.13",
"@types/resolve": "^1.17.1",
"create-require": "^1.0.2",
"eslint": "^7.2.0",
"esm": "^3.2.25",
"mkdirp": "^1.0.4",
"resolve": "^1.17.0",
"standard-version": "^8.0.0",
"ts-loader": "^7.0.5",
"tslib": "^2.0.0",
"typescript": "^3.9.5",
"v8-compile-cache": "^2.1.1",
"webpack": "^5.0.0-beta.17",
"webpack-cli": "^3.3.11"
},
"files": [
"index.js",
"dist"
],
"homepage": "https://github.com/nuxt-contrib/jiti#readme",
"license": "MIT",
"main": "./index.js",
"name": "jiti",
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt-contrib/jiti.git"
},
"scripts": {
"build": "yarn clean && NODE_ENV=production yarn webpack",
"build:babel": "ncc build src/babel.ts -t -m -o dist/babel",
"clean": "rm -rf dist",
"dev": "yarn clean && yarn webpack --watch",
"lint": "eslint --ext .ts,.js .",
"release": "yarn test && yarn build && yarn standard-version && git push --follow-tags && npm publish",
"test": "yarn lint"
},
"types": "dist/jiti.d.ts",
"version": "0.1.11"
}