diff --git a/runtime/JavaScript/package-lock.json b/runtime/JavaScript/package-lock.json index 08444d33b9..75dcd37a11 100644 --- a/runtime/JavaScript/package-lock.json +++ b/runtime/JavaScript/package-lock.json @@ -2480,9 +2480,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001525", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001525.tgz", - "integrity": "sha512-/3z+wB4icFt3r0USMwxujAqRvaD/B7rvGTsKhbhSQErVrJvkZCLhgNLJxU8MevahQVH6hCU9FsHdNUFbiwmE7Q==", + "version": "1.0.30001600", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001600.tgz", + "integrity": "sha512-+2S9/2JFhYmYaDpZvo0lKkfvuKIglrx68MwOBqMGHhQsNkLjB5xtc/TGoEPs+MxjSyN/72qer2g97nzR641mOQ==", "dev": true, "funding": [ { diff --git a/runtime/JavaScript/package.json b/runtime/JavaScript/package.json index 6744ebb4a8..d7e0156b13 100644 --- a/runtime/JavaScript/package.json +++ b/runtime/JavaScript/package.json @@ -42,7 +42,8 @@ }, "scripts": { "build": "webpack", - "test": "jasmine", + "test": "jasmine && npm run test:projects", + "test:projects": "bash test-projects.sh", "coverage": "c8 jasmine", "lint": "eslint src/antlr4/" }, @@ -51,14 +52,13 @@ }, "exports": { ".": { + "types": "./src/antlr4/index.d.cts", "node": { - "types": "./src/antlr4/index.d.ts", "import": "./dist/antlr4.node.mjs", "require": "./dist/antlr4.node.cjs", "default": "./dist/antlr4.node.mjs" }, "browser": { - "types": "./src/antlr4/index.d.ts", "import": "./dist/antlr4.web.mjs", "require": "./dist/antlr4.web.cjs", "default": "./dist/antlr4.web.mjs" diff --git a/runtime/JavaScript/spec/imports/setups/node-cjs-ts/.gitignore b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/.gitignore new file mode 100644 index 0000000000..51e7ab2727 --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/.gitignore @@ -0,0 +1,3 @@ +/node_modules + +package-lock.json \ No newline at end of file diff --git a/runtime/JavaScript/spec/imports/setups/node-cjs-ts/index.ts b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/index.ts new file mode 100644 index 0000000000..12ced671b2 --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/index.ts @@ -0,0 +1,5 @@ +const { CharStream } = require("antlr4"); + +const cs = new CharStream("OK"); + +console.log(cs.toString()); \ No newline at end of file diff --git a/runtime/JavaScript/spec/imports/setups/node-cjs-ts/package.json b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/package.json new file mode 100644 index 0000000000..4eb48c37b8 --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/package.json @@ -0,0 +1,18 @@ +{ + "name": "test-import-node-cjs-ts", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "commonjs", + "scripts": { + "test": "bash test.sh" + }, + "author": "", + "license": "ISC", + "dependencies": { + "antlr4": "file:../../../.." + }, + "devDependencies": { + "typescript": "^5.4.3" + } +} diff --git a/runtime/JavaScript/spec/imports/setups/node-cjs-ts/test.sh b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/test.sh new file mode 100644 index 0000000000..83297693c7 --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/test.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +tsconfigFiles=( + "tsconfig.node.commonjs.json" +) + +failure=0 + +for tsconfig in "${tsconfigFiles[@]}"; do + echo -n "$tsconfig " + + ./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; } + result=$(node ./tsOutput/index.js) + [[ $result == "OK" ]] && echo "OK" + [[ $result != "OK" ]] && { failure=1 ; echo "FAIL runtime: $tsconfig"; } +done + +exit $failure \ No newline at end of file diff --git a/runtime/JavaScript/spec/imports/setups/node-cjs-ts/tsconfig.node.commonjs.json b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/tsconfig.node.commonjs.json new file mode 100644 index 0000000000..ffbcc90f97 --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-cjs-ts/tsconfig.node.commonjs.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "skipLibCheck": true, + "outDir": "./tsOutput", + "module": "commonjs", + "moduleResolution": "node" + }, + "include": ["index.ts"], +} diff --git a/runtime/JavaScript/spec/imports/setups/node-esm-ts/.gitignore b/runtime/JavaScript/spec/imports/setups/node-esm-ts/.gitignore new file mode 100644 index 0000000000..51e7ab2727 --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-esm-ts/.gitignore @@ -0,0 +1,3 @@ +/node_modules + +package-lock.json \ No newline at end of file diff --git a/runtime/JavaScript/spec/imports/setups/node-esm-ts/index.ts b/runtime/JavaScript/spec/imports/setups/node-esm-ts/index.ts new file mode 100644 index 0000000000..86e19f06ed --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-esm-ts/index.ts @@ -0,0 +1,5 @@ +import { CharStream } from "antlr4"; + +const cs = new CharStream("OK"); + +console.log(cs.toString()); \ No newline at end of file diff --git a/runtime/JavaScript/spec/imports/setups/node-esm-ts/package.json b/runtime/JavaScript/spec/imports/setups/node-esm-ts/package.json new file mode 100644 index 0000000000..5573527365 --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-esm-ts/package.json @@ -0,0 +1,18 @@ +{ + "name": "test-import-node-esm-ts", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "test": "bash test.sh" + }, + "author": "", + "license": "ISC", + "dependencies": { + "antlr4": "file:../../../.." + }, + "devDependencies": { + "typescript": "^5.4.3" + } +} diff --git a/runtime/JavaScript/spec/imports/setups/node-esm-ts/test.sh b/runtime/JavaScript/spec/imports/setups/node-esm-ts/test.sh new file mode 100644 index 0000000000..772e4a3927 --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-esm-ts/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +tsconfigFiles=( + "tsconfig.node16.json" + "tsconfig.bundler.es2022.json" +) + +failure=0 + +for tsconfig in "${tsconfigFiles[@]}"; do + echo -n "$tsconfig " + + ./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; } + result=$(node ./tsOutput/index.js) + [[ $result == "OK" ]] && echo "OK" + [[ $result != "OK" ]] && { failure=1 ; echo "FAIL runtime: $tsconfig"; } +done + +exit $failure \ No newline at end of file diff --git a/runtime/JavaScript/spec/imports/setups/node-esm-ts/tsconfig.bundler.es2022.json b/runtime/JavaScript/spec/imports/setups/node-esm-ts/tsconfig.bundler.es2022.json new file mode 100644 index 0000000000..edcacb220d --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-esm-ts/tsconfig.bundler.es2022.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "skipLibCheck": true, + "outDir": "./tsOutput", + "module": "es2022", + "moduleResolution": "bundler" + }, + "include": ["index.ts"], +} diff --git a/runtime/JavaScript/spec/imports/setups/node-esm-ts/tsconfig.node16.json b/runtime/JavaScript/spec/imports/setups/node-esm-ts/tsconfig.node16.json new file mode 100644 index 0000000000..badf533fad --- /dev/null +++ b/runtime/JavaScript/spec/imports/setups/node-esm-ts/tsconfig.node16.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "skipLibCheck": true, + "outDir": "./tsOutput", + "module": "node16", + "moduleResolution": "node16" + }, + "include": ["index.ts"], +} diff --git a/runtime/JavaScript/test-projects.sh b/runtime/JavaScript/test-projects.sh new file mode 100644 index 0000000000..2e548d5ce8 --- /dev/null +++ b/runtime/JavaScript/test-projects.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +cd spec/imports/setups/node-esm-ts +npm run test +cd ../node-cjs-ts +npm run test \ No newline at end of file