Created
December 2, 2021 20:10
-
-
Save jschill/6d79abaa12be3a5ca29368718bb7768f to your computer and use it in GitHub Desktop.
Postinstall script to fix issue with bundler not supporting the .cjs extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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