diff --git a/CHANGES.md b/CHANGES.md index eee74164..009b6966 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +# 0.26.0 / 2020-10-20 +## Fixes +- Don't fail building when there is .babelrc file. Instead, use .babelrc.build for the temporary config. + + [Babel CLI](https://babeljs.io/docs/en/babel-cli#custom-config-path) allows for `--config-file` option with which you can specify your own config file. Thanks to that, if there is already .babelrc file in the repo, the build can still continue instead of being stopped. + +# MISSING ## Dependencies - @babel/cli: v7.8.4 → [v7.10.3](https://github.com/babel/babel/blob/master/CHANGELOG.md#v7102-2020-05-30) diff --git a/package.json b/package.json index bfbb76e8..9adb9b5a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "nwb", "description": "A toolkit for React, Preact & Inferno apps, React libraries and other npm modules for the web, with no configuration (until you need it)", - "version": "0.25.2", + "version": "0.26.0", "license": "MIT", "author": "Jonny Buchanan ", "bin": { diff --git a/src/moduleBuild.js b/src/moduleBuild.js index a9d1f8c0..c8aef7d2 100644 --- a/src/moduleBuild.js +++ b/src/moduleBuild.js @@ -10,7 +10,6 @@ import cleanModule from './commands/clean-module' import {getPluginConfig, getUserConfig} from './config' import createBabelConfig from './createBabelConfig' import debug from './debug' -import {UserError} from './errors' import {deepToString, formatPackageName} from './utils' import webpackBuild from './webpackBuild' import {createBanner, createExternals, logGzippedFileSizes} from './webpackUtils' @@ -23,10 +22,12 @@ const DEFAULT_BABEL_IGNORE_CONFIG = [ '**/__tests__/' ] +const DEFAULT_BABEL_CONFIG_FILE = '.babelrc' + /** * Run Babel with generated config written to a temporary .babelrc. */ -function runBabel(name, {copyFiles, outDir, src}, buildBabelConfig, userConfig, cb) { +function runBabel(name, {copyFiles, outDir, src, configFileName}, buildBabelConfig, userConfig, cb) { let babelConfig = createBabelConfig(buildBabelConfig, userConfig.babel, userConfig.path) babelConfig.ignore = DEFAULT_BABEL_IGNORE_CONFIG @@ -37,7 +38,11 @@ function runBabel(name, {copyFiles, outDir, src}, buildBabelConfig, userConfig, args.push('--copy-files', '--no-copy-ignored') } - fs.writeFile('.babelrc', JSON.stringify(babelConfig, null, 2), (err) => { + if (configFileName !== DEFAULT_BABEL_CONFIG_FILE) { + args.push('--config-file', path.resolve(configFileName)) + } + + fs.writeFile(configFileName, JSON.stringify(babelConfig, null, 2), (err) => { if (err) return cb(err) let spinner = ora(`Creating ${name} build`).start() let babel = spawn(require.resolve('.bin/babel'), args, {stdio: 'inherit'}) @@ -50,7 +55,7 @@ function runBabel(name, {copyFiles, outDir, src}, buildBabelConfig, userConfig, else { spinner.succeed() } - fs.unlink('.babelrc', (unlinkError) => { + fs.unlink(configFileName, (unlinkError) => { cb(babelError || unlinkError) }) }) @@ -114,12 +119,16 @@ function buildUMD(args, buildConfig, userConfig, cb) { } export default function moduleBuild(args, buildConfig = {}, cb) { - // XXX Babel doesn't support passing the path to a babelrc file any more - if (fs.existsSync('.babelrc')) { - throw new UserError( - 'Unable to build the module as there is a .babelrc in your project\n' + - 'nwb needs to write a temporary .babelrc to configure the build' + let configFileName = DEFAULT_BABEL_CONFIG_FILE + + if (fs.existsSync(configFileName)) { + console.info( + `There is a ${configFileName} in your project ` + + `nwb needs to write a temporary ${configFileName} to configure the build, ` + + `will use ${configFileName}.build instead` ) + + configFileName += '.build' } if (!process.env.NODE_ENV) { @@ -131,6 +140,7 @@ export default function moduleBuild(args, buildConfig = {}, cb) { let babelCliOptions = { copyFiles: !!args['copy-files'], src: path.resolve('src'), + configFileName } let tasks = [(cb) => cleanModule(args, cb)]