it('should resolve to the highest package that matches a range target, not ignoring pre-releases if they are the only versions', function (next) { var source = String(Math.random()); var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); var json = { name: 'foo' }; // Create some versions fs.mkdirSync(sourceDir); json.version = '0.1.0-rc.1'; fs.mkdirSync(path.join(sourceDir, '0.1.0-rc.1')); fs.writeFileSync(path.join(sourceDir, '0.1.0-rc.1', '.bower.json'), JSON.stringify(json, null, ' ')); json.version = '0.1.0-rc.2'; fs.mkdirSync(path.join(sourceDir, '0.1.0-rc.2')); fs.writeFileSync(path.join(sourceDir, '0.1.0-rc.2', '.bower.json'), JSON.stringify(json, null, ' ')); resolveCache.retrieve(source, '~0.1.0') .spread(function (canonicalDir, pkgMeta) { expect(pkgMeta).to.be.an('object'); expect(pkgMeta.version).to.equal('0.1.0-rc.2'); expect(canonicalDir).to.equal(path.join(sourceDir, '0.1.0-rc.2')); next(); }) .done(); });
it('should remove entry from in memory cache if the source-md5 folder was deleted', function (next) { var source = String(Math.random()); var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); // Create some versions fs.mkdirSync(sourceDir); fs.mkdirSync(path.join(sourceDir, '0.0.1')); // Feed up the cache resolveCache.versions(source) // Eliminate .then(function () { return resolveCache.eliminate({ name: 'foo', version: '0.0.1', _source: source, _target: '*' }); }) .then(function () { // At this point the parent folder should be deleted // To test against the in-memory cache, we create a folder // manually and request the versions mkdirp.sync(path.join(sourceDir, '0.0.2')); resolveCache.versions(source) .then(function (versions) { expect(versions).to.eql(['0.0.2']); next(); }); }) .done(); });
it('should erase the in-memory cache', function (next) { var source = String(Math.random()); var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); // Create some versions fs.mkdirSync(sourceDir); fs.mkdirSync(path.join(sourceDir, '0.0.1')); // Feed the in-memory cache resolveCache.versions(source) .then(function () { // Delete 0.0.1 and create 0.0.2 fs.rmdirSync(path.join(sourceDir, '0.0.1')); fs.mkdirSync(path.join(sourceDir, '0.0.2')); // Reset cache resolveCache.reset(); // Get versions return resolveCache.versions(source); }) .then(function (versions) { expect(versions).to.eql(['0.0.2']); next(); }) .done(); });
it('should remove invalid packages from the cache if their package meta is missing or invalid', function (next) { var source = String(Math.random()); var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); // Create some versions fs.mkdirSync(sourceDir); fs.mkdirSync(path.join(sourceDir, '0.0.1')); fs.mkdirSync(path.join(sourceDir, '0.1.0')); fs.mkdirSync(path.join(sourceDir, '0.1.9')); fs.mkdirSync(path.join(sourceDir, '0.2.0')); // Create an invalid package meta fs.writeFileSync(path.join(sourceDir, '0.2.0', '.bower.json'), 'w00t'); resolveCache.retrieve(source, '~0.1.0') .spread(function () { var dirs = fs.readdirSync(sourceDir); expect(arguments.length).to.equal(0); expect(dirs).to.contain('0.0.1'); expect(dirs).to.contain('0.2.0'); next(); }) .done(); });
it('should resolve to empty if there are no suitable packages for the requested target', function (next) { var source = String(Math.random()); var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); // Create some versions fs.mkdirSync(sourceDir); fs.mkdirSync(path.join(sourceDir, '0.0.1')); fs.mkdirSync(path.join(sourceDir, '0.1.0')); fs.mkdirSync(path.join(sourceDir, '0.1.9')); fs.mkdirSync(path.join(sourceDir, '0.2.0')); resolveCache.retrieve(source, '~0.3.0') .spread(function () { expect(arguments.length).to.equal(0); return resolveCache.retrieve(source, 'some-branch'); }) .spread(function () { expect(arguments.length).to.equal(0); next(); }) .done(); });
it('should erase the in-memory cache', function (next) { var source = String(Math.random()); var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); // Create some versions fs.mkdirSync(sourceDir); fs.mkdirSync(path.join(sourceDir, '0.0.1')); // Feed the in-memory cache resolveCache.versions(source) // Clear .then(function () { return resolveCache.clear(); }) .then(function () { // To test against the in-memory cache, we create a folder // manually and request the versions mkdirp.sync(path.join(sourceDir, '0.0.2')); resolveCache.versions(source) .then(function (versions) { expect(versions).to.eql(['0.0.2']); next(); }); }) .done(); });
it('should delete entries if failed to read package meta', function (next) { var source = 'list-package-1'; var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); var json = { name: 'foo' }; // Create invalid versions fs.mkdirSync(sourceDir); fs.mkdirSync(path.join(sourceDir, '0.0.1')); fs.mkdirSync(path.join(sourceDir, '0.0.2')); fs.writeFileSync(path.join(sourceDir, '0.0.2', '.bower.json'), 'w00t'); // Create valid version fs.mkdirSync(path.join(sourceDir, '0.0.3')); json.version = '0.0.3'; fs.writeFileSync(path.join(sourceDir, '0.0.3', '.bower.json'), JSON.stringify(json, null, ' ')); // It should not error out resolveCache.list() .then(function (entries) { expect(entries).to.be.an('array'); expect(entries.length).to.be(1); expect(entries[0].pkgMeta).to.eql(json); // Packages with invalid metas should have been removed expect(fs.existsSync(path.join(sourceDir, '0.0.1'))).to.be(false); expect(fs.existsSync(path.join(sourceDir, '0.0.2'))).to.be(false); next(); }) .done(); });
.then(function () { // Create some more fs.mkdirSync(path.join(sourceDir, '0.0.3')); fs.mkdirSync(path.join(sourceDir2, '0.0.4')); // Reset cache ResolveCache.clearRuntimeCache(); })
beforeEach(function(done) { fs.mkdirSync(outputBase); fs.mkdirSync(outputDirpath); fs.symlinkSync(inputDirpath, symlinkDirpath); fs.symlinkSync(symlinkDirpath, symlinkMultiDirpath); fs.symlinkSync(symlinkMultiDirpath, symlinkMultiDirpathSecond); fs.symlinkSync(inputPath, symlinkPath); fs.symlinkSync(symlinkNestedTarget, symlinkNestedSecond); fs.symlinkSync(symlinkNestedSecond, symlinkNestedFirst); done(); });
file.mkdirSync = function (dirpath, mode) { mode = mode || parseInt('0777', 8) & (~process.umask()); if (!fs.existsSync(dirpath)) { var parentDir = path.dirname(dirpath); if (fs.existsSync(parentDir)) { fs.mkdirSync(dirpath, mode); } else { file.mkdirSync(parentDir); fs.mkdirSync(dirpath, mode); } } };
beforeEach(() => { TEST_DIR = path.join(os.tmpdir(), 'fs-extra', 'move') fse.emptyDirSync(TEST_DIR) // Create fixtures: fs.writeFileSync(path.join(TEST_DIR, 'a-file'), 'sonic the hedgehog\n') fs.mkdirSync(path.join(TEST_DIR, 'a-folder')) fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-file'), 'tails\n') fs.mkdirSync(path.join(TEST_DIR, 'a-folder/another-folder')) fs.writeFileSync(path.join(TEST_DIR, 'a-folder/another-folder/file3'), 'knuckles\n') })
function _constructHasteInst(config, options) { var HASTE_IGNORE_REGEX = new RegExp( config.modulePathIgnorePatterns.length > 0 ? config.modulePathIgnorePatterns.join('|') : '$.' // never matches ); if (!fs.existsSync(config.cacheDirectory)) { fs.mkdirSync(config.cacheDirectory); } return new NodeHaste( _buildLoadersList(config), (config.testPathDirs || []), { ignorePaths: function(path) { return path.match(HASTE_IGNORE_REGEX); }, version: JSON.stringify(config), useNativeFind: true, maxProcesses: os.cpus().length, maxOpenFiles: options.maxOpenFiles || 100 } ); }
treeNodes.forEach(function(file){ var stat = fs.statSync(srcDir + file); if(stat.isDirectory()){ fs.mkdirSync(desDir + file); fs.readdir(srcDir + file, function(err, files){ files = Array.prototype.slice.call(files); parseTreeJson(files, srcDir + file + '/', desDir + file + '/'); }); }else{ var input = fs.createReadStream(srcDir + file); var output = fs.createWriteStream(desDir + file); input.on('data', function(data){ if(output.write(data) === false){ input.pause(); } recursion++; }); output.on('drain', function(){ input.resume(); }); } });
it('reports IO errors', function(done) { // Changing the mode of a file is not supported by node.js in Windows. // This test is skipped on Windows because we have to chmod the file to 0. if (isWindows) { this.skip(); return; } var file = new File({ base: inputBase, path: inputPath, contents: null, }); fs.mkdirSync(outputBase); fs.chmodSync(outputBase, 0); function assert(err) { expect(err.code).toEqual('EACCES'); done(); } pipe([ from.obj([file]), vfs.symlink(outputDirpath), ], assert); });
it('should retry if the lockfile was removed when verifying staleness', async () => { const mtime = new Date(Date.now() - 60000); let count = 0; const customFs = { ...fs, mkdir: jest.fn((...args) => fs.mkdir(...args)), stat: jest.fn((...args) => { if (count % 2 === 0) { rimraf.sync(`${tmpDir}/foo.lock`); } fs.stat(...args); count += 1; }), }; fs.writeFileSync(`${tmpDir}/foo`, ''); fs.mkdirSync(`${tmpDir}/foo.lock`); fs.utimesSync(`${tmpDir}/foo.lock`, mtime, mtime); await lockfile.lock(`${tmpDir}/foo`, { fs: customFs }); expect(customFs.mkdir).toHaveBeenCalledTimes(2); expect(customFs.stat).toHaveBeenCalledTimes(2); expect(fs.statSync(`${tmpDir}/foo.lock`).mtime.getTime()).toBeGreaterThan(Date.now() - 3000); });
function createDirectory (pwd) { var pathToBundle = path.join(pwd, 'node_shrinkwrap'); if (!fs.existsSync(pathToBundle)) { fs.mkdirSync(pathToBundle); } return pathToBundle; }
helper.create_folder_path = function(_dest, _clean) { //create folders at the destination recursively, as needed var _dest_path_items = _dest.split('/'); if(_dest_path_items.length) { //for each folder in the dest path var _current = _dest_path_items[0] + '/'; // helper.log('- starting at ' + _current); for(var j = 1; j < _dest_path_items.length; ++j) { if(_dest_path_items[j] != '') { _current += _dest_path_items[j] + '/'; var _curpath = path.resolve(helper.root, _current); var _exists = fs.existsSync(_curpath); // helper.log('- next: ' + _curpath + ' at ' + helper.root); if(!_exists) { helper.log("- creating new dir " + _curpath); fs.mkdirSync(_curpath); } //if !exists } //!='' } //for } //if any paths exist } //create_folder_path
exports.loadEndpoint = function(endpoint) { if (endpointClasses[endpoint]) return endpointClasses[endpoint]; try { // ensure the tmpDir exists var tmpDir = process.env.HOME + path.sep + '.jspm' + path.sep + 'tmp-' + endpoint; if (!fs.existsSync(tmpDir)) fs.mkdirSync(tmpDir); var options = { log: false, timeout: 120, tmpDir: tmpDir }; extend(options, config.globalConfig[endpoint] || {}); var endpointClass = require(config.globalConfig.endpoint && config.globalConfig.endpoint[endpoint]); return endpointClasses[endpoint] = new endpointClass(options); } catch(e) { ui.log('err', e.stack || e); throw 'Unable to load endpoint %' + endpoint + '%'; } }
it('should report IO errors', function(cb) { var inputPath = path.join(__dirname, 'fixtures/vinyl/test.coffee'); var inputBase = path.join(__dirname, 'fixtures/vinyl/'); var expectedContents = fs.readFileSync(inputPath); var expectedBase = path.join(__dirname, 'actual'); var expectedMode = parseInt('722', 8); var expectedFile = new File({ base: inputBase, cwd: __dirname, path: inputPath, contents: expectedContents, stat: { mode: expectedMode } }); fs.mkdirSync(expectedBase); fs.chmodSync(expectedBase, 0); var stream = app.symlink('actual/', {cwd: __dirname}); stream.on('error', function(err) { assert.equal(err.code, 'EACCES'); cb(); }); stream.write(expectedFile); });
it('should create the lockfile inside a folder', async () => { fs.mkdirSync(`${tmpDir}/foo-dir`); await lockfile.lock(`${tmpDir}/foo-dir`, { lockfilePath: `${tmpDir}/foo-dir/dir.lock` }); expect(fs.existsSync(`${tmpDir}/foo-dir/dir.lock`)).toBe(true); });
function mkdir(dir) { try { fs.mkdirSync(dir); } catch(err) { if(err.code != 'EEXIST') throw err } }
function mkdirsSync(path) { if (!path) throw new TypeError('path is required!'); const parent = dirname(path); const exist = fs.existsSync(parent); if (!exist) mkdirsSync(parent); fs.mkdirSync(path); }
spider.prototype.download = function (jobpack_json, b) { var setting = this.setting; var schema = jobpack_json.schema[jobpack_json.parser_name]; var params = schema.params; var url = jobpack_json.urls[0]; if(!(typeof params.download === 'undefined') && params.download){ var task_dir = util.format("%s/%s", setting.data_path, jobpack_json.task_id); if(!fs.existsSync(task_dir)) { fs.mkdirSync(task_dir); } var download_dir = util.format("%s/%s", task_dir, jobpack_json.parser_name); if(!fs.existsSync(download_dir)) { fs.mkdirSync(download_dir); } var fname = util.format("%s/%s", download_dir, url.getfname()); fs.writeFile(fname, b, function(err) {}); } };
createFolder: function(next){ var uriFolder = __dirname + '/' + options.folderName; //Create the folder if(!fs.existsSync(uriFolder)){ fs.mkdirSync(uriFolder); } next(null, uriFolder); },
it('should order the versions', function (next) { var source = String(Math.random()); var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); // Create some versions fs.mkdirSync(sourceDir); fs.mkdirSync(path.join(sourceDir, '0.0.1')); fs.mkdirSync(path.join(sourceDir, '0.1.0')); fs.mkdirSync(path.join(sourceDir, '0.1.0-rc.1')); resolveCache.versions(source) .then(function (versions) { expect(versions).to.eql(['0.1.0', '0.1.0-rc.1', '0.0.1']); next(); }) .done(); });
// utils //var mkdirsSync = module.exports.mkdirsSync = function mkdirsSync(dirpath, mode) { if (fs.existsSync(dirpath)) { return true; } else { if (mkdirsSync(path.dirname(dirpath), mode)) { fs.mkdirSync(dirpath, mode); return true; } } };
function makePath( path ) { var folders = path.split('/'); var checkPath = ''; for( var i=0; i<folders.length; i++ ) { checkPath += folders[i]+'/'; //console.log(checkPath); if( !fs.existsSync(checkPath) ) fs.mkdirSync(checkPath); } }
it('should clear the in-memory cache for all sources', function (next) { var source = String(Math.random()); var sourceId = md5(source); var sourceDir = path.join(cacheDir, sourceId); var source2 = String(Math.random()); var sourceId2 = md5(source2); var sourceDir2 = path.join(cacheDir, sourceId2); // Create some versions fs.mkdirSync(sourceDir); fs.mkdirSync(path.join(sourceDir, '0.0.1')); fs.mkdirSync(sourceDir2); fs.mkdirSync(path.join(sourceDir2, '0.0.2')); // Feed the cache resolveCache.versions(source) .then(function () { return resolveCache.versions(source2); }) .then(function () { // Create some more fs.mkdirSync(path.join(sourceDir, '0.0.3')); fs.mkdirSync(path.join(sourceDir2, '0.0.4')); // Reset cache ResolveCache.clearRuntimeCache(); }) .then(function () { return resolveCache.versions(source) .then(function (versions) { expect(versions).to.eql(['0.0.3', '0.0.1']); return resolveCache.versions(source2); }) .then(function (versions) { expect(versions).to.eql(['0.0.4', '0.0.2']); next(); }); }) .done(); });
function compile(config, pkg, outputDir, opt) { var keys, key, paths, path, vals; opt = opt || {}; console.log('Output Dir:',outputDir) if ( !fs.existsSync(outputDir) ) fs.mkdirSync(outputDir); // Root files if ( config.rootFileDirs ) { paths = config.rootFileDirs; if ( !util.isArray(paths) ) paths = [paths]; paths.forEach(function(path) { console.log('Copying files in ', path,'to',outputDir+'/'); var files = fs.readdirSync(path).forEach(function(file) { _copy(path+'/'+file, outputDir+'/'+file); }); }); } // Static files keys = Object.keys(config.staticFileDirs); keys.forEach(function(key) { paths = config.staticFileDirs[key]; if ( !util.isArray(paths) ) paths = [paths]; paths.forEach(function(path) { if ( !path ) return; console.log('Copying',key,path,'to',outputDir+'/'+key+'/'); _copy(path, outputDir+'/'+key); }); }); keys = Object.keys(config.groups); keys.forEach(function(key) { var group = config.groups[key]; // Skip groups that don't need to be written to disk if ( group.saveOutput === false ) return; console.log('Compiling',key+'...'); handlers.css.fetch( group, key, opt, write.bind(null, outputDir+'/'+key+'.css')); handlers.css.fetchMin(group, key, opt, write.bind(null, outputDir+'/'+key+'.min.css')); handlers.js.fetch( group, key, opt, write.bind(null, outputDir+'/'+key+'.js')); handlers.js.fetchMin( group, key, opt, write.bind(null, outputDir+'/'+key+'.min.js')); }); }
!function(){ var file = keys.shift(); var stat = fs.statSync(file); if(stat.isDirectory()){ fs.mkdirSync(list[file]); var files = fs.readdirSync(file); files.forEach(function(path){ list[file + path + '/'] = list[file] + path + '/'; keys.push(file + path + '/'); }); }else{ var input = fs.createReadStream(file); var output = fs.createWriteStream(list[file]); // input.pipe(output); input.on('data', function(data){ if(output.write(data) === false){ input.pause(); pauseTotal++; } dataTotal++; }); output.on('drain', function(){ input.resume(); resumeTotal++; }); input.on('error', function(){ console.log('error'); }); input.on('end', function(){ endTotal++; console.log('end' + endTotal + '>>close' + closeTotal+ '>>dataTota' + dataTotal + '>>pauseTota' + pauseTotal+ '>>resumeTota' + resumeTotal+ '>>outFinish'+outFinishTo + '>>outClose'+outCloseTo ); }); input.on('close', function(){ closeTotal++; console.log('end' + endTotal + '>>close' + closeTotal+ '>>dataTota' + dataTotal + '>>pauseTota' + pauseTotal+ '>>resumeTota' + resumeTotal+ '>>outFinish'+outFinishTo + '>>outClose'+outCloseTo ); }); output.on('finish', function(){ outFinishTo++; // console.log('end' + endTotal + '>>close' + closeTotal+ '>>dataTotal' + dataTotal + '>>pauseTotal' + pauseTotal+ '>>resumeTotal' + resumeTotal+ '>>outFinish'+outFinishTo + '>>outClose'+outCloseTo ); }); output.on('close', function(){ outCloseTo++; // console.log('end' + endTotal + '>>close' + closeTotal+ '>>dataTotal' + dataTotal + '>>pauseTotal' + pauseTotal+ '>>resumeTotal' + resumeTotal+ '>>outFinish'+outFinishTo + '>>outClose'+outCloseTo ); }); fileTotal++; } delete list[file]; console.log(keys.length); }();