remove absolute file paths embedded in sourcemaps generated by `SourceMapPlugin`

Aberta
#1,518 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
50/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
typescript, webpack
Domínio
build-system

Direção de pesquisa

Start in packages/repack/src/plugins/SourceMapPlugin.ts, where module names are built into the source map's sources (around lines 92-95) and where the commented-out read of output.devtoolModuleFilenameTemplate sits (around lines 107-108). Check how compiler.options.context is available there and whether the webpack config can be exercised with a small production build. Done means the emitted map no longer contains machine-specific absolute paths, either by honoring the template or by defaulting to paths relative to the context. Agreeing on which of the two options to take first is likely needed with a maintainer.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

status:new type:feature
Description

When building without a dev server (e.g. a release bundle built in CI), SourceMapPlugin names every module in the source map's sources by its absolute path on the build machine, and there's no way to override this.

https://github.com/callstack/repack/blob/171e3ec6e8011db0a756d19e1d806d512982c93c/packages/repack/src/plugins/SourceMapPlugin.ts#L92-L95

RepackPlugin always applies SourceMapPlugin, and SourceMapPlugin ignores output.devtoolModuleFilenameTemplate (the line that would read it is commented out)

Why this is a problem

The source map ends up depending on where the build ran, not just on its inputs:

  • Non-reproducible builds. On remote-execution or sandboxed build systems (Bazel, Buck, etc.) the absolute path includes a per-job working directory, so the same commit yields a different map on each worker:
    /mnt/ci/worker/7/exec/bazel-out/<config>/bin/<target>.runfiles/<workspace>/node_modules/react-native/Libraries/Components/Pressable/Pressable.js
    
  • Error-reporting tools show machine-specific paths. Sentry and similar tools display these paths as frame filenames. Because the prefix changes between builds, a single code mapping (stack trace → repository) can't cover them.

The web-oriented default, webpack://[namespace]/[resourcePath], has none of these problems because [resourcePath] is relative to context.

Suggested solution
  1. Honor output.devtoolModuleFilenameTemplate when set, falling back to the current behavior otherwise. This seems to be what the commented-out code intended or
  2. Default to paths relative to compiler.options.context for production builds. That keeps the map reproducible, and tools can still resolve files by joining with the project root.
Additional context

No response

Linguagem predominante
TypeScript
Estrelas
1.9k
Forks
177
Merge médio
2d 10h
PRs com merge (30d)
23

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de callstack/repack

Todas as issues de callstack/repack

Issues semelhantes

Mais issues de TypeScript

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.