Skip to content

Commit

Permalink
Merge branch 'canary' into 10-30-update-chunk-config-node
Browse files Browse the repository at this point in the history
  • Loading branch information
ijjk authored Oct 31, 2023
2 parents d96dc7d + f3bba78 commit 99f621e
Show file tree
Hide file tree
Showing 41 changed files with 491 additions and 146 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": "14.0.1"
"version": "14.0.2-canary.0"
}
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": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"@next/eslint-plugin-next": "14.0.2-canary.0",
"@rushstack/eslint-patch": "^1.3.3",
"@typescript-eslint/parser": "^5.4.2 || ^6.0.0",
"eslint-import-resolver-node": "^0.3.6",
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": "14.0.1",
"version": "14.0.2-canary.0",
"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,6 +1,6 @@
{
"name": "@next/font",
"version": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"version": "14.0.2-canary.0",
"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": "14.0.1",
"version": "14.0.2-canary.0",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ fn djb2_hash(str: &str) -> u32 {
})
}

// this is here to mirror next.js behaviour.
// this is here to mirror next.js behaviour (`toString(36).slice(0, 6)`)
fn format_radix(mut x: u32, radix: u32) -> String {
let mut result = vec![];

Expand All @@ -273,7 +273,8 @@ fn format_radix(mut x: u32, radix: u32) -> String {
}
}

result.into_iter().rev().collect()
result.reverse();
result[..6].iter().collect()
}

/// If there's special convention like (...) or @ in the page path,
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": "14.0.1",
"version": "14.0.2-canary.0",
"private": true,
"scripts": {
"clean": "node ../../scripts/rm.mjs native",
Expand Down
14 changes: 7 additions & 7 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "14.0.1",
"version": "14.0.2-canary.0",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -92,7 +92,7 @@
]
},
"dependencies": {
"@next/env": "14.0.1",
"@next/env": "14.0.2-canary.0",
"@swc/helpers": "0.5.2",
"busboy": "1.6.0",
"caniuse-lite": "^1.0.30001406",
Expand Down Expand Up @@ -146,11 +146,11 @@
"@mswjs/interceptors": "0.23.0",
"@napi-rs/cli": "2.16.2",
"@napi-rs/triples": "1.1.0",
"@next/polyfill-module": "14.0.1",
"@next/polyfill-nomodule": "14.0.1",
"@next/react-dev-overlay": "14.0.1",
"@next/react-refresh-utils": "14.0.1",
"@next/swc": "14.0.1",
"@next/polyfill-module": "14.0.2-canary.0",
"@next/polyfill-nomodule": "14.0.2-canary.0",
"@next/react-dev-overlay": "14.0.2-canary.0",
"@next/react-refresh-utils": "14.0.2-canary.0",
"@next/swc": "14.0.2-canary.0",
"@opentelemetry/api": "1.4.1",
"@playwright/test": "^1.35.1",
"@taskr/clear": "1.1.0",
Expand Down
25 changes: 21 additions & 4 deletions packages/next/src/build/webpack-build/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import {
} from '../build-context'
import { createEntrypoints } from '../entries'
import loadConfig from '../../server/config'
import { trace } from '../../trace'
import {
getTraceEvents,
initializeTraceState,
trace,
type TraceEvent,
type TraceState,
} from '../../trace'
import { WEBPACK_LAYERS } from '../../lib/constants'
import { TraceEntryPointsPlugin } from '../webpack/plugins/next-trace-entrypoints-plugin'
import type { BuildTraceContext } from '../webpack/plugins/next-trace-entrypoints-plugin'
Expand Down Expand Up @@ -331,10 +337,18 @@ export async function webpackBuildImpl(
export async function workerMain(workerData: {
compilerName: keyof typeof COMPILER_INDEXES
buildContext: typeof NextBuildContext
}) {
traceState: TraceState
}): Promise<
Awaited<ReturnType<typeof webpackBuildImpl>> & {
debugTraceEvents: TraceEvent[]
}
> {
// setup new build context from the serialized data passed from the parent
Object.assign(NextBuildContext, workerData.buildContext)

// Initialize tracer state from the parent
initializeTraceState(workerData.traceState)

// Resume plugin state
resumePluginState(NextBuildContext.pluginState)

Expand All @@ -343,7 +357,9 @@ export async function workerMain(workerData: {
PHASE_PRODUCTION_BUILD,
NextBuildContext.dir!
)
NextBuildContext.nextBuildSpan = trace('next-build')
NextBuildContext.nextBuildSpan = trace(
`worker-main-${workerData.compilerName}`
)

const result = await webpackBuildImpl(workerData.compilerName)
const { entriesTrace, chunksTrace } = result.buildTraceContext ?? {}
Expand All @@ -361,5 +377,6 @@ export async function workerMain(workerData: {
const entryNameFilesMap = chunksTrace.entryNameFilesMap
result.buildTraceContext!.chunksTrace!.entryNameFilesMap = entryNameFilesMap
}
return result
NextBuildContext.nextBuildSpan.stop()
return { ...result, debugTraceEvents: getTraceEvents() }
}
9 changes: 9 additions & 0 deletions packages/next/src/build/webpack-build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Worker } from 'next/dist/compiled/jest-worker'
import origDebug from 'next/dist/compiled/debug'
import type { ChildProcess } from 'child_process'
import path from 'path'
import { exportTraceState, recordTraceEvents } from '../../trace'

const debug = origDebug('next:build:webpack-build')

Expand Down Expand Up @@ -83,7 +84,15 @@ async function webpackBuildWithWorker(
const curResult = await worker.workerMain({
buildContext: prunedBuildContext,
compilerName,
traceState: {
...exportTraceState(),
defaultParentSpanId: nextBuildSpan?.id,
shouldSaveTraceEvents: true,
},
})
if (nextBuildSpan && curResult.debugTraceEvents) {
recordTraceEvents(curResult.debugTraceEvents)
}
// destroy worker so it's not sticking around using memory
await worker.end()

Expand Down
37 changes: 23 additions & 14 deletions packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -730,13 +730,8 @@ export default async function getBaseWebpackConfig(
const shouldIncludeExternalDirs =
config.experimental.externalDir || !!config.transpilePackages

const codeCondition = {
test: /\.(tsx|ts|js|cjs|mjs|jsx)$/,
...(shouldIncludeExternalDirs
? // Allowing importing TS/TSX files from outside of the root dir.
{}
: { include: [dir, ...babelIncludeRegexes] }),
exclude: (excludePath: string) => {
function createLoaderRuleExclude(skipNodeModules: boolean) {
return (excludePath: string) => {
if (babelIncludeRegexes.some((r) => r.test(excludePath))) {
return false
}
Expand All @@ -747,8 +742,17 @@ export default async function getBaseWebpackConfig(
)
if (shouldBeBundled) return false

return excludePath.includes('node_modules')
},
return skipNodeModules && excludePath.includes('node_modules')
}
}

const codeCondition = {
test: /\.(tsx|ts|js|cjs|mjs|jsx)$/,
...(shouldIncludeExternalDirs
? // Allowing importing TS/TSX files from outside of the root dir.
{}
: { include: [dir, ...babelIncludeRegexes] }),
exclude: createLoaderRuleExclude(true),
}

let webpackConfig: webpack.Configuration = {
Expand Down Expand Up @@ -1401,12 +1405,17 @@ export default async function getBaseWebpackConfig(
use: swcLoaderForServerLayer,
},
{
...codeCondition,
issuerLayer: [
WEBPACK_LAYERS.appPagesBrowser,
WEBPACK_LAYERS.serverSideRendering,
],
test: codeCondition.test,
exclude: codeCondition.exclude,
issuerLayer: [WEBPACK_LAYERS.appPagesBrowser],
use: swcLoaderForClientLayer,
resolve: {
mainFields: getMainField('app', compilerType),
},
},
{
test: codeCondition.test,
issuerLayer: [WEBPACK_LAYERS.serverSideRendering],
use: swcLoaderForClientLayer,
resolve: {
mainFields: getMainField('app', compilerType),
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/lib/server-external-packages.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"@aws-sdk/client-s3",
"@aws-sdk/s3-presigned-post",
"@blockfrost/blockfrost-js",
"@highlight-run/node",
"@libsql/client",
"@jpg-store/lucid-cardano",
"@mikro-orm/core",
Expand Down
10 changes: 8 additions & 2 deletions packages/next/src/shared/lib/hash.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// http://www.cse.yorku.ca/~oz/hash.html
// More specifically, 32-bit hash via djbxor
// (ref: https://gist.github.com/eplawless/52813b1d8ad9af510d85?permalink_comment_id=3367765#gistcomment-3367765)
// This is due to number type differences between rust for turbopack to js number types,
// where rust does not have easy way to repreesnt js's 53-bit float number type for the matching
// overflow behavior. This is more `correct` in terms of having canonical hash across different runtime / implementation
// as can gaurantee determinstic output from 32bit hash.
export function djb2Hash(str: string) {
let hash = 5381
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i)
hash = (hash << 5) + hash + char
hash = ((hash << 5) + hash + char) & 0xffffffff
}
return Math.abs(hash)
return hash >>> 0
}

export function hexHash(str: string) {
Expand Down
27 changes: 23 additions & 4 deletions packages/next/src/trace/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
import { trace, flushAllTraces, Span, SpanStatus } from './trace'
import type { SpanId } from './shared'
import {
trace,
exportTraceState,
flushAllTraces,
getTraceEvents,
initializeTraceState,
recordTraceEvents,
Span,
SpanStatus,
} from './trace'
import { setGlobal } from './shared'
import type { SpanId, TraceEvent, TraceState } from './types'

export { trace, flushAllTraces, Span, setGlobal, SpanStatus }
export type { SpanId }
export {
trace,
exportTraceState,
flushAllTraces,
getTraceEvents,
initializeTraceState,
recordTraceEvents,
Span,
setGlobal,
SpanStatus,
}
export type { SpanId, TraceEvent, TraceState }
Loading

0 comments on commit 99f621e

Please sign in to comment.