Skip to content

chore: inline 5 dependencies, removing external packages#500

Merged
cameri merged 6 commits intomainfrom
chore/inline-dependencies
Apr 18, 2026
Merged

chore: inline 5 dependencies, removing external packages#500
cameri merged 6 commits intomainfrom
chore/inline-dependencies

Conversation

@phoenix-server
Copy link
Copy Markdown
Collaborator

@phoenix-server phoenix-server commented Apr 18, 2026

Summary

  • Removed bech32, dotenv, helmet, and tor-control-ts from production dependencies (16 → 12)
  • Each package was replaced by inlining its functionality directly into the codebase

Changes

  • bech32 — ~75-line pure bech32 encode/decode inlined into src/utils/transform.ts
  • tor-control-ts — replaced with a ~60-line TorClient class using Node.js net.Socket in src/tor/client.ts; tests updated to stub TorClient.prototype directly
  • helmet — replaced with an inline CSP middleware in src/factories/web-app-factory.ts
  • dotenv — replaced with Node.js --env-file-if-exists=.env flag in npm scripts (requires Node 22.9+; this project targets Node 24)

Test plan

  • npm run build passes (TypeScript)
  • npm test passes (all 623 unit tests)
  • npm run lint passes (Biome)
  • Manual smoke: relay connection, event publish, NIP-05 lookup

🤖 Generated with Claude Code

- bech32: inline encode/decode in transform.ts (~75 lines)
- accepts: replace with request.headers.accept?.includes() check
- tor-control-ts: inline Tor control protocol via net.Socket (TorClient class)
- helmet: inline Content-Security-Policy header construction
- dotenv: use Node.js --env-file-if-exists flag in npm scripts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coveralls
Copy link
Copy Markdown
Collaborator

coveralls commented Apr 18, 2026

Coverage Status

Coverage is 68.308%chore/inline-dependencies into main. No base build found for main.

@cameri
Copy link
Copy Markdown
Owner

cameri commented Apr 18, 2026

@copilot resolve the merge conflicts in this pull request, make no mistakes

phoenix-server and others added 2 commits April 18, 2026 13:43
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@socket-security
Copy link
Copy Markdown

socket-security Bot commented Apr 18, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​types/​accepts@​1.3.71001007080100

View full report

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

@copilot resolve the merge conflicts in this pull request, make no mistakes

Resolved in 353caca. Three files had conflicts:

  • src/tor/client.ts — kept TorClient class name, fixed spacing
  • src/utils/transform.ts — kept inlined bech32, adopted multi-line ramda import style from main
  • test/unit/tor/onion.spec.ts — kept TorClient prototype stubs, removed unused mockModule helper from main's stale version

All 769 unit tests pass, build and lint are clean.

@cameri
Copy link
Copy Markdown
Owner

cameri commented Apr 18, 2026

@copilot what's the size on disk of dependencies before/after? and what's the % relative change?

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

@copilot what's the size on disk of dependencies before/after? and what's the % relative change?

Measured using du -sb (actual byte content, no block-size padding):

Package Removed (bytes)
bech32 10,209
dotenv 36,605
helmet 90,584
tor-control-ts 13,520
Total removed 150,918

The inlined replacements added ~4,864 bytes to source files (transform.ts +2,443, client.ts +2,264, web-app-factory.ts +157), so the net reduction is ~146 KB of package code.

node_modules disk usage:

  • Before: 280,707,677 bytes (267.7 MB)
  • After: 280,562,512 bytes (267.5 MB)
  • Reduction: 145,165 bytes (141.8 KB) — −0.05%

The small relative change is expected: these were lightweight packages against a 268 MB node_modules. The value here is fewer external supply-chain dependencies rather than a significant size win.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces production dependencies by inlining functionality previously provided by bech32, tor-control-ts, helmet, and dotenv, updating the Tor client, CSP handling, and environment-variable loading accordingly.

Changes:

  • Inlined bech32 encode/decode logic into src/utils/transform.ts.
  • Replaced tor-control-ts with a custom TorClient over net.Socket, updating Tor-related unit tests.
  • Replaced helmet CSP middleware with an inline CSP header builder and removed dotenv initialization in favor of Node’s --env-file-if-exists.

Reviewed changes

Copilot reviewed 10 out of 11 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
test/unit/tor/onion.spec.ts Updates Tor tests to stub the new TorClient instead of tor-control-ts.
src/utils/transform.ts Removes external bech32 dependency and adds inline bech32 encode/decode helpers.
src/tor/client.ts Introduces TorClient based on net.Socket and updates onion creation flow.
src/scripts/export-events.ts Removes dotenv startup loading.
src/index.ts Removes dotenv startup loading.
src/import-events.ts Removes dotenv startup loading.
src/handlers/request-handlers/root-request-handler.ts Import ordering change.
src/factories/web-app-factory.ts Replaces helmet CSP middleware with manual CSP header construction.
src/clean-db.ts Removes dotenv startup loading.
package.json Updates scripts to use --env-file-if-exists and removes several dependencies; adds @types/accepts.
package-lock.json Reflects dependency removals/additions from package.json.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tor/client.ts
Comment thread src/utils/transform.ts Outdated
Comment thread src/utils/transform.ts Outdated
Comment thread package.json
Comment thread package.json
Comment thread test/unit/tor/onion.spec.ts
Comment thread src/tor/client.ts Outdated
Comment thread src/tor/client.ts Outdated
@cameri
Copy link
Copy Markdown
Owner

cameri commented Apr 18, 2026

@copilot address all inline comments

…validation, type deps, engines, await closeTorClient, TorClient tests

Agent-Logs-Url: https://github.com/cameri/nostream/sessions/f56791f2-7216-4d11-b88a-63b5d2c432e5

Co-authored-by: cameri <378886+cameri@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

@copilot address all inline comments

All addressed in 2ed81f5:

  • src/tor/client.ts: Added isCompleteTorReply for proper multi-line Tor reply parsing (handles 250- continuations, 250+ data blocks, and terminating 250 OK). sendCommand now uses it instead of the naive endsWith('\r\n') check, and attaches an error handler with cleanup on both resolve and reject.
  • src/utils/transform.ts: bech32Convert now validates each input symbol is within the expected bit range and rejects non-zero leftover bits in the non-padded decode path. fromBech32 normalizes input to lowercase before the prefix check and rejects mixed-case inputs.
  • package.json: @types/accepts moved to devDependencies; added "engines": { "node": ">=22.9" }.
  • test/unit/tor/onion.spec.ts: All closeTorClient() calls are now await closeTorClient().
  • test/unit/tor/client.spec.ts (new): 22 focused tests covering isCompleteTorReply (10 cases), sendCommand (8 cases including fragmented TCP chunks, listener cleanup, socket error mid-command), and connect (4 cases). All 791 unit tests pass.

@cameri cameri self-assigned this Apr 18, 2026
Comment thread package.json Outdated
@cameri cameri assigned Copilot and unassigned cameri Apr 18, 2026
Copilot AI requested a review from cameri April 18, 2026 18:50
@cameri cameri merged commit b73bcdc into main Apr 18, 2026
14 checks passed
@cameri cameri deleted the chore/inline-dependencies branch April 18, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants