Files
RSSHub/lib/shims/node-module.ts
Tony c6cfb4f53f build: update cloudflare workers build (#23177)
* build: bump workers compatibility date

* build: remove implemented shim

* build: use native createRequire for node:module shim

* fix: resolve process through the node:module shim

this fixes youtubei.js on workers

* style: fix oxlint

* refactor: ditch vm2 for ichunqiu

* build: bundle data files header-generator in workers
2026-09-02 10:24:24 +08:00

13 lines
721 B
TypeScript

// oxlint-disable unicorn/prefer-node-protocol -- 'node:module' is aliased to this file, the bare specifier reaches the runtime module
// Shim for node:module in Cloudflare Workers
import { createRequire as nativeCreateRequire } from 'module';
// Rolldown calls createRequire(import.meta.url), and import.meta.url is undefined in Workers ESM.
// The native createRequire rejects undefined, so default the path and delegate to the native module.
export const createRequire = (filename?: string | URL) => {
const require = nativeCreateRequire(filename ?? 'file:///worker/index.mjs');
return (id: string) => (id === 'process' || id === 'node:process' ? process : require(id));
};
export default { createRequire };