Skip to content
This repository has been archived by the owner on Sep 25, 2019. It is now read-only.

Commit

Permalink
Merge pull request #61 from pirelenito/upgrade-to-babel-6
Browse files Browse the repository at this point in the history
Upgrade to babel 6
  • Loading branch information
pirelenito committed Mar 15, 2016
2 parents 0dfe28a + a30b7bc commit df38406
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"stage": 0
"presets": ["es2015", "stage-0"]
}
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
template
lib
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
lib
25 changes: 19 additions & 6 deletions bin/sagui
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
#!/usr/bin/env node

try {
/**
* Try loading the compiled code.
*/
require('../lib/cli').default(process.argv)
} catch (e) {
/**
* If the compiled code is not available,
* use the babel-registery and load from source.
*/
try {
require('babel-register')({
only: /(sagui\/src)/
})

require('babel/register')({
only: /(sagui\/src)/
})


require('../src/cli')(process.argv)
require('../src/cli').default(process.argv)
} catch (e) {
throw e
}
}
37 changes: 26 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,21 @@
"bin": {
"sagui": "./bin/sagui"
},
"main": "src/index.js",
"main": "lib/index.js",
"files": [
"bin",
"lib",
"template",
".eslintrc"
],
"scripts": {
"build": "rm -rf lib && babel src --out-dir lib --ignore *.spec.js",
"test": "npm run test:lint && npm run test:unit",
"test:lint": "eslint .",
"test:unit": "mocha --compilers js:babel/register --recursive --reporter spec ./src",
"test:unit": "mocha --compilers js:babel-register --recursive --reporter spec ./src",
"test:unit-watch": "npm run test:unit -- --watch",
"test:integration": "./bin/test-integration.sh",
"prepublish": "npm prune && npm test",
"test:integration": "npm run build && ./bin/test-integration.sh",
"prepublish": "not-in-install && npm prune && npm test && npm run build || in-install",
"postinstall": "./bin/sagui install"
},
"repository": {
Expand All @@ -27,12 +34,16 @@
},
"homepage": "https://github.com/pirelenito/sagui#readme",
"dependencies": {
"babel": "^5.8.23",
"babel-core": "^5.0.0",
"babel-eslint": "^4.1.3",
"babel-loader": "^5.1.2",
"babel-plugin-react-transform": "^1.1.1",
"babel-runtime": "^5.8.25",
"babel-core": "^6.4.0",
"babel-eslint": "^5.0.0",
"babel-loader": "^6.2.1",
"babel-plugin-react-transform": "^2.0.2",
"babel-plugin-transform-es2015-modules-commonjs": "^6.7.0",
"babel-plugin-transform-runtime": "^6.4.3",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"babel-register": "^6.7.2",
"chai": "^3.3.0",
"chalk": "^1.1.1",
"commander": "^2.8.1",
Expand Down Expand Up @@ -60,7 +71,7 @@
"phantomjs-prebuilt": "^2.1.4",
"postcss-loader": "^0.8.0",
"postcss-modules-values": "^1.1.1",
"react-transform-hmr": "^1.0.0",
"react-transform-hmr": "^1.0.4",
"resolve-url-loader": "^1.3.0",
"rimraf": "^2.4.3",
"sass-loader": "^3.0.0",
Expand All @@ -72,5 +83,9 @@
"webpack-dev-middleware": "^1.2.0",
"webpack-hot-middleware": "^2.0.0",
"webpack-merge": "^0.7.3"
},
"devDependencies": {
"babel-cli": "^6.6.5",
"in-publish": "^2.0.0"
}
}
16 changes: 8 additions & 8 deletions src/configure/webpack/plugins/archetype-library.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { join } from 'path'
import { expect } from 'chai'
import { configure } from './archetype-library'
import plugin from './archetype-library'

const saguiPath = join(__dirname, '../../../../')
const projectPath = join(saguiPath, 'spec/fixtures/library-project')
Expand All @@ -14,33 +14,33 @@ describe('configure webpack library', function () {
}

it('should have a single entry pointing to index.js', function () {
const webpackConfig = configure(baseConfiguration)
const webpackConfig = plugin.configure(baseConfiguration)
expect(webpackConfig.entry).eql('./index.js')
})

it('should have the default exporting target of commonjs2 (module.exports = xxx)', function () {
const webpackConfig = configure(baseConfiguration)
const webpackConfig = plugin.configure(baseConfiguration)
expect(webpackConfig.output.libraryTarget).eql('commonjs2')
})

it('should NOT SET the exporting target if buildTarget is test (a browser wont understand commonjs modules)', function () {
const webpackConfig = configure({ ...baseConfiguration, buildTarget: 'test' })
const webpackConfig = plugin.configure({ ...baseConfiguration, buildTarget: 'test' })
expect(webpackConfig.output.libraryTarget).undefined
})

it('should have the filename as index.js', function () {
const webpackConfig = configure(baseConfiguration)
const webpackConfig = plugin.configure(baseConfiguration)
expect(webpackConfig.output.filename).eql('index.js')
})

it('should have the output path configured as the dist folder', function () {
const webpackConfig = configure(baseConfiguration)
const webpackConfig = plugin.configure(baseConfiguration)
expect(webpackConfig.output.path).eql(join(projectPath, 'dist'))
})

describe('externals', function () {
it('should infer the externals based on the packgage.json peerDependencies', function () {
const webpackConfig = configure(baseConfiguration)
const webpackConfig = plugin.configure(baseConfiguration)
expect(webpackConfig.externals).eql(['react', 'react-dom'])
})

Expand All @@ -50,7 +50,7 @@ describe('configure webpack library', function () {
})

it('should have an empty externals if the packgage.json does not have a peerDependencies', function () {
const webpackConfig = configure({ ...baseConfiguration, projectPath: projectWithoutPeerDependenciesPath })
const webpackConfig = plugin.configure({ ...baseConfiguration, projectPath: projectWithoutPeerDependenciesPath })
expect(webpackConfig.externals).eql([])
})
})
Expand Down
26 changes: 13 additions & 13 deletions src/configure/webpack/plugins/archetype-pages.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@ import HtmlWebpackPlugin from 'html-webpack-plugin'
import { optimize } from 'webpack'
import { expect } from 'chai'

import { configure } from './archetype-pages'
import plugin from './archetype-pages'

const projectPath = '/tmp/projec-path'

describe('configure webpack pages', function () {
describe('undefined pages', function () {
it('should return an empty configuration', function () {
const webpackConfig = configure({})
const webpackConfig = plugin.configure({})
expect(webpackConfig).eql({})
})
})

describe('empty pages', function () {
it('should return an empty configuration', function () {
const webpackConfig = configure({ pages: [] })
const webpackConfig = plugin.configure({ pages: [] })
expect(webpackConfig).eql({})
})
})
Expand All @@ -25,20 +25,20 @@ describe('configure webpack pages', function () {
const baseConfig = { pages: ['index'], projectPath }

it('should have the output path configured as the dist folder', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)
expect(webpackConfig.output.path).eql('/tmp/projec-path/dist')
})

it('should have the entrypoints setup with the index', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)

expect(webpackConfig.entry).eql({
index: ['./index']
})
})

it('should have a plugin seting up the HTML template', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)

const html = webpackConfig.plugins.filter(plugin => plugin instanceof HtmlWebpackPlugin)
expect(html.length).equal(1)
Expand All @@ -51,17 +51,17 @@ describe('configure webpack pages', function () {
})

it('should setup the output filename of entrypoints based on the name of the page and hash', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)
expect(webpackConfig.output.filename).eql('[name]-[hash].js')
})

it('should setup the output filename of other files based on their name and hash', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)
expect(webpackConfig.output.chunkFilename).eql('[name]-[hash].chunk.js')
})

it('should NOT have the CommonsChunkPlugin enabled (not needed)', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)

