Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7.0.0 #43

Merged
merged 23 commits into from Feb 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 21 additions & 20 deletions .eslintrc.json
@@ -1,22 +1,23 @@
{
"parserOptions": {
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"mocha": true,
"jasmine": true
},
"extends": "eslint:recommended",
"rules": {
"no-cond-assign": 2,
"no-console": 1,
"no-const-assign": 2,
"no-class-assign": 2,
"no-this-before-super": 2,
"no-unused-vars": 1,
"no-var": 2,
"object-shorthand": [2, "always"]
}
"parserOptions": {
"ecmaVersion": 2017,
"sourceType": "module"
},
"env": {
"es6": true,
"node": true,
"mocha": true,
"jasmine": true
},
"extends": "eslint:recommended",
"rules": {
"no-cond-assign": 2,
"no-console": 1,
"no-const-assign": 2,
"no-class-assign": 2,
"no-this-before-super": 2,
"no-unused-vars": 1,
"no-var": 2,
"object-shorthand": [2, "always"]
}
}
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,7 +1,7 @@
language: node_js
dist: trusty
node_js:
- '6'
- "8"
sudo: required
addons:
chrome: stable
Expand Down
22 changes: 20 additions & 2 deletions CHANGELOG.md
@@ -1,5 +1,23 @@
# Change Log

## Unreleased

### Added

