Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@11ty/eleventy-fetch

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@11ty/eleventy-fetch - npm Package Compare versions

Comparing version 4.0.0 to 4.0.1

2

package.json
{
"name": "@11ty/eleventy-fetch",
"version": "4.0.0",
"version": "4.0.1",
"description": "Fetch and locally cache remote API calls and assets.",

@@ -5,0 +5,0 @@ "publishConfig": {

@@ -11,2 +11,3 @@ const fs = require("fs");

constructor(uniqueKey, cacheDirectory, options = {}) {
this.uniqueKey = uniqueKey;
this.hash = AssetCache.getHash(uniqueKey, options.hashLength);

@@ -18,2 +19,10 @@ this.cacheDirectory = cacheDirectory || ".cache";

log(message) {
if(this.options.verbose) {
console.log(`[11ty/eleventy-fetch] ${message}`);
} else {
debug(message);
}
}
// Defult hashLength also set in global options, duplicated here for tests

@@ -65,3 +74,3 @@ static getHash(url, hashLength = 30) {

// https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html
// Bad: LAMBDA_TASK_ROOT is /var/task/ on AWS so we must use ELEVENTY_ROOT

@@ -138,4 +147,8 @@ // When using ELEVENTY_ROOT, cacheDirectory must be relative

}
let contentPath = this.getCachedContentsPath(type);
// the contents must exist before the cache metadata are saved below
await fsp.writeFile(this.getCachedContentsPath(type), contents);
await fsp.writeFile(contentPath, contents);
debug(`Writing ${contentPath}`);

@@ -152,2 +165,4 @@ let cache = this.cache;

let contentPath = this.getCachedContentsPath(type);
debug(`Fetching from cache ${contentPath}`);
if(type === "json") {

@@ -219,5 +234,7 @@ return require(contentPath);

// promise
this.log( `Using cached version of: ${this.uniqueKey}` );
return this.getCachedValue();
}
this.log( `Saving ${this.uniqueKey} to ${this.cacheFilename}` );
await this.save(this.source, options.type);

@@ -224,0 +241,0 @@

@@ -36,10 +36,2 @@ const fs = require("fs");

log(message) {
if(this.options.verbose) {
console.log(message);
} else {
debug(message);
}
}
get url() {

@@ -67,2 +59,3 @@ return this._url;

if(super.isCacheValid(duration) ) {
this.log( `Cache hit for ${this.displayUrl}` );
return super.getCachedValue();

@@ -73,3 +66,3 @@ }

let isDryRun = optionsOverride.dryRun || this.options.dryRun;
this.log( `[11ty/eleventy-fetch] ${isDryRun? "Fetching" : "Caching"}: ${this.displayUrl}` );
this.log( `${isDryRun? "Fetching" : "Cache miss for"} ${this.displayUrl}`);

@@ -90,4 +83,4 @@ let fetchOptions = optionsOverride.fetchOptions || this.options.fetchOptions || {};

if(this.cachedObject) {
this.log( `[11ty/eleventy-fetch] Error fetching ${this.displayUrl}. Message: ${e.message}`);
this.log( `[11ty/eleventy-fetch] Failing gracefully with an expired cache entry.` );
this.log( `Error fetching ${this.displayUrl}. Message: ${e.message}`);
this.log( `Failing gracefully with an expired cache entry.` );
return super.getCachedValue();

@@ -94,0 +87,0 @@ } else {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc