Exemplo n.º 1
0
      it('has stable output (mtime, size, mode, relativePath)', function() {
        var beforeTree = walkSync.entries(tmp);

        expect(beforeTree.length).to.eql(4);

        treeSync.sync();

        var afterTree = walkSync.entries(tmp);

        expect(afterTree.length).to.eql(4);
        expect(beforeTree).to.deep.equal(afterTree);
      });
Exemplo n.º 2
0
      it('should update changed files on initial build', function() {
        var afterTree = walkSync.entries(tmp);

        // tree should be updated with OMG in one/foo.txt
        expect(initialTree).to.not.deep.equal(afterTree);

        var contents = fs.readFileSync(tmp + '/one/foo.txt', { encoding: 'utf8'} );
        expect(contents).to.equal('OMG');

        // sync again to ensure stablity after synced
        treeSync.sync();

        expect(afterTree).to.deep.equal(walkSync.entries(tmp));
      });
      return builder.build().then(function(results) {
        outputPath = results.directory;

        lastEntries = walkSync.entries(outputPath);
        expect(lastEntries).to.have.length(2);
        return builder.build();
      });
Exemplo n.º 4
0
 listEntries() {
   // If we have no inputFiles at all, use undefined as the filter to return
   // all files in the inputDir.
   let filter = this.allInputFiles.length ? this.allInputFiles : undefined;
   let inputDir = this.inputPaths[0];
   return walkSync.entries(inputDir, filter);
 }
Exemplo n.º 5
0
Funnel.prototype.processFilters = function (inputPath) {
    var nextTree;

    this.outputToInputMappings = {}; // we allow users to rename files

    if (this.files && !this.exclude && !this.include) {
        // clone to be compatible with walkSync
        nextTree = FSTree.fromPaths(this._processPaths(this.files));
    } else {
        var entries;

        if (this._matchedWalk) {
            entries = walkSync.entries(inputPath, this.include);
        } else {
            entries = walkSync.entries(inputPath);
        }

        nextTree = new FSTree({
            entries: this._processEntries(entries)
        });
    }

    var patch = this._currentTree.calculatePatch(nextTree);

    this._currentTree = nextTree;

    this._debug('patch size: %d', patch.length);

    var outputPath = this.outputPath;

    patch.forEach(function (entry) {
        this._applyPatch(entry, inputPath, outputPath);
    }, this);

    var count = nextTree.size;

    this._debug('processFilters %o', {
        in: new Date() - this._buildStart + 'ms',
        filesFound: this._currentTree.size,
        filesProcessed: count,
        operations: patch.length,
        inputPath: inputPath,
        destPath: this.destPath
    });
};
Exemplo n.º 6
0
Funnel.prototype.processFilters = function(inputPath) {
  var nextTree;

  var instrumentation = heimdall.start('derivePatches');
  var entries;

  this.outputToInputMappings = {}; // we allow users to rename files

  if (this.files && !this.exclude && !this.include) {
    entries = this._processPaths(this.files);
    // clone to be compatible with walkSync
    nextTree = FSTree.fromPaths(entries, { sortAndExpand: true });
  } else {

    if (this._matchedWalk) {
      entries = walkSync.entries(inputPath, this.include);
    } else {
      entries = walkSync.entries(inputPath);
    }

    entries = this._processEntries(entries);
    nextTree = FSTree.fromEntries(entries, { sortAndExpand: true });
  }

  var patches = this._currentTree.calculatePatch(nextTree);

  this._currentTree = nextTree;

  instrumentation.stats.patches = patches.length;
  instrumentation.stats.entries = entries.length;

  var outputPath = this.outputPath;

  instrumentation.stop();

  instrumentation = heimdall.start('applyPatch', ApplyPatchesSchema);

  patches.forEach(function(entry) {
    this._applyPatch(entry, inputPath, outputPath, instrumentation.stats);
  }, this);

  instrumentation.stop();
};
      return builder.build().then(function(results) {
        var outputPath = results.directory;
        var entries = walkSync.entries(outputPath);

        expect(entries).to.have.length(2);

        var output = fs.readFileSync(outputPath + '/fixtures.js', 'UTF8');
        var input = fs.readFileSync(expectations + '/expected.es6', 'UTF8');

        expect(output).to.eql(input);
      });
Exemplo n.º 8
0
IncludeAll.prototype.build = function() {
  var srcDir = this.inputPaths[0];

  var entries = walkSync.entries(srcDir);
  var nextTree = new FSTree.fromEntries(entries, { sortAndExpand: true });
  var currentTree = this.currentTree;

  this.currentTree = nextTree;
  var patches = currentTree.calculatePatch(nextTree);

  return Promise.resolve().then(this.importPods.bind(this, patches, srcDir));
};
    it('mixed rebuild', function() {
      var entries = walkSync.entries(outputPath);
      expect(entries).to.have.length(2);

      fs.writeFileSync('tests/fixtures/files/apple.ts', 'var apple : String;');
      fs.writeFileSync('tests/fixtures/files/orange.js', 'var orange;');

      mkdirp.sync('tests/fixtures/files/red/');
      mkdirp.sync('tests/fixtures/files/orange/');

      fs.writeFileSync('tests/fixtures/files/red/one.ts', 'var one : String');
      fs.writeFileSync('tests/fixtures/files/orange/two.js', 'var two');

      return builder.build().then(function(results) {
        var entries = walkSync.entries(results.directory);

        expect(entries).to.not.deep.equal(lastEntries);
        expect(entries).to.have.length(8);

        rimraf.sync('tests/fixtures/files/apple.ts');
        fs.writeFileSync('tests/fixtures/files/orange.js', 'var orange : String;');

        rimraf.sync('tests/fixtures/files/red/');

        rimraf.sync('tests/fixtures/files/red/one.ts');
        fs.writeFileSync('tests/fixtures/files/orange/two.js', 'var wasTwo;');

        return builder.build();
      }).then(function(results) {
        var entries = walkSync.entries(results.directory);

        expect(entries).to.not.deep.equal(lastEntries);
        expect(entries).to.have.length(5);

        // expected stability
        expect(entryFor('fixtures.js', entries)).to.eql(entryFor('fixtures.js', lastEntries));
        expect(entryFor('oranges/',    entries)).to.eql(entryFor('oranges/', lastEntries));
        expect(entryFor('types.js',    entries)).to.eql(entryFor('types.js', lastEntries));

        // expected in-stability
        expect(entryFor('orange.js',     entries)).to.not.eql(entryFor('orange.js', lastEntries));
        expect(entryFor('orange/two.js', entries)).to.not.eql(entryFor('orange/two.js', lastEntries));

        expect(entries.map(function(entry) { return entry.relativePath; })).to.deep.eql([
          'fixtures.js',
          'orange/',
          'orange/two.js',
          'orange.js',
          'types.js'
        ]);
      });
    });
Exemplo n.º 10
0
      it('has stable output (mtime, size, mode, relativePath)', function() {
        var entries = walkSync.entries(tmp);

        expect(entries).to.have.deep.property('0.relativePath', 'one/');
        expect(entries).to.have.deep.property('0.mode', 16877);

        expect(entries).to.have.deep.property('1.relativePath', 'one/bar/');
        expect(entries).to.have.deep.property('1.mode', 16877);

        expect(entries).to.have.deep.property('2.relativePath', 'one/bar/bar.txt');
        expect(entries).to.have.deep.property('2.mode', 33188);

        expect(entries.length).to.eql(3);
      });
Exemplo n.º 11
0
  build() {
    let inputPath = this.inputPaths[0];
    let outputPath = this.outputPath;
    let proposedTemplate = TemplateFile.fromPath(this._templatePath);

    if (!proposedTemplate.equal(this._currentTemplate)) {
      this._currentTemplate = proposedTemplate;
      rimraf.sync(this.outputPath);
      fs.mkdirSync(this.outputPath);
      this._previousInput = FSTree.fromPaths([]);
    }

    let currentInput = FSTree.fromEntries(walkSync.entries(inputPath));

    let changes = this._previousInput.calculatePatch(currentInput);
    let hasChanges = changes.length > 0;

    changes.forEach(change => {
      let operation = change[0];
      let file = change[1];
      let entry = change[2];
      let inputFilePath = `${inputPath}/${file}`;
      let outputFilePath = `${outputPath}/${file}`;

      switch (operation) {
        case 'change':
        case 'create':
          fs.writeFileSync(outputFilePath, this._processString(fs.readFileSync(inputFilePath, 'UTF8'), file));
          break;
        case 'unlink': {
          fs.unlinkSync(outputFilePath);
          break;
        }
        case 'rmdir': {
          fs.rmdirSync(outputFilePath);
          break;
        }
        case 'mkdir': {
          fs.mkdirSync(outputFilePath);
          break;
        }
        default: {
          throw new TypeError(`Unknown operation: ${operation} on ${file}`)
        }
      }
    });

    this._previousInput = currentInput;
  }
Exemplo n.º 12
0
      it('has stable output (mtime, size, mode, relativePath)', function() {
        var beforeTree = walkSync.entries(tmp);

        expect(beforeTree.length).to.eql(4);

        fs.writeFileSync(newFilePath, 'OMG', { mode: 33152 } ); // add file
        treeSync.sync();

        var afterTree = walkSync.entries(tmp);

        expect(afterTree.length).to.eql(5);
        expect(beforeTree).to.not.deep.equal(afterTree);

        var addedEntry = afterTree.filter(function(entry) {
          return entry['relativePath'] === 'one/added-file.js';
        })[0];

        expectMode(addedEntry, 'mode', 33152);
        expect(addedEntry).to.have.property('relativePath', 'one/added-file.js');

        treeSync.sync();

        expect(afterTree).to.deep.equal(walkSync.entries(tmp));
      });
Exemplo n.º 13
0
// Executes `npm run build` if any of the files in src/ are older than the browserified bundle.
function rebuildIfModified() {
  // Get a sorted list of last-modified times for every file in the 'src' dir.
  var srcEntries = walkSync.entries(path.join(__dirname, '../src'));
  var mtimes = srcEntries.map(function(entry) { return entry.mtime; });
  mtimes.sort(function(a, b) { return a - b; });

  var srcDate = new Date(mtimes.pop());
  var bundleDate = fs.statSync(path.join(__dirname, '../dist/ohm.js')).mtime;

  if (bundleDate < srcDate) {
    var p = exec('npm run build');
    p.stdout.on('data', function() { /* ignore */ });
    p.stderr.pipe(process.stderr);
  }
}
      return builder.build().then(function(results) {
        var entries = walkSync.entries(results.directory);

        expect(entries).to.not.deep.equal(lastEntries);
        expect(entries).to.have.length(8);

        rimraf.sync('tests/fixtures/files/apple.ts');
        fs.writeFileSync('tests/fixtures/files/orange.js', 'var orange : String;');

        rimraf.sync('tests/fixtures/files/red/');

        rimraf.sync('tests/fixtures/files/red/one.ts');
        fs.writeFileSync('tests/fixtures/files/orange/two.js', 'var wasTwo;');

        return builder.build();
      }).then(function(results) {
Exemplo n.º 15
0
      beforeEach(function() {
        originalValue = fs.readFileSync(changeFilePath, { encoding: 'utf8' });

        // populate tmp simulating a pre-existing output
        treeSync.sync();

        // grab state of `tmp` after initial sync
        initialTree = walkSync.entries(tmp);

        // change a file in the input tree
        fs.writeFileSync(changeFilePath, 'OMG');

        // build a new `TreeSync` that does not have `lastInput` populated
        treeSync = new TreeSync(__dirname + '/fixtures/', tmp);

        treeSync.sync();
      });
      }).then(function(results) {
        var entries = walkSync.entries(results.directory);

        expect(entries).to.not.deep.equal(lastEntries);
        expect(entries).to.have.length(5);

        // expected stability
        expect(entryFor('fixtures.js', entries)).to.eql(entryFor('fixtures.js', lastEntries));
        expect(entryFor('oranges/',    entries)).to.eql(entryFor('oranges/', lastEntries));
        expect(entryFor('types.js',    entries)).to.eql(entryFor('types.js', lastEntries));

        // expected in-stability
        expect(entryFor('orange.js',     entries)).to.not.eql(entryFor('orange.js', lastEntries));
        expect(entryFor('orange/two.js', entries)).to.not.eql(entryFor('orange/two.js', lastEntries));

        expect(entries.map(function(entry) { return entry.relativePath; })).to.deep.eql([
          'fixtures.js',
          'orange/',
          'orange/two.js',
          'orange.js',
          'types.js'
        ]);
      });
Exemplo n.º 17
0
    return builder.build().then(function(tree) {
      var entries = walkSync.entries(tree.directory);
      paths = entries.map(function(entry) {
        return entry.relativePath;
      });

      if (filter) {
        paths = filter(paths, tree);
      }

      return {
        files: paths,
        entries: entries,
        directory: tree.directory,
        builder: function() {
          return build().then(function(results) {
            process.chdir(cwd);
            return results;
          });
        },
        subject: plugin
      };
    });
Exemplo n.º 18
0
StubGenerator.prototype.build = function() {
  var start = Date.now();
  var inputPath = this.inputPaths[0];
  var previous  = this._previousTree;

  // get patchset
  var input = walkSync.entries(inputPath, [ '**/*.js' ]);

  debug('input: %d', input.length);

  var next = this._previousTree = FSTree.fromEntries(input);
  var patchset = previous.calculatePatch(next);

  debug('patchset: %d', patchset.length);

  var applyPatch = Date.now();

  // process patchset
  patchset.forEach(function(patch) {
    var operation = patch[0];
    var path      = patch[1];
    var fullPath  = inputPath + '/' + path;

    switch (operation) {
      case 'unlink': this.stubs.delete(fullPath); break;
      case 'create':
      case 'change': this.stubs.set(fullPath, fs.readFileSync(fullPath)); break;
    }
  }, this);

  debug('patched applied in: %dms', Date.now() - applyPatch);

  // apply output
  this.writeFileIfContentChanged(this.outputPath + '/browserify_stubs.js', this.stubs.toAMD());

  debug('build in %dms', Date.now() - start);
};
Exemplo n.º 19
0
CachingWriter.prototype._conditionalBuild = function () {
  var writer = this;
  var start = new Date();

  var invalidateCache = false;
  var dir;
  var lastKeys = [];

  if (!writer._lastKeys) {
    writer._lastKeys = [];
    // Force initial build even if inputNodes is []
    invalidateCache = true;
  }

  function shouldNotBeIgnored(relativePath) {
    /*jshint validthis:true */
    return !this.shouldBeIgnored(relativePath);
  }

  function keyForFile(relativePath) {
    var fullPath =  dir + '/' + relativePath;

    var stats = fs.statSync(fullPath);

    /*jshint validthis:true */
    return new Key({
      relativePath: relativePath,
      fullPath: dir + '/' + relativePath,
      basePath: dir,
      mode: stats.mode,
      size: stats.size,
      mtime: stats.mtime.getTime(),
      isDirectory: function() {
        return false;
      }
    }, undefined, this.debug);
  }
  for (var i = 0, l = writer.inputPaths.length; i < l; i++) {
    dir = writer.inputPaths[i];

    var files;

    if (canUseInputFiles(this._inputFiles)) {
      this.debug('using inputFiles directly');
      files = this._inputFiles.filter(shouldNotBeIgnored, this).map(keyForFile, this);
    } else {
      this.debug('walking %o', this.inputFiles);
      files = walkSync.entries(dir,  this.inputFiles).filter(entriesShouldNotBeIgnored, this).map(keyForEntry, this);
    }

    this._stats.files += files.length;

    var lastKey = writer._lastKeys[i];
    var key = keyForDir(dir, files, this.debug);

    lastKeys.push(key);

    if (!invalidateCache /* short circuit */ && !key.isEqual(lastKey)) {
      invalidateCache = true;
    }
  }

  this._stats.inputPaths = writer.inputPaths;
  this.debug('%o', this._stats);
  this.debug('derive cacheKey in %dms', new Date() - start);
  this._resetStats();

  if (invalidateCache) {
    start = new Date();
    writer._lastKeys = lastKeys;

    var promise = RSVP.Promise.resolve();
    if (!this._cachingWriterPersistentOutput) {
      promise = promise.then(function() {
        return rimraf(writer.outputPath);
      }).then(function() {
        fs.mkdirSync(writer.outputPath);
      }).finally(function() {

        this.debug('purge output in %dms', new Date() - start);
        start = new Date();
      }.bind(this));
    }
    return promise.then(function() {
      return writer.build();
    }).finally( function() {
      this.debug('rebuilding cache in %dms', new Date() - start);
    }.bind(this));
  }
};
      return builder.build().then(function(results) {
        var entries = walkSync.entries(results.directory);

        expect(entries).to.deep.equal(lastEntries);
        expect(entries).to.have.length(2);
      });
