Skip to content

Bundle Node entrypoint with ncc to slim install footprint - #10

Open
collin-rogers wants to merge 1 commit into
masterfrom
collin/int-2071-ncc-build
Open

Bundle Node entrypoint with ncc to slim install footprint#10
collin-rogers wants to merge 1 commit into
masterfrom
collin/int-2071-ncc-build

Conversation

@collin-rogers

Copy link
Copy Markdown

Problem

Installing cyberchef-node unpacks a very large node_modules tree (~16k files, ~183M). On network-backed disks the per-file round-trips dominate install time — installs of consuming integrations have been observed at ~9 minutes. The file count is the lever, not total bytes.

Change

Bundle the pure-JS runtime dependencies into a single file with @vercel/ncc at build/publish time. The published package now ships ~11 files instead of thousands.

Metric Before After
Files shipped (package) ~16,415 11
Consuming integration archive (CyberChef) 18,344 files / 214M 2,392 files / 70M
Local extract time (integration archive) ~8.8s ~1.2s

What's in the PR

  • scripts/bundle.js — runs ncc against the generated src/node/index.js, emitting dist/index.js (+ ncc lazy chunks).
  • WebAssembly packages stay external. tesseract.js, tesseract.js-core, libyara-wasm, libbzip2-wasm, and argon2-browser ship WASM that ncc/webpack cannot inline. They remain the package's only runtime dependencies and resolve from node_modules at runtime.
  • package.jsonmaindist/index.js; build split into generate + bundle; added prepack so the bundle is produced automatically on npm pack/npm publish (release workflow needs no change). Inlined runtime deps moved to devDependencies; only the 4 WASM packages remain in dependencies.
  • package-lock.json — regenerated. Full dependency graph preserved (378 packages before and after) so security scanning against the lockfile is unaffected; deps only move between dependencies/devDependencies.
  • .npmignore — publish dist/ instead of src/tests/scripts.
  • .gitignore — ignore generated dist/.

Verification

  • Packed tarball with only the 4 WASM deps installed loads all 408 operations and runs both non-WASM ops (Base64) and WASM-backed ops (YARA Rules, confirmed match).
  • Bundle output matches source for sampled operations (Base64, To Hex, ROT13, URL Encode, Base32).
  • The 3 pre-existing crypto-api test failures (analyzeHash, HMAC, Snefru) and the MD5/SHA2 has160 resolution issue exist identically on masternot introduced by this change.

Notes / follow-ups

  • The ~30M tesseract.js OCR closure is the largest remaining external. If OCR isn't required downstream, dropping it would shrink the external closure further — separate change.
  • Ref: INT-2071 (build-time ncc bundling investigation).

Installing cyberchef-node currently unpacks a very large node_modules
tree (~16k files). On network-backed disks the per-file round-trips
dominate install time (installs of consuming integrations have been
observed at ~9 min). Bundle the pure-JS runtime dependencies into a
single file with @vercel/ncc so the published package ships ~11 files
instead of thousands, cutting the shipped file count by ~98% with no
change in behavior.

- Add scripts/bundle.js: runs ncc against the generated
  src/node/index.js, emitting dist/index.js (+ lazy chunks). WebAssembly
  packages (tesseract.js, tesseract.js-core, libyara-wasm,
  libbzip2-wasm, argon2-browser) cannot be inlined by ncc/webpack, so
  they are kept external and remain the package's only runtime
  dependencies.
- package.json: point main at dist/index.js; split build into
  generate + bundle; add prepack so the bundle is produced automatically
  on npm pack/publish (release workflow needs no change). Move the now
  inlined runtime deps to devDependencies; only the WASM packages remain
  in dependencies.
- package-lock.json: regenerated. The full dependency graph is preserved
  (378 packages before and after) so security scanning against the
  lockfile is unaffected; deps only move between dependencies and
  devDependencies.
- .npmignore: publish dist/ instead of src/tests/scripts.
- .gitignore: ignore generated dist/.

Verified: the packed tarball with only the 4 WASM deps installed loads
all 408 operations and runs both non-WASM and WASM-backed ops (YARA);
bundle output matches source for sampled operations. Pre-existing
crypto-api resolution failures (MD5/SHA2) are unchanged by this commit.
@collin-rogers
collin-rogers requested a review from sarus July 8, 2026 19:40
@collin-rogers

Copy link
Copy Markdown
Author

This pr is a precursor to the work to be done for INT-2074

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.

1 participant