Skip to content

Commit

Permalink
Merge branch 'canary' into bump-swc
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk committed Jul 25, 2024
2 parents 1fe16d6 + c7b6759 commit ac5f86f
Show file tree
Hide file tree
Showing 20 changed files with 98 additions and 115 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "15.0.0-canary.81"
"version": "15.0.0-canary.82"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"keywords": [
"react",
"next",
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-config-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "eslint-config-next",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"description": "ESLint configuration used by Next.js.",
"main": "index.js",
"license": "MIT",
Expand All @@ -10,7 +10,7 @@
},
"homepage": "https://nextjs.org/docs/app/building-your-application/configuring/eslint#eslint-config",
"dependencies": {
"@next/eslint-plugin-next": "15.0.0-canary.81",
"@next/eslint-plugin-next": "15.0.0-canary.82",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/eslint-plugin": "^5.4.2 || ^6.0.0 || ^7.0.0",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0 || ^7.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/eslint-plugin-next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/eslint-plugin-next",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"description": "ESLint plugin for Next.js.",
"main": "dist/index.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/font/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@next/font",
"private": true,
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"repository": {
"url": "vercel/next.js",
"directory": "packages/font"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"main": "index.js",
"types": "index.d.ts",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-codemod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/codemod",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"license": "MIT",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-env/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/env",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-storybook",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-module/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-module",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"description": "A standard library polyfill for ES Modules supporting browsers (Edge 16+, Firefox 60+, Chrome 61+, Safari 10.1+)",
"main": "dist/polyfill-module.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-swc/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/swc",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"private": true,
"scripts": {
"clean": "node ../../scripts/rm.mjs native",
Expand Down
12 changes: 6 additions & 6 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -93,7 +93,7 @@
]
},
"dependencies": {
"@next/env": "15.0.0-canary.81",
"@next/env": "15.0.0-canary.82",
"@swc/counter": "0.1.3",
"@swc/helpers": "0.5.12",
"busboy": "1.6.0",
Expand Down Expand Up @@ -158,10 +158,10 @@
"@jest/types": "29.5.0",
"@mswjs/interceptors": "0.23.0",
"@napi-rs/triples": "1.2.0",
"@next/polyfill-module": "15.0.0-canary.81",
"@next/polyfill-nomodule": "15.0.0-canary.81",
"@next/react-refresh-utils": "15.0.0-canary.81",
"@next/swc": "15.0.0-canary.81",
"@next/polyfill-module": "15.0.0-canary.82",
"@next/polyfill-nomodule": "15.0.0-canary.82",
"@next/react-refresh-utils": "15.0.0-canary.82",
"@next/swc": "15.0.0-canary.82",
"@opentelemetry/api": "1.6.0",
"@playwright/test": "1.41.2",
"@swc/core": "1.7.1",
Expand Down
61 changes: 42 additions & 19 deletions packages/next/src/build/flying-shuttle/detect-changed-entries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,40 @@ import path from 'path'
import crypto from 'crypto'
import { getPageFromPath } from '../entries'
import { Sema } from 'next/dist/compiled/async-sema'
import { generateShuttleManifest } from './store-shuttle'
import { generateShuttleManifest, type ShuttleManifest } from './store-shuttle'
import type { NextConfigComplete } from '../../server/config-shared'

export interface DetectedEntriesResult {
app: string[]
pages: string[]
}

function deepEqual(obj1: any, obj2: any) {
if (obj1 === obj2) return true

if (
typeof obj1 !== 'object' ||
obj1 === null ||
typeof obj2 !== 'object' ||
obj2 === null
) {
return false
}

let keys1 = Object.keys(obj1)
let keys2 = Object.keys(obj2)

if (keys1.length !== keys2.length) return false

for (let key of keys1) {
if (!keys2.includes(key) || !deepEqual(obj1[key], obj2[key])) {
return false
}
}

return true
}

let _hasShuttle: undefined | boolean = undefined
export async function hasShuttle(
config: NextConfigComplete,
Expand All @@ -19,44 +45,41 @@ export async function hasShuttle(
if (typeof _hasShuttle === 'boolean') {
return _hasShuttle
}
let foundShuttleManifest:
| ReturnType<typeof generateShuttleManifest>
| undefined
let foundShuttleManifest: ShuttleManifest

try {
foundShuttleManifest = JSON.parse(
await fs.promises
.readFile(path.join(shuttleDir, 'shuttle-manifest.json'), 'utf8')
.catch(() => '{}')
await fs.promises.readFile(
path.join(shuttleDir, 'shuttle-manifest.json'),
'utf8'
)
)
_hasShuttle = true
} catch (err: unknown) {
_hasShuttle = false
console.log(`Failed to read shuttle manifest`)
return _hasShuttle
}
const currentShuttleManifest = generateShuttleManifest(config)
const currentShuttleManifest = JSON.parse(generateShuttleManifest(config))

if (
currentShuttleManifest.nextVersion !== foundShuttleManifest?.nextVersion
) {
if (currentShuttleManifest.nextVersion !== foundShuttleManifest.nextVersion) {
// we don't allow using shuttle from differing Next.js version
// as it could have internal changes
console.log(
`shuttle has differing Next.js version ${foundShuttleManifest?.nextVersion} versus current ${currentShuttleManifest.nextVersion}, skipping.`
`shuttle has differing Next.js version ${foundShuttleManifest.nextVersion} versus current ${currentShuttleManifest.nextVersion}, skipping.`
)
_hasShuttle = false
}

if (
_hasShuttle !== false &&
currentShuttleManifest.globalHash !== foundShuttleManifest?.globalHash
) {
// if the global hash was invalidated we bypass the cache to be safe
if (!deepEqual(currentShuttleManifest.config, foundShuttleManifest.config)) {
_hasShuttle = false
console.log(
`shuttle has differing global hash ${foundShuttleManifest?.globalHash} versus current ${currentShuttleManifest.globalHash}, skipping.`
`Mismatching shuttle configs`,
currentShuttleManifest.config,
foundShuttleManifest.config
)
_hasShuttle = false
}

return _hasShuttle
}

Expand Down
75 changes: 23 additions & 52 deletions packages/next/src/build/flying-shuttle/store-shuttle.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import fs from 'fs'
import path from 'path'
import crypto from 'crypto'
import { recursiveCopy } from '../../lib/recursive-copy'
import { version as nextVersion } from 'next/package.json'
import type { NextConfigComplete } from '../../server/config-shared'
Expand All @@ -12,58 +11,31 @@ import {
PAGES_MANIFEST,
ROUTES_MANIFEST,
} from '../../shared/lib/constants'
import { getNextPublicEnvironmentVariables } from '../webpack/plugins/define-env-plugin'

export function generateShuttleManifest(config: NextConfigComplete) {
// NEXT_PUBLIC_ changes for now since they are inlined
// and specific next config values that can impact the build
const globalHash = crypto.createHash('sha256')
const nextPublicEnv = getNextPublicEnvironmentVariables()
// sort for deterministic order
const publicEnvKeys = Object.keys(nextPublicEnv).sort()

for (const key of publicEnvKeys) {
globalHash.update(`${key}=${nextPublicEnv[key]}`)
}

// TODO: make this opt-out list instead?
// also ensure this list is complete this is minimal set
const configsToInvalidateOn = [
'basePath',
'env',
'i18n',
'images',
'productionBrowserSourceMaps',
'webpack',
'sassOptions',
'trailingSlash',
'experimental.flyingShuttle',
'experimental.ppr',
'experimental.reactCompiler',
].sort()

for (const key of configsToInvalidateOn) {
let value = config[key]

if (key.includes('.')) {
value = config

const keyParts = key.split('.')
for (let i = 0; i < keyParts.length; i++) {
value = value[keyParts[i]]
}
}

let serializedConfig =
typeof value === 'function' ? value.toString() : JSON.stringify(value)

globalHash.update(`${key}=${serializedConfig}`)
}
export interface ShuttleManifest {
nextVersion: string
config: Record<string, any>
}

return {
export function generateShuttleManifest(config: NextConfigComplete) {
return JSON.stringify({
nextVersion,
globalHash: globalHash.digest('hex'),
}
config: {
env: config.env,
i18n: config.i18n,
basePath: config.basePath,
sassOptions: config.sassOptions,
trailingSlash: config.trailingSlash,
productionBrowserSourceMaps: config.productionBrowserSourceMaps,

experimental: {
ppr: config.experimental.ppr,
reactCompiler: config.experimental.reactCompiler,
serverSourceMaps: config.experimental.serverSourceMaps,
serverMinification: config.experimental.serverMinification,
},
},
} satisfies ShuttleManifest)
}

// we can create a new shuttle with the outputs before env values have
Expand All @@ -80,10 +52,9 @@ export async function storeShuttle({
await fs.promises.rm(shuttleDir, { force: true, recursive: true })
await fs.promises.mkdir(shuttleDir, { recursive: true })

const shuttleManifest = generateShuttleManifest(config)
await fs.promises.writeFile(
path.join(shuttleDir, 'shuttle-manifest.json'),
JSON.stringify(shuttleManifest)
generateShuttleManifest(config)
)

// copy all server entries
Expand Down
2 changes: 1 addition & 1 deletion packages/react-refresh-utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/react-refresh-utils",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"description": "An experimental package providing utilities for React Refresh.",
"repository": {
"url": "vercel/next.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/third-parties/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/third-parties",
"version": "15.0.0-canary.81",
"version": "15.0.0-canary.82",
"repository": {
"url": "vercel/next.js",
"directory": "packages/third-parties"
Expand All @@ -26,7 +26,7 @@
"third-party-capital": "1.0.20"
},
"devDependencies": {
"next": "15.0.0-canary.81",
"next": "15.0.0-canary.82",
"outdent": "0.8.0",
"prettier": "2.5.1"
},
Expand Down
Loading

0 comments on commit ac5f86f

Please sign in to comment.