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

karma-rollup-preprocessor

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

karma-rollup-preprocessor - npm Package Compare versions

Comparing version 4.0.4 to 5.0.0

test/fixtures/1.js

26

CHANGELOG.md
# 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,
})
}
'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 @@

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