Unverified Commit e57b2091 authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Bring over fixes from #15185 (#15326)

Co-authored-by: 's avatarJoe Haddad <joe.haddad@zeit.co>
parent a26c69d1
...@@ -944,7 +944,8 @@ export default async function getBaseWebpackConfig( ...@@ -944,7 +944,8 @@ export default async function getBaseWebpackConfig(
new ProfilingPlugin({ new ProfilingPlugin({
tracer, tracer,
}), }),
config.experimental.modern && !isWebpack5 &&
config.experimental.modern &&
!isServer && !isServer &&
!dev && !dev &&
(() => { (() => {
......
...@@ -102,6 +102,7 @@ export class DropClientPage implements Plugin { ...@@ -102,6 +102,7 @@ export class DropClientPage implements Plugin {
// @ts-ignore TODO: webpack 5 types // @ts-ignore TODO: webpack 5 types
const module = compilation.moduleGraph.getModule(dependency) const module = compilation.moduleGraph.getModule(dependency)
if (module?.buildInfo?.NEXT_ampFirst) { if (module?.buildInfo?.NEXT_ampFirst) {
ampFirstEntryNamesItem.push(name)
// @ts-ignore @types/webpack has outdated types for webpack 5 // @ts-ignore @types/webpack has outdated types for webpack 5
compilation.entries.delete(name) compilation.entries.delete(name)
} }
......
...@@ -41,7 +41,11 @@ async function tryApplyUpdates() { ...@@ -41,7 +41,11 @@ async function tryApplyUpdates() {
const res = await fetch(`${hotUpdatePath}${curHash}.hot-update.json`) const res = await fetch(`${hotUpdatePath}${curHash}.hot-update.json`)
const jsonData = await res.json() const jsonData = await res.json()
const curPage = page === '/' ? 'index' : page const curPage = page === '/' ? 'index' : page
const pageUpdated = Object.keys(jsonData.c).some((mod) => { // webpack 5 uses an array instead
const pageUpdated = (Array.isArray(jsonData.c)
? jsonData.c
: Object.keys(jsonData.c)
).some((mod) => {
return ( return (
mod.indexOf( mod.indexOf(
`pages${curPage.substr(0, 1) === '/' ? curPage : `/${curPage}`}` `pages${curPage.substr(0, 1) === '/' ? curPage : `/${curPage}`}`
......
...@@ -6,6 +6,7 @@ import { ...@@ -6,6 +6,7 @@ import {
// @ts-ignore exists in webpack 5 // @ts-ignore exists in webpack 5
RuntimeGlobals, RuntimeGlobals,
version, version,
// @ts-ignore exists in webpack 5
compilation as Compilation, compilation as Compilation,
} from 'webpack' } from 'webpack'
......
import { loader } from 'webpack' import {
// @ts-ignore exists in webpack 5
loader,
} from 'webpack'
import RefreshModuleRuntime from './internal/ReactRefreshModule.runtime' import RefreshModuleRuntime from './internal/ReactRefreshModule.runtime'
let refreshModuleRuntime = RefreshModuleRuntime.toString() let refreshModuleRuntime = RefreshModuleRuntime.toString()
......
...@@ -172,7 +172,8 @@ describe('CSS Module client-side navigation in Production', () => { ...@@ -172,7 +172,8 @@ describe('CSS Module client-side navigation in Production', () => {
}) })
}) })
describe('CSS Module client-side navigation in Production (Modern)', () => { // TODO: Make webpack 5 work with nest-esm-plugin
describe.skip('CSS Module client-side navigation in Production (Modern)', () => {
const appDir = join(fixturesDir, 'multi-module-modern') const appDir = join(fixturesDir, 'multi-module-modern')
beforeAll(async () => { beforeAll(async () => {
......
...@@ -519,7 +519,8 @@ function runTests(dev) { ...@@ -519,7 +519,8 @@ function runTests(dev) {
} }
}) })
} else { } else {
it('should output modern bundles with dynamic route correctly', async () => { // TODO: Make webpack 5 work with nest-esm-plugin
it.skip('should output modern bundles with dynamic route correctly', async () => {
const buildManifest = require(join('../.next', 'build-manifest.json')) const buildManifest = require(join('../.next', 'build-manifest.json'))
const files = buildManifest.pages[ const files = buildManifest.pages[
......
...@@ -5,12 +5,19 @@ import { findPort, killApp, launchApp, nextBuild } from 'next-test-utils' ...@@ -5,12 +5,19 @@ import { findPort, killApp, launchApp, nextBuild } from 'next-test-utils'
import webdriver from 'next-webdriver' import webdriver from 'next-webdriver'
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir' import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
import { join } from 'path' import { join } from 'path'
import { version } from 'webpack'
const isWebpack5 = parseInt(version) === 5
jest.setTimeout(1000 * 60 * 1) jest.setTimeout(1000 * 60 * 1)
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
describe('Legacy Sass Support Should Disable New CSS', () => { // TODO: Make legacy Sass support work with webpack 5
const describeFn = isWebpack5 ? describe.skip : describe
// TODO: Make legacy Sass support work with webpack 5
describeFn('Legacy Sass Support Should Disable New CSS', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
await nextBuild(appDir) await nextBuild(appDir)
...@@ -26,7 +33,7 @@ describe('Legacy Sass Support Should Disable New CSS', () => { ...@@ -26,7 +33,7 @@ describe('Legacy Sass Support Should Disable New CSS', () => {
}) })
}) })
describe('Legacy Sass Support should work in development', () => { describeFn('Legacy Sass Support should work in development', () => {
beforeAll(async () => { beforeAll(async () => {
await remove(join(appDir, '.next')) await remove(join(appDir, '.next'))
}) })
......
...@@ -19,7 +19,8 @@ let appDir = join(__dirname, '..') ...@@ -19,7 +19,8 @@ let appDir = join(__dirname, '..')
let server let server
let appPort let appPort
describe('Modern Mode', () => { // TODO: Make webpack 5 work with nest-esm-plugin
describe.skip('Modern Mode', () => {
beforeAll(async () => { beforeAll(async () => {
await runNextCommand(['build'], { await runNextCommand(['build'], {
cwd: appDir, cwd: appDir,
......
...@@ -15,7 +15,7 @@ jest.setTimeout(1000 * 60 * 3) ...@@ -15,7 +15,7 @@ jest.setTimeout(1000 * 60 * 3)
const appDir = join(__dirname, '../') const appDir = join(__dirname, '../')
describe('no duplicate compile error output', () => { describe('no duplicate compile error output', () => {
it('show not show compile error on page refresh', async () => { it('should not show compile error on page refresh', async () => {
let stdout = '' let stdout = ''
let stderr = '' let stderr = ''
......
...@@ -7,7 +7,8 @@ const appDir = join(__dirname, '../') ...@@ -7,7 +7,8 @@ const appDir = join(__dirname, '../')
const profileEventsPath = join(appDir, '.next', 'profile-events.json') const profileEventsPath = join(appDir, '.next', 'profile-events.json')
jest.setTimeout(1000 * 60 * 5) jest.setTimeout(1000 * 60 * 5)
describe('Profiling Usage', () => { // TODO: Make profiling experimental flag work with webpack 5
describe.skip('Profiling Usage', () => {
beforeAll(async () => { beforeAll(async () => {
// Delete file if it already exists // Delete file if it already exists
if (await fs.existsSync(profileEventsPath)) if (await fs.existsSync(profileEventsPath))
......
module.exports = {
experimental: { modern: true },
}
// Below type error is intentional, it helps check typescript → ignoreDevErrors / ignoreBuildErrors flags in next.config.js // Below type error is intentional, it helps check typescript → ignoreBuildErrors flags in next.config.js
export default (): boolean => 'Index page' export default (): boolean => 'Index page'
/* eslint-env jest */ /* eslint-env jest */
import { join } from 'path' import { join } from 'path'
import { import { nextBuild, File } from 'next-test-utils'
renderViaHTTP,
nextBuild,
findPort,
launchApp,
killApp,
File,
} from 'next-test-utils'
jest.setTimeout(1000 * 60 * 2) jest.setTimeout(1000 * 60 * 2)
...@@ -18,71 +11,40 @@ const nextConfigFile = new File(join(appDir, 'next.config.js')) ...@@ -18,71 +11,40 @@ const nextConfigFile = new File(join(appDir, 'next.config.js'))
describe('TypeScript with error handling options', () => { describe('TypeScript with error handling options', () => {
// Dev can no longer show errors (for now), logbox will cover this in the // Dev can no longer show errors (for now), logbox will cover this in the
// future. // future.
for (const ignoreDevErrors of [/*false,*/ true]) { for (const ignoreBuildErrors of [false, true]) {
for (const ignoreBuildErrors of [false, true]) { describe(`ignoreBuildErrors: ${ignoreBuildErrors}`, () => {
describe(`ignoreDevErrors: ${ignoreDevErrors}, ignoreBuildErrors: ${ignoreBuildErrors}`, () => { beforeAll(() => {
beforeAll(() => { const nextConfig = {
const nextConfig = { typescript: { ignoreBuildErrors },
experimental: { modern: true }, }
typescript: { ignoreDevErrors, ignoreBuildErrors }, nextConfigFile.write('module.exports = ' + JSON.stringify(nextConfig))
} })
nextConfigFile.write('module.exports = ' + JSON.stringify(nextConfig)) afterAll(() => {
}) nextConfigFile.restore()
afterAll(() => { })
nextConfigFile.restore()
})
it(
ignoreDevErrors
? 'Next renders the page in dev despite type errors'
: 'Next dev does not render the page in dev because of type errors',
async () => {
let app
let output = ''
try {
const appPort = await findPort()
app = await launchApp(appDir, appPort, {
onStdout: (msg) => (output += msg),
onStderr: (msg) => (output += msg),
})
await renderViaHTTP(appPort, '')
if (ignoreDevErrors) {
expect(output).not.toContain('waiting for typecheck results...')
expect(output).not.toContain("not assignable to type 'boolean'")
} else {
expect(output).toContain('waiting for typecheck results...')
expect(output).toContain("not assignable to type 'boolean'")
}
} finally {
await killApp(app)
}
}
)
it(
ignoreBuildErrors
? 'Next builds the application despite type errors'
: 'Next fails to build the application despite type errors',
async () => {
const { stdout, stderr } = await nextBuild(appDir, [], {
stdout: true,
stderr: true,
})
if (ignoreBuildErrors) { it(
expect(stdout).toContain('Compiled successfully') ignoreBuildErrors
expect(stderr).not.toContain('Failed to compile.') ? 'Next builds the application despite type errors'
expect(stderr).not.toContain("not assignable to type 'boolean'") : 'Next fails to build the application despite type errors',
} else { async () => {
expect(stdout).not.toContain('Compiled successfully') const { stdout, stderr } = await nextBuild(appDir, [], {
expect(stderr).toContain('Failed to compile.') stdout: true,
expect(stderr).toContain('./pages/index.tsx:2:31') stderr: true,
expect(stderr).toContain("not assignable to type 'boolean'") })
}
if (ignoreBuildErrors) {
expect(stdout).toContain('Compiled successfully')
expect(stderr).not.toContain('Failed to compile.')
expect(stderr).not.toContain("not assignable to type 'boolean'")
} else {
expect(stdout).not.toContain('Compiled successfully')
expect(stderr).toContain('Failed to compile.')
expect(stderr).toContain('./pages/index.tsx:2:31')
expect(stderr).toContain("not assignable to type 'boolean'")
} }
) }
}) )
} })
} }
}) })
...@@ -9,7 +9,8 @@ const context = {} ...@@ -9,7 +9,8 @@ const context = {}
jest.setTimeout(1000 * 60 * 2) jest.setTimeout(1000 * 60 * 2)
describe('Web Workers with Fast Refresh', () => { // TODO: Upgrade worker-loader when it's published with webpack 5 support
describe.skip('Web Workers with Fast Refresh', () => {
beforeAll(async () => { beforeAll(async () => {
context.appPort = await findPort() context.appPort = await findPort()
context.server = await launchApp(appDir, context.appPort) context.server = await launchApp(appDir, context.appPort)
......
...@@ -24,7 +24,7 @@ export function initNextServerScript( ...@@ -24,7 +24,7 @@ export function initNextServerScript(
opts opts
) { ) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const instance = spawn('node', [scriptPath], { env }) const instance = spawn('node', ['--no-deprecation', scriptPath], { env })
function handleStdout(data) { function handleStdout(data) {
const message = data.toString() const message = data.toString()
...@@ -99,7 +99,7 @@ export function runNextCommand(argv, options = {}) { ...@@ -99,7 +99,7 @@ export function runNextCommand(argv, options = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
console.log(`Running command "next ${argv.join(' ')}"`) console.log(`Running command "next ${argv.join(' ')}"`)
const instance = spawn('node', [nextBin, ...argv], { const instance = spawn('node', ['--no-deprecation', nextBin, ...argv], {
...options.spawnOptions, ...options.spawnOptions,
cwd, cwd,
env, env,
...@@ -159,7 +159,11 @@ export function runNextCommandDev(argv, stdOut, opts = {}) { ...@@ -159,7 +159,11 @@ export function runNextCommandDev(argv, stdOut, opts = {}) {
} }
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const instance = spawn('node', ['dist/bin/next', ...argv], { cwd, env }) const instance = spawn(
'node',
['--no-deprecation', 'dist/bin/next', ...argv],
{ cwd, env }
)
let didResolve = false let didResolve = false
function handleStdout(data) { function handleStdout(data) {
...@@ -246,7 +250,7 @@ export function buildTS(args = [], cwd, env = {}) { ...@@ -246,7 +250,7 @@ export function buildTS(args = [], cwd, env = {}) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const instance = spawn( const instance = spawn(
'node', 'node',
[require.resolve('typescript/lib/tsc'), ...args], ['--no-deprecation', require.resolve('typescript/lib/tsc'), ...args],
{ cwd, env } { cwd, env }
) )
let output = '' let output = ''
......
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