From ad6ebdf444a71f2e3aa7dfd594416f52a9e7b161 Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 11:45:34 +0100 Subject: [PATCH 01/10] Upgrade to Babel 6 --- .babelrc | 2 +- package.json | 21 +++++++++++++-------- src/configure/webpack/plugins/babel.js | 6 ++++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/.babelrc b/.babelrc index b0b9a96..eaf3238 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,3 @@ { - "stage": 0 + "presets": ["es2015", "stage-0"] } diff --git a/package.json b/package.json index 7dc6a5c..af7d937 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "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", @@ -27,12 +27,17 @@ }, "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-cli": "^6.6.5", + "babel-core": "^6.4.0", + "babel-eslint": "^4.1.8", + "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", @@ -60,7 +65,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", diff --git a/src/configure/webpack/plugins/babel.js b/src/configure/webpack/plugins/babel.js index eb43cb2..c65c021 100644 --- a/src/configure/webpack/plugins/babel.js +++ b/src/configure/webpack/plugins/babel.js @@ -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', @@ -20,8 +23,7 @@ export default { return { babel: { - optional: ['runtime'], - stage: 0, + presets: [es2015, stage0, react], env: buildTarget === 'develop' ? hmrEnv : {} }, From d5caee6344d1dbf762953d7dc066f2e6e3a4479e Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 11:46:25 +0100 Subject: [PATCH 02/10] =?UTF-8?q?Fix=20all=20tests=20broken=20after=20chan?= =?UTF-8?q?ge=20in=20Babel=20=E2=80=9Cdefault=E2=80=9D=20exports?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit see: https://phabricator.babeljs.io/T2212 --- .../webpack/plugins/archetype-library.spec.js | 16 ++++++------ .../webpack/plugins/archetype-pages.spec.js | 26 +++++++++---------- src/configure/webpack/plugins/base.spec.js | 6 ++--- src/configure/webpack/plugins/json.spec.js | 4 +-- 4 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/configure/webpack/plugins/archetype-library.spec.js b/src/configure/webpack/plugins/archetype-library.spec.js index 438c1dc..84ee3c5 100644 --- a/src/configure/webpack/plugins/archetype-library.spec.js +++ b/src/configure/webpack/plugins/archetype-library.spec.js @@ -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') @@ -14,38 +14,38 @@ 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']) }) 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([]) }) }) diff --git a/src/configure/webpack/plugins/archetype-pages.spec.js b/src/configure/webpack/plugins/archetype-pages.spec.js index 23f1d55..d0d26f1 100644 --- a/src/configure/webpack/plugins/archetype-pages.spec.js +++ b/src/configure/webpack/plugins/archetype-pages.spec.js @@ -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({}) }) }) @@ -25,12 +25,12 @@ 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'] @@ -38,7 +38,7 @@ describe('configure webpack pages', function () { }) 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) @@ -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) @@ -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'], @@ -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) @@ -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) @@ -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) diff --git a/src/configure/webpack/plugins/base.spec.js b/src/configure/webpack/plugins/base.spec.js index 6f5bfeb..ef847d0 100644 --- a/src/configure/webpack/plugins/base.spec.js +++ b/src/configure/webpack/plugins/base.spec.js @@ -2,7 +2,7 @@ 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') @@ -10,14 +10,14 @@ 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) diff --git a/src/configure/webpack/plugins/json.spec.js b/src/configure/webpack/plugins/json.spec.js index 26e3567..60bcad3 100644 --- a/src/configure/webpack/plugins/json.spec.js +++ b/src/configure/webpack/plugins/json.spec.js @@ -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)$/) }) From 70ee50c9d985eba72f312a2db1f9fdb9449d861d Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 11:48:40 +0100 Subject: [PATCH 03/10] Publish built version of Sagui, removing babel-register dependency in runtime --- .eslintignore | 1 + .gitignore | 1 + bin/sagui | 16 +++++++++------- package.json | 10 ++++++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.eslintignore b/.eslintignore index 3236cba..805af30 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1 +1,2 @@ template +lib diff --git a/.gitignore b/.gitignore index 3c3629e..491fc35 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +lib diff --git a/bin/sagui b/bin/sagui index 78e5161..ea44db4 100755 --- a/bin/sagui +++ b/bin/sagui @@ -1,9 +1,11 @@ #!/usr/bin/env node - -require('babel/register')({ - only: /(sagui\/src)/ -}) - - -require('../src/cli')(process.argv) +if (process.env.SAGUI_LINK === 'true') { + require('babel-register')({ + only: /(sagui\/src)/ + }) + + require('../src/cli').default(process.argv) +} else { + require('../lib/cli').default(process.argv) +} diff --git a/package.json b/package.json index af7d937..e7ae84d 100644 --- a/package.json +++ b/package.json @@ -6,14 +6,20 @@ "bin": { "sagui": "./bin/sagui" }, - "main": "src/index.js", + "main": "lib/index.js", + "files": [ + "bin", + "lib", + "template" + ], "scripts": { + "build": "babel src --out-dir lib", "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-watch": "npm run test:unit -- --watch", "test:integration": "./bin/test-integration.sh", - "prepublish": "npm prune && npm test", + "prepublish": "npm prune && npm test && npm run build", "postinstall": "./bin/sagui install" }, "repository": { From d7b71240431003c61e24221222285f035fc2688b Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 11:50:22 +0100 Subject: [PATCH 04/10] Babel-cli can be a development dependency It is only used while publishing a new version --- package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index e7ae84d..4ef96e1 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,6 @@ }, "homepage": "https://github.com/pirelenito/sagui#readme", "dependencies": { - "babel-cli": "^6.6.5", "babel-core": "^6.4.0", "babel-eslint": "^4.1.8", "babel-loader": "^6.2.1", @@ -83,5 +82,8 @@ "webpack-dev-middleware": "^1.2.0", "webpack-hot-middleware": "^2.0.0", "webpack-merge": "^0.7.3" + }, + "devDependencies": { + "babel-cli": "^6.6.5" } } From 593d3fa2a2dc57d5a04c33af3a024bcacadbd445 Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 13:02:26 +0100 Subject: [PATCH 05/10] Build before running the integration test --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4ef96e1..c6c14cb 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "test:lint": "eslint .", "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", + "test:integration": "npm run build && ./bin/test-integration.sh", "prepublish": "npm prune && npm test && npm run build", "postinstall": "./bin/sagui install" }, From 08282e19b7f6038c59ab928038ed175001eaac27 Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 13:04:54 +0100 Subject: [PATCH 06/10] =?UTF-8?q?Don=E2=80=99t=20build=20spec=20files?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c6c14cb..555c537 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "template" ], "scripts": { - "build": "babel src --out-dir lib", + "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", From bd319b53b9c50cc9685229978988650f8a90d59a Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 13:14:30 +0100 Subject: [PATCH 07/10] Sagui binary first tries to load compiled code and then fallbacks to the source --- bin/sagui | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/bin/sagui b/bin/sagui index ea44db4..4c4e852 100755 --- a/bin/sagui +++ b/bin/sagui @@ -1,11 +1,22 @@ #!/usr/bin/env node -if (process.env.SAGUI_LINK === 'true') { - require('babel-register')({ - only: /(sagui\/src)/ - }) - - require('../src/cli').default(process.argv) -} else { +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('../src/cli').default(process.argv) + } catch (e) { + throw e + } } From bd021e30374bb3b5d773846291f05494cb8026b4 Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 13:28:07 +0100 Subject: [PATCH 08/10] Update babel-eslint to 5.x --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 555c537..e6f237a 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "homepage": "https://github.com/pirelenito/sagui#readme", "dependencies": { "babel-core": "^6.4.0", - "babel-eslint": "^4.1.8", + "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", From cf99bfaea53f41fcbbcc41838a13f4da5cafefec Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 13:35:25 +0100 Subject: [PATCH 09/10] Change prepublish to not run on `npm install` More information: https://github.com/iarna/in-publish --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index e6f237a..914f3fb 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "test:unit": "mocha --compilers js:babel-register --recursive --reporter spec ./src", "test:unit-watch": "npm run test:unit -- --watch", "test:integration": "npm run build && ./bin/test-integration.sh", - "prepublish": "npm prune && npm test && npm run build", + "prepublish": "not-in-install && npm prune && npm test && npm run build || in-install", "postinstall": "./bin/sagui install" }, "repository": { @@ -84,6 +84,7 @@ "webpack-merge": "^0.7.3" }, "devDependencies": { - "babel-cli": "^6.6.5" + "babel-cli": "^6.6.5", + "in-publish": "^2.0.0" } } From a30b7bcd63b9f1ba447b4260ba43745da1809fdd Mon Sep 17 00:00:00 2001 From: Paulo Ragonha Date: Tue, 15 Mar 2016 13:45:52 +0100 Subject: [PATCH 10/10] Adds missing .eslintrc file on publishing to NPM --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 914f3fb..beb69e0 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "files": [ "bin", "lib", - "template" + "template", + ".eslintrc" ], "scripts": { "build": "rm -rf lib && babel src --out-dir lib --ignore *.spec.js",