Skip to content

Commit d4b0b2d

Browse files
committed
first commit
0 parents  commit d4b0b2d

File tree

7 files changed

+265
-0
lines changed

7 files changed

+265
-0
lines changed

.gitignore

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# See http://help.github.com/ignore-files/ for more about ignoring files.
2+
3+
# compiled output
4+
/dist
5+
/tmp
6+
/out-tsc
7+
8+
# Runtime data
9+
pids
10+
*.pid
11+
*.seed
12+
*.pid.lock
13+
14+
# Directory for instrumented libs generated by jscoverage/JSCover
15+
lib-cov
16+
17+
# Coverage directory used by tools like istanbul
18+
coverage
19+
20+
# nyc test coverage
21+
.nyc_output
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# Bower dependency directory (https://bower.io/)
27+
bower_components
28+
29+
# node-waf configuration
30+
.lock-wscript
31+
32+
# IDEs and editors
33+
.idea
34+
.project
35+
.classpath
36+
.c9/
37+
*.launch
38+
.settings/
39+
*.sublime-workspace
40+
41+
# IDE - VSCode
42+
.vscode/*
43+
!.vscode/settings.json
44+
!.vscode/tasks.json
45+
!.vscode/launch.json
46+
!.vscode/extensions.json
47+
48+
# misc
49+
.sass-cache
50+
connect.lock
51+
typings
52+
53+
# Logs
54+
logs
55+
*.log
56+
npm-debug.log*
57+
yarn-debug.log*
58+
yarn-error.log*
59+
60+
61+
# Dependency directories
62+
node_modules/
63+
jspm_packages/
64+
65+
# Optional npm cache directory
66+
.npm
67+
68+
# Optional eslint cache
69+
.eslintcache
70+
71+
# Optional REPL history
72+
.node_repl_history
73+
74+
# Output of 'npm pack'
75+
*.tgz
76+
77+
# Yarn Integrity file
78+
.yarn-integrity
79+
80+
# dotenv environment variables file
81+
.env
82+
83+
# next.js build output
84+
.next
85+
86+
# Lerna
87+
lerna-debug.log
88+
89+
# System Files
90+
.DS_Store
91+
Thumbs.db
92+
93+
# Executables
94+
*.exe
95+
*.out
96+
*.app
97+
*.i*86
98+
*.x86_64
99+
*.hex

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# How to Native executable application using JavaScript/TypeScript and CoffeeScript
2+
3+
Hello, everyone. What about it? This tutorial shows how to create a single-line executable using JavaScript, CoffeeScript, and TypeScript programming languages, right? So, It must be **Deno**, and **Bun** are examples of JavaScript or TypeScript engines.
4+
5+
We have you create single-line executable applications for this feature allows the distribution of a Deno and Bun application conveniently to a system. How about this step-by-step?
6+
7+
## `JavaScript/TypeScript`
8+
9+
It can be TypeScript or JavaScript source file.
10+
11+
* <h3>Deno</h3>
12+
13+
Cross-compiling to different target architectures is supported using the `--target flag`. On the first invocation of `deno compile`, Deno will download the relevant binary and cache it in `$DENO_DIR`. You can cross-compile binaries for other platforms by using the `--target` flag.
14+
15+
```bash
16+
# Windows
17+
$ deno compile --target x86_64-pc-windows-msvc src/format.js
18+
19+
# Apple macOS
20+
$ deno compile --target x86_64-apple-darwin src/format.js
21+
$ deno compile --target aarch64-apple-darwin src/format.js
22+
23+
# Linux
24+
$ deno compile --target x86_64-unknown-linux-gnu src/format.js
25+
$ deno compile --target aarch64-unknown-linux-gnu src/format.js
26+
```
27+
28+
**Supported Targets**: Deno supports cross compiling to all targets regardless of the host platform.
29+
30+
| Operating System | Architecture | Target |
31+
|:-:|:-:|:-:|
32+
| Windows | x86_64 | `x86_64-pc-windows-msvc` |
33+
| macOS | x86_64 | `x86_64-apple-darwin` |
34+
| macOS | ARM64 | `aarch64-apple-darwin` |
35+
| Linux | x86_64 | `x86_64-unknown-linux-gnu` |
36+
| Linux | ARM64 | `aarch64-unknown-linux-gnu` |
37+
38+
**Learn more** please: [Deno compile](https://docs.deno.com/runtime/reference/cli/compile)
39+
40+
* <h3>Bun</h3>
41+
42+
Bun's bundler implements a `--compile` flag for generating a standalone binary from a TypeScript or JavaScript file.
43+
44+
```bash
45+
# Default operating system
46+
$ bun build ./src/format.js --compile --outfile format
47+
```
48+
49+
This bundles `format.js` into an executable that can be executed directly:
50+
51+
```bash
52+
$ ./format
53+
```
54+
55+
All imported files and packages are bundled into the executable, along with a copy of the Bun runtime.
56+
57+
The `--target` flag lets you compile your standalone executable for a different operating system, architecture, or version of Bun than the machine you're running bun build on.
58+
59+
```bash
60+
# Windows
61+
$ bun build --compile --target=bun-windows-x64 ./src/format.js --outfile format
62+
$ bun build --compile --target=bun-windows-x64-baseline ./src/format.js --outfile format
63+
$ bun build --compile --target=bun-windows-x64-modern ./src/format.js --outfile format
64+
65+
# Apple macOS
66+
$ bun build --compile --target=bun-darwin-arm64 ./src/format.js --outfile format
67+
$ bun build --compile --target=bun-darwin-x64 ./src/format.js --outfile format
68+
69+
# Linux
70+
$ bun build --compile --target=bun-linux-x64 ./src/format.js --outfile format
71+
$ bun build --compile --target=bun-linux-x64-baseline ./src/format.js --outfile format
72+
$ bun build --compile --target=bun-linux-x64-modern ./src/format.js --outfile format
73+
# Note: the default architecture is x64 if no architecture is specified.
74+
$ bun build --compile --target=bun-linux-arm64 ./src/format.js --outfile format
75+
```
76+
77+
**Supported Targets**: Bun supports cross compiling to all targets regardless of the host platform.
78+
79+
| Operating System | Architecture | Target |
80+
|:-:|:-:|:-:|
81+
| Windows | x86_64 | `--target=bun-windows-x64` |
82+
| Windows | x86_64 | `--target=bun-windows-x64-baseline` |
83+
| Windows | x86_64 | `--target=bun-windows-x64-modern` |
84+
| macOS | x86_64 | `--target=bun-darwin-x64` |
85+
| macOS | ARM64 | `--target=bun-darwin-arm64` |
86+
| Linux | x86_64 | `--target=bun-linux-x64` |
87+
| Linux | x86_64 | `--target=bun-linux-x64-baseline` |
88+
| Linux | x86_64 | `--target=bun-linux-x64-modern` |
89+
| Linux | ARM64 | `--target=bun-linux-arm64` |
90+
91+
On x64 platforms, Bun uses SIMD optimizations which require a modern CPU supporting AVX2 instructions. The `-baseline` build of Bun is for older CPUs that don't support these optimizations. Normally, when you install Bun we automatically detect which version to use but this can be harder to do when cross-compiling since you might not know the target CPU. You usually don't need to worry about it on Darwin x64, but it is relevant for Windows x64 and Linux x64. If you or your users see "Illegal instruction" errors, you might need to use the baseline version.
92+
93+
**Learn more** please: [Bun executables](https://bun.sh/docs/bundler/executables)
94+
95+
## `CoffeeScript`
96+
97+
It can be CoffeeScript source file into JavaScript source file using `npm`.
98+
99+
```
100+
# npm
101+
$ npm run coffee
102+
103+
# npx
104+
$ coffee -c -o dist src/format.coffee
105+
```
106+
107+
# Copyright
108+
109+
Copyright (c) 2025 Cyril John Magayaga

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "javascript-executables",
3+
"version": "1.0.0",
4+
"description": "Hello, everyone. What about it? This tutorial shows how to create a single-line executable using JavaScript, CoffeeScript, and TypeScript programming languages, right? So, It must be **Deno**, and **Bun** are examples of JavaScript or TypeScript engines.",
5+
"main": "src/format.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1",
8+
"coffee": "coffee -c -o dist src/format.coffee"
9+
},
10+
"keywords": [],
11+
"author": "",
12+
"license": "ISC",
13+
"dependencies": {
14+
"coffeescript": "^2.7.0"
15+
}
16+
}

src/format.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Single-line executable using TypeScript
2+
# Copyright (c) 2025 Cyril John Magayaga
3+
4+
console.log "Hello, World!"

src/format.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Single-line executable using JavaScript
2+
// Copyright (c) 2025 Cyril John Magayaga
3+
4+
console.log("Hello, World!")

src/format.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Single-line executable using TypeScript
2+
// Copyright (c) 2025 Cyril John Magayaga
3+
4+
console.log("Hello, World!")

0 commit comments

Comments
 (0)