Commit ca36b00d authored by Tobias Koppers's avatar Tobias Koppers

Use process.env.__NEXT_VERSION consistently in packages/next/src

Replace all require('next/package.json').version and import { version }
from 'next/package.json' usages with process.env.__NEXT_VERSION, which
is inlined at build time by taskfile-swc.js.
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
parent dcfd6e51
...@@ -89,7 +89,7 @@ export async function turbopackAnalyze( ...@@ -89,7 +89,7 @@ export async function turbopackAnalyze(
writeRoutesHashesManifest: false, writeRoutesHashesManifest: false,
currentNodeJsVersion, currentNodeJsVersion,
isPersistentCachingEnabled: persistentCaching, isPersistentCachingEnabled: persistentCaching,
nextVersion: require('next/package.json').version, nextVersion: process.env.__NEXT_VERSION as string,
}, },
{ {
memoryLimit: config.experimental?.turbopackMemoryLimit, memoryLimit: config.experimental?.turbopackMemoryLimit,
......
...@@ -105,7 +105,7 @@ export async function turbopackBuild(): Promise<{ ...@@ -105,7 +105,7 @@ export async function turbopackBuild(): Promise<{
currentNodeJsVersion, currentNodeJsVersion,
isPersistentCachingEnabled: persistentCaching, isPersistentCachingEnabled: persistentCaching,
deferredEntries: config.experimental.deferredEntries, deferredEntries: config.experimental.deferredEntries,
nextVersion: require('next/package.json').version, nextVersion: process.env.__NEXT_VERSION as string,
} }
const sharedTurboOptions = { const sharedTurboOptions = {
......
...@@ -2,7 +2,7 @@ import { promises } from 'fs' ...@@ -2,7 +2,7 @@ import { promises } from 'fs'
import * as Log from '../build/output/log' import * as Log from '../build/output/log'
import findUp from 'next/dist/compiled/find-up' import findUp from 'next/dist/compiled/find-up'
// @ts-ignore no-json types // @ts-ignore no-json types
import nextPkgJson from 'next/package.json' import { optionalDependencies as nextOptionalDeps } from 'next/package.json'
import type { UnwrapPromise } from './coalesced-function' import type { UnwrapPromise } from './coalesced-function'
import { isCI } from '../server/ci-info' import { isCI } from '../server/ci-info'
import { getRegistry } from './helpers/get-registry' import { getRegistry } from './helpers/get-registry'
...@@ -19,7 +19,7 @@ async function fetchPkgInfo(pkg: string) { ...@@ -19,7 +19,7 @@ async function fetchPkgInfo(pkg: string) {
) )
} }
const data = await res.json() const data = await res.json()
const versionData = data.versions[nextPkgJson.version] const versionData = data.versions[process.env.__NEXT_VERSION as string]
return { return {
os: versionData.os, os: versionData.os,
...@@ -56,16 +56,16 @@ export async function patchIncorrectLockfile(dir: string) { ...@@ -56,16 +56,16 @@ export async function patchIncorrectLockfile(dir: string) {
const lockfileParsed = JSON.parse(content) const lockfileParsed = JSON.parse(content)
const lockfileVersion = parseInt(lockfileParsed?.lockfileVersion, 10) const lockfileVersion = parseInt(lockfileParsed?.lockfileVersion, 10)
const expectedSwcPkgs = Object.keys( const expectedSwcPkgs = Object.keys(nextOptionalDeps || {}).filter((pkg) =>
nextPkgJson['optionalDependencies'] || {} pkg.startsWith('@next/swc-')
).filter((pkg) => pkg.startsWith('@next/swc-')) )
const patchDependency = ( const patchDependency = (
pkg: string, pkg: string,
pkgData: UnwrapPromise<ReturnType<typeof fetchPkgInfo>> pkgData: UnwrapPromise<ReturnType<typeof fetchPkgInfo>>
) => { ) => {
lockfileParsed.dependencies[pkg] = { lockfileParsed.dependencies[pkg] = {
version: nextPkgJson.version, version: process.env.__NEXT_VERSION as string,
resolved: pkgData.tarball, resolved: pkgData.tarball,
integrity: pkgData.integrity, integrity: pkgData.integrity,
optional: true, optional: true,
...@@ -77,7 +77,7 @@ export async function patchIncorrectLockfile(dir: string) { ...@@ -77,7 +77,7 @@ export async function patchIncorrectLockfile(dir: string) {
pkgData: UnwrapPromise<ReturnType<typeof fetchPkgInfo>> pkgData: UnwrapPromise<ReturnType<typeof fetchPkgInfo>>
) => { ) => {
lockfileParsed.packages[pkg] = { lockfileParsed.packages[pkg] = {
version: nextPkgJson.version, version: process.env.__NEXT_VERSION as string,
resolved: pkgData.tarball, resolved: pkgData.tarball,
integrity: pkgData.integrity, integrity: pkgData.integrity,
cpu: pkgData.cpu, cpu: pkgData.cpu,
......
...@@ -8,7 +8,7 @@ export async function getVersionInfo(): Promise<VersionInfo> { ...@@ -8,7 +8,7 @@ export async function getVersionInfo(): Promise<VersionInfo> {
let installed = '0.0.0' let installed = '0.0.0'
try { try {
installed = require('next/package.json').version installed = process.env.__NEXT_VERSION as string
let res let res
......
...@@ -403,7 +403,7 @@ export async function createHotReloaderTurbopack( ...@@ -403,7 +403,7 @@ export async function createHotReloaderTurbopack(
isPersistentCachingEnabled: isFileSystemCacheEnabledForDev( isPersistentCachingEnabled: isFileSystemCacheEnabledForDev(
opts.nextConfig opts.nextConfig
), ),
nextVersion: require('next/package.json').version, nextVersion: process.env.__NEXT_VERSION as string,
}, },
{ {
memoryLimit: opts.nextConfig.experimental?.turbopackMemoryLimit, memoryLimit: opts.nextConfig.experimental?.turbopackMemoryLimit,
......
import { traceGlobals } from '../../trace/shared' import { traceGlobals } from '../../trace/shared'
import type { Telemetry } from '../storage' import type { Telemetry } from '../storage'
// @ts-ignore JSON // @ts-ignore JSON
import { version as nextVersion, optionalDependencies } from 'next/package.json' import { optionalDependencies } from 'next/package.json'
const EVENT_PLUGIN_PRESENT = 'NEXT_SWC_LOAD_FAILURE' const EVENT_PLUGIN_PRESENT = 'NEXT_SWC_LOAD_FAILURE'
export type EventSwcLoadFailure = { export type EventSwcLoadFailure = {
...@@ -54,7 +54,7 @@ export async function eventSwcLoadFailure( ...@@ -54,7 +54,7 @@ export async function eventSwcLoadFailure(
telemetry.record({ telemetry.record({
eventName: EVENT_PLUGIN_PRESENT, eventName: EVENT_PLUGIN_PRESENT,
payload: { payload: {
nextVersion, nextVersion: process.env.__NEXT_VERSION as string,
glibcVersion, glibcVersion,
installedSwcPackages, installedSwcPackages,
arch: process.arch, arch: process.arch,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment