fix: add createRequire banner for CJS compat in ESM bundles

Bundled CJS dependencies (e.g. reading-time) use require() for Node
builtins like 'stream' and 'util'. In ESM output, the esbuild-generated
__require shim throws 'Dynamic require of X is not supported' because
there is no global require in ESM context.

Add platform: 'node' and a banner that injects createRequire from the
'module' builtin, providing a working require() function for the CJS
compatibility layer.
This commit is contained in:
saberzero1 2026-03-17 20:34:33 +01:00
parent 6e0799acce
commit d63abb365d
No known key found for this signature in database
3 changed files with 10 additions and 4 deletions

8
dist/index.js vendored
View file

@ -1,3 +1,4 @@
import { createRequire } from 'module';
import path from 'path';
import fs from 'fs/promises';
import { styleText } from 'util';
@ -6,16 +7,17 @@ import { joinSegments } from '@quartz-community/types';
import { unescapeHTML } from '@quartz-community/utils';
import { jsxs, Fragment, jsx } from 'preact/jsx-runtime';
const require$1 = createRequire(import.meta.url);
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __require = /* @__PURE__ */ ((x2) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x2, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
var __require = /* @__PURE__ */ ((x2) => typeof require$1 !== "undefined" ? require$1 : typeof Proxy !== "undefined" ? new Proxy(x2, {
get: (a, b) => (typeof require$1 !== "undefined" ? require$1 : a)[b]
}) : x2)(function(x2) {
if (typeof require !== "undefined") return require.apply(this, arguments);
if (typeof require$1 !== "undefined") return require$1.apply(this, arguments);
throw Error('Dynamic require of "' + x2 + '" is not supported');
});
var __esm = (fn, res) => function __init() {

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -13,7 +13,11 @@ export default defineConfig({
target: "es2022",
splitting: false,
outDir: "dist",
platform: "node",
external: ["sharp"],
banner: {
js: 'import { createRequire } from "module"; const require = createRequire(import.meta.url);',
},
esbuildOptions(options: BuildOptions) {
options.jsx = "automatic";
options.jsxImportSource = "preact";