Skip to content

Commit

Permalink
Merge branch 'canary' into jrl-update-turbopack
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Sep 2, 2023
2 parents 046452e + 125605c commit 1a5e4d5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 69 deletions.
51 changes: 27 additions & 24 deletions packages/next/src/cli/next-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { getProjectDir } from '../lib/get-project-dir'
import { CONFIG_FILES, PHASE_DEVELOPMENT_SERVER } from '../shared/lib/constants'
import path from 'path'
import { NextConfigComplete } from '../server/config-shared'
import { traceGlobals } from '../trace/shared'
import { setGlobal, traceGlobals } from '../trace/shared'
import { Telemetry } from '../telemetry/storage'
import loadConfig from '../server/config'
import { findPagesDir } from '../lib/find-pages-dir'
Expand All @@ -27,6 +27,7 @@ import type { ChildProcess } from 'child_process'
import { checkIsNodeDebugging } from '../server/lib/is-node-debugging'
import { createSelfSignedCertificate } from '../lib/mkcert'
import uploadTrace from '../trace/upload-trace'
import { trace } from '../trace'

let dir: string
let config: NextConfigComplete
Expand Down Expand Up @@ -90,19 +91,13 @@ const handleSessionStop = async () => {
}

if (traceUploadUrl) {
if (isTurboSession) {
console.warn(
'Uploading traces with Turbopack is not yet supported. Skipping sending trace.'
)
} else {
uploadTrace({
traceUploadUrl,
mode: 'dev',
isTurboSession,
projectDir: dir,
distDir: config.distDir,
})
}
uploadTrace({
traceUploadUrl,
mode: 'dev',
isTurboSession,
projectDir: dir,
distDir: config.distDir,
})
}

// ensure we re-enable the terminal cursor before exiting
Expand Down Expand Up @@ -330,6 +325,10 @@ const nextDev: CliCommand = async (argv) => {
process.env.EXPERIMENTAL_TURBOPACK = '1'
}

const distDir = path.join(dir, config.distDir ?? '.next')
setGlobal('phase', PHASE_DEVELOPMENT_SERVER)
setGlobal('distDir', distDir)

if (process.env.TURBOPACK) {
isTurboSession = true

Expand All @@ -339,7 +338,6 @@ const nextDev: CliCommand = async (argv) => {
require('../build/swc') as typeof import('../build/swc')
const { eventCliSession } =
require('../telemetry/events/version') as typeof import('../telemetry/events/version')
const { setGlobal } = require('../trace') as typeof import('../trace')
require('../telemetry/storage') as typeof import('../telemetry/storage')
const findUp =
require('next/dist/compiled/find-up') as typeof import('next/dist/compiled/find-up')
Expand All @@ -351,7 +349,6 @@ const nextDev: CliCommand = async (argv) => {
isDev: true,
})

const distDir = path.join(dir, rawNextConfig.distDir || '.next')
const { pagesDir, appDir } = findPagesDir(dir)
const telemetry = new Telemetry({
distDir,
Expand Down Expand Up @@ -380,15 +377,19 @@ const nextDev: CliCommand = async (argv) => {
// Turbopack need to be in control over reading the .env files and watching them.
// So we need to start with a initial env to know which env vars are coming from the user.
resetEnv()
let bindings = await loadBindings()
let server
trace('start-dev-server').traceAsyncFn(async (_) => {
let bindings = await loadBindings()

server = bindings.turbo.startDev({
...devServerOptions,
showAll: args['--show-all'] ?? false,
root: args['--root'] ?? findRootDir(dir),
})

let server = bindings.turbo.startDev({
...devServerOptions,
showAll: args['--show-all'] ?? false,
root: args['--root'] ?? findRootDir(dir),
// Start preflight after server is listening and ignore errors:
preflight(false).catch(() => {})
})
// Start preflight after server is listening and ignore errors:
preflight(false).catch(() => {})

if (!isCustomTurbopack) {
await telemetry.flush()
Expand Down Expand Up @@ -468,7 +469,9 @@ const nextDev: CliCommand = async (argv) => {
}
})

runningServer = await runDevServer(false)
await trace('start-dev-server').traceAsyncFn(async (_) => {
runningServer = await runDevServer(false)
})
}
}

Expand Down
30 changes: 0 additions & 30 deletions packages/next/src/shared/lib/flatten.ts

This file was deleted.

30 changes: 18 additions & 12 deletions packages/next/src/shared/lib/page-path/get-page-paths.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { denormalizePagePath } from './denormalize-page-path'
import { flatten } from '../flatten'
import path from '../isomorphic/path'

/**
Expand All @@ -8,7 +7,8 @@ import path from '../isomorphic/path'
* and to debug inspected locations.
*
* For pages, map `/route` to [`/route.[ext]`, `/route/index.[ext]`]
* For app paths, map `/route/page` to [`/route/page.[ext]`]
* For app paths, map `/route/page` to [`/route/page.[ext]`] or `/route/route`
* to [`/route/route.[ext]`]
*
* @param normalizedPagePath Normalized page path (it will denormalize).
* @param extensions Allowed extensions.
Expand All @@ -20,15 +20,21 @@ export function getPagePaths(
) {
const page = denormalizePagePath(normalizedPagePath)

return flatten(
extensions.map((extension) => {
const appPage = `${page}.${extension}`
const folderIndexPage = path.join(page, `index.${extension}`)
let prefixes: string[]
if (isAppDir) {
prefixes = [page]
} else if (normalizedPagePath.endsWith('/index')) {
prefixes = [path.join(page, 'index')]
} else {
prefixes = [page, path.join(page, 'index')]
}

if (!normalizedPagePath.endsWith('/index')) {
return isAppDir ? [appPage] : [`${page}.${extension}`, folderIndexPage]
}
return [isAppDir ? appPage : folderIndexPage]
})
)
const paths: string[] = []
for (const extension of extensions) {
for (const prefix of prefixes) {
paths.push(`${prefix}.${extension}`)
}
}

return paths
}
5 changes: 2 additions & 3 deletions packages/next/src/shared/lib/page-path/normalize-page-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@ import { NormalizeError } from '../utils'
* - `/index` -> `/index/index`
*/
export function normalizePagePath(page: string): string {
const normalized = ensureLeadingSlash(
const normalized =
/^\/index(\/|$)/.test(page) && !isDynamicRoute(page)
? `/index${page}`
: page === '/'
? '/index'
: page
)
: ensureLeadingSlash(page)

if (process.env.NEXT_RUNTIME !== 'edge') {
const { posix } = require('path')
Expand Down

0 comments on commit 1a5e4d5

Please sign in to comment.