Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
unenv-nightly
Advanced tools
`unenv` is a framework-agnostic system that allows converting JavaScript code to be platform agnostic and work in any environment including Browsers, Workers, Node.js, or JavaScript runtime.
unenv
is a framework-agnostic system that allows converting JavaScript code to be platform agnostic and work in any environment including Browsers, Workers, Node.js, or JavaScript runtime.
# Using npm
npm i -D unenv
# Using yarn
yarn add --dev unenv
# Using pnpm
pnpm add -D unenv
Using env
utility and built-in presets, unenv
will provide an abstract configuration that can be used in building pipelines (rollup.js, webpack, etc.).
import { env } from "unenv";
const { alias, inject, polyfill, external } = env({}, {}, {});
Note: You can provide as many presets as you want. unenv will merge them internally and the right-most preset has a higher priority.
node
Suitable to convert universal libraries working in Node.js.
fetch
APIimport { env, node } from "unenv";
const envConfig = env(node, {});
nodeless
Suitable to transform libraries made for Node.js to run in other JavaScript runtimes.
import { env, nodeless } from "unenv";
const envConfig = env(nodeless, {});
deno
This preset can be used to extend nodeless
to use Deno's Node.js API Compatibility (docs, docs).
[!WARNING] This preset is experimental and behavior might change!
import { env, nodeless, deno } from "unenv";
const envConfig = env(nodeless, deno, {});
cloudflare
This preset can be used to extend nodeless
to use Cloudflare Worker Node.js API Compatibility (docs).
[!WARNING] This preset is experimental and behavior might change!
[!NOTE] Make sure to enable
nodejs_compat
compatibility flag.
import { env, nodeless, cloudflare } from "unenv";
const envConfig = env(nodeless, cloudflare, {});
vercel
This preset can be used to extend nodeless
to use Vercel Edge Node.js API Compatibility (docs).
[!WARNING] This preset is experimental and behavior might change!
import { env, nodeless, vercel } from "unenv";
const envConfig = env(nodeless, vercel, {});
unenv
provides a replacement for all Node.js built-ins for cross-platform compatibility.
unenv
provides a replacement for common npm packages for cross platform compatibility.
Package | Status | Source |
---|---|---|
npm/consola | Use native console | unenv/runtime/npm/consola |
npm/cross-fetch | Use native fetch | unenv/runtime/npm/cross-fetch |
npm/debug | Mocked with console.debug | unenv/runtime/npm/debug |
npm/fsevents | Mocked | unenv/runtime/npm/fsevents |
npm/inherits | Inlined | unenv/runtime/npm/inherits |
npm/mime-db | Minimized | unenv/runtime/npm/mime-db |
npm/mime | Minimized | unenv/runtime/npm/mime |
npm/node-fetch | Use native fetch | unenv/runtime/npm/node-fetch |
npm/whatwg-url | Use native URL | unenv/runtime/npm/whatwg-url |
import MockProxy from "unenv/runtime/mock/proxy";
console.log(MockProxy().foo.bar()[0]);
The above package doesn't work outside of Node.js and neither we need any platform-specific logic! When aliasing os
to mock/proxy-cjs
, it will be auto-mocked using a Proxy Object which can be recursively traversed like an Object
, called like a Function
, Iterated like an Array
, or instantiated like a Class
.
We use this proxy for auto-mocking unimplemented internals. Imagine a package does this:
const os = require("node:os");
if (os.platform() === "windows") {
/* do some fix */
}
module.exports = "Hello world";
By aliasing os
to unenv/runtime/mock/proxy-cjs
, the code will be compatible with other platforms.
To discover other polyfills, please check ./src/runtime.
You can use nightly release channel to try latest changes in main
branch via unenv-nightly
.
If directly using unenv
in your project:
{
"devDependencies": {
"unenv": "npm:unenv-nightly"
}
}
If using unenv
via another tool (Nuxt or Nitro) in your project:
{
"resolutions": {
"unenv": "npm:unenv-nightly"
}
}
MIT
FAQs
<!-- automd:badges color=yellow packagephobia -->
The npm package unenv-nightly receives a total of 615,141 weekly downloads. As such, unenv-nightly popularity was classified as popular.
We found that unenv-nightly demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.