1
+ const debugUtil = require ( "debug" ) ;
1
2
const { parseXml } = require ( '@rgrove/parse-xml' ) ;
2
3
3
4
const Sources = require ( "./Sources.js" ) ;
4
5
const AssetCache = require ( "./AssetCache.js" ) ;
5
- const assetDebug = require ( "debug" ) ( "Eleventy:Assets" ) ;
6
+
7
+ const debug = debugUtil ( "Eleventy:Fetch" ) ;
8
+ const debugAssets = debugUtil ( "Eleventy:Assets" ) ;
6
9
7
10
class RemoteAssetCache extends AssetCache {
8
11
#queue;
@@ -135,7 +138,7 @@ class RemoteAssetCache extends AssetCache {
135
138
// Important: no disk writes when dryRun
136
139
// As of Fetch v4, reads are now allowed!
137
140
if ( this . isCacheValid ( optionsOverride . duration ) ) {
138
- this . log ( `Cache hit for ${ this . displayUrl } ` ) ;
141
+ debug ( `Cache hit for ${ this . displayUrl } ` ) ;
139
142
this . #lastFetchType = "hit" ;
140
143
return super . getCachedValue ( ) ;
141
144
}
@@ -144,7 +147,7 @@ class RemoteAssetCache extends AssetCache {
144
147
145
148
try {
146
149
let isDryRun = optionsOverride . dryRun || this . options . dryRun ;
147
- this . log ( `${ isDryRun ? " Fetching" : "Cache miss for" } ${ this . displayUrl } ` ) ;
150
+ this . log ( `Fetching ${ this . displayUrl } ` ) ;
148
151
149
152
let body ;
150
153
let metadata = { } ;
@@ -162,7 +165,8 @@ class RemoteAssetCache extends AssetCache {
162
165
163
166
this . fetchCount ++ ;
164
167
165
- assetDebug ( "Fetching remote asset: %o" , this . source ) ;
168
+ debugAssets ( "[@11ty/eleventy-fetch] Fetching: %o" , this . source ) ;
169
+
166
170
// v5: now using global (Node-native or otherwise) fetch instead of node-fetch
167
171
let response = await fetch ( this . source , fetchOptions ) ;
168
172
if ( ! response . ok ) {
@@ -196,8 +200,8 @@ class RemoteAssetCache extends AssetCache {
196
200
return body ;
197
201
} catch ( e ) {
198
202
if ( this . cachedObject ) {
199
- this . log ( `Error fetching ${ this . displayUrl } . Message: ${ e . message } ` ) ;
200
- this . log ( `Failing gracefully with an expired cache entry.` ) ;
203
+ debug ( `Error fetching ${ this . displayUrl } . Message: ${ e . message } ` ) ;
204
+ debug ( `Failing gracefully with an expired cache entry.` ) ;
201
205
return super . getCachedValue ( ) ;
202
206
} else {
203
207
return Promise . reject ( e ) ;
0 commit comments