Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: next dev with edge runtime on windows #56502

Merged
merged 12 commits into from Oct 10, 2023
3 changes: 0 additions & 3 deletions .github/actions/next-stats-action/src/index.js
Expand Up @@ -127,9 +127,6 @@ if (!allowedActions.has(actionInfo.actionName) && !actionInfo.isRelease) {
)
.catch(console.error)

console.log(await exec(`ls ${path.join(__dirname, '../native')}`))
console.log(await exec(`cd ${dir} && ls ${dir}/packages/next-swc/native`))

logger(`Linking packages in ${dir}`)
const isMainRepo = dir === mainRepoDir
const pkgPaths = await linkPackages({
Expand Down
146 changes: 73 additions & 73 deletions azure-pipelines.yml
Expand Up @@ -111,76 +111,76 @@ stages:
env:
NEXT_TEST_MODE: 'dev'

# - job: test_e2e_dev
# pool:
# vmImage: 'windows-2019'
# steps:
# - task: NodeTool@0
# inputs:
# versionSpec: $(node_16_version)
# displayName: 'Install Node.js'

# - bash: |
# node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No"
# displayName: 'Check Docs Only Change'

# - script: corepack enable
# condition: eq(variables['isDocsOnly'], 'No')
# displayName: 'Enable Corepack'

# - script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
# condition: eq(variables['isDocsOnly'], 'No')

# - script: pnpm store path
# condition: eq(variables['isDocsOnly'], 'No')

# - script: pnpm install && pnpm run build
# condition: eq(variables['isDocsOnly'], 'No')
# displayName: 'Install and build'

# - script: npx playwright@1.35.1 install chromium
# condition: eq(variables['isDocsOnly'], 'No')

# - script: |
# node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts
# condition: eq(variables['isDocsOnly'], 'No')
# displayName: 'Run tests (E2E Development)'
# env:
# NEXT_TEST_MODE: 'dev'

# - job: test_e2e_prod
# pool:
# vmImage: 'windows-2019'
# steps:
# - task: NodeTool@0
# inputs:
# versionSpec: $(node_16_version)
# displayName: 'Install Node.js'

# - bash: |
# node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No"
# displayName: 'Check Docs Only Change'

# - script: corepack enable
# condition: eq(variables['isDocsOnly'], 'No')
# displayName: 'Enable Corepack'

# - script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
# condition: eq(variables['isDocsOnly'], 'No')

# - script: pnpm store path
# condition: eq(variables['isDocsOnly'], 'No')

# - script: pnpm install && pnpm run build
# condition: eq(variables['isDocsOnly'], 'No')
# displayName: 'Install and build'

# - script: npx playwright@1.35.1 install chromium
# condition: eq(variables['isDocsOnly'], 'No')

# - script: |
# node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts
# condition: eq(variables['isDocsOnly'], 'No')
# displayName: 'Run tests (E2E Production)'
# env:
# NEXT_TEST_MODE: 'start'
- job: test_e2e_dev
pool:
vmImage: 'windows-2019'
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_16_version)
displayName: 'Install Node.js'

- bash: |
node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No"
displayName: 'Check Docs Only Change'

- script: corepack enable
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Enable Corepack'

- script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm store path
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm install && pnpm run build
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Install and build'

- script: npx playwright@1.35.1 install chromium
condition: eq(variables['isDocsOnly'], 'No')

- script: |
node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts test/e2e/app-dir/app-edge/app-edge.test.ts
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Run tests (E2E Development)'
env:
NEXT_TEST_MODE: 'dev'

- job: test_e2e_prod
pool:
vmImage: 'windows-2019'
steps:
- task: NodeTool@0
inputs:
versionSpec: $(node_16_version)
displayName: 'Install Node.js'

- bash: |
node scripts/run-for-change.js --not --type docs --exec echo "##vso[task.setvariable variable=isDocsOnly]No"
displayName: 'Check Docs Only Change'

- script: corepack enable
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Enable Corepack'

- script: pnpm config set store-dir $(PNPM_CACHE_FOLDER)
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm store path
condition: eq(variables['isDocsOnly'], 'No')

- script: pnpm install && pnpm run build
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Install and build'

- script: npx playwright@1.35.1 install chromium
condition: eq(variables['isDocsOnly'], 'No')

- script: |
node run-tests.js -c 1 --debug test/e2e/app-dir/app/index.test.ts test/e2e/app-dir/app-edge/app-edge.test.ts
condition: eq(variables['isDocsOnly'], 'No')
displayName: 'Run tests (E2E Production)'
env:
NEXT_TEST_MODE: 'start'
41 changes: 27 additions & 14 deletions packages/next/src/build/webpack-config.ts
Expand Up @@ -822,28 +822,41 @@ export default async function getBaseWebpackConfig(
'next/dist/server': 'next/dist/esm/server',

// Alias the usage of next public APIs
[`${NEXT_PROJECT_ROOT}/server`]:
[path.join(NEXT_PROJECT_ROOT, 'server')]:
'next/dist/esm/server/web/exports/index',
[`${NEXT_PROJECT_ROOT}/dist/client/link`]:
[path.join(NEXT_PROJECT_ROOT_DIST, 'client', 'link')]:
'next/dist/esm/client/link',
[`${NEXT_PROJECT_ROOT}/dist/shared/lib/image-external`]:
'next/dist/esm/shared/lib/image-external',
[`${NEXT_PROJECT_ROOT}/dist/client/script`]:
[path.join(
NEXT_PROJECT_ROOT,
'dist',
'shared',
'lib',
'image-external'
)]: 'next/dist/esm/shared/lib/image-external',
[path.join(NEXT_PROJECT_ROOT_DIST, 'client', 'script')]:
'next/dist/esm/client/script',
[`${NEXT_PROJECT_ROOT}/dist/client/router`]:
[path.join(NEXT_PROJECT_ROOT_DIST, 'client', 'router')]:
'next/dist/esm/client/router',
[`${NEXT_PROJECT_ROOT}/dist/shared/lib/head`]:
[path.join(NEXT_PROJECT_ROOT_DIST, 'shared', 'lib', 'head')]:
'next/dist/esm/shared/lib/head',
[`${NEXT_PROJECT_ROOT}/dist/shared/lib/dynamic`]:
[path.join(NEXT_PROJECT_ROOT_DIST, 'shared', 'lib', 'dynamic')]:
'next/dist/esm/shared/lib/dynamic',
[`${NEXT_PROJECT_ROOT}/dist/pages/_document`]:
[path.join(NEXT_PROJECT_ROOT_DIST, 'pages', '_document')]:
'next/dist/esm/pages/_document',
[`${NEXT_PROJECT_ROOT}/dist/pages/_app`]:
[path.join(NEXT_PROJECT_ROOT_DIST, 'pages', '_app')]:
'next/dist/esm/pages/_app',
[`${NEXT_PROJECT_ROOT}/dist/client/components/navigation`]:
'next/dist/esm/client/components/navigation',
[`${NEXT_PROJECT_ROOT}/dist/client/components/headers`]:
'next/dist/esm/client/components/headers',
[path.join(
NEXT_PROJECT_ROOT_DIST,
'client',
'components',
'navigation'
)]: 'next/dist/esm/client/components/navigation',
[path.join(
NEXT_PROJECT_ROOT_DIST,
'client',
'components',
'headers'
)]: 'next/dist/esm/client/components/headers',
}
: undefined),

