@freestyle-sh/with-deno 0.0.2 → 0.0.3

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.
Files changed (2) hide show
  1. package/README.md +81 -5
  2. package/package.json +3 -3
package/README.md CHANGED
@@ -14,11 +14,8 @@ npm install @freestyle-sh/with-deno freestyle-sandboxes
14
14
  import { freestyle, VmSpec } from "freestyle-sandboxes";
15
15
  import { VmDeno } from "@freestyle-sh/with-deno";
16
16
 
17
- const spec = new VmSpec({
18
- with: {
19
- deno: new VmDeno(),
20
- },
21
- });
17
+ const deno = new VmDeno();
18
+ const spec = new VmSpec().with("deno", deno);
22
19
 
23
20
  const { vm } = await freestyle.vms.create({ spec });
24
21
 
@@ -101,6 +98,10 @@ type InstallResult = {
101
98
  Deno has native support for [JSR](https://jsr.io) (JavaScript Registry), which hosts TypeScript-first packages including the Deno standard library.
102
99
 
103
100
  ```typescript
101
+ const deno = new VmDeno();
102
+ const spec = new VmSpec().with("deno", deno);
103
+ const { vm } = await freestyle.vms.create({ spec });
104
+
104
105
  // Install @std/path from JSR
105
106
  await vm.deno.install({ deps: ["jsr:@std/path"] });
106
107
 
@@ -116,6 +117,81 @@ const res = await vm.deno.runCode({
116
117
  });
117
118
  ```
118
119
 
120
+ ## Workspaces and Tasks
121
+
122
+ Use the Deno builder to attach a workspace and run a Deno task as a managed systemd service.
123
+
124
+ ```typescript
125
+ import { Freestyle, VmSpec } from "freestyle-sandboxes";
126
+ import { VmDeno } from "@freestyle-sh/with-deno";
127
+
128
+ const freestyle = new Freestyle();
129
+
130
+ const deno = new VmDeno();
131
+ const workspace = deno.workspace({ path: "/root/app", install: true });
132
+ const appTask = workspace.task("start", {
133
+ env: {
134
+ HOST: "0.0.0.0",
135
+ },
136
+ });
137
+
138
+ const spec = new VmSpec()
139
+ .with("deno", deno)
140
+ .repo("https://github.com/deco-sites/storefront", "/root/app")
141
+ .with("workspace", workspace)
142
+ .with("app", appTask)
143
+ .snapshot()
144
+ .waitFor("curl http://localhost:8000")
145
+ .snapshot();
146
+
147
+ const { repoId } = await freestyle.git.repos.create({
148
+ source: {
149
+ url: "https://github.com/deco-sites/storefront",
150
+ },
151
+ });
152
+
153
+ const domain = `${crypto.randomUUID()}.style.dev`;
154
+
155
+ const { vm } = await freestyle.vms.create({
156
+ spec,
157
+ domains: [{ domain, vmPort: 8000 }],
158
+ git: {
159
+ repos: [{ repo: repoId, path: "/root/app" }],
160
+ },
161
+ });
162
+
163
+ // Task instance comes from .with("app", appTask)
164
+ const recentLogs = await vm.app.logs();
165
+ console.log(recentLogs);
166
+ ```
167
+
168
+ ### Workspace API
169
+
170
+ ```typescript
171
+ const workspace = deno.workspace({
172
+ path: "/root/app",
173
+ install: true,
174
+ });
175
+ ```
176
+
177
+ - `path`: Working directory for `deno install` and task execution.
178
+ - `install`: When true, runs `deno install` in the workspace during VM startup.
179
+
180
+ ### Task API
181
+
182
+ ```typescript
183
+ const task = workspace.task("start", {
184
+ env: { HOST: "0.0.0.0" },
185
+ serviceName: "my-deno-app",
186
+ });
187
+ ```
188
+
189
+ - `name`: Task name from `deno.json`.
190
+ - `env`: Optional environment variables for the task service.
191
+ - `serviceName`: Optional explicit systemd service name.
192
+
193
+ When added to the spec with `.with("app", task)`, you can access task logs with `vm.app.logs()`.
194
+
119
195
  ## Documentation
120
196
 
121
197
  - [Freestyle Documentation](https://docs.freestyle.sh)
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@freestyle-sh/with-deno",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "private": false,
5
5
  "dependencies": {
6
- "freestyle-sandboxes": "^0.1.41",
7
- "@freestyle-sh/with-type-js": "0.2.8"
6
+ "freestyle-sandboxes": "^0.1.43",
7
+ "@freestyle-sh/with-type-js": "0.2.9"
8
8
  },
9
9
  "devDependencies": {
10
10
  "@types/node": "^22.0.0",