-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
6585245
commit 8740e05
Showing
13 changed files
with
676 additions
and
3,920 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
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,34 @@ | ||
{ | ||
"name": "@oxc-node/cli", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"type": "module", | ||
"description": "OXC Node cli", | ||
"bin": { | ||
"oxnode": "./dist/index.js" | ||
}, | ||
"dependencies": { | ||
"@oxc-node/core": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"clipanion": "^4.0.0-rc.3", | ||
"rolldown": "^0.12.2" | ||
}, | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "rolldown --config ./rolldown.config.js", | ||
"dev": "node --import @oxc-node/core/register ./src/index.ts" | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/Brooooooklyn" | ||
}, | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/Boshen" | ||
} | ||
] | ||
} |
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,16 @@ | ||
import { defineConfig } from 'rolldown' | ||
|
||
export default defineConfig({ | ||
input: './src/index.ts', | ||
resolve: { | ||
conditionNames: ['module', 'node'], | ||
mainFields: ['module', 'main'], | ||
}, | ||
platform: 'node', | ||
external: ['@oxc-node/core'], | ||
treeshake: true, | ||
output: { | ||
format: 'esm', | ||
assetFileNames: '[name].js', | ||
}, | ||
}) |
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,83 @@ | ||
import process from 'node:process' | ||
import { exec, execSync } from 'node:child_process' | ||
|
||
import { Command, Option, Cli, Usage, Builtins } from 'clipanion' | ||
|
||
import pkgJson from '../package.json' with { type: 'json' } | ||
|
||
const [node, app, ...stdArgs] = process.argv | ||
|
||
class MainCommand extends Command { | ||
static paths = [[]] | ||
|
||
static usage: Usage = { | ||
description: `Run a script with oxc transformer and oxc-resolver`, | ||
details: `oxnode is a CLI tool that runs a script with oxc transformer and oxc-resolver. | ||
The esm module is resolved by oxc-resolver and transformed by oxc transformer. | ||
The cjs module support will be added in the future. | ||
`, | ||
examples: [ | ||
[`Run a script`, `oxnode ./src/index.ts`], | ||
[`repl`, `oxnode`], | ||
], | ||
} | ||
|
||
help = Option.Boolean(`-h,--help`, false, { | ||
description: `Show help`, | ||
}) | ||
|
||
nodeHelp = Option.Boolean(`--node-help`, false, { | ||
description: `Show Node.js help`, | ||
}) | ||
|
||
args = Option.Rest() | ||
|
||
async execute() { | ||
if (this.help) { | ||
this.context.stdout.write(this.cli.usage()) | ||
return | ||
} | ||
if (this.nodeHelp) { | ||
this.args.push(`--help `) | ||
} | ||
const args = this.args.length ? ` ${this.args.join(' ')}` : '' | ||
if (!args.length) { | ||
execSync(`node --import @oxc-node/core/register`, { | ||
env: process.env, | ||
cwd: process.cwd(), | ||
stdio: `inherit`, | ||
}) | ||
return | ||
} | ||
const cp = exec(`node --import @oxc-node/core/register ${args}`, { | ||
env: process.env, | ||
cwd: process.cwd(), | ||
}) | ||
cp.addListener(`error`, (error) => { | ||
console.error(error) | ||
}) | ||
if (cp.stdin) { | ||
this.context.stdin.pipe(cp.stdin) | ||
} | ||
if (cp.stdout) { | ||
cp.stdout.pipe(this.context.stdout) | ||
} | ||
if (cp.stderr) { | ||
cp.stderr.pipe(this.context.stderr) | ||
} | ||
cp.addListener(`exit`, (code) => { | ||
process.exit(code ?? 0) | ||
}) | ||
} | ||
} | ||
|
||
const cli = new Cli({ | ||
binaryLabel: `oxnode`, | ||
binaryName: `${node} ${app}`, | ||
binaryVersion: pkgJson.version, | ||
}) | ||
|
||
cli.register(MainCommand) | ||
cli.register(Builtins.HelpCommand) | ||
cli.register(Builtins.VersionCommand) | ||
cli.runExit(stdArgs) |
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,11 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"composite": true, | ||
"outDir": "./dist", | ||
"rootDir": "./src", | ||
"resolveJsonModule": true | ||
}, | ||
"include": ["package.json", "./src"], | ||
"exclude": ["__tests__", "./dist"] | ||
} |
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
Oops, something went wrong.