perf: optimize analytics app imports to avoid loading entire app store (#23372)
* perf: optimize analytics app imports to avoid loading entire app store - Add analytics service generation to app-store-cli build process - Generate analytics.services.generated.ts with only analytics apps (dub) - Update getAnalytics.ts to use AnalyticsServiceMap instead of full appStore - Add NEXT_PUBLIC_IS_E2E to turbo.json globalEnv for generated files - Reduces import footprint from 100+ apps to only analytics apps with AnalyticsService - Follows same pattern as calendar services optimization from PR #22450 Co-Authored-By: [email protected] <[email protected]> * Reorder cli output * fix: follow getCalendar pattern in getAnalytics and maintain alphabetical order in turbo.json - Remove unnecessary object wrapping in getAnalytics.ts to match getCalendar.ts pattern - Move NEXT_PUBLIC_IS_E2E to correct alphabetical position in turbo.json globalEnv - Address PR feedback from keithwillcode Co-Authored-By: [email protected] <[email protected]> * chore: update yarn.lock after analytics optimization changes Co-Authored-By: [email protected] <[email protected]> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
6d1fe32a39
commit
520e711ca6
5 files changed
+82
-24
No files matched your search
@@ -378,12 +378,50 @@ function generateFiles() {
|
||||
calendarOutput.push(...calendarServices);
|
||||
}
|
||||
|
||||
const analyticsOutput = [];
|
||||
const analyticsServices = getExportedObject(
|
||||
"AnalyticsServiceMap",
|
||||
{
|
||||
importConfig: {
|
||||
fileToBeImported: "lib/AnalyticsService.ts",
|
||||
importName: "default",
|
||||
},
|
||||
lazyImport: true,
|
||||
},
|
||||
(app: App) => {
|
||||
const hasAnalyticsService = fs.existsSync(
|
||||
path.join(APP_STORE_PATH, app.path, "lib/AnalyticsService.ts")
|
||||
);
|
||||
return hasAnalyticsService;
|
||||
}
|
||||
);
|
||||
|
||||
const analyticsExportLineIndex = analyticsServices.findIndex((line) =>
|
||||
line.startsWith("export const AnalyticsServiceMap")
|
||||
);
|
||||
if (analyticsExportLineIndex !== -1) {
|
||||
const exportLine = analyticsServices[analyticsExportLineIndex];
|
||||
const objectContent = analyticsServices.slice(analyticsExportLineIndex + 1, -1);
|
||||
|
||||
analyticsOutput.push(
|
||||
exportLine.replace(
|
||||
"export const AnalyticsServiceMap = {",
|
||||
"export const AnalyticsServiceMap = process.env.NEXT_PUBLIC_IS_E2E ? {} : {"
|
||||
),
|
||||
...objectContent,
|
||||
"};"
|
||||
);
|
||||
} else {
|
||||
analyticsOutput.push(...analyticsServices);
|
||||
}
|
||||
|
||||
const banner = `/**
|
||||
This file is autogenerated using the command \`yarn app-store:build --watch\`.
|
||||
Don't modify this file manually.
|
||||
**/
|
||||
`;
|
||||
const filesToGenerate: [string, string[]][] = [
|
||||
["analytics.services.generated.ts", analyticsOutput],
|
||||
["apps.metadata.generated.ts", metadataOutput],
|
||||
["apps.server.generated.ts", serverOutput],
|
||||
["apps.browser.generated.tsx", browserOutput],
|
||||
|
||||
Reference in new issue
Block a user