Socket
Socket
Sign inDemoInstall

@stencila/dockter

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@stencila/dockter - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

73

dist/Doer.js

@@ -8,12 +8,9 @@ "use strict";

const fast_glob_1 = __importDefault(require("fast-glob"));
// @ts-ignore
const cached_request_1 = __importDefault(require("cached-request"));
const got_1 = __importDefault(require("got"));
const node_persist_1 = __importDefault(require("node-persist"));
const path_1 = __importDefault(require("path"));
const rimraf_1 = __importDefault(require("rimraf"));
const request_1 = __importDefault(require("request"));
const tmp_1 = __importDefault(require("tmp"));
const errors_1 = require("./errors");
const REQUEST_CACHE_DIR = '/tmp/dockter-request-cache';
const requestCache = cached_request_1.default(request_1.default);
requestCache.setCacheDirectory(REQUEST_CACHE_DIR);
let REQUEST_CACHE_INITIALISED = false;
/**

@@ -52,28 +49,48 @@ * A utility base class for the `Parser` and `Generator` classes

}
fetch(url) {
return new Promise((resolve, reject) => {
requestCache({
url,
json: true,
async fetch(url) {
if (!REQUEST_CACHE_INITIALISED) {
await node_persist_1.default.init({
dir: REQUEST_CACHE_DIR,
ttl: 60 * 60 * 1000 // Milliseconds to cache responses for
}, (error, response, body) => {
if (error) {
if (['ENOTFOUND', 'EAI_AGAIN', 'DEPTH_ZERO_SELF_SIGNED_CERT'].includes(error.code)) {
// These are usually connection errors
error = new errors_1.NetworkError(`There was a problem fetching ${url} (${error.code}). Are you connected to the internet?`);
}
else if (error instanceof SyntaxError && error.message.includes(' JSON ')) {
// We can get here if a previous attempt had a network error and resulted in corrupt
// JSON being written to the cache. So clear the cache...
rimraf_1.default.sync(REQUEST_CACHE_DIR);
// Ask the user to try again
error = new errors_1.ApplicationError(`There was a problem fetching ${url}. Please try again.`);
}
return reject(error);
});
REQUEST_CACHE_INITIALISED = true;
}
let value;
try {
value = await node_persist_1.default.getItem(url);
}
catch (error) {
if (error.message.includes('does not look like a valid storage file')) {
// It seems that `persist.setItem` is not atomic and that the storage file can
// have zero bytes when we make multiple requests, some of which are for the same
// url. So we ignore this error and continue with the duplicate request.
}
else {
throw error;
}
}
if (!value) {
try {
const response = await got_1.default(url, {
json: true
});
value = response.body;
}
catch (error) {
if (error.statusCode === 404) {
value = null;
}
resolve(body);
});
});
else if (['ENOTFOUND', 'EAI_AGAIN', 'DEPTH_ZERO_SELF_SIGNED_CERT'].includes(error.code)) {
// These are usually connection errors
throw new errors_1.NetworkError(`There was a problem fetching ${url} (${error.code}). Are you connected to the internet?`);
}
else {
throw error;
}
}
await node_persist_1.default.setItem(url, value);
}
return value;
}
}
exports.default = Doer;

@@ -135,9 +135,6 @@ "use strict";

// Fetch meta-data from CRANDB
// If null (i.e. 404) then return package as is
const crandb = await this.fetch(`http://crandb.r-pkg.org/${name}`);
if (crandb.error) {
if (crandb.error === 'not_found')
return pkg;
else
throw new Error(crandb.error);
}
if (crandb === null)
return pkg;
// schema:Thing

@@ -144,0 +141,0 @@ pkg.description = crandb.Description;

{
"name": "@stencila/dockter",
"version": "0.2.5",
"version": "0.2.6",
"description": "A Docker image builder for researchers",

@@ -50,6 +50,7 @@ "main": "dist/index.js",

"@types/express": "^4.16.0",
"@types/got": "^8.3.4",
"@types/jest": "^23.3.3",
"@types/js-yaml": "^3.11.2",
"@types/node-persist": "0.0.33",
"@types/request": "^2.47.1",
"@types/rimraf": "^2.0.2",
"@types/tar-fs": "^1.16.1",

@@ -74,3 +75,2 @@ "@types/tar-stream": "^1.6.0",

"dependencies": {
"cached-request": "^1.1.4",
"docker-file-parser": "^1.0.4",

@@ -80,3 +80,5 @@ "dockerode": "^2.5.7",

"fast-glob": "^2.2.3",
"got": "^9.2.2",
"js-yaml": "^3.12.0",
"node-persist": "^3.0.1",
"request": "^2.88.0",

@@ -83,0 +85,0 @@ "rimraf": "^2.6.2",

import fs from 'fs'
import glob from 'fast-glob'
// @ts-ignore
import cachedRequest from 'cached-request'
import got from 'got'
import persist from 'node-persist'
import path from 'path'
import rimraf from 'rimraf'
import request from 'request'
import tmp from 'tmp'
import { PermissionError, NetworkError, ApplicationError } from './errors'
import { PermissionError, NetworkError } from './errors'
const REQUEST_CACHE_DIR = '/tmp/dockter-request-cache'
const requestCache = cachedRequest(request)
requestCache.setCacheDirectory(REQUEST_CACHE_DIR)
let REQUEST_CACHE_INITIALISED = false

@@ -58,26 +55,44 @@ /**

fetch (url: string): Promise<any> {
return new Promise((resolve, reject) => {
requestCache({
url,
json: true,
async fetch (url: string): Promise<any> {
if (!REQUEST_CACHE_INITIALISED) {
await persist.init({
dir: REQUEST_CACHE_DIR,
ttl: 60 * 60 * 1000 // Milliseconds to cache responses for
}, (error: any, response: any, body: any) => {
if (error) {
if (['ENOTFOUND', 'EAI_AGAIN', 'DEPTH_ZERO_SELF_SIGNED_CERT'].includes(error.code)) {
// These are usually connection errors
error = new NetworkError(`There was a problem fetching ${url} (${error.code}). Are you connected to the internet?`)
} else if (error instanceof SyntaxError && error.message.includes(' JSON ')) {
// We can get here if a previous attempt had a network error and resulted in corrupt
// JSON being written to the cache. So clear the cache...
rimraf.sync(REQUEST_CACHE_DIR)
// Ask the user to try again
error = new ApplicationError(`There was a problem fetching ${url}. Please try again.`)
}
return reject(error)
})
REQUEST_CACHE_INITIALISED = true
}
let value
try {
value = await persist.getItem(url)
} catch (error) {
if (error.message.includes('does not look like a valid storage file')) {
// It seems that `persist.setItem` is not atomic and that the storage file can
// have zero bytes when we make multiple requests, some of which are for the same
// url. So we ignore this error and continue with the duplicate request.
} else {
throw error
}
}
if (!value) {
try {
const response = await got(url, {
json: true
})
value = response.body
} catch (error) {
if (error.statusCode === 404) {
value = null
} else if (['ENOTFOUND', 'EAI_AGAIN', 'DEPTH_ZERO_SELF_SIGNED_CERT'].includes(error.code)) {
// These are usually connection errors
throw new NetworkError(`There was a problem fetching ${url} (${error.code}). Are you connected to the internet?`)
} else {
throw error
}
resolve(body)
})
})
}
await persist.setItem(url, value)
}
return value
}
}

@@ -137,7 +137,5 @@ import path from 'path'

// Fetch meta-data from CRANDB
// If null (i.e. 404) then return package as is
const crandb = await this.fetch(`http://crandb.r-pkg.org/${name}`)
if (crandb.error) {
if (crandb.error === 'not_found') return pkg
else throw new Error(crandb.error)
}
if (crandb === null) return pkg

@@ -144,0 +142,0 @@ // schema:Thing

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