function expectBundleContainments(bundleFile, testFiles) { var extractedFiles = unpack(bundleFile.bundled).map(function(row) { return row.id; }); forEach(testFiles, function(f) { expect(extractedFiles).to.contain(f.path); }); }
var minify_require_paths = function(orig, callback, packOptions){ if (arguments.length === 0) { var code = ''; return through(function(data){ code += data; }, function(){ var self = this; minify_require_paths(code, function(res){ self.queue(res); self.queue(null); }); }); } var unpacked = unpack(orig.toString()); intreqFn(unpacked, function(rows){ var p = pack(packOptions); var data = ''; p.on('data', function(buf){ data += buf; }); p.on('end', function(){ callback(data); }); p.end(JSON.stringify(rows)); }); };
collapse(src).pipe(concat(function (body) { vm.runInNewContext(body, { console: { log: log } }); function log (msg) { t.equal(msg, 300) } var rows = unpack(body.toString('utf8')); rows.forEach(function (row) { t.deepEqual(trim(row), trim(expected.shift())); }); }));
module.exports = function (src) { var rows = unpack(src); var p = pack({ raw: true }); rows.forEach(function (row) { row.source = replace(row.source, row.deps); row.deps = {}; p.write(row); }); p.end(); return p; };
plugin.preprocess(bundleFile, [ testFile ], function() { // then // bundle got passed through var bundledFiles = unpack(bundleFile.bundled) .map(function (row) { return row.id; }); expect(bundledFiles).to.contain(path.relative('', 'test/fixtures/b.js')); // test file got regenerated expect(testFile.bundled).to.eql(expectedBundle('test/fixtures/b.js')); done(); });
plugin.preprocess(bundleFile, [ testFile ], function() { // then // bundle got passed through var entryPointFiles = unpack(bundleFile.bundled) .filter(function (row) { return row.entry; }) .map(function (row) { return row.id; }); expect(entryPointFiles).to.eql([ path.resolve('test/fixtures/b.js') ]); // test file got regenerated expect(testFile.bundled).to.eql('/* bundled */'); done(); });
process.stdin.pipe(concat(function (body) { t.equal(spiceGirlsSrc.length, 213, 'You should not edit the spice-girls.js file') t.equal(mainSrc.length, 81, 'You should not edit the main.js file') try { var rows = unpack(body) } catch (err) { return t.fail('The input had a syntax error!') } if (!rows) return t.fail('The input is not a browserify bundle or an error occurred (see above)!'); Function(['console'], injectWindow + body.toString())({ log: function (msg) { t.equal(msg, girls) }, error: console.error }); }));
plugin.preprocess(bundleFile, [ testFileB, testFileC ], function() { // then // bundle got created var bundledFiles = unpack(bundleFile.bundled) .map(function (row) { return row.id; }); expect(bundledFiles).to.contain(path.relative('', 'test/fixtures/c.js')); expect(bundledFiles).to.contain(path.relative('', 'test/fixtures/b.js')); // test file stub got created expect(testFileB.bundled).to.eql(expectedBundle('test/fixtures/b.js')); expect(testFileC.bundled).to.eql(expectedBundle('test/fixtures/c.js')); done(); });
process.stdin.pipe(concat(function (body) { var rows; try { rows = unpack(body); } catch (err) { return t.fail('The input had a syntax error!'); } if (!rows) { return t.fail('The input is not a browserify bundle!'); } t.deepEqual(rows[0].deps, {}, 'shouldn\'t have any deps'); run(body.toString(), function (approximate) { return function (fixture) { t.equal(approximate(fixture.text), expectation[fixture.file], fixture.file + '? ' + expectation[fixture.file]); }; }); }));
plugin.preprocess(bundleFile, [ testFileB, testFileC ], function(order) { // then // resolve order: bundle, testFileStubs ... expect(order).to.eql([ bundleFile, testFileB, testFileC ]); // bundle got created var entryPointFiles = unpack(bundleFile.bundled) .filter(function (row) { return row.entry; }) .map(function (row) { return row.id; }); expect(entryPointFiles).to.eql([ path.resolve('test/fixtures/b.js'), path.resolve('test/fixtures/c.js') ]); // test file stub got created expect(testFileB.bundled).to.eql('/* bundled */'); expect(testFileC.bundled).to.eql('/* bundled */'); done(); });
gulp.task("build:page-js", function() { //console.log('dirName: ' + __dirname); var coreFilePath = glob.sync(buildConfig.corejsSrcMatchPattern)[0]; //unpack the bundled core.js to grab all the row/module ids so we can flag them as external and not include them in the app bundle. var src = fs.readFileSync(coreFilePath, 'utf8'); var coreBundleRows = browserUnpack(src); //console.log('bundled rows: ' + JSON.stringify(coreBundleRows.length)); var coreBundleModuleIds = _.pluck(coreBundleRows, 'id'); function browserifyIt(filePath, outputName){ console.log('building page: ' + outputName + ' from path: ' + filePath); var bundler = browserify({ entries: [filePath], transform: [hbsfy] // We want to convert Handlebars templates to normal javascript }) .external(coreBundleModuleIds); //exclude modules defined inside of core.js return bundler.bundle() .on("error", function(){ console.log(arguments)}) .pipe(source(outputName)) .pipe(gStreamify(uglify(buildConfig.uglify))) .pipe(gulp.dest(buildConfig.jsDistDir)); } //read each page js(x) file from the pages dir and build it var files = glob.sync(buildConfig.jsPagesDir + '/*.js*', { matchBase:true }); console.log('build %s page files', files.length); var streams = files .map(function(filePath) { var outputName = filePath.substr(filePath.lastIndexOf('/') + 1).replace('.jsx', '.js'); return browserifyIt(filePath, outputName); }); // Return a merged stream and fire a livereload once all of the individual files are built return merge(streams) .pipe(livereload()); });
return through.obj(function (bundle, encoding, callback) { if (!(bundle instanceof Buffer)) { callback(new Error('Sorry, this transform only supports Buffers.')); return; } var bundleContent = bundle.toString('utf8'); var packEntries = unpack(bundleContent); var metadata = updateBundleStubs(packEntries, bundleDef.moduleMappings, true); metadata = fullPathsToTruncatedPaths(metadata); var bundleInfo = { jsModulesId: bundleDef.asModuleSpec.importAs(), created: Date.now(), jsBuilderVer: getBuilderVersion() }; if (maven.isHPI()) { bundleInfo.hpiPluginId = maven.getArtifactId(); } bundleInfo.moduleDefs = metadata.modulesDefs; // Dump data that can be used by tooling. // .json file can't be loaded as an adjunct (ffs :) ) paths.mkdirp(paths.parentDir(bundleOutFile)); require('fs').writeFileSync(bundleOutFile + '-info.js', JSON.stringify(bundleInfo)); require('fs').writeFileSync(bundleOutFile + '-packEntries.js', JSON.stringify(metadata.packEntries)); // We told updateBundleStubs (above) to skipFullPathToIdRewrite, // so we need to do that before going further. if (!args.isArgvSpecified('--full-paths')) { fullPathsToIds(metadata); } this.push(JSON.stringify(packEntries)); callback(); });