fix: do not glob from the filesystem root - #609
Conversation
140a777 to
0bc03e1
Compare
…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
left a comment
There was a problem hiding this comment.
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.
A string like
`/${dir}/routes`reachesemitAssetPathas/<*>/routes. On POSIX the parent is''and the stat fails. On Windows it resolves toD:\<*>\routes, the parentD:exists, and nft globsD:/**/*/routes, the entire drive.The "do not emit directories above
__dirname" rule invalidWildcardonly 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.jstraces the fixture withbaseset to the filesystem root; the unit harness skips itsbase: '/'variant on Windows. Seen in the wild via sveltejs/kit#16963.