From 317eb6e4f84f9bbabc7ca6d8ccaf62dc11c56c7e Mon Sep 17 00:00:00 2001 From: Mike Donnalley Date: Wed, 4 Oct 2023 19:54:26 -0600 Subject: [PATCH] fix: esm docs --- docs/esm.md | 29 ++++++++++++----------------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/docs/esm.md b/docs/esm.md index ad855998..14914e87 100644 --- a/docs/esm.md +++ b/docs/esm.md @@ -68,23 +68,16 @@ Rename `bin/dev` to `bin/dev.js` and replace the existing code with the followin ```js #!/usr/bin/env node // eslint-disable-next-line node/shebang -(async () => { - const oclif = await import('@oclif/core') - await oclif.execute({development: true, dir: import.meta.url}) -})() +async function main() { + const {execute} = await import('@oclif/core') + await execute({development: true, dir: import.meta.url}) +} + +await main() ``` 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 still adjust oclif `settings` before executing the CLI. For example, -```js -#!/usr/bin/env node -// eslint-disable-next-line node/shebang -(async () => { - const oclif = await import('@oclif/core') - oclif.settings.performanceEnabled = true - await oclif.execute({type: 'esm', development: true, dir: import.meta.url}) -})() -``` #### bin/run → bin/run.js @@ -92,10 +85,12 @@ Rename `bin/run` to `bin/run.js` and replace the existing code with the followin ```js #!/usr/bin/env node -(async () => { - const oclif = await import('@oclif/core') - await oclif.execute({dir: import.meta.url}) -})() +async function main() { + const {execute} = await import('@oclif/core') + await execute({dir: import.meta.url}) +} + +await main() ``` ### Update tsconfig.json