Expand Down
12 changes: 11 additions & 1 deletion test/e2e/app-dir/app-edge/app-edge.test.ts
Expand Up @@ -55,12 +55,22 @@ createNextDescribe(
next.on('stderr', (log) => {
logs.push(log)
})
await next.render('app-edge')
await next.render('/app-edge')
expect(
logs.some((log) => log.includes(`Attempted import error:`))
).toBe(false)
})

it('should resolve client component without error', async () => {
const logs = []
next.on('stderr', (log) => {
logs.push(log)
})
const html = await next.render('/with-client')
expect(html).toContain('My Button')
expect(logs).toEqual([])
})

it('should handle edge rsc hmr', async () => {
const pageFile = 'app/edge/basic/page.tsx'
const content = await next.readFile(pageFile)
Expand Down
13 changes: 13 additions & 0 deletions test/e2e/app-dir/app-edge/app/with-client/page.tsx
@@ -0,0 +1,13 @@
import Button from '../../components/button'
import React from 'react'

export const runtime = 'edge'

export default function Home() {
return (
<>
<h1>Import a client component</h1>
<Button />
</>
)
}
9 changes: 9 additions & 0 deletions test/e2e/app-dir/app-edge/components/button.tsx
@@ -0,0 +1,9 @@
'use client'
import { useRouter } from 'next/navigation'
import React from 'react'

export default function Button() {
const router = useRouter()
const onClick = () => router.push('/')
return <button onClick={onClick}>My Button</button>
}