diff --git a/index.js b/index.js deleted file mode 100644 index 7344282..0000000 --- a/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = require("./src-node/nodeJavaBridge"); diff --git a/package-lock.json b/package-lock.json index a596ce1..b90d9da 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,10 +18,12 @@ }, "devDependencies": { "@eslint/js": "^9.27.0", + "@types/node": "^22.15.21", "chalk": "2.4.2", "eslint": "^9.27.0", "globals": "^16.1.0", "prettier": "^3.5.3", + "typescript": "^5.8.3", "vitest": "^3.1.3", "when": "3.7.8" }, @@ -1115,6 +1117,16 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/node": { + "version": "22.15.21", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.15.21.tgz", + "integrity": "sha512-EV/37Td6c+MgKAbkcLG6vqZ2zEYHD7bvSrzqqs2RIhbA6w3x+Dqz8MZM3sP6kGTeLrdoOgKZe+Xja7tUB2DNkQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~6.21.0" + } + }, "node_modules/@vitest/expect": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.1.3.tgz", @@ -3426,6 +3438,27 @@ "node": ">= 0.8.0" } }, + "node_modules/typescript": { + "version": "5.8.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.3.tgz", + "integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, + "node_modules/undici-types": { + "version": "6.21.0", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz", + "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==", + "dev": true, + "license": "MIT" + }, "node_modules/unique-filename": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-3.0.0.tgz", diff --git a/package.json b/package.json index fef7677..c9ffeb9 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,20 @@ "type": "git", "url": "https://github.com/joeferner/node-java.git" }, + "main": "./build/cjs/index.js", + "module": "./build/esm/index.mjs", + "types": "./build/types/index.d.ts", + "exports": { + ".": { + "types": "./build/types/nodeJavaBridge.d.ts", + "require": "./build/cjs/nodeJavaBridge.js", + "import": "./build/esm/nodeJavaBridge.js", + "default": "./build/esm/nodeJavaBridge.js" + } + }, + "files": [ + "build" + ], "dependencies": { "async": "^3.2.6", "find-java-home": "^2.0.0", @@ -34,14 +48,18 @@ }, "devDependencies": { "@eslint/js": "^9.27.0", + "@types/node": "^22.15.21", "chalk": "2.4.2", "eslint": "^9.27.0", "globals": "^16.1.0", "prettier": "^3.5.3", + "typescript": "^5.8.3", "vitest": "^3.1.3", "when": "3.7.8" }, "scripts": { + "compile": "tsc -b ./tsconfig.cjs.json ./tsconfig.esm.json ./tsconfig.types.json", + "build": "npm run compile && node ./scripts/fix-tsc-build.js", "install": "node-gyp rebuild", "clean": "rm -rf build", "test": "node ./scripts/testRunner.js", @@ -50,6 +68,5 @@ "format": "prettier --write .", "format-cpp": "clang-format --version; find src-cpp/ -iname '*.h' -o -iname '*.cpp' | xargs clang-format -i", "precommit": "npm run format-cpp && npm run format && npm run lint && npm test" - }, - "main": "./index.js" -} + } +} \ No newline at end of file diff --git a/scripts/fix-tsc-build.js b/scripts/fix-tsc-build.js new file mode 100644 index 0000000..4528e80 --- /dev/null +++ b/scripts/fix-tsc-build.js @@ -0,0 +1,18 @@ +const fs = require("node:fs"); +const path = require("node:path"); + +const buildDir = path.join(__dirname, "..", "build", "esm"); +function createEsmModulePackageJson() { + const packageJsonFile = path.join(buildDir, "/package.json"); + fs.writeFileSync( + packageJsonFile, + new Uint8Array(Buffer.from('{"type": "module"}')), + function (err) { + if (err) { + throw err; + } + } + ); +} + +createEsmModulePackageJson(); \ No newline at end of file diff --git a/src-node/nodeJavaBridge.js b/src-node/nodeJavaBridge.ts similarity index 100% rename from src-node/nodeJavaBridge.js rename to src-node/nodeJavaBridge.ts diff --git a/tsconfig.base.json b/tsconfig.base.json new file mode 100644 index 0000000..01a9c60 --- /dev/null +++ b/tsconfig.base.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "lib": [ + "esnext" + ], + "strict": true, + "esModuleInterop": false, + "skipLibCheck": true, + "forceConsistentCasingInFileNames": true, + "moduleResolution": "node", + "baseUrl": ".", + "rootDir": "./src-node" + }, + "include": [ + "src-node" + ], + "exclude": [ + "build", + "node_modules" + ] +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 0000000..c769912 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "commonjs", + "outDir": "./build/cjs", + "target": "ES2015" + } +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 0000000..8f336ba --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "module": "esnext", + "outDir": "./build/esm", + "target": "esnext" + } +} diff --git a/tsconfig.types.json b/tsconfig.types.json new file mode 100644 index 0000000..0685647 --- /dev/null +++ b/tsconfig.types.json @@ -0,0 +1,8 @@ +{ + "extends": "./tsconfig.base.json", + "compilerOptions": { + "outDir": "./build/types", + "declaration": true, + "emitDeclarationOnly": true + } +}