rollup-plugin-node-resolve
Advanced tools
Comparing version 3.1.0 to 3.2.0
@@ -20,2 +20,30 @@ 'use strict'; | ||
var readFileCache = {}; | ||
var readFileAsync = function (file) { return new Promise(function (fulfil, reject) { return fs.readFile(file, function (err, contents) { return err ? reject(err) : fulfil(contents); }); }); }; | ||
var statAsync = function (file) { return new Promise(function (fulfil, reject) { return fs.stat(file, function (err, contents) { return err ? reject(err) : fulfil(contents); }); }); }; | ||
function cachedReadFile (file, cb) { | ||
if (file in readFileCache === false) { | ||
readFileCache[file] = readFileAsync(file).catch(function (err) { | ||
delete readFileCache[file]; | ||
throw err; | ||
}); | ||
} | ||
readFileCache[file].then(function (contents) { return cb(null, contents); }, cb); | ||
} | ||
var isFileCache = {}; | ||
function cachedIsFile (file, cb) { | ||
if (file in isFileCache === false) { | ||
isFileCache[file] = statAsync(file) | ||
.then( | ||
function (stat) { return stat.isFile(); }, | ||
function (err) { | ||
if (err.code == 'ENOENT') { return false; } | ||
delete isFileCache[file]; | ||
throw err; | ||
}); | ||
} | ||
isFileCache[file].then(function (contents) { return cb(null, contents); }, cb); | ||
} | ||
function nodeResolve ( options ) { | ||
@@ -52,2 +80,7 @@ if ( options === void 0 ) options = {}; | ||
onwrite: function onwrite () { | ||
isFileCache = {}; | ||
readFileCache = {}; | ||
}, | ||
resolveId: function resolveId$1 ( importee, importer ) { | ||
@@ -107,3 +140,3 @@ if ( /\0/.test( importee ) ) { return null; } // ignore IDs with null character, these belong to other plugins | ||
} | ||
if (options.browser && typeof pkg[ 'browser' ] === 'string') { | ||
@@ -120,2 +153,4 @@ pkg[ 'main' ] = pkg[ 'browser' ]; | ||
}, | ||
readFile: cachedReadFile, | ||
isFile: cachedIsFile, | ||
extensions: options.extensions | ||
@@ -122,0 +157,0 @@ }; |
@@ -16,2 +16,30 @@ import { dirname, resolve, extname, normalize, sep } from 'path'; | ||
var readFileCache = {}; | ||
var readFileAsync = function (file) { return new Promise(function (fulfil, reject) { return fs.readFile(file, function (err, contents) { return err ? reject(err) : fulfil(contents); }); }); }; | ||
var statAsync = function (file) { return new Promise(function (fulfil, reject) { return fs.stat(file, function (err, contents) { return err ? reject(err) : fulfil(contents); }); }); }; | ||
function cachedReadFile (file, cb) { | ||
if (file in readFileCache === false) { | ||
readFileCache[file] = readFileAsync(file).catch(function (err) { | ||
delete readFileCache[file]; | ||
throw err; | ||
}); | ||
} | ||
readFileCache[file].then(function (contents) { return cb(null, contents); }, cb); | ||
} | ||
var isFileCache = {}; | ||
function cachedIsFile (file, cb) { | ||
if (file in isFileCache === false) { | ||
isFileCache[file] = statAsync(file) | ||
.then( | ||
function (stat) { return stat.isFile(); }, | ||
function (err) { | ||
if (err.code == 'ENOENT') { return false; } | ||
delete isFileCache[file]; | ||
throw err; | ||
}); | ||
} | ||
isFileCache[file].then(function (contents) { return cb(null, contents); }, cb); | ||
} | ||
function nodeResolve ( options ) { | ||
@@ -48,2 +76,7 @@ if ( options === void 0 ) options = {}; | ||
onwrite: function onwrite () { | ||
isFileCache = {}; | ||
readFileCache = {}; | ||
}, | ||
resolveId: function resolveId$1 ( importee, importer ) { | ||
@@ -103,3 +136,3 @@ if ( /\0/.test( importee ) ) { return null; } // ignore IDs with null character, these belong to other plugins | ||
} | ||
if (options.browser && typeof pkg[ 'browser' ] === 'string') { | ||
@@ -116,2 +149,4 @@ pkg[ 'main' ] = pkg[ 'browser' ]; | ||
}, | ||
readFile: cachedReadFile, | ||
isFile: cachedIsFile, | ||
extensions: options.extensions | ||
@@ -118,0 +153,0 @@ }; |
{ | ||
"name": "rollup-plugin-node-resolve", | ||
"description": "Bundle third-party dependencies in node_modules", | ||
"version": "3.1.0", | ||
"version": "3.2.0", | ||
"devDependencies": { | ||
@@ -6,0 +6,0 @@ "buble": "^0.19.3", |
@@ -11,2 +11,30 @@ import { dirname, resolve, extname, normalize, sep } from 'path'; | ||
let readFileCache = {}; | ||
const readFileAsync = file => new Promise((fulfil, reject) => fs.readFile(file, (err, contents) => err ? reject(err) : fulfil(contents))); | ||
const statAsync = file => new Promise((fulfil, reject) => fs.stat(file, (err, contents) => err ? reject(err) : fulfil(contents))); | ||
function cachedReadFile (file, cb) { | ||
if (file in readFileCache === false) { | ||
readFileCache[file] = readFileAsync(file).catch(err => { | ||
delete readFileCache[file]; | ||
throw err; | ||
}); | ||
} | ||
readFileCache[file].then(contents => cb(null, contents), cb); | ||
} | ||
let isFileCache = {}; | ||
function cachedIsFile (file, cb) { | ||
if (file in isFileCache === false) { | ||
isFileCache[file] = statAsync(file) | ||
.then( | ||
stat => stat.isFile(), | ||
err => { | ||
if (err.code == 'ENOENT') return false; | ||
delete isFileCache[file]; | ||
throw err; | ||
}); | ||
} | ||
isFileCache[file].then(contents => cb(null, contents), cb); | ||
} | ||
export default function nodeResolve ( options = {} ) { | ||
@@ -41,2 +69,7 @@ const useModule = options.module !== false; | ||
onwrite () { | ||
isFileCache = {}; | ||
readFileCache = {}; | ||
}, | ||
resolveId ( importee, importer ) { | ||
@@ -96,3 +129,3 @@ if ( /\0/.test( importee ) ) return null; // ignore IDs with null character, these belong to other plugins | ||
} | ||
if (options.browser && typeof pkg[ 'browser' ] === 'string') { | ||
@@ -109,2 +142,4 @@ pkg[ 'main' ] = pkg[ 'browser' ]; | ||
}, | ||
readFile: cachedReadFile, | ||
isFile: cachedIsFile, | ||
extensions: options.extensions | ||
@@ -111,0 +146,0 @@ }; |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
27213
531
0