THRIFT-5811: Add ESM support to nodejs codegen
Client: nodejs
Patch: Cameron Martin <cameronm@graphcore.ai>
This closes #3083
This adds a flag to the JS generator to output ES modules instead of CommonJS. This is only valid when targeting node. A lot of the changes here are to test this.
The `testAll.sh` script now generates an ES module version of the services and types, and tests the client and the server with these. This has a few knock-on effects. Firstly, any module that imports a generated ES module must itself be an ES module, since CommonJS modules cannot import ES modules. ES modules also do not support `NODE_PATH`, so instead the tests directory is converted into a node package with a `file:` dependency on the root thrift package.
diff --git a/lib/nodejs/test/package-lock.json b/lib/nodejs/test/package-lock.json
new file mode 100644
index 0000000..e7f9543
--- /dev/null
+++ b/lib/nodejs/test/package-lock.json
@@ -0,0 +1,52 @@
+{
+ "name": "test",
+ "lockfileVersion": 3,
+ "requires": true,
+ "packages": {
+ "": {
+ "devDependencies": {
+ "thrift": "file:../../.."
+ }
+ },
+ "../../..": {
+ "version": "0.22.0",
+ "dev": true,
+ "license": "Apache-2.0",
+ "dependencies": {
+ "browser-or-node": "^1.2.1",
+ "isomorphic-ws": "^4.0.1",
+ "node-int64": "^0.4.0",
+ "q": "^1.5.0",
+ "ws": "^5.2.3"
+ },
+ "devDependencies": {
+ "@eslint/js": "^9.18.0",
+ "@types/node": "^22.10.5",
+ "@types/node-int64": "^0.4.29",
+ "@types/q": "^1.5.1",
+ "buffer-equals": "^1.0.4",
+ "commander": "^13.0.0",
+ "connect": "^3.6.6",
+ "eslint": "^9.18.0",
+ "eslint-config-prettier": "^10.0.1",
+ "eslint-plugin-prettier": "^5.2.1",
+ "globals": "^15.14.0",
+ "html-validator-cli": "^2.0.0",
+ "jsdoc": "^4.0.2",
+ "json-int64": "^1.0.2",
+ "nyc": "^15.0.0",
+ "prettier": "^3.4.2",
+ "tape": "^4.9.0",
+ "typescript": "^5.7.2",
+ "utf-8-validate": "^5.0.0"
+ },
+ "engines": {
+ "node": ">= 10.18.0"
+ }
+ },
+ "node_modules/thrift": {
+ "resolved": "../../..",
+ "link": true
+ }
+ }
+}