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
This commit is contained in:
parent
493441f57b
commit
9c8a7c0b09
4 changed files with 63 additions and 4 deletions
7
.changeset/four-numbers-flash.md
Normal file
7
.changeset/four-numbers-flash.md
Normal file
|
@ -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
|
5
.changeset/funny-terms-matter.md
Normal file
5
.changeset/funny-terms-matter.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@astrojs/telemetry': patch
|
||||
---
|
||||
|
||||
Add's optional integrations field to `@astrojs/telemetry`'s payload
|
|
@ -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 }];
|
||||
}
|
||||
|
|
|
@ -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 = {};
|
||||
|
|
Loading…
Reference in a new issue