From aeae3cf86ac773594a97084582934c01c70a921f Mon Sep 17 00:00:00 2001 From: Evan Wallace Date: Thu, 6 Jan 2022 11:00:32 -0500 Subject: [PATCH] fix #1913: enable the CLI with Deno --- CHANGELOG.md | 8 ++++++++ Makefile | 3 ++- lib/deno/mod.ts | 13 +++++++++++++ lib/tsconfig-deno.json | 10 ++++++++++ lib/tsconfig.json | 7 +++++-- scripts/esbuild.js | 2 +- 6 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 lib/tsconfig-deno.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 562f05d49b0..617f28c8970 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,14 @@ ╵ ~~~~~~ ``` +* Enable esbuild's CLI with Deno ([#1913](https://github.com/evanw/esbuild/issues/1913)) + + This release allows you to use Deno as an esbuild installer, without also needing to use esbuild's JavaScript API. You can now use esbuild's CLI with Deno: + + ``` + deno run --allow-all "https://deno.land/x/esbuild@v0.14.11/mod.js" --version + ``` + ## 0.14.10 * Enable tree shaking of classes with lowered static fields ([#175](https://github.com/evanw/esbuild/issues/175)) diff --git a/Makefile b/Makefile index b33706d77a1..e2840728bb0 100644 --- a/Makefile +++ b/Makefile @@ -93,7 +93,8 @@ node-unref-tests: | scripts/node_modules node scripts/node-unref-tests.js lib-typecheck: | lib/node_modules - cd lib && node_modules/.bin/tsc -noEmit -p . + cd lib && node_modules/.bin/tsc -noEmit -p tsconfig.json + cd lib && node_modules/.bin/tsc -noEmit -p tsconfig-deno.json # End-to-end tests test-e2e: test-e2e-npm test-e2e-pnpm test-e2e-yarn-berry diff --git a/lib/deno/mod.ts b/lib/deno/mod.ts index c4305db554c..5e078627da7 100644 --- a/lib/deno/mod.ts +++ b/lib/deno/mod.ts @@ -328,3 +328,16 @@ let ensureServiceIsRunning = (): Promise => { } return longLivedService } + +// If we're called as the main script, forward the CLI to the underlying executable +if (import.meta.main) { + Deno.run({ + cmd: [await install()].concat(Deno.args), + cwd: defaultWD, + stdin: 'inherit', + stdout: 'inherit', + stderr: 'inherit', + }).status().then(({ code }) => { + Deno.exit(code) + }) +} diff --git a/lib/tsconfig-deno.json b/lib/tsconfig-deno.json new file mode 100644 index 00000000000..78884b953d9 --- /dev/null +++ b/lib/tsconfig-deno.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "module": "es2020", // Allow the "import.meta" syntax + "target": "es2017", // Allow calling APIs such as "Object.entries" + "strict": true, + }, + "exclude": [ + "npm", + ], +} diff --git a/lib/tsconfig.json b/lib/tsconfig.json index 3ae74009ee1..64585b60a38 100644 --- a/lib/tsconfig.json +++ b/lib/tsconfig.json @@ -2,6 +2,9 @@ "compilerOptions": { "module": "CommonJS", // Allow the "import assignment" syntax "target": "es2017", // Allow calling APIs such as "Object.entries" - "strict": true - } + "strict": true, + }, + "exclude": [ + "deno", + ], } diff --git a/scripts/esbuild.js b/scripts/esbuild.js index 241033c0acb..b1bb464835f 100644 --- a/scripts/esbuild.js +++ b/scripts/esbuild.js @@ -237,7 +237,7 @@ const buildDenoLib = (esbuildPath) => { path.join(repoDir, 'lib', 'deno', 'mod.ts'), '--bundle', '--outfile=' + path.join(denoDir, 'mod.js'), - '--target=es2020', + '--target=esnext', '--define:ESBUILD_VERSION=' + JSON.stringify(version), '--platform=neutral', '--log-level=warning',