diff options
author | 2022-06-16 14:53:07 -0400 | |
---|---|---|
committer | 2022-06-16 14:53:07 -0400 | |
commit | 9c8a7c0b09db2fb6925929d4efe01d5ececbf08e (patch) | |
tree | 74eead0a8bab911d19c32911c233fce96088bd51 | |
parent | 493441f57b304b298c1869e09875a27ba6a4a438 (diff) | |
download | astro-9c8a7c0b09db2fb6925929d4efe01d5ececbf08e.tar.gz astro-9c8a7c0b09db2fb6925929d4efe01d5ececbf08e.tar.zst astro-9c8a7c0b09db2fb6925929d4efe01d5ececbf08e.zip |
fix(@astrojs/telemetry): add optional integrations field (#3614)
* fix: filter out falsy integration from telemetry
Falsy integrations are now ignored in `@astrojs/telemetry`
This error should no longer occur,
```ts
error Cannot read properties of null (reading 'name')
at file:///workspaces/bundle/node_modules/.pnpm/@astrojs+telemetry@0.1.2/node_modules/@astrojs/telemetry/dist/events/session.js:53:117
...
```
* ci: add tests for optional integrations
* ci: add changeset
* fix(@astrojs/telemetry): count number of optional integrations in use
* ci: add test for counting the total number of optional integrations in use
* ci: update changeset
* chore: make the changes @tony-sull sugested
* revert(@astrojs/webapi): mod.d.ts -> a4c78b5: [ci] format
* ci: remove `@astrojs/webapi` patch change
* chore(@astrojs/telemetry): remove totalIntegrations payload field
* fix(@astrojs/telemetry): add optional integrations field
* ci: add changeset
-rw-r--r-- | .changeset/four-numbers-flash.md | 7 | ||||
-rw-r--r-- | .changeset/funny-terms-matter.md | 5 | ||||
-rw-r--r-- | packages/telemetry/src/events/session.ts | 13 | ||||
-rw-r--r-- | packages/telemetry/test/session-event.test.js | 42 |
4 files changed, 63 insertions, 4 deletions
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<string, any> ): { 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 = {}; |