Skip to content

Commit 839fb1c

Browse files
lukeedtimneutkens
authored andcommitted
[WIP] Migrate from Gulp to Fly (vercel#965)
* install fly & plugins * start flyfile conversion * install node-notifier directly * send task notifications * upgrade to fly@2.0.1 * fix watch rebuilds * compile in parallel * remove gulp-related deps * enable start|stop-chromedriver * run build before watching * extract webpack config * fix webpack build * use serial chain within 'build' -- faster * update to fly-watch@1.1.0 * generate new yarn.lock after rebase * rename tasks; use fly-esnext (async/await) * bump fly deps (node4 supp) * remove destructured assignment * import latest package.json changes
1 parent 97714e8 commit 839fb1c

File tree

4 files changed

+336
-937
lines changed

4 files changed

+336
-937
lines changed

flyfile.js

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
const webpack = require('webpack')
2+
const notifier = require('node-notifier')
3+
const childProcess = require('child_process')
4+
const webpackConfig = require('./webpack.config')
5+
const isWindows = /^win/.test(process.platform)
6+
7+
export async function compile(fly) {
8+
await fly.parallel(['bin', 'server', 'lib', 'client'])
9+
await fly.start('unrestrict')
10+
}
11+
12+
export async function bin(fly, opts) {
13+
await fly.source(opts.src || 'bin/*').babel().target('dist/bin')
14+
notify('Compiled binaries')
15+
}
16+
17+
export async function lib(fly, opts) {
18+
await fly.source(opts.src || 'lib/**/*.js').babel().target('dist/lib')
19+
notify('Compiled lib files')
20+
}
21+
22+
export async function server(fly, opts) {
23+
await fly.source(opts.src || 'server/**/*.js').babel().target('dist/server')
24+
notify('Compiled server files')
25+
}
26+
27+
export async function client(fly, opts) {
28+
await fly.source(opts.src || 'client/**/*.js').babel().target('dist/client')
29+
notify('Compiled client files')
30+
}
31+
32+
export async function unrestrict(fly) {
33+
await fly.source('dist/lib/eval-script.js').babel({
34+
babelrc: false,
35+
plugins: ['babel-plugin-transform-remove-strict-mode']
36+
}).target('dist/lib')
37+
notify('Completed removing strict mode for eval script')
38+
}
39+
40+
export async function copy(fly) {
41+
await fly.source('pages/**/*.js').target('dist/pages')
42+
}
43+
44+
export async function build(fly) {
45+
await fly.serial(['copy', 'compile', 'prefetcher'])
46+
}
47+
48+
const compiler = webpack(webpackConfig)
49+
export async function prefetcher(fly) {
50+
compiler.run((err, stats) => {
51+
if (err) throw err
52+
notify('Built release prefetcher')
53+
})
54+
}
55+
56+
export async function bench(fly) {
57+
await fly.parallel(['compile', 'copy'])
58+
// copy bench fixtures
59+
await fly.source('bench/fixtures/**/*').target('dist/bench/fixtures')
60+
// compile bench
61+
await fly.source('bench/*.js').babel().target('dist/bench')
62+
notify('Compiled bench files')
63+
// yield fly.source('dist/bench/*.js').benchmark({
64+
// benchmark.reporters.etalon('RegExp#test')
65+
// })
66+
}
67+
68+
export default async function (fly) {
69+
await fly.start('build')
70+
await fly.watch('bin/*', 'bin')
71+
await fly.watch('pages/**/*.js', 'copy')
72+
await fly.watch('server/**/*.js', 'server')
73+
await fly.watch('client/**/*.js', ['client', 'prefetcher'])
74+
await fly.watch('lib/**/*.js', ['lib', 'prefetcher'])
75+
}
76+
77+
export async function release(fly) {
78+
await fly.clear('dist').start('build')
79+
}
80+
81+
// We run following task inside a NPM script chain and it runs chromedriver
82+
// inside a child process tree.
83+
// Even though we kill this task's process, chromedriver exists throughout
84+
// the lifetime of the original npm script.
85+
86+
export async function pretest(fly) {
87+
const processName = isWindows ? 'chromedriver.cmd' : 'chromedriver'
88+
const chromedriver = childProcess.spawn(processName, { stdio: 'inherit' })
89+
// We need to do this, otherwise this task's process will keep waiting.
90+
setTimeout(() => process.exit(0), 2000)
91+
}
92+
93+
export async function posttest(fly) {
94+
try {
95+
const cmd = isWindows ? 'taskkill /im chromedriver* /t /f' : 'pkill chromedriver'
96+
childProcess.execSync(cmd, { stdio: 'ignore' })
97+
} catch(err) {
98+
// Do nothing
99+
}
100+
}
101+
102+
// notification helper
103+
function notify(msg) {
104+
return notifier.notify({
105+
title: '▲ Next',
106+
message: msg,
107+
icon: false
108+
})
109+
}

package.json

+11-12
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
"next": "./dist/bin/next"
2424
},
2525
"scripts": {
26-
"build": "gulp",
27-
"release": "gulp release",
28-
"pretestonly": "gulp start-chromedriver",
26+
"build": "fly",
27+
"release": "fly release",
28+
"pretestonly": "fly pretest",
2929
"testonly": "cross-env NODE_PATH=test/lib jest \\.test.js",
30-
"posttestonly": "gulp stop-chromedriver",
30+
"posttestonly": "fly posttest",
3131
"pretest": "npm run lint && cross-env NODE_ENV=test npm run release",
3232
"test": "npm run testonly -- --coverage --forceExit",
3333
"coveralls": "nyc --instrument=false --source-map=false report --temp-directory=./coverage --reporter=text-lcov | coveralls",
@@ -95,21 +95,20 @@
9595
"chromedriver": "^2.26.1",
9696
"coveralls": "2.11.16",
9797
"cross-env": "^3.1.4",
98-
"gulp": "3.9.1",
99-
"gulp-babel": "6.1.2",
100-
"gulp-benchmark": "1.1.1",
101-
"gulp-cached": "1.1.1",
102-
"gulp-notify": "3.0.0",
98+
"fly": "^2.0.3",
99+
"fly-babel": "^2.1.1",
100+
"fly-clear": "^1.0.1",
101+
"fly-esnext": "^2.0.0",
102+
"fly-watch": "^1.1.1",
103103
"husky": "0.13.1",
104104
"jest-cli": "^18.0.0",
105105
"node-fetch": "^1.6.3",
106+
"node-notifier": "^5.0.2",
106107
"nyc": "^10.0.0",
107108
"react": "15.4.2",
108109
"react-dom": "15.4.2",
109-
"run-sequence": "1.2.2",
110110
"standard": "8.6.0",
111-
"wd": "^1.1.3",
112-
"webpack-stream": "3.2.0"
111+
"wd": "^1.1.3"
113112
},
114113
"peerDependencies": {
115114
"react": "^15.4.2",

webpack.config.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const resolve = require('path').resolve
2+
const webpack = require('webpack')
3+
4+
module.exports = {
5+
entry: './client/next-prefetcher.js',
6+
output: {
7+
filename: 'next-prefetcher-bundle.js',
8+
path: resolve(__dirname, 'dist/client')
9+
},
10+
plugins: [
11+
new webpack.DefinePlugin({
12+
'process.env': {
13+
NODE_ENV: JSON.stringify('production')
14+
}
15+
})
16+
],
17+
module: {
18+
rules: [{
19+
test: /\.js$/,
20+
exclude: /node_modules/,
21+
loader: 'babel-loader',
22+
options: {
23+
babelrc: false,
24+
presets: [
25+
['env', {
26+
targets: {
27+
// All browsers which supports service workers
28+
browsers: ['chrome 49', 'firefox 49', 'opera 41']
29+
}
30+
}]
31+
]
32+
}
33+
}]
34+
}
35+
}

0 commit comments

Comments
 (0)