diff --git a/dev/fixAntlr4.js b/dev/fixAntlr4.js new file mode 100644 index 000000000..0a6f9b7e8 --- /dev/null +++ b/dev/fixAntlr4.js @@ -0,0 +1,18 @@ +/** + * The purpose of this script is to modify the configuration. + * of the antlr4 dependency. This is necessary as a workaround + * in order to avoid performance problems from antlr4. + * The fix is taken from https://github.com/antlr/antlr4/pull/4323 + * This script can be removed when the fix is available as part of + * a published NPM package. + */ + +const fs = require('fs-extra'); +const path = require('path'); + +const antlr4BabelPath = path.join(__dirname, '..', 'node_modules', 'antlr4', '.babelrc'); +const babelContents = { + presets: ['@babel/preset-env'], + targets: 'defaults' +}; +fs.writeJSONSync(antlr4BabelPath, babelContents); diff --git a/package.json b/package.json index 02a0927d0..14f12d0a0 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,10 @@ "regression": "ts-node regression/run-regression.ts", "regression:all": "ts-node regression/run-regression.ts regression/repos-all.txt", "prepare": "npm run build", + "postinstall": "npm run fixAntlr4", "prepublishOnly": "npm run check && npm run fixGrammarTypes", - "fixGrammarTypes": "ts-node dev/fixGrammarTypes.ts" + "fixGrammarTypes": "ts-node dev/fixGrammarTypes.ts", + "fixAntlr4": "node dev/fixAntlr4.js && cd node_modules && cd antlr4 && npm install && npm run build" }, "contributors": [ "Julia Afeltra ", @@ -42,7 +44,8 @@ "dist/**/*.{js,json,d.ts}", "dist/ig/files/**/*", "dist/utils/init-project/**/*", - "antlr/**/*.g4" + "antlr/**/*.g4", + "dev/fixAntlr4.js" ], "license": "Apache-2.0", "devDependencies": {