Skip to content

Commit

Permalink
chore(headless): esm build for node will look for "module" files inst…
Browse files Browse the repository at this point in the history
  • Loading branch information
alexprudhomme authored Sep 11, 2024
1 parent cb20ded commit f83b610
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions packages/headless/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ const nodeEsm = Object.entries(useCaseEntries).map((entry) => {
outfile,
format: 'esm',
external: ['pino'],
mainFields: ['module', 'main'],
},
dir
);
Expand Down Expand Up @@ -263,30 +264,6 @@ async function buildNodeConfig(options, outDir) {
return out;
}

// https://github.com/coveo/ui-kit/issues/1616
function adjustRequireImportsInNodeEsmBundles() {
const paths = getNodeEsmBundlePaths();

return paths.map(async (filePath) => {
const resolvedPath = resolve(filePath);

const content = await promises.readFile(resolvedPath, {
encoding: 'utf-8',
});
const modified = content.replace(/__require\(/g, 'require(');

await promises.writeFile(resolvedPath, modified);
});
}

function getNodeEsmBundlePaths() {
return Object.entries(useCaseEntries).map((entry) => {
const [useCase] = entry;
const dir = getUseCaseDir('dist/', useCase);
return `${dir}/headless.esm.js`;
});
}

function outputMetafile(platform, outDir, metafile) {
const outFile = resolve(outDir, `${platform}.stats.json`);
writeFileSync(outFile, JSON.stringify(metafile));
Expand All @@ -301,7 +278,6 @@ async function main() {
...nodeCjs,
...quanticUmd,
]);
await Promise.all(adjustRequireImportsInNodeEsmBundles());
}

main();

0 comments on commit f83b610

Please sign in to comment.