-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
52 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import path from 'path' | ||
import { transformSync, Loader } from 'esbuild' | ||
import { addHook } from 'pirates' | ||
|
||
const files = new Set<string>() | ||
|
||
function compile(code: string, filename: string) { | ||
const match = new RegExp(`(${[...files].join('|')})`) | ||
if (!match.test(filename)) { | ||
return code | ||
} | ||
const { code: js, warnings } = transformSync(code, { | ||
sourcefile: filename, | ||
sourcemap: false, | ||
target: 'node12.0.0', | ||
format: 'cjs', | ||
loader: path.extname(filename).slice(1) as Loader | ||
}) | ||
if (warnings && warnings.length > 0) { | ||
for (const warning of warnings) { | ||
console.log(warning.location) | ||
console.log(warning.text) | ||
} | ||
} | ||
return js | ||
} | ||
|
||
let revert: any | ||
|
||
export function register(file: string[]) { | ||
file.forEach((f) => files.add(f)) | ||
if (!revert) { | ||
revert = addHook(compile, { | ||
exts: ['.js', '.jsx', '.ts', '.tsx'], | ||
ignoreNodeModules: false | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters