Refactoring, env, closing a bunch of issues#53
Refactoring, env, closing a bunch of issues#53paulmillr merged 28 commits intobabel:masterfrom denysdovhan:fix-52-and-41
Conversation
index.js
Outdated
|
|
||
| try { | ||
| const babelrc = fs.existsSync(babelrcPath); | ||
| const packageConfig = JSON.parse(fs.readFileSync(packagePath)); |
index.js
Outdated
| if (!opts.presets) opts.presets = ['latest']; | ||
| if (opts.presets.length === 0) delete opts.presets; | ||
|
|
||
| // Include 'latest' preset only if: |
There was a problem hiding this comment.
Comments are too length and extra. Code is pretty self-explanatory.
There was a problem hiding this comment.
Maybe better to leave a link to related issues? Just an reminder why this code shouldn't be removed.
index.js
Outdated
| // * there's no .babelrc file in root directory | ||
| // * there's no 'babel' field in package.json | ||
| if (!opts.presets) { | ||
| const babelrcPath = path.resolve(config.paths.root, '.babelrc'); |
There was a problem hiding this comment.
Extensions? Parent dirs?
There was a problem hiding this comment.
Yeah, thought about it.
I don't want to duplicate whole resolution logic from Babel. Maybe we could reuse it somehow?
There was a problem hiding this comment.
Not sure, it is not in the public API afaik, but it may be worth exposing.
However, I don't see it blocking from merging this PR. Some time later.
There was a problem hiding this comment.
I'm gonna dig a bit in Babel's sources. I'll keep you updated.
|
One more thing: |
index.js
Outdated
| return error; | ||
| }; | ||
|
|
||
| const lookup = (where, filename) => { |
There was a problem hiding this comment.
@shvaikalesh here's a little bit complex resolution. What do you think?
|
Generally I think the Babel team as a whole has mixed feelings about enabling plugins/presets by default like this FYI, but it seems like that has already been released as a feature, right? Given that, the currently-used approach (in babel-loader and babel-register) to resolving the config is the following: It's an ugly API but please do not try to hardcode this. If we fix bugs or add new config methods like the newly-landed for 7.x |
|
@shvaikalesh reasonable notice from Babel's Slack: Actually, this PR could be easily resolved by removing these lines: -if (!opts.presets) {
- opts.presets = ['latest'];
- // ['env', opts.env]
-}Unfortunately, it would break backward compat. |
|
I don't understand why "having defaults" is a bad idea. Brunch is all about simplicity and no bullshit. We don't want users to write configs when the program can think for them instead. |
|
@paulmillr okay. Anyway, I'm gonna find a better solutions. Will update my PR soon. @loganfsmyth don't we run the risk using some kind of internal APIs? Probably, you would like to change Babel's internal API and then we will find ourselves in the situation when our users get broken builds. |
I'm not sure what you mean? The point of the |
|
Agreed with Paul here. We should have cool defaults, like |
@loganfsmyth |
|
It definitely won't break in 6.x and I'm planning to specifically leave a dummy class of It's used by |
test.js
Outdated
| }); | ||
| return plugin.compile({data: content, path: 'file.js'}) | ||
| .then(result => result.data.should.contain(expected)) | ||
| .catch(should.not.throw); |
test.js
Outdated
| }, error => assert(!error)); | ||
| return plugin.compile({data: content, path: 'file.js'}) | ||
| .then(result => result.data.should.contain(expected)) | ||
| .catch(should.not.throw); |
test.js
Outdated
| }, error => assert(!error)); | ||
| return plugin.compile({data: content, path: 'file.js'}) | ||
| .then(result => result.data.should.contain(expected)) | ||
| .catch(should.not.throw); |
test.js
Outdated
|
|
||
| return plugin.compile({data: content, path: 'file.js'}) | ||
| .then(result => result.data.should.contain(expected)) | ||
| .catch(should.not.throw); |
test.js
Outdated
|
|
||
| return plugin.compile({data: content, path: 'file.js'}) | ||
| .then(result => result.data.should.contain(expected)) | ||
| .catch(should.not.throw); |
test.js
Outdated
| it('should properly link to source file in source maps', () => | ||
| sourceMapPlugin.compile({data: content, path}) | ||
| .then(result => { | ||
| JSON.parse(result.map).should.not.throw; |
| ); | ||
|
|
||
| it('should properly link to source file in source maps', () => | ||
| sourceMapPlugin.compile({data: content, path}) |
test.js
Outdated
| JSON.parse(result.map).should.not.throw; | ||
| JSON.parse(result.map).sources.should.contain(path); | ||
| }) | ||
| .catch(should.not.throw) |
test.js
Outdated
| }, error => assert(!error)); | ||
| return plugin.compile({data: content, path: 'file.js'}) | ||
| .then(result => JSON.parse(result.map).should.not.throw) | ||
| .catch(should.not.throw); |
test.js
Outdated
| done(); | ||
| }, error => assert(!error)); | ||
| return plugin.compile({data: content, path: 'file.js'}) | ||
| .then(result => JSON.parse(result.map).should.not.throw) |
There was a problem hiding this comment.
should.not.throw is extra
test.js
Outdated
| }, error => assert(!error)); | ||
| return plugin.compile({data: content, path: 'vendor/file.js'}) | ||
| .then(result => result.data.should.be.equal(content)) | ||
| .catch(should.not.throw); |
test.js
Outdated
| it('should be an object', function() { | ||
| assert(plugin); | ||
| }); | ||
| it('should have #compile method', () => |
There was a problem hiding this comment.
why return Assertion to mocha?
There was a problem hiding this comment.
Does Mocha care about what is returned?
Anyway, yeah, that's not a good practice. Gonna add curly brackets around it.
|
Now @shvaikalesh @paulmillr what do you think about |
index.js
Outdated
| try { | ||
| const pkgPath = path.resolve(pkgFile); | ||
| const isProduction = process.env.NODE_ENV === 'production'; | ||
| const isUglify = 'uglify-js-brunch' in require(pkgPath).devDependencies; |
There was a problem hiding this comment.
require('uglify-js-brunch')
|
Done, I think. Can be merged. |
index.js
Outdated
| if (!this.options.presets) { | ||
| const babelConfig = new babel.OptionManager().init(this.options); | ||
| const hasConfig = | ||
| babelConfig.presets && babelConfig.presets.length > 0 || |
There was a problem hiding this comment.
JS is not Ruby. 0 is falsy.
There was a problem hiding this comment.
JS is not Ruby. 0 is falsy.
Correct me if I'm wrong, and it's not immediately clear, but this should work because @denysdovhan is checking length > 0.
I suggest wrapping the comparison check in parens so it is more obvious that you're using a comparison operator.
const hasConfig =
babelConfig.presets && (babelConfig.presets.length > 0) ||
babelConfig.plugins && (babelConfig.plugins.length > 0);There was a problem hiding this comment.
@millerized @shvaikalesh is right. Doesn't matter. This should work too:
const hasConfig =
babelConfig.presets && babelConfig.presets.length ||
babelConfig.plugins && babelConfig.plugins.length;|
Hi @denysdovhan. I would offer to help contribute and get this past the finish line, but it looks like you are almost there. I am looking forward to using brunch with |

Aims to fix #52 and #41.