Skip to content

Commit aeae3cf

Browse files
committed
fix #1913: enable the CLI with Deno
1 parent 9d5fdb6 commit aeae3cf

File tree

6 files changed

+39
-4
lines changed

6 files changed

+39
-4
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@
2020
╵ ~~~~~~
2121
```
2222

23+
* Enable esbuild's CLI with Deno ([#1913](https://github.com/evanw/esbuild/issues/1913))
24+
25+
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:
26+
27+
```
28+
deno run --allow-all "https://deno.land/x/[email protected]/mod.js" --version
29+
```
30+
2331
## 0.14.10
2432

2533
* Enable tree shaking of classes with lowered static fields ([#175](https://github.com/evanw/esbuild/issues/175))

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ node-unref-tests: | scripts/node_modules
9393
node scripts/node-unref-tests.js
9494

9595
lib-typecheck: | lib/node_modules
96-
cd lib && node_modules/.bin/tsc -noEmit -p .
96+
cd lib && node_modules/.bin/tsc -noEmit -p tsconfig.json
97+
cd lib && node_modules/.bin/tsc -noEmit -p tsconfig-deno.json
9798

9899
# End-to-end tests
99100
test-e2e: test-e2e-npm test-e2e-pnpm test-e2e-yarn-berry

lib/deno/mod.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,3 +328,16 @@ let ensureServiceIsRunning = (): Promise<Service> => {
328328
}
329329
return longLivedService
330330
}
331+
332+
// If we're called as the main script, forward the CLI to the underlying executable
333+
if (import.meta.main) {
334+
Deno.run({
335+
cmd: [await install()].concat(Deno.args),
336+
cwd: defaultWD,
337+
stdin: 'inherit',
338+
stdout: 'inherit',
339+
stderr: 'inherit',
340+
}).status().then(({ code }) => {
341+
Deno.exit(code)
342+
})
343+
}

lib/tsconfig-deno.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"compilerOptions": {
3+
"module": "es2020", // Allow the "import.meta" syntax
4+
"target": "es2017", // Allow calling APIs such as "Object.entries"
5+
"strict": true,
6+
},
7+
"exclude": [
8+
"npm",
9+
],
10+
}

lib/tsconfig.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"compilerOptions": {
33
"module": "CommonJS", // Allow the "import assignment" syntax
44
"target": "es2017", // Allow calling APIs such as "Object.entries"
5-
"strict": true
6-
}
5+
"strict": true,
6+
},
7+
"exclude": [
8+
"deno",
9+
],
710
}

scripts/esbuild.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ const buildDenoLib = (esbuildPath) => {
237237
path.join(repoDir, 'lib', 'deno', 'mod.ts'),
238238
'--bundle',
239239
'--outfile=' + path.join(denoDir, 'mod.js'),
240-
'--target=es2020',
240+
'--target=esnext',
241241
'--define:ESBUILD_VERSION=' + JSON.stringify(version),
242242
'--platform=neutral',
243243
'--log-level=warning',

0 commit comments

Comments
 (0)