fix(build): resolve vendored blessed requires - #1521
Open
John-David Dalton (jdalton) wants to merge 1 commit into
Open
fix(build): resolve vendored blessed requires#1521John-David Dalton (jdalton) wants to merge 1 commit into
John-David Dalton (jdalton) wants to merge 1 commit into
Conversation
The published package shipped bare require('blessed/...') calls in
external/blessed-contrib/lib/widget/{table,charts/bar,charts/line}.js and
external/blessed/vendor/tng.js. Node resolves bare specifiers only through
node_modules, and external/ is not one, so `socket threat-feed` crashed on
launch with "Cannot find module 'blessed/lib/widgets/box'". `socket
analytics` and `socket audit-log` load the same widgets.
copyExternalPackages() already rewired those requires, but it runs in the
first config's writeBundle, and the blessed-contrib configs then bundle
back out over the same files with 'blessed' marked external. Give that
bundle its own rewrite so the emitted requires are relative when written,
and widen the copy pass to blessed's own tree so vendor/tng.js is covered.
Adds a test over the built external/ tree, scoped to the packages the
build vendors there.
Refs SURF-1445, SURF-1639
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
socket threat-feedcrashes the moment it draws its table, on every run, for everyone, dying withCannot find module 'blessed/lib/widgets/box'. It is present in 1.1.160 and in the currentlatest, 1.1.162, andsocket analyticsandsocket audit-logload the same widgets.Why the module is unreachable
The published package ships
blessedatexternal/blessed/, but four vendored files still ask for it by its bare name. Node only resolves a bare name likeblessed/lib/widgets/boxby walking up throughnode_modulesdirectories.external/is not one, andexternal/blessedhas nopackage.json, so the module cannot be found even though the file is sitting right there on disk.Why the existing rewrite did not catch it
copyExternalPackages()already rewrites these requires to relative paths. It just runs too early to matter.The dist config exports an array of rollup configs, and rollup runs them in order:
src/intodist/. ItswriteBundlehook callscopyExternalPackages(), which rewritesrequire('blessed/…')to a relative path acrossexternal/blessed-contrib/**/*.js.src/external/blessed-contrib/**/*.mjsstraight back out to those same files. They markblessedasexternal, so the requires they emit stay bare, and they carry no rewrite of their own.Step 2 lands on top of step 1's work. The rewrite happens, then gets overwritten.
Separately, the rewrite globs with
cwd: blessedContribPath, so it never looks inside blessed itself. That is whyexternal/blessed/vendor/tng.jskeeps its barerequire('blessed/lib/colors').What changed
socketModifyPlugin, so the requires it emits are already relative at the moment they are written and there is nothing left to clobber. The plugin runs inrenderChunk, on final emitted code, and computes the relative path from that specific output file's depth.copyExternalPackages()now walks blessed's own tree as well as blessed-contrib's, which coversvendor/tng.js.newBareBlessedRequireRegExp()hands back a fresh regexp per call, becausesocketModifyPluginadvanceslastIndexand a shared instance would let chunks skip each other's matches.relativeBlessedPath()falls back to'.'so a file sitting in blessed's own root cannot produce an absolute-looking specifier.The four files, and the new guard
Scanning the shipped 1.1.162 tarball turns up eight bare requires across four files:
test/external-bare-requires.test.mtswalks the builtexternal/tree and fails on any bare require of a package the build vendors there. Run against 1.1.162 its rule reports exactly those eight and nothing else.It is deliberately scoped to the three names in
EXTERNAL_PACKAGESrather than to "any undeclared package". Widening it that far also picks upbraces,micromatch,picomatchandnode-gypunderexternal/@socketsecurity/registry/, pluspty.jsandterm.jsfrom blessed's optional terminal widget. Those are longstanding and unrelated to this crash, and they deserve their own look rather than being swept in here.Known gap
The crash tears down the alt screen without restoring terminal state, leaving a one-line scroll region and the tty in raw mode until the user runs
reset. That is a separate cleanup bug that outlives any require-path fix, and it is not addressed here.Refs SURF-1445, SURF-1639.
Note
Medium Risk
Changes published packaging and module resolution for vendored TUI dependencies; impact is broad for blessed-based commands but scoped to build output with a regression test.
Overview
Fixes runtime
Cannot find module 'blessed/…'crashes when TUI commands (e.g. threat-feed) render tables, because vendored files underexternal/still used bareblessedspecifiers that Node cannot resolve there.The dist build now rewrites those requires in two places that actually stick:
copyExternalPackages()walksblessedas well asblessed-contrib, and the blessed-contrib Rollup bundle gets asocketModifyPluginso emittedrequire('blessed/…')become relative paths at write time instead of being overwritten by a later bundle pass. Shared helpersnewBareBlessedRequireRegExp()andrelativeBlessedPath()avoid regexplastIndexbugs and edge cases at blessed’s root.Adds
test/external-bare-requires.test.mts, which fails if builtexternal/**/*.jsstill bare-requiresblessed,blessed-contrib, or@socketsecurity/registry.Reviewed by Cursor Bugbot for commit 668365a. Configure here.