esbuild-isolated-dts
Version:
Generate declarations fast using isolated declarations
23 lines (22 loc) • 995 B
JavaScript
import { defaultExts, initializeOptions } from './options.js';
import { transpileDeclaration } from './transpiler.js';
export function isoldatedDtsPlugin(opts) {
opts = opts || {};
return {
name: 'esbuild-isolated-dts',
setup(build) {
const filePaths = [], buildOpts = build.initialOptions, exts = opts.exts || defaultExts, filter = new RegExp(`\\.(${exts.join('|')})$`);
build.onLoad({ filter }, async (args) => {
filePaths.push(args.path);
return {};
});
build.onEnd(async (result) => {
const optsI = initializeOptions(opts, buildOpts, filePaths), diagnostics = await Promise.all(filePaths.map((fp) => transpileDeclaration(fp, optsI, result)));
return {
errors: diagnostics.flatMap((d) => d.errors || []),
warnings: diagnostics.flatMap((d) => d.warnings || []),
};
});
},
};
}