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

Release test #68

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- 0.10
- 10.16

before_script:
- export DISPLAY=:99.0
Expand All @@ -9,4 +9,4 @@ before_script:
- npm install

script:
- grunt
- grunt
6 changes: 5 additions & 1 deletion Gruntfile.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,14 @@ module.exports = (grunt) ->
options:
commitMessage: 'chore: update contributors'

'auto-release':
options:
remote: 'origin'

bump:
options:
commitMessage: 'chore: release v%VERSION%'
pushTo: 'upstream'
pushTo: 'origin'

grunt.loadTasks 'tasks'
grunt.loadNpmTasks 'grunt-contrib-jshint'
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ commonjsPreprocessor: {
```
When not specified the root folder defaults to the `karma.basePath/node_modules` configuration option.

#### Externals

When external dependencies have prebundled sources.
You can specify what file should be included from the root folder

```js
// karma.conf.js
module.exports = function(config) {
config.set({
// ...
commonjsPreprocessor: {
modulesRoot: 'components',
externals: {
'angular': 'angular/angular.min.js'
}
},
// ...
});
};
```

This effectively translates any `require('angular')` statements into `require('./components/angular/angular.min.js')`.

----

For an example project, check out Karma's [client tests](https://github.com/karma-runner/karma/tree/master/test/client).

----
Expand Down
2 changes: 1 addition & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ module.exports = function(config) {
browsers: process.env.TRAVIS ? ['Firefox'] : ['Chrome'],
reporters: ['dots']
});
};
};
44 changes: 43 additions & 1 deletion lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,28 @@ var os = require('os');

var BRIDGE_FILE_PATH = path.normalize(__dirname + '/../client/commonjs_bridge.js');

var initCommonJS = function(/* config.files */ files) {
var initCommonJS = function(
files,
config,
basePath,
preprocessors,
) {

if (config.externals) {
const keys = Object.keys(config.externals);
for (const key of keys) {
const pattern = path.resolve(config.modulesRoot || 'node_modules', config.externals[key]);
console.log(pattern);
files.push({
pattern: pattern,
included: true,
served: true,
watched: false,
});
preprocessors[pattern] = preprocessors[pattern] || [];
preprocessors[pattern].push("commonjs");
}
}

// Include the file that resolves all the dependencies on the client.
files.push({
Expand All @@ -13,6 +34,12 @@ var initCommonJS = function(/* config.files */ files) {
watched: false
});
};
initCommonJS.$inject = [
"config.files",
"config.commonjsPreprocessor",
"config.basePath",
"config.preprocessors",
];

var createPreprocesor = function(logger, config, basePath) {
var log = logger.create('preprocessor.commonjs');
Expand All @@ -24,6 +51,17 @@ var createPreprocesor = function(logger, config, basePath) {

log.debug('Configured root path for modules "%s".', modulesRootPath);

const externalAugment = {};
if (config.externals) {
const keys = Object.keys(config.externals);

for (const key of keys) {
const expectedPath = path.resolve(modulesRootPath, key, "index.js");
const actualPath = path.resolve(modulesRootPath, config.externals[key]);
externalAugment[actualPath] = expectedPath;
}
}

return function(content, file, done) {

if (file.originalPath === BRIDGE_FILE_PATH) {
Expand All @@ -32,6 +70,10 @@ var createPreprocesor = function(logger, config, basePath) {

log.debug('Processing "%s".', file.originalPath);

if (externalAugment[file.path]) {
file.path = externalAugment[file.path];
}

if (path.extname(file.originalPath) === '.json') {
return done('window.__cjs_module__["' + file.path + '"] = ' + content + ';' + os.EOL);
}
Expand Down
Loading