diff --git a/CHANGES.md b/CHANGES.md index 3fc9bf0f..8a3547c3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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. diff --git a/package.json b/package.json index e65476f1..3e648a15 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/createKarmaConfig.js b/src/createKarmaConfig.js index b53e6230..0645cdcf 100644 --- a/src/createKarmaConfig.js +++ b/src/createKarmaConfig.js @@ -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' @@ -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, { @@ -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' @@ -186,7 +176,7 @@ export default function(config) { ] }, files: [ - require.resolve('phantomjs-polyfill/bind-polyfill.js'), + require.resolve('babel-core/lib/polyfill'), testFiles ], preprocessors, diff --git a/src/createWebpackConfig.js b/src/createWebpackConfig.js index 32c22095..5c900089 100644 --- a/src/createWebpackConfig.js +++ b/src/createWebpackConfig.js @@ -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 => { @@ -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 } } diff --git a/src/utils.js b/src/utils.js index 22423a4e..c7d3bfa5 100644 --- a/src/utils.js +++ b/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()