Skip to content

Commit

Permalink
Alias babel-runtime by default so it can be found when needed
Browse files Browse the repository at this point in the history
Drop phantomjs-polyfill and use Babel's polyfill in Karma config, as it
includes the regenerator runtime.

Fixes #10
  • Loading branch information
insin committed Dec 4, 2015
1 parent cb923e4 commit 4f2e1e0
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Expand Up @@ -6,6 +6,10 @@ Changed:

- Webpack loader config objects are now merged with [webpack-merge](https://github.com/survivejs/webpack-merge); query objects will now be deep merged, with lists occurring at the same position in build and user config being concatenated instead of overwritten.

Fixed:

- babel-runtime can now be resolved from nwb's dependencies when using `optional: ['runtime']` Babel config.

# 0.1.0 / 2015-12-02

First 0.x release.
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -51,7 +51,6 @@
"karma-sourcemap-loader": "0.3.6",
"karma-webpack": "1.7.0",
"phantomjs": "1.9.19",
"phantomjs-polyfill": "0.0.1",

"mocha": "2.3.4",
"expect": "1.13.0",
Expand Down
22 changes: 6 additions & 16 deletions src/createKarmaConfig.js
Expand Up @@ -5,12 +5,10 @@ process.env.NODE_ENV = 'test'

import path from 'path'

import glob from 'glob'

import createWebpackConfig, {loaderConfigFactory} from './createWebpackConfig'
import debug from './debug'
import getUserConfig from './getUserConfig'
import {typeOf} from './utils'
import {findNodeModules, typeOf} from './utils'

const DEFAULT_TESTS = 'tests/**/*-test.js'

Expand Down Expand Up @@ -142,17 +140,9 @@ export default function(config) {

let {plugins, frameworks, reporters, loaders} = getKarmaConfig(cwd, runCoverage, userConfig)
let testFiles = path.join(cwd, userKarma.tests || DEFAULT_TESTS)
let preprocessors = {[testFiles]: ['webpack', 'sourcemap']}

// Find the node_modules directory containing nwb's dependencies
let nodeModules
if (glob.sync('../node_modules/', {cwd: __dirname}).length > 0) {
// Global installs and npm@2 local installs have a local node_modules dir
nodeModules = path.join(__dirname, '../node_modules')
}
else {
// Otherwise assume an npm@3 local install, with node_modules as the parent
nodeModules = path.join(__dirname, '../../node_modules')
let preprocessors = {
[require.resolve('babel-core/lib/polyfill')]: ['webpack', 'sourcemap'],
[testFiles]: ['webpack', 'sourcemap']
}

let webpackConfig = createWebpackConfig(cwd, {
Expand All @@ -166,7 +156,7 @@ export default function(config) {
'src': path.join(cwd, 'src')
},
// Fall back to resolve test runtime dependencies from nwb's dependencies
fallback: [nodeModules]
fallback: [findNodeModules()]
},
node: {
fs: 'empty'
Expand All @@ -186,7 +176,7 @@ export default function(config) {
]
},
files: [
require.resolve('phantomjs-polyfill/bind-polyfill.js'),
require.resolve('babel-core/lib/polyfill'),
testFiles
],
preprocessors,
Expand Down
14 changes: 9 additions & 5 deletions src/createWebpackConfig.js
Expand Up @@ -17,7 +17,7 @@ import webpack, {optimize} from 'webpack'
import merge from 'webpack-merge'

import debug from './debug'
import {typeOf} from './utils'
import {findNodeModules, typeOf} from './utils'

export let combineLoaders = loaders =>
loaders.map(loader => {
Expand Down Expand Up @@ -234,10 +234,14 @@ export default function createWebpackConfig(cwd, buildConfig, userConfig = {}) {
loaders: createLoaders(server, loaders, userConfig.loaders)
},
plugins: createPlugins(server, cwd, plugins),
resolve: {
extensions: ['', '.web.js', '.js', '.jsx', '.json'],
...resolve
},
resolve: merge({
alias: {
// Alias babel-runtime so it can be found from nwb's dependencies when
// using Babel stage: 0 and optional: ['runtime'] for async/await.
'babel-runtime': path.join(findNodeModules(), 'babel-runtime')
},
extensions: ['', '.web.js', '.js', '.jsx', '.json']
}, resolve),
...otherConfig
}
}
23 changes: 23 additions & 0 deletions src/utils.js
@@ -1,3 +1,26 @@
import path from 'path'

import glob from 'glob'

/**
* Find the node_modules directory containing nwb's dependencies.
*/
export function findNodeModules() {
let nodeModules
if (glob.sync('../node_modules/', {cwd: __dirname}).length > 0) {
// Global installs and npm@2 local installs have a local node_modules dir
nodeModules = path.join(__dirname, '../node_modules')
}
else {
// Otherwise assume an npm@3 local install, with node_modules as the parent
nodeModules = path.join(__dirname, '../../node_modules')
}
return nodeModules
}

/**
* Better typeof.
*/
export function typeOf(o) {
if (Number.isNaN(o)) return 'nan'
return Object.prototype.toString.call(o).slice(8, -1).toLowerCase()
Expand Down

0 comments on commit 4f2e1e0

Please sign in to comment.