rollup-watch
Advanced tools
Comparing version 3.2.2 to 4.0.0
# rollup-watch changelog | ||
## 4.0.0 | ||
* On error, watch files from last successful build ([#38](https://github.com/rollup/rollup-watch/issues/38)) | ||
* Fix bug preventing `chokidar` from ever working ([#45](https://github.com/rollup/rollup-watch/issues/45)) | ||
* Add `options.watch.useChokidar` option | ||
## 3.2.2 | ||
@@ -4,0 +10,0 @@ |
@@ -6,20 +6,16 @@ 'use strict'; | ||
var EventEmitter = _interopDefault(require('events')); | ||
var path = require('path'); | ||
var path__default = path['default']; | ||
var path = _interopDefault(require('path')); | ||
var module$1 = _interopDefault(require('module')); | ||
var fs = require('fs'); | ||
var path$1 = path__default; | ||
var Module = module$1; | ||
var modules = {}; | ||
var getModule = function(dir) { | ||
var rootPath = dir ? path$1.resolve(dir) : process.cwd(); | ||
var rootName = path$1.join(rootPath, '@root'); | ||
var rootPath = dir ? path.resolve(dir) : process.cwd(); | ||
var rootName = path.join(rootPath, '@root'); | ||
var root = modules[rootName]; | ||
if (!root) { | ||
root = new Module(rootName); | ||
root = new module$1(rootName); | ||
root.filename = rootName; | ||
root.paths = Module._nodeModulePaths(rootPath); | ||
root.paths = module$1._nodeModulePaths(rootPath); | ||
modules[rootName] = root; | ||
@@ -37,3 +33,3 @@ } | ||
var root = getModule(relativeTo); | ||
return Module._resolveFilename(requested, root); | ||
return module$1._resolveFilename(requested, root); | ||
}; | ||
@@ -69,4 +65,4 @@ | ||
class FileWatcher { | ||
constructor ( file, data, callback, dispose ) { | ||
const handleWatchEvent = event => { | ||
constructor ( file, data, callback, useChokidar, dispose ) { | ||
const handleWatchEvent = (event) => { | ||
if ( event === 'rename' || event === 'unlink' ) { | ||
@@ -87,3 +83,3 @@ this.fsWatcher.close(); | ||
try { | ||
if (chokidar) | ||
if (useChokidar) | ||
{ this.fsWatcher = chokidar.watch(file, { ignoreInitial: true }).on('all', handleWatchEvent); } | ||
@@ -111,2 +107,9 @@ else | ||
function watch$1 ( rollup, options ) { | ||
const watchOptions = options.watch || {}; | ||
const useChokidar = 'useChokidar' in watchOptions ? watchOptions.useChokidar : !!chokidar; | ||
if ( useChokidar && !chokidar ) { | ||
throw new Error( `options.watch.useChokidar is true, but chokidar could not be found. Have you installed it?` ); | ||
} | ||
const watcher = new EventEmitter(); | ||
@@ -134,2 +137,29 @@ | ||
function addFileWatchersForModules ( modules ) { | ||
modules.forEach( module => { | ||
let id = module.id; | ||
// skip plugin helper modules | ||
if ( /\0/.test( id ) ) { return; } | ||
try { | ||
id = fs.realpathSync( id ); | ||
} catch ( err ) { | ||
return; | ||
} | ||
if ( ~dests.indexOf( id ) ) { | ||
throw new Error( 'Cannot import the generated bundle' ); | ||
} | ||
if ( !filewatchers.has( id ) ) { | ||
const watcher = new FileWatcher( id, module.originalCode, triggerRebuild, useChokidar, () => { | ||
filewatchers.delete( id ); | ||
}); | ||
if ( watcher.fileExists ) { filewatchers.set( id, watcher ); } | ||
} | ||
}); | ||
} | ||
function build () { | ||
@@ -154,26 +184,3 @@ if ( building || closed ) { return; } | ||
if ( !closed ) { | ||
bundle.modules.forEach( module => { | ||
let id = module.id; | ||
// skip plugin helper modules | ||
if ( /\0/.test( id ) ) { return; } | ||
try { | ||
id = fs.realpathSync( id ); | ||
} catch ( err ) { | ||
return; | ||
} | ||
if ( ~dests.indexOf( id ) ) { | ||
throw new Error( 'Cannot import the generated bundle' ); | ||
} | ||
if ( !filewatchers.has( id ) ) { | ||
const watcher = new FileWatcher( id, module.originalCode, triggerRebuild, () => { | ||
filewatchers.delete( id ); | ||
}); | ||
if ( watcher.fileExists ) { filewatchers.set( id, watcher ); } | ||
} | ||
}); | ||
addFileWatchersForModules(bundle.modules); | ||
} | ||
@@ -200,2 +207,9 @@ | ||
}, error => { | ||
try { | ||
//If build failed, make sure we are still watching those files from the most recent successful build. | ||
addFileWatchersForModules( cache.modules ); | ||
} | ||
catch (e) { | ||
//Ignore if they tried to import the output. We are already inside of a catch (probably caused by that). | ||
} | ||
watcher.emit( 'event', { | ||
@@ -202,0 +216,0 @@ code: 'ERROR', |
import EventEmitter from 'events'; | ||
import { resolve } from 'path'; | ||
import path__default from 'path'; | ||
import * as path from 'path'; | ||
import path from 'path'; | ||
import module$1 from 'module'; | ||
@@ -9,15 +7,12 @@ import { readFileSync, realpathSync, watch } from 'fs'; | ||
var path$1 = path__default; | ||
var Module = module$1; | ||
var modules = {}; | ||
var getModule = function(dir) { | ||
var rootPath = dir ? path$1.resolve(dir) : process.cwd(); | ||
var rootName = path$1.join(rootPath, '@root'); | ||
var rootPath = dir ? path.resolve(dir) : process.cwd(); | ||
var rootName = path.join(rootPath, '@root'); | ||
var root = modules[rootName]; | ||
if (!root) { | ||
root = new Module(rootName); | ||
root = new module$1(rootName); | ||
root.filename = rootName; | ||
root.paths = Module._nodeModulePaths(rootPath); | ||
root.paths = module$1._nodeModulePaths(rootPath); | ||
modules[rootName] = root; | ||
@@ -35,3 +30,3 @@ } | ||
var root = getModule(relativeTo); | ||
return Module._resolveFilename(requested, root); | ||
return module$1._resolveFilename(requested, root); | ||
}; | ||
@@ -67,4 +62,4 @@ | ||
class FileWatcher { | ||
constructor ( file, data, callback, dispose ) { | ||
const handleWatchEvent = event => { | ||
constructor ( file, data, callback, useChokidar, dispose ) { | ||
const handleWatchEvent = (event) => { | ||
if ( event === 'rename' || event === 'unlink' ) { | ||
@@ -85,3 +80,3 @@ this.fsWatcher.close(); | ||
try { | ||
if (chokidar) | ||
if (useChokidar) | ||
{ this.fsWatcher = chokidar.watch(file, { ignoreInitial: true }).on('all', handleWatchEvent); } | ||
@@ -109,5 +104,12 @@ else | ||
function watch$1 ( rollup, options ) { | ||
const watchOptions = options.watch || {}; | ||
const useChokidar = 'useChokidar' in watchOptions ? watchOptions.useChokidar : !!chokidar; | ||
if ( useChokidar && !chokidar ) { | ||
throw new Error( `options.watch.useChokidar is true, but chokidar could not be found. Have you installed it?` ); | ||
} | ||
const watcher = new EventEmitter(); | ||
const dests = options.dest ? [ resolve( options.dest ) ] : options.targets.map( target => resolve( target.dest ) ); | ||
const dests = options.dest ? [ path.resolve( options.dest ) ] : options.targets.map( target => path.resolve( target.dest ) ); | ||
let filewatchers = new Map(); | ||
@@ -132,2 +134,29 @@ | ||
function addFileWatchersForModules ( modules ) { | ||
modules.forEach( module => { | ||
let id = module.id; | ||
// skip plugin helper modules | ||
if ( /\0/.test( id ) ) { return; } | ||
try { | ||
id = realpathSync( id ); | ||
} catch ( err ) { | ||
return; | ||
} | ||
if ( ~dests.indexOf( id ) ) { | ||
throw new Error( 'Cannot import the generated bundle' ); | ||
} | ||
if ( !filewatchers.has( id ) ) { | ||
const watcher = new FileWatcher( id, module.originalCode, triggerRebuild, useChokidar, () => { | ||
filewatchers.delete( id ); | ||
}); | ||
if ( watcher.fileExists ) { filewatchers.set( id, watcher ); } | ||
} | ||
}); | ||
} | ||
function build () { | ||
@@ -152,26 +181,3 @@ if ( building || closed ) { return; } | ||
if ( !closed ) { | ||
bundle.modules.forEach( module => { | ||
let id = module.id; | ||
// skip plugin helper modules | ||
if ( /\0/.test( id ) ) { return; } | ||
try { | ||
id = realpathSync( id ); | ||
} catch ( err ) { | ||
return; | ||
} | ||
if ( ~dests.indexOf( id ) ) { | ||
throw new Error( 'Cannot import the generated bundle' ); | ||
} | ||
if ( !filewatchers.has( id ) ) { | ||
const watcher = new FileWatcher( id, module.originalCode, triggerRebuild, () => { | ||
filewatchers.delete( id ); | ||
}); | ||
if ( watcher.fileExists ) { filewatchers.set( id, watcher ); } | ||
} | ||
}); | ||
addFileWatchersForModules(bundle.modules); | ||
} | ||
@@ -198,2 +204,9 @@ | ||
}, error => { | ||
try { | ||
//If build failed, make sure we are still watching those files from the most recent successful build. | ||
addFileWatchersForModules( cache.modules ); | ||
} | ||
catch (e) { | ||
//Ignore if they tried to import the output. We are already inside of a catch (probably caused by that). | ||
} | ||
watcher.emit( 'event', { | ||
@@ -200,0 +213,0 @@ code: 'ERROR', |
{ | ||
"name": "rollup-watch", | ||
"version": "3.2.2", | ||
"version": "4.0.0", | ||
"description": "Watch files for changes and perform incremental rebuilds with Rollup", | ||
@@ -32,2 +32,3 @@ "main": "dist/rollup-watch.cjs.js", | ||
"dependencies": { | ||
"chokidar": "^1.7.0", | ||
"require-relative": "0.8.7" | ||
@@ -38,9 +39,9 @@ }, | ||
"mocha": "^3.2.0", | ||
"rollup": "^0.39.0", | ||
"rollup": "^0.42.0", | ||
"rollup-plugin-buble": "^0.15.0", | ||
"rollup-plugin-commonjs": "^7.0.0", | ||
"rollup-plugin-commonjs": "^8.0.2", | ||
"rollup-plugin-json": "^2.0.0", | ||
"rollup-plugin-node-resolve": "^2.0.0", | ||
"rollup-plugin-node-resolve": "^3.0.0", | ||
"sander": "^0.6.0" | ||
} | ||
} |
@@ -1,3 +0,22 @@ | ||
# work in progress | ||
# rollup-watch | ||
This module will support the `rollup --watch` command, enabling fast incremental rebuilds. | ||
This module is used by the [Rollup](https://rollupjs.org) command line interface to enable automatic incremental rebuilds. | ||
Install it to your project like so... | ||
```bash | ||
npm install --save-dev rollup-watch | ||
``` | ||
...then invoke it by adding the `--watch` flag (or `-w`) to the command that starts Rollup. In this example, `npm run dev` will create your bundle then recreate it whenever its sources change: | ||
```js | ||
// package.json | ||
{ | ||
// ... | ||
"scripts": { | ||
"build": "rollup -c", | ||
"dev": "rollup -c -w" | ||
} | ||
} | ||
``` |
import EventEmitter from 'events'; | ||
import relative from 'require-relative'; | ||
import * as path from 'path'; | ||
import path from 'path'; | ||
import * as fs from 'fs'; | ||
@@ -18,4 +18,4 @@ import { sequence } from './utils/promise.js'; | ||
class FileWatcher { | ||
constructor ( file, data, callback, dispose ) { | ||
const handleWatchEvent = event => { | ||
constructor ( file, data, callback, useChokidar, dispose ) { | ||
const handleWatchEvent = (event) => { | ||
if ( event === 'rename' || event === 'unlink' ) { | ||
@@ -36,3 +36,3 @@ this.fsWatcher.close(); | ||
try { | ||
if (chokidar) | ||
if (useChokidar) | ||
this.fsWatcher = chokidar.watch(file, { ignoreInitial: true }).on('all', handleWatchEvent); | ||
@@ -60,2 +60,9 @@ else | ||
export default function watch ( rollup, options ) { | ||
const watchOptions = options.watch || {}; | ||
const useChokidar = 'useChokidar' in watchOptions ? watchOptions.useChokidar : !!chokidar; | ||
if ( useChokidar && !chokidar ) { | ||
throw new Error( `options.watch.useChokidar is true, but chokidar could not be found. Have you installed it?` ); | ||
} | ||
const watcher = new EventEmitter(); | ||
@@ -83,2 +90,29 @@ | ||
function addFileWatchersForModules ( modules ) { | ||
modules.forEach( module => { | ||
let id = module.id; | ||
// skip plugin helper modules | ||
if ( /\0/.test( id ) ) return; | ||
try { | ||
id = fs.realpathSync( id ); | ||
} catch ( err ) { | ||
return; | ||
} | ||
if ( ~dests.indexOf( id ) ) { | ||
throw new Error( 'Cannot import the generated bundle' ); | ||
} | ||
if ( !filewatchers.has( id ) ) { | ||
const watcher = new FileWatcher( id, module.originalCode, triggerRebuild, useChokidar, () => { | ||
filewatchers.delete( id ); | ||
}); | ||
if ( watcher.fileExists ) filewatchers.set( id, watcher ); | ||
} | ||
}); | ||
} | ||
function build () { | ||
@@ -103,26 +137,3 @@ if ( building || closed ) return; | ||
if ( !closed ) { | ||
bundle.modules.forEach( module => { | ||
let id = module.id; | ||
// skip plugin helper modules | ||
if ( /\0/.test( id ) ) return; | ||
try { | ||
id = fs.realpathSync( id ); | ||
} catch ( err ) { | ||
return; | ||
} | ||
if ( ~dests.indexOf( id ) ) { | ||
throw new Error( 'Cannot import the generated bundle' ); | ||
} | ||
if ( !filewatchers.has( id ) ) { | ||
const watcher = new FileWatcher( id, module.originalCode, triggerRebuild, () => { | ||
filewatchers.delete( id ); | ||
}); | ||
if ( watcher.fileExists ) filewatchers.set( id, watcher ); | ||
} | ||
}); | ||
addFileWatchersForModules(bundle.modules); | ||
} | ||
@@ -149,2 +160,9 @@ | ||
}, error => { | ||
try { | ||
//If build failed, make sure we are still watching those files from the most recent successful build. | ||
addFileWatchersForModules( cache.modules ); | ||
} | ||
catch (e) { | ||
//Ignore if they tried to import the output. We are already inside of a catch (probably caused by that). | ||
} | ||
watcher.emit( 'event', { | ||
@@ -151,0 +169,0 @@ code: 'ERROR', |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18944
530
23
2
+ Addedchokidar@^1.7.0
+ Addedanymatch@1.3.2(transitive)
+ Addedarr-diff@2.0.04.0.0(transitive)
+ Addedarr-flatten@1.1.0(transitive)
+ Addedarr-union@3.1.0(transitive)
+ Addedarray-unique@0.2.10.3.2(transitive)
+ Addedassign-symbols@1.0.0(transitive)
+ Addedasync-each@1.0.6(transitive)
+ Addedatob@2.1.2(transitive)
+ Addedbase@0.11.2(transitive)
+ Addedbinary-extensions@1.13.1(transitive)
+ Addedbindings@1.5.0(transitive)
+ Addedbraces@1.8.52.3.2(transitive)
+ Addedcache-base@1.0.1(transitive)
+ Addedchokidar@1.7.0(transitive)
+ Addedclass-utils@0.3.6(transitive)
+ Addedcollection-visit@1.0.0(transitive)
+ Addedcomponent-emitter@1.3.1(transitive)
+ Addedcopy-descriptor@0.1.1(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddecode-uri-component@0.2.2(transitive)
+ Addeddefine-property@0.2.51.0.02.0.2(transitive)
+ Addedexpand-brackets@0.1.52.1.4(transitive)
+ Addedexpand-range@1.8.2(transitive)
+ Addedextend-shallow@2.0.13.0.2(transitive)
+ Addedextglob@0.3.22.0.4(transitive)
+ Addedfile-uri-to-path@1.0.0(transitive)
+ Addedfilename-regex@2.0.1(transitive)
+ Addedfill-range@2.2.44.0.0(transitive)
+ Addedfor-in@1.0.2(transitive)
+ Addedfor-own@0.1.5(transitive)
+ Addedfragment-cache@0.2.1(transitive)
+ Addedfsevents@1.2.13(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-value@2.0.6(transitive)
+ Addedglob-base@0.3.0(transitive)
+ Addedglob-parent@2.0.0(transitive)
+ Addedgraceful-fs@4.2.11(transitive)
+ Addedhas-value@0.3.11.0.0(transitive)
+ Addedhas-values@0.1.41.0.0(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-accessor-descriptor@1.0.1(transitive)
+ Addedis-binary-path@1.0.1(transitive)
+ Addedis-buffer@1.1.6(transitive)
+ Addedis-data-descriptor@1.0.1(transitive)
+ Addedis-descriptor@0.1.71.0.3(transitive)
+ Addedis-dotfile@1.0.3(transitive)
+ Addedis-equal-shallow@0.1.3(transitive)
+ Addedis-extendable@0.1.11.0.1(transitive)
+ Addedis-extglob@1.0.0(transitive)
+ Addedis-glob@2.0.1(transitive)
+ Addedis-number@2.1.03.0.04.0.0(transitive)
+ Addedis-plain-object@2.0.4(transitive)
+ Addedis-posix-bracket@0.1.1(transitive)
+ Addedis-primitive@2.0.0(transitive)
+ Addedis-windows@1.0.2(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedisobject@2.1.03.0.1(transitive)
+ Addedkind-of@3.2.24.0.06.0.3(transitive)
+ Addedmap-cache@0.2.2(transitive)
+ Addedmap-visit@1.0.0(transitive)
+ Addedmath-random@1.0.4(transitive)
+ Addedmicromatch@2.3.113.1.10(transitive)
+ Addedmixin-deep@1.3.2(transitive)
+ Addedms@2.0.0(transitive)
+ Addednan@2.22.0(transitive)
+ Addednanomatch@1.2.13(transitive)
+ Addednormalize-path@2.1.1(transitive)
+ Addedobject-copy@0.1.0(transitive)
+ Addedobject-visit@1.0.1(transitive)
+ Addedobject.omit@2.0.1(transitive)
+ Addedobject.pick@1.3.0(transitive)
+ Addedparse-glob@3.0.4(transitive)
+ Addedpascalcase@0.1.1(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedposix-character-classes@0.1.1(transitive)
+ Addedpreserve@0.2.0(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedrandomatic@3.1.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedreaddirp@2.2.1(transitive)
+ Addedregex-cache@0.4.4(transitive)
+ Addedregex-not@1.0.2(transitive)
+ Addedremove-trailing-separator@1.1.0(transitive)
+ Addedrepeat-element@1.1.4(transitive)
+ Addedrepeat-string@1.6.1(transitive)
+ Addedresolve-url@0.2.1(transitive)
+ Addedret@0.1.15(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsafe-regex@1.1.0(transitive)
+ Addedset-value@2.0.1(transitive)
+ Addedsnapdragon@0.8.2(transitive)
+ Addedsnapdragon-node@2.1.1(transitive)
+ Addedsnapdragon-util@3.0.1(transitive)
+ Addedsource-map@0.5.7(transitive)
+ Addedsource-map-resolve@0.5.3(transitive)
+ Addedsource-map-url@0.4.1(transitive)
+ Addedsplit-string@3.1.0(transitive)
+ Addedstatic-extend@0.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedto-object-path@0.3.0(transitive)
+ Addedto-regex@3.0.2(transitive)
+ Addedto-regex-range@2.1.1(transitive)
+ Addedunion-value@1.0.1(transitive)
+ Addedunset-value@1.0.0(transitive)
+ Addedurix@0.1.0(transitive)
+ Addeduse@3.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)