Skip to content

Commit 039c465

Browse files
committed
test: create ts projects using esm and cjs
Signed-off-by: Jonathan MASSUCHETTI <[email protected]>
1 parent 380ce4b commit 039c465

13 files changed

+130
-3
lines changed

runtime/JavaScript/package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
},
4343
"scripts": {
4444
"build": "webpack",
45-
"test": "jasmine",
45+
"test": "jasmine && npm run test:projects",
46+
"test:projects": "bash test-projects.sh",
4647
"coverage": "c8 jasmine",
4748
"lint": "eslint src/antlr4/"
4849
},
@@ -51,14 +52,13 @@
5152
},
5253
"exports": {
5354
".": {
55+
"types": "./src/antlr4/index.d.cts",
5456
"node": {
55-
"types": "./src/antlr4/index.d.ts",
5657
"import": "./dist/antlr4.node.mjs",
5758
"require": "./dist/antlr4.node.cjs",
5859
"default": "./dist/antlr4.node.mjs"
5960
},
6061
"browser": {
61-
"types": "./src/antlr4/index.d.ts",
6262
"import": "./dist/antlr4.web.mjs",
6363
"require": "./dist/antlr4.web.cjs",
6464
"default": "./dist/antlr4.web.mjs"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
3+
package-lock.json
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());
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+
}
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 runtime: $tsconfig"; }
16+
rm -rf ./tsOutput
17+
done
18+
19+
exit $failure
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/node_modules
2+
3+
package-lock.json
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());
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+
}
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 runtime: $tsconfig"; }
17+
rm -rf ./tsOutput
18+
done
19+
20+
exit $failure
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": "es2022",
7+
"moduleResolution": "bundler"
8+
},
9+
"include": ["index.ts"],
10+
}
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": "node16",
7+
"moduleResolution": "node16"
8+
},
9+
"include": ["index.ts"],
10+
}

runtime/JavaScript/test-projects.sh

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
cd spec/imports/setups/node-esm-ts
4+
npm run test
5+
cd ../node-cjs-ts
6+
npm run test

0 commit comments

Comments
 (0)