Exemplo n.º 21
0
 getDirectoryEntries(directory) {
   return walkSync.entries(directory);
 }
Exemplo n.º 22
0
 getDirectoryEntries: function(directory) {
   return walkSync.entries(directory);
 },
Exemplo n.º 23
0
TreeSync.prototype.sync = function() {
  mkdirp.sync(this._output);
  mkdirp.sync(this._input);

  debug('syncing %s -> %s', this._input, this._output);

  var input = FSTree.fromEntries(walkSync.entries(this._input));
  var output = FSTree.fromEntries(walkSync.entries(this._output));

  debug('walked %s %dms and  %s %dms', this._input, input.size, this._output, output.size);

  var isFirstSync = !this._hasSynced;
  var operations = output.calculatePatch(input).filter(function(operation) {
    if (operation[0] === 'change') {
      return isFirstSync;
    } else {
      return true;
    }
  });

  var inputOperations = this._lastInput.calculatePatch(input).filter(function(operation) {
    return operation[0] === 'change';
  });

  this._lastInput = input;

  operations = operations.concat(inputOperations);

  debug('calc operations %d', operations.length);

  operations.forEach(function(patch) {
    var operation = patch[0];
    var pathname = patch[1];

    var inputFullpath = this._input + '/' + pathname;
    var outputFullpath = this._output + '/' + pathname;

    switch(operation) {
      case 'create' :
        return fs.writeFileSync(outputFullpath, fs.readFileSync(inputFullpath));
      case 'change' :
        return fs.writeFileSync(outputFullpath, fs.readFileSync(inputFullpath));
      case 'mkdir' :
        try {
          return fs.mkdirSync(outputFullpath);
        } catch(e) {
          if (e && e.code === 'EEXIST') { /* do nothing */ }
          else { throw e; }
        }
      case 'unlink':
        try {
          return fs.unlinkSync(outputFullpath);
        } catch(e) {
          if (e && e.code === 'ENOENT') { /* do nothing */ }
          else { throw e; }
        }
      case 'rmdir':
        return fs.rmdir(outputFullpath);
      default:
        throw TypeError('Unknown operation:' + operation + ' on path: ' + pathname);
    }
  }, this);

  this._hasSynced = true;
  debug('applied patches: %d', operations.length);
};