-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Expand file tree
/
Copy pathutil.ts
More file actions
66 lines (57 loc) · 1.58 KB
/
util.ts
File metadata and controls
66 lines (57 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import { parseSemver } from '@sentry/core';
import * as fs from 'fs';
import { sync as resolveSync } from 'resolve';
/**
* Returns the version of Next.js installed in the project, or undefined if it cannot be determined.
*/
export function getNextjsVersion(): string | undefined {
const nextjsPackageJsonPath = resolveNextjsPackageJson();
if (nextjsPackageJsonPath) {
try {
const nextjsPackageJson: { version: string } = JSON.parse(
fs.readFileSync(nextjsPackageJsonPath, { encoding: 'utf-8' }),
);
return nextjsPackageJson.version;
} catch {
// noop
}
}
return undefined;
}
function resolveNextjsPackageJson(): string | undefined {
try {
return resolveSync('next/package.json', { basedir: process.cwd() });
} catch {
return undefined;
}
}
/**
* Checks if the current Next.js version supports the runAfterProductionCompile hook.
* This hook was introduced in Next.js 15.4.1. (https://github.com/vercel/next.js/pull/77345)
*
* @returns true if Next.js version is 15.4.1 or higher
*/
export function supportsProductionCompileHook(): boolean {
const version = getNextjsVersion();
if (!version) {
return false;
}
const { major, minor, patch } = parseSemver(version);
if (major === undefined || minor === undefined || patch === undefined) {
return false;
}
if (major > 15) {
return true;
}
// For major version 15, check if it's 15.4.1 or higher
if (major === 15) {
if (minor > 4) {
return true;
}
if (minor === 4 && patch >= 1) {
return true;
}
return false;
}
return false;
}