From 2a7904a595479954ccfb1c78124fc3d7f5bebcb1 Mon Sep 17 00:00:00 2001 From: Jonathan MASSUCHETTI Date: Tue, 17 Sep 2024 18:41:01 +0200 Subject: [PATCH] Add projects to test typescript support with different compiler options (#4597) * test: create ts projects using esm and cjs Signed-off-by: Jonathan MASSUCHETTI * misc: rename "projects" to "builds Signed-off-by: Jonathan MASSUCHETTI * build(typescript): reference the new definition file in the package.json "types" fields Signed-off-by: Jonathan MASSUCHETTI --------- Signed-off-by: Jonathan MASSUCHETTI --- runtime/JavaScript/package.json | 3 ++- .../imports/builds/node-cjs-ts/.gitignore | 3 +++ .../spec/imports/builds/node-cjs-ts/index.ts | 5 +++++ .../imports/builds/node-cjs-ts/package.json | 18 +++++++++++++++++ .../spec/imports/builds/node-cjs-ts/test.sh | 19 ++++++++++++++++++ .../node-cjs-ts/tsconfig.node.commonjs.json | 10 ++++++++++ .../imports/builds/node-esm-ts/.gitignore | 3 +++ .../spec/imports/builds/node-esm-ts/index.ts | 5 +++++ .../imports/builds/node-esm-ts/package.json | 18 +++++++++++++++++ .../spec/imports/builds/node-esm-ts/test.sh | 20 +++++++++++++++++++ .../node-esm-ts/tsconfig.bundler.es2022.json | 10 ++++++++++ .../builds/node-esm-ts/tsconfig.node16.json | 10 ++++++++++ runtime/JavaScript/test-builds.sh | 6 ++++++ 13 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 runtime/JavaScript/spec/imports/builds/node-cjs-ts/.gitignore create mode 100644 runtime/JavaScript/spec/imports/builds/node-cjs-ts/index.ts create mode 100644 runtime/JavaScript/spec/imports/builds/node-cjs-ts/package.json create mode 100644 runtime/JavaScript/spec/imports/builds/node-cjs-ts/test.sh create mode 100644 runtime/JavaScript/spec/imports/builds/node-cjs-ts/tsconfig.node.commonjs.json create mode 100644 runtime/JavaScript/spec/imports/builds/node-esm-ts/.gitignore create mode 100644 runtime/JavaScript/spec/imports/builds/node-esm-ts/index.ts create mode 100644 runtime/JavaScript/spec/imports/builds/node-esm-ts/package.json create mode 100644 runtime/JavaScript/spec/imports/builds/node-esm-ts/test.sh create mode 100644 runtime/JavaScript/spec/imports/builds/node-esm-ts/tsconfig.bundler.es2022.json create mode 100644 runtime/JavaScript/spec/imports/builds/node-esm-ts/tsconfig.node16.json create mode 100644 runtime/JavaScript/test-builds.sh diff --git a/runtime/JavaScript/package.json b/runtime/JavaScript/package.json index bdbaef27e5..6af0625d6e 100644 --- a/runtime/JavaScript/package.json +++ b/runtime/JavaScript/package.json @@ -47,7 +47,8 @@ }, "scripts": { "build": "webpack", - "test": "jasmine", + "test": "jasmine && npm run test:builds", + "test:builds": "bash test-builds.sh", "coverage": "c8 jasmine", "lint": "eslint src/antlr4/" }, diff --git a/runtime/JavaScript/spec/imports/builds/node-cjs-ts/.gitignore b/runtime/JavaScript/spec/imports/builds/node-cjs-ts/.gitignore new file mode 100644 index 0000000000..51e7ab2727 --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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/builds/node-cjs-ts/index.ts b/runtime/JavaScript/spec/imports/builds/node-cjs-ts/index.ts new file mode 100644 index 0000000000..12ced671b2 --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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/builds/node-cjs-ts/package.json b/runtime/JavaScript/spec/imports/builds/node-cjs-ts/package.json new file mode 100644 index 0000000000..4eb48c37b8 --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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/builds/node-cjs-ts/test.sh b/runtime/JavaScript/spec/imports/builds/node-cjs-ts/test.sh new file mode 100644 index 0000000000..d06c95f3ea --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/node-cjs-ts/test.sh @@ -0,0 +1,19 @@ +#!/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 loading runtime with config: $tsconfig"; } + rm -rf ./tsOutput +done + +exit $failure \ No newline at end of file diff --git a/runtime/JavaScript/spec/imports/builds/node-cjs-ts/tsconfig.node.commonjs.json b/runtime/JavaScript/spec/imports/builds/node-cjs-ts/tsconfig.node.commonjs.json new file mode 100644 index 0000000000..ffbcc90f97 --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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/builds/node-esm-ts/.gitignore b/runtime/JavaScript/spec/imports/builds/node-esm-ts/.gitignore new file mode 100644 index 0000000000..51e7ab2727 --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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/builds/node-esm-ts/index.ts b/runtime/JavaScript/spec/imports/builds/node-esm-ts/index.ts new file mode 100644 index 0000000000..86e19f06ed --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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/builds/node-esm-ts/package.json b/runtime/JavaScript/spec/imports/builds/node-esm-ts/package.json new file mode 100644 index 0000000000..5573527365 --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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/builds/node-esm-ts/test.sh b/runtime/JavaScript/spec/imports/builds/node-esm-ts/test.sh new file mode 100644 index 0000000000..179eb1046e --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/node-esm-ts/test.sh @@ -0,0 +1,20 @@ +#!/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 loading runtime with config: $tsconfig"; } + rm -rf ./tsOutput +done + +exit $failure \ No newline at end of file diff --git a/runtime/JavaScript/spec/imports/builds/node-esm-ts/tsconfig.bundler.es2022.json b/runtime/JavaScript/spec/imports/builds/node-esm-ts/tsconfig.bundler.es2022.json new file mode 100644 index 0000000000..edcacb220d --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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/builds/node-esm-ts/tsconfig.node16.json b/runtime/JavaScript/spec/imports/builds/node-esm-ts/tsconfig.node16.json new file mode 100644 index 0000000000..badf533fad --- /dev/null +++ b/runtime/JavaScript/spec/imports/builds/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-builds.sh b/runtime/JavaScript/test-builds.sh new file mode 100644 index 0000000000..8a0510d226 --- /dev/null +++ b/runtime/JavaScript/test-builds.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +cd spec/imports/builds/node-esm-ts +npm run test +cd ../node-cjs-ts +npm run test \ No newline at end of file