Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Extend and dereference our configuration
this.config = extendr.deep(
{
log: null,
cache: 1000 * 60 * 60 * 24, // one day by default
tmpPath: null,
requestOptions: null,
plugins: null
},
this.config || {},
config
)
// Get the temp path right away
safeps.getTmpPath(function(err, tmpPath) {
if (err) {
console.error(err)
} else {
me.config.tmpPath = tmpPath
}
})
}
error = new Error(
'lazy-require: cannot save the module as `opts.cwd` did not contain a `package.json` file'
)
}
// Install
else {
// Arguments
const args = ['npm', 'install', name]
if (opts.save === true) {
args.push('--save')
opts.save = null // {delete opts.save} is very slow
}
// Install
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)
}
lazyRequire.canSyncInstall = function canSyncInstall(opts, next) {
// Prepare
;[opts, next] = extractOptsAndCallback(opts, next)
let result = safeps.hasSpawnSync()
let error = null
// Fetch
if (result instanceof Error) {
error = result
result = null
}
// Complete
return complete(error, result, next)
}
error = new Error(
'lazy-require: cannot save the module as `opts.cwd` did not contain a `package.json` file'
)
}
// Install
else {
// Arguments
const args = ['npm', 'install', name]
if (opts.save === true) {
args.push('--save')
opts.save = null // {delete opts.save} is very slow
}
// Install
const 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)
}
return new Promise(function(resolve, reject) {
safeps.spawn(command, opts, function(err, stdout) {
if (err)
return reject(new Errlop(`spawn failed: ${command.join(' ')}`, err))
return resolve(stdout)
})
})
}
startLocalDocPadExecutable: function(next) {
var args, command;
args = process.argv.slice(2);
command = ['node', docpadUtil.getLocalDocPadExecutable()].concat(args);
return require('safeps').spawn(command, {
stdio: 'inherit'
}, function(err) {
var message;
if (err) {
if (next) {
return next(err);
} else {
message = 'An error occured within the child DocPad instance: ' + err.message + '\n';
return process.stderr.write(message);
}
} else {
return typeof next === "function" ? next() : void 0;
}
});
},
getBasename: function(filename) {
return new Promise(function(resolve, reject) {
safeps.exec(command, opts, function(err, stdout) {
if (err) return reject(new Errlop(`exec failed: ${command}`, err))
return resolve(stdout)
})
})
}