Skip to content

Commit 55e8949

Browse files
authored
Run lifecycle hooks for specific functions (#6023)
* run lifecycle hooks for individual functions
1 parent 0bcee86 commit 55e8949

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
- Run lifecycle hooks for specific functions. (#6023)
12
- Increased extension instance create poll timeout to 1h to match backend (#5969).
23
- Refactored `ext:install` to use the latest extension metadata. (#5997)
34
- Added descriptive error when repo is private or not found during `ext:dev:upload`. (#6052)

src/deploy/lifecycleHooks.ts

+34-6
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,46 @@ function getReleventConfigs(target: string, options: Options) {
132132

133133
onlyTargets = onlyTargets
134134
.filter((individualOnly) => {
135-
return individualOnly.indexOf(`${target}:`) === 0;
135+
return individualOnly.startsWith(`${target}:`);
136136
})
137137
.map((individualOnly) => {
138138
return individualOnly.replace(`${target}:`, "");
139139
});
140140

141-
return targetConfigs.filter((config: any) => {
142-
if (target === "functions") {
143-
return onlyTargets.includes(config.codebase);
141+
if (target === "functions") {
142+
let onlyConfigs = [];
143+
const matched = onlyTargets.reduce(
144+
(matched: object, target: string) => ({ ...matched, [target]: false }),
145+
{}
146+
);
147+
for (const config of targetConfigs) {
148+
if (!config.codebase) {
149+
onlyConfigs.push(config);
150+
} else {
151+
const found = onlyTargets.find(
152+
(individualOnly) => config.codebase === individualOnly.split(":")[0]
153+
);
154+
if (found) {
155+
onlyConfigs.push(config);
156+
matched[found] = true;
157+
}
158+
}
144159
}
145-
return !config.target || onlyTargets.includes(config.target);
146-
});
160+
// if there are --only targets that failed to match, we assume that the target is a
161+
// individually specified function and so we run lifecycle hooks for all codebases.
162+
// However, this also means that codebases or functions that don't exist will also run
163+
// the all codebase lifecycle hooks. Until we can significantly refactor the way we
164+
// identify which functions are in which codebase in the predeploy phase, we have to live
165+
// with this default behavior.
166+
if (!Object.values(matched).every((matched) => matched)) {
167+
onlyConfigs = targetConfigs;
168+
}
169+
return onlyConfigs;
170+
} else {
171+
return targetConfigs.filter((config: any) => {
172+
return !config.target || onlyTargets.includes(config.target);
173+
});
174+
}
147175
}
148176

149177
export function lifecycleHooks(

0 commit comments

Comments
 (0)