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 3.2.2 to 4.0.0

6

CHANGELOG.md
# 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 @@

88

dist/rollup-watch.cjs.js

@@ -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',

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