Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function flattenPolyfillDirectories(directory) {
// Recursively discover all subfolders and produce a flattened list.
// Directories prefixed with '__' are not polyfill features and are not included.
let results = [];
for (const item of fs.readdirSync(directory)) {
const joined = path.join(directory, item);
if (fs.lstatSync(joined).isDirectory() && item.indexOf('__') !== 0) {
results = results
.concat(flattenPolyfillDirectories(joined))
.concat(joined);
}
}
return results;
}
test('writes to symlinks without clobbering (sync)', function (t) {
t.plan(4)
var file = tmpFile()
var link = tmpFile()
fs.writeFileSync(file, '42')
fs.symlinkSync(file, link)
didWriteFileAtomicSync(t, currentUser(), link, '43')
t.is(readFile(file), '43', 'target content ok')
t.is(readFile(link), '43', 'link content ok')
t.ok(fs.lstatSync(link).isSymbolicLink(), 'link is link')
})
var onEnd = function(){
buffered.length.should.equal(1);
buffered[0].should.equal(expectedFile);
buffered[0].cwd.should.equal(__dirname, 'cwd should have changed');
buffered[0].base.should.equal(expectedBase, 'base should have changed');
buffered[0].path.should.equal(expectedPath, 'path should have changed');
fs.readlinkSync(expectedPath).should.equal(inputPath);
fs.lstatSync(expectedPath).isDirectory().should.equal(false);
fs.statSync(expectedPath).isDirectory().should.equal(true);
done();
};
var onEnd = function(){
expectedCount.should.equal(1);
assert(!chmodSpy.called);
realMode(fs.lstatSync(expectedPath).mode).should.equal(expectedMode);
done();
};
function assert(files) {
var stats = fs.lstatSync(outputPath);
expect(files.length).toEqual(1);
expect(files).toInclude(file);
expect(stats.size).toEqual(size);
};
var onEnd = function(){
masked(fs.lstatSync(expectedBase).mode).should.equal(expectedDirMode);
masked(buffered[0].stat.mode).should.equal(expectedFileMode);
cb();
};
var read = function (filePath, onFileLoad, onAllLoad) {
if (fs.lstatSync(filePath).isDirectory()) {
readDirectory(filePath, onFileLoad, onAllLoad);
}
else if (fileIsStylesheet(filePath)) {
readFile(filePath, function (err, data) {
onFileLoad(err, data);
onAllLoad();
});
} else {
onAllLoad();
}
}
function copyFileSync (srcFile, destFile, options) {
const overwrite = options.overwrite
const errorOnExist = options.errorOnExist
const preserveTimestamps = options.preserveTimestamps
if (fs.existsSync(destFile)) {
if (overwrite) {
fs.unlinkSync(destFile)
} else if (errorOnExist) {
throw new Error(`${destFile} already exists`)
} else return
}
if (typeof fs.copyFileSync === 'function') {
fs.copyFileSync(srcFile, destFile)
const st = fs.lstatSync(srcFile)
fs.chmodSync(destFile, st.mode)
if (preserveTimestamps) utimesSync(destFile, st.atime, st.mtime)
return undefined
}
return copyFileSyncFallback(srcFile, destFile, preserveTimestamps)
}
function markDir(file) {
if (file.slice(-1) !== path.sep) {
if (fs.lstatSync(file).isDirectory()) {
file += path.sep;
}
}
return file;
}
function createLinkSync (srcpath, dstpath, callback) {
var destinationExists = fs.existsSync(dstpath)
if (destinationExists) return undefined
try {
fs.lstatSync(srcpath)
} catch (err) {
err.message = err.message.replace('lstat', 'ensureLink')
throw err
}
var dir = path.dirname(dstpath)
var dirExists = fs.existsSync(dir)
if (dirExists) return fs.linkSync(srcpath, dstpath)
mkdir.mkdirsSync(dir)
return fs.linkSync(srcpath, dstpath)
}