Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Run lifecycle hooks for specific functions. (#6023)
- Increased extension instance create poll timeout to 1h to match backend (#5969).
- Refactored `ext:install` to use the latest extension metadata. (#5997)
- Added descriptive error when repo is private or not found during `ext:dev:upload`. (#6052)
Expand Down
40 changes: 34 additions & 6 deletions src/deploy/lifecycleHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,46 @@ function getReleventConfigs(target: string, options: Options) {

onlyTargets = onlyTargets
.filter((individualOnly) => {
return individualOnly.indexOf(`${target}:`) === 0;
return individualOnly.startsWith(`${target}:`);
})
.map((individualOnly) => {
return individualOnly.replace(`${target}:`, "");
});

return targetConfigs.filter((config: any) => {
if (target === "functions") {
return onlyTargets.includes(config.codebase);
if (target === "functions") {
let onlyConfigs = [];
const matched = onlyTargets.reduce(
(matched: object, target: string) => ({ ...matched, [target]: false }),
{}
);
for (const config of targetConfigs) {
if (!config.codebase) {
onlyConfigs.push(config);
} else {
const found = onlyTargets.find(
(individualOnly) => config.codebase === individualOnly.split(":")[0]
);
if (found) {
onlyConfigs.push(config);
matched[found] = true;
}
}
}
return !config.target || onlyTargets.includes(config.target);
});
// if there are --only targets that failed to match, we assume that the target is a
// individually specified function and so we run lifecycle hooks for all codebases.
// However, this also means that codebases or functions that don't exist will also run
// the all codebase lifecycle hooks. Until we can significantly refactor the way we
// identify which functions are in which codebase in the predeploy phase, we have to live
// with this default behavior.
if (!Object.values(matched).every((matched) => matched)) {
onlyConfigs = targetConfigs;
}
return onlyConfigs;
} else {
return targetConfigs.filter((config: any) => {
return !config.target || onlyTargets.includes(config.target);
});
}
}

export function lifecycleHooks(
Expand Down