Skip to content

Commit b4071ef

Browse files
roli-lpciclaude
andauthored
chore(remix): Replace glob with native recursive fs walk (#19531)
Replaces the `glob` dependency in `@sentry/remix` with a simple recursive `fs.readdirSync` walk for finding `.map` files to delete after source map upload. - [x] If you've added code that should be tested, please add tests. - [x] Ensure your code lints and the test suite passes (`yarn lint`) & (`yarn test`). - [ ] Link an issue if there is one related to your pull request. If no issue is linked, one will be auto-generated and linked. Ref #19447 ## What this does Replaces `glob.sync('**/*.map', { cwd: buildPath })` in `deleteSourcemaps.js` with a manual recursive directory walk using native `fs.readdirSync`. This removes the `glob` package and its transitive dependency tree (minimatch, brace-expansion, balanced-match, minipass, jackspeak, path-scurry, foreground-child) from `@sentry/remix`. Also cleans up orphaned `glob`/`jackspeak`/`path-scurry` resolution overrides in the integration test `package.json`. ## Why manual recursion instead of `fs.readdirSync({recursive: true})` `fs.readdirSync(dir, { recursive: true, withFileTypes: true })` silently drops entries on Node 18.17-18.18 due to a known Node.js bug. Since `@sentry/remix` supports Node >= 18, a manual recursive walk avoids this edge case entirely. ## Behavioral notes - The walk returns relative paths from `buildPath`, matching `glob.sync`'s `{ cwd }` output shape - Non-existent directories return `[]` gracefully (matching glob behavior) - The walk includes dotfiles (glob excludes by default with `dot: false`), but this has zero practical impact since Remix build output never produces `.map` dotfiles Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent cac4c46 commit b4071ef

File tree

3 files changed

+38
-6
lines changed

3 files changed

+38
-6
lines changed

packages/remix/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
"@sentry/core": "10.45.0",
7373
"@sentry/node": "10.45.0",
7474
"@sentry/react": "10.45.0",
75-
"glob": "^13.0.6",
7675
"yargs": "^17.6.0"
7776
},
7877
"devDependencies": {

packages/remix/scripts/deleteSourcemaps.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,49 @@
22
const fs = require('fs');
33
const path = require('path');
44

5-
const { globSync } = require('glob');
5+
/**
6+
* Recursively walks a directory and returns relative paths of all files
7+
* matching the given extension.
8+
*
9+
* Uses manual recursion instead of `fs.readdirSync({ recursive: true, withFileTypes: true })`
10+
* to avoid a bug in Node 18.17–18.18 where `withFileTypes` returns incorrect `parentPath` values
11+
* when combined with `recursive: true`.
12+
*
13+
* @param {string} rootDir - The root directory to start walking from.
14+
* @param {string} extension - The file extension to match (e.g. '.map').
15+
* @returns {string[]} Relative file paths from rootDir.
16+
*/
17+
function walkDirectory(rootDir, extension) {
18+
const results = [];
19+
20+
function walk(dir) {
21+
let entries;
22+
try {
23+
entries = fs.readdirSync(dir, { withFileTypes: true });
24+
} catch {
25+
return;
26+
}
27+
28+
for (const entry of entries) {
29+
const fullPath = path.join(dir, entry.name);
30+
31+
if (entry.isDirectory()) {
32+
walk(fullPath);
33+
} else if (entry.name.endsWith(extension)) {
34+
results.push(path.relative(rootDir, fullPath));
35+
}
36+
}
37+
}
38+
39+
walk(rootDir);
40+
return results;
41+
}
642

743
function deleteSourcemaps(buildPath) {
844
console.info(`[sentry] Deleting sourcemaps from ${buildPath}`);
945

1046
// Delete all .map files in the build folder and its subfolders
11-
const mapFiles = globSync('**/*.map', { cwd: buildPath });
47+
const mapFiles = walkDirectory(buildPath, '.map');
1248

1349
mapFiles.forEach(file => {
1450
fs.unlinkSync(path.join(buildPath, file));

packages/remix/test/integration/package.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@
3939
"@vanilla-extract/css": "1.13.0",
4040
"@vanilla-extract/integration": "6.2.4",
4141
"@types/mime": "^3.0.0",
42-
"@sentry/remix/glob": "<10.4.3",
43-
"jackspeak": "<3.4.1",
44-
"**/path-scurry/lru-cache": "10.2.0",
4542
"vite": "^6.0.0"
4643
},
4744
"engines": {

0 commit comments

Comments
 (0)