Skip to content

Commit c201b44

Browse files
committed
Modernization
- Upgrades dependencies - Ensures support for React 16 - Switches from Babel compilation to Rollup - Updates example
1 parent 7b75fe8 commit c201b44

File tree

15 files changed

+2794
-1213
lines changed

15 files changed

+2794
-1213
lines changed

.babelrc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
22
"presets": [
3-
"es2015",
3+
[
4+
"env",
5+
{
6+
"useBuiltIns": false,
7+
"loose": true,
8+
"modules": false
9+
}
10+
],
411
"react",
512
"stage-2"
6-
],
7-
"sourceMaps": "inline"
13+
]
814
}

Makefile

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,22 @@
1-
SHELL := /bin/bash
2-
PATH := ./node_modules/.bin:$(PATH)
1+
all: bundle package.json documentation
32

4-
.PHONY: clean test test-watch package.json javascript release example documentation
5-
6-
all: javascript package.json documentation
7-
8-
javascript: $(shell find src -name '*.js*' ! -name '*.test.js*')
9-
mkdir -p dist
10-
babel -d dist $^
3+
bundle:
4+
@ ./bin/bundle
115

126
package.json:
13-
node -p 'p=require("./package");p.private=undefined;p.scripts=p.devDependencies=undefined;JSON.stringify(p,null,2)' > dist/package.json
7+
@ node -p 'p=require("./package");p.private=undefined;p.scripts=p.devDependencies=undefined;JSON.stringify(p,null,2)' > dist/package.json
148

159
documentation: README.md LICENSE.md
16-
mkdir -p dist
17-
cp -r $^ dist
10+
@ mkdir -p dist
11+
@ cp -r $^ dist
1812

1913
release: clean all
20-
npm publish dist
14+
@ npm publish dist
2115

22-
release-support: clean all
23-
npm publish dist --tag support
24-
25-
example:
26-
open example/index.html
27-
webpack -wd
16+
prerelease: clean all
17+
@ npm publish dist --tag beta
2818

2919
clean:
30-
rm -rf dist
31-
32-
lint:
33-
@ eslint {src,test}/**/*.{js,jsx}
20+
@ rm -rf dist
3421

35-
test: lint
36-
NODE_ENV=test karma start --single-run
22+
.PHONY: clean package.json bundle release documentation

bin/bundle

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env node
2+
3+
'use strict'
4+
5+
const rollup = require('rollup')
6+
const buble = require('rollup-plugin-buble')
7+
const path = require('path')
8+
9+
let bundler = rollup.rollup({
10+
input: path.resolve(__dirname, '../src/focus-trap'),
11+
plugins: [
12+
buble()
13+
],
14+
external: ['react', 'react-dom'],
15+
onwarn: function(error) {
16+
// Do not raise warnings for named exports
17+
if (error.code !== 'MIXED_EXPORTS') {
18+
console.warn(error.toString())
19+
}
20+
}
21+
})
22+
23+
let write = bundler.then(bundle => {
24+
return bundle.write({
25+
file: './dist/index.js',
26+
format: 'cjs',
27+
sourcemap: true
28+
})
29+
})
30+
31+
write.catch(error => console.error(error.toString()))

bin/format

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
# Format our code according to our standards
4+
#
5+
# Run this command with:
6+
# ./bin/format
7+
8+
PATH=$(yarn bin):$PATH
9+
10+
# Run prettier on these files:
11+
SRC=$(git ls-files | grep -v "^\." | grep ".js\$")
12+
13+
# Prettier is an automated code formatter.
14+
# https://github.com/prettier/prettier
15+
prettier --write $SRC

bin/lint

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
3+
# Check our code base for inconsistencies in code formatting
4+
# and common mistakes.
5+
#
6+
# Run this command with:
7+
# ./bin/lint
8+
9+
set -e
10+
11+
PATH=$(yarn bin):$PATH
12+
13+
# Check these files for mistakes:
14+
SRC=$(git ls-files | grep -v "^\." | grep ".js\$")
15+
16+
# Prettier is an automated code formatter.
17+
# https://github.com/prettier/prettier
18+
if ! prettier --list-different $SRC; then
19+
echo "Auto-formatting is out of sync. Please run yarn format and commit the result."
20+
exit 1
21+
fi

