New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.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 3.0.3 to 4.0.0

LICENSE.md

7

.eslintrc.json
{
"env": {
"es6": true,
"node": true

@@ -7,2 +8,3 @@ },

"rules": {
"arrow-spacing": 2,
"array-bracket-spacing": [2, "never", { "arraysInArrays": true }],

@@ -18,6 +20,9 @@ "block-spacing": 2,

"no-cond-assign": 2,
"no-const-assign": 2,
"no-trailing-spaces": 2,
"no-mixed-spaces-and-tabs": [2, "smart-tabs"],
"no-var": 2,
"object-curly-spacing": [2, "always"],
"semi": [2, "always"],
"object-shorthand": [2, "always"],
"semi": [2, "never"],
"space-before-blocks": [2, "always"],

@@ -24,0 +29,0 @@ "space-before-function-paren": [2, "always"],

12

CHANGELOG.md

@@ -8,2 +8,10 @@ # Change Log

## [4.0.0] - 2017-04-04
### Added
- Custom preprocessors are now supported. [@mjeanroy](https://github.com/mjeanroy) [#20](https://github.com/jlmakes/karma-rollup-preprocessor/pull/20)
### Changed
- **Breaking:** Dropped support for Node `0.12`.
## [3.0.3] - 2017-01-03

@@ -14,5 +22,2 @@

### Removed
- Dropped support for Node `0.12`.
## [3.0.2] - 2016-12-29

@@ -84,2 +89,3 @@

[4.0.0]: https://github.com/jlmakes/karma-rollup-preprocessor/compare/3.0.3...4.0.0
[3.0.3]: https://github.com/jlmakes/karma-rollup-preprocessor/compare/3.0.2...3.0.3

@@ -86,0 +92,0 @@ [3.0.2]: https://github.com/jlmakes/karma-rollup-preprocessor/compare/3.0.1...3.0.2

@@ -17,2 +17,3 @@ // Karma configuration

'test/main.js',
'test/main-node.js',
],

@@ -24,2 +25,3 @@

'test/main.js': ['rollup'],
'test/main-node.js': ['rollupNode'],
},

@@ -30,2 +32,3 @@

rollupPreprocessor: {
format: 'iife',
plugins: [

@@ -36,2 +39,17 @@ require('rollup-plugin-buble')(),

// specify a custom config for the rollup pre-processor:
// run node-resolve + commonjs + buble plugin on the code
customPreprocessors: {
rollupNode: {
base: 'rollup',
options: {
plugins: [
require('rollup-plugin-node-resolve')(),
require('rollup-plugin-commonjs')(),
require('rollup-plugin-buble')(),
],
},
},
},
// load necessary plugins

@@ -38,0 +56,0 @@ plugins: [

@@ -1,14 +0,14 @@

'use strict';
'use strict'
var fs = require('fs');
var rollup = require('rollup').rollup;
var debounce = require('debounce');
const fs = require('fs')
const rollup = require('rollup').rollup
const _ = require('lodash')
var dependencyMap = new Map();
var staleDependants = new Set();
function createPreprocessor (customConfig, baseConfig, logger) {
const dependencyMap = new Map()
const staleDependants = new Set()
const log = logger.create('preprocessor.rollup')
function createPreprocessor (config, logger) {
var log = logger.create('preprocessor.rollup');
var cache;
let cache

@@ -19,23 +19,23 @@ /**

*/
var recompileDependants = debounce(function () {
var now = Date.now();
for (var dependant of staleDependants.values()) {
fs.utimes(dependant, now, now, function() {
log.debug('Recompiling dependant %s', dependant);
});
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);
staleDependants.clear()
}, 50)
config = config || {};
const config = _.assign({}, baseConfig, (customConfig || {}).options)
function preprocess (content, file, done) {
log.debug('Processing %s', file.originalPath);
log.debug('Processing %s', file.originalPath)
try {
config.entry = file.originalPath;
config.cache = cache;
config.entry = file.originalPath
config.cache = cache
rollup(config).then(function (bundle) {
rollup(config).then(bundle => {

@@ -46,6 +46,6 @@ /**

file.dependencies = bundle.modules
.map(function (module) { return module.id; })
.filter(function (id) { return id !== file.originalPath; });
.map(module => module.id)
.filter(id => id !== file.originalPath)
dependencyMap.set(file.originalPath, file.dependencies);
dependencyMap.set(file.originalPath, file.dependencies)

@@ -57,40 +57,38 @@ /**

*/
for (var entry of dependencyMap.entries()) {
var dependant = entry[0];
var dependencies = entry[1];
if (dependencies.indexOf(file.originalPath) > -1) {
staleDependants.add(dependant);
recompileDependants();
for (const entry of dependencyMap.entries()) {
const dependant = entry[0]
const dependencies = entry[1]
if (dependencies.indexOf(file.originalPath) !== -1) {
staleDependants.add(dependant)
recompileDependants()
}
}
var generated = bundle.generate(config);
var processed = generated.code;
const generated = bundle.generate(config)
cache = bundle;
const processed = (config.sourceMap === 'inline')
? generated.code + `\n//# sourceMappingURL=${generated.map.toUrl()}\n`
: generated.code
if (config.sourceMap === 'inline') {
processed += '\n' + '//# sourceMappingURL=' + generated.map.toUrl() + '\n';
}
done(null, processed);
cache = bundle
done(null, processed)
})
.catch(function (error) {
log.error('Failed to process %s\n\n%s\n', file.originalPath, error.message);
done(error, null);
});
.catch(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);
log.error('Exception processing %s\n\n%s\n', file.originalPath, exception.message)
done(exception, null)
}
}
return preprocess;
return preprocess
}
createPreprocessor.$inject = ['config.rollupPreprocessor', 'logger'];
createPreprocessor.$inject = ['args', 'config.rollupPreprocessor', 'logger']
module.exports = {
'preprocessor:rollup': ['factory', createPreprocessor],
};
}
{
"name": "karma-rollup-preprocessor",
"version": "3.0.3",
"version": "4.0.0",
"description": "Karma preprocessor to bundle ES2015 modules using Rollup",

@@ -28,4 +28,4 @@ "main": "lib/index.js",

"dependencies": {
"debounce": "^1.0.0",
"rollup": "^0.x"
"rollup": "^0.x",
"lodash": "^4.17.4"
},

@@ -38,3 +38,5 @@ "devDependencies": {

"karma-phantomjs-launcher": "^1.0.0",
"rollup-plugin-buble": "^0.15.0"
"rollup-plugin-buble": "^0.15.0",
"rollup-plugin-commonjs": "^8.0.2",
"rollup-plugin-node-resolve": "^2.0.0"
},

@@ -41,0 +43,0 @@ "author": "Julian Lloyd",

@@ -1,2 +0,2 @@

<p align="center"><img width="200"src="https://jlmak.es/logos/png/karma-rollup-preprocessor.png?v=1"></p>
<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 ES2015 modules using <a href="http://rollupjs.org/">Rollup</a>.</p>

@@ -40,3 +40,3 @@ <p align="center">

### Example
### Standard
Below is a well-founded recommendation using the [Bublé](https://buble.surge.sh) ES2015 transpiler:

@@ -75,4 +75,47 @@

### Configured Preprocessors
Below shows one example where [`customPreprocessors` option](http://karma-runner.github.io/1.0/config/preprocessors.html) can be very helpful:
```js
// karma.conf.js
module.exports = function (config) {
config.set({
files: [
// watch src files for changes but
// don't load them into the browser.
{ pattern: 'src/**/*.js', included: false },
'test/**/*.spec.js',
],
preprocessors: {
'test/buble/**/*.spec.js': ['rollup'],
'test/babel/**/*.spec.js': ['rollupBabel'],
},
rollupPreprocessor: {
plugins: [
require('rollup-plugin-buble')(),
],
format: 'iife',
moduleName: '<your_project>',
sourceMap: 'inline',
},
customPreprocessors: {
rollupBabel: {
base: 'rollup',
options: {
plugins: [
require('rollup-plugin-babel')(),
],
}
}
}
});
};
```
## Support
Supports all Rollup plug-ins, and works on Node `4` and up. Happy bundling!
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