Unverified Commit 0683859c authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Migrate app-dir-export test to be isolated (#86534)

Flakey:
```
❌ test/integration/app-dir-export/test/start.test.ts output:
HEADLESS=true NEXT_TELEMETRY_DISABLED=1 CI= NEXT_TEST_CI=true IS_RETRY=undefined TRACE_PLAYWRIGHT=true CIRCLECI= GITHUB_ACTIONS= CONTINUOUS_INTEGRATION= RUN_ID= BUILD_NUMBER= JEST_JUNIT_OUTPUT_NAME=test_integration_app-dir-export_test_start.test.ts JEST_SUITE_NAME=default:12/13:integration:test/integration/app-dir-export/test/start.test.ts /root/actions-runner/_work/next.js/next.js/node_modules/.bin/jest '--ci' '--runInBand' '--forceExit' '--verbose' '--json' '--outputFile=test/integration/app-dir-export/test/start.test.ts.results.json' 'test/integration/app-dir-export/test/start.test.ts'
[08:48:33.323Z] Running command "next build /root/actions-runner/_work/next.js/next.js/test/integration/app-dir-export"
▲ Next.js 16.1.0-canary.1
- Local:         http://[::1]:36371
- Network:       http://[::]:36371

✓ Starting...
Error: "next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.
    at <unknown> (dist/server/next.js:230:53)
    at async NextServer.prepare (dist/server/next.js:177:24)
    at async initializeImpl (dist/server/lib/render-server.js:132:5)
    at async initialize (dist/server/lib/router-server.js:538:22)
    at async Server.<anonymous> (dist/server/lib/start-server.js:381:36)
[08:49:12.558Z] Running command "next build /root/actions-runner/_work/next.js/next.js/test/integration/app-dir-export"
FAIL webpack test/integration/app-dir-export/test/start.test.ts (100.119 s)
  app dir - with output export (next start)
    production mode
      ✓ should error during next start with output export (39235 ms)
      ✕ should warn during next start with output standalone (60029 ms)

  ● app dir - with output export (next start) › production mode › should warn during next start with output standalone

    thrown: "Exceeded timeout of 60000 ms for a test.
    Add a timeout value to this test to increase the timeout, if this is a long-running test. See https://jestjs.io/docs/api#testname-fn-timeout."

      46 |
      47 |       // TODO: Move this test to test/production to run in isolation.
    > 48 |       ;(process.env.TURBOPACK_BUILD ? it.skip : it)(
         |                                                  ^
      49 |         'should warn during next start with output standalone',
      50 |         async () => {
      51 |           nextConfig.replace(`output: 'export'`, `output: 'standalone'`)

      at integration/app-dir-export/test/start.test.ts:48:50
      at integration/app-dir-export/test/start.test.ts:21:56
      at Object.describe (integration/app-dir-export/test/start.test.ts:20:1)

```
parent f71ce534
...@@ -290,6 +290,13 @@ ...@@ -290,6 +290,13 @@
"test/e2e/app-dir/use-selected-layout-segment-s/use-selected-layout-segment-s.test.ts", "test/e2e/app-dir/use-selected-layout-segment-s/use-selected-layout-segment-s.test.ts",
"test/e2e/app-dir/use-server-inserted-html/use-server-inserted-html.test.ts", "test/e2e/app-dir/use-server-inserted-html/use-server-inserted-html.test.ts",
"test/e2e/app-dir/with-exported-function-config/with-exported-function-config.test.ts", "test/e2e/app-dir/with-exported-function-config/with-exported-function-config.test.ts",
"test/e2e/app-dir-export/test/config.test.ts",
"test/e2e/app-dir-export/test/dev-custom-dist-dir.test.ts",
"test/e2e/app-dir-export/test/dynamic-missing-gsp.test.ts",
"test/e2e/app-dir-export/test/dynamicapiroute.test.ts",
"test/e2e/app-dir-export/test/dynamicpage.test.ts",
"test/e2e/app-dir-export/test/start.test.ts",
"test/e2e/app-dir-export/test/trailing-slash.test.ts",
"test/e2e/app-document/client.test.ts", "test/e2e/app-document/client.test.ts",
"test/e2e/app-document/csp.test.ts", "test/e2e/app-document/csp.test.ts",
"test/e2e/app-document/index.test.ts", "test/e2e/app-document/index.test.ts",
......
import { runNextCommand } from 'next-test-utils'
import { join } from 'path'
import { expectedWhenTrailingSlashTrue, getFiles } from './utils'
import { FileRef, isNextStart, nextTestSetup, PatchedFileRef } from 'e2e-utils'
describe('app dir - with output export', () => {
if (isNextStart) {
describe('with exportPathMap configured', () => {
let { next } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, '..', 'app')),
'next.config.js': new PatchedFileRef(
join(__dirname, '..', 'next.config.js'),
(content) =>
content.replace(
'trailingSlash: true,',
`trailingSlash: true,
exportPathMap: async function (map) {
return map
},`
)
),
},
skipStart: true,
})
it('should throw', async () => {
let { exitCode, cliOutput } = await next.build()
expect(exitCode).toBe(1)
expect(cliOutput).toContain(
'The "exportPathMap" configuration cannot be used with the "app" directory. Please use generateStaticParams() instead.'
)
})
})
describe('without next config', () => {
let { next } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, '..', 'app')),
},
skipStart: true,
})
it('should error when running next export', async () => {
let { exitCode } = await next.build()
expect(exitCode).toBe(0)
expect(await getFiles(join(next.testDir, 'out'))).toEqual([])
let stdout = ''
let stderr = ''
let error = undefined
try {
await runNextCommand(['export'], {
cwd: next.testDir,
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
})
} catch (e) {
error = e
}
expect(error).toBeDefined()
expect(stderr).toContain(
`\`next export\` has been removed in favor of 'output: export' in next.config.js`
)
expect(stdout).not.toContain('Export successful. Files written to')
expect(await getFiles(join(next.testDir, 'out'))).toEqual([])
})
})
describe('with distDir configured', () => {
let { next } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, '..', 'app')),
'next.config.js': new PatchedFileRef(
join(__dirname, '..', 'next.config.js'),
(content) =>
content.replace(
'trailingSlash: true,',
`trailingSlash: true,
distDir: 'output',`
)
),
},
skipStart: true,
})
it('should correctly emit exported assets to config.distDir', async () => {
let { exitCode } = await next.build()
expect(exitCode).toBe(0)
expect(await getFiles(join(next.testDir, 'output'))).toEqual(
expectedWhenTrailingSlashTrue
)
})
})
} else {
it('skipped in dev', () => {})
}
})
import { join } from 'path'
import { FileRef, isNextDev, nextTestSetup, PatchedFileRef } from 'e2e-utils'
describe('app dir - with output export and custom distDir in dev', () => {
if (isNextDev) {
const { next } = nextTestSetup({
files: {
app: new FileRef(join(__dirname, '..', 'app')),
'next.config.js': new PatchedFileRef(
join(__dirname, '..', 'next.config.js'),
(content) => content.replace('// distDir', 'distDir')
),
},
})
it('should render properly in dev', async () => {
expect(next.distDir).toContain('.next-custom')
const res = await next.render('/')
expect(res).toContain('Home')
})
} else {
it('skipped in prod', () => {})
}
})
import { isNextDev } from 'e2e-utils'
import { runTests } from './utils'
describe('app dir - with output export - dynamic missing gsp', () => {
describe('should error when dynamic route is missing generateStaticParams', () => {
runTests({
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set noop',
expectedErrMsg: isNextDev
? 'Page "/another/[slug]/page" is missing exported function "generateStaticParams()", which is required with "output: export" config.'
: 'Page "/another/[slug]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.',
})
})
describe('should error when client component has generateStaticParams', () => {
const expectedErrMsg = process.env.IS_TURBOPACK_TEST
? 'App pages cannot use both "use client" and export function "generateStaticParams()".'
: 'Page "/another/[slug]/page" cannot use both "use client" and export function "generateStaticParams()".'
runTests({
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set client',
expectedErrMsg: expectedErrMsg,
})
})
if (isNextDev) {
describe('should error when dynamic route is set to true', () => {
runTests({
dynamicPage: 'undefined',
dynamicParams: 'true',
expectedErrMsg:
'"dynamicParams: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports',
})
})
}
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic api route', () => {
describe.each([
{
dynamicApiRoute: 'undefined',
expectedErrMsg:
'export const dynamic = "force-static"/export const revalidate not configured on route',
},
{ dynamicApiRoute: "'error'" },
{ dynamicApiRoute: "'force-static'" },
{
dynamicApiRoute: "'force-dynamic'",
expectedErrMsg:
'export const dynamic = "force-dynamic" on page "/api/json" cannot be used with "output: export".',
},
])(
'should work in prod with dynamicApiRoute $dynamicApiRoute',
({ dynamicApiRoute, expectedErrMsg }) => {
runTests({ dynamicApiRoute, expectedErrMsg })
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic api route', () => {
describe.each([
{ dynamicPage: 'undefined' },
{ dynamicPage: "'error'" },
{ dynamicPage: "'force-static'" },
{
dynamicPage: "'force-dynamic'",
expectedErrMsg:
'Page with `dynamic = "force-dynamic"` couldn\'t be exported. `output: "export"` requires all pages be renderable statically',
},
])(
'should work in prod with dynamicPage $dynamicPage',
({ dynamicPage, expectedErrMsg }) => {
runTests({ dynamicPage, expectedErrMsg })
}
)
})
import { join } from 'path'
import { isNextStart, nextTestSetup } from 'e2e-utils'
import { retry } from 'next-test-utils'
describe('app dir - with output export (next start)', () => {
if (isNextStart) {
const { next } = nextTestSetup({
files: join(__dirname, '..'),
skipStart: true,
})
it('should error during next start with output export', async () => {
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
try {
await next.start({ skipBuild: true })
} catch (e) {}
await retry(() => {
expect(next.cliOutput).toContain(
`"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.`
)
})
})
it('should warn during next start with output standalone', async () => {
await next.patchFile(
'next.config.js',
(content) =>
content.replace(`output: 'export'`, `output: 'standalone'`),
async () => {
const { exitCode } = await next.build()
expect(exitCode).toBe(0)
try {
await next.start({ skipBuild: true })
} catch (e) {}
await retry(() => {
expect(next.cliOutput).toContain(
`"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.`
)
})
}
)
})
} else {
it('skipped in dev', () => {})
}
})
import { runTests } from './utils'
describe('app dir - with output export - trailing slash', () => {
describe.each([{ trailingSlash: false }, { trailingSlash: true }])(
"should work in prod with trailingSlash '$trailingSlash'",
({ trailingSlash }) => {
runTests({ trailingSlash })
}
)
})
import fs from 'fs-extra'
import { nextBuild, runNextCommand } from 'next-test-utils'
import { join } from 'path'
import {
appDir,
distDir,
expectedWhenTrailingSlashTrue,
exportDir,
getFiles,
nextConfig,
} from './utils'
describe('app dir - with output export (next dev / next build)', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
it('should throw when exportPathMap configured', async () => {
nextConfig.replace(
'trailingSlash: true,',
`trailingSlash: true,
exportPathMap: async function (map) {
return map
},`
)
await fs.remove(distDir)
await fs.remove(exportDir)
let result = { code: 0, stderr: '' }
try {
result = await nextBuild(appDir, [], { stderr: true })
} finally {
nextConfig.restore()
}
expect(result.code).toBe(1)
expect(result.stderr).toContain(
'The "exportPathMap" configuration cannot be used with the "app" directory. Please use generateStaticParams() instead.'
)
})
it('should error when running next export', async () => {
await fs.remove(distDir)
await fs.remove(exportDir)
nextConfig.delete()
try {
await nextBuild(appDir)
expect(await getFiles()).toEqual([])
let stdout = ''
let stderr = ''
let error = undefined
try {
await runNextCommand(['export', appDir], {
onStdout(msg) {
stdout += msg
},
onStderr(msg) {
stderr += msg
},
})
} catch (e) {
error = e
}
expect(error).toBeDefined()
expect(stderr).toContain(
`\`next export\` has been removed in favor of 'output: export' in next.config.js`
)
expect(stdout).not.toContain('Export successful. Files written to')
expect(await getFiles()).toEqual([])
} finally {
nextConfig.restore()
await fs.remove(distDir)
await fs.remove(exportDir)
}
})
it('should correctly emit exported assets to config.distDir', async () => {
const outputDir = join(appDir, 'output')
await fs.remove(distDir)
await fs.remove(outputDir)
nextConfig.replace(
'trailingSlash: true,',
`trailingSlash: true,
distDir: 'output',`
)
try {
await nextBuild(appDir)
expect(await getFiles(outputDir)).toEqual(
expectedWhenTrailingSlashTrue
)
} finally {
nextConfig.restore()
await fs.remove(distDir)
await fs.remove(outputDir)
}
})
}
)
})
/* eslint-env jest */
import { join } from 'path'
import fs from 'fs-extra'
import {
fetchViaHTTP,
File,
findPort,
killApp,
launchApp,
} from 'next-test-utils'
const appDir = join(__dirname, '..')
const distDir = join(appDir, '.next-custom')
const nextConfig = new File(join(appDir, 'next.config.js'))
let app
let appPort
describe('app dir - with output export and custom distDir (next dev)', () => {
beforeAll(async () => {
nextConfig.replace('// distDir', 'distDir')
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
nextConfig.restore()
await fs.remove(distDir)
await killApp(app)
})
it('should render properly', async () => {
const res = await fetchViaHTTP(appPort, '/')
expect(res.status).toBe(200)
expect(await res.text()).toContain('Home')
})
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic missing gsp dev', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it('should error when dynamic route is missing generateStaticParams', async () => {
await runTests({
isDev: true,
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set noop',
expectedErrMsg:
'Page "/another/[slug]/page" is missing exported function "generateStaticParams()", which is required with "output: export" config.',
})
})
it('should error when dynamic route is set to true', async () => {
await runTests({
isDev: true,
dynamicPage: 'undefined',
dynamicParams: 'true',
expectedErrMsg:
'"dynamicParams: true" cannot be used with "output: export". See more info here: https://nextjs.org/docs/app/building-your-application/deploying/static-exports',
})
})
it('should error when client component has generateStaticParams', async () => {
const expectedErrMsg = process.env.IS_TURBOPACK_TEST
? 'App pages cannot use both "use client" and export function "generateStaticParams()".'
: 'Page "/another/[slug]/page" cannot use both "use client" and export function "generateStaticParams()".'
await runTests({
isDev: true,
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set client',
expectedErrMsg,
})
})
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic missing gsp prod', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
it('should error when dynamic route is missing generateStaticParams', async () => {
await runTests({
isDev: false,
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set noop',
expectedErrMsg:
'Page "/another/[slug]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.',
})
})
it('should error when client component has generateStaticParams', async () => {
const expectedErrMsg = process.env.IS_TURBOPACK_TEST
? 'App pages cannot use both "use client" and export function "generateStaticParams()".'
: 'Page "/another/[slug]/page" cannot use both "use client" and export function "generateStaticParams()".'
await runTests({
isDev: false,
dynamicPage: 'undefined',
generateStaticParamsOpt: 'set client',
expectedErrMsg: expectedErrMsg,
})
})
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic api route dev', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it.each([
{
dynamicApiRoute: 'undefined',
expectedErrMsg:
'export const dynamic = "force-static"/export const revalidate not configured on route',
},
{ dynamicApiRoute: "'error'" },
{ dynamicApiRoute: "'force-static'" },
{
dynamicApiRoute: "'force-dynamic'",
expectedErrMsg:
'export const dynamic = "force-dynamic" on page "/api/json" cannot be used with "output: export".',
},
])(
'should work in dev with dynamicApiRoute $dynamicApiRoute',
async ({ dynamicApiRoute, expectedErrMsg }) => {
await runTests({ isDev: true, dynamicApiRoute, expectedErrMsg })
}
)
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic api route prod', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
it.each([
{
dynamicApiRoute: 'undefined',
expectedErrMsg:
'export const dynamic = "force-static"/export const revalidate not configured on route',
},
{ dynamicApiRoute: "'error'" },
{ dynamicApiRoute: "'force-static'" },
{
dynamicApiRoute: "'force-dynamic'",
expectedErrMsg:
'export const dynamic = "force-dynamic" on page "/api/json" cannot be used with "output: export".',
},
])(
'should work in prod with dynamicApiRoute $dynamicApiRoute',
async ({ dynamicApiRoute, expectedErrMsg }) => {
await runTests({ isDev: false, dynamicApiRoute, expectedErrMsg })
}
)
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic page dev', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it.each([
{ dynamicPage: 'undefined' },
{ dynamicPage: "'error'" },
{ dynamicPage: "'force-static'" },
{
dynamicPage: "'force-dynamic'",
expectedErrMsg:
'Page with `dynamic = "force-dynamic"` couldn\'t be exported. `output: "export"` requires all pages be renderable statically',
},
])(
'should work in dev with dynamicPage $dynamicPage',
async ({ dynamicPage, expectedErrMsg }) => {
await runTests({ isDev: true, dynamicPage, expectedErrMsg })
}
)
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - dynamic api route prod', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
it.each([
{ dynamicPage: 'undefined' },
{ dynamicPage: "'error'" },
{ dynamicPage: "'force-static'" },
{
dynamicPage: "'force-dynamic'",
expectedErrMsg:
'Page with `dynamic = "force-dynamic"` couldn\'t be exported. `output: "export"` requires all pages be renderable statically',
},
])(
'should work in prod with dynamicPage $dynamicPage',
async ({ dynamicPage, expectedErrMsg }) => {
await runTests({ isDev: false, dynamicPage, expectedErrMsg })
}
)
}
)
})
/* eslint-env jest */
import { join } from 'path'
import fs from 'fs-extra'
import {
check,
File,
findPort,
killApp,
nextBuild,
nextStart,
} from 'next-test-utils'
const appDir = join(__dirname, '..')
const distDir = join(appDir, '.next')
const exportDir = join(appDir, 'out')
const nextConfig = new File(join(appDir, 'next.config.js'))
let app
describe('app dir - with output export (next start)', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
afterEach(async () => {
await killApp(app)
nextConfig.restore()
await fs.remove(distDir)
await fs.remove(exportDir)
})
it('should error during next start with output export', async () => {
const { code } = await nextBuild(appDir)
expect(code).toBe(0)
const port = await findPort()
let stderr = ''
app = await nextStart(appDir, port, {
onStderr(msg: string) {
stderr += msg || ''
},
})
await check(() => stderr, /error/i)
expect(stderr).toContain(
'"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.'
)
})
// TODO: Move this test to test/production to run in isolation.
;(process.env.TURBOPACK_BUILD ? it.skip : it)(
'should warn during next start with output standalone',
async () => {
nextConfig.replace(`output: 'export'`, `output: 'standalone'`)
const { code } = await nextBuild(appDir)
// eslint-disable-next-line jest/no-standalone-expect
expect(code).toBe(0)
const port = await findPort()
let stderr = ''
app = await nextStart(appDir, port, {
onStderr(msg: string) {
stderr += msg || ''
},
})
await check(() => stderr, /⚠/i)
// eslint-disable-next-line jest/no-standalone-expect
expect(stderr).toContain(
`"next start" does not work with "output: standalone" configuration. Use "node .next/standalone/server.js" instead.`
)
}
)
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - trailing slash dev', () => {
;(process.env.TURBOPACK_BUILD ? describe.skip : describe)(
'development mode',
() => {
it.each([{ trailingSlash: false }, { trailingSlash: true }])(
"should work in dev with trailingSlash '$trailingSlash'",
async ({ trailingSlash }) => {
await runTests({ isDev: true, trailingSlash })
}
)
}
)
})
import { runTests } from './utils'
describe('app dir - with output export - trailing slash prod', () => {
;(process.env.TURBOPACK_DEV ? describe.skip : describe)(
'production mode',
() => {
it.each([{ trailingSlash: false }, { trailingSlash: true }])(
"should work in prod with trailingSlash '$trailingSlash'",
async ({ trailingSlash }) => {
await runTests({ isDev: false, trailingSlash })
}
)
}
)
})
...@@ -127,6 +127,20 @@ export class FileRef { ...@@ -127,6 +127,20 @@ export class FileRef {
} }
} }
/**
* FileRef is wrapper around a file path that is meant be copied
* to the location where the next instance is being created
*/
export class PatchedFileRef {
public fsPath: string
public cb: (content: string) => string
constructor(path: string, cb: (content: string) => string) {
this.fsPath = path
this.cb = cb
}
}
let nextInstance: NextInstance | undefined = undefined let nextInstance: NextInstance | undefined = undefined
if (typeof afterAll === 'function') { if (typeof afterAll === 'function') {
......
...@@ -3,7 +3,7 @@ import path from 'path' ...@@ -3,7 +3,7 @@ import path from 'path'
import { existsSync, promises as fs, rmSync, readFileSync } from 'fs' import { existsSync, promises as fs, rmSync, readFileSync } from 'fs'
import treeKill from 'tree-kill' import treeKill from 'tree-kill'
import type { NextConfig } from 'next' import type { NextConfig } from 'next'
import { FileRef, isNextDeploy } from '../e2e-utils' import { FileRef, isNextDeploy, PatchedFileRef } from '../e2e-utils'
import { ChildProcess } from 'child_process' import { ChildProcess } from 'child_process'
import { createNextInstall } from '../create-next-install' import { createNextInstall } from '../create-next-install'
import { Span } from 'next/dist/trace' import { Span } from 'next/dist/trace'
...@@ -30,7 +30,10 @@ export type PackageJson = { ...@@ -30,7 +30,10 @@ export type PackageJson = {
[key: string]: unknown [key: string]: unknown
} }
type ResolvedFileConfig = FileRef | { [filename: string]: string | FileRef } type ResolvedFileConfig =
| FileRef
| PatchedFileRef
| { [filename: string]: string | FileRef | PatchedFileRef }
type FilesConfig = ResolvedFileConfig | string type FilesConfig = ResolvedFileConfig | string
export interface NextInstanceOpts { export interface NextInstanceOpts {
files: FilesConfig files: FilesConfig
...@@ -155,7 +158,7 @@ export class NextInstance { ...@@ -155,7 +158,7 @@ export class NextInstance {
if (typeof item === 'string') { if (typeof item === 'string') {
await fs.mkdir(path.dirname(outputFilename), { recursive: true }) await fs.mkdir(path.dirname(outputFilename), { recursive: true })
await fs.writeFile(outputFilename, item) await fs.writeFile(outputFilename, item)
} else { } else if (item instanceof FileRef) {
try { try {
const existingStat = await fs.lstat(outputFilename) const existingStat = await fs.lstat(outputFilename)
if (existingStat.isFile() || existingStat.isSymbolicLink()) { if (existingStat.isFile() || existingStat.isSymbolicLink()) {
...@@ -166,6 +169,20 @@ export class NextInstance { ...@@ -166,6 +169,20 @@ export class NextInstance {
} }
await fs.cp(item.fsPath, outputFilename, { recursive: true }) await fs.cp(item.fsPath, outputFilename, { recursive: true })
} else if (item instanceof PatchedFileRef) {
try {
const existingStat = await fs.lstat(outputFilename)
if (existingStat.isFile() || existingStat.isSymbolicLink()) {
await fs.unlink(outputFilename)
}
} catch {
// file might not exist or can't be unliked. carry on
}
await fs.writeFile(
outputFilename,
item.cb(await fs.readFile(item.fsPath, 'utf8'))
)
} }
} }
} }
......
...@@ -110,13 +110,15 @@ export class NextStartInstance extends NextInstance { ...@@ -110,13 +110,15 @@ export class NextStartInstance extends NextInstance {
this.handleStdio(this.childProcess) this.handleStdio(this.childProcess)
this.childProcess.on('close', (code, signal) => { this.childProcess.on('close', (code, signal) => {
if (this.isStopping) return this.childProcess = undefined
if (code || signal) { if (code || signal) {
require('console').error( let message = `next start exited unexpectedly with code/signal ${
`next start exited unexpectedly with code/signal ${ code || signal
code || signal }`
}` if (!this.isStopping) {
) require('console').error(message)
}
reject(new Error(message))
} }
}) })
......
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