Skip to content

Commit 6fdd918

Browse files
authored
feat(logging): use babel-plugin-dev-expression for logging errors (#41)
* feat(logging): use babel-plugin-dev-expression for logging errors on both server+client * refactor(example): example app installs src as node_module * refactor(example): use localhost as host in hapi server
1 parent b957675 commit 6fdd918

18 files changed

Lines changed: 1229 additions & 714 deletions

.eslintrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const path = require('path')
33
module.exports = {
44
extends: 'eslint-config-ns',
55
plugins: ['react-hooks'],
6+
globals: {
7+
__DEV__: true,
8+
},
69
rules: {
710
'jest/prefer-strict-equal': 'error',
811
'no-underscore-dangle': 0,

babel.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ module.exports = {
2727
'@babel/plugin-transform-modules-commonjs',
2828
'@babel/plugin-proposal-class-properties',
2929
'@babel/plugin-proposal-object-rest-spread',
30+
// https://github.com/4Catalyzer/babel-plugin-dev-expression
31+
'babel-plugin-dev-expression',
3032
],
3133
}

example/.env

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# "production": will disable logging in the client
2+
NODE_ENV="development"

example/package-lock.json

Lines changed: 528 additions & 327 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "server/index.js",
66
"private": true,
77
"scripts": {
8-
"build": "BABEL_ENV=production webpack -p",
8+
"build": "NODE_ENV=production BABEL_ENV=production webpack -p",
99
"prebuild": "rimraf dist",
1010
"start": "node .",
1111
"test": "echo \"Error: no test specified\" && exit 1",
@@ -17,7 +17,11 @@
1717
"type": "git",
1818
"url": "git+https://github.com/natterstefan/react-component-catalog.git"
1919
},
20-
"keywords": ["react", "components", "registry"],
20+
"keywords": [
21+
"react",
22+
"components",
23+
"registry"
24+
],
2125
"author": "Stefan Natter <stefan@natter.at>",
2226
"license": "MIT",
2327
"bugs": {
@@ -28,25 +32,28 @@
2832
"babel-core": "6.x || ^7.0.0-bridge.0"
2933
},
3034
"dependencies": {
31-
"@babel/register": "^7.4.4",
35+
"@babel/register": "^7.5.5",
36+
"dotenv": "^8.0.0",
3237
"hapi": "^18.1.0",
3338
"inert": "^5.1.3",
3439
"react": "^16.8.6",
40+
"react-component-catalog": "file:..",
3541
"react-dom": "^16.8.6"
3642
},
3743
"devDependencies": {
38-
"@babel/cli": "7.4.4",
39-
"@babel/core": "7.4.5",
40-
"@babel/plugin-proposal-class-properties": "7.4.4",
41-
"@babel/plugin-proposal-object-rest-spread": "7.4.4",
44+
"@babel/cli": "7.5.5",
45+
"@babel/core": "7.5.5",
46+
"@babel/plugin-proposal-class-properties": "7.5.5",
47+
"@babel/plugin-proposal-object-rest-spread": "7.5.5",
4248
"@babel/polyfill": "7.4.4",
43-
"@babel/preset-env": "7.4.5",
49+
"@babel/preset-env": "7.5.5",
4450
"@babel/preset-react": "7.0.0",
4551
"babel-core": "7.0.0-bridge.0",
4652
"babel-loader": "8.0.6",
53+
"babel-plugin-dev-expression": "^0.2.2",
4754
"nodemon": "1.19.1",
4855
"rimraf": "2.6.3",
49-
"webpack": "4.31.0",
50-
"webpack-cli": "3.3.5"
56+
"webpack": "4.36.1",
57+
"webpack-cli": "3.3.6"
5158
}
5259
}

example/server/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-console */
12
require('@babel/register')({
23
babelrc: true,
34
})
@@ -8,9 +9,13 @@ async function startServer() {
89
try {
910
const server = await createServer()
1011
await server.start()
11-
console.log('server running at:', server.info.uri)
12+
console.log(
13+
`Server running at: ${server.info.uri}`,
14+
'\n- Open base: http://localhost:8000/base',
15+
'\n- Open client: http://localhost:8000/client1',
16+
)
1217
} catch (err) {
13-
console.log(err)
18+
console.error(err)
1419
process.exit(1)
1520
}
1621
}

example/server/render.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* For now we just allow the server to serve clients defined in `allowedClients`
33
* in a more sophisticated setup, one would derive the `client` value from other
44
* parameters (eg. hostname, path, ...).
5-
*
5+
*
66
* For this demo this restriction and identification of the client is enough.
77
*/
88
const allowedClients = ['base', 'client1']

example/server/server.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import Hapi from 'hapi'
22
import inert from 'inert'
3+
34
import render from './render'
45

56
export const createServer = async () => {
67
/**
78
* BASIC SERVER
89
*/
910
const server = Hapi.server({
11+
host: 'localhost',
1012
port: 8000,
1113
})
1214
await server.register(inert)

example/webpack.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
const { resolve } = require('path')
22

3+
require('dotenv').config()
4+
35
const bundle = client => ({
46
[`${client}.bundled.js`]: [
57
'@babel/polyfill',
@@ -13,7 +15,7 @@ module.exports = {
1315
...bundle('base'),
1416
...bundle('client1'),
1517
},
16-
mode: 'development',
18+
mode: process.env.BABEL_ENV || process.env.NODE_ENV || 'development',
1719
module: {
1820
rules: [
1921
{
@@ -44,7 +46,6 @@ module.exports = {
4446
// https://reactjs.org/warnings/invalid-hook-call-warning.html#duplicate-react
4547
alias: {
4648
react: resolve(__dirname, 'node_modules/react'),
47-
'react-component-catalog': resolve(__dirname, '..', 'src/'),
4849
'react-dom': resolve(__dirname, 'node_modules/react-dom'),
4950
},
5051
},

jest.setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ import { configure } from 'enzyme'
33
import Adapter from 'enzyme-adapter-react-16'
44

55
configure({ adapter: new Adapter() })
6+
7+
global.__DEV__ = true

0 commit comments

Comments
 (0)