Skip to content

RUM-12185: Support aliased import paths for local SVG discovery - #1352

Open
jonathanmos wants to merge 1 commit into
developfrom
jmoskovich/rum-12185/support-alias-paths
Open

RUM-12185: Support aliased import paths for local SVG discovery#1352
jonathanmos wants to merge 1 commit into
developfrom
jmoskovich/rum-12185/support-alias-paths

Conversation

@jonathanmos

@jonathanmosjonathanmos commented Jul 28, 2026

Copy link
Copy Markdown
Member

What does this PR do?

Adds support for resolving aliased local SVG imports during Session Replay asset discovery.

Supports TypeScript/JavaScript path mappings and babel-plugin-module-resolver, including .babelrc, function-form plugin configurations, and Windows paths. Includes regression coverage for the supported configurations.

Before
Screenshot 2026-07-28 at 16 24 52

After
Screenshot 2026-07-28 at 16 36 24

Motivation

What inspired you to submit this pull request?

Additional Notes

Anything else we should know when reviewing?

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests
  • Make sure you discussed the feature or bugfix with the maintaining team in an Issue
  • Make sure each commit and the PR mention the Issue number (cf the CONTRIBUTING doc)
  • If this PR is auto-generated, please make sure also to manually update the code related to the change

@datadog-prod-us1-5

datadog-prod-us1-5Bot commented Jul 28, 2026

Copy link
Copy Markdown

Tests

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🔄 Datadog auto-retried 5 jobs - 4 passed on retry View in Datadog

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ffa6d6f | Docs | Datadog PR Page | Give us feedback!

@jonathanmos
jonathanmosforce-pushed the jmoskovich/rum-12185/support-alias-paths branch from 1a97eab to ffa6d6fCompareJuly 28, 2026 12:21
@jonathanmos
jonathanmos requested a review from CopilotJuly 28, 2026 12:21

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support for resolving aliased local .svg imports during Session Replay asset discovery, so ReactNativeSVG.buildSvgMap() can map SVG components even when imports use TS/JS path mappings or babel-plugin-module-resolver.

Changes:

  • Introduces PathAliasResolver to resolve non-relative SVG import specifiers via babel-plugin-module-resolver and tsconfig.json/jsconfig.jsonpaths.
  • Updates ReactNativeSVG.buildSvgMap() to use the resolver (and reset cached alias config between runs).
  • Adds regression tests and a benchmark scenario exercising aliased SVG imports.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
yarn.lockAdds lock entries for tsconfig-paths and babel-plugin-module-resolver (and transitive deps).
packages/react-native-babel-plugin/test/react-native-svg.test.tsAdds coverage for alias resolution via tsconfig/jsconfig + babel-module-resolver, and precedence/fallback behavior.
packages/react-native-babel-plugin/src/libraries/react-native-svg/pathAliasResolver.tsNew resolver implementing alias lookup via Babel partial config + tsconfig-paths.
packages/react-native-babel-plugin/src/libraries/react-native-svg/index.tsWires alias resolution into buildSvgMap() via resolveImportSource().
packages/react-native-babel-plugin/package.jsonAdds tsconfig-paths dependency and babel-plugin-module-resolver devDependency.
benchmarks/src/scenario/SessionReplay/component/Svg.tsxAdds an aliased SVG import case (Group H) to the benchmark test screen.
benchmarks/package.jsonAdds babel-plugin-module-resolver for the benchmark app.
benchmarks/babel.config.jsConfigures module-resolver alias used by the benchmark aliased SVG case.

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

@jonathanmos
jonathanmos marked this pull request as ready for review July 28, 2026 14:37
@jonathanmos
jonathanmos requested a review from a team as a code ownerJuly 28, 2026 14:37
@jonathanmos
jonathanmos requested a review from cdn34ddJuly 28, 2026 14:38
Comment on lines 50 to 67
@@ -60,6 +61,7 @@
"@swc/core": "^1.13.21",
"@swc/jest": "^0.2.38",
"@types/jest": "^30.0.0",
"babel-plugin-module-resolver": "^5.0.2",
"jest": "^29.7.0",
"react-native-builder-bob": "0.26.0",
"tsc-alias": "^1.8.16",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We're adding new dependencies, make sure these are listed here: LICENSE-3rdparty.csv

"@swc/core": "^1.13.21",
"@swc/jest": "^0.2.38",
"@types/jest": "^30.0.0",
"babel-plugin-module-resolver": "^5.0.2",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

"babel-plugin-module-resolver": "5.0.2",

SInce the benchmark already uses this dependency, we should also use "5.0.2" here (remove the ^) as leaving it there could lead to duplicate dependencies. EX:. 5.0.2 and 5.0.3

Comment on lines +111 to +113
if (!resolved || !isRelativePath(resolved)) {
return null;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What about absolute paths ? (probably not common), but maybe computed paths should be handled, check the Metro example above ?

Comment on lines 162 to 165
const source = path.node.source?.value;
if (!source?.endsWith('.svg')) {
return;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I believe this may not work, if we have something like this:

alias: {
'@logo': './src/assets/logo.svg'
}

and then import it like so:

import Logo from '@logo';

There won't be an .svg in the import statement.

Comment on lines +41 to +48
* Resolves non-relative import specifiers (e.g. `@components/Logo`) against a
* project's `babel-plugin-module-resolver` config and/or its
* `tsconfig.json`/`jsconfig.json` `paths` mapping, so aliased local SVG
* imports can be found on disk the same way they resolve at runtime.
*
* Callers should still fall back to plain relative resolution when this
* returns `null` -- that covers projects that don't use any aliasing.
*/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

What about those set in the metro resolver config, do we support them ?

//(...)
resolver: {extraNodeModules: {'@assets': path.resolve(__dirname,'src/assets')}}//(...)

Sign up for freeto 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.

3 participants

@jonathanmos@cdn34dd