- Support for Rollup `1.0.0` [#42](https://github.com/jlmakes/karma-rollup-preprocessor/issues/42)

### Changed

- **Breaking:** Dropped support for Rollup `< 1.0.0`
- **Breaking:** Dropped support for Node `< 8.0.0`
- Watcher no longer relies on Karma’s `run_start` event. [#41](https://github.com/jlmakes/karma-rollup-preprocessor/issues/41)
- Upgraded dependencies.

### Fixed

- Watcher only rebundles changed files and their dependents. [#28](https://github.com/jlmakes/karma-rollup-preprocessor/issues/28)
- Each entry file has its bundle cache.

## [6.1.2] - 2019-01-02

### Changed
Expand Down Expand Up @@ -33,7 +51,7 @@

### Changed

- **Breaking:** Dropped support for Node < 6.
- **Breaking:** Dropped support for Node `< 6.0.0`

## [5.1.1] - 2018-01-08

Expand All @@ -45,7 +63,7 @@

### Added

- File names containing null bytes are now ignored.
- File names containing null bytes are now ignored. [@brianmhunt](https://github.com/brianmhunt) [#30](https://github.com/jlmakes/karma-rollup-preprocessor/issues/30)

## [5.0.3] - 2018-01-05

Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
@@ -1,6 +1,6 @@
The MIT License

Copyright (C) 2015–2018 [Contributors](https://github.com/jlmakes/karma-rollup-preprocessor/graphs/contributors)
Copyright (C) 2019 [Contributors](https://github.com/jlmakes/karma-rollup-preprocessor/graphs/contributors)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
126 changes: 63 additions & 63 deletions README.md
Expand Up @@ -32,9 +32,9 @@

## Features

* Rebundles your files when watched dependencies change
* Caches bundle output for improved performance
* Maintained with ![heart](http://i.imgur.com/oXJmdtz.gif) by [@jlmakes](https://twitter.com/jlmakes)
- Rebundles your files when watched dependencies change
- Caches bundle output for improved performance
- Maintained with ![heart](http://i.imgur.com/oXJmdtz.gif) by [@jlmakes](https://twitter.com/jlmakes)

<br>

Expand All @@ -57,33 +57,33 @@ Below is a well-founded recommendation using the [Bublé](https://buble.surge.sh
```js
// karma.conf.js
module.exports = function(config) {
config.set({
files: [
/**
* Make sure to disable Karma’s file watcher
* because the preprocessor will use its own.
*/
{ pattern: 'test/**/*.spec.js', watched: false }
],

preprocessors: {
'test/**/*.spec.js': ['rollup']
},

rollupPreprocessor: {
/**
* This is just a normal Rollup config object,
* except that `input` is handled for you.
*/
plugins: [require('rollup-plugin-buble')()],
output: {
format: 'iife', // Helps prevent naming collisions.
name: '<your_project>', // Required for 'iife' format.
sourcemap: 'inline' // Sensible for testing.
}
}
})
}
config.set({
files: [
/**
* Make sure to disable Karma’s file watcher
* because the preprocessor will use its own.
*/
{ pattern: "test/**/*.spec.js", watched: false }
],

preprocessors: {
"test/**/*.spec.js": ["rollup"]
},

rollupPreprocessor: {
/**
* This is just a normal Rollup config object,
* except that `input` is handled for you.
*/
plugins: [require("rollup-plugin-buble")()],
output: {
format: "iife", // Helps prevent naming collisions.
name: "<your_project>", // Required for 'iife' format.
sourcemap: "inline" // Sensible for testing.
}
}
});
};
```

<br>
Expand All @@ -95,40 +95,40 @@ Below shows an example where [configured preprocessors](http://karma-runner.gith
```js
// karma.conf.js
module.exports = function(config) {
config.set({
files: [{ pattern: 'test/**/*.spec.js', watched: false }],

preprocessors: {
'test/buble/**/*.spec.js': ['rollup'],
'test/babel/**/*.spec.js': ['rollupBabel']
},

rollupPreprocessor: {
plugins: [require('rollup-plugin-buble')()],
output: {
format: 'iife',
name: '<your_project>',
sourcemap: 'inline'
}
},

customPreprocessors: {
/**
* Clones the base preprocessor, but overwrites
* its options with those defined below...
*/
rollupBabel: {
base: 'rollup',
options: {
// In this case, to use a different transpiler:
plugins: [require('rollup-plugin-babel')()]
}
}
}
})
}
config.set({
files: [{ pattern: "test/**/*.spec.js", watched: false }],

preprocessors: {
"test/buble/**/*.spec.js": ["rollup"],
"test/babel/**/*.spec.js": ["rollupBabel"]
},

rollupPreprocessor: {
plugins: [require("rollup-plugin-buble")()],
output: {
format: "iife",
name: "<your_project>",
sourcemap: "inline"
}
},

customPreprocessors: {
/**
* Clones the base preprocessor, but overwrites
* its options with those defined below...
*/
rollupBabel: {
base: "rollup",
options: {
// In this case, to use a different transpiler:
plugins: [require("rollup-plugin-babel")()]
}
}
}
});
};
```

## Support

Supports all Rollup plug-ins, and works on Node `6` and up. Happy bundling!
Supports all Rollup plug-ins, and works on Node `8` and up. Happy bundling!
96 changes: 48 additions & 48 deletions karma.conf.js
@@ -1,57 +1,57 @@
module.exports = function(config) {
config.set({
plugins: [
"karma-jasmine",
"karma-mocha-reporter",
"karma-chrome-launcher",
require("./lib")
],
config.set({
plugins: [
"karma-jasmine",
"karma-mocha-reporter",
"karma-chrome-launcher",
require("./lib")
],

frameworks: ["jasmine"],
reporters: ["mocha"],
browsers: ["ChromeHeadless"],
frameworks: ["jasmine"],
reporters: ["mocha"],
browsers: ["ChromeHeadless"],

logLevel: config.LOG_INFO, // disable > error > warn > info > debug
captureTimeout: 60000,
autoWatch: true,
singleRun: true,
colors: true,
port: 9876,
logLevel: config.LOG_INFO, // disable > error > warn > info > debug
captureTimeout: 60000,
autoWatch: true,
singleRun: true,
colors: true,
port: 9876,

basePath: "",
files: [
{ pattern: "test/t1.js", watched: false },
{ pattern: "test/t2.js", watched: false },
{ pattern: "test/t3.js", watched: false }
],
exclude: [],
basePath: "",
files: [
{ pattern: "test/t1.js", watched: false },
{ pattern: "test/t2.js", watched: false },
{ pattern: "test/t3.js", watched: false }
],
exclude: [],

preprocessors: {
"test/t1.js": ["rollup"],
"test/t2.js": ["rollup"],
"test/t3.js": ["rollupNode"]
},
preprocessors: {
"test/t1.js": ["rollup"],
"test/t2.js": ["rollup"],
"test/t3.js": ["rollupNode"]
},

rollupPreprocessor: {
output: {
name: "lib",
format: "iife",
sourcemap: "inline"
},
plugins: [require("rollup-plugin-buble")()]
},
rollupPreprocessor: {
output: {
name: "lib",
format: "iife",
sourcemap: "inline"
},
plugins: [require("rollup-plugin-buble")()]
},

customPreprocessors: {
rollupNode: {
base: "rollup",
options: {
plugins: [
require("rollup-plugin-node-resolve")(),
require("rollup-plugin-commonjs")(),
require("rollup-plugin-buble")()
]
}
}
customPreprocessors: {
rollupNode: {
base: "rollup",
options: {
plugins: [
require("rollup-plugin-node-resolve")(),
require("rollup-plugin-commonjs")(),
require("rollup-plugin-buble")()
]
}
});
}
}
});
};
41 changes: 41 additions & 0 deletions lib/Watcher.js
@@ -0,0 +1,41 @@
"use strict";

const chokidar = require("chokidar");
const debounce = require("debounce");

class Watcher {
constructor(emitter) {
this.emitter = emitter;
this.files = new Map();
this.watch = chokidar.watch();
this.watch.on("change", debounce(this.handleChange.bind(this), 150));
}

add(entry, dependencies) {
if (!hasNullByte(entry)) {
const filteredDependencies = dependencies.filter(
path => !hasNullByte(path)
);
this.files.set(entry, filteredDependencies);
this.watch.add([entry, ...filteredDependencies]);
}
}

handleChange(path) {
for (const [entry, dependencies] of this.files.entries()) {
if (entry === path || dependencies.includes(path)) {
return this.refreshFile(entry);
}
}
}

refreshFile(path) {
this.emitter._fileList.changeFile(path, true);
}
}

function hasNullByte(string) {
return string.includes("\u0000");
}

module.exports = Watcher;