-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.js
37 lines (35 loc) · 1.21 KB
/
build.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
27
28
29
30
31
32
33
34
35
36
37
const esbuild = require('esbuild')
const path = require('path')
const fs = require('fs')
esbuild.build({
entryPoints: [path.resolve(__dirname, './src/index.js')],
outfile: path.resolve(__dirname, './dist/index.js'),
bundle: true,
platform: 'node',
target: 'node12.13.0',
external: ['prettier'],
minify: process.argv.includes('--minify'),
watch: process.argv.includes('--watch'),
plugins: [
{
// https://github.com/benjamn/recast/issues/611
name: 'patch-recast',
setup(build) {
build.onLoad({ filter: /recast\/lib\/patcher\.js$/ }, async (args) => {
let original = await fs.promises.readFile(args.path, 'utf8')
return {
contents: original
.replace(
'var nls = needsLeadingSpace(lines, oldNode.loc, newLines);',
'var nls = oldNode.type !== "TemplateElement" && needsLeadingSpace(lines, oldNode.loc, newLines);',
)
.replace(
'var nts = needsTrailingSpace(lines, oldNode.loc, newLines)',
'var nts = oldNode.type !== "TemplateElement" && needsTrailingSpace(lines, oldNode.loc, newLines)',
),
}
})
},
},
],
})