Skip to content

Commit

Permalink
Merge pull request #223 from mon-jai/patch-1
Browse files Browse the repository at this point in the history
chore: simplify ESM execute example
  • Loading branch information
mdonnalley authored Feb 12, 2024
2 parents 543a20a + ce5968f commit c9c1f00
Showing 1 changed file with 11 additions and 18 deletions.
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

0 comments on commit c9c1f00

Please sign in to comment.