karma-rollup-preprocessor
Advanced tools
Comparing version
@@ -1,13 +0,62 @@ | ||
# 2.0.2 | ||
* #7 Fixed errors during rollup not rejecting the promise | ||
* #9 Update dependencies | ||
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
# 2.0.1 | ||
* #5 Add logging on compile error & update to latest Rollup | ||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/) | ||
# 2.0.0 | ||
**BREAKING** the options for the preprocessor are now specified in 2 separate object, `rollup` and `bundle` | ||
## [3.0.0] - 2016-12-02 | ||
# 1.0.0 | ||
Initial version | ||
A special thanks to [@klaascuvelier](https://github.com/klaascuvelier) who originally authored this repository, and has passed the torch to [@jlmakes](https://github.com/jlmakes) to keep things in tidy working order. | ||
### Added | ||
- Support for Karma `autoWatch: true`. Any file changes now properly reprocess all dependencies. [@brianmhunt](https://github.com/brianmhunt) [#3](https://github.com/jlmakes/karma-rollup-preprocessor/issues/3) [#11](https://github.com/jlmakes/karma-rollup-preprocessor/pull/11) | ||
- Generated bundles are now cached for improved performance. [#10](https://github.com/jlmakes/karma-rollup-preprocessor/issues/10) | ||
- Error log output has been improved for clarity. | ||
### Changed | ||
- **Breaking:** The `2.0.0` change that split preprocessor options has been reverted. | ||
- Rollup dependency range changed to anything < `1.0.0`. [#12](https://github.com/jlmakes/karma-rollup-preprocessor/pull/12) [#13](https://github.com/jlmakes/karma-rollup-preprocessor/issues/13) | ||
- Travis CI now tests in Node `0.12`, `4` and `6`. | ||
- Updated `karma-jasmine` to latest major version. | ||
### Removed | ||
- Preprocessor no longer sets a default bundle format. | ||
### Fixed | ||
- Test script now uses explicit path to Karma binary. | ||
## [2.0.2] - 2016-05-13 | ||
### Changed | ||
- Rollup dependency version updated. [#9](https://github.com/jlmakes/karma-rollup-preprocessor/pull/9) | ||
- Updated `karma-phantomjs-launcher` to latest major version. [#9](https://github.com/jlmakes/karma-rollup-preprocessor/pull/9) | ||
- Replaced `phantomjs` with `phantomjs-prebuild`. [#9](https://github.com/jlmakes/karma-rollup-preprocessor/pull/9) | ||
### Fixed | ||
- Corrected typo preventing Rollup errors outputting to karma error log. [#7](https://github.com/jlmakes/karma-rollup-preprocessor/pull/7) | ||
## [2.0.1] - 2016-01-11 | ||
### Added | ||
- Rollup errors are now output to the karma error log. [#5](https://github.com/jlmakes/karma-rollup-preprocessor/pull/5) | ||
- Rollup dependency version updated. | ||
## [2.0.0] - 2015-12-14 | ||
### Changed | ||
- **Breaking:** Preprocessor options have been split into 2 separate objects, `rollup` and `bundle`. | ||
## [1.0.0] - 2015-12-09 | ||
Hello  World | ||
[3.0.0]: https://github.com/jlmakes/karma-rollup-preprocessor/compare/2.0.2...3.0.0 | ||
[2.0.2]: https://github.com/jlmakes/karma-rollup-preprocessor/compare/2658714f911bac857be4b2d169ea363d33d85050...2.0.2 | ||
[2.0.1]: https://github.com/jlmakes/karma-rollup-preprocessor/compare/2.0.0...2658714f911bac857be4b2d169ea363d33d85050 | ||
[2.0.0]: https://github.com/jlmakes/karma-rollup-preprocessor/compare/1.0.0...2.0.0 | ||
[1.0.0]: https://github.com/jlmakes/karma-rollup-preprocessor/tree/1.0.0 |
// Karma configuration | ||
// Generated on Wed Dec 09 2015 16:06:35 GMT+0100 (CET) | ||
module.exports = function (config) { | ||
config.set({ | ||
module.exports = function (config) | ||
{ | ||
config.set({ | ||
// base path, that will be used to resolve files and exclude | ||
basePath: '', | ||
// base path, that will be used to resolve files and exclude | ||
basePath: '', | ||
// frameworks to use | ||
frameworks: ['jasmine'], | ||
// frameworks to use | ||
frameworks: ['jasmine'], | ||
// list of files / patterns to load in the browser | ||
files: [ | ||
'test/main.js', | ||
], | ||
// list of files / patterns to load in the browser | ||
files: [ | ||
'test/main.js' | ||
], | ||
// add a preprocessor for the main test file | ||
preprocessors: { | ||
'test/main.js': ['rollup'], | ||
}, | ||
// add a preprocessor for the main test file | ||
preprocessors: { | ||
'test/main.js': ['rollup'] | ||
}, | ||
// specify the config for the rollup pre-processor: run babel plugin on the code | ||
rollupPreprocessor: { | ||
plugins: [ | ||
require('rollup-plugin-buble')(), | ||
], | ||
}, | ||
// specify the config for the rollup pre-processor: run babel plugin on the code | ||
rollupPreprocessor: { | ||
rollup: { | ||
plugins: [ | ||
require('rollup-plugin-babel')({ | ||
presets: [ | ||
require('babel-preset-es2015-rollup') | ||
] | ||
}) | ||
] | ||
} | ||
}, | ||
// load necessary plugins | ||
plugins: [ | ||
'karma-jasmine', | ||
'karma-phantomjs-launcher', | ||
require('./lib'), | ||
], | ||
// load necessary plugins | ||
plugins: [ | ||
'karma-jasmine', | ||
'karma-phantomjs-launcher', | ||
require('./lib') | ||
], | ||
// list of files to exclude | ||
exclude: [], | ||
// list of files to exclude | ||
exclude: [], | ||
// test results reporter to use | ||
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' | ||
reporters: ['progress'], | ||
// test results reporter to use | ||
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' | ||
reporters: ['progress'], | ||
// web server port | ||
port: 9876, | ||
// web server port | ||
port: 9876, | ||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || | ||
// config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || | ||
// config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: false, | ||
// enable / disable watching file and executing tests whenever any file changes | ||
autoWatch: false, | ||
// Start these browsers, currently available: | ||
// - Chrome | ||
// - ChromeCanary | ||
// - Firefox | ||
// - Opera (has to be installed with `npm install karma-opera-launcher`) | ||
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) | ||
// - PhantomJS | ||
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) | ||
browsers: ['PhantomJS'], | ||
// Start these browsers, currently available: | ||
// - Chrome | ||
// - ChromeCanary | ||
// - Firefox | ||
// - Opera (has to be installed with `npm install karma-opera-launcher`) | ||
// - Safari (only Mac; has to be installed with `npm install karma-safari-launcher`) | ||
// - PhantomJS | ||
// - IE (only Windows; has to be installed with `npm install karma-ie-launcher`) | ||
browsers: ['PhantomJS'], | ||
// If browser does not capture in given timeout [ms], kill it | ||
captureTimeout: 60000, | ||
// If browser does not capture in given timeout [ms], kill it | ||
captureTimeout: 60000, | ||
// Continuous Integration mode | ||
// if true, it capture browsers, run tests and exit | ||
singleRun: true | ||
}); | ||
// Continuous Integration mode | ||
// if true, it capture browsers, run tests and exit | ||
singleRun: true, | ||
}); | ||
}; |
120
lib/index.js
'use strict'; | ||
var rollup = require('rollup'); | ||
var fs = require('fs'); | ||
var rollup = require('rollup').rollup; | ||
var debounce = require('debounce'); | ||
// @param args {Object} - Config object of custom preprocessor. | ||
// @param config {Object} - Config object of rollupPreprocessor. | ||
// @param logger {Object} - Karma's logger. | ||
// @helper helper {Object} - Karma's helper functions. | ||
function createPreprocessor (args, config, logger, helper) | ||
{ | ||
var log = logger.create('preprocessor.rollup'); | ||
config = config || {}; | ||
var dependencyMap = new Map(); | ||
var staleDependants = new Set(); | ||
var rollupConfig = config.rollup || {}; | ||
var bundleConfig = config.bundle || {}; | ||
function preprocess (content, file, done) | ||
{ | ||
log.debug('Processing "%s".', file.originalPath); | ||
function createPreprocessor (config, logger) { | ||
var log = logger.create('preprocessor.rollup'); | ||
var cache; | ||
try { | ||
rollupConfig.entry = file.originalPath; | ||
/** | ||
* Manually update the modified and accessed timestamps | ||
* of all dependants marked by changed dependencies. | ||
*/ | ||
var recompileDependants = debounce(function () { | ||
var now = Date.now(); | ||
for (var dependant of staleDependants.values()) { | ||
fs.utimes(dependant, now, now); | ||
log.debug('Recompiling dependant %s', dependant); | ||
} | ||
staleDependants.clear(); | ||
}, 50); | ||
rollup | ||
.rollup(rollupConfig) | ||
.then(function (bundle) | ||
{ | ||
if (!bundleConfig.hasOwnProperty('format')) { | ||
bundleConfig.format = 'es6'; | ||
} | ||
var generated = bundle.generate(bundleConfig); | ||
var processed = generated.code; | ||
config = config || {}; | ||
if (bundleConfig.sourceMap === 'inline') { | ||
var url = generated.map.toUrl(); | ||
processed += "\n" + '//# sourceMappingURL=' + url; | ||
} | ||
function preprocess (content, file, done) { | ||
log.debug('Processing %s', file.originalPath); | ||
done(null, processed); | ||
}) | ||
.catch(function (error) | ||
{ | ||
log.error('Failed to process "%s".\n %s', file.originalPath, error.message); | ||
done(error, null) | ||
}); | ||
try { | ||
config.entry = file.originalPath; | ||
config.cache = cache; | ||
} | ||
catch (exception) { | ||
log.error('%s\n at %s', exception.message, file.originalPath); | ||
done(exception, null); | ||
} | ||
} | ||
rollup(config).then(function (bundle) { | ||
return preprocess; | ||
/** | ||
* Map all dependencies of the current file | ||
*/ | ||
file.dependencies = bundle.modules | ||
.map(function (module) { return module.id; }) | ||
.filter(function (id) { return id !== file.originalPath; }); | ||
dependencyMap.set(file.originalPath, file.dependencies); | ||
/** | ||
* Check all dependants to see if the current file | ||
* is one of their dependencies, marking those that | ||
* match as stale and triggering their recompilation. | ||
*/ | ||
for (var entry of dependencyMap.entries()) { | ||
var dependant = entry[0]; | ||
var dependencies = entry[1]; | ||
if (dependencies.indexOf(file.originalPath) > -1) { | ||
staleDependants.add(dependant); | ||
recompileDependants(); | ||
} | ||
} | ||
var generated = bundle.generate(config); | ||
var processed = generated.code; | ||
cache = bundle; | ||
if (config.sourceMap === 'inline') { | ||
processed += '\n' + '//# sourceMappingURL=' + generated.map.toUrl() + '\n'; | ||
} | ||
done(null, processed); | ||
}) | ||
.catch(function (error) { | ||
log.error('Failed to process %s\n\n%s\n', file.originalPath, error.message); | ||
done(error, null); | ||
}); | ||
} catch (exception) { | ||
log.error('Exception processing %s\n\n%s\n', file.originalPath, exception.message); | ||
done(exception, null); | ||
} | ||
} | ||
return preprocess; | ||
} | ||
createPreprocessor.$inject = ['args', 'config.rollupPreprocessor', 'logger', 'helper']; | ||
createPreprocessor.$inject = ['config.rollupPreprocessor', 'logger']; | ||
module.exports = { | ||
'preprocessor:rollup': ['factory', createPreprocessor] | ||
'preprocessor:rollup': ['factory', createPreprocessor], | ||
}; |
The MIT License | ||
Copyright (c) 2010-2015 Showpad | ||
Copyright (c) 2016 Julian Lloyd | ||
@@ -21,2 +21,2 @@ Permission is hereby granted, free of charge, to any person obtaining a copy | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
THE SOFTWARE. |
{ | ||
"name": "karma-rollup-preprocessor", | ||
"version": "2.0.2", | ||
"description": "A rollup preprocessor for Karma", | ||
"version": "3.0.0", | ||
"description": "Karma preprocessor to bundle ES6 modules using Rollup", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "karma start" | ||
"test": "./node_modules/karma/bin/karma start karma.conf.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/showpad/karma-rollup-preprocessor.git" | ||
"url": "git://github.com/jlmakes/karma-rollup-preprocessor.git" | ||
}, | ||
"keywords": [ | ||
"es2015", | ||
"karma", | ||
"rollup", | ||
"preprocessor" | ||
"modules", | ||
"import", | ||
"export", | ||
"plugin", | ||
"preprocessor", | ||
"rollup" | ||
], | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/showpad/karma-rollup-preprocessor/issues" | ||
"url": "https://github.com/jlmakes/karma-rollup-preprocessor/issues" | ||
}, | ||
"homepage": "https://github.com/showpad/karma-rollup-preprocessor", | ||
"homepage": "https://github.com/jlmakes/karma-rollup-preprocessor", | ||
"dependencies": { | ||
"rollup": "^0.26.0" | ||
"debounce": "^1.0.0", | ||
"rollup": "^0.x" | ||
}, | ||
"devDependencies": { | ||
"babel-preset-es2015-rollup": "^1.0.0", | ||
"eslint": "^3.11.1", | ||
"jasmine-core": "^2.4.1", | ||
"karma": "^0.13.15", | ||
"karma-jasmine": "^0.3.6", | ||
"karma": "^1.3.0", | ||
"karma-jasmine": "^1.0.2", | ||
"karma-phantomjs-launcher": "^1.0.0", | ||
"phantomjs-prebuilt": "^2.1.7", | ||
"rollup-plugin-babel": "^2.2.0" | ||
} | ||
"rollup-plugin-buble": "^0.14.0" | ||
}, | ||
"author": "Julian Lloyd", | ||
"license": "MIT" | ||
} |
@@ -1,13 +0,31 @@ | ||
# karma-rollup-preprocessor | ||
<p align="center"><img width="200"src="https://jlmak.es/logos/png/karma-rollup-preprocessor.png?v=1"></p> | ||
<p align="center">Karma preprocessor to bundle ES6 modules using <a href="http://rollupjs.org/">Rollup</a>.</p> | ||
<p align="center"> | ||
<a href="https://travis-ci.org/jlmakes/karma-rollup-preprocessor"> | ||
<img src="https://img.shields.io/travis/jlmakes/karma-rollup-preprocessor.svg" alt="Build Status"> | ||
</a> | ||
<a href="https://david-dm.org/jlmakes/karma-rollup-preprocessor"> | ||
<img src="https://img.shields.io/david/jlmakes/karma-rollup-preprocessor.svg" alt="Dependency Status"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/karma-rollup-preprocessor"> | ||
<img src="https://img.shields.io/npm/dm/karma-rollup-preprocessor.svg" alt="Downloads"> | ||
</a> | ||
<a href="https://www.npmjs.com/package/karma-rollup-preprocessor"> | ||
<img src="https://img.shields.io/npm/v/karma-rollup-preprocessor.svg" alt="Version"> | ||
</a> | ||
<a href="https://opensource.org/licenses/MIT"> | ||
<img src="https://img.shields.io/npm/l/karma-rollup-preprocessor.svg" alt="License"> | ||
</a> | ||
</p> | ||
[](https://travis-ci.org/showpad/karma-rollup-preprocessor) | ||
[](https://www.npmjs.org/package/karma-rollup-preprocessor) | ||
[](https://www.npmjs.org/package/karma-rollup-preprocessor) | ||
<br> | ||
> Preprocessor to bundle ES6 modules fly with [rollup](http://rollupjs.org/). | ||
## Features | ||
- Rebundles your files when watched dependencies change | ||
- Caches bundle output for improved performance | ||
- Maintained with  by [@jlmakes](https://twitter.com/jlmakes) | ||
This preprocessor is mainly used to bundle your spec entry point but might be useful in other cases as well. | ||
<br> | ||
# Installation | ||
## Installation | ||
```bash | ||
@@ -17,38 +35,41 @@ npm install karma-rollup-preprocessor --save-dev | ||
<br> | ||
# Configuration | ||
The `rollupPreprocessor` configuration is optional. (You'll need to install more dependencies). It takes two keys: `rollup` and | ||
`bundle`. | ||
## Configuration | ||
All the options detailed in the [Rollup Documentation](https://github.com/rollup/rollup/wiki/JavaScript-API) can be passed to `rollupPreprocessor`. | ||
`rollup` is the configuration object for `rollup` (See [rollup.rollup](https://github.com/rollup/rollup/wiki/JavaScript-API#rolluprollup-options-) for more details). | ||
### Example | ||
Below is a well-founded recommendation using the [Bublé](https://buble.surge.sh) ES2015 transpiler: | ||
`bundle` is the configuration object used when generating the bundle (See [bundle.generate](https://github.com/rollup/rollup/wiki/JavaScript-API#bundlegenerate-options-) for more details) | ||
*Notice* this is preprocessor and does not write a file or return the bundle, only the content of the processed file gets changed. | ||
So when adding the `sourceMaps` options, `inline` is the only logical value. | ||
## Example | ||
```js | ||
// karma.conf.js | ||
module.exports = function (config) { | ||
config.set({ | ||
preprocessors: { | ||
'test/main.js': ['rollup'] | ||
}, | ||
rollupPreprocessor: { | ||
rollup: { | ||
plugins: [ | ||
require('rollup-plugin-babel')({ | ||
presets: [ | ||
require('babel-preset-es2015-rollup') | ||
] | ||
}) | ||
] | ||
}, | ||
bundle: { | ||
sourceMap: 'inline' | ||
} | ||
} | ||
}); | ||
config.set({ | ||
files: [ | ||
'src/**/*.js', | ||
'test/**/*.spec.js', | ||
], | ||
preprocessors: { | ||
'src/**/*.js': ['rollup'], | ||
'test/**/*.spec.js': ['rollup'], | ||
}, | ||
rollupPreprocessor: { | ||
plugins: [ | ||
require('rollup-plugin-buble')(), | ||
], | ||
format: 'iife', // helps prevent naming collisions | ||
moduleName: '<your_project>' // required for 'iife' format | ||
sourceMap: 'inline', // sensible for testing | ||
}, | ||
}); | ||
}; | ||
``` | ||
<br> | ||
## Support | ||
Supports all Rollup plug-ins, and works on Node `0.12.x` and up. Happy bundling! |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
12591
43.44%6
-14.29%11
10%163
34.71%0
-100%75
38.89%2
100%1
Infinity%1
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
Updated