Skip to content

Instantly share code, notes, and snippets.

@jschill
Created December 2, 2021 20:10
Show Gist options
  • Save jschill/6d79abaa12be3a5ca29368718bb7768f to your computer and use it in GitHub Desktop.
Save jschill/6d79abaa12be3a5ca29368718bb7768f to your computer and use it in GitHub Desktop.
Postinstall script to fix issue with bundler not supporting the .cjs extension
const fs = require('fs');
const { copyFileSync, existsSync } = fs;
console.log('Running post npm install tasks...')
// Fix for virtuoso.dev/react-urx and virtuoso.dev/urx
const filesToFix = [
__dirname + '/../node_modules/@virtuoso.dev/urx/dist/index.cjs',
__dirname + '/../node_modules/@virtuoso.dev/react-urx/dist/index.cjs',
];
const addJsExtensionToFile = (theFile) => {
if (existsSync(theFile)) {
console.log(theFile, 'exists');
const theFileWithJs = theFile + '.js';
if (!existsSync(theFileWithJs)) {
copyFileSync(theFile, theFileWithJs);
console.log(theFileWithJs, 'exists');
}
} else {
console.log(theFile, 'doesn\'t exist');
}
};
for (const fileToFix of filesToFix) {
addJsExtensionToFile(fileToFix);
}
console.log('Post npm install tasks done.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment