Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: limit static download concurrency #217

Merged
merged 2 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"ipx": "^0.6.0",
"is-https": "^3.0.2",
"node-fetch": "^2.6.1",
"p-limit": "^3.1.0",
"requrl": "^3.0.2",
"ufo": "^0.6.11",
"upath": "^2.0.1"
Expand Down
6 changes: 4 additions & 2 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { mkdirp } from 'fs-extra'
import { dirname, join, relative, resolve, extname } from 'upath'
import fetch from 'node-fetch'
import { joinURL, hasProtocol, parseURL } from 'ufo'
import pLimit from 'p-limit'
import { ModuleOptions, MapToStatic, ResolvedImage } from './types'
import { hash, logger } from './utils'

Expand All @@ -27,15 +28,16 @@ export function setupStaticGeneration (nuxt: any, options: ModuleOptions) {

nuxt.hook('generate:done', async () => {
const { dir: generateDir } = nuxt.options.generate
const limit = pLimit(5)
jdempster marked this conversation as resolved.
Show resolved Hide resolved
const downloads = Object.entries(staticImages).map(([url, name]) => {
if (!hasProtocol(url)) {
url = joinURL(options.internalUrl, url)
}
return downloadImage({
return limit(() => downloadImage({
url,
name,
outDir: resolve(generateDir, '_nuxt/image' /* TODO: staticImagesBase */)
})
}))
})
await Promise.all(downloads)
})
Expand Down
4 changes: 3 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8752,7 +8752,7 @@ p-limit@^2.0.0, p-limit@^2.2.0:
dependencies:
p-try "^2.0.0"

p-limit@^3.0.2:
p-limit@^3.0.2, p-limit@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-3.1.0.tgz#e1daccbe78d0d1388ca18c64fea38e3e57e3706b"
integrity sha512-TYOanM3wGwNGsZN2cVTYPArw454xnXj5qmWF1bEoAc4+cU/ol7GVh7odevjp1FNHduHc3KZMcFduxU5Xc6uJRQ==
Expand Down Expand Up @@ -12337,8 +12337,10 @@ watchpack@^1.7.4:
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.7.5.tgz#1267e6c55e0b9b5be44c2023aed5437a2c26c453"
integrity sha512-9P3MWk6SrKjHsGkLT2KHXdQ/9SNkyoJbabxnKOoJepsvJjJG8uYTR3yTPxPQvNDI3w4Nz1xnE0TLHK4RIVe/MQ==
dependencies:
chokidar "^3.4.1"
graceful-fs "^4.1.2"
neo-async "^2.5.0"
watchpack-chokidar2 "^2.0.1"
optionalDependencies:
chokidar "^3.4.1"
watchpack-chokidar2 "^2.0.1"
Expand Down