1- /* eslint-disable no-console */
1+
22/**
33 * This was taken and modified from https://github.com/getsentry/sentry-javascript/blob/15256034ee8150a5b7dcb97d23eca1a5486f0cae/packages/nextjs/src/config/util.ts
44 *
2828import { readFileSync } from 'fs'
2929import { fileURLToPath } from 'url'
3030
31- function _parseInt ( input : string | undefined ) : number {
31+ /**
32+ * @param {string | undefined } input
33+ * @returns {number }
34+ */
35+ function _parseInt ( input ) {
3236 return parseInt ( input || '' , 10 )
3337}
3438
3539/**
3640 * Represents Semantic Versioning object
41+ * @typedef {Object } SemVer
42+ * @property {string } [buildmetadata]
43+ * @property {number } [canaryVersion] - undefined if not a canary version
44+ * @property {number } [major]
45+ * @property {number } [minor]
46+ * @property {number } [patch]
47+ * @property {string } [prerelease]
3748 */
38- type SemVer = {
39- buildmetadata ?: string
40- /**
41- * undefined if not a canary version
42- */
43- canaryVersion ?: number
44- major ?: number
45- minor ?: number
46- patch ?: number
47- prerelease ?: string
48- }
4949
5050// https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string
5151const SEMVER_REGEXP =
5252 / ^ ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) \. ( 0 | [ 1 - 9 ] \d * ) (?: - ( (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z - ] [ 0 - 9 a - z - ] * ) (?: \. (?: 0 | [ 1 - 9 ] \d * | \d * [ a - z - ] [ 0 - 9 a - z - ] * ) ) * ) ) ? (?: \+ ( [ 0 - 9 a - z - ] + (?: \. [ 0 - 9 a - z - ] + ) * ) ) ? $ / i
5353
5454/**
5555 * Parses input into a SemVer interface
56- * @param input string representation of a semver version
56+ * @param {string } input - string representation of a semver version
57+ * @returns {SemVer }
5758 */
58- export function parseSemver ( input : string ) : SemVer {
59+ export function parseSemver ( input ) {
5960 const match = input . match ( SEMVER_REGEXP ) || [ ]
6061 const major = _parseInt ( match [ 1 ] )
6162 const minor = _parseInt ( match [ 2 ] )
@@ -78,10 +79,12 @@ export function parseSemver(input: string): SemVer {
7879
7980/**
8081 * Returns the version of Next.js installed in the project, or undefined if it cannot be determined.
82+ * @returns {SemVer | undefined }
8183 */
82- export function getNextjsVersion ( ) : SemVer | undefined {
84+ export function getNextjsVersion ( ) {
8385 try {
84- let pkgPath : string
86+ /** @type {string } */
87+ let pkgPath
8588
8689 // Check if we're in ESM or CJS environment
8790 if ( typeof import . meta?. resolve === 'function' ) {
@@ -106,10 +109,10 @@ export function getNextjsVersion(): SemVer | undefined {
106109/**
107110 * Checks if the current Next.js version supports Turbopack externalize transitive dependencies.
108111 * This was introduced in Next.js v16.1.0-canary.3
112+ * @param {SemVer | undefined } version
113+ * @returns {boolean }
109114 */
110- export function supportsTurbopackExternalizeTransitiveDependencies (
111- version : SemVer | undefined ,
112- ) : boolean {
115+ export function supportsTurbopackExternalizeTransitiveDependencies ( version ) {
113116 if ( ! version ) {
114117 return false
115118 }
0 commit comments