Skip to content
Closed
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import antlr4 from 'file://<runtimePath>/src/antlr4/index.node.js'
import antlr4 from 'antlr4';
import <lexerName> from './<lexerName>.js';
<if(parserName)>
import <parserName> from './<parserName>.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"type": "module",
"devDependencies": {
"devDependencies": {
"@types/node": "^18.0.5"
},
"dependencies": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the dependency is required for 'npm link antlr4' to succeed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, all the tests passed without it. You don't need to actually have a package installed to link it. If that were the case nobody would be able to link packages that weren't published first... :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's not my experience at all
it doesn't need to be installed but it has to be declared

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are all passing without it, and I use it all the time without first installing, so I guess we have different experiences here :-)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well it's not like having it breaks anything does it ?

"antlr4": "^4.12.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,28 @@
import org.antlr.v4.test.runtime.states.GeneratedState;
import org.stringtemplate.v4.ST;

import java.io.IOException;
import java.nio.file.Paths;
import java.util.List;

import static org.antlr.v4.test.runtime.FileUtils.writeFile;
import static org.antlr.v4.test.runtime.RuntimeTestUtils.isWindows;

public class NodeRunner extends RuntimeRunner {
private final static String NPM_EXEC = "npm" + (isWindows() ? ".cmd" : "");

@Override
public String getLanguage() {
return "JavaScript";
}

@Override
protected void initRuntime(RunOptions runOptions) throws Exception {
npmLinkRuntime();
}

private void npmLinkRuntime() throws Exception {
Processor.run(new String[] {NPM_EXEC, "--silent", "install"}, normalizedRuntimePath);
Processor.run(new String[] {NPM_EXEC, "--silent", "run", "build"}, normalizedRuntimePath);
Processor.run(new String[] {NPM_EXEC, "--silent", "link"}, normalizedRuntimePath);
}

@Override
public String getExtension() { return "js"; }

Expand All @@ -35,25 +45,24 @@ public String getLanguage() {
public String getRuntimeToolName() { return "node"; }

private final static String normalizedRuntimePath = getRuntimePath("JavaScript").replace('\\', '/');
private final static String newImportAntlrString =
"import antlr4 from 'file://" + normalizedRuntimePath + "/src/antlr4/index.node.js'";

@Override
protected CompiledState compile(RunOptions runOptions, GeneratedState generatedState) {
List<GeneratedFile> generatedFiles = generatedState.generatedFiles;
for (GeneratedFile generatedFile : generatedFiles) {
try {
FileUtils.replaceInFile(Paths.get(getTempDirPath(), generatedFile.name),
"import antlr4 from 'antlr4';",
newImportAntlrString);
} catch (IOException e) {
return new CompiledState(generatedState, e);
}
try {
writeFile(getTempDirPath(), "package.json",
RuntimeTestUtils.getTextFromResource("org/antlr/v4/test/runtime/helpers/package_js.json"));

npmLinkAntlr4();

return new CompiledState(generatedState, null);

} catch (Exception e) {
return new CompiledState(generatedState, e);
}
}

writeFile(getTempDirPath(), "package.json",
RuntimeTestUtils.getTextFromResource("org/antlr/v4/test/runtime/helpers/package_js.json"));
return new CompiledState(generatedState, null);
private void npmLinkAntlr4() throws Exception {
Processor.run(new String[] {NPM_EXEC, "--silent", "link", "antlr4"}, getTempDirPath());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public class TsNodeRunner extends RuntimeRunner {
/* TypeScript runtime is the same as JavaScript runtime */
private final static String NORMALIZED_JAVASCRIPT_RUNTIME_PATH = getRuntimePath("JavaScript").replace('\\', '/');
private final static String NPM_EXEC = "npm" + (isWindows() ? ".cmd" : "");
private final static String WEBPACK_EXEC = "webpack" + (isWindows() ? ".cmd" : "");

@Override
public String getLanguage() {
Expand All @@ -30,17 +29,17 @@ public String getLanguage() {

@Override
protected void initRuntime(RunOptions runOptions) throws Exception {
npmInstallTsNodeAndWebpack();
npmInstallTsNode();
npmLinkRuntime();
}

private void npmInstallTsNodeAndWebpack() throws Exception {
Processor.run(new String[] {NPM_EXEC, "--silent", "install", "-g", "typescript", "ts-node", "webpack", "webpack-cli"}, null);
private void npmInstallTsNode() throws Exception {
Processor.run(new String[] {NPM_EXEC, "--silent", "install", "-g", "typescript", "ts-node"}, null);
}

private void npmLinkRuntime() throws Exception {
Processor.run(new String[] {NPM_EXEC, "--silent", "install"}, NORMALIZED_JAVASCRIPT_RUNTIME_PATH);
Processor.run(new String[] {WEBPACK_EXEC, "--no-stats"}, NORMALIZED_JAVASCRIPT_RUNTIME_PATH);
Processor.run(new String[] {NPM_EXEC, "--silent", "run", "build"}, NORMALIZED_JAVASCRIPT_RUNTIME_PATH);
Processor.run(new String[] {NPM_EXEC, "--silent", "link"}, NORMALIZED_JAVASCRIPT_RUNTIME_PATH);
}

Expand Down
3 changes: 0 additions & 3 deletions runtime/JavaScript/.babelrc

This file was deleted.

5 changes: 4 additions & 1 deletion runtime/JavaScript/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
/dist/
/umd/*
/cjs/*
/esm/*
!/esm/package.json
/node_modules
21 changes: 21 additions & 0 deletions runtime/JavaScript/babel.commonjs.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
modules: "commonjs",
targets: {
browsers: [
// 'last 2 versions',
// 'not ie > 0',
"chrome > 60"
]
}
// "targets": "> 0.25%, not dead"
// "targets": "last 2 versions, > 5%"
}
]
],
plugins: [
]
};
21 changes: 21 additions & 0 deletions runtime/JavaScript/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
presets: [
[
"@babel/preset-env",
{
modules: false,
targets: {
browsers: [
// 'last 2 versions',
// 'not ie > 0',
"chrome > 60"
]
}
// "targets": "> 0.25%, not dead"
// "targets": "last 2 versions, > 5%"
}
]
],
plugins: [
]
};
3 changes: 3 additions & 0 deletions runtime/JavaScript/esm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "module"
}
Loading