Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix js webpack issue #4104

Merged
merged 5 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,11 +242,11 @@ jobs:
python-version: '3.x'
architecture: 'x64'

- name: Set up Node 14
- name: Set up Node 16
if: (matrix.target == 'javascript') || (matrix.target == 'typescript')
uses: actions/setup-node@v3.5.1
uses: actions/setup-node@v3.6.0
with:
node-version: '14'
node-version: '16'

- name: Setup Dotnet
if: matrix.target == 'csharp'
Expand Down
4 changes: 2 additions & 2 deletions runtime/JavaScript/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 3 additions & 5 deletions runtime/JavaScript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "antlr4",
"version": "4.12.0-beta.4",
"version": "4.12.0-beta.5",
"type": "module",
"description": "JavaScript runtime for ANTLR4",
"main": "dist/antlr4.js",
Expand All @@ -20,9 +20,9 @@
"homepage": "https://github.com/antlr/antlr4",
"devDependencies": {
"@babel/core": "^7.19.1",
"@babel/eslint-parser": "^7.19.1",
"@babel/preset-env": "^7.19.4",
"@types/node": "^18.7.23",
"@babel/eslint-parser": "^7.19.1",
"babel-loader": "^8.2.5",
"compression-webpack-plugin": "^10.0.0",
"eslint": "^8.23.1",
Expand All @@ -45,8 +45,6 @@
"node": ">=16"
},
"browser": {
"fs": false,
"net": false,
"module": false
"fs": false
}
}
9 changes: 8 additions & 1 deletion runtime/JavaScript/src/antlr4/FileStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@
*/

import InputStream from './InputStream.js';
import fs from "fs";
const isNode =
typeof process !== "undefined" &&
process.versions != null &&
process.versions.node != null;
// use eval to fool webpack and mocha
const fs = isNode ? await eval("import('fs')") : null;

/**
* This is an InputStream that is loaded from a file all at once
* when you construct the object.
*/
export default class FileStream extends InputStream {
constructor(fileName, decodeToUnicodeCodePoints) {
if(!isNode)
throw new Error("FileStream is only available when running in Node!");
const data = fs.readFileSync(fileName, "utf8");
super(data, decodeToUnicodeCodePoints);
this.fileName = fileName;
Expand Down
4 changes: 1 addition & 3 deletions runtime/JavaScript/webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ module.exports = {
resolve: {
extensions: [ '.js'],
fallback: {
module: false,
net: false,
fs: false
}
},
target: "node16",
target: "web",
module: {
rules: [{
test: /\.js$/,
Expand Down