// Webpack loader. CommonJS entry (webpack requires loaders synchronously)// that hands off to the ESM core via the async loader API. Works in Next.js// through next.config webpack(config) — see examples/27-nextjs.const fs = require("node:fs");const path = require("node:path");// The loader's real logic lives in ESM files webpack cannot see through the// dynamic import, so its persistent cache (Next.js keeps one in .next/cache)// would keep serving output from an older compiler. Declaring them as build// dependencies invalidates that cache when the compiler or runtime changes.const compilerFiles = () => { const dirs = [__dirname, path.join(__dirname, "..", "cli", "src"), path.join(__dirname, "..", "runtime")]; return dirs.flatMap((dir) => fs.existsSync(dir) ? fs.readdirSync(dir).filter((f) => f.endsWith(".js")).map((f) => path.join(dir, f)) : [], );};module.exports = function tsusLoader(source) { const callback = this.async(); if (typeof this.addBuildDependency === "function") { for (const file of compilerFiles()) { this.addBuildDependency(file); } } import("./core.js") .then(({ transformSource }) => { callback(null, transformSource(source, this.resourcePath)); }) .catch(callback);};