From 5917a50bf3108f620499786a8362d929e2678322 Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Wed, 22 Nov 2023 15:08:14 +0100 Subject: [PATCH] feat: add polyfill for `node:https` with named exports resolves #92 --- README.md | 2 +- src/runtime/node/https/index.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/runtime/node/https/index.ts diff --git a/README.md b/README.md index d638e5b5..60ae1f7e 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Using this preset, we can convert a code that is depending on Node.js to work an | [node:fs/promises](https://nodejs.org/api/fs/promises.html) | Polyfilled | [unenv/node/fs/promises](./src/runtime/node/fs/promises) | | [node:http2](https://nodejs.org/api/http2.html) | Mocked | - | | [node:http](https://nodejs.org/api/http.html) | Polyfilled | [unenv/node/http](./src/runtime/node/http) | -| [node:https](https://nodejs.org/api/https.html) | Mocked | - | +| [node:https](https://nodejs.org/api/https.html) | Polyfilled | [unenv/node/https](./src/runtime/node/https) | | [node:inspector](https://nodejs.org/api/inspector.html) | Mocked | - | | [node:module](https://nodejs.org/api/module.html) | Polyfilled | [unenv/node/module](./src/runtime/node/module) - | | [node:net](https://nodejs.org/api/net.html) | Polyfilled | [unenv/node/net](./src/runtime/node/net) | diff --git a/src/runtime/node/https/index.ts b/src/runtime/node/https/index.ts new file mode 100644 index 00000000..0dc71826 --- /dev/null +++ b/src/runtime/node/https/index.ts @@ -0,0 +1,27 @@ +// https://nodejs.org/api/https.html +import type nodeHttps from "node:https"; +import { notImplemented, notImplementedClass } from "../../_internal/utils"; + +export const Server: typeof nodeHttps.Server = + notImplementedClass("https.Server"); + +export const Agent: typeof nodeHttps.Agent = notImplementedClass("https.Agent"); + +export const globalAgent = undefined as any as typeof nodeHttps.globalAgent; + +export const get: typeof nodeHttps.get = notImplemented("https.get"); + +export const createServer: typeof nodeHttps.createServer = + notImplemented("https.createServer"); + +export const request: typeof nodeHttps.request = + notImplemented("https.request"); + +export default { + Server, + Agent, + globalAgent, + get, + createServer, + request, +};