Skip to content

Commit 2a7904a

Browse files
authored
Add projects to test typescript support with different compiler options (#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]>
1 parent eec3ff1 commit 2a7904a

File tree

13 files changed

+129
-1
lines changed

13 files changed

+129
-1
lines changed

runtime/JavaScript/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@
4747
},
4848
"scripts": {
4949
"build": "webpack",
50-
"test": "jasmine",
50+
"test": "jasmine && npm run test:builds",
51+
"test:builds": "bash test-builds.sh",
5152
"coverage": "c8 jasmine",
5253
"lint": "eslint src/antlr4/"
5354
},
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
3+
package-lock.json
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const { CharStream } = require("antlr4");
2+
3+
const cs = new CharStream("OK");
4+
5+
console.log(cs.toString());
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "test-import-node-cjs-ts",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "commonjs",
7+
"scripts": {
8+
"test": "bash test.sh"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"antlr4": "file:../../../.."
14+
},
15+
"devDependencies": {
16+
"typescript": "^5.4.3"
17+
}
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
tsconfigFiles=(
4+
"tsconfig.node.commonjs.json"
5+
)
6+
7+
failure=0
8+
9+
for tsconfig in "${tsconfigFiles[@]}"; do
10+
echo -n "$tsconfig "
11+
12+
./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; }
13+
result=$(node ./tsOutput/index.js)
14+
[[ $result == "OK" ]] && echo "OK"
15+
[[ $result != "OK" ]] && { failure=1 ; echo "FAIL loading runtime with config: $tsconfig"; }
16+
rm -rf ./tsOutput
17+
done
18+
19+
exit $failure
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"baseUrl": ".",
4+
"skipLibCheck": true,
5+
"outDir": "./tsOutput",
6+
"module": "commonjs",
7+
"moduleResolution": "node"
8+
},
9+
"include": ["index.ts"],
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
3+
package-lock.json
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { CharStream } from "antlr4";
2+
3+
const cs = new CharStream("OK");
4+
5+
console.log(cs.toString());
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "test-import-node-esm-ts",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"type": "module",
7+
"scripts": {
8+
"test": "bash test.sh"
9+
},
10+
"author": "",
11+
"license": "ISC",
12+
"dependencies": {
13+
"antlr4": "file:../../../.."
14+
},
15+
"devDependencies": {
16+
"typescript": "^5.4.3"
17+
}
18+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
3+
tsconfigFiles=(
4+
"tsconfig.node16.json"
5+
"tsconfig.bundler.es2022.json"
6+
)
7+
8+
failure=0
9+
10+
for tsconfig in "${tsconfigFiles[@]}"; do
11+
echo -n "$tsconfig "
12+
13+
./node_modules/.bin/tsc -p $tsconfig || { failure=1 ; echo "FAIL tsc: $tsconfig"; }
14+
result=$(node ./tsOutput/index.js)
15+
[[ $result == "OK" ]] && echo "OK"
16+
[[ $result != "OK" ]] && { failure=1 ; echo "FAIL loading runtime with config: $tsconfig"; }
17+
rm -rf ./tsOutput
18+
done
19+
20+
exit $failure

0 commit comments

Comments
 (0)