fix(unused-deps): credit node:module register() loader specifiers (#293)#296
Merged
BartWaardenburg merged 1 commit intofallow-rs:mainfrom May 6, 2026
Conversation
Closes fallow-rs#293. `register('@swc-node/register/esm', pathToFileURL('./'))` from `node:module` loads a loader module by specifier rather than via a static or dynamic `import`. Without recognising this hook the loader package is reported as an unused (dev-)dependency. The visitor now records the first argument of `register(...)` as a `DynamicImportInfo` when the callee resolves to the `register` export of `node:module` (or `module`). Both forms are matched: import { register } from 'node:module'; register('@swc-node/register/esm', pathToFileURL('./')); import * as Module from 'node:module'; Module.register('tsx/esm', import.meta.url); Aliased named imports (`register as registerLoader`) work too. Calls to unrelated `register(...)` functions are left untouched.
54ecfef to
0aa047c
Compare
BartWaardenburg
added a commit
that referenced
this pull request
May 6, 2026
Reflect the broader implementation that landed in #296: vehicle switched from require_calls to dynamic_imports, namespace-import and template-literal first-arg forms now engage, helper renamed.
Collaborator
|
Thanks @ChrisJr404, this is a nicer take than my earlier patch — the namespace-call shape ( |
Collaborator
|
Released in v2.66.1. Thanks @ChrisJr404. |
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.
Closes #293.
Problem
The visitor currently treats packages loaded via Node's
registerhook as unused. The OP's repro:fallow dead-codeflags@swc-node/registeras unused even though it is loaded by specifier at runtime.Fix
When a
register(...)call is bound to theregisterexport ofnode:module(or the unprefixedmodule), record the first-argument specifier as aDynamicImportInfo. The graph layer already credits the resolving package viaResolveResult::NpmPackage, so@swc-node/register/esmflows back to@swc-node/registerinpackage.json.Recognised forms:
Unrelated
register(...)functions imported from anything other thannode:moduleare not affected. Non-string first arguments (register(loaderUrl, ...)) are also ignored, matching how the visitor handlesimport(variable).Tests
crates/extract/src/tests/js_ts/dynamic_imports.rscovering named + aliased + namespace forms, the unprefixedmodulespecifier, template-literal first-argument, the negative case (registerfrom another module is not credited), and the dynamic-first-argument case (no entry recorded).crates/core/tests/integration_test/false_positive_fixes.rsreproducing the OP's setup end-to-end and asserting@swc-node/registeris not inunused_dev_dependencies.Full suites green locally:
cargo test -p fallow-extract --lib— 1399 passed.cargo test -p fallow-core --test integration_test false_positive_fixes— 16 passed.cargo test -p fallow-cli --bin fallow— 1755 passed.Notes
vi.mockandcustomElements.defineare handled).vitest_mock_source/extract_custom_elements_definestyle: a small free helper for the specifier extraction plus a method onModuleInfoExtractorfor the import-binding lookup.