mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 09:27:13 +00:00
fix(generator, builder): empty build and dist directories instead of remove (#7361)
This commit is contained in:
parent
df4296c164
commit
2e5184688f
@ -153,8 +153,8 @@ export default class Builder {
|
||||
|
||||
consola.debug(`App root: ${this.options.srcDir}`)
|
||||
|
||||
// Create .nuxt/, .nuxt/components and .nuxt/dist folders
|
||||
await fsExtra.remove(r(this.options.buildDir))
|
||||
// Create or empty .nuxt/, .nuxt/components and .nuxt/dist folders
|
||||
await fsExtra.emptyDir(r(this.options.buildDir))
|
||||
const buildDirs = [r(this.options.buildDir, 'components')]
|
||||
if (!this.options.dev) {
|
||||
buildDirs.push(
|
||||
@ -162,7 +162,7 @@ export default class Builder {
|
||||
r(this.options.buildDir, 'dist', 'server')
|
||||
)
|
||||
}
|
||||
await Promise.all(buildDirs.map(dir => fsExtra.mkdirp(dir)))
|
||||
await Promise.all(buildDirs.map(dir => fsExtra.emptyDir(dir)))
|
||||
|
||||
// Call ready hook
|
||||
await this.nuxt.callHook('builder:prepared', this, this.options.build)
|
||||
|
@ -18,6 +18,7 @@ jest.mock('@nuxt/webpack')
|
||||
describe('builder: builder build', () => {
|
||||
beforeAll(() => {
|
||||
jest.spyOn(path, 'join').mockImplementation((...args) => `join(${args.join(', ')})`)
|
||||
r.mockImplementation((...args) => `r(${args.join(', ')})`)
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
@ -44,8 +45,6 @@ describe('builder: builder build', () => {
|
||||
builder.generateRoutesAndFiles = jest.fn()
|
||||
builder.resolvePlugins = jest.fn()
|
||||
|
||||
r.mockImplementation((dir, src) => `r(${dir})`)
|
||||
|
||||
const buildReturn = await builder.build()
|
||||
|
||||
expect(consola.info).toBeCalledTimes(3)
|
||||
@ -60,12 +59,11 @@ describe('builder: builder build', () => {
|
||||
expect(consola.success).toBeCalledWith('Builder initialized')
|
||||
expect(consola.debug).toBeCalledTimes(1)
|
||||
expect(consola.debug).toBeCalledWith('App root: /var/nuxt/src')
|
||||
expect(fsExtra.remove).toBeCalledTimes(1)
|
||||
expect(fsExtra.remove).toBeCalledWith('r(/var/nuxt/build)')
|
||||
expect(fsExtra.mkdirp).toBeCalledTimes(3)
|
||||
expect(fsExtra.mkdirp).nthCalledWith(1, 'r(/var/nuxt/build)')
|
||||
expect(fsExtra.mkdirp).nthCalledWith(2, 'r(/var/nuxt/build)')
|
||||
expect(fsExtra.mkdirp).nthCalledWith(3, 'r(/var/nuxt/build)')
|
||||
expect(fsExtra.emptyDir).toBeCalledTimes(4)
|
||||
expect(fsExtra.emptyDir).nthCalledWith(1, 'r(/var/nuxt/build)')
|
||||
expect(fsExtra.emptyDir).nthCalledWith(2, 'r(/var/nuxt/build, components)')
|
||||
expect(fsExtra.emptyDir).nthCalledWith(3, 'r(/var/nuxt/build, dist, client)')
|
||||
expect(fsExtra.emptyDir).nthCalledWith(4, 'r(/var/nuxt/build, dist, server)')
|
||||
expect(r).toBeCalledTimes(4)
|
||||
expect(r).nthCalledWith(1, '/var/nuxt/build')
|
||||
expect(r).nthCalledWith(2, '/var/nuxt/build', 'components')
|
||||
@ -132,8 +130,9 @@ describe('builder: builder build', () => {
|
||||
expect(consola.info).toBeCalledTimes(2)
|
||||
expect(consola.info).nthCalledWith(1, 'Preparing project for development')
|
||||
expect(consola.info).nthCalledWith(2, 'Initial build may take a while')
|
||||
expect(fsExtra.mkdirp).toBeCalledTimes(1)
|
||||
expect(fsExtra.mkdirp).toBeCalledWith('r(/var/nuxt/build)')
|
||||
expect(fsExtra.emptyDir).toBeCalledTimes(2)
|
||||
expect(fsExtra.emptyDir).nthCalledWith(1, 'r(/var/nuxt/build)')
|
||||
expect(fsExtra.emptyDir).nthCalledWith(2, 'r(/var/nuxt/build, components)')
|
||||
expect(r).toBeCalledTimes(2)
|
||||
expect(r).nthCalledWith(1, '/var/nuxt/build')
|
||||
expect(r).nthCalledWith(2, '/var/nuxt/build', 'components')
|
||||
|
@ -219,7 +219,7 @@ export default class Generator {
|
||||
|
||||
async initDist () {
|
||||
// Clean destination folder
|
||||
await fsExtra.remove(this.distPath)
|
||||
await fsExtra.emptyDir(this.distPath)
|
||||
|
||||
consola.info(`Generating output directory: ${path.basename(this.distPath)}/`)
|
||||
await this.nuxt.callHook('generate:distRemoved', this)
|
||||
|
@ -182,8 +182,8 @@ describe('generator: initialize', () => {
|
||||
|
||||
await generator.initDist()
|
||||
|
||||
expect(fsExtra.remove).toBeCalledTimes(1)
|
||||
expect(fsExtra.remove).toBeCalledWith(generator.distPath)
|
||||
expect(fsExtra.emptyDir).toBeCalledTimes(1)
|
||||
expect(fsExtra.emptyDir).toBeCalledWith(generator.distPath)
|
||||
expect(nuxt.callHook).toBeCalledTimes(2)
|
||||
expect(nuxt.callHook).nthCalledWith(1, 'generate:distRemoved', generator)
|
||||
expect(fsExtra.exists).toBeCalledTimes(1)
|
||||
|
Loading…
Reference in New Issue
Block a user