-
Notifications
You must be signed in to change notification settings - Fork 176
add new feature in config for copying files to a specified server function after the build is done #807
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
Conversation
|
commit: |
export function copyCustomFiles(copyFiles: CopyFile[], outputPath: string) { | ||
copyFiles.forEach(({ srcPath, dstPath }) => { | ||
// Find all files matching the pattern | ||
const matchedFiles = globSync(srcPath, { |
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.
would that work with "relative" files?
and relative to what?
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.
would that work with "relative" files?
and relative to what?
yeah, and by default its relative to process.cwd()
. perhaps i should change that in-case you are in a monorepo.
"another-filedsfdsf.txt": "another content", | ||
}, | ||
"empty-file.txtfdsf": "", | ||
"imporant-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.
"imporant-files": { | |
"important-files": { |
return; | ||
} | ||
|
||
if (matchedFiles.length === 1) { |
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 I want to copy *.js
to /some/path
, will be behavior be different if there is one vs multiple files? (if yes, that does not sound right)
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 I want to copy
*.js
to/some/path
, will be behavior be different if there is one vs multiple files? (if yes, that does not sound right)
yeah your correct about that one. after some more thought i should probably think about a better way to handle this. im open for suggestions.
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.
One way to handle that could be to have exclusive dstFile
(error on multiple match) and dstDir
options
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.
Also I am not sure what use case you are solving with this PR. Maybe having a hook accepting a function taking the buildOptions as a parameter could be good enough - that would mean the options are part of the API and must be documented and ~stable.
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.
One way to handle that could be to have exclusive
dstFile
(error on multiple match) anddstDir
options
thats a good idea. probably something I would go for if we choose to proceed with this PR.
Also I am not sure what use case you are solving with this PR
the idea was that sometimes you need or want a file that's not there. we've had a few cases where people were missing a file in the server function's output. i.e this discord thread
however, if you guys think this wont be needed i can close it. Next does have outputFileTracingIncludes
which probably might be enough for most cases anyways.
Maybe having a hook accepting a function taking the buildOptions as a parameter could be good enough - that would mean the options are part of the API and must be documented and ~stable.
that is an excellent idea. im gonna think about this until tomorrow. with more thoroughly thought this PR might not be needed for any use-cases.
thanks for the feedback on this @vicb. after a night sleep I decided to close this, and I will instead write about |
This PR introduces a new feature for
open-next.config.ts
. You can now specify additional files to be copied after the server function(s) has been bundled. This feature also supports split functions.The
srcPath
can be a relative or absolute path and can accept glob patterns. If a glob matches multiple files,dstPath
will be treated as a directory. If only a single file is matched,dstPath
will be treated as a file.Here is an example: