-
-
Notifications
You must be signed in to change notification settings - Fork 41
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
feat(netlify): support included/excluded files #325
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 1a2319f The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/netlify/src/ssr-function.ts
Outdated
return async function handler(request: Request, context: Context) { | ||
// This entrypoint will be deep inside the directory structure below cwd | ||
// We chdir to the root so that we can resolve the correct paths at runtime | ||
process.chdir(root); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we sure it can't break any existing app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can work out, existing apps that rely on cwd would either have unchanged behaviour (if they're not a monorepo), or would already be broken (if they are using a monorepo)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what the "correct paths at runtime" refers to here. It feels dangerous to call chdir()
as a request handler. Can you explain where is resolving from the cwd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a site uses filesystem functions at runtime, this is the only way it can correctly load the files
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think using filesystem functions is something Astro supports in the runtime? Files could be moved during bundling and it wouldn't work later.
Is process.chdir()
needed for this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't prevent people using fs functions, so I'd imagine lots of people do. This PR was prompted by an issue where a library was trying to load i18n data and it wasn't found. This part fixes precisely that issue: of files being moved during bundling. Without that there's not a lot of point to allowing users to include files in the bundle, because the user code won't be able to find them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't feel like fs functions are a common thing especially when dealing in a bundled runtime. There's Vite APIs like import.meta.glob
, ?url
, and ?raw
for them. Fs functions are also likely to fail elsewhere than only on Netlify, and so we shouldn't support and encourage them.
I figured the benefit with includeFiles
and excludeFiles
are like Vercel's option, because nft has trouble sometimes detecting every file. Especially inside node_modules where libraries use fs relatively, those code are not processed by Vite so we could use the option for them, however if they resolve relatively I'm not sure how cwd helps here. And if the library do resolve from cwd, it would've been generally a problem if an Astro is also hosted on a subdirectory or any other fine setup.
I'm not really comfortable with keeping this in the adapter. It feels surprising to me that it could change the cwd internally and on every request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are like Vercel's option. In fact they use almost the same implementation. With libraries that use fs functions, they usually accept a directory as an option or resolve relative to cwd. It's very common for i18n libraries such as i18next, for example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're about to do a major I can do a breaking changeset for the chdir part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks super helpful, @ascorbic and the docs are fabulous!
Just a couple of quick thoughts mostly on formatting.
(In particular, we do tend to use inline code when naming a feature, not quotation marks. And both inline AND quotation marks are reserved for when that's how the feature would be shown in the reader's code (e.g. output: 'server'
. (Though, we're more relaxed with hybrid
and server
just written on their own.)
Otherwise, great intro, great explanation, and helpful code example. What more could I possibly want? 😄
Co-authored-by: Sarah Rainsberger <[email protected]>
!preview include-files |
Snapshots have been released for the following packages:
Publish Log
Build Log
|
@ascorbic Do you want to land this before the next minor of the Netlify Adapter? |
@alexanderniebuhr Ideally, yes. It's still waiting on an approval |
I already looked at it and quite liked it, but I can review it later today, so we can land it before we cut the release :) |
Co-authored-by: Bjorn Lu <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I miss specific platform knowledge but I like the feature and implementation looks good and has tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just left a suggestion of a more compact style, if you'd like one!
Co-authored-by: Sarah Rainsberger <[email protected]>
I was not able to wait for this PR to make it into the release, I needed to ship Cloudflare bugfixes.. Are all discussions resolved? |
The changeset is fine by docs, but we will need documentation in the Netlify adapter page in docs. A new As Matt wrote, it can take very much the form of what's in the changeset, plus any other important characteristics to document (because I said the changeset doesn't have to be exhaustive -- but there may be other details appropriate for full documentation). |
74fcbdb
to
5570bdf
Compare
!preview include-files |
Snapshots have been released for the following packages:
Publish Log
Build Log
|
Changes
Adds "includedFiles" and "excludedFiles" options. These allow extra files to be deployed in the SSR function bundle. It globs these files at build time, and includes them in the file list that is deployed in the function. This PR also ensures that process.cwd matches the site root during SSR.
Testing
Adds new test fixture and tests.
Docs
This needs docs. The changeset includes a lot of the required info, as do the types.