Skip to content

Commit 5b63a57

Browse files
author
Karl Weber
committed
fix: flesh out ImportTS example with fixes from @krodak, and a little documentation.
1 parent a069e3a commit 5b63a57

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

Examples/ImportTS/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Import TypeScript example
2+
3+
Install Development Snapshot toolchain `DEVELOPMENT-SNAPSHOT-2024-07-08-a` or later from [swift.org/install](https://www.swift.org/install/) and run the following commands:
4+
5+
```sh
6+
$ (
7+
set -eo pipefail; \
8+
V="$(swiftc --version | head -n1)"; \
9+
TAG="$(curl -sL "https://raw.githubusercontent.com/swiftwasm/swift-sdk-index/refs/heads/main/v1/tag-by-version.json" | jq -e -r --arg v "$V" '.[$v] | .[-1]')"; \
10+
curl -sL "https://raw.githubusercontent.com/swiftwasm/swift-sdk-index/refs/heads/main/v1/builds/$TAG.json" | \
11+
jq -r '.["swift-sdks"]["wasm32-unknown-wasip1-threads"] | "swift sdk install \"\(.url)\" --checksum \"\(.checksum)\""' | sh -x
12+
)
13+
$ export SWIFT_SDK_ID=$(
14+
V="$(swiftc --version | head -n1)"; \
15+
TAG="$(curl -sL "https://raw.githubusercontent.com/swiftwasm/swift-sdk-index/refs/heads/main/v1/tag-by-version.json" | jq -e -r --arg v "$V" '.[$v] | .[-1]')"; \
16+
curl -sL "https://raw.githubusercontent.com/swiftwasm/swift-sdk-index/refs/heads/main/v1/builds/$TAG.json" | \
17+
jq -r '.["swift-sdks"]["wasm32-unknown-wasip1-threads"]["id"]'
18+
)
19+
```
20+
21+
## Ensure dependencies are installed:
22+
Install node.js separately, Then:
23+
```sh
24+
$ npm install
25+
$ ./build.sh
26+
$ npx serve
27+
```
28+
29+
You should see <strong>Hello, World!</strong>, in your localhost at port 3000.

Examples/ImportTS/build.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
set -euxo pipefail
3+
export SWIFT_SDK_ID=6.1-RELEASE-wasm32-unknown-wasip1-threads
4+
JAVASCRIPTKIT_EXPERIMENTAL_BRIDGEJS=1 swift package --swift-sdk $SWIFT_SDK_ID js

Examples/ImportTS/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
</head>
77

88
<body>
9+
<script type="importmap">
10+
{
11+
"imports": {
12+
"@bjorn3/browser_wasi_shim": "./node_modules/@bjorn3/browser_wasi_shim/dist/index.js"
13+
}
14+
}
15+
</script>
916
<script type="module" src="index.js"></script>
1017

1118
<div id="exports-result"></div>

Examples/ImportTS/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "importts",
3+
"version": "1.0.0",
4+
"description": "``` npm install typescript --save-dev ```",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"license": "ISC",
11+
"devDependencies": {
12+
"@bjorn3/browser_wasi_shim": "^0.3.0",
13+
"typescript": "^5.9.2"
14+
}
15+
}

0 commit comments

Comments
 (0)