Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify ESM execute example #223

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 11 additions & 18 deletions docs/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,22 @@ Rename `bin/dev` to `bin/dev.js` and replace the existing code with the followin

```js
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
// eslint-disable-next-line node/shebang
async function main() {
const {execute} = await import('@oclif/core')
await execute({development: true, dir: import.meta.url})
}

await main()
import {execute} from '@oclif/core'

await execute({development: true, dir: import.meta.url})
```

This leverages oclif's `execute` function which handles all the development setup for you. You no longer need set the `NODE_ENV` env var or register the project with `ts-node`. You can still adjust oclif `settings` before executing the CLI. For example,

```js
#!/usr/bin/env -S node --loader ts-node/esm --no-warnings=ExperimentalWarning
// eslint-disable-next-line node/shebang
async function main() {
const {execute, settings} = await import('@oclif/core')
settings.performanceEnabled = true
await execute({development: true, dir: import.meta.url})
}

await main()
import {execute, settings} from '@oclif/core'

settings.performanceEnabled = true

await execute({development: true, dir: import.meta.url})
```


Expand All @@ -97,12 +92,10 @@ Rename `bin/run` to `bin/run.js` and replace the existing code with the followin

```js
#!/usr/bin/env node
async function main() {
const {execute} = await import('@oclif/core')
await execute({dir: import.meta.url})
}

await main()
import {execute} from '@oclif/core'

await execute({dir: import.meta.url})
```

### Update tsconfig.json
Expand Down