{"id":19560626,"url":"https://github.com/zoubin/factor-bundle-reset-patch","last_synced_at":"2025-09-09T13:46:19.324Z","repository":{"id":57143994,"uuid":"39130441","full_name":"zoubin/factor-bundle-reset-patch","owner":"zoubin","description":"Patch for factor-bundle to work with watchify","archived":false,"fork":false,"pushed_at":"2015-07-17T05:44:49.000Z","size":136,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-09T06:36:42.339Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zoubin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-07-15T10:19:40.000Z","updated_at":"2017-08-29T05:45:59.000Z","dependencies_parsed_at":"2022-09-05T12:31:26.291Z","dependency_job_id":null,"html_url":"https://github.com/zoubin/factor-bundle-reset-patch","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ffactor-bundle-reset-patch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ffactor-bundle-reset-patch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ffactor-bundle-reset-patch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zoubin%2Ffactor-bundle-reset-patch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zoubin","download_url":"https://codeload.github.com/zoubin/factor-bundle-reset-patch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240822615,"owners_count":19863302,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T05:08:18.642Z","updated_at":"2025-02-26T08:41:28.761Z","avatar_url":"https://github.com/zoubin.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# factor-bundle-reset-patch\nPatch for [factor-bundle@2.4.1](https://www.npmjs.com/package/factor-bundle) to work with [watchify](https://www.npmjs.com/package/watchify).\n\nThere is a problem to use `2.4.1` with watchify: output streams are `finish`ed after `bundle` and thus not writable anymore, so you will run into errors when `watchify` fires `update` to re`bundle`.\n\nTo solve this problem, output streams are rebuilt every time `reset`.\n\n## Example\n\n`example/gulpfile.js`\n\n```javascript\nvar path = require('path');\nvar gulp = require('gulp');\nvar uglify = require('gulp-uglify');\nvar buffer = require('gulp-buffer');\nvar gutil = require('gulp-util');\n\nvar factor = require('factor-bundle-reset-patch');\nvar browserify = require('browserify');\nvar watchify = require('watchify');\n\nvar source = require('vinyl-source-stream');\nvar merge = require('merge-stream');\nvar readonly = require('read-only-stream');\nvar del = require('del');\n\nvar PassThrough = require('stream').PassThrough;\n\nvar fixtures = path.resolve.bind(path, __dirname);\n\ngulp.task('clean', function (cb) {\n    del(fixtures('dist'), cb);\n});\n\ngulp.task('default', ['clean'], function () {\n    return bundle(getBundle());\n});\n\ngulp.task('watch', ['clean'], function (cb) {\n    var b = watchify(getBundle());\n    b.on('update', _bundle);\n    _bundle();\n\n    function _bundle() {\n        bundle(b);\n    }\n});\n\nfunction bundle(b) {\n    return b.bundle()\n        // from now on, use gulp plugins to transform contents\n        .pipe(buffer())\n        .pipe(uglify())\n        .pipe(gulp.dest(fixtures('dist')))\n        ;\n}\n\nfunction getBundle() {\n    var entries = ['a.js', 'b.js'];\n    var basedir = fixtures('src');\n    var b = browserify(entries, { basedir: basedir })\n    b.plugin(factor, {\n        entries: entries,\n        basedir: basedir,\n        outputs: entries,\n        // overwrite default `fs.createWriteStream` to make vinyl streams\n        createWriteStream: source,\n    });\n    b.on('log', gutil.log);\n    b.on('error', gutil.log);\n    // make `bundle` return a vinyl stream.\n    // perhaps another plugin to gulpify `bundle`\n    b.bundle = function () {\n        var pipeline = PassThrough({ objectMode: true });\n        var common = browserify.prototype.bundle.call(b)\n            .pipe(source('common.js'));\n        b.once('factor.pipelines', function (files, pipelines, outputs) {\n            merge(outputs.concat(common)).pipe(pipeline);\n        });\n        return readonly(pipeline);\n    };\n    return b;\n}\n```\n\n```\n⌘ tree example/\nexample/\n├── dist\n│   ├── a.js\n│   ├── b.js\n│   └── common.js\n├── gulpfile.js\n└── src\n    ├── a.js\n    ├── b.js\n    └── c.js\n```\n\n## b.plugin(factor, opts)\n\n### opts\n\n#### entries\n\nType: `Array`\n\nEntry file paths. Absolute or relative to `opts.basedir`\n\n#### basedir\n\nType: `String`\n\n#### outputs\n\nType: `Array`, `String`\n\nOutput destinations. Passed to `opts.createWriteStream` to make output streams.\n\nType: `Function`\n\nIt receives `opts.entries, opts.basedir`, and should return output streams.\n\n#### createWriteStream\n\nType: `Function`\n\nDefault: `fs.createWriteStream`\n\n#### pack\n\nType: `Function`, `browser-plugin`\n\nDefault: [browser-pack](https://npmjs.org/package/browser-pack)\n\n\n#### theshold\n\nSame with that in [factor-bundle](https://github.com/substack/factor-bundle#var-fr--factorfiles-opts).\n\n## events\n\n### b.on('factor.pipelines', function(files, pipelines, outputStreams){})\n\nEmits all absolute entry files, [pipeline](https://github.com/substack/factor-bundle#bonfactorpipeline-function-file-pipeline-)s, and output streams.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Ffactor-bundle-reset-patch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzoubin%2Ffactor-bundle-reset-patch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzoubin%2Ffactor-bundle-reset-patch/lists"}