Skip to content

Commit

Permalink
BC-5080 - fix compilation problem on windows (#4426)
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenWaysDP authored Sep 21, 2023
1 parent b088aef commit f369d58
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions esbuild/esmodules-bundler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable import/no-extraneous-dependencies */
const { dtsPlugin } = require('esbuild-plugin-d.ts');
const { build } = require('esbuild');
const { exec } = require('child_process');

const fs = require('fs');
const { resolve } = require('path');
// add files to be transformed from CommonJs to EsModules in the following list
const options = [
{
Expand All @@ -14,10 +14,9 @@ const options = [
name: 'file-type-lib',
entryPoint: ['esbuild/content/file-type-cjs-index.ts'],
outdir: 'node_modules/file-type-cjs',
// Path to file containing the resolution-mode="require" declaration.
pathToResolutionModeError: 'node_modules/file-type/dist/index.d.ts',
},
{
// Path to file containing the resolution-mode="require" declaration.
pathToResolutionModeError: 'node_modules/peek-readable/lib/StreamReader.d.ts',
},
{
Expand All @@ -42,6 +41,18 @@ const globalOptions = {
loader: { '.js': 'jsx' },
};

function replace(pathToResolutionModeError) {
const file = resolve(__dirname, '..', pathToResolutionModeError);
fs.readFile(file, 'utf8', (err, data) => {
if (err) throw err;
const result = data.replace(/resolution-mode="require"/g, '');

fs.writeFile(file, result, 'utf8', (err) => {
if (err) throw err;
});
});
}

for (const option of options) {
const { entryPoint, outdir, pathToResolutionModeError } = option;
try {
Expand All @@ -60,7 +71,7 @@ for (const option of options) {

// remove resolution-mode="require" from file because it provokes an error in the commonjs build
if (pathToResolutionModeError) {
exec(`sed -i -- 's/resolution-mode="require"//g' ${pathToResolutionModeError} `);
replace(pathToResolutionModeError);
}
} catch (e) {
process.exit(1);
Expand Down

0 comments on commit f369d58

Please sign in to comment.