Skip to content

fix: do not glob from the filesystem root - #609

Open
Nic-Polumeyv wants to merge 1 commit into
vercel:mainfrom
Nic-Polumeyv:root-wildcard-glob
Open

fix: do not glob from the filesystem root#609
Nic-Polumeyv wants to merge 1 commit into
vercel:mainfrom
Nic-Polumeyv:root-wildcard-glob

Conversation

@Nic-Polumeyv

@Nic-Polumeyv Nic-Polumeyv commented Aug 27, 2026

Copy link
Copy Markdown

A string like `/${dir}/routes` reaches emitAssetPath as /<*>/routes. On POSIX the parent is '' and the stat fails. On Windows it resolves to D:\<*>\routes, the parent D: exists, and nft globs D:/**/*/routes, the entire drive.

The "do not emit directories above __dirname" rule in validWildcard only handled a trailing wildcard; it now checks the directory the wildcard sits in, which covers this and any other glob rooted at an ancestor of the importing file.

test/wildcard-root.test.js traces the fixture with base set to the filesystem root; the unit harness skips its base: '/' variant on Windows. Seen in the wild via sveltejs/kit#16963.

@Nic-Polumeyv
Nic-Polumeyv requested review from a team, icyJoseph, ijjk and styfle as code owners August 27, 2026 23:49
Rich-Harris pushed a commit to sveltejs/kit that referenced this pull request Aug 28, 2026
…dows (#16972)

`create_function_bundle` traces with `base` set to the filesystem root.
nft treats any absolute-looking string with a dynamic segment as an
asset glob, and the server output has URL strings like

```js
`/${app_dir}/routes${route_id}`   // runtime/pathname.js
```

On Linux this resolves to `/<*>/routes`, the parent directory is `''`,
the stat fails and nothing happens. On Windows it resolves to
`D:\<*>\routes`, the parent `D:` stats fine, and nft runs
`glob('D:/**/*/routes')` over the whole drive, which never finishes once
it hits `pagefile.sys`.

nft also evaluates `process.cwd()` as `base` unless told otherwise, so
`path.join(process.cwd(), 'asset.txt')` was traced from `/` and never
bundled.

nft calls `ignore` with the glob relative to `base` before walking, and
a base-rooted glob is `**\*\routes`. The cwd case has a regression test;
the root-glob case can't fire on Linux for the reason above.

Fixes #16963. Supersedes #16964. Related: vercel/nft#609.

@ijjk ijjk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a breaking change. base and ignore already let callers define the permitted tracing boundary. A caller that sets base to the filesystem root is explicitly allowing files beneath that root, and may rely on inferred wildcards being traced there.

This patch adds a new global restriction based on the importing file’s directory, causing previously included files to be silently excluded despite being within base. The reported case should be handled by giving nft the intended project/common-ancestor base, or by excluding root-wide globs through ignore, as SvelteKit has done. I don’t think validWildcard should override existing caller configuration; otherwise this needs to be treated and documented as a breaking change.

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

2 participants