mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 17:07:22 +00:00
fix: use perfect-debounce
to handle trailing run of promise (#3679)
Co-authored-by: pooya parsa <pyapar@gmail.com>
This commit is contained in:
parent
3a8bef609d
commit
ff88d91bae
@ -46,8 +46,8 @@
|
|||||||
"murmurhash-es": "^0.1.1",
|
"murmurhash-es": "^0.1.1",
|
||||||
"node-fetch": "^3.2.3",
|
"node-fetch": "^3.2.3",
|
||||||
"nuxi": "3.0.0",
|
"nuxi": "3.0.0",
|
||||||
"p-debounce": "^4.0.0",
|
|
||||||
"pathe": "^0.2.0",
|
"pathe": "^0.2.0",
|
||||||
|
"perfect-debounce": "^0.1.3",
|
||||||
"postcss": "^8",
|
"postcss": "^8",
|
||||||
"postcss-import": "^14.0.2",
|
"postcss-import": "^14.0.2",
|
||||||
"postcss-import-resolver": "^2.0.0",
|
"postcss-import-resolver": "^2.0.0",
|
||||||
|
@ -3,7 +3,7 @@ import * as vite from 'vite'
|
|||||||
import { createVuePlugin } from 'vite-plugin-vue2'
|
import { createVuePlugin } from 'vite-plugin-vue2'
|
||||||
import { logger } from '@nuxt/kit'
|
import { logger } from '@nuxt/kit'
|
||||||
import fse from 'fs-extra'
|
import fse from 'fs-extra'
|
||||||
import pDebounce from 'p-debounce'
|
import { debounce } from 'perfect-debounce'
|
||||||
import { bundleRequest } from '../../../vite/src/dev-bundler'
|
import { bundleRequest } from '../../../vite/src/dev-bundler'
|
||||||
import { isCSS } from '../../../vite/src/utils'
|
import { isCSS } from '../../../vite/src/utils'
|
||||||
import { wpfs } from './utils/wpfs'
|
import { wpfs } from './utils/wpfs'
|
||||||
@ -118,7 +118,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
consola.info(`Server built in ${time}ms`)
|
consola.info(`Server built in ${time}ms`)
|
||||||
await onBuild()
|
await onBuild()
|
||||||
}
|
}
|
||||||
const doBuild = pDebounce(pDebounce.promise(_doBuild), 300)
|
const doBuild = debounce(_doBuild)
|
||||||
|
|
||||||
// Initial build
|
// Initial build
|
||||||
await _doBuild()
|
await _doBuild()
|
||||||
|
@ -55,8 +55,8 @@
|
|||||||
"node-fetch": "^3.2.3",
|
"node-fetch": "^3.2.3",
|
||||||
"ohmyfetch": "^0.4.15",
|
"ohmyfetch": "^0.4.15",
|
||||||
"ora": "^6.1.0",
|
"ora": "^6.1.0",
|
||||||
"p-debounce": "^4.0.0",
|
|
||||||
"pathe": "^0.2.0",
|
"pathe": "^0.2.0",
|
||||||
|
"perfect-debounce": "^0.1.3",
|
||||||
"pkg-types": "^0.3.2",
|
"pkg-types": "^0.3.2",
|
||||||
"pretty-bytes": "^6.0.0",
|
"pretty-bytes": "^6.0.0",
|
||||||
"rollup": "^2.70.1",
|
"rollup": "^2.70.1",
|
||||||
|
@ -4,7 +4,7 @@ import { IncomingMessage, ServerResponse } from 'http'
|
|||||||
import { existsSync, promises as fsp } from 'fs'
|
import { existsSync, promises as fsp } from 'fs'
|
||||||
import { loading as loadingTemplate } from '@nuxt/ui-templates'
|
import { loading as loadingTemplate } from '@nuxt/ui-templates'
|
||||||
import chokidar, { FSWatcher } from 'chokidar'
|
import chokidar, { FSWatcher } from 'chokidar'
|
||||||
import debounce from 'p-debounce'
|
import { debounce } from 'perfect-debounce'
|
||||||
import { promisifyHandle, createApp, Middleware, useBase } from 'h3'
|
import { promisifyHandle, createApp, Middleware, useBase } from 'h3'
|
||||||
import httpProxy from 'http-proxy'
|
import httpProxy from 'http-proxy'
|
||||||
import { listen, Listener, ListenOptions } from 'listhen'
|
import { listen, Listener, ListenOptions } from 'listhen'
|
||||||
@ -128,7 +128,7 @@ export function createDevServer (nitroContext: NitroContext) {
|
|||||||
let watcher: FSWatcher
|
let watcher: FSWatcher
|
||||||
function watch () {
|
function watch () {
|
||||||
if (watcher) { return }
|
if (watcher) { return }
|
||||||
const dReload = debounce(debounce.promise(() => reload().catch(console.warn)), 200, { before: true })
|
const dReload = debounce(() => reload().catch(console.warn))
|
||||||
watcher = chokidar.watch([
|
watcher = chokidar.watch([
|
||||||
resolve(nitroContext.output.serverDir, pattern),
|
resolve(nitroContext.output.serverDir, pattern),
|
||||||
resolve(nitroContext._nuxt.buildDir, 'dist/server', pattern)
|
resolve(nitroContext._nuxt.buildDir, 'dist/server', pattern)
|
||||||
|
@ -37,8 +37,8 @@
|
|||||||
"listhen": "^0.2.6",
|
"listhen": "^0.2.6",
|
||||||
"mlly": "^0.4.3",
|
"mlly": "^0.4.3",
|
||||||
"mri": "^1.2.0",
|
"mri": "^1.2.0",
|
||||||
"p-debounce": "^4.0.0",
|
|
||||||
"pathe": "^0.2.0",
|
"pathe": "^0.2.0",
|
||||||
|
"perfect-debounce": "^0.1.3",
|
||||||
"pkg-types": "^0.3.2",
|
"pkg-types": "^0.3.2",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"scule": "^0.2.1",
|
"scule": "^0.2.1",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { resolve, relative } from 'pathe'
|
import { resolve, relative } from 'pathe'
|
||||||
import chokidar from 'chokidar'
|
import chokidar from 'chokidar'
|
||||||
import debounce from 'p-debounce'
|
import { debounce } from 'perfect-debounce'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import consola from 'consola'
|
import consola from 'consola'
|
||||||
import { withTrailingSlash } from 'ufo'
|
import { withTrailingSlash } from 'ufo'
|
||||||
@ -69,7 +69,7 @@ export default defineNuxtCommand({
|
|||||||
|
|
||||||
// Watch for config changes
|
// Watch for config changes
|
||||||
// TODO: Watcher service, modules, and requireTree
|
// TODO: Watcher service, modules, and requireTree
|
||||||
const dLoad = debounce(debounce.promise(load), 250)
|
const dLoad = debounce(load)
|
||||||
const watcher = chokidar.watch([rootDir], { ignoreInitial: true, depth: 1 })
|
const watcher = chokidar.watch([rootDir], { ignoreInitial: true, depth: 1 })
|
||||||
watcher.on('all', (event, file) => {
|
watcher.on('all', (event, file) => {
|
||||||
if (!currentNuxt) { return }
|
if (!currentNuxt) { return }
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import chokidar from 'chokidar'
|
import chokidar from 'chokidar'
|
||||||
import type { Nuxt } from '@nuxt/schema'
|
import type { Nuxt } from '@nuxt/schema'
|
||||||
import { isIgnored, tryImportModule } from '@nuxt/kit'
|
import { isIgnored, tryImportModule } from '@nuxt/kit'
|
||||||
import debounce from 'p-debounce'
|
import { debounce } from 'perfect-debounce'
|
||||||
import { createApp, generateApp as _generateApp } from './app'
|
import { createApp, generateApp as _generateApp } from './app'
|
||||||
|
|
||||||
export async function build (nuxt: Nuxt) {
|
export async function build (nuxt: Nuxt) {
|
||||||
const app = createApp(nuxt)
|
const app = createApp(nuxt)
|
||||||
const generateApp = debounce(debounce.promise(() => _generateApp(nuxt, app)), 1)
|
const generateApp = debounce(() => _generateApp(nuxt, app), undefined, { leading: true })
|
||||||
await generateApp()
|
await generateApp()
|
||||||
|
|
||||||
if (nuxt.options.dev) {
|
if (nuxt.options.dev) {
|
||||||
@ -48,7 +48,7 @@ function watch (nuxt: Nuxt) {
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|
||||||
const watchHook = debounce(debounce.promise((event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', path: string) => nuxt.callHook('builder:watch', event, path)), 1)
|
const watchHook = debounce((event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', path: string) => nuxt.callHook('builder:watch', event, path))
|
||||||
watcher.on('all', watchHook)
|
watcher.on('all', watchHook)
|
||||||
nuxt.hook('close', () => watcher.close())
|
nuxt.hook('close', () => watcher.close())
|
||||||
return watcher
|
return watcher
|
||||||
|
@ -34,8 +34,8 @@
|
|||||||
"knitwork": "^0.1.1",
|
"knitwork": "^0.1.1",
|
||||||
"magic-string": "^0.26.1",
|
"magic-string": "^0.26.1",
|
||||||
"mlly": "^0.4.3",
|
"mlly": "^0.4.3",
|
||||||
"p-debounce": "^4.0.0",
|
|
||||||
"pathe": "^0.2.0",
|
"pathe": "^0.2.0",
|
||||||
|
"perfect-debounce": "^0.1.3",
|
||||||
"postcss": "^8.4.12",
|
"postcss": "^8.4.12",
|
||||||
"postcss-import": "^14.0.2",
|
"postcss-import": "^14.0.2",
|
||||||
"postcss-url": "^10.1.3",
|
"postcss-url": "^10.1.3",
|
||||||
|
@ -4,7 +4,7 @@ import vuePlugin from '@vitejs/plugin-vue'
|
|||||||
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
import viteJsxPlugin from '@vitejs/plugin-vue-jsx'
|
||||||
import { logger, resolveModule } from '@nuxt/kit'
|
import { logger, resolveModule } from '@nuxt/kit'
|
||||||
import fse from 'fs-extra'
|
import fse from 'fs-extra'
|
||||||
import pDebounce from 'p-debounce'
|
import { debounce } from 'perfect-debounce'
|
||||||
import { withoutTrailingSlash } from 'ufo'
|
import { withoutTrailingSlash } from 'ufo'
|
||||||
import { ViteBuildContext, ViteOptions } from './vite'
|
import { ViteBuildContext, ViteOptions } from './vite'
|
||||||
import { wpfs } from './utils/wpfs'
|
import { wpfs } from './utils/wpfs'
|
||||||
@ -154,7 +154,7 @@ export async function buildServer (ctx: ViteBuildContext) {
|
|||||||
logger.success(`Vite server built in ${time}ms`)
|
logger.success(`Vite server built in ${time}ms`)
|
||||||
await onBuild()
|
await onBuild()
|
||||||
}
|
}
|
||||||
const doBuild = pDebounce(pDebounce.promise(_doBuild), 100)
|
const doBuild = debounce(_doBuild)
|
||||||
|
|
||||||
// Initial build
|
// Initial build
|
||||||
await _doBuild()
|
await _doBuild()
|
||||||
|
15
yarn.lock
15
yarn.lock
@ -2620,8 +2620,8 @@ __metadata:
|
|||||||
node-fetch: ^3.2.3
|
node-fetch: ^3.2.3
|
||||||
nuxi: 3.0.0
|
nuxi: 3.0.0
|
||||||
nuxt: ^2
|
nuxt: ^2
|
||||||
p-debounce: ^4.0.0
|
|
||||||
pathe: ^0.2.0
|
pathe: ^0.2.0
|
||||||
|
perfect-debounce: ^0.1.3
|
||||||
postcss: ^8
|
postcss: ^8
|
||||||
postcss-import: ^14.0.2
|
postcss-import: ^14.0.2
|
||||||
postcss-import-resolver: ^2.0.0
|
postcss-import-resolver: ^2.0.0
|
||||||
@ -3027,8 +3027,8 @@ __metadata:
|
|||||||
node-fetch: ^3.2.3
|
node-fetch: ^3.2.3
|
||||||
ohmyfetch: ^0.4.15
|
ohmyfetch: ^0.4.15
|
||||||
ora: ^6.1.0
|
ora: ^6.1.0
|
||||||
p-debounce: ^4.0.0
|
|
||||||
pathe: ^0.2.0
|
pathe: ^0.2.0
|
||||||
|
perfect-debounce: ^0.1.3
|
||||||
pkg-types: ^0.3.2
|
pkg-types: ^0.3.2
|
||||||
pretty-bytes: ^6.0.0
|
pretty-bytes: ^6.0.0
|
||||||
rollup: ^2.70.1
|
rollup: ^2.70.1
|
||||||
@ -3328,8 +3328,8 @@ __metadata:
|
|||||||
knitwork: ^0.1.1
|
knitwork: ^0.1.1
|
||||||
magic-string: ^0.26.1
|
magic-string: ^0.26.1
|
||||||
mlly: ^0.4.3
|
mlly: ^0.4.3
|
||||||
p-debounce: ^4.0.0
|
|
||||||
pathe: ^0.2.0
|
pathe: ^0.2.0
|
||||||
|
perfect-debounce: ^0.1.3
|
||||||
postcss: ^8.4.12
|
postcss: ^8.4.12
|
||||||
postcss-import: ^14.0.2
|
postcss-import: ^14.0.2
|
||||||
postcss-url: ^10.1.3
|
postcss-url: ^10.1.3
|
||||||
@ -15323,8 +15323,8 @@ __metadata:
|
|||||||
listhen: ^0.2.6
|
listhen: ^0.2.6
|
||||||
mlly: ^0.4.3
|
mlly: ^0.4.3
|
||||||
mri: ^1.2.0
|
mri: ^1.2.0
|
||||||
p-debounce: ^4.0.0
|
|
||||||
pathe: ^0.2.0
|
pathe: ^0.2.0
|
||||||
|
perfect-debounce: ^0.1.3
|
||||||
pkg-types: ^0.3.2
|
pkg-types: ^0.3.2
|
||||||
rimraf: ^3.0.2
|
rimraf: ^3.0.2
|
||||||
scule: ^0.2.1
|
scule: ^0.2.1
|
||||||
@ -16180,6 +16180,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"perfect-debounce@npm:^0.1.3":
|
||||||
|
version: 0.1.3
|
||||||
|
resolution: "perfect-debounce@npm:0.1.3"
|
||||||
|
checksum: c77465eb23d87669e5ee646d12331507c45278e0f2e6fc20a587104b956c1a53f9afe723915d882f73fa588e42770a2edd2bbd93eb0b958c9ff1eb7b915ccdc1
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"performance-now@npm:^2.1.0":
|
"performance-now@npm:^2.1.0":
|
||||||
version: 2.1.0
|
version: 2.1.0
|
||||||
resolution: "performance-now@npm:2.1.0"
|
resolution: "performance-now@npm:2.1.0"
|
||||||
|
Loading…
Reference in New Issue
Block a user