-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a sucrase-node CLI that wraps node (#288)
Fixes #262
- Loading branch information
1 parent
c6879ba
commit d31351a
Showing
4 changed files
with
40 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env node | ||
const Module = require("module"); | ||
const {resolve} = require("path"); | ||
|
||
/* | ||
* Simple wrapper around node that first registers Sucrase with default settings. | ||
* | ||
* This is meant for simple use cases, and doesn't support custom Node/V8 args, | ||
* executing a code snippet, a REPL, or other things that you might find in | ||
* node, babel-node, or ts-node. For more advanced use cases, you can use | ||
* `node -r sucrase/register` or register a require hook programmatically from | ||
* your own code. | ||
*/ | ||
require("../register"); | ||
|
||
process.argv.splice(1, 1); | ||
process.argv[1] = resolve(process.argv[1]); | ||
Module.runMain(); |
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 |
---|---|---|
@@ -1,10 +1,18 @@ | ||
#!/usr/bin/env node | ||
const Module = require("module"); | ||
const {resolve} = require("path"); | ||
|
||
// Hacky wrapper around Sucrase for internal scripts. Not yet part of the | ||
// published package since that requires more work to get right. | ||
/* | ||
* Simple wrapper around node that first registers Sucrase with default settings. | ||
* | ||
* This is meant for simple use cases, and doesn't support custom Node/V8 args, | ||
* executing a code snippet, a REPL, or other things that you might find in | ||
* node, babel-node, or ts-node. For more advanced use cases, you can use | ||
* `node -r sucrase/register` or register a require hook programmatically from | ||
* your own code. | ||
*/ | ||
require("sucrase/register"); | ||
|
||
const file = process.argv[2]; | ||
process.argv.splice(1, 1); | ||
// eslint-disable-next-line import/no-dynamic-require | ||
require(`../${file}`); | ||
process.argv[1] = resolve(process.argv[1]); | ||
Module.runMain(); |