karma-rollup-preprocessor
Advanced tools
Comparing version 4.0.4 to 5.0.0
# Change Log | ||
All notable changes to this project will be documented in this file. | ||
The format is based on [Keep a Changelog](http://keepachangelog.com/) | ||
and this project adheres to [Semantic Versioning](http://semver.org/) | ||
## [5.0.0] - 2017-08-24 | ||
### Changed | ||
- **Breaking:** Rollup 0.47.x and below is no longer supported. | ||
- **Breaking:** Rollup is now a peer dependency. | ||
- **Breaking:** Requires different Karma configuration. | ||
### Fixed | ||
- The file watcher has been re-built stronger, better, and faster. [#17](https://github.com/jlmakes/karma-rollup-preprocessor/issues/17) | ||
## [4.0.4] - 2017-08-22 | ||
### Changed | ||
- Is there an echo in here? Update dependency versions. Require Rollup 0.45 – 0.47. [#24](https://github.com/jlmakes/karma-rollup-preprocessor/issues/24) | ||
- Is there an echo in here? Update depedency versions. Require Rollup 0.45 – 0.47. [#24](https://github.com/jlmakes/karma-rollup-preprocessor/issues/24) | ||
## [4.0.3] - 2017-08-11 | ||
### Changed | ||
- Update dependency versions. Allow Rollup >= v0.45. | ||
- Update depedency versions. Allow Rollup >= v0.45. | ||
## [4.0.2] - 2017-07-30 | ||
### Changed | ||
- Update dependency versions. Require Rollup v0.45. [#21](https://github.com/jlmakes/karma-rollup-preprocessor/pull/21) | ||
- Update depedency versions. Require Rollup v0.45. [#21](https://github.com/jlmakes/karma-rollup-preprocessor/pull/21) | ||
## [4.0.1] - 2017-07-14 | ||
@@ -75,9 +77,9 @@ | ||
### Fixed | ||
- Test script now uses explicit path to Karma binary. | ||
### 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 | ||
@@ -84,0 +86,0 @@ |
@@ -1,31 +0,38 @@ | ||
// Karma configuration | ||
// Generated on Wed Dec 09 2015 16:06:35 GMT+0100 (CET) | ||
module.exports = function (config) { | ||
config.set({ | ||
plugins: [ | ||
'karma-jasmine', | ||
'karma-mocha-reporter', | ||
'karma-phantomjs-launcher', | ||
require('./lib'), | ||
], | ||
// base path, that will be used to resolve files and exclude | ||
basePath: '', | ||
// frameworks to use | ||
frameworks: ['jasmine'], | ||
reporters: ['mocha'], | ||
browsers: ['PhantomJS'], | ||
logLevel: config.LOG_INFO, // disable > error > warn > info > debug | ||
captureTimeout: 60000, | ||
autoWatch: true, | ||
singleRun: true, | ||
colors: true, | ||
port: 9876, | ||
// list of files / patterns to load in the browser | ||
basePath: '', | ||
files: [ | ||
'test/main.js', | ||
'test/main-node.js', | ||
{ pattern: 'test/t1.js', watched: false }, | ||
{ pattern: 'test/t2.js', watched: false }, | ||
{ pattern: 'test/t3.js', watched: false }, | ||
], | ||
exclude: [], | ||
// add a preprocessor for the main test file | ||
preprocessors: { | ||
'test/main.js': ['rollup'], | ||
'test/main-node.js': ['rollupNode'], | ||
'test/t1.js': ['rollup'], | ||
'test/t2.js': ['rollup'], | ||
'test/t3.js': ['rollupNode'], | ||
}, | ||
// specify the config for the rollup pre-processor: run babel plugin on the code | ||
rollupPreprocessor: { | ||
format: 'iife', | ||
name: 'lib', | ||
plugins: [ | ||
@@ -36,4 +43,2 @@ require('rollup-plugin-buble')(), | ||
// specify a custom config for the rollup pre-processor: | ||
// run node-resolve + commonjs + buble plugin on the code | ||
customPreprocessors: { | ||
@@ -51,57 +56,3 @@ rollupNode: { | ||
}, | ||
// load necessary plugins | ||
plugins: [ | ||
'karma-jasmine', | ||
'karma-phantomjs-launcher', | ||
require('./lib'), | ||
], | ||
// list of files to exclude | ||
exclude: [], | ||
// test results reporter to use | ||
// possible values: 'dots', 'progress', 'junit', 'growl', 'coverage' | ||
reporters: ['progress'], | ||
// web server port | ||
port: 9876, | ||
// 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, | ||
// 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'], | ||
// 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, | ||
}) | ||
} |
136
lib/index.js
'use strict' | ||
const fs = require('fs') | ||
const path = require('path') | ||
const rollup = require('rollup').rollup | ||
const debounce = require('lodash/debounce') | ||
const assign = require('lodash/assign') | ||
const assign = require('object-assign') | ||
const chokidar = require('chokidar') | ||
function createPreprocessor (customConfig, baseConfig, logger) { | ||
const dependencyMap = new Map() | ||
const staleDependants = new Set() | ||
function createPreprocessor (options, preconfig, basePath, emitter, logger) { | ||
const log = logger.create('preprocessor.rollup') | ||
const watch = new Watch(emitter) | ||
let cache | ||
let buffer | ||
/** | ||
* Manually update the modified and accessed timestamps | ||
* of all dependants marked by changed dependencies. | ||
*/ | ||
const recompileDependants = debounce(() => { | ||
const now = Date.now() | ||
for (const dependant of staleDependants.values()) { | ||
fs.utimes(dependant, now, now, () => { | ||
log.debug('Recompiling dependant %s', dependant) | ||
}) | ||
} | ||
staleDependants.clear() | ||
}, 50) | ||
const config = assign({}, baseConfig, (customConfig || {}).options) | ||
function preprocess (content, file, done) { | ||
log.debug('Processing %s', file.originalPath) | ||
try { | ||
config.entry = file.originalPath | ||
config.cache = cache | ||
rollup(config).then(bundle => { | ||
buffer = bundle | ||
/** | ||
* Map all dependencies of the current file | ||
*/ | ||
file.dependencies = bundle.modules | ||
.map(module => module.id) | ||
.filter(id => 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 (const entry of dependencyMap.entries()) { | ||
const dependant = entry[0] | ||
const dependencies = entry[1] | ||
if (dependencies.indexOf(file.originalPath) !== -1) { | ||
staleDependants.add(dependant) | ||
recompileDependants() | ||
} | ||
} | ||
return (content, file, done) => { | ||
const config = assign({}, options, preconfig.options, | ||
{ | ||
input: file.path, | ||
cache, | ||
} | ||
) | ||
rollup(config) | ||
.then(bundle => { | ||
cache = bundle | ||
watch.capture(bundle) | ||
return bundle.generate(config) | ||
}) | ||
.then(generated => { | ||
const processed = (config.sourceMap === 'inline') | ||
? generated.code + `\n//# sourceMappingURL=${generated.map.toUrl()}\n` | ||
: generated.code | ||
cache = buffer | ||
done(null, processed) | ||
let output = generated.code | ||
if (config.sourcemap === 'inline') { | ||
output += `\n//# sourceMappingURL=${generated.map.toUrl()}\n` | ||
} | ||
done(null, output) | ||
}) | ||
.catch(error => { | ||
log.error('Failed to process %s\n\n%s\n', file.originalPath, error.message) | ||
const location = path.relative(basePath, file.path) | ||
log.error('Error processing “%s”\n\n%s\n', location, error.message) | ||
done(error, null) | ||
}) | ||
} | ||
} | ||
} catch (exception) { | ||
log.error('Exception processing %s\n\n%s\n', file.originalPath, exception.message) | ||
done(exception, null) | ||
} | ||
function Watch (emitter) { | ||
this.buffer = new Set() | ||
this.watchList = new Set() | ||
this.watch = chokidar.watch() | ||
this.watch.on('change', () => emitter.refreshFiles()) | ||
emitter.on('run_start', () => this.start()) | ||
} | ||
Watch.prototype.capture = function (bundle) { | ||
for (const module of bundle.modules) { | ||
this.buffer.add(module.id) | ||
} | ||
} | ||
return preprocess | ||
Watch.prototype.clean = function () { | ||
this.watchList.forEach(m => { | ||
if (!this.buffer.has(m)) { | ||
this.watch.unwatch(m) | ||
this.watchList.delete(m) | ||
} | ||
}) | ||
} | ||
createPreprocessor.$inject = ['args', 'config.rollupPreprocessor', 'logger'] | ||
Watch.prototype.start = function () { | ||
this.clean() | ||
this.buffer.forEach(m => { | ||
if (!this.watchList.has(m)) { | ||
this.watch.add(m) | ||
this.watchList.add(m) | ||
} | ||
}) | ||
this.buffer.clear() | ||
} | ||
module.exports = { | ||
'preprocessor:rollup': ['factory', createPreprocessor], | ||
} | ||
createPreprocessor.$inject = [ | ||
'config.rollupPreprocessor', 'args', | ||
'config.basePath', 'emitter', 'logger', | ||
] | ||
module.exports = { 'preprocessor:rollup': ['factory', createPreprocessor] } |
{ | ||
"name": "karma-rollup-preprocessor", | ||
"version": "4.0.4", | ||
"version": "5.0.0", | ||
"description": "Karma preprocessor to bundle ES2015 modules using Rollup", | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"test": "./node_modules/karma/bin/karma start karma.conf.js" | ||
"test": "./node_modules/karma/bin/karma start karma.conf.js", | ||
"testing": "npm test -- --no-single-run" | ||
}, | ||
@@ -27,5 +28,8 @@ "repository": { | ||
"homepage": "https://github.com/jlmakes/karma-rollup-preprocessor", | ||
"peerDependencies": { | ||
"rollup": ">= 0.48" | ||
}, | ||
"dependencies": { | ||
"rollup": "0.45 - 0.47", | ||
"lodash": "^4.17.4" | ||
"chokidar": "^1.7.0", | ||
"object-assign": "^4.1.1" | ||
}, | ||
@@ -37,2 +41,3 @@ "devDependencies": { | ||
"karma-jasmine": "^1.0.2", | ||
"karma-mocha-reporter": "^2.2.3", | ||
"karma-phantomjs-launcher": "^1.0.0", | ||
@@ -39,0 +44,0 @@ "rollup-plugin-buble": "^0.15.0", |
@@ -32,3 +32,3 @@ <p align="center"><img width="200" src="https://jlmak.es/logos/png/karma-rollup-preprocessor.png?v=1"></p> | ||
```bash | ||
npm install karma-rollup-preprocessor --save-dev | ||
npm install karma-rollup-preprocessor | ||
``` | ||
@@ -50,11 +50,9 @@ | ||
files: [ | ||
// Watch src files for changes but | ||
// don't load them into the browser. | ||
{ pattern: 'src/**/*.js', included: false }, | ||
'test/**/*.spec.js', | ||
// Make sure to disable Karma’s file watcher | ||
// because the preprocessor will use its own. | ||
{ pattern: 'test/**/*.spec.js', watched: false } | ||
], | ||
preprocessors: { | ||
'src/**/*.js': ['rollup'], | ||
'test/**/*.spec.js': ['rollup'], | ||
'test/**/*.spec.js': ['rollup'] | ||
}, | ||
@@ -64,10 +62,10 @@ | ||
plugins: [ | ||
require('rollup-plugin-buble')(), | ||
require('rollup-plugin-buble')() | ||
], | ||
format: 'iife', // Helps prevent naming collisions. | ||
moduleName: '<your_project>', // Required for 'iife' format. | ||
sourceMap: 'inline', // Sensible for testing. | ||
}, | ||
}); | ||
}; | ||
format: 'iife', // Helps prevent naming collisions. | ||
name: '<your_project>', // Required for 'iife' format. | ||
sourcemap: 'inline' // Sensible for testing. | ||
} | ||
}) | ||
} | ||
``` | ||
@@ -86,6 +84,3 @@ | ||
files: [ | ||
// Watch src files for changes but | ||
// don't load them into the browser. | ||
{ pattern: 'src/**/*.js', included: false }, | ||
'test/**/*.spec.js', | ||
{ pattern: 'test/**/*.spec.js', watched: false } | ||
], | ||
@@ -95,3 +90,3 @@ | ||
'test/buble/**/*.spec.js': ['rollup'], | ||
'test/babel/**/*.spec.js': ['rollupBabel'], | ||
'test/babel/**/*.spec.js': ['rollupBabel'] | ||
}, | ||
@@ -101,7 +96,7 @@ | ||
plugins: [ | ||
require('rollup-plugin-buble')(), | ||
require('rollup-plugin-buble')() | ||
], | ||
format: 'iife', | ||
moduleName: '<your_project>', | ||
sourceMap: 'inline', | ||
name: '<your_project>', | ||
sourcemap: 'inline' | ||
}, | ||
@@ -111,16 +106,15 @@ | ||
// Clones the base preprocessor, but overwrites | ||
// its options with those defined below. | ||
// its options with those defined below... | ||
rollupBabel: { | ||
base: 'rollup', | ||
options: { | ||
// In this case, to use | ||
// a different transpiler: | ||
// In this case, to use a different transpiler: | ||
plugins: [ | ||
require('rollup-plugin-babel')(), | ||
], | ||
require('rollup-plugin-babel')() | ||
] | ||
} | ||
} | ||
} | ||
}); | ||
}; | ||
}) | ||
} | ||
``` | ||
@@ -127,0 +121,0 @@ |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
18
223
0
15907
3
9
118
1
+ Addedchokidar@^1.7.0
+ Addedobject-assign@^4.1.1
+ Added@rollup/rollup-android-arm-eabi@4.30.1(transitive)
+ Added@rollup/rollup-android-arm64@4.30.1(transitive)
+ Added@rollup/rollup-darwin-arm64@4.30.1(transitive)
+ Added@rollup/rollup-darwin-x64@4.30.1(transitive)
+ Added@rollup/rollup-freebsd-arm64@4.30.1(transitive)
+ Added@rollup/rollup-freebsd-x64@4.30.1(transitive)
+ Added@rollup/rollup-linux-arm-gnueabihf@4.30.1(transitive)
+ Added@rollup/rollup-linux-arm-musleabihf@4.30.1(transitive)
+ Added@rollup/rollup-linux-arm64-gnu@4.30.1(transitive)
+ Added@rollup/rollup-linux-arm64-musl@4.30.1(transitive)
+ Added@rollup/rollup-linux-loongarch64-gnu@4.30.1(transitive)
+ Added@rollup/rollup-linux-powerpc64le-gnu@4.30.1(transitive)
+ Added@rollup/rollup-linux-riscv64-gnu@4.30.1(transitive)
+ Added@rollup/rollup-linux-s390x-gnu@4.30.1(transitive)
+ Added@rollup/rollup-linux-x64-gnu@4.30.1(transitive)
+ Added@rollup/rollup-linux-x64-musl@4.30.1(transitive)
+ Added@rollup/rollup-win32-arm64-msvc@4.30.1(transitive)
+ Added@rollup/rollup-win32-ia32-msvc@4.30.1(transitive)
+ Added@rollup/rollup-win32-x64-msvc@4.30.1(transitive)
+ Added@types/estree@1.0.6(transitive)
+ 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.132.3.3(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-assign@4.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)
+ Addedrollup@4.30.1(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)
- Removedlodash@^4.17.4
- Removedrollup@0.45 - 0.47
- Removedlodash@4.17.21(transitive)
- Removedrollup@0.47.6(transitive)