const commons = webpackConfig.plugins.filter(plugin => plugin instanceof optimize.CommonsChunkPlugin)
expect(commons.length).equal(0)
Expand All @@ -72,7 +72,7 @@ describe('configure webpack pages', function () {
const baseConfig = { pages: ['index', 'demo'], projectPath }

it('should have two distinct entrypoints', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)

expect(webpackConfig.entry).eql({
index: ['./index'],
Expand All @@ -81,7 +81,7 @@ describe('configure webpack pages', function () {
})

it('should have a plugin seting up the HTML template for each chunk', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)

const html = webpackConfig.plugins.filter(plugin => plugin instanceof HtmlWebpackPlugin)
expect(html.length).equal(2)
Expand All @@ -98,7 +98,7 @@ describe('configure webpack pages', function () {
})

it('should have the CommonsChunkPlugin enabled', function () {
const webpackConfig = configure(baseConfig)
const webpackConfig = plugin.configure(baseConfig)

const commons = webpackConfig.plugins.filter(plugin => plugin instanceof optimize.CommonsChunkPlugin)
expect(commons.length).equal(1)
Expand All @@ -107,7 +107,7 @@ describe('configure webpack pages', function () {
// Karma has an issue with the CommonsChunk plugin
// see: https://github.com/webpack/karma-webpack/issues/24
it('should NOT have the CommonsChunkPlugin enabled if buildTarget is test (breaks Karma)', function () {
const webpackConfig = configure({ ...baseConfig, buildTarget: 'test' })
const webpackConfig = plugin.configure({ ...baseConfig, buildTarget: 'test' })

const commons = webpackConfig.plugins.filter(plugin => plugin instanceof optimize.CommonsChunkPlugin)
expect(commons.length).equal(0)
Expand Down
6 changes: 4 additions & 2 deletions src/configure/webpack/plugins/babel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import reactTransform from 'babel-plugin-react-transform'
import es2015 from 'babel-preset-es2015'
import stage0 from 'babel-preset-stage-0'
import react from 'babel-preset-react'

export default {
name: 'webpack-babel',
Expand All @@ -20,8 +23,7 @@ export default {

return {
babel: {
optional: ['runtime'],
stage: 0,
presets: [es2015, stage0, react],
env: buildTarget === 'develop' ? hmrEnv : {}
},

Expand Down
6 changes: 3 additions & 3 deletions src/configure/webpack/plugins/base.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ import { expect } from 'chai'
import { join } from 'path'
import { HotModuleReplacementPlugin, optimize } from 'webpack'

import { configure } from './base'
import plugin from './base'

const saguiPath = join(__dirname, '../../../../')
const projectPath = join(saguiPath, 'spec/fixtures/simple-project')

describe('configure webpack base', function () {
describe('targets', function () {
it('should have the UglifyJsPlugin enabled while distributing', function () {
const config = configure({ projectPath, saguiPath, buildTarget: 'dist' })
const config = plugin.configure({ projectPath, saguiPath, buildTarget: 'dist' })

const commons = config.plugins.filter(plugin => plugin instanceof optimize.UglifyJsPlugin)
expect(commons.length).equal(1)
})

it('should have the HotModuleReplacementPlugin enabled while developing', function () {
const config = configure({ projectPath, saguiPath, buildTarget: 'develop' })
const config = plugin.configure({ projectPath, saguiPath, buildTarget: 'develop' })

const commons = config.plugins.filter(plugin => plugin instanceof HotModuleReplacementPlugin)
expect(commons.length).equal(1)
Expand Down
4 changes: 2 additions & 2 deletions src/configure/webpack/plugins/json.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { expect } from 'chai'

import { configure } from './json'
import plugin from './json'

describe('configure webpack json', function () {
it('should have a JSON loader', function () {
const webpackConfig = configure({})
const webpackConfig = plugin.configure({})
const loader = webpackConfig.module.loaders.find(loader => loader.loader === 'json-loader')
expect(loader.test).eql(/\.(json)$/)
})
Expand Down

0 comments on commit df38406

Please sign in to comment.