example/index.js

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,60 @@
1-
var React = require('react')
2-
var DOM = require('react-dom')
3-
var FocusTrap = require('../src/focus-trap')
4-
5-
var Component = React.createClass({
6-
7-
getInitialState() {
8-
return {
9-
focusOne: false,
10-
focusTwo: false
11-
}
12-
},
1+
import React from 'react'
2+
import DOM from 'react-dom'
3+
import FocusTrap from '../src/focus-trap'
4+
5+
class Component extends React.Component {
6+
state = {
7+
focusOne: false,
8+
focusTwo: false
9+
}
1310

1411
render() {
1512
return (
1613
<div>
17-
<button onClick={ this._onOpenOne}>Open Dialog One</button>
18-
<FocusTrap onExit={ this._onExitOne } active={ this.state.focusOne }>
14+
<button onClick={this._onOpenOne}>Open Dialog One</button>
15+
16+
<FocusTrap onExit={this._onExitOne} active={this.state.focusOne}>
1917
<h1>This is the primary dialog</h1>
20-
<p><a href="http://google.com">Focus one</a></p>
21-
<p><a href="http://google.com">Focus two</a></p>
22-
<button onClick={ this._onOpenTwo }>Open Dialog Two</button>
18+
<p>
19+
<a href="http://google.com">Focus one</a>
20+
</p>
21+
<p>
22+
<a href="http://google.com">Focus two</a>
23+
</p>
24+
<button onClick={this._onOpenTwo}>Open Dialog Two</button>
2325
</FocusTrap>
24-
<FocusTrap onExit={ this._onExitTwo } active={ this.state.focusTwo }>
26+
27+
<FocusTrap onExit={this._onExitTwo} active={this.state.focusTwo}>
2528
<h1>This is the secondary dialog</h1>
2629

2730
<input type="text" placeholder="This should autofocus" autoFocus />
2831

29-
<p><a href="http://google.com">Focus one</a></p>
30-
<p><a href="http://google.com">Focus two</a></p>
32+
<p>
33+
<a href="http://google.com">Focus one</a>
34+
</p>
35+
<p>
36+
<a href="http://google.com">Focus two</a>
37+
</p>
3138
</FocusTrap>
3239
</div>
3340
)
34-
},
41+
}
3542

36-
_onOpenOne() {
43+
_onOpenOne = () => {
3744
this.setState({ focusOne: true })
38-
},
45+
}
3946

40-
_onOpenTwo() {
47+
_onOpenTwo = () => {
4148
this.setState({ focusTwo: true })
42-
},
49+
}
4350

44-
_onExitOne() {
51+
_onExitOne = () => {
4552
this.setState({ focusOne: false })
46-
},
53+
}
4754

48-
_onExitTwo() {
55+
_onExitTwo = () => {
4956
this.setState({ focusTwo: false })
5057
}
51-
52-
})
58+
}
5359

5460
DOM.render(<Component />, window.app)

example/index.html renamed to example/public/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<title>React Ink Example</title>
6-
<link rel="stylesheet" href="./style.css">
6+
<link rel="stylesheet" href="/style.css">
77
<style>
88
body {
99
font-family: sans-serif;
@@ -23,6 +23,6 @@
2323
<h1>Example loading...</h1>
2424
</div>
2525

26-
<script src="example.build.js"></script>
26+
<script src="/bundle.js"></script>
2727
</body>
2828
</html>
File renamed without changes.

karma.conf.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
var webpackConfig = require('./webpack.config')
2-
3-
module.exports = function (config) {
1+
const webpackConfig = require('./webpack.config')
42

3+
module.exports = function(config) {
54
config.set({
5+
hostname: '0.0.0.0',
66

7-
browsers: [ 'Chrome' ],
7+
browsers: ['Chrome'],
88

9-
frameworks: [ 'mocha' ],
9+
frameworks: ['mocha'],
1010

11-
files: [
12-
'test/*.js*'
13-
],
11+
files: ['test/*.js*'],
1412

15-
reporters: [ 'progress' ],
13+
reporters: ['progress'],
1614

1715
preprocessors: {
18-
'test/*.js*': [ 'webpack' ]
16+
'test/*.js*': ['webpack']
1917
},
2018

2119
webpack: {
22-
resolve : webpackConfig.resolve,
23-
module : webpackConfig.module
24-
},
25-
26-
webpackServer: {
27-
noInfo: true
20+
module: webpackConfig.module
2821
}
2922
})
3023
}

package.json

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,20 @@
55
"description": "Traps focus for accessible dropdowns and modal content.",
66
"main": "src/focus-trap.js",
77
"scripts": {
8-
"start": "make example",
9-
"test": "make test"
8+
"start": "webpack-dev-server",
9+
"build": "make all",
10+
"test": "NODE_ENV=test karma start --single-run",
11+
"format": "./bin/format",
12+
"lint": "./bin/lint"
1013
},
1114
"repository": {
1215
"type": "git",
1316
"url": "git@github.com:vigetlabs/react-focus-trap.git"
1417
},
18+
"prettier": {
19+
"semi": false,
20+
"singleQuote": true
21+
},
1522
"keywords": [
1623
"react",
1724
"a11y"
@@ -21,21 +28,26 @@
2128
"devDependencies": {
2229
"babel-cli": "^6.24.1",
2330
"babel-core": "^6.24.1",
24-
"babel-eslint": "^7.2.3",
25-
"babel-loader": "6.2.4",
26-
"babel-preset-es2015": "^6.24.1",
27-
"babel-preset-react": "^6.24.1",
31+
"babel-eslint": "^8.0.0",
32+
"babel-loader": "^7.0.0",
33+
"babel-preset-env": "^1.6.1",
2834
"babel-preset-stage-2": "^6.24.1",
29-
"eslint": "3.1.1",
30-
"eslint-plugin-react": "5.2.2",
31-
"karma": "1.1.1",
32-
"karma-chrome-launcher": "1.0.1",
33-
"karma-mocha": "1.1.1",
34-
"karma-webpack": "~1",
35-
"mocha": "2.5.3",
36-
"react": "^15.5.4",
37-
"react-addons-test-utils": "^15.5.1",
38-
"react-dom": "^15.5.4",
39-
"webpack": "~1.13.1"
35+
"eslint": "^4.10.0",
36+
"eslint-plugin-react": "^7.4.0",
37+
"karma": "^1.7.0",
38+
"karma-chrome-launcher": "^2.2.0",
39+
"karma-mocha": "^1.3.0",
40+
"karma-webpack": "^2.0.0",
41+
"mocha": "^4.0.0",
42+
"prettier": "^1.7.4",
43+
"react": "^16.0.0",
44+
"react-dom": "^16.0.0",
45+
"rollup": "^0.50.0",
46+
"rollup-plugin-buble": "^0.16.0",
47+
"webpack": "^3.8.1",
48+
"webpack-dev-server": "^2.9.3"
49+
},
50+
"dependencies": {
51+
"babel-preset-react": "^6.24.1"
4052
}
4153
}

0 commit comments

Comments
 (0)