@open-workspace/create 0.5.1 → 0.5.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.
@@ -52,13 +52,11 @@ export function invitationFile(path: string, origin: string) {
52
52
  process.kill(pending.pid, 0);
53
53
  throw new Error(`Another import is writing ${path}.`);
54
54
  } catch (error) {
55
- if (
56
- !(
57
- error instanceof Error &&
58
- "code" in error &&
59
- error.code === "ESRCH"
60
- )
61
- ) {
55
+ if (!(
56
+ error instanceof Error &&
57
+ "code" in error &&
58
+ error.code === "ESRCH"
59
+ )) {
62
60
  throw error;
63
61
  }
64
62
  }
package/index.ts CHANGED
@@ -1,12 +1,16 @@
1
1
  #!/usr/bin/env bun
2
2
  // `bun create @open-workspace` writes a new project; `… module <name>` adds a
3
- // module to one; `… import` brings people and mail into a deployed workspace.
3
+ // module to one; `… import` brings people and mail into a deployed workspace;
4
+ // `… update` moves one to the latest release and deploys it.
4
5
  if (process.argv[2] === "module") {
5
6
  const { main } = await import("./module.ts");
6
7
  process.exitCode = main(process.argv.slice(3));
7
8
  } else if (process.argv[2] === "import") {
8
9
  const { main } = await import("./import/cli.ts");
9
10
  process.exitCode = await main(process.argv.slice(3));
11
+ } else if (process.argv[2] === "update") {
12
+ const { main } = await import("./update.ts");
13
+ process.exitCode = await main(process.argv.slice(3));
10
14
  } else if (process.argv[2] === "restore-mx") {
11
15
  const { main } = await import("./setup/mx-recovery.ts");
12
16
  process.exitCode = await main(process.argv.slice(3));
@@ -11,17 +11,17 @@ export const MODULE_NAME = /^[a-z]+(?:-[a-z]+)*$/u;
11
11
 
12
12
  /** What the generated module imports, at the versions core is built with. */
13
13
  export const moduleDependencies = {
14
- "@tanstack/react-query": "5.107.1",
14
+ "@tanstack/react-query": "5.108.4",
15
15
  "drizzle-orm": "0.45.4",
16
- hono: "4.13.17",
17
- "lucide-react": "1.71.0",
16
+ hono: "4.13.23",
17
+ "lucide-react": "1.84.0",
18
18
  react: "19.3.1",
19
- "react-router": "8.5.1",
19
+ "react-router": "8.5.3",
20
20
  zod: "4.6.7",
21
21
  } satisfies Record<string, string>;
22
22
 
23
23
  export const moduleDevDependencies = {
24
- "@types/react": "19.3.0",
24
+ "@types/react": "19.3.3",
25
25
  "drizzle-kit": "0.31.11",
26
26
  } satisfies Record<string, string>;
27
27
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-workspace/create",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "Create an OpenWorkspace deployment (`bun create @open-workspace`), and import people, teams, SSO apps and mail.",
5
5
  "homepage": "https://openworkspace.dev",
6
6
  "license": "Apache-2.0",
@@ -17,6 +17,7 @@
17
17
  "create.ts",
18
18
  "templates.ts",
19
19
  "module.ts",
20
+ "update.ts",
20
21
  "setup",
21
22
  "module-templates.ts",
22
23
  "import",
@@ -42,14 +43,14 @@
42
43
  },
43
44
  "dependencies": {
44
45
  "@clack/prompts": "1.9.0",
45
- "imapflow": "2.11.0",
46
+ "imapflow": "2.12.2",
46
47
  "zod": "4.6.7"
47
48
  },
48
49
  "devDependencies": {
49
- "@alchemy.run/cloudflare": "2.0.0-beta.85",
50
- "@types/bun": "1.4.4",
51
- "alchemy": "2.0.0-beta.85",
52
- "effect": "4.1.3",
50
+ "@alchemy.run/cloudflare": "2.0.0-beta.87",
51
+ "@types/bun": "1.4.5",
52
+ "alchemy": "2.0.0-beta.87",
53
+ "effect": "4.1.7",
53
54
  "hoodiecrow-imap": "3.3.1",
54
55
  "typescript": "7.0.2"
55
56
  }
package/templates.ts CHANGED
@@ -14,11 +14,11 @@ export type ProjectAnswers = {
14
14
  };
15
15
 
16
16
  export const versions = {
17
- openWorkspace: "0.5.1",
18
- alchemy: "2.0.0-beta.85",
19
- effect: "4.1.3",
17
+ openWorkspace: "0.5.2",
18
+ alchemy: "2.0.0-beta.87",
19
+ effect: "4.1.7",
20
20
  typescript: "7.0.2",
21
- nodeTypes: "26.6.6",
21
+ nodeTypes: "26.6.11",
22
22
  bun: "1.4.4",
23
23
  };
24
24
 
@@ -31,6 +31,9 @@ export const versions = {
31
31
  */
32
32
  export const DEPLOY_STAGE = "production";
33
33
 
34
+ /** The project's `update` script: the latest release, installed and deployed. */
35
+ export const UPDATE_SCRIPT = "bunx @open-workspace/create@latest update";
36
+
34
37
  export function packageJson(answers: ProjectAnswers) {
35
38
  return `${JSON.stringify(
36
39
  {
@@ -44,6 +47,7 @@ export function packageJson(answers: ProjectAnswers) {
44
47
  dev: "alchemy dev",
45
48
  destroy: `alchemy destroy --stage ${DEPLOY_STAGE}`,
46
49
  logs: `alchemy logs --tail --stage ${DEPLOY_STAGE}`,
50
+ update: UPDATE_SCRIPT,
47
51
  },
48
52
  dependencies: {
49
53
  "@open-workspace/core": versions.openWorkspace,
@@ -255,10 +259,9 @@ passkey, as on the deployed app. Mail from outside doesn't reach it.
255
259
 
256
260
  ## Update
257
261
 
258
- \`\`\`sh
259
- bun update --latest @open-workspace/core @open-workspace/email
260
- bun run deploy
261
- \`\`\`
262
+ \`bun run update\` moves OpenWorkspace to the latest release, with the Alchemy
263
+ and Effect versions it needs, installs it and deploys. Read the release's
264
+ upgrade notes first; Administration shows them when an update is available.
262
265
  `;
263
266
  }
264
267
 
package/update.ts ADDED
@@ -0,0 +1,180 @@
1
+ import { readFileSync, writeFileSync } from "node:fs";
2
+ import { join, resolve } from "node:path";
3
+
4
+ import { z } from "zod";
5
+
6
+ import { UPDATE_SCRIPT } from "./templates";
7
+
8
+ /** What npm says of @open-workspace/core's latest release. */
9
+ const latestSchema = z.object({
10
+ version: z.string(),
11
+ peerDependencies: z.record(z.string(), z.string()).default({}),
12
+ });
13
+
14
+ export type LatestRelease = z.infer<typeof latestSchema>;
15
+
16
+ const manifestSchema = z.looseObject({
17
+ scripts: z.record(z.string(), z.string()).optional(),
18
+ dependencies: z.record(z.string(), z.string()).optional(),
19
+ devDependencies: z.record(z.string(), z.string()).optional(),
20
+ });
21
+
22
+ /** The packages released together under one version. */
23
+ const OWN_PACKAGES = new Set(["@open-workspace/core", "@open-workspace/email"]);
24
+
25
+ /** Versioned with effect, though core doesn't name them. */
26
+ const EFFECT_PLATFORMS = new Set([
27
+ "@effect/platform-bun",
28
+ "@effect/platform-node",
29
+ ]);
30
+
31
+ export type VersionChange = { name: string; from: string; to: string };
32
+
33
+ /**
34
+ * The project's package.json moved to `latest`: OpenWorkspace's packages to
35
+ * its version, and Alchemy and Effect to the versions core was built with
36
+ * (it pins them as peers), with the `update` script added if missing.
37
+ */
38
+ export function updatedManifest(text: string, latest: LatestRelease) {
39
+ const manifest = manifestSchema.parse(JSON.parse(text));
40
+ const changes: VersionChange[] = [];
41
+
42
+ const wanted = (name: string) => {
43
+ if (OWN_PACKAGES.has(name)) return latest.version;
44
+
45
+ if (EFFECT_PLATFORMS.has(name)) return latest.peerDependencies.effect;
46
+
47
+ return latest.peerDependencies[name];
48
+ };
49
+
50
+ for (const field of ["dependencies", "devDependencies"] as const) {
51
+ const deps = manifest[field];
52
+
53
+ if (!deps) continue;
54
+
55
+ for (const [name, from] of Object.entries(deps)) {
56
+ const to = wanted(name);
57
+
58
+ if (to && to !== from) {
59
+ deps[name] = to;
60
+ changes.push({ name, from, to });
61
+ }
62
+ }
63
+ }
64
+
65
+ const scripts = manifest.scripts ?? {};
66
+ const addsScript = !scripts.update;
67
+
68
+ if (addsScript) manifest.scripts = { ...scripts, update: UPDATE_SCRIPT };
69
+
70
+ return {
71
+ text: `${JSON.stringify(manifest, null, 2)}\n`,
72
+ changes,
73
+ addsScript,
74
+ };
75
+ }
76
+
77
+ export type UpdateDeps = {
78
+ latest: () => Promise<LatestRelease>;
79
+ /** Runs a command in the project on this terminal; whether it succeeded. */
80
+ run: (command: string[]) => Promise<boolean>;
81
+ log: (line: string) => void;
82
+ };
83
+
84
+ const usage = `Usage: bunx @open-workspace/create update [--no-deploy] (or bun run update), in your workspace's project
85
+
86
+ Moves @open-workspace/core and email to the latest release, with the Alchemy
87
+ and Effect versions it needs, installs them and deploys.`;
88
+
89
+ /**
90
+ * `bunx @open-workspace/create update`, run in a deployment project. Returns
91
+ * the exit code.
92
+ */
93
+ export async function main(
94
+ args: string[],
95
+ cwd = process.cwd(),
96
+ deps: UpdateDeps = defaultDeps(cwd)
97
+ ) {
98
+ const unknown = args.filter((arg) => arg !== "--no-deploy");
99
+
100
+ if (unknown.length) {
101
+ deps.log(usage);
102
+
103
+ return unknown.includes("--help") || unknown.includes("-h") ? 0 : 1;
104
+ }
105
+
106
+ const path = join(resolve(cwd), "package.json");
107
+ let text: string;
108
+
109
+ try {
110
+ text = readFileSync(path, "utf-8");
111
+ } catch {
112
+ deps.log(`No package.json here. ${usage}`);
113
+
114
+ return 1;
115
+ }
116
+
117
+ if (!text.includes('"@open-workspace/core"')) {
118
+ deps.log(`This project doesn't use @open-workspace/core. ${usage}`);
119
+
120
+ return 1;
121
+ }
122
+
123
+ const latest = await deps.latest();
124
+ const updated = updatedManifest(text, latest);
125
+
126
+ if (!updated.changes.length) {
127
+ if (updated.addsScript) writeFileSync(path, updated.text);
128
+ deps.log(`Already on OpenWorkspace ${latest.version}.`);
129
+
130
+ return 0;
131
+ }
132
+
133
+ for (const change of updated.changes) {
134
+ deps.log(`${change.name} ${change.from} → ${change.to}`);
135
+ }
136
+
137
+ deps.log(
138
+ `What changed: https://github.com/iivankin/openworkspace/releases/tag/v${latest.version}`
139
+ );
140
+ writeFileSync(path, updated.text);
141
+
142
+ if (!(await deps.run([process.execPath, "install"]))) return 1;
143
+
144
+ if (args.includes("--no-deploy")) {
145
+ deps.log("Updated. Deploy with: bun run deploy");
146
+
147
+ return 0;
148
+ }
149
+
150
+ return (await deps.run([process.execPath, "run", "deploy"])) ? 0 : 1;
151
+ }
152
+
153
+ function defaultDeps(cwd: string) {
154
+ const deps: UpdateDeps = {
155
+ async latest() {
156
+ const response = await fetch(
157
+ "https://registry.npmjs.org/@open-workspace/core/latest"
158
+ );
159
+
160
+ if (!response.ok) {
161
+ throw new Error(`npm answered ${response.status}`);
162
+ }
163
+
164
+ return latestSchema.parse(await response.json());
165
+ },
166
+ async run(command) {
167
+ const child = Bun.spawn(command, {
168
+ cwd,
169
+ stdin: "inherit",
170
+ stdout: "inherit",
171
+ stderr: "inherit",
172
+ });
173
+
174
+ return (await child.exited) === 0;
175
+ },
176
+ log: console.log,
177
+ };
178
+
179
+ return deps;
180
+ }