Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: native esm support #259

Merged
merged 7 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ Use transpile cache

If set to `true` will use `node_modules/.cache/jiti` (if exists) or `{TMP_DIR}/node-jiti`

### `esmResolve`

- Type: Boolean | String
- Default: `false`
- Environment Variable: `JITI_ESM_RESOLVE`

Using esm resolution algorithm to support `import` condition.

### `transform`

- Type: Function
Expand Down
13 changes: 8 additions & 5 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ function onError(err) {
throw err; /* ↓ Check stack trace ↓ */
}

module.exports = function jiti(filename, opts) {
const jiti = require("../dist/jiti");

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

if (!opts.transform) {
opts.transform = require("../dist/babel");
}

return jiti(filename, opts);
const nativeImport = (id) => import(id);

return _createJITI(filename, opts, {
onError,
nativeImport,
});
};
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@
},
"devDependencies": {
"@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",
"@babel/plugin-syntax-class-properties": "^7.12.13",
"@babel/plugin-syntax-import-assertions": "^7.24.7",
"@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",
Expand All @@ -45,7 +47,6 @@
"@types/semver": "^7.5.8",
"@vitest/coverage-v8": "^1.6.0",
"acorn": "^8.12.0",
"babel-plugin-dynamic-import-node": "^2.3.3",
"babel-plugin-parameter-decorator": "^1.0.16",
"babel-plugin-transform-typescript-metadata": "^0.3.2",
"changelogen": "^0.5.5",
Expand Down
148 changes: 12 additions & 136 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading