-
Notifications
You must be signed in to change notification settings - Fork 136
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to allow app directory globs from packages #77
Comments
I never really understood why the package boundary was necessary. This was something @guybedford was very keen on adding. It also matches the behavior of ncc. However, I don't understand how your two examples are outside the package boundary? Perhaps you could add a unit test to show it fail for your use case? |
The actual case where I ran into it was:
NFT recognizes the reads in Code for the handler where it stats the chunk dir (which should cause a glob include of all files since it's a directory): https://github.com/azukaru/progressive-fetching/blob/bcc665cbf30934d3570c20d18c7860c658fe40b2/packages/next-dynamic-bundle/src/handler.ts#L20 |
The line you linked to is reading a dynamic path |
I tried a couple of variants. Debugging with the CLI directly showed that the glob is being done but then it is followed by "Ignoring X because it is outside of the package". So I'm pretty sure it's finding the assets successfully. |
Have you tried setting the You could potentially allow everything with const { fileList } = await nodeFileTrace(files, {
base: '/'
} https://github.com/zeit/node-file-trace/blob/master/readme.md#base |
The issue is that |
That condition can be changed to something more appropriate. The main thing it's trying to protect against is an invalid analysis inadvertantly globbing all of node_modules and defeating the point of tracing. So it's very much about balancing those things. I'm not sure the best way to extend / adjust the logic here, it may come down to some trial and error on the analysis paths as well. |
Suggestion for a revised logic: If the path starts with the overall |
The specific case to be weary of is The My concern is any logic to relax this will let the problematic case slip through. |
I think the specific hole I'd like to punch is: Allow a glob relative to the project directory that "definitely" (minus symlinks) doesn't include To elaborate on my proposal, in semi pseudo code: if (pkgBase) {
const nodeModulesBase = id.substr(0, id.indexOf(path.sep + 'node_modules')) + path.sep + 'node_modules' + path.sep;
if (!assetPath.startsWith(nodeModulesBase)) {
// Allow after all if it's an app-level glob
const appSubGlob = assetPath.substr(base.length + 1);
const segments = appSubGlob.split(path.sep);
if (
!assetPath.startsWith(base) ||
segments.length < 2 ||
isGlobOrNodeModules(segments[0])
) {
return false;
}
}
} |
Yes that sounds like it would work! If we can guarantee that whatever is being dived into is not a Note the other thing to still be weary of is backtracking below the base (security risk), but that is still covered if there is a change of logic to this part since that check happens earlier I believe. You happy to go ahead with a PR there further? |
May find some time to get a PR together for this. Thanks for the buddy-check on the overall approach! |
I also would like this feature. Blitz framework code (inside node_modules) is reading config files in the app directory at runtime. Currently that is not detected by NFT and the config files are eliminated. |
For things like automatic loading of translation files, it may be nice to allow globs of files even when they are not within the package boundary. Right now the following fails if it's part of a module:
In my specific case, I was also interested in having an installed module be able to preserve a directory by doing:
But there may be more examples, like automatically loaded config files from the app/working directory.
The text was updated successfully, but these errors were encountered: