forked from stripe-archive/flow-to-typescript-codemod
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esBuild.js
executable file
·34 lines (32 loc) · 881 Bytes
/
esBuild.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
#!/usr/bin/env node
/* eslint-disable @typescript-eslint/no-var-requires */
// yargs and esbuild have some incompatibility. This fixes it
// See https://github.com/evanw/esbuild/issues/1492
const importMeta = {
name: 'Import Meta',
setup({onLoad}) {
const fs = require('fs');
const url = require('url');
onLoad({filter: /.*/}, (args) => {
let code = fs.readFileSync(args.path, 'utf8');
code = code.replace(
/\bimport\.meta\.url\b/g,
JSON.stringify(url.pathToFileURL(args.path)),
);
return {contents: code, loader: 'default'};
});
},
};
require('esbuild')
.build({
entryPoints: ['src/index.ts'],
bundle: true,
external: ['babylon'],
platform: 'node',
format: 'cjs',
outdir: 'dist',
plugins: [importMeta],
// Linked sourcemap
sourcemap: true,
})
.catch(() => process.exit(1));