Skip to content

Commit

Permalink
Add projects to test typescript support with different compiler optio…
Browse files Browse the repository at this point in the history
…ns (#4597)

* test: create ts projects using esm and cjs

Signed-off-by: Jonathan MASSUCHETTI <[email protected]>

* misc: rename "projects" to "builds

Signed-off-by: Jonathan MASSUCHETTI <[email protected]>

* build(typescript): reference the new definition file in the package.json "types" fields

Signed-off-by: Jonathan MASSUCHETTI <[email protected]>

---------

Signed-off-by: Jonathan MASSUCHETTI <[email protected]>
  • Loading branch information
JesusTheHun authored Sep 17, 2024
1 parent eec3ff1 commit 2a7904a
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 1 deletion.
3 changes: 2 additions & 1 deletion runtime/JavaScript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/"
},
Expand Down
3 changes: 3 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-cjs-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules

package-lock.json
5 changes: 5 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-cjs-ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const { CharStream } = require("antlr4");

const cs = new CharStream("OK");

console.log(cs.toString());
18 changes: 18 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-cjs-ts/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
19 changes: 19 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-cjs-ts/test.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "commonjs",
"moduleResolution": "node"
},
"include": ["index.ts"],
}
3 changes: 3 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-esm-ts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/node_modules

package-lock.json
5 changes: 5 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-esm-ts/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { CharStream } from "antlr4";

const cs = new CharStream("OK");

console.log(cs.toString());
18 changes: 18 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-esm-ts/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
20 changes: 20 additions & 0 deletions runtime/JavaScript/spec/imports/builds/node-esm-ts/test.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "es2022",
"moduleResolution": "bundler"
},
"include": ["index.ts"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"baseUrl": ".",
"skipLibCheck": true,
"outDir": "./tsOutput",
"module": "node16",
"moduleResolution": "node16"
},
"include": ["index.ts"],
}
6 changes: 6 additions & 0 deletions runtime/JavaScript/test-builds.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2a7904a

Please sign in to comment.