@vercel/speed-insights 0.0.1-beta.1 → 0.0.1-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/speed-insights",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.2",
4
4
  "description": "Speed Insights is a tool for measuring web performance and providing suggestions for improvement.",
5
5
  "keywords": [
6
6
  "speed-insights",
@@ -61,6 +61,7 @@
61
61
  "scripts": {
62
62
  "build": "tsup",
63
63
  "dev": "tsup --watch",
64
+ "postinstall": "node scripts/postinstall.js",
64
65
  "lint": "eslint .",
65
66
  "lint-fix": "eslint . --fix",
66
67
  "test": "jest",
@@ -0,0 +1,81 @@
1
+ /* eslint-disable -- We want to log here */
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+
5
+ const customPath = process.argv[2];
6
+
7
+ // Check .env.local for the presence of the analyticsId key
8
+ function checkAnalyticsIdInEnv() {
9
+ const files = ['.env.local', '.env.development.local', '.env'];
10
+ const projectDir = customPath || path.resolve(process.cwd());
11
+
12
+ const envFile = files.find((file) => {
13
+ const envPath = path.join(projectDir, file);
14
+ if (!fs.existsSync(envPath)) {
15
+ return false;
16
+ }
17
+
18
+ const envContent = fs.readFileSync(envPath, 'utf-8');
19
+
20
+ return envContent.includes('VERCEL_ANALYTICS_ID');
21
+ });
22
+
23
+ return envFile;
24
+ }
25
+
26
+ function isAnalyticsIdInNextConfig() {
27
+ const projectDir = customPath || path.resolve(process.cwd());
28
+ const jsConfigPath = path.join(projectDir, 'next.config.js');
29
+ const mjsConfigPath = path.join(projectDir, 'next.config.mjs');
30
+ const packageJsonPath = path.join(projectDir, 'package.json');
31
+
32
+ if (!fs.existsSync(packageJsonPath)) {
33
+ console.error('Error: package.json not found in the current directory.');
34
+ return;
35
+ }
36
+
37
+ const packageJsonContent = fs.readFileSync(packageJsonPath, 'utf-8');
38
+ const packageJson = JSON.parse(packageJsonContent);
39
+
40
+ if (!packageJson.dependencies) {
41
+ return;
42
+ }
43
+
44
+ const hasSpeedInsightsInstalled =
45
+ packageJson.dependencies['@vercel/speed-insights'];
46
+
47
+ if (!hasSpeedInsightsInstalled) {
48
+ // Has no speed-insights installed, so no need to check for analyticsId
49
+ return;
50
+ }
51
+
52
+ let configFile;
53
+
54
+ if (fs.existsSync(jsConfigPath)) {
55
+ configFile = jsConfigPath;
56
+ } else if (fs.existsSync(mjsConfigPath)) {
57
+ configFile = mjsConfigPath;
58
+ } else {
59
+ return;
60
+ }
61
+
62
+ const configContent = fs.readFileSync(configFile, 'utf-8');
63
+
64
+ return configContent.includes('analyticsId');
65
+ }
66
+
67
+ const isInConfig = isAnalyticsIdInNextConfig();
68
+ const envFile = checkAnalyticsIdInEnv();
69
+
70
+ if (isInConfig) {
71
+ console.warn(
72
+ '\x1b[31m',
73
+ `Please remove 'analyticsId' from your next.config.js file.`,
74
+ );
75
+ }
76
+ if (envFile) {
77
+ console.log(
78
+ '\x1b[31m',
79
+ `Please remove 'VERCEL_ANALYTICS_ID' from your ${envFile} file.`,
80
+ );
81
+ }