@11ty/eleventy-fetch
Advanced tools
Comparing version 3.0.0 to 4.0.0
{ | ||
"name": "@11ty/eleventy-fetch", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Fetch and locally cache remote API calls and assets.", | ||
@@ -22,3 +22,3 @@ "publishConfig": { | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14" | ||
}, | ||
@@ -44,6 +44,6 @@ "funding": { | ||
"devDependencies": { | ||
"ava": "^4.0.1" | ||
"ava": "^5.2.0" | ||
}, | ||
"dependencies": { | ||
"debug": "^4.3.3", | ||
"debug": "^4.3.4", | ||
"flat-cache": "^3.0.4", | ||
@@ -50,0 +50,0 @@ "node-fetch": "^2.6.7", |
@@ -1,6 +0,6 @@ | ||
<p align="center"><img src="https://www.11ty.dev/img/logo-github.png" alt="eleventy Logo"></p> | ||
<p align="center"><img src="https://www.11ty.dev/img/logo-github.svg" width="200" height="200" alt="eleventy Logo"></p> | ||
# eleventy-fetch | ||
_Requires Node 12+_ | ||
_Requires Node 14+_ | ||
@@ -7,0 +7,0 @@ Formerly known as [`@11ty/eleventy-cache-assets`](https://www.npmjs.com/package/@11ty/eleventy-cache-assets). |
@@ -125,2 +125,7 @@ const fs = require("fs"); | ||
async save(contents, type = "buffer") { | ||
if(this.options.dryRun) { | ||
debug("An attempt was made to save to the file system with `dryRun: true`. Skipping."); | ||
return; | ||
} | ||
await this.ensureDir(); | ||
@@ -127,0 +132,0 @@ |
@@ -62,6 +62,6 @@ const fs = require("fs"); | ||
async fetch(optionsOverride = {}) { | ||
let isDryRun = optionsOverride.dryRun || this.options.dryRun; | ||
let duration = optionsOverride.duration || this.options.duration; | ||
// Important: no disk writes/reads when dryRun | ||
if( !isDryRun && super.isCacheValid(duration) ) { | ||
// Important: no disk writes when dryRun | ||
// As of Fetch v4, reads are now allowed! | ||
if(super.isCacheValid(duration) ) { | ||
return super.getCachedValue(); | ||
@@ -71,6 +71,9 @@ } | ||
try { | ||
let isDryRun = optionsOverride.dryRun || this.options.dryRun; | ||
this.log( `[11ty/eleventy-fetch] ${isDryRun? "Fetching" : "Caching"}: ${this.displayUrl}` ); | ||
let fetchOptions = optionsOverride.fetchOptions || this.options.fetchOptions || {}; | ||
let response = await fetch(this.url, fetchOptions); | ||
if(!response.ok) { | ||
throw new Error(`Bad response for ${this.displayUrl} (${response.status}): ${response.statusText}`) | ||
throw new Error(`Bad response for ${this.displayUrl} (${response.status}): ${response.statusText}`, { cause: response }); | ||
} | ||
@@ -80,3 +83,2 @@ | ||
let body = await this.getResponseValue(response, type); | ||
this.log( `[11ty/eleventy-fetch] ${isDryRun? "Fetching" : "Caching"}: ${this.displayUrl}` ); | ||
if(!isDryRun) { | ||
@@ -83,0 +85,0 @@ await super.save(body, type); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14555
344
Updateddebug@^4.3.4