-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
26 lines (25 loc) · 790 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var flowRemoveTypes = require('flow-remove-types')
var { readFile } = require('fs').promises
module.exports = (regexp = /$^/, force) => {
return {
name: 'flow',
setup(build) {
build.onLoad({ filter: regexp }, async (args) => {
const source = await readFile(args.path, 'utf8')
let output = source
if (force) {
output = flowRemoveTypes('// @flow\n' + source, { pretty: true })
} else {
if (source.slice(0, 8) === '// @flow' || source.match(/^\/\*.*@flow.*\*\//s)) {
output = flowRemoveTypes(source, { pretty: true })
}
}
const contents = output.toString().replace(/static\s+\+/g, 'static ')
return {
contents,
loader: 'jsx',
}
})
},
}
}