make local builds respect "ignore" files when uploading the built output#10438
make local builds respect "ignore" files when uploading the built output#10438
Conversation
…put to GCS for zip deploys
There was a problem hiding this comment.
Code Review
This pull request refactors the ignore pattern logic in src/deploy/apphosting/util.ts by centralizing it into a new resolveIgnorePatterns function, which is now utilized by both createLocalBuildTarArchive and createSourceDeployArchive. Additionally, it introduces unit tests to ensure that ignore patterns from configuration and .gitignore files are correctly respected. Feedback includes a recommendation to avoid using 'as any' in test files to comply with the repository's style guide and a suggestion to remove the export keyword from the new utility function if it is only intended for internal use.
| const configWithoutIgnore = { | ||
| backendId: "test-backend", | ||
| rootDir: "", | ||
| } as any; |
There was a problem hiding this comment.
The use of as any is discouraged by the repository style guide. While this is a test case, it's better to use a more type-safe approach, such as casting to unknown first or using a Partial type if the intention is to simulate a missing property. However, the best approach would be to ensure the type definition for AppHostingSingle correctly reflects that ignore might be optional if that is indeed the case at runtime.
| const configWithoutIgnore = { | |
| backendId: "test-backend", | |
| rootDir: "", | |
| } as any; | |
| const configWithoutIgnore = { | |
| backendId: "test-backend", | |
| rootDir: "", | |
| } as unknown as AppHostingSingle; |
References
- Never use any or unknown as an escape hatch. Define proper interfaces/types or use type guards. (link)
| return tmpFile; | ||
| } | ||
|
|
||
| export function resolveIgnorePatterns(config: AppHostingSingle, targetDir: string): string[] { |
There was a problem hiding this comment.
The function resolveIgnorePatterns is currently exported but only appears to be used within this file (util.ts). To maintain a clean API surface and follow encapsulation best practices, consider removing the export keyword unless this function is intended to be used by other modules in the future.
| export function resolveIgnorePatterns(config: AppHostingSingle, targetDir: string): string[] { | |
| function resolveIgnorePatterns(config: AppHostingSingle, targetDir: string): string[] { |
… before we actually build it
Description
We already respect the "ignore" entry in firebase.json for source deploys and we want to do the same for local builds.
One crucial difference. For local builds, we apply this filter AFTER the build, on the built output. We can not prevent files from being included in the build.
Scenarios Tested