pack.js 902 B

123456789101112131415161718192021222324252627282930313233
  1. var browserify = require('../');
  2. var vm = require('vm');
  3. var through = require('through2');
  4. var test = require('tap').test;
  5. var fs = require('fs');
  6. var sources = {
  7. 1: fs.readFileSync(__dirname + '/entry/main.js', 'utf8'),
  8. 2: fs.readFileSync(__dirname + '/entry/one.js', 'utf8'),
  9. 3: fs.readFileSync(__dirname + '/entry/two.js', 'utf8')
  10. };
  11. var deps = {
  12. 1: { './two': 3, './one': 2 },
  13. 2: {},
  14. 3: {}
  15. };
  16. test('custom packer', function (t) {
  17. t.plan(7);
  18. var b = browserify(__dirname + '/entry/main.js');
  19. b.pipeline.get('pack').splice(0,1, through.obj(function (row, enc, next) {
  20. t.equal(sources[row.id], row.source);
  21. t.deepEqual(deps[row.id], row.deps);
  22. this.push(row.id + '\n');
  23. next();
  24. }));
  25. b.pipeline.get('wrap').splice(0);
  26. b.bundle(function (err, src) {
  27. t.equal(src.toString('utf8'), '1\n2\n3\n');
  28. });
  29. });