diff --git a/build.mjs b/build.mjs index 9675c9a..e239999 100644 --- a/build.mjs +++ b/build.mjs @@ -31,6 +31,28 @@ function patchRecast() { } } +/** + * @returns {import('esbuild').Plugin} + */ +function patchJiti() { + return { + name: 'patch-jiti', + setup(build) { + // TODO: Switch to rolldown and see if we can chunk split this instead? + build.onLoad({ filter: /jiti\/lib\/jiti\.mjs$/ }, async (args) => { + let original = await fs.promises.readFile(args.path, 'utf8') + + return { + contents: original.replace( + 'createRequire(import.meta.url)("../dist/babel.cjs")', + 'require("../dist/babel.cjs")', + ), + } + }) + }, + } +} + /** * @returns {import('esbuild').Plugin} */ @@ -115,7 +137,7 @@ let context = await esbuild.context({ entryPoints: [path.resolve(__dirname, './src/index.js')], outfile: path.resolve(__dirname, './dist/index.mjs'), format: 'esm', - plugins: [patchRecast(), patchCjsInterop(), inlineCssImports()], + plugins: [patchRecast(), patchJiti(), patchCjsInterop(), inlineCssImports()], }) await context.rebuild() diff --git a/package-lock.json b/package-lock.json index 87e17ea..4e3efa0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,7 +27,7 @@ "esbuild": "^0.25.9", "escalade": "^3.2.0", "import-sort-style-module": "^6.0.0", - "jiti": "^2.5.1", + "jiti": "^2.6.0", "jsesc": "^3.1.0", "license-checker": "^25.0.1", "line-column": "^1.0.2", @@ -4067,9 +4067,9 @@ "dev": true }, "node_modules/jiti": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.5.1.tgz", - "integrity": "sha512-twQoecYPiVA5K/h6SxtORw/Bs3ar+mLUtoPSc7iMXzQzK8d7eJ/R09wmTwAjiamETn1cXYPGfNnu7DMoHgu12w==", + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/jiti/-/jiti-2.6.0.tgz", + "integrity": "sha512-VXe6RjJkBPj0ohtqaO8vSWP3ZhAKo66fKrFNCll4BTcwljPLz03pCbaNKfzGP5MbrCYcbJ7v0nOYYwUzTEIdXQ==", "dev": true, "license": "MIT", "bin": { diff --git a/package.json b/package.json index e74a423..b0f3530 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ "esbuild": "^0.25.9", "escalade": "^3.2.0", "import-sort-style-module": "^6.0.0", - "jiti": "^2.5.1", + "jiti": "^2.6.0", "jsesc": "^3.1.0", "license-checker": "^25.0.1", "line-column": "^1.0.2",