-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
detect package manager and improve types #3847
Merged
+89
−44
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@astrojs/telemetry': patch | ||
--- | ||
|
||
Detect package manager, improve types |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,12 @@ import { getSystemInfo, SystemInfo } from './system-info.js'; | |
|
||
export type AstroTelemetryOptions = { astroVersion: string; viteVersion: string }; | ||
export type TelemetryEvent = { eventName: string; payload: Record<string, any> }; | ||
interface EventContext { | ||
|
||
interface EventMeta extends SystemInfo {} | ||
interface EventContext extends ProjectInfo { | ||
anonymousId: string; | ||
anonymousProjectId: string; | ||
anonymousSessionId: string; | ||
} | ||
|
||
interface EventMeta extends SystemInfo { | ||
isGit: boolean; | ||
} | ||
export class AstroTelemetry { | ||
private _anonymousSessionId: string | undefined; | ||
private _anonymousProjectInfo: ProjectInfo | undefined; | ||
|
@@ -118,29 +115,19 @@ export class AstroTelemetry { | |
return Promise.resolve(); | ||
} | ||
|
||
if (this.debug.enabled) { | ||
// Print to standard error to simplify selecting the output | ||
events.forEach(({ eventName, payload }) => | ||
this.debug(JSON.stringify({ eventName, payload }, null, 2)) | ||
); | ||
// Do not send the telemetry data if debugging. Users may use this feature | ||
// to preview what data would be sent. | ||
return Promise.resolve(); | ||
} | ||
|
||
// Skip recording telemetry if the feature is disabled | ||
if (this.isDisabled) { | ||
this.debug('telemetry disabled'); | ||
return Promise.resolve(); | ||
} | ||
|
||
const meta: EventMeta = { | ||
...getSystemInfo({ astroVersion: this.astroVersion, viteVersion: this.viteVersion }), | ||
isGit: this.anonymousProjectInfo.isGit, | ||
}; | ||
|
||
const context: EventContext = { | ||
...this.anonymousProjectInfo, | ||
anonymousId: this.anonymousId, | ||
anonymousProjectId: this.anonymousProjectInfo.anonymousProjectId, | ||
anonymousSessionId: this.anonymousSessionId, | ||
}; | ||
|
||
|
@@ -150,6 +137,15 @@ export class AstroTelemetry { | |
context.anonymousId = `CI.${meta.ciName || 'UNKNOWN'}`; | ||
} | ||
|
||
if (this.debug.enabled) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Moved this down here so that it would output all data collected, not just the specific event payload. |
||
// Print to standard error to simplify selecting the output | ||
this.debug({ context, meta }); | ||
this.debug(JSON.stringify(events, null, 2)); | ||
// Do not send the telemetry data if debugging. Users may use this feature | ||
// to preview what data would be sent. | ||
return Promise.resolve(); | ||
} | ||
|
||
return post({ | ||
context, | ||
meta, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Callout that we have a which-pm helper in
create-astro
already! Pulled from Vite'screate-vite
package, and looks roughly the same as thewhich-pm-runs
source code. Happy to pull in this package though given how small it is 🤷 Your call on which we'd preferThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you mean
preferred-pm
, which I'd be happy to use but has an async-only API and this needs to be quick and sync. That's also more complex since it looks at your file system, reads up directory trees for different lockfiles, etc.I actually wonder if
create-astro
should be moved towhich-pm-runs
, since actually don't want that data when running create-astro.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually wait, it looks like it's used in
add
, and notcreate-astro
. That actually needs to rely on your file system and not just which pm you used to run command with, so we can keep as is.create-astro
is using a custom solution, which could probably be replaced with this to save us some maintainance.