Files
klz-cables.com/.pnpm-store/v10/files/a1/eeb87abe03b60085c57aab4fc93c44c34ad879db75bc878f09b4e8d7ff2b3824b9f0707dc34a71fd61fe08b75dfa8ba54fb71258b58a1f594029d8f819e057
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

208 lines
5.5 KiB
Plaintext

import { parseSemver } from '@sentry/core';
import * as fs from 'fs';
import { createRequire } from 'module';
import * as path from 'path';
/**
* Returns the version of Next.js installed in the project, or undefined if it cannot be determined.
*/
function getNextjsVersion() {
const nextjsPackageJsonPath = resolveNextjsPackageJson();
if (nextjsPackageJsonPath) {
try {
const nextjsPackageJson = JSON.parse(
fs.readFileSync(nextjsPackageJsonPath, { encoding: 'utf-8' }),
);
return nextjsPackageJson.version;
} catch {
// noop
}
}
return undefined;
}
function resolveNextjsPackageJson() {
try {
return createRequire(`${process.cwd()}/`).resolve('next/package.json');
} 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)
*
* @param version - version string to check.
* @returns true if Next.js version is 15.4.1 or higher
*/
function supportsProductionCompileHook(version) {
const versionToCheck = version;
if (!versionToCheck) {
return false;
}
const { major, minor, patch } = parseSemver(versionToCheck);
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;
}
/**
* Checks if the current Next.js version supports native debug ids for turbopack.
* This feature was first introduced in Next.js v15.6.0-canary.36 and marked stable in Next.js v16
*
* @param version - version string to check.
* @returns true if Next.js version supports native debug ids for turbopack builds
*/
function supportsNativeDebugIds(version) {
if (!version) {
return false;
}
const { major, minor, prerelease } = parseSemver(version);
if (major === undefined || minor === undefined) {
return false;
}
// Next.js 16+ supports native debug ids
if (major >= 16) {
return true;
}
// For Next.js 15, check if it's 15.6.0-canary.36+
if (major === 15 && prerelease?.startsWith('canary.')) {
// Any canary version 15.7+ supports native debug ids
if (minor > 6) {
return true;
}
// For 15.6 canary versions, check if it's canary.36 or higher
if (minor === 6) {
const canaryNumber = parseInt(prerelease.split('.')[1] || '0', 10);
if (canaryNumber >= 36) {
return true;
}
}
}
return false;
}
/**
* Checks if the given Next.js version requires the `experimental.instrumentationHook` option.
* Next.js 15.0.0 and higher (including certain RC and canary versions) no longer require this option
* and will print a warning if it is set.
*
* @param version - version string to check.
* @returns true if the version requires the instrumentationHook option to be set
*/
function requiresInstrumentationHook(version) {
if (!version) {
return true; // Default to requiring it if version cannot be determined
}
const { major, minor, patch, prerelease } = parseSemver(version);
if (major === undefined || minor === undefined || patch === undefined) {
return true; // Default to requiring it if parsing fails
}
// Next.js 16+ never requires the hook
if (major >= 16) {
return false;
}
// Next.js 14 and below always require the hook
if (major < 15) {
return true;
}
// At this point, we know it's Next.js 15.x.y
// Stable releases (15.0.0+) don't require the hook
if (!prerelease) {
return false;
}
// Next.js 15.x.y with x > 0 or y > 0 don't require the hook
if (minor > 0 || patch > 0) {
return false;
}
// Check specific prerelease versions that don't require the hook
if (prerelease.startsWith('rc.')) {
const rcNumber = parseInt(prerelease.split('.')[1] || '0', 10);
return rcNumber === 0; // Only rc.0 requires the hook
}
if (prerelease.startsWith('canary.')) {
const canaryNumber = parseInt(prerelease.split('.')[1] || '0', 10);
return canaryNumber < 124; // canary.124+ doesn't require the hook
}
// All other 15.0.0 prerelease versions (alpha, beta, etc.) require the hook
return true;
}
/**
* Determines which bundler is actually being used based on environment variables,
* and CLI flags.
*
* @returns 'turbopack' or 'webpack'
*/
function detectActiveBundler() {
const turbopackEnv = process.env.TURBOPACK;
// Check if TURBOPACK env var is set to a truthy value (excluding falsy strings like 'false', '0', '')
const isTurbopackEnabled = turbopackEnv && turbopackEnv !== 'false' && turbopackEnv !== '0';
if (isTurbopackEnabled || process.argv.includes('--turbo')) {
return 'turbopack';
} else {
return 'webpack';
}
}
/**
* Extract modules from project directory's package.json
*/
function getPackageModules(projectDir) {
try {
const packageJson = path.join(projectDir, 'package.json');
const packageJsonContent = fs.readFileSync(packageJson, 'utf8');
const packageJsonObject = JSON.parse(packageJsonContent)
;
return {
...packageJsonObject.dependencies,
...packageJsonObject.devDependencies,
};
} catch {
return {};
}
}
export { detectActiveBundler, getNextjsVersion, getPackageModules, requiresInstrumentationHook, supportsNativeDebugIds, supportsProductionCompileHook };
//# sourceMappingURL=util.js.map