Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
mkDirRecursive(dir, root, fnDir, dirSeparator = '/') {
let baseDir, recursiveDir, dirList;
if (dir === root) {
// Resolve the promise immediately as the root directory must exist
return Promise.resolve();
}
if (dir.startsWith(root) || dir.includes(tmp.tmpdir)) {
// Dir starts with the root path, or is part of the temporary file path
baseDir = utils.trimSeparators(dir.replace(root, ''), dirSeparator);
recursiveDir = baseDir.split(dirSeparator);
dirList = [];
// First, create a directory list for the Promise loop to iterate over
recursiveDir.reduce((acc, current) => {
let pathname = (acc === '' ? current : (acc + dirSeparator + current));
if (pathname !== '') {
dirList.push(
utils.addTrailingSeperator(root, dirSeparator) + pathname
);
}
return pathname;
module.exports.withDir = async function withDir(fn, options) {
const { path, cleanup } = await module.exports.dir(options);
try {
return await fn({ path });
} finally {
await cleanup();
}
};
// name generation
module.exports.tmpNameSync = tmp.tmpNameSync;
module.exports.tmpName = promisify(tmp.tmpName);
module.exports.tmpdir = tmp.tmpdir;
module.exports.setGracefulCleanup = tmp.setGracefulCleanup;
.then(function(dir) {
var dirname;
var osTempDir;
expect(dir).to.be.a('string');
expect(fs.existsSync(dir)).to.be(true);
dirname = path.dirname(dir);
osTempDir = path.resolve(tmp.tmpdir);
expect(dir.indexOf(osTempDir)).to.be(0);
expect(dir.indexOf(config.tmp)).to.be(0);
expect(path.basename(dirname)).to.equal('bower');
expect(path.dirname(path.dirname(dirname))).to.equal(
osTempDir
);
next();
})
.done();
.then(function (dir) {
var dirname;
var osTempDir;
expect(dir).to.be.a('string');
expect(fs.existsSync(dir)).to.be(true);
dirname = path.dirname(dir);
osTempDir = path.resolve(tmp.tmpdir);
expect(dir.indexOf(osTempDir)).to.be(0);
expect(dir.indexOf(defaultConfig.tmp)).to.be(0);
expect(path.basename(dirname)).to.equal('upt');
expect(path.dirname(path.dirname(dirname))).to.equal(osTempDir);
next();
})
.done();
function setupOutputRedirection() {
const fs = require('fs');
const tmp = require('tmp');
const papercutTmpDir = path.join(tmp.tmpdir, 'Papercut');
let debugPapercut = process.debugPapercut;
if (!debugPapercut) {
tmp.setGracefulCleanup();
}
if (!fs.existsSync(papercutTmpDir)){
fs.mkdirSync(papercutTmpDir)
}
let tempFile = tmp.fileSync(
{
prefix: 'Output-',
postfix: '.log',
discardDescriptor: true,
dir: papercutTmpDir,