@flowscripter/template-bun-executable 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/check-bun-dependencies.yml +9 -0
- package/.github/workflows/lint-pr-message.yml +11 -0
- package/.github/workflows/release-bun-executable.yml +10 -0
- package/.github/workflows/validate-bun-executable-pr.yml +8 -0
- package/LICENSE +21 -0
- package/README.md +97 -0
- package/bun.lock +35 -0
- package/functional_tests/README.md +23 -0
- package/functional_tests/features/environment.py +9 -0
- package/functional_tests/features/executable.feature +9 -0
- package/functional_tests/features/steps/executable.py +18 -0
- package/functional_tests/features/support/pexpect_wrapper.py +45 -0
- package/functional_tests/pip-requirements.txt +2 -0
- package/index.ts +4 -0
- package/package.json +19 -0
- package/src/hello.ts +12 -0
- package/tests/hello_test.ts +9 -0
- package/tsconfig.json +27 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Flowscripter
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# template-bun-executable
|
|
2
|
+
|
|
3
|
+
[](https://github.com/flowscripter/template-bun-executable/releases)
|
|
4
|
+
[](https://github.com/flowscripter/template-bun-executable/actions/workflows/release-bun-executable.yml)
|
|
5
|
+
[](https://codecov.io/gh/flowscripter/template-bun-executable)
|
|
6
|
+
[](https://flowscripter.github.io/template-bun-executable/index.html)
|
|
7
|
+
[](https://github.com/flowscripter/template-bun-executable/blob/main/LICENSE)
|
|
8
|
+
|
|
9
|
+
> Project template for a cross-platform Bun executable with ffi native library
|
|
10
|
+
> and Bun library dependencies.
|
|
11
|
+
|
|
12
|
+
## Template Usage
|
|
13
|
+
|
|
14
|
+
Create a new Bun project using this as a template:
|
|
15
|
+
|
|
16
|
+
`bun create @flowscripter/template-bun-executable`
|
|
17
|
+
|
|
18
|
+
## Bun Module Usage
|
|
19
|
+
|
|
20
|
+
Add the module:
|
|
21
|
+
|
|
22
|
+
`bun add @flowscripter/template-bun-executable`
|
|
23
|
+
|
|
24
|
+
Use the module:
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import { world } from "@flowscripter/template-deno-executable";
|
|
28
|
+
|
|
29
|
+
world();
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Binary Executable Usage
|
|
33
|
+
|
|
34
|
+
Download and extract zip from:
|
|
35
|
+
https://github.com/flowscripter/template-bun-executable/releases
|
|
36
|
+
|
|
37
|
+
Run the executable: `./template-bun-executable`
|
|
38
|
+
|
|
39
|
+
**NOTE**: The executable is 10's of megabytes in size as the entire Bun runtime
|
|
40
|
+
is included.
|
|
41
|
+
|
|
42
|
+
**NOTE**: Due to this issue https://github.com/oven-sh/bun/issues/7208 the MacOS
|
|
43
|
+
executable is neither signed nor notarised. This means a "Developer cannot be
|
|
44
|
+
verified" error will be displayed when the CLI it is executed. This requires
|
|
45
|
+
explicitly allowing the CLI to be executed via:
|
|
46
|
+
|
|
47
|
+
_"System Settings" > "Privacy & Security" > "Security" > "Allow Anyway"_
|
|
48
|
+
|
|
49
|
+
## Functional Tests
|
|
50
|
+
|
|
51
|
+
Refer to [functional_tests/README.md](functional_tests/README.md)
|
|
52
|
+
|
|
53
|
+
## Development
|
|
54
|
+
|
|
55
|
+
Test:
|
|
56
|
+
|
|
57
|
+
`bun test`
|
|
58
|
+
|
|
59
|
+
Compile binary:
|
|
60
|
+
|
|
61
|
+
`bun build index.ts --compile --outfile /tmp/template-bun-executable`
|
|
62
|
+
|
|
63
|
+
**NOTE**: The following tasks use Deno as it excels at these and Bun does not
|
|
64
|
+
currently provide such functionality:
|
|
65
|
+
|
|
66
|
+
Format:
|
|
67
|
+
|
|
68
|
+
`deno fmt`
|
|
69
|
+
|
|
70
|
+
Lint:
|
|
71
|
+
|
|
72
|
+
`deno lint index.ts src/ tests/`
|
|
73
|
+
|
|
74
|
+
Generate HTML API Documentation:
|
|
75
|
+
|
|
76
|
+
`deno doc --html --name=template-bun-executable index.ts`
|
|
77
|
+
|
|
78
|
+
## Documentation
|
|
79
|
+
|
|
80
|
+
### Overview
|
|
81
|
+
|
|
82
|
+
Sample mermaid diagram to test rendering in markdown:
|
|
83
|
+
|
|
84
|
+
```mermaid
|
|
85
|
+
classDiagram
|
|
86
|
+
Foo <|-- Bar
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### API
|
|
90
|
+
|
|
91
|
+
Link to auto-generated API docs:
|
|
92
|
+
|
|
93
|
+
[API Documentation](https://flowscripter.github.io/template-bun-executable/index.html)
|
|
94
|
+
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
MIT © Flowscripter
|
package/bun.lock
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"workspaces": {
|
|
4
|
+
"": {
|
|
5
|
+
"name": "@flowscripter/template-bun-executable",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"@flowscripter/template-bun-library": "1.0.3",
|
|
8
|
+
"@flowscripter/template-bun-rust-library": "1.0.6",
|
|
9
|
+
},
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@types/bun": "latest",
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"typescript": "^5.0.0",
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
},
|
|
18
|
+
"packages": {
|
|
19
|
+
"@flowscripter/template-bun-library": ["@flowscripter/template-bun-library@1.0.3", "", { "peerDependencies": { "typescript": "^5.7.3" } }, "sha512-0AQLu8hGf+dzT+0m7EbUG8lJadzTcUROzp3Z8swlKcqhTBuIZrb+Vg9fyWw1M8YWsk9Jk/ZaXjb00teAI5D6Zg=="],
|
|
20
|
+
|
|
21
|
+
"@flowscripter/template-bun-rust-library": ["@flowscripter/template-bun-rust-library@1.0.6", "", { "peerDependencies": { "typescript": "^5.0.0" } }, "sha512-jFE005w91y1zen81KHU6wfuf2xrSFm5+zo75GCuI6GSolfnfGWLaDuLwQce/gvGegCz0dDvj4WxmQMMH9OrOzA=="],
|
|
22
|
+
|
|
23
|
+
"@types/bun": ["@types/bun@1.2.2", "", { "dependencies": { "bun-types": "1.2.2" } }, "sha512-tr74gdku+AEDN5ergNiBnplr7hpDp3V1h7fqI2GcR/rsUaM39jpSeKH0TFibRvU0KwniRx5POgaYnaXbk0hU+w=="],
|
|
24
|
+
|
|
25
|
+
"@types/node": ["@types/node@22.13.2", "", { "dependencies": { "undici-types": "~6.20.0" } }, "sha512-Z+r8y3XL9ZpI2EY52YYygAFmo2/oWfNSj4BCpAXE2McAexDk8VcnBMGC9Djn9gTKt4d2T/hhXqmPzo4hfIXtTg=="],
|
|
26
|
+
|
|
27
|
+
"@types/ws": ["@types/ws@8.5.14", "", { "dependencies": { "@types/node": "*" } }, "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw=="],
|
|
28
|
+
|
|
29
|
+
"bun-types": ["bun-types@1.2.2", "", { "dependencies": { "@types/node": "*", "@types/ws": "~8.5.10" } }, "sha512-RCbMH5elr9gjgDGDhkTTugA21XtJAy/9jkKe/G3WR2q17VPGhcquf9Sir6uay9iW+7P/BV0CAHA1XlHXMAVKHg=="],
|
|
30
|
+
|
|
31
|
+
"typescript": ["typescript@5.7.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw=="],
|
|
32
|
+
|
|
33
|
+
"undici-types": ["undici-types@6.20.0", "", {}, "sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg=="],
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## Executable Functional Tests
|
|
2
|
+
|
|
3
|
+
#### Setup
|
|
4
|
+
|
|
5
|
+
Ensure the executable is built:
|
|
6
|
+
|
|
7
|
+
bun build ../index.ts --compile --outfile /tmp/template-bun-executable
|
|
8
|
+
|
|
9
|
+
Install requirements:
|
|
10
|
+
|
|
11
|
+
pip3 install -r pip-requirements.txt
|
|
12
|
+
|
|
13
|
+
#### Testing
|
|
14
|
+
|
|
15
|
+
Run the functional tests:
|
|
16
|
+
|
|
17
|
+
export EXECUTABLE=/tmp/template-bun-executable
|
|
18
|
+
behave
|
|
19
|
+
|
|
20
|
+
To run with logging output from the test steps (this is the best set of
|
|
21
|
+
arguments I can find):
|
|
22
|
+
|
|
23
|
+
behave --no-logcapture --no-color --logging-level=DEBUG
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Feature: Executable
|
|
2
|
+
|
|
3
|
+
Scenario: Executable success
|
|
4
|
+
When the executable is launched
|
|
5
|
+
Then the executable should complete successfully
|
|
6
|
+
And the executable should have output "Hello"
|
|
7
|
+
And the executable should have output "World"
|
|
8
|
+
And the executable should have output "Hello"
|
|
9
|
+
And the executable should have output "World 4"
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from behave import when, then
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
@when('the executable is launched')
|
|
5
|
+
def step_impl(context):
|
|
6
|
+
context.pexpect_wrapper.start()
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@then('the executable should complete successfully')
|
|
10
|
+
def step_impl(context):
|
|
11
|
+
context.pexpect_wrapper.expect_eof()
|
|
12
|
+
status = context.pexpect_wrapper.complete()
|
|
13
|
+
assert status == 0, 'unexpected exit status: {}'.format(status)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@then('the executable should have output "{message}"')
|
|
17
|
+
def step_impl(context, message):
|
|
18
|
+
context.pexpect_wrapper.expect(message)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
from pexpect.popen_spawn import PopenSpawn
|
|
2
|
+
from pexpect import EOF
|
|
3
|
+
import logging
|
|
4
|
+
log = logging.getLogger("pexpect_wrapper")
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class PExpectWrapper:
|
|
8
|
+
|
|
9
|
+
def __init__(self, executable):
|
|
10
|
+
self.executable = executable
|
|
11
|
+
self.child = None
|
|
12
|
+
self.output = None
|
|
13
|
+
|
|
14
|
+
def start(self):
|
|
15
|
+
assert self.child is None
|
|
16
|
+
|
|
17
|
+
self.child = PopenSpawn(self.executable, encoding='utf-8')
|
|
18
|
+
|
|
19
|
+
def expect(self, message):
|
|
20
|
+
assert self.child is not None
|
|
21
|
+
|
|
22
|
+
found = ''
|
|
23
|
+
while len(self.output) > 0:
|
|
24
|
+
next_line = self.output.pop(0)
|
|
25
|
+
log.debug('looking for "{}" in "{}"'.format(message, next_line))
|
|
26
|
+
if message in next_line:
|
|
27
|
+
found = next_line
|
|
28
|
+
break
|
|
29
|
+
|
|
30
|
+
assert found != '', 'expected {} in output'.format(message)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def expect_eof(self):
|
|
34
|
+
assert self.child is not None
|
|
35
|
+
|
|
36
|
+
self.child.expect(EOF)
|
|
37
|
+
|
|
38
|
+
def complete(self):
|
|
39
|
+
assert self.child is not None
|
|
40
|
+
|
|
41
|
+
exit_status = self.child.wait()
|
|
42
|
+
|
|
43
|
+
self.output = self.child.before.split('\n')
|
|
44
|
+
|
|
45
|
+
return exit_status
|
package/index.ts
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flowscripter/template-bun-executable",
|
|
3
|
+
"module": "index.ts",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/bun": "latest"
|
|
11
|
+
},
|
|
12
|
+
"peerDependencies": {
|
|
13
|
+
"typescript": "^5.0.0"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@flowscripter/template-bun-library": "1.0.3",
|
|
17
|
+
"@flowscripter/template-bun-rust-library": "1.0.6"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/hello.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as bunLib from "@flowscripter/template-bun-library";
|
|
2
|
+
import * as rustLib from "@flowscripter/template-bun-rust-library";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Logs out some greetings.
|
|
6
|
+
*/
|
|
7
|
+
export function hello(): void {
|
|
8
|
+
console.info("Hello");
|
|
9
|
+
bunLib.world();
|
|
10
|
+
console.info("Hello");
|
|
11
|
+
rustLib.world();
|
|
12
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
// Enable latest features
|
|
4
|
+
"lib": ["ESNext", "DOM"],
|
|
5
|
+
"target": "ESNext",
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"moduleDetection": "force",
|
|
8
|
+
"jsx": "react-jsx",
|
|
9
|
+
"allowJs": true,
|
|
10
|
+
|
|
11
|
+
// Bundler mode
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
// Best practices
|
|
18
|
+
"strict": true,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noFallthroughCasesInSwitch": true,
|
|
21
|
+
|
|
22
|
+
// Some stricter flags (disabled by default)
|
|
23
|
+
"noUnusedLocals": false,
|
|
24
|
+
"noUnusedParameters": false,
|
|
25
|
+
"noPropertyAccessFromIndexSignature": false
|
|
26
|
+
}
|
|
27
|
+
}
|