-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[cli] Ignore VERCEL_ANALYTICS_ID if @vercel/speed-insights is present…
… on the project (#11305) In the past, we used the `VERCEL_ANALYTICS_ID` environment variable with the previous Speed Insights feature on Vercel to activate specific logic in Next.js, Nuxt and Gatsby for collecting and sending web vitals data. With the new Speed Insights, that's not required anymore. We no longer want to set the environment variable when detecting the new `@vercel/speed-insights` package. This PR confirms that the variable is not set if the new package is detected.
- Loading branch information
Showing
41 changed files
with
2,621 additions
and
27 deletions.
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 @@ | ||
--- | ||
'vercel': minor | ||
--- | ||
|
||
Don't propagate legacy env VERCEL_ANALYTICS_ID if @vercel/speed-insights package is detected |
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,22 @@ | ||
import debug from './debug'; | ||
|
||
export async function getInstalledPackageVersion( | ||
packageName: string, | ||
path?: string | string[] | ||
): Promise<string | undefined> { | ||
try { | ||
const resolved = require.resolve(`${packageName}/package.json`, { | ||
paths: path ? (Array.isArray(path) ? path : [path]) : [process.cwd()], | ||
}); | ||
|
||
const version: string = require(resolved).version; | ||
|
||
return version; | ||
} catch (err) { | ||
debug( | ||
`Could not resolve package "${packageName}". Package is not installed.`, | ||
err | ||
); | ||
return undefined; | ||
} | ||
} |
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
2 changes: 2 additions & 0 deletions
2
packages/cli/test/fixtures/unit/commands/build/nextjs-with-speed-insights-package/.gitignore
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,2 @@ | ||
!.vercel | ||
public/env.json |
7 changes: 7 additions & 0 deletions
7
...test/fixtures/unit/commands/build/nextjs-with-speed-insights-package/.vercel/project.json
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,7 @@ | ||
{ | ||
"orgId": ".", | ||
"projectId": ".", | ||
"settings": { | ||
"analyticsId": "12345" | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...s/cli/test/fixtures/unit/commands/build/nextjs-with-speed-insights-package/next.config.js
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 @@ | ||
const fs = require('fs'); | ||
fs.mkdirSync('public', { recursive: true }); | ||
fs.writeFileSync('public/env.json', JSON.stringify(process.env)); | ||
|
||
module.exports = {}; |
Oops, something went wrong.