Skip to content

Commit 1167e55

Browse files
authored
Merge pull request #173 from halfzebra/upgrade-dependencies-and-introduce-unexpectedjs
Upgrade dependencies and introduce unexpectedjs
2 parents fba0117 + 094920a commit 1167e55

15 files changed

+1014
-659
lines changed

config/env.js

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,23 @@ process.env.NODE_PATH = (process.env.NODE_PATH || '')
5858
const ELM_APP = /^ELM_APP_/i;
5959

6060
function getClientEnvironment(publicUrl) {
61-
const raw = Object.keys(process.env).filter(key => ELM_APP.test(key)).reduce((
62-
env,
63-
key
64-
) => {
65-
env[key] = process.env[key];
66-
return env;
67-
}, {
68-
// Useful for determining whether we’re running in production mode.
69-
NODE_ENV: process.env.NODE_ENV || 'development',
70-
// Useful for resolving the correct path to static assets in `public`.
71-
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
72-
// This should only be used as an escape hatch. Normally you would put
73-
// images into the `src` and `import` them in code to get their paths.
74-
PUBLIC_URL: publicUrl
75-
});
61+
const raw = Object.keys(process.env)
62+
.filter(key => ELM_APP.test(key))
63+
.reduce(
64+
(env, key) => {
65+
env[key] = process.env[key];
66+
return env;
67+
},
68+
{
69+
// Useful for determining whether we’re running in production mode.
70+
NODE_ENV: process.env.NODE_ENV || 'development',
71+
// Useful for resolving the correct path to static assets in `public`.
72+
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
73+
// This should only be used as an escape hatch. Normally you would put
74+
// images into the `src` and `import` them in code to get their paths.
75+
PUBLIC_URL: publicUrl
76+
}
77+
);
7678
// Stringify all values so we can feed into Webpack DefinePlugin
7779
const stringified = {
7880
'process.env': Object.keys(raw).reduce((env, key) => {

config/webpack.config.dev.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,24 @@ module.exports = {
7474
exclude: [/elm-stuff/, /node_modules/],
7575
loader: require.resolve('babel-loader'),
7676
query: {
77+
// Latest stable ECMAScript features
7778
presets: [
78-
require.resolve('babel-preset-es2015'),
79-
require.resolve('babel-preset-es2016'),
80-
require.resolve('babel-preset-es2017')
79+
[
80+
require.resolve('babel-preset-env'),
81+
{
82+
targets: {
83+
// React parses on ie 9, so we should too
84+
ie: 9,
85+
// We currently minify with uglify
86+
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
87+
uglify: true
88+
},
89+
// Disable polyfill transforms
90+
useBuiltIns: false,
91+
// Do not transform modules to CJS
92+
modules: false
93+
}
94+
]
8195
]
8296
}
8397
},

config/webpack.config.prod.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,24 @@ module.exports = {
7171
exclude: [/elm-stuff/, /node_modules/],
7272
loader: require.resolve('babel-loader'),
7373
query: {
74+
// Latest stable ECMAScript features
7475
presets: [
75-
require.resolve('babel-preset-es2015'),
76-
require.resolve('babel-preset-es2016'),
77-
require.resolve('babel-preset-es2017')
76+
[
77+
require.resolve('babel-preset-env'),
78+
{
79+
targets: {
80+
// React parses on ie 9, so we should too
81+
ie: 9,
82+
// We currently minify with uglify
83+
// Remove after https://github.com/mishoo/UglifyJS2/issues/448
84+
uglify: true
85+
},
86+
// Disable polyfill transforms
87+
useBuiltIns: false,
88+
// Do not transform modules to CJS
89+
modules: false
90+
}
91+
]
7892
]
7993
}
8094
},
@@ -226,7 +240,7 @@ module.exports = {
226240
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
227241
navigateFallbackWhitelist: [/^(?!\/__).*/],
228242
// Don't precache sourcemaps (they're large) and build asset manifest:
229-
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
230-
}),
243+
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/]
244+
})
231245
]
232246
};

config/webpackDevServer.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const errorOverlayMiddleware = require('react-error-overlay/middleware');
3+
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
44
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
55
const config = require('./webpack.config.dev');
66
const paths = require('./paths');

package.json

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,17 @@
1818
},
1919
"dependencies": {
2020
"assets-webpack-plugin": "^3.5.1",
21-
"autoprefixer": "^7.1.2",
21+
"autoprefixer": "^7.1.4",
2222
"babel-cli": "^6.26.0",
2323
"babel-core": "^6.26.0",
2424
"babel-loader": "^7.1.2",
25-
"babel-preset-es2015": "^6.24.1",
26-
"babel-preset-es2016": "^6.24.1",
27-
"babel-preset-es2017": "^6.24.1",
28-
"chalk": "^2.0.1",
25+
"babel-preset-env": "^1.6.0",
26+
"chalk": "^2.1.0",
2927
"clean-webpack-plugin": "^0.1.16",
3028
"cli-table": "0.3.1",
3129
"connect-history-api-fallback": "^1.3.0",
3230
"cross-spawn": "^5.1.0",
33-
"css-loader": "^0.28.5",
31+
"css-loader": "^0.28.7",
3432
"dotenv": "^4.0.0",
3533
"elm": "^0.18.0",
3634
"elm-hot-loader": "0.5.4",
@@ -44,29 +42,29 @@
4442
"minimist": "1.2.0",
4543
"postcss-loader": "^2.0.5",
4644
"prompt": "1.0.0",
47-
"react-dev-utils": "^3.1.1",
48-
"react-error-overlay": "^1.0.10",
45+
"react-dev-utils": "^4.0.1",
46+
"react-error-overlay": "^2.0.1",
4947
"string-replace-loader": "^1.3.0",
5048
"style-loader": "^0.18.1",
5149
"sw-precache-webpack-plugin": "^0.11.4",
5250
"url-loader": "^0.5.9",
53-
"webpack": "^3.5.5",
54-
"webpack-dev-server": "^2.7.1"
51+
"webpack": "^3.5.6",
52+
"webpack-dev-server": "^2.8.1"
5553
},
5654
"devDependencies": {
57-
"babel-eslint": "^7.2.3",
58-
"chai": "^4.1.0",
55+
"babel-eslint": "^8.0.0",
5956
"commitizen": "^2.9.6",
6057
"cz-conventional-changelog": "^2.0.0",
6158
"dir-compare": "^1.3.0",
62-
"eslint": "^4.3.0",
63-
"eslint-plugin-prettier": "^2.1.2",
59+
"eslint": "^4.6.1",
60+
"eslint-plugin-prettier": "^2.2.0",
6461
"husky": "^0.14.3",
65-
"mocha": "^3.5.0",
62+
"mocha": "^3.5.2",
6663
"nightmare": "^2.10.0",
67-
"prettier": "^1.5.3",
64+
"prettier": "^1.7.0",
6865
"rimraf": "^2.5.4",
69-
"semantic-release": "^6.3.2"
66+
"semantic-release": "^7.0.2",
67+
"unexpected": "^10.35.0"
7068
},
7169
"engines": {
7270
"node": ">=6.0.0"
@@ -93,7 +91,7 @@
9391
"eslint": "eslint .",
9492
"prettier": "prettier --write --single-quote '{bin,config,scripts,template/src,tests}/**/*.js'",
9593
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
96-
"test": "npm run -s test:cli && npm run -s test:functional",
94+
"test": "npm run test:cli && npm run test:functional",
9795
"test:cli": "mocha tests/cliAccessibility.js --reporter spec --timeout 15000",
9896
"test:functional": "mocha tests/*.spec.js --reporter spec --timeout 15000"
9997
}

scripts/utils/webpackHotDevClient.js

Lines changed: 22 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -12,146 +12,29 @@
1212
var SockJS = require('sockjs-client');
1313
var stripAnsi = require('strip-ansi');
1414
var url = require('url');
15+
var launchEditorEndpoint = require('react-dev-utils/launchEditorEndpoint');
1516
var formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
16-
var Entities = require('html-entities').AllHtmlEntities;
17-
var ansiHTML = require('react-dev-utils/ansiHTML');
17+
var ErrorOverlay = require('react-error-overlay');
1818
var highlightElmCompilerErrors = require('./highlightElmCompilerErrors');
19-
var entities = new Entities();
20-
21-
function createOverlayIframe(onIframeLoad) {
22-
var iframe = document.createElement('iframe');
23-
iframe.id = 'react-dev-utils-webpack-hot-dev-client-overlay';
24-
iframe.src = 'about:blank';
25-
iframe.style.position = 'fixed';
26-
iframe.style.left = 0;
27-
iframe.style.top = 0;
28-
iframe.style.right = 0;
29-
iframe.style.bottom = 0;
30-
iframe.style.width = '100vw';
31-
iframe.style.height = '100vh';
32-
iframe.style.border = 'none';
33-
iframe.style.zIndex = 2147483647;
34-
iframe.onload = onIframeLoad;
35-
return iframe;
36-
}
37-
38-
function addOverlayDivTo(iframe) {
39-
// TODO: unify these styles with react-error-overlay
40-
iframe.contentDocument.body.style.margin = 0;
41-
iframe.contentDocument.body.style.maxWidth = '100vw';
42-
43-
var outerDiv = iframe.contentDocument.createElement('div');
44-
outerDiv.id = 'react-dev-utils-webpack-hot-dev-client-overlay-div';
45-
outerDiv.style.width = '100%';
46-
outerDiv.style.height = '100%';
47-
outerDiv.style.boxSizing = 'border-box';
48-
outerDiv.style.textAlign = 'center';
49-
outerDiv.style.backgroundColor = 'rgb(255, 255, 255)';
50-
51-
var div = iframe.contentDocument.createElement('div');
52-
div.style.position = 'relative';
53-
div.style.display = 'inline-flex';
54-
div.style.flexDirection = 'column';
55-
div.style.height = '100%';
56-
div.style.width = '1024px';
57-
div.style.maxWidth = '100%';
58-
div.style.overflowX = 'hidden';
59-
div.style.overflowY = 'auto';
60-
div.style.padding = '0.5rem';
61-
div.style.boxSizing = 'border-box';
62-
div.style.textAlign = 'left';
63-
div.style.fontFamily = 'Consolas, Menlo, monospace';
64-
div.style.fontSize = '11px';
65-
div.style.whiteSpace = 'pre-wrap';
66-
div.style.wordBreak = 'break-word';
67-
div.style.lineHeight = '1.5';
68-
div.style.color = 'rgb(41, 50, 56)';
69-
70-
outerDiv.appendChild(div);
71-
iframe.contentDocument.body.appendChild(outerDiv);
72-
return div;
73-
}
74-
75-
function overlayHeaderStyle() {
76-
return (
77-
'font-size: 2em;' +
78-
'font-family: sans-serif;' +
79-
'color: rgb(206, 17, 38);' +
80-
'white-space: pre-wrap;' +
81-
'margin: 0 2rem 0.75rem 0px;' +
82-
'flex: 0 0 auto;' +
83-
'max-height: 35%;' +
84-
'overflow: auto;'
85-
);
86-
}
87-
88-
var overlayIframe = null;
89-
var overlayDiv = null;
90-
var lastOnOverlayDivReady = null;
91-
92-
function ensureOverlayDivExists(onOverlayDivReady) {
93-
if (overlayDiv) {
94-
// Everything is ready, call the callback right away.
95-
onOverlayDivReady(overlayDiv);
96-
return;
97-
}
98-
99-
// Creating an iframe may be asynchronous so we'll schedule the callback.
100-
// In case of multiple calls, last callback wins.
101-
lastOnOverlayDivReady = onOverlayDivReady;
102-
103-
if (overlayIframe) {
104-
// We're already creating it.
105-
return;
106-
}
107-
108-
// Create iframe and, when it is ready, a div inside it.
109-
overlayIframe = createOverlayIframe(function onIframeLoad() {
110-
overlayDiv = addOverlayDivTo(overlayIframe);
111-
// Now we can talk!
112-
lastOnOverlayDivReady(overlayDiv);
113-
});
114-
115-
// Zalgo alert: onIframeLoad() will be called either synchronously
116-
// or asynchronously depending on the browser.
117-
// We delay adding it so `overlayIframe` is set when `onIframeLoad` fires.
118-
document.body.appendChild(overlayIframe);
119-
}
12019

121-
function showErrorOverlay(message) {
122-
ensureOverlayDivExists(function onOverlayDivReady(overlayDiv) {
123-
// TODO: unify this with our runtime overlay
124-
overlayDiv.innerHTML =
125-
'<div style="' +
126-
overlayHeaderStyle() +
127-
'">Failed to compile</div>' +
128-
'<pre style="' +
129-
'display: block; padding: 0.5em; margin-top: 0; ' +
130-
'margin-bottom: 0.5em; overflow-x: auto; white-space: pre-wrap; ' +
131-
'border-radius: 0.25rem; background-color: rgba(206, 17, 38, 0.05)">' +
132-
'<code style="font-family: Consolas, Menlo, monospace;">' +
133-
ansiHTML(entities.encode(message)) +
134-
'</code></pre>' +
135-
'<div style="' +
136-
'font-family: sans-serif; color: rgb(135, 142, 145); margin-top: 0.5rem; ' +
137-
'flex: 0 0 auto">' +
138-
'This error occurred during the build time and cannot be dismissed.</div>';
20+
ErrorOverlay.startReportingRuntimeErrors({
21+
launchEditorEndpoint: launchEditorEndpoint,
22+
onError: function() {
23+
// TODO: why do we need this?
24+
if (module.hot && typeof module.hot.decline === 'function') {
25+
module.hot.decline();
26+
}
27+
},
28+
filename: '/static/js/bundle.js'
29+
});
30+
31+
if (module.hot && typeof module.hot.dispose === 'function') {
32+
module.hot.dispose(function() {
33+
// TODO: why do we need this?
34+
ErrorOverlay.stopReportingRuntimeErrors();
13935
});
14036
}
14137

142-
function destroyErrorOverlay() {
143-
if (!overlayDiv) {
144-
// It is not there in the first place.
145-
return;
146-
}
147-
148-
// Clean up and reset internal state.
149-
document.body.removeChild(overlayIframe);
150-
overlayDiv = null;
151-
overlayIframe = null;
152-
lastOnOverlayDivReady = null;
153-
}
154-
15538
// Connect to WebpackDevServer via a socket.
15639
var connection = new SockJS(
15740
url.format({
@@ -199,9 +82,9 @@ function handleSuccess() {
19982
// Attempt to apply hot updates or reload.
20083
if (isHotUpdate) {
20184
tryApplyUpdates(function onHotUpdateSuccess() {
202-
// Only destroy it when we're sure it's a hot update.
85+
// Only dismiss it when we're sure it's a hot update.
20386
// Otherwise it would flicker right before the reload.
204-
destroyErrorOverlay();
87+
ErrorOverlay.dismissBuildError();
20588
});
20689
}
20790
}
@@ -241,9 +124,9 @@ function handleWarnings(warnings) {
241124
// Only print warnings if we aren't refreshing the page.
242125
// Otherwise they'll disappear right away anyway.
243126
printWarnings();
244-
// Only destroy it when we're sure it's a hot update.
127+
// Only dismiss it when we're sure it's a hot update.
245128
// Otherwise it would flicker right before the reload.
246-
destroyErrorOverlay();
129+
ErrorOverlay.dismissBuildError();
247130
});
248131
} else {
249132
// Print initial warnings immediately.
@@ -267,7 +150,7 @@ function handleErrors(errors) {
267150
);
268151

269152
// Only show the first error.
270-
showErrorOverlay(formatted.errors[0]);
153+
ErrorOverlay.reportBuildError(formatted.errors[0]);
271154

272155
// Also log them to the console.
273156
if (typeof console !== 'undefined' && typeof console.error === 'function') {

0 commit comments

Comments
 (0)