Repository navigation
Conversation
nodejsGuessRegexps decided whether the bare imports search runs at all, but
its third pattern only matched string literals, so dependencies spelled with
template literals (require(`pkg`), import(`pkg`)) were never detected:
GuessWithCache skipped the search when hashImports returned empty, leaving
the project with zero dependencies.
Match backticks alongside single/double quotes (\x60, since backticks cannot
appear in raw string literals). Template substitutions are still excluded by
the existing \{\} exclusion, so require(`pkg-${v}`) is not a false
dependency.
Adds regex-level and end-to-end GuessWithCache regression tests (both fail
before the fix, pass after). Does not touch the tree-sitter query, which
already handles backtick call arguments.
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.
UPM's Node.js dependency detection uses
nodejsGuessRegexpsto determine whether the bare-import scan should run. The existing pattern recognized module specifiers enclosed in single or double quotes, but did not recognize backtick-delimited template literals.For example:
If a project referenced its dependencies only through this syntax, the initial import detection could return no matches. Since
GuessWithCachemay skip the bare-import scan when no imports are detected, the dependency could be missed entirely.What changed
require(...)and dynamicimport(...)calls to recognize static module specifiers enclosed in backticks, in addition to single and double quotes.require(\pkg-${version}`)`, because their module names cannot be determined statically.NodejsNPMBackend.Guessandstore.GuessWithCache, ensuring that a dependency referenced through backticks is detected even when it is the project's only dependency.Test plan
The added regression tests cover the following scenarios:
TestNodejsGuessRegexps— verifies supported import syntaxes and ensures interpolated templates are not treated as static dependencies.TestNodejsGuessBacktickImports— verifies that the Node.js backend detects a dependency referenced through a backtick-delimitedrequire()call.TestNodejsGuessWithCacheBacktickImports— verifies that the dependency remains detectable through the cached guessing flow when it is the project's only dependency.