Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rollup-watch

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rollup-watch - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

CHANGELOG.md

7

package.json
{
"name": "rollup-watch",
"version": "1.0.0",
"version": "2.0.0",
"description": "Watch files for changes and perform incremental rebuilds with Rollup",

@@ -32,8 +32,9 @@ "main": "dist/rollup-watch.cjs.js",

"rollup": "^0.28.0",
"rollup-plugin-buble": "^0.10.0"
"rollup-plugin-buble": "^0.10.0",
"rollup-plugin-json": "^2.0.0"
},
"dependencies": {
"chokidar": "^1.5.2",
"require-relative": "^0.8.7"
"semver": "^5.1.0"
}
}
import buble from 'rollup-plugin-buble';
import json from 'rollup-plugin-json';
export default {
entry: 'src/index.js',
plugins: [ buble() ],
plugins: [ json(), buble() ],
targets: [

@@ -7,0 +8,0 @@ { dest: 'dist/rollup-watch.cjs.js', format: 'cjs' },

@@ -0,76 +1,95 @@

import EventEmitter from 'events';
import * as chokidar from 'chokidar';
import relative from 'require-relative';
import { sequence } from './utils/promise.js';
import { name, version } from '../package.json';
import checkVersion from './utils/checkVersion.js';
export default function watch ( options ) {
let rollup;
export default function watch ( rollup, options ) {
const emitter = new EventEmitter();
try {
rollup = relative( 'rollup', process.cwd() );
} catch ( err ) {
// TODO handle gracefully
throw err;
}
process.nextTick( () => emitter.emit( 'event', { code: 'STARTING' }) );
let watchedIds;
let rebuildScheduled = false;
let building = false;
checkVersion( name, version )
.catch( err => {
if ( err.code === 'OUT_OF_DATE' ) {
// TODO offer to update
console.error( `rollup-watch is out of date (you have ${err.localVersion}, latest version is ${err.latestVersion}). Update it with npm install -g rollup-watch` ); // eslint-disable-line no-console
}
})
.then( () => {
let watchedIds;
let rebuildScheduled = false;
let building = false;
let watcher;
let watcher;
function triggerRebuild () {
rebuildScheduled = true;
if ( !building ) build();
}
function triggerRebuild () {
rebuildScheduled = true;
if ( !building ) build();
}
function build () {
if ( building ) return;
function build () {
if ( building ) return;
rebuildScheduled = false;
building = true;
let start = Date.now();
let initial = !watcher;
return rollup.rollup( options )
.then( bundle => {
const moduleIds = bundle.modules.map( module => module.id );
emitter.emit( 'event', { code: 'BUILD_START' });
if ( !watcher ) {
watcher = chokidar.watch( moduleIds, {
persistent: true,
ignoreInitial: true
});
rebuildScheduled = false;
building = true;
watcher.on( 'change', triggerRebuild );
watcher.on( 'unlink', triggerRebuild );
return rollup.rollup( options )
.then( bundle => {
const moduleIds = bundle.modules.map( module => module.id );
watchedIds = moduleIds;
} else {
moduleIds.forEach( id => {
if ( !~watchedIds.indexOf( id ) ) {
watcher.add( id );
if ( !watcher ) {
watcher = chokidar.watch( moduleIds, {
persistent: true,
ignoreInitial: true
});
watcher.on( 'change', triggerRebuild );
watcher.on( 'unlink', triggerRebuild );
watchedIds = moduleIds;
} else {
moduleIds.forEach( id => {
if ( !~watchedIds.indexOf( id ) ) {
watcher.add( id );
}
});
watchedIds.forEach( id => {
if ( !~moduleIds.indexOf( id ) ) {
watcher.unwatch( id );
}
});
}
});
watchedIds.forEach( id => {
if ( !~moduleIds.indexOf( id ) ) {
watcher.unwatch( id );
if ( options.targets ) {
return sequence( options.targets, target => {
const mergedOptions = Object.assign( {}, options, target );
return bundle.write( mergedOptions );
});
}
});
}
if ( options.targets ) {
return sequence( options.targets, target => {
const mergedOptions = Object.assign( {}, options, target );
return bundle.write( mergedOptions );
return bundle.write( options );
})
.then( () => {
emitter.emit( 'event', {
code: 'BUILD_END',
duration: Date.now() - start,
initial
});
building = false;
if ( rebuildScheduled ) build();
});
}
}
return bundle.write( options );
})
.then( () => {
building = false;
if ( rebuildScheduled ) build();
});
}
build();
});
build();
return emitter;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc