@@ -4,14 +4,12 @@ import { promisify } from 'util'
44import stream from 'stream'
55import { mkdirp } from 'fs-extra'
66import { dirname , join , relative , basename , trimExt } from 'upath'
7- import fetch from 'node-fetch'
7+ import { fetch } from 'node-fetch-native '
88import { joinURL , hasProtocol , parseURL , withoutTrailingSlash } from 'ufo'
99import pLimit from 'p-limit'
1010import { ModuleOptions , MapToStatic , ResolvedImage } from './types'
1111import { hash , logger , guessExt } from './utils'
1212
13- const pipeline = promisify ( stream . pipeline )
14-
1513export function setupStaticGeneration ( nuxt : any , options : ModuleOptions ) {
1614 const staticImages : Record < string , string > = { } // url ~> hashed file name
1715
@@ -50,13 +48,14 @@ export function setupStaticGeneration (nuxt: any, options: ModuleOptions) {
5048 } )
5149}
5250
51+ const pipeline = promisify ( stream . pipeline )
5352async function downloadImage ( { url, name, outDir } : { url : string , name : string , outDir : string } ) {
5453 try {
5554 const response = await fetch ( url )
5655 if ( ! response . ok ) { throw new Error ( `Unexpected response ${ response . statusText } ` ) }
5756 const dstFile = join ( outDir , name )
5857 await mkdirp ( dirname ( dstFile ) )
59- await pipeline ( response . body , createWriteStream ( dstFile ) )
58+ await pipeline ( response . body as any , createWriteStream ( dstFile ) )
6059 logger . success ( 'Generated static image ' + relative ( process . cwd ( ) , dstFile ) )
6160 } catch ( error : any ) {
6261 logger . error ( error ?. message )
0 commit comments