Skip to content

Commit

Permalink
feat!: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jun 21, 2022
1 parent 37f09b0 commit d4de9d3
Show file tree
Hide file tree
Showing 4 changed files with 2,014 additions and 2,129 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
"hasha": "^5.2.2",
"image-meta": "^0.1.1",
"is-https": "^4.0.0",
"lru-cache": "^6.0.0",
"node-fetch": "^2.6.7",
"lru-cache": "^7.10.0",
"node-fetch-native": "^0.1.4",
"p-limit": "^3.1.0",
"rc9": "^1.2.2",
"requrl": "^3.0.2",
Expand All @@ -43,7 +43,7 @@
"@babel/preset-env": "latest",
"@babel/preset-typescript": "latest",
"@cyrilf/vue-dat-gui": "latest",
"@nuxt/test-utils": "latest",
"@nuxt/test-utils": "^0.2.2",
"@nuxt/types": "latest",
"@nuxt/typescript-build": "latest",
"@nuxt/typescript-runtime": "latest",
Expand All @@ -58,6 +58,7 @@
"babel-eslint": "latest",
"eslint": "latest",
"jest": "latest",
"jest-environment-jsdom": "^28.1.1",
"jsdom": "latest",
"jsdom-global": "latest",
"mkdist": "latest",
Expand Down
7 changes: 3 additions & 4 deletions src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { promisify } from 'util'
import stream from 'stream'
import { mkdirp } from 'fs-extra'
import { dirname, join, relative, basename, trimExt } from 'upath'
import fetch from 'node-fetch'
import { fetch } from 'node-fetch-native'
import { joinURL, hasProtocol, parseURL, withoutTrailingSlash } from 'ufo'
import pLimit from 'p-limit'
import { ModuleOptions, MapToStatic, ResolvedImage } from './types'
import { hash, logger, guessExt } from './utils'

const pipeline = promisify(stream.pipeline)

export function setupStaticGeneration (nuxt: any, options: ModuleOptions) {
const staticImages: Record<string, string> = {} // url ~> hashed file name

Expand Down Expand Up @@ -50,13 +48,14 @@ export function setupStaticGeneration (nuxt: any, options: ModuleOptions) {
})
}

const pipeline = promisify(stream.pipeline)
async function downloadImage ({ url, name, outDir }: { url: string, name: string, outDir: string }) {
try {
const response = await fetch(url)
if (!response.ok) { throw new Error(`Unexpected response ${response.statusText}`) }
const dstFile = join(outDir, name)
await mkdirp(dirname(dstFile))
await pipeline(response.body, createWriteStream(dstFile))
await pipeline(response.body as any, createWriteStream(dstFile))
logger.success('Generated static image ' + relative(process.cwd(), dstFile))
} catch (error: any) {
logger.error(error?.message)
Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const imageModule: Module<ModuleOptions> = async function imageModule (moduleOpt
setupStaticGeneration(nuxt, options)
})

const cache = new LruCache()
const cache = new LruCache({ max: 1000 })
nuxt.hook('vue-renderer:context', (ssrContext: any) => {
ssrContext.cache = cache
})
Expand Down
Loading

0 comments on commit d4de9d3

Please sign in to comment.