Missing package.json declaring module type (ESM/CJS mismatch between tests and lib) #24
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
test/lib.test.jsuses ESMimportsyntax whiletailscalectl/lib.jsuses CommonJSmodule.exports. There is nopackage.jsondeclaring"type": "module". The current setup works only because of Node.js 22’s heuristic module detection and will fail on Node 18 and earlier or under different configuration.Impact
Tests are not portable across Node versions and rely on an implicit, fragile behavior rather than an explicit module declaration.
Proposed Path Forward — lib.js Cleanup & Test Coverage
Resolves: #20 (for...in without hasOwnProperty), #21 (missing edge-case tests), #22 (redundant duplicate keys in errorMessage), #24 (missing package.json)
Overview
These four issues are all in the JavaScript layer (
lib.jsand test infrastructure). #20 is a code quality fix, #21 is test coverage, #22 is dead code removal, and #24 is a missing build artifact. They're all small, self-contained changes.Plan
Step 1 — Fix for...in iteration (fixes #20)
In
findActiveExitNode(), replace:with:
This avoids prototype chain traversal.
Object.keys()only returns own enumerable properties.Step 2 — Remove duplicate keys (fixes #22)
In
errorMessage(), remove the"up"and"down"keys since they map to the same strings as"connect"and"disconnect", and the QML code only ever calls with"connect","disconnect","set", or"status". The function becomes:Update the test cases that call
errorMessage("up")anderrorMessage("down")to callerrorMessage("connect")anderrorMessage("disconnect")instead.Step 3 — Add edge-case tests (fixes #21)
Add test cases for:
parsePeers(null)→[]parsePeers(undefined)→[]parsePeers({})→[]parsePeerswith peer missingTailscaleIPs→ ip is""parsePeerswith peer missingHostName→ hostname is the keyfindActiveExitNode(null)→""findActiveExitNode({})→""These verify the guard clauses and default values in both functions.
Step 4 — Add package.json (fixes #24)
Create
package.jsonat the repo root:This explicitly declares ESM mode, making the test imports portable across Node versions. The
"type": "module"field ensuresimportsyntax works without relying on Node 22's heuristic detection.Success Criteria
findActiveExitNodeusesObject.keys()iteration.errorMessagehas no duplicate keys.parsePeersandfindActiveExitNode.package.jsonexists with"type": "module".node --test test/lib.test.jsexits 0.AFK Classification
AFK. Pure JavaScript changes with automated test verification. The agent can make all edits, run the tests, and confirm they pass. No HITL needed.
Files Modified
tailscalectl/lib.js— for...in → Object.keys, remove duplicate keystest/lib.test.js— update existing tests, add edge-case testspackage.json— new fileAlso resolves: #20, #21, #22
Okay. No red flags from me. Do it. Let's see the result.
Added package.json with type:module for ESM/CJS consistency. Merged to vibes.
Resolved via merge
daab237. The plugin is confirmed working by @jtmorris. Human code review required before merging to testing.