mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
fix: remove require.cache deletion
This commit is contained in:
parent
39ef28ca2a
commit
a74f206189
@ -11,7 +11,7 @@ const webpackDevMiddleware = require('webpack-dev-middleware')
|
||||
const webpackHotMiddleware = require('webpack-hot-middleware')
|
||||
const Debug = require('debug')
|
||||
const Glob = require('glob')
|
||||
const { r, wp, wChunk, createRoutes, sequence, relativeTo, waitFor, rmCache } = require('../common/utils')
|
||||
const { r, wp, wChunk, createRoutes, sequence, relativeTo, waitFor } = require('../common/utils')
|
||||
const { Options } = require('../common')
|
||||
const clientWebpackConfig = require('./webpack/client.config.js')
|
||||
const serverWebpackConfig = require('./webpack/server.config.js')
|
||||
@ -465,12 +465,6 @@ module.exports = class Builder {
|
||||
compiler.watch(this.options.watchers.webpack, (err) => {
|
||||
/* istanbul ignore if */
|
||||
if (err) return reject(err)
|
||||
// not keep modified or deleted items in Vue.prototype
|
||||
Object.keys(require.cache).forEach(key => {
|
||||
if (!/(node_modules\/postcss)|(\.node$)/.test(key)) {
|
||||
rmCache(key)
|
||||
}
|
||||
})
|
||||
})
|
||||
)
|
||||
return
|
||||
|
@ -268,16 +268,3 @@ exports.createRoutes = function createRoutes(files, srcDir) {
|
||||
})
|
||||
return cleanChildrenRoutes(routes)
|
||||
}
|
||||
|
||||
exports.rmCache = function rmCache(path) {
|
||||
const mod = require.cache[path]
|
||||
delete require.cache[path]
|
||||
if (mod.parent && mod.parent.children) {
|
||||
for (let i = 0; i < mod.parent.children.length; i++) {
|
||||
if (mod.parent.children[i] === mod) {
|
||||
mod.parent.children.splice(i, 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,11 @@
|
||||
import test from 'ava'
|
||||
import { resolve } from 'path'
|
||||
import { intercept, release } from './helpers/console'
|
||||
import { Nuxt, Builder, Utils } from '..'
|
||||
import { truncateSync, readFileSync, writeFileSync } from 'fs'
|
||||
import { Nuxt, Builder } from '..'
|
||||
|
||||
const port = 4001
|
||||
const url = (route) => 'http://localhost:' + port + route
|
||||
const rootDir = resolve(__dirname, 'fixtures/basic')
|
||||
const pluginPath = resolve(rootDir, 'plugins', 'watch.js')
|
||||
const pluginContent = readFileSync(pluginPath)
|
||||
|
||||
let nuxt = null
|
||||
|
||||
@ -24,10 +21,7 @@ test.serial('Init Nuxt.js', async t => {
|
||||
extractCSS: {
|
||||
allChunks: true
|
||||
}
|
||||
},
|
||||
plugins: [
|
||||
'~/plugins/watch.js'
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
const spies = await intercept({ log: true, stderr: true }, async () => {
|
||||
@ -49,31 +43,6 @@ test.serial('Init Nuxt.js', async t => {
|
||||
// t.is(window.getComputedStyle(window.document.body).getPropertyValue('font-size'), '30px')
|
||||
// })
|
||||
|
||||
test.serial('remove mixins in live reloading', async t => {
|
||||
const spies = await intercept({ log: true, error: true, stderr: true })
|
||||
await nuxt.renderRoute(url('/'))
|
||||
t.true(spies.log.calledWith('I am mixin'))
|
||||
|
||||
truncateSync(pluginPath)
|
||||
await new Promise(async (resolve, reject) => {
|
||||
let waitTimes = 0
|
||||
while (spies.log.neverCalledWithMatch(/Compiled successfully/)) {
|
||||
if (waitTimes++ >= 20) {
|
||||
t.fail('Dev server doesn\'t reload after 2000ms')
|
||||
reject(Error())
|
||||
}
|
||||
await Utils.waitFor(100)
|
||||
}
|
||||
resolve()
|
||||
})
|
||||
spies.log.reset()
|
||||
|
||||
await nuxt.renderRoute(url('/'))
|
||||
t.true(spies.log.neverCalledWith('I am mixin'))
|
||||
t.is(spies.error.getCall(0).args[0].statusCode, 404)
|
||||
release()
|
||||
})
|
||||
|
||||
test.serial('/stateless', async t => {
|
||||
const spies = await intercept()
|
||||
const window = await nuxt.renderAndGetWindow(url('/stateless'))
|
||||
@ -94,6 +63,5 @@ test.serial('/stateless', async t => {
|
||||
|
||||
// Close server and ask nuxt to stop listening to file changes
|
||||
test.after.always('Closing server and nuxt.js', async t => {
|
||||
writeFileSync(pluginPath, pluginContent)
|
||||
await nuxt.close()
|
||||
})
|
||||
|
12
test/fixtures/basic/plugins/watch.js
vendored
12
test/fixtures/basic/plugins/watch.js
vendored
@ -1,12 +0,0 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const Plugin = {
|
||||
install(Vue) {
|
||||
Vue.mixin({
|
||||
created() {
|
||||
console.log('I am mixin') // eslint-disable-line no-console
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Vue.use(Plugin)
|
Loading…
Reference in New Issue
Block a user