| @@ -1,7 +1,11 @@ | ||
| 1 | 1 | import { recordPluginActivity } from '@shared/api/DataApi'; |
| 2 | 2 | import { digest } from '@shared/api/digest'; |
| 3 | 3 | import { enableAutoUpdate } from '@shared/api/wp'; |
| 4 | +import { | |
| 5 | + failedDependencies, | |
| 6 | + processWithSecondPass, | |
| 7 | +} from '@shared/lib/patterns'; | |
| 4 | 8 | import apiFetch from '@wordpress/api-fetch'; |
| 5 | 9 | import { addQueryArgs } from '@wordpress/url'; |
| 6 | 10 | |
| 7 | 11 | export const getActivePlugins = () => |
| @@ -159,8 +163,26 @@ | ||
| 159 | 163 | }, |
| 160 | 164 | }); |
| 161 | 165 | }; |
| 162 | 166 | |
| 167 | +export const reportFailedDependencies = (pages) => { | |
| 168 | + const failed = [ | |
| 169 | + ...new Set(pages.flatMap(({ patterns }) => failedDependencies(patterns))), | |
| 170 | + ]; | |
| 171 | + if (!failed.length) return; | |
| 172 | + | |
| 173 | + digest({ | |
| 174 | + error: { | |
| 175 | + message: `Patterns left static after a failed dependency: ${failed.join(', ')}`, | |
| 176 | + }, | |
| 177 | + details: { | |
| 178 | + source: 'auto-launch', | |
| 179 | + caller: 'reportFailedDependencies', | |
| 180 | + failed, | |
| 181 | + }, | |
| 182 | + }); | |
| 183 | +}; | |
| 184 | + | |
| 163 | 185 | // Currently this only processes patterns with placeholders |
| 164 | 186 | // by swapping out the placeholders with the actual code |
| 165 | 187 | // returns the patterns as blocks with the placeholders replaced |
| 166 | 188 | export const replacePlaceholderPatterns = async (patterns) => { |
| @@ -195,16 +217,9 @@ | ||
| 195 | 217 | source: 'auto-launch', |
| 196 | 218 | }); |
| 197 | 219 | } |
| 198 | 220 | |
| 199 | - try { | |
| 200 | - return await processPlaceholders(patterns); | |
| 201 | - } catch (_e) { | |
| 202 | - // Try one more time (plugins installed may not be fully loaded) | |
| 203 | - return await processPlaceholders(patterns) | |
| 204 | - // If this fails, just return the original patterns | |
| 205 | - .catch(() => patterns); | |
| 206 | - } | |
| 221 | + return await processWithSecondPass(processPlaceholders, patterns); | |
| 207 | 222 | }; |
| 208 | 223 | |
| 209 | 224 | // This endpoint installs pattern dependencies from PHP, outside the queue. |
| 210 | 225 | export const processPlaceholders = async (patterns) => { |