build
build copied to clipboard
Better handling of already-transpiled TypeScript functions
When a TypeScript function has been transpiled before zip-it-and-ship-it starts, it will be present in the functions directory both as a .ts and a .js file. The current behavior seems to be:
- Both the
.tsand.jsfiles are being bundled, separately. - In production, the
.jsfunction is being served and the.tsone is being ignored. listFunctions()andlistFunctionsFiles()return both the.tsand.jsfiles.
Instead, we should ignore the .ts file when a sibling file with the same filename but a .js extension exists.
- Both the
.tsand.jsfiles are being bundled, separately.
We keep a list of allowed extensions, sorted by priority (https://github.com/netlify/zip-it-and-ship-it/blob/main/src/runtimes/node/finder.js#L9-L21). When you have foo.js and foo.ts, we only create one foo.zip with the contents of the JavaScript function.
Can you clarify what you mean when you say that both files are bundled? Do you have a repro case?
This specific commit is an example of a site using both a *.js function and a *.ts function.
Both functions are being bundled:
Packaging Functions from netlify/functions directory:
- typescript.ts
- typescript.js
As you mention, although both are being bundled, in production, the *.js file is being served, not the *.ts file.
Finally, when running listFunctions() or listFunctionsFiles(), both files are returned.
We generate that message using listFunctions (see https://github.com/netlify/build/blob/main/packages/build/src/plugins_core/functions/utils.js#L13-L20). So what you're seeing doesn't mean that both functions are being bundled, it just means that we incorrectly list them both as a result of listFunctions's behaviour.
I think we can fix this simply by removing duplicates in the list before printing them. Because we get all functions, we could even go a step further and say that typescript.ts was ignored because it was overridden by typescript.js, like we do with environment variables from different sources in the CLI.
This makes sense!
Transferred to netlify/build.
This issue has been automatically marked as stale because it has not had activity in 1 year. It will be closed in 14 days if no further activity occurs. Thanks!
This issue was closed because it had no activity for over 1 year.