diff --git a/.changeset/four-numbers-flash.md b/.changeset/four-numbers-flash.md new file mode 100644 index 000000000..4e6046624 --- /dev/null +++ b/.changeset/four-numbers-flash.md @@ -0,0 +1,7 @@ +--- +'@astrojs/telemetry': patch +--- + +Fix telemetry crashing astro build/dev when using optional integrations + +Telemetry will now ignore falsy integration values but will gather a count of how many integrations out of the total are now optional integrations \ No newline at end of file diff --git a/.changeset/funny-terms-matter.md b/.changeset/funny-terms-matter.md new file mode 100644 index 000000000..50e953fe0 --- /dev/null +++ b/.changeset/funny-terms-matter.md @@ -0,0 +1,5 @@ +--- +'@astrojs/telemetry': patch +--- + +Add's optional integrations field to `@astrojs/telemetry`'s payload diff --git a/packages/telemetry/src/events/session.ts b/packages/telemetry/src/events/session.ts index 995cf5075..babd09e55 100644 --- a/packages/telemetry/src/events/session.ts +++ b/packages/telemetry/src/events/session.ts @@ -36,6 +36,7 @@ interface EventCliSessionInternal extends EventCliSession { config?: ConfigInfo; configKeys?: string[]; flags?: string[]; + optionalIntegrations?: number; } function getViteVersion() { @@ -89,6 +90,8 @@ export function eventCliSession( userConfig?: AstroUserConfig, flags?: Record ): { eventName: string; payload: EventCliSessionInternal }[] { + // Filter out falsy integrations + const integrations = userConfig?.integrations?.filter?.(Boolean) ?? []; const configValues = userConfig ? { markdownPlugins: [ @@ -96,17 +99,17 @@ export function eventCliSession( userConfig?.markdown?.rehypePlugins ?? [], ].flat(1), adapter: userConfig?.adapter?.name ?? null, - integrations: userConfig?.integrations?.map((i: any) => i.name) ?? [], + integrations: integrations?.map?.((i: any) => i?.name) ?? [], trailingSlash: userConfig?.trailingSlash, build: userConfig?.build ? { - format: userConfig?.build?.format, + format: userConfig?.build?.format, } : undefined, markdown: userConfig?.markdown ? { - mode: userConfig?.markdown?.mode, - syntaxHighlight: userConfig.markdown?.syntaxHighlight, + mode: userConfig?.markdown?.mode, + syntaxHighlight: userConfig.markdown?.syntaxHighlight, } : undefined, } @@ -125,6 +128,8 @@ export function eventCliSession( // Config Values config: configValues, flags: cliFlags, + // Optional integrations + optionalIntegrations: userConfig?.integrations?.length - integrations?.length }; return [{ eventName: EVENT_SESSION, payload }]; } diff --git a/packages/telemetry/test/session-event.test.js b/packages/telemetry/test/session-event.test.js index 70705512f..07b214c30 100644 --- a/packages/telemetry/test/session-event.test.js +++ b/packages/telemetry/test/session-event.test.js @@ -411,6 +411,48 @@ describe('Session event', () => { }); }); + describe('config.integrations + optionalIntegrations', () => { + it('optional/conditional integrations', () => { + const config = { + srcDir: 1, + integrations: [ + null, + undefined, + { name: "example-integration" } + ] + }; + const [{ payload }] = events.eventCliSession( + { + cliCommand: 'dev', + astroVersion: '0.0.0', + }, + config + ); + expect(payload.config.integrations).deep.equal(["example-integration"]); + expect(payload.optionalIntegrations).to.equal(2); + }); + + it('falsy integrations', () => { + const config = { + srcDir: 1, + integrations: [ + null, + undefined, + false + ] + }; + const [{ payload }] = events.eventCliSession( + { + cliCommand: 'dev', + astroVersion: '0.0.0', + }, + config + ); + expect(payload.config.integrations.length).to.equal(0); + expect(payload.optionalIntegrations).to.equal(3); + }); + }); + describe('flags', () => { it('includes cli flags in payload', () => { const config = {};