bug: additionalFiles copies ../ matches outside the build on Windows

Aperta
#5,074 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #5075 di @SimoMay — chiusa senza merge

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
node.js, typescript
Ambito
build-system

Direzione di ricerca

Start with packages/build/src/internal/copyFiles.ts and inspect findFilesByMatchers, focusing on how relative() paths are split and joined. Use the included path.win32 reproduction to confirm the Windows behavior, then verify the destination resolves to <build>/shared/a.md on both Windows and POSIX paths. A linked pull request, #5075, already addresses this issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Provide environment information

  • OS: Windows (fails); macOS and Linux are not affected
  • trigger.dev CLI and @trigger.dev/build: 4.5.16
  • The same code is in 4.8.1 and on main

Describe the bug

additionalFiles is meant to strip leading .. segments so that a pattern like ../shared/** copies files inside the build output. On Windows the segments are not stripped, and the files are copied outside the build directory. The deploy goes ahead without them.

The cause is findFilesByMatchers in packages/build/src/internal/copyFiles.ts:

const pathInsideDestinationDir = relative(cwd, file)
  .split(posix.sep)
  .filter((p) => p !== "..")
  .join(posix.sep);

On Windows, relative() returns a backslash path (..\shared\a.md). Splitting on / gives one segment, so no .. is removed, and join(destinationDir, "..\shared\a.md") resolves outside the build directory, one level up for each ...

Expected: the files land at <build>/shared/a.md on every OS, as they do on macOS and Linux.

Reproduction repo

No repo needed. The Node script below runs the same path logic with path.win32, on any OS.

To reproduce

const { win32, posix } = require("node:path");
const cwd = "C:\\repo\\app";
const file = "C:\\repo\\shared\\a.md";
const dest = "C:\\repo\\app\\.trigger\\tmp\\build-x";

const inside = win32.relative(cwd, file).split(posix.sep).filter((p) => p !== "..").join(posix.sep);
console.log(win32.join(dest, inside));
// C:\repo\app\.trigger\tmp\shared\a.md   <- outside build-x

End to end, on Windows:

  1. In a project one level below the repo root, add additionalFiles({ files: ["../shared/**"] }) to trigger.config.ts.
  2. Run npx trigger.dev deploy.
  3. The deployed image has no shared/ folder. The same deploy from macOS includes it.

A task that reads one of those files at runtime then fails with a missing file.

Suggested fix

Split on the platform separator, and keep joining with / (join accepts it on Windows):

const pathInsideDestinationDir = relative(cwd, file)
  .split(sep)
  .filter((p) => p !== "..")
  .join(posix.sep);

With path.win32 and path.posix, both resolve to <build>/shared/a.md. A PR with this change follows.

Lingua principale
TypeScript
Stelle
16.5k
Fork
1.5k
Merge medio
1g 15h
PR unite (30g)
17

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di triggerdotdev/trigger.dev

Tutte le issue di triggerdotdev/trigger.dev

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.