@john-yuan/dev-browserify-watcher
Advanced tools
+26
-33
@@ -1,2 +0,1 @@ | ||
| var fs = require('fs'); | ||
| var path = require('path'); | ||
@@ -26,47 +25,41 @@ var fse = require('fs-extra'); | ||
| var bundler = browserify(options.entry, options.browserifyOptions || {}); | ||
| var inputStream = null; | ||
| var writeStream = null; | ||
| var output = path.resolve(process.cwd(), options.output); | ||
| var dirname = path.dirname(output); | ||
| var paths = options.paths; | ||
| var chokidarOptions = options.chokidarOptions; | ||
| var initBuildExecuted = false; | ||
| var buildId = 0; | ||
| try { | ||
| fse.ensureDirSync(dirname); | ||
| } catch (e) { | ||
| logger.error('[Error] Failed to create directory ' + dirname); | ||
| throw e; | ||
| } | ||
| logger.info('Watcher started'); | ||
| return chokidar.watch(options.paths, options.chokidarOptions).on('all', function (event, path) { | ||
| if (writeStream && event === 'add') { | ||
| return chokidar.watch(paths, chokidarOptions).on('all', function (event, path) { | ||
| var currentBuildId = null; | ||
| if (event === 'add' && initBuildExecuted) { | ||
| return; | ||
| } | ||
| if (!writeStream) { | ||
| if (initBuildExecuted) { | ||
| logger.info('build (' + path + ')'); | ||
| } else { | ||
| initBuildExecuted = true; | ||
| logger.info('build (initial)'); | ||
| } else { | ||
| logger.info('build (' + path + ')'); | ||
| } | ||
| if (inputStream) { | ||
| inputStream.pause(); | ||
| inputStream = null; | ||
| } | ||
| if (writeStream) { | ||
| writeStream.end(); | ||
| writeStream = null; | ||
| } | ||
| try { | ||
| inputStream = bundler.bundle(err => { | ||
| if (err) { | ||
| logger.error(err); | ||
| currentBuildId = (buildId = buildId + 1); | ||
| bundler.bundle(function (err, buf) { | ||
| if (currentBuildId === buildId) { | ||
| if (err) { | ||
| logger.error(err); | ||
| } else { | ||
| try { | ||
| fse.outputFileSync(output, buf.toString()); | ||
| } catch (e) { | ||
| logger.error(e.stack); | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| writeStream = fs.createWriteStream(options.output); | ||
| inputStream.pipe(writeStream); | ||
| } catch (err) { | ||
| logger.error(err.stack); | ||
| } catch (e) { | ||
| logger.error(e.stack); | ||
| } | ||
@@ -73,0 +66,0 @@ }); |
+1
-1
| { | ||
| "name": "@john-yuan/dev-browserify-watcher", | ||
| "version": "1.0.5", | ||
| "version": "1.0.6", | ||
| "description": "A browserify watcher", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
1
-50%6024
-0.13%89
-5.32%