rockstar-strudel 1.0.1 → 1.0.2
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/README.md +22 -1
- package/package.json +1 -1
- package/src/index.js +19 -0
- package/PLAN.md +0 -227
package/README.md
CHANGED
|
@@ -22,8 +22,11 @@ returned as JS `number`; everything else is returned as a `string`.
|
|
|
22
22
|
|
|
23
23
|
## Using it in strudel.cc
|
|
24
24
|
|
|
25
|
+
This package is ESM-only. In `strudel.cc`, use dynamic `import()` rather than
|
|
26
|
+
static `import ... from`, since the editor input is not a module file.
|
|
27
|
+
|
|
25
28
|
```js
|
|
26
|
-
|
|
29
|
+
const { init, rockstar } = await import('https://esm.sh/rockstar-strudel')
|
|
27
30
|
|
|
28
31
|
// Pre-warm the WASM engine while other code loads (optional but recommended)
|
|
29
32
|
await init()
|
|
@@ -43,6 +46,24 @@ const notes = await rockstar`
|
|
|
43
46
|
note(notes).sound("piano").slow(2)
|
|
44
47
|
```
|
|
45
48
|
|
|
49
|
+
Standalone browser example:
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
<script type="module">
|
|
53
|
+
import { init, rockstar } from 'https://esm.sh/rockstar-strudel'
|
|
54
|
+
|
|
55
|
+
await init()
|
|
56
|
+
|
|
57
|
+
const notes = await rockstar`
|
|
58
|
+
Tommy was 60
|
|
59
|
+
Build Tommy up, up, up, up
|
|
60
|
+
Shout Tommy
|
|
61
|
+
`
|
|
62
|
+
|
|
63
|
+
console.log(notes)
|
|
64
|
+
</script>
|
|
65
|
+
```
|
|
66
|
+
|
|
46
67
|
### Template interpolations
|
|
47
68
|
|
|
48
69
|
JavaScript values can be spliced into the source, letting you parameterise
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rockstar-strudel",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "Run Rockstar lang programs via the Starship WASM engine, returning output as a JS array. Designed for use in the strudel.cc live-coding REPL.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/index.js
CHANGED
|
@@ -108,10 +108,29 @@ async function _loadRunner(dotnetUrl) {
|
|
|
108
108
|
`Add your CDN prefix to ALLOWED_URL_PREFIXES in src/index.js if needed.`
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
|
+
const dotnetOrigin = new URL(dotnetUrl).origin;
|
|
111
112
|
// eslint-disable-next-line no-eval -- dynamic import from a runtime URL
|
|
112
113
|
const { dotnet } = await import(/* webpackIgnore: true */ dotnetUrl);
|
|
113
114
|
const { getAssemblyExports, getConfig } = await dotnet
|
|
114
115
|
.withDiagnosticTracing(false)
|
|
116
|
+
.withResourceLoader((type, name, defaultUri, integrity) => {
|
|
117
|
+
const resourceUrl = new URL(defaultUri, dotnetUrl);
|
|
118
|
+
|
|
119
|
+
if (resourceUrl.origin === window.location.origin) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (resourceUrl.origin !== dotnetOrigin) {
|
|
124
|
+
throw new Error(
|
|
125
|
+
`Unexpected runtime asset origin for ${name}: "${resourceUrl.origin}".`
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return fetch(resourceUrl, {
|
|
130
|
+
credentials: 'omit',
|
|
131
|
+
integrity,
|
|
132
|
+
});
|
|
133
|
+
})
|
|
115
134
|
.create();
|
|
116
135
|
const config = getConfig();
|
|
117
136
|
const exports = await getAssemblyExports(config.mainAssemblyName);
|
package/PLAN.md
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
# Plan: shipping `rockstar-strudel` from a RockstarLang/rockstar fork
|
|
2
|
-
|
|
3
|
-
This document describes every step needed to wire the existing Starship WASM
|
|
4
|
-
engine up to the `rockstar` template-tag module in this repo so that
|
|
5
|
-
strudel.cc users can simply write:
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
import { init, rockstar } from 'https://esm.sh/rockstar-strudel'
|
|
9
|
-
await init('https://<your-username>.github.io/rockstar/wasm/wwwroot/_framework/dotnet.js')
|
|
10
|
-
const data = await rockstar`Shout 42`
|
|
11
|
-
// data === [42]
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
## Background: why anything needs to change
|
|
17
|
-
|
|
18
|
-
The Starship engine is already built and running at
|
|
19
|
-
`https://codewithrockstar.com/wasm/`. The issue is that browsers enforce the
|
|
20
|
-
**Same-Origin Policy**: a page on `strudel.cc` cannot load a JS/WASM module
|
|
21
|
-
from `codewithrockstar.com` unless that server explicitly opts in via a CORS
|
|
22
|
-
header (`Access-Control-Allow-Origin: *`).
|
|
23
|
-
|
|
24
|
-
`codewithrockstar.com` uses a **custom domain**, which means CORS headers must
|
|
25
|
-
be configured at the CDN/DNS level (e.g. Cloudflare) by the site owner — a
|
|
26
|
-
change that can't be made via a GitHub PR to the repo.
|
|
27
|
-
|
|
28
|
-
However, **GitHub Pages on `*.github.io` domains serves all static assets with
|
|
29
|
-
`Access-Control-Allow-Origin: *` built in**, at no extra configuration cost.
|
|
30
|
-
This means a fork of the repo deployed to GitHub Pages at its default
|
|
31
|
-
`<you>.github.io/rockstar` URL has CORS working immediately, with no CDN
|
|
32
|
-
setup needed.
|
|
33
|
-
|
|
34
|
-
The complete build pipeline (`.NET` WASM compile → Jekyll site build →
|
|
35
|
-
GitHub Pages deploy) is already automated in the repo's GitHub Actions
|
|
36
|
-
workflows, so enabling it on a fork is a matter of enabling Pages in the
|
|
37
|
-
fork's settings.
|
|
38
|
-
|
|
39
|
-
---
|
|
40
|
-
|
|
41
|
-
## Option A — Fork and host on GitHub Pages (unblocked today)
|
|
42
|
-
|
|
43
|
-
This is the fastest path. No CDN, no Cloudflare, no extra accounts needed.
|
|
44
|
-
|
|
45
|
-
### Step 1 — Fork `RockstarLang/rockstar`
|
|
46
|
-
|
|
47
|
-
Fork it on GitHub (keep it **public** so the free GitHub Pages tier is
|
|
48
|
-
available).
|
|
49
|
-
|
|
50
|
-
### Step 2 — Enable GitHub Pages on the fork
|
|
51
|
-
|
|
52
|
-
1. Go to your fork → **Settings → Pages**
|
|
53
|
-
2. Under *Build and deployment*, set Source to **GitHub Actions**
|
|
54
|
-
(not a branch — the workflow handles deployment itself)
|
|
55
|
-
3. Save.
|
|
56
|
-
|
|
57
|
-
### Step 3 — Trigger the first build
|
|
58
|
-
|
|
59
|
-
The build pipeline is three chained workflows:
|
|
60
|
-
|
|
61
|
-
```
|
|
62
|
-
build-rockstar-2.0
|
|
63
|
-
└─► release-rockstar-engine
|
|
64
|
-
└─► build-and-deploy-codewithrockstar.com → GitHub Pages
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
Trigger the first one manually:
|
|
68
|
-
- Go to **Actions → build-rockstar-2.0 → Run workflow** (pick `main`)
|
|
69
|
-
|
|
70
|
-
This will:
|
|
71
|
-
1. Build the Starship .NET engine and run its tests
|
|
72
|
-
2. Compile the WASM with `dotnet publish Starship/Rockstar.Wasm -c Release`
|
|
73
|
-
3. Copy the WASM into the Jekyll site and deploy it to GitHub Pages
|
|
74
|
-
|
|
75
|
-
After a few minutes your site will be live at:
|
|
76
|
-
```
|
|
77
|
-
https://<your-username>.github.io/rockstar/
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
And the WASM loader will be at:
|
|
81
|
-
```
|
|
82
|
-
https://<your-username>.github.io/rockstar/wasm/wwwroot/_framework/dotnet.js
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### Step 4 — Point `rockstar-strudel` at your fork
|
|
86
|
-
|
|
87
|
-
Update `DEFAULT_DOTNET_URL` in `src/index.js`:
|
|
88
|
-
|
|
89
|
-
```js
|
|
90
|
-
const DEFAULT_DOTNET_URL =
|
|
91
|
-
'https://<your-username>.github.io/rockstar/wasm/wwwroot/_framework/dotnet.js';
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
Or leave the default pointing at `codewithrockstar.com` and let users pass
|
|
95
|
-
their own URL via `init()`:
|
|
96
|
-
|
|
97
|
-
```js
|
|
98
|
-
await init('https://<your-username>.github.io/rockstar/wasm/wwwroot/_framework/dotnet.js')
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Step 5 — Publish the npm package
|
|
102
|
-
|
|
103
|
-
```bash
|
|
104
|
-
cd rockstar-strudel
|
|
105
|
-
npm publish --access public
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
Users can then import from `https://esm.sh/rockstar-strudel`.
|
|
109
|
-
|
|
110
|
-
---
|
|
111
|
-
|
|
112
|
-
## Option B — PR / issue to `RockstarLang/rockstar` (long-term fix)
|
|
113
|
-
|
|
114
|
-
A PR to the repo **cannot** fix CORS for the custom domain by itself — that
|
|
115
|
-
change must be made in the Cloudflare (or equivalent CDN) dashboard by the
|
|
116
|
-
site owner. The most useful thing you can do is:
|
|
117
|
-
|
|
118
|
-
1. **Open an issue** explaining the strudel.cc use case and asking them to add
|
|
119
|
-
`Access-Control-Allow-Origin: *` to the `/wasm/` path in their CDN config.
|
|
120
|
-
A single Cloudflare Transform Rule would fix it permanently for all users.
|
|
121
|
-
|
|
122
|
-
2. Optionally include a **PR that adds a `_headers` file** as a signal of
|
|
123
|
-
intent (it has no effect on a custom domain, but documents the desired
|
|
124
|
-
config):
|
|
125
|
-
|
|
126
|
-
```
|
|
127
|
-
# codewithrockstar.com/_headers
|
|
128
|
-
/wasm/*
|
|
129
|
-
Access-Control-Allow-Origin: *
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
Once the upstream site adds the header, update `DEFAULT_DOTNET_URL` back to
|
|
133
|
-
`https://codewithrockstar.com/wasm/wwwroot/_framework/dotnet.js` so users
|
|
134
|
-
get the canonical URL by default.
|
|
135
|
-
|
|
136
|
-
---
|
|
137
|
-
|
|
138
|
-
## Summary
|
|
139
|
-
|
|
140
|
-
| Path | Works today? | Effort |
|
|
141
|
-
|---|---|---|
|
|
142
|
-
| Fork → GitHub Pages (Option A) | ✅ Yes, ~20 min | Fork + enable Pages + trigger build |
|
|
143
|
-
| PR/issue to upstream (Option B) | ⏳ Depends on maintainer | Low effort, uncertain timeline |
|
|
144
|
-
|
|
145
|
-
**Do both**: use Option A to unblock yourself right now, open an upstream
|
|
146
|
-
issue (Option B) so the permanent fix lands in `codewithrockstar.com`.
|
|
147
|
-
|
|
148
|
-
---
|
|
149
|
-
|
|
150
|
-
## Local smoke-test (optional but recommended)
|
|
151
|
-
|
|
152
|
-
To verify `src/index.js` against a local WASM build before publishing:
|
|
153
|
-
|
|
154
|
-
### Build the WASM locally
|
|
155
|
-
|
|
156
|
-
You need the **.NET 9 SDK** (`dotnet --version` should show `9.x`).
|
|
157
|
-
|
|
158
|
-
```bash
|
|
159
|
-
cd Starship
|
|
160
|
-
dotnet workload install wasm-tools
|
|
161
|
-
dotnet publish Rockstar.Wasm -c Release -o ../wasm-publish
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
The output in `../wasm-publish/wwwroot/` contains:
|
|
165
|
-
|
|
166
|
-
```
|
|
167
|
-
_framework/
|
|
168
|
-
dotnet.js ← the JS loader
|
|
169
|
-
dotnet.native.js
|
|
170
|
-
dotnet.runtime.js
|
|
171
|
-
dotnet.wasm ← the .NET runtime (~7 MB, AOT-compiled in Release)
|
|
172
|
-
Rockstar.Wasm.wasm ← the Rockstar engine
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### Run the integration test
|
|
176
|
-
|
|
177
|
-
Create a minimal HTML file in the same directory as the WASM:
|
|
178
|
-
|
|
179
|
-
```html
|
|
180
|
-
<!-- wasm-publish/wwwroot/test.html -->
|
|
181
|
-
<script type="module">
|
|
182
|
-
import { init, rockstar } from '/path/to/rockstar-strudel/src/index.js'
|
|
183
|
-
|
|
184
|
-
// localhost is in the allowed URL list, so no allowlist update needed
|
|
185
|
-
await init('http://localhost:8080/_framework/dotnet.js')
|
|
186
|
-
|
|
187
|
-
const result = await rockstar`
|
|
188
|
-
My heart is 123
|
|
189
|
-
Let your love be 456
|
|
190
|
-
Put 789 into the night
|
|
191
|
-
Shout my heart. Scream your love. Whisper the night.
|
|
192
|
-
`
|
|
193
|
-
console.assert(JSON.stringify(result) === '[123,456,789]',
|
|
194
|
-
'Expected [123,456,789], got ' + JSON.stringify(result))
|
|
195
|
-
document.body.textContent = JSON.stringify(result)
|
|
196
|
-
</script>
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
Serve from localhost (same origin as the WASM avoids CORS entirely):
|
|
200
|
-
|
|
201
|
-
```bash
|
|
202
|
-
cd wasm-publish/wwwroot
|
|
203
|
-
npx serve -p 8080
|
|
204
|
-
# open http://localhost:8080/test.html
|
|
205
|
-
```
|
|
206
|
-
|
|
207
|
-
---
|
|
208
|
-
|
|
209
|
-
## Summary checklist
|
|
210
|
-
|
|
211
|
-
- [ ] Fork `RockstarLang/rockstar` on GitHub (keep public)
|
|
212
|
-
- [ ] Fork Settings → Pages → Source: **GitHub Actions**
|
|
213
|
-
- [ ] Actions → `build-rockstar-2.0` → **Run workflow** (triggers the full chain)
|
|
214
|
-
- [ ] Wait for Pages deployment; note your URL: `https://<you>.github.io/rockstar/`
|
|
215
|
-
- [ ] Update `DEFAULT_DOTNET_URL` in `src/index.js` to your fork's WASM URL
|
|
216
|
-
(or let users pass it to `init()`)
|
|
217
|
-
- [ ] `npm publish --access public` the `rockstar-strudel` package
|
|
218
|
-
- [ ] Verify in strudel.cc:
|
|
219
|
-
```js
|
|
220
|
-
import { init, rockstar } from 'https://esm.sh/rockstar-strudel'
|
|
221
|
-
await init('https://<you>.github.io/rockstar/wasm/wwwroot/_framework/dotnet.js')
|
|
222
|
-
const data = await rockstar`Shout 42` // [42]
|
|
223
|
-
```
|
|
224
|
-
- [ ] Open an issue on `RockstarLang/rockstar` asking them to add
|
|
225
|
-
`Access-Control-Allow-Origin: *` to `/wasm/` at their CDN level, so
|
|
226
|
-
the default URL can eventually point back at `codewithrockstar.com`
|
|
227
|
-
|