lazy-require
Advanced tools
Comparing version 3.5.0 to 4.0.0-next.1589158074.b755edf0a64ce40929138266193f5da46b920bfe
/* eslint no-sync:0 */ | ||
'use strict'; // Import | ||
'use strict' // Import | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
function _slicedToArray(arr, i) { | ||
return ( | ||
_arrayWithHoles(arr) || | ||
_iterableToArrayLimit(arr, i) || | ||
_unsupportedIterableToArray(arr, i) || | ||
_nonIterableRest() | ||
) | ||
} | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _nonIterableRest() { | ||
throw new TypeError( | ||
'Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.' | ||
) | ||
} | ||
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _unsupportedIterableToArray(o, minLen) { | ||
if (!o) return | ||
if (typeof o === 'string') return _arrayLikeToArray(o, minLen) | ||
var n = Object.prototype.toString.call(o).slice(8, -1) | ||
if (n === 'Object' && o.constructor) n = o.constructor.name | ||
if (n === 'Map' || n === 'Set') return Array.from(o) | ||
if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) | ||
return _arrayLikeToArray(o, minLen) | ||
} | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _arrayLikeToArray(arr, len) { | ||
if (len == null || len > arr.length) len = arr.length | ||
for (var i = 0, arr2 = new Array(len); i < len; i++) { | ||
arr2[i] = arr[i] | ||
} | ||
return arr2 | ||
} | ||
var pathUtil = require('path'); | ||
function _iterableToArrayLimit(arr, i) { | ||
if (typeof Symbol === 'undefined' || !(Symbol.iterator in Object(arr))) return | ||
var _arr = [] | ||
var _n = true | ||
var _d = false | ||
var _e = undefined | ||
try { | ||
for ( | ||
var _i = arr[Symbol.iterator](), _s; | ||
!(_n = (_s = _i.next()).done); | ||
_n = true | ||
) { | ||
_arr.push(_s.value) | ||
if (i && _arr.length === i) break | ||
} | ||
} catch (err) { | ||
_d = true | ||
_e = err | ||
} finally { | ||
try { | ||
if (!_n && _i['return'] != null) _i['return']() | ||
} finally { | ||
if (_d) throw _e | ||
} | ||
} | ||
return _arr | ||
} | ||
var fsUtil = require('fs'); | ||
function _arrayWithHoles(arr) { | ||
if (Array.isArray(arr)) return arr | ||
} | ||
var safeps = require('safeps'); | ||
var pathUtil = require('path') | ||
var extractOptsAndCallback = require('extract-opts'); | ||
var fsUtil = require('fs') | ||
var Errlop = require('errlop'); // Prepare | ||
var safeps = require('safeps') | ||
var extractOptsAndCallback = require('extract-opts') | ||
var Errlop = require('errlop') // Prepare | ||
function complete(error, result, next) { | ||
if (next) { | ||
next(error, result); | ||
return null; | ||
} else { | ||
return error || result; | ||
} | ||
if (next) { | ||
next(error, result) | ||
return null | ||
} else { | ||
return error || result | ||
} | ||
} // ===================================== | ||
@@ -35,296 +91,263 @@ // Define Module | ||
function lazyRequire(name, opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba2 = _slicedToArray(_extractOptsAndCallba, 2) | ||
var _extractOptsAndCallba2 = _slicedToArray(_extractOptsAndCallba, 2); | ||
opts = _extractOptsAndCallba2[0]; | ||
next = _extractOptsAndCallba2[1]; | ||
// If we have a callback, then do async | ||
return next ? lazyRequire.async(name, opts, next) : lazyRequire.sync(name, opts); | ||
opts = _extractOptsAndCallba2[0] | ||
next = _extractOptsAndCallba2[1] | ||
// If we have a callback, then do async | ||
return next | ||
? lazyRequire.async(name, opts, next) | ||
: lazyRequire.sync(name, opts) | ||
} // Require or install a package synchronously or asynchronously | ||
lazyRequire.auto = function auto(name, opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba3 = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba3 = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba4 = _slicedToArray(_extractOptsAndCallba3, 2) | ||
var _extractOptsAndCallba4 = _slicedToArray(_extractOptsAndCallba3, 2); | ||
opts = _extractOptsAndCallba4[0] | ||
next = _extractOptsAndCallba4[1] | ||
opts = _extractOptsAndCallba4[0]; | ||
next = _extractOptsAndCallba4[1]; | ||
// If we have no callback, or if we support sync, then do sync | ||
if (!next || lazyRequire.canSyncInstall()) { | ||
return lazyRequire.requireOrInstallSync(name, opts, next) | ||
} else { | ||
return lazyRequire.requireOrInstallAsync(name, opts, next) | ||
} | ||
} // Require or install a package synchronously | ||
// If we have no callback, or if we support sync, then do sync | ||
if (!next || lazyRequire.canSyncInstall()) { | ||
return lazyRequire.requireOrInstallSync(name, opts, next); | ||
} else { | ||
return lazyRequire.requireOrInstallAsync(name, opts, next); | ||
} | ||
}; // Require or install a package synchronously | ||
lazyRequire.sync = function sync(name, opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba5 = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba5 = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba6 = _slicedToArray(_extractOptsAndCallba5, 2) | ||
var _extractOptsAndCallba6 = _slicedToArray(_extractOptsAndCallba5, 2); | ||
opts = _extractOptsAndCallba6[0] | ||
next = _extractOptsAndCallba6[1] | ||
opts = _extractOptsAndCallba6[0]; | ||
next = _extractOptsAndCallba6[1]; | ||
var result = lazyRequire.require(name, opts) | ||
var result = lazyRequire.require(name, opts); | ||
var error = null // Synchronous | ||
var error = null; // Synchronous | ||
if (result instanceof Error) { | ||
result = lazyRequire.installSync(name, opts) | ||
if (result instanceof Error) { | ||
result = lazyRequire.installSync(name, opts); | ||
if (result instanceof Error) { | ||
error = result | ||
result = null | ||
} | ||
} // Complete | ||
if (result instanceof Error) { | ||
error = result; | ||
result = null; | ||
} | ||
} // Complete | ||
return complete(error, result, next) | ||
} // Require or install a package asynchronously | ||
return complete(error, result, next); | ||
}; // Require or install a package asynchronously | ||
lazyRequire.async = function async(name, opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba7 = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba7 = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba8 = _slicedToArray(_extractOptsAndCallba7, 2) | ||
var _extractOptsAndCallba8 = _slicedToArray(_extractOptsAndCallba7, 2); | ||
opts = _extractOptsAndCallba8[0] | ||
next = _extractOptsAndCallba8[1] | ||
opts = _extractOptsAndCallba8[0]; | ||
next = _extractOptsAndCallba8[1]; | ||
// Asynchronous | ||
lazyRequire.require(name, opts, function (error, result) { | ||
if (result) return next(error, result) | ||
lazyRequire.installAsync(name, opts, next) | ||
}) // Exit | ||
// Asynchronous | ||
lazyRequire.require(name, opts, function (error, result) { | ||
if (result) return next(error, result); | ||
lazyRequire.installAsync(name, opts, next); | ||
}); // Exit | ||
return null | ||
} // Attempt to require a module | ||
return null; | ||
}; // Attempt to require a module | ||
lazyRequire.require = function _require(name, opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba9 = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba9 = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba10 = _slicedToArray(_extractOptsAndCallba9, 2) | ||
var _extractOptsAndCallba10 = _slicedToArray(_extractOptsAndCallba9, 2); | ||
opts = _extractOptsAndCallba10[0] | ||
next = _extractOptsAndCallba10[1] | ||
var result = null | ||
var error = null // Fetch | ||
opts = _extractOptsAndCallba10[0]; | ||
next = _extractOptsAndCallba10[1]; | ||
var result = null; | ||
var error = null; // Fetch | ||
try { | ||
result = require(name) | ||
} catch (e1) { | ||
error = e1 | ||
try { | ||
result = require(name); | ||
} catch (e1) { | ||
error = e1; | ||
if (opts.cwd) { | ||
try { | ||
var path = pathUtil.join(opts.cwd, 'node_modules', name) | ||
result = require(path) | ||
error = null | ||
} catch (e2) { | ||
error = new Errlop(e2, error) | ||
if (opts.cwd) { | ||
try { | ||
var path = pathUtil.join(opts.cwd, 'node_modules', name); | ||
result = require(path); | ||
error = null; | ||
} catch (e2) { | ||
error = new Errlop(e2, error); | ||
try { | ||
var _path = pathUtil.join(opts.cwd, 'node_modules', name) | ||
try { | ||
var _path = pathUtil.join(opts.cwd, 'node_modules', name); | ||
var pkg = pathUtil.join(_path, 'package.json') | ||
var main = pathUtil.join(_path, require(pkg).main) | ||
result = require(main) | ||
error = null | ||
} catch (e3) { | ||
error = new Errlop(e3, error) | ||
} | ||
} | ||
} | ||
} // Complete | ||
var pkg = pathUtil.join(_path, 'package.json'); | ||
var main = pathUtil.join(_path, require(pkg).main); | ||
result = require(main); | ||
error = null; | ||
} catch (e3) { | ||
error = new Errlop(e3, error); | ||
} | ||
} | ||
} | ||
} // Complete | ||
return complete(error, result, next) | ||
} // Can Save | ||
return complete(error, result, next); | ||
}; // Can Save | ||
lazyRequire.canSave = function canSave(name, opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba11 = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba11 = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba12 = _slicedToArray(_extractOptsAndCallba11, 2) | ||
var _extractOptsAndCallba12 = _slicedToArray(_extractOptsAndCallba11, 2); | ||
opts = _extractOptsAndCallba12[0] | ||
next = _extractOptsAndCallba12[1] | ||
var result = null | ||
var error = null // Options | ||
opts = _extractOptsAndCallba12[0]; | ||
next = _extractOptsAndCallba12[1]; | ||
var result = null; | ||
var error = null; // Options | ||
if (opts.cwd == null) { | ||
opts.cwd = process.cwd() | ||
} | ||
if (opts.cwd == null) { | ||
opts.cwd = process.cwd(); | ||
} | ||
opts.packagePath = pathUtil.join(opts.cwd, 'package.json') // Fetch | ||
opts.packagePath = pathUtil.join(opts.cwd, 'package.json'); // Fetch | ||
try { | ||
result = fsUtil.existsSync(opts.packagePath) === true | ||
} catch (err) { | ||
error = err | ||
} // Complete | ||
try { | ||
result = fsUtil.existsSync(opts.packagePath) === true; | ||
} catch (err) { | ||
error = err; | ||
} // Complete | ||
return complete(error, result, next) | ||
} // Can install synchronously | ||
return complete(error, result, next); | ||
}; // Can install synchronously | ||
lazyRequire.canSyncInstall = function canSyncInstall(opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba13 = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba13 = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba14 = _slicedToArray(_extractOptsAndCallba13, 2) | ||
var _extractOptsAndCallba14 = _slicedToArray(_extractOptsAndCallba13, 2); | ||
opts = _extractOptsAndCallba14[0] | ||
next = _extractOptsAndCallba14[1] | ||
var result = safeps.hasSpawnSync() | ||
var error = null // Fetch | ||
opts = _extractOptsAndCallba14[0]; | ||
next = _extractOptsAndCallba14[1]; | ||
var result = safeps.hasSpawnSync(); | ||
var error = null; // Fetch | ||
if (result instanceof Error) { | ||
error = result | ||
result = null | ||
} // Complete | ||
if (result instanceof Error) { | ||
error = result; | ||
result = null; | ||
} // Complete | ||
return complete(error, result, next); | ||
}; // Attempt to require a module (will install if missing) | ||
return complete(error, result, next) | ||
} // Attempt to require a module (will install if missing) | ||
// Asynchronous with optional callback | ||
lazyRequire.installAsync = function installAsync(name, opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba15 = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba15 = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba16 = _slicedToArray(_extractOptsAndCallba15, 2) | ||
var _extractOptsAndCallba16 = _slicedToArray(_extractOptsAndCallba15, 2); | ||
opts = _extractOptsAndCallba16[0] | ||
next = _extractOptsAndCallba16[1] | ||
var error = null // Defaults | ||
opts = _extractOptsAndCallba16[0]; | ||
next = _extractOptsAndCallba16[1]; | ||
var error = null; // Defaults | ||
if (opts.save == null) { | ||
opts.save = false | ||
} | ||
if (opts.save == null) { | ||
opts.save = false; | ||
} | ||
if (opts.cwd == null) { | ||
opts.cwd = process.cwd() | ||
} // Check that we are not in the browser | ||
if (opts.cwd == null) { | ||
opts.cwd = process.cwd(); | ||
} // Check that we are not in the browser | ||
if (process.browser === true) { | ||
error = new Error('lazy-require: installing in the browser is not possible') | ||
} // Check saving | ||
else if (opts.save === true && lazyRequire.canSave() === false) { | ||
error = new Error( | ||
'lazy-require: cannot save the module as `opts.cwd` did not contain a `package.json` file' | ||
) | ||
} // Install | ||
else { | ||
// Arguments | ||
var args = ['npm', 'install', name] | ||
if (opts.save === true) { | ||
args.push('--save') | ||
opts.save = null // {delete opts.save} is very slow | ||
} // Install | ||
if (process.browser === true) { | ||
error = new Error('lazy-require: installing in the browser is not possible'); | ||
} // Check saving | ||
else if (opts.save === true && lazyRequire.canSave() === false) { | ||
error = new Error('lazy-require: cannot save the module as `opts.cwd` did not contain a `package.json` file'); | ||
} // Install | ||
else { | ||
// Arguments | ||
var args = ['npm', 'install', name]; | ||
safeps.spawn(args, opts, function (err) { | ||
// Check | ||
if (err) return next(err) // Try to load the module | ||
if (opts.save === true) { | ||
args.push('--save'); | ||
opts.save = null; // {delete opts.save} is very slow | ||
} // Install | ||
lazyRequire.require(name, opts, next) | ||
}) // Exit | ||
return null | ||
} // Complete | ||
safeps.spawn(args, opts, function (err) { | ||
// Check | ||
if (err) return next(err); // Try to load the module | ||
lazyRequire.require(name, opts, next); | ||
}); // Exit | ||
return null; | ||
} // Complete | ||
return complete(error, null, next); | ||
}; // Attempt to require a module (will install if missing) | ||
return complete(error, null, next) | ||
} // Attempt to require a module (will install if missing) | ||
// Synchronous with optional callback | ||
lazyRequire.installSync = function installSync(name, opts, next) { | ||
// Prepare | ||
; | ||
// Prepare | ||
var _extractOptsAndCallba17 = extractOptsAndCallback(opts, next) | ||
var _extractOptsAndCallba17 = extractOptsAndCallback(opts, next); | ||
var _extractOptsAndCallba18 = _slicedToArray(_extractOptsAndCallba17, 2) | ||
var _extractOptsAndCallba18 = _slicedToArray(_extractOptsAndCallba17, 2); | ||
opts = _extractOptsAndCallba18[0] | ||
next = _extractOptsAndCallba18[1] | ||
var error = null // Defaults | ||
opts = _extractOptsAndCallba18[0]; | ||
next = _extractOptsAndCallba18[1]; | ||
var error = null; // Defaults | ||
if (opts.save == null) { | ||
opts.save = false | ||
} | ||
if (opts.save == null) { | ||
opts.save = false; | ||
} | ||
if (opts.cwd == null) { | ||
opts.cwd = process.cwd() | ||
} // Check that we are not in the browser | ||
if (opts.cwd == null) { | ||
opts.cwd = process.cwd(); | ||
} // Check that we are not in the browser | ||
if (typeof process !== 'undefined' && process.browser === true) { | ||
error = new Error('lazy-require: installing in the browser is not possible') | ||
} // Check that spawnSync exists, check that the project's package.json exists | ||
else if (lazyRequire.canSyncInstall() === false) { | ||
error = new Error('lazy-require: installing synchronously is not possible') | ||
} // Check saving | ||
else if (opts.save === true && lazyRequire.canSave() === false) { | ||
error = new Error( | ||
'lazy-require: cannot save the module as `opts.cwd` did not contain a `package.json` file' | ||
) | ||
} // Install | ||
else { | ||
// Arguments | ||
var args = ['npm', 'install', name] | ||
if (opts.save === true) { | ||
args.push('--save') | ||
opts.save = null // {delete opts.save} is very slow | ||
} // Install | ||
if (typeof process !== 'undefined' && process.browser === true) { | ||
error = new Error('lazy-require: installing in the browser is not possible'); | ||
} // Check that spawnSync exists, check that the project's package.json exists | ||
else if (lazyRequire.canSyncInstall() === false) { | ||
error = new Error('lazy-require: installing synchronously is not possible'); | ||
} // Check saving | ||
else if (opts.save === true && lazyRequire.canSave() === false) { | ||
error = new Error('lazy-require: cannot save the module as `opts.cwd` did not contain a `package.json` file'); | ||
} // Install | ||
else { | ||
// Arguments | ||
var args = ['npm', 'install', name]; | ||
var spawnResult = safeps.spawnSync(args, opts) | ||
if (opts.save === true) { | ||
args.push('--save'); | ||
opts.save = null; // {delete opts.save} is very slow | ||
} // Install | ||
if (spawnResult instanceof Error) { | ||
error = spawnResult | ||
} else { | ||
// Exit | ||
return lazyRequire.require(name, opts, next) | ||
} | ||
} // Complete | ||
return complete(error, null, next) | ||
} // Export | ||
var spawnResult = safeps.spawnSync(args, opts); | ||
if (spawnResult instanceof Error) { | ||
error = spawnResult; | ||
} else { | ||
// Exit | ||
return lazyRequire.require(name, opts, next); | ||
} | ||
} // Complete | ||
return complete(error, null, next); | ||
}; // Export | ||
module.exports = lazyRequire; | ||
module.exports = lazyRequire |
# History | ||
## v4.0.0 2020 May 11 | ||
- Updated dependencies, [base files](https://github.com/bevry/base), and [editions](https://editions.bevry.me) using [boundation](https://github.com/bevry/boundation) | ||
- Minimum required node version changed from `node: >=8` to `node: >=10` to keep up with mandatory ecosystem changes | ||
## v3.5.0 2019 December 9 | ||
@@ -4,0 +9,0 @@ |
{ | ||
"title": "Lazy Require", | ||
"name": "lazy-require", | ||
"version": "3.5.0", | ||
"version": "4.0.0-next.1589158074.b755edf0a64ce40929138266193f5da46b920bfe", | ||
"description": "Lazy require allows you to require modules lazily, meaning that when you lazy require a module that is missing, lazy require will automatically install it for you.", | ||
@@ -9,8 +9,11 @@ "homepage": "https://github.com/bevry/lazy-require", | ||
"keywords": [ | ||
"require", | ||
"browser", | ||
"dependencies", | ||
"deps", | ||
"esnext", | ||
"lazy", | ||
"node", | ||
"optDependencies", | ||
"optionalDependencies", | ||
"optDependencies", | ||
"dependencies", | ||
"deps" | ||
"require" | ||
], | ||
@@ -45,3 +48,7 @@ "badges": { | ||
"wishlistURL": "https://bevry.me/wishlist", | ||
"travisTLD": "com" | ||
"travisTLD": "com", | ||
"githubUsername": "bevry", | ||
"githubRepository": "lazy-require", | ||
"githubSlug": "bevry/lazy-require", | ||
"npmPackageName": "lazy-require" | ||
} | ||
@@ -52,8 +59,7 @@ }, | ||
"maintainers": [ | ||
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)" | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)" | ||
], | ||
"contributors": [ | ||
"Benjamin Lupton <b@lupton.cc> (http://balupton.com)", | ||
"Rob Loach <robloach@gmail.com> (http://robloach.net)", | ||
"dependabot-preview[bot] (http://github.com/apps/dependabot-preview)" | ||
"Benjamin Lupton <b@lupton.cc> (https://github.com/balupton)", | ||
"Rob Loach <robloach@gmail.com> (https://github.com/RobLoach)" | ||
], | ||
@@ -68,7 +74,7 @@ "bugs": { | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
"editions": [ | ||
{ | ||
"description": "esnext source code with require for modules", | ||
"description": "ESNext source code for Node.js with Require for modules", | ||
"directory": "source", | ||
@@ -82,3 +88,3 @@ "entry": "index.js", | ||
"engines": { | ||
"node": "8 || 10 || 12", | ||
"node": "10 || 12 || 13 || 14", | ||
"browsers": false | ||
@@ -88,3 +94,3 @@ } | ||
{ | ||
"description": "esnext compiled for browsers with require for modules", | ||
"description": "ESNext compiled for web browsers with Require for modules", | ||
"directory": "edition-browsers", | ||
@@ -103,25 +109,27 @@ "entry": "index.js", | ||
"type": "commonjs", | ||
"main": "source/index.js", | ||
"main": "index.js", | ||
"browser": "edition-browsers/index.js", | ||
"dependencies": { | ||
"errlop": "^1.7.0", | ||
"editions": "^2.3.0", | ||
"errlop": "^2.2.0", | ||
"extract-opts": "^4.3.0", | ||
"safeps": "^9.2.0" | ||
"safeps": "^9.3.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/cli": "^7.7.5", | ||
"@babel/core": "^7.7.5", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.7.4", | ||
"@babel/preset-env": "^7.7.6", | ||
"assert-helpers": "^5.8.0", | ||
"eslint": "^6.7.2", | ||
"eslint-config-bevry": "^2.3.0", | ||
"eslint-config-prettier": "^6.7.0", | ||
"@babel/cli": "^7.8.4", | ||
"@babel/core": "^7.9.6", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.9.6", | ||
"@babel/preset-env": "^7.9.6", | ||
"@bevry/update-contributors": "^1.1.0", | ||
"assert-helpers": "^6.2.0", | ||
"eslint": "^7.0.0", | ||
"eslint-config-bevry": "^3.4.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-babel": "^5.3.0", | ||
"eslint-plugin-prettier": "^3.1.1", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"kava": "^4.4.0", | ||
"prettier": "^1.19.1", | ||
"projectz": "^1.15.0", | ||
"rimraf": "^3.0.0", | ||
"valid-directory": "^1.5.0" | ||
"prettier": "^2.0.5", | ||
"projectz": "^2.0.0", | ||
"rimraf": "^3.0.2", | ||
"valid-directory": "^1.6.0" | ||
}, | ||
@@ -133,4 +141,5 @@ "scripts": { | ||
"our:deploy": "echo no need for this project", | ||
"our:meta": "npm run our:meta:projectz", | ||
"our:meta:projectz": "projectz compile", | ||
"our:meta": "npm run our:meta:contributors && npm run our:meta:projectz", | ||
"our:meta:contributors": "npx @bevry/update-contributors", | ||
"our:meta:projectz": "npx projectz compile", | ||
"our:release": "npm run our:release:prepare && npm run our:release:check-changelog && npm run our:release:check-dirty && npm run our:release:tag && npm run our:release:push", | ||
@@ -147,5 +156,5 @@ "our:release:check-changelog": "cat ./HISTORY.md | grep v$npm_package_version || (echo add a changelog entry for v$npm_package_version && exit -1)", | ||
"our:verify:directory": "npx valid-directory", | ||
"our:verify:eslint": "eslint --fix --ignore-pattern '**/*.d.ts' --ignore-pattern '**/vendor/' --ignore-pattern '**/node_modules/' --ext .mjs,.js,.jsx,.ts,.tsx ./source", | ||
"our:verify:prettier": "prettier --write ./source/**", | ||
"test": "node ./source/test.js" | ||
"our:verify:eslint": "npx eslint --fix --ignore-pattern '**/*.d.ts' --ignore-pattern '**/vendor/' --ignore-pattern '**/node_modules/' --ext .mjs,.js,.jsx,.ts,.tsx ./source", | ||
"our:verify:prettier": "prettier --write .", | ||
"test": "node ./test.js" | ||
}, | ||
@@ -169,3 +178,6 @@ "eslintConfig": { | ||
{ | ||
"targets": "defaults", | ||
"targets": { | ||
"esmodules": false, | ||
"browsers": "defaults" | ||
}, | ||
"modules": false | ||
@@ -172,0 +184,0 @@ } |
140
README.md
@@ -7,3 +7,2 @@ <!-- TITLE/ --> | ||
<!-- BADGES/ --> | ||
@@ -29,3 +28,2 @@ | ||
<!-- DESCRIPTION/ --> | ||
@@ -37,35 +35,5 @@ | ||
<!-- INSTALL/ --> | ||
<h2>Install</h2> | ||
<a href="https://npmjs.com" title="npm is a package manager for javascript"><h3>npm</h3></a> | ||
<ul> | ||
<li>Install: <code>npm install --save lazy-require</code></li> | ||
<li>Require: <code>require('lazy-require')</code></li> | ||
</ul> | ||
<a href="https://jspm.io" title="Native ES Modules CDN"><h3>jspm</h3></a> | ||
``` html | ||
<script type="module"> | ||
import * as pkg from '//dev.jspm.io/lazy-require' | ||
</script> | ||
``` | ||
<h3><a href="https://editions.bevry.me" title="Editions are the best way to produce and consume packages you care about.">Editions</a></h3> | ||
<p>This package is published with the following editions:</p> | ||
<ul><li><code>lazy-require</code> aliases <code>lazy-require/source/index.js</code></li> | ||
<li><code>lazy-require/source/index.js</code> is esnext source code with require for modules</li> | ||
<li><code>lazy-require/edition-browsers/index.js</code> is esnext compiled for browsers with require for modules</li></ul> | ||
<!-- /INSTALL --> | ||
## Usage | ||
``` javascript | ||
```javascript | ||
// Import | ||
@@ -77,8 +45,10 @@ var lazyRequire = require('lazy-require') | ||
// Passing a callback as the 3rd argument will do this asynchronously, available in all node versions | ||
var ambi = lazyRequire('ambi', {/* options */}) | ||
if ( ambi instanceof Error ) { | ||
// Error .... | ||
console.log('ambi failed to load because of:', ambi.stack) | ||
var ambi = lazyRequire('ambi', { | ||
/* options */ | ||
}) | ||
if (ambi instanceof Error) { | ||
// Error .... | ||
console.log('ambi failed to load because of:', ambi.stack) | ||
} else { | ||
// Success ... | ||
// Success ... | ||
} | ||
@@ -88,26 +58,47 @@ | ||
// Do this synchronously but with a callback, only available in Node 0.12 and above | ||
lazyRequire.sync('ambi', {/* options */}, function(err, ambi){ | ||
// Error ... | ||
if (err) return console.log('ambi failed to load because of:', err.stack) | ||
lazyRequire.sync( | ||
'ambi', | ||
{ | ||
/* options */ | ||
}, | ||
function (err, ambi) { | ||
// Error ... | ||
if (err) | ||
return console.log('ambi failed to load because of:', err.stack) | ||
// Success ... | ||
}) | ||
// Success ... | ||
} | ||
) | ||
// Attempt to load the module `ambi`, if it doesn't exist, then try to install it and load it again | ||
// Do this asynchronously, available in all node versions | ||
lazyRequire.async('ambi', {/* options */}, function(err, ambi){ | ||
// Error ... | ||
if (err) return console.log('ambi failed to load because of:', err.stack) | ||
lazyRequire.async( | ||
'ambi', | ||
{ | ||
/* options */ | ||
}, | ||
function (err, ambi) { | ||
// Error ... | ||
if (err) | ||
return console.log('ambi failed to load because of:', err.stack) | ||
// Success ... | ||
}) | ||
// Success ... | ||
} | ||
) | ||
// Attempt to load the module `ambi`, if it doesn't exist, then try to install it and load it again | ||
// Do this synchronously if supported (Node 0.12 and above), otherwise do it asynchronously | ||
lazyRequire.auto('ambi', {/* options */}, function(err, ambi){ | ||
// Error ... | ||
if (err) return console.log('ambi failed to load because of:', err.stack) | ||
lazyRequire.auto( | ||
'ambi', | ||
{ | ||
/* options */ | ||
}, | ||
function (err, ambi) { | ||
// Error ... | ||
if (err) | ||
return console.log('ambi failed to load because of:', err.stack) | ||
// Success ... | ||
}) | ||
// Success ... | ||
} | ||
) | ||
``` | ||
@@ -117,8 +108,37 @@ | ||
- `cwd` the module path that you would like the requested package to be installed to if it doesn't exist, always recommended | ||
- `save` if the requested package doesn't exist, would you like to do a `npm --save` for it to add it to your `cwd`'s `package.json` dependencies? | ||
- `cwd` the module path that you would like the requested package to be installed to if it doesn't exist, always recommended | ||
- `save` if the requested package doesn't exist, would you like to do a `npm --save` for it to add it to your `cwd`'s `package.json` dependencies? | ||
There's some other methods also available to you, for now, read the source to discover them. | ||
<!-- INSTALL/ --> | ||
<h2>Install</h2> | ||
<a href="https://npmjs.com" title="npm is a package manager for javascript"><h3>npm</h3></a> | ||
<ul> | ||
<li>Install: <code>npm install --save lazy-require</code></li> | ||
<li>Import: <code>import * as pkg from ('lazy-require')</code></li> | ||
<li>Require: <code>const pkg = require('lazy-require')</code></li> | ||
</ul> | ||
<a href="https://jspm.io" title="Native ES Modules CDN"><h3>jspm</h3></a> | ||
```html | ||
<script type="module"> | ||
import * as pkg from '//dev.jspm.io/lazy-require@4.0.0' | ||
</script> | ||
``` | ||
<h3><a href="https://editions.bevry.me" title="Editions are the best way to produce and consume packages you care about.">Editions</a></h3> | ||
<p>This package is published with the following editions:</p> | ||
<ul><li><code>lazy-require</code> aliases <code>lazy-require/index.js</code> which uses the <a href="https://github.com/bevry/editions" title="You can use the Editions Autoloader to autoload the appropriate edition for your consumers environment">Editions Autoloader</a> to automatically select the correct edition for the consumer's environment</li> | ||
<li><code>lazy-require/source/index.js</code> is <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> source code for <a href="https://nodejs.org" title="Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine">Node.js</a> with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li> | ||
<li><code>lazy-require/edition-browsers/index.js</code> is <a href="https://en.wikipedia.org/wiki/ECMAScript#ES.Next" title="ECMAScript Next">ESNext</a> compiled for web browsers with <a href="https://nodejs.org/dist/latest-v5.x/docs/api/modules.html" title="Node/CJS Modules">Require</a> for modules</li></ul> | ||
<!-- /INSTALL --> | ||
<!-- HISTORY/ --> | ||
@@ -132,3 +152,2 @@ | ||
<!-- CONTRIBUTE/ --> | ||
@@ -142,3 +161,2 @@ | ||
<!-- BACKERS/ --> | ||
@@ -152,3 +170,3 @@ | ||
<ul><li><a href="http://balupton.com">Benjamin Lupton</a> — <a href="https://github.com/bevry/lazy-require/commits?author=balupton" title="View the GitHub contributions of Benjamin Lupton on repository bevry/lazy-require">view contributions</a></li></ul> | ||
<ul><li><a href="https://github.com/balupton">Benjamin Lupton</a> — <a href="https://github.com/bevry/lazy-require/commits?author=balupton" title="View the GitHub contributions of Benjamin Lupton on repository bevry/lazy-require">view contributions</a></li></ul> | ||
@@ -173,5 +191,4 @@ <h3>Sponsors</h3> | ||
<ul><li><a href="http://balupton.com">Benjamin Lupton</a> — <a href="https://github.com/bevry/lazy-require/commits?author=balupton" title="View the GitHub contributions of Benjamin Lupton on repository bevry/lazy-require">view contributions</a></li> | ||
<li><a href="http://robloach.net">Rob Loach</a> — <a href="https://github.com/bevry/lazy-require/commits?author=RobLoach" title="View the GitHub contributions of Rob Loach on repository bevry/lazy-require">view contributions</a></li> | ||
<li><a href="http://github.com/apps/dependabot-preview">dependabot-preview[bot]</a> — <a href="https://github.com/bevry/lazy-require/commits?author=dependabot-preview[bot]" title="View the GitHub contributions of dependabot-preview[bot] on repository bevry/lazy-require">view contributions</a></li></ul> | ||
<ul><li><a href="https://github.com/balupton">Benjamin Lupton</a> — <a href="https://github.com/bevry/lazy-require/commits?author=balupton" title="View the GitHub contributions of Benjamin Lupton on repository bevry/lazy-require">view contributions</a></li> | ||
<li><a href="https://github.com/RobLoach">Rob Loach</a> — <a href="https://github.com/bevry/lazy-require/commits?author=RobLoach" title="View the GitHub contributions of Rob Loach on repository bevry/lazy-require">view contributions</a></li></ul> | ||
@@ -182,3 +199,2 @@ <a href="https://github.com/bevry/lazy-require/blob/master/CONTRIBUTING.md#files">Discover how you can contribute by heading on over to the <code>CONTRIBUTING.md</code> file.</a> | ||
<!-- LICENSE/ --> | ||
@@ -185,0 +201,0 @@ |
@@ -75,3 +75,3 @@ /* eslint no-sync:0 */ | ||
// Asynchronous | ||
lazyRequire.require(name, opts, function(error, result) { | ||
lazyRequire.require(name, opts, function (error, result) { | ||
if (result) return next(error, result) | ||
@@ -199,3 +199,3 @@ lazyRequire.installAsync(name, opts, next) | ||
// Install | ||
safeps.spawn(args, opts, function(err) { | ||
safeps.spawn(args, opts, function (err) { | ||
// Check | ||
@@ -202,0 +202,0 @@ if (err) return next(err) |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
37482
510
202
4
16
1
+ Addededitions@^2.3.0
- Removederrlop@1.7.0(transitive)
Updatederrlop@^2.2.0
Updatedsafeps@^9.3.0