Skip to content

Commit 62e72cd

Browse files
committed
Cut runtime dependencies from 17 packages to 10
Remove fs-extra and debug from the runtime dependencies, and which from the dev dependencies: - fs-extra: 3 of its 7 call sites (existsSync, statSync) were plain node:fs re-exports; the rest map to fs.promises.mkdir/writeFile/readdir and JSON.parse(fs.readFileSync()). Drops fs-extra, graceful-fs, jsonfile and universalify. - debug: replaced by a ~10 line local helper. util.debuglog cannot be used because it only reads NODE_DEBUG from the launch environment, so it would have broken the documented DEBUG=java-caller contract, which this helper keeps working unchanged. Drops debug and ms. - which: used once, to find the java binary in a test, and its engines field (^22.22.2 || ^24.15.0 || >=26) excludes the Node 18/20 versions the CI matrix tests. Replaced by a findInPath test helper. - Bump yauzl so it no longer pulls buffer-crc32. Also fixes a few things found on the way: - engines said node >=12 while njre@3 requires >=18 and every dev tool needs 18+, so consumers on Node 12-16 installed a broken tree. - npm run lint was already broken on main: eslint 10 no longer hoists @eslint/js and globals, which eslint.config.js requires. They are now declared explicitly, and a Lint job runs npm run lint in CI so the script cannot silently rot again. - Drop the @babel/core and uuid overrides, which matched no package in the tree.
1 parent 0549039 commit 62e72cd

9 files changed

Lines changed: 115 additions & 111 deletions

File tree

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,24 @@ concurrency:
1111
cancel-in-progress: true
1212

1313
jobs:
14+
lint:
15+
name: Lint
16+
runs-on: ubuntu-latest
17+
timeout-minutes: 10
18+
steps:
19+
- name: Checkout Code
20+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
21+
with:
22+
persist-credentials: false
23+
- name: Install node
24+
uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
25+
with:
26+
node-version: "24"
27+
- name: Install dependencies
28+
run: npm ci
29+
- name: Run lint
30+
run: npm run lint
31+
1432
test:
1533
if: github.event_name != 'push' || github.ref_name == github.event.repository.default_branch
1634
strategy:

CLAUDE.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,11 @@ Three modules in `lib/`, re-exported from `index.js`:
5050
- **Java-version resolution is cached on `globalThis.JAVA_CALLER_VERSIONS_CACHE`** to avoid repeated lookups across instances in one process. Tests reset this in `test/helpers/init.js`; if you add caching state, reset it there too.
5151
- **Platform branching** lives in `getPlatformBinPath()` (darwin = `Contents/Home/bin`) and several `os.platform() === "win32"` checks. Windows also handles arg quoting (`windowsVerbatimArguments`), `javaw` for windowless, and `windowsHide`. Any new behavior must be validated on win32/darwin/linux.
5252
- **`classPath`** accepts a string (split on `:`, converted to the OS delimiter) or a string array; resolved against `rootPath` unless `useAbsoluteClassPaths` is set.
53+
- **Runtime dependencies are deliberately minimal** (`njre` + `semver` only): prefer `node:` built-ins over adding a package. The `debug()` helper at the top of `java-caller.js` is a local ~10-line replacement for the `debug` package and keeps the documented `DEBUG=java-caller` contract — `util.debuglog` can't, since it only reads `NODE_DEBUG` from the launch environment.
5354

5455
## Testing notes
5556

5657
- Tests are mocha + `node:assert`, with shared helpers in `test/helpers/common.js` (`checkStatus`, `checkStdOutIncludes`, etc.) and per-run init in `test/helpers/init.js` (loaded via the `mocha.require` config in `package.json`).
5758
- `test/java-install.test.js` exercises the real `njre` download/install path, which is why the mocha timeout is 5 minutes.
58-
- CI (`.github/workflows/test.yml`) runs the matrix Node 18/20/24 × Java 8/11/17/21/25 × ubuntu/macos/windows, plus a no-Java job (`Test - No Java`) that runs the suite in a container without a system JDK.
59+
- CI (`.github/workflows/test.yml`) runs the matrix Node 18/20/24 × Java 8/11/17/21/25 × ubuntu/macos/windows, plus a no-Java job (`Test - No Java`) that runs the suite in a container without a system JDK, plus a `Lint` job running `npm run lint`.
5960
- macOS defaults `minimumJavaVersion` to 11 (no Java 8 there); keep that branch intact.

lib/cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#! /usr/bin/env node
22
const { JavaCaller } = require("./java-caller");
3-
const fse = require("fs-extra");
3+
const fs = require("fs");
44
const path = require("path");
55

66
class JavaCallerCli {
@@ -11,7 +11,7 @@ class JavaCallerCli {
1111
constructor(baseDir) {
1212
// Use user-defined JSON file to read configuration
1313
const configFile = path.resolve(`${baseDir}/java-caller-config.json`);
14-
const options = fse.readJSONSync(configFile);
14+
const options = JSON.parse(fs.readFileSync(configFile, "utf8"));
1515
// Default output is console with CLI
1616
if (options.output == null) {
1717
options.output = "console";

lib/java-caller.js

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
#! /usr/bin/env node
2-
const debug = require("debug")("java-caller");
3-
const fse = require("fs-extra");
2+
const fs = require("fs");
43
const os = require("os");
54
const path = require("path");
5+
const util = require("util");
66
const { spawn } = require("child_process");
77
const semver = require("semver");
88

9+
// Traces are activated with DEBUG=java-caller, as before: util.debuglog is not usable here
10+
// because it only reads NODE_DEBUG from the environment the process was launched with.
11+
// Read at call time so DEBUG can be set after this module is loaded.
12+
const isDebugEnabled = () =>
13+
(process.env.DEBUG || "").split(",").some((entry) => {
14+
const namespace = entry.trim();
15+
return namespace === "java-caller" || namespace === "*";
16+
});
17+
const debug = (...args) => {
18+
if (isDebugEnabled()) {
19+
console.error(`java-caller ${util.format(...args)}`);
20+
}
21+
};
22+
923
class JavaCaller {
1024
"use strict";
1125
minimumJavaVersion = os.platform() === "darwin" ? 11 : 8; // Mac starts at 11
@@ -334,15 +348,15 @@ class JavaCaller {
334348
console.log(`Installing Java ${javaTypeToInstall} ${javaVersionToInstall} in ${this.javaCallerSupportDir}...`);
335349

336350
// Create a directory for installing Java and ensure it contains a dummy package.json
337-
await fse.ensureDir(this.javaCallerSupportDir, { mode: "0777" });
351+
await fs.promises.mkdir(this.javaCallerSupportDir, { recursive: true, mode: "0777" });
338352
const packageJson = `${this.javaCallerSupportDir + path.sep}package.json`;
339-
if (!fse.existsSync(packageJson)) {
353+
if (!fs.existsSync(packageJson)) {
340354
const packageJsonContent = {
341355
name: "java-caller-support",
342356
version: "1.0.0",
343357
description: "Java installations by java-caller (https://github.com/nvuillam/node-java-caller)",
344358
};
345-
await fse.writeFile(packageJson, JSON.stringify(packageJsonContent), "utf8");
359+
await fs.promises.writeFile(packageJson, JSON.stringify(packageJsonContent), "utf8");
346360
}
347361

348362
// Install appropriate java version using njre
@@ -464,15 +478,15 @@ class JavaCaller {
464478
// check if one matches with javaType , minimumJavaVersion and maximumJavaVersion
465479
async findJavaVersionHome() {
466480
const javaInstallsTopDir = path.join(this.javaCallerSupportDir, "jre");
467-
if (!fse.existsSync(javaInstallsTopDir)) {
481+
if (!fs.existsSync(javaInstallsTopDir)) {
468482
return {};
469483
}
470484

471-
return await fse
485+
return await fs.promises
472486
.readdir(javaInstallsTopDir)
473487
.then((items) =>
474488
items
475-
.filter((item) => fse.statSync(path.join(javaInstallsTopDir, item)).isDirectory())
489+
.filter((item) => fs.statSync(path.join(javaInstallsTopDir, item)).isDirectory())
476490
.map((folder) => {
477491
const version = semver.coerce(folder);
478492
return { version, folder };
@@ -483,7 +497,7 @@ class JavaCaller {
483497
const bin = path.join(home, this.getPlatformBinPath());
484498
return { version, folder, home, bin };
485499
})
486-
.find(({ bin }) => fse.existsSync(bin)),
500+
.find(({ bin }) => fs.existsSync(bin)),
487501
)
488502
.then((match) => {
489503
if (!match) return {};

package-lock.json

Lines changed: 42 additions & 84 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,29 +37,26 @@
3737
},
3838
"homepage": "https://github.com/nvuillam/node-java-caller#readme",
3939
"dependencies": {
40-
"debug": "^4.3.4",
41-
"fs-extra": "^11.1.1",
4240
"njre": "^3.0.0",
4341
"semver": "^7.5.4"
4442
},
4543
"devDependencies": {
44+
"@eslint/js": "^10.0.1",
4645
"@types/node": "^25.2.0",
4746
"eslint": "^10.0.0",
47+
"globals": "^17.9.0",
4848
"mocha": "^11.0.0",
4949
"prettier": "^3.1.0",
50-
"typescript": "^7.0.0",
51-
"which": "^7.0.0"
50+
"typescript": "^7.0.0"
5251
},
5352
"overrides": {
54-
"@babel/core": "^8.0.0",
5553
"brace-expansion": "^5.0.6",
5654
"diff": "^9.0.0",
5755
"js-yaml": "^5.0.0",
58-
"serialize-javascript": "^7.0.5",
59-
"uuid": "^14.0.0"
56+
"serialize-javascript": "^7.0.5"
6057
},
6158
"engines": {
62-
"node": ">=12.0.0"
59+
"node": ">=18.0.0"
6360
},
6461
"mocha": {
6562
"require": [

0 commit comments

Comments
 (0)