@magneticjs/cli 0.1.5 → 0.1.6

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/dist/cli.js CHANGED
@@ -148,42 +148,8 @@ function generateBridge(scan) {
148
148
 
149
149
  // src/bundler.ts
150
150
  import { build } from "esbuild";
151
- import { join as join2, dirname as dirname2 } from "node:path";
152
- import { mkdirSync, existsSync as existsSync2, statSync as statSync2, readdirSync as readdirSync2, readFileSync as readFileSync2, copyFileSync } from "node:fs";
153
- import { createRequire } from "node:module";
154
- function copyFrameworkAsset(filename, appDir, monorepoRoot) {
155
- const publicDir = join2(appDir, "public");
156
- const dest = join2(publicDir, filename);
157
- if (existsSync2(dest)) return true;
158
- const candidates = [];
159
- if (monorepoRoot) {
160
- candidates.push(join2(monorepoRoot, "js/packages/magnetic-server/wasm", filename));
161
- if (filename === "magnetic.js") {
162
- candidates.push(join2(monorepoRoot, "js/packages/sdk-web-runtime/dist/magnetic.min.js"));
163
- }
164
- }
165
- try {
166
- const require2 = createRequire(join2(appDir, "package.json"));
167
- const serverPkg = require2.resolve("@magneticjs/server");
168
- candidates.push(join2(dirname2(serverPkg), "..", "wasm", filename));
169
- } catch {
170
- }
171
- candidates.push(join2(import.meta.dirname || __dirname, "..", "wasm", filename));
172
- for (const src of candidates) {
173
- if (existsSync2(src)) {
174
- mkdirSync(publicDir, { recursive: true });
175
- copyFileSync(src, dest);
176
- return true;
177
- }
178
- }
179
- return false;
180
- }
181
- function copyTransportWasm(appDir, monorepoRoot) {
182
- return copyFrameworkAsset("transport.wasm", appDir, monorepoRoot);
183
- }
184
- function copyClientRuntime(appDir, monorepoRoot) {
185
- return copyFrameworkAsset("magnetic.js", appDir, monorepoRoot);
186
- }
151
+ import { join as join2 } from "node:path";
152
+ import { mkdirSync, existsSync as existsSync2, statSync as statSync2, readdirSync as readdirSync2, readFileSync as readFileSync2 } from "node:fs";
187
153
  async function bundleApp(opts) {
188
154
  const outDir = opts.outDir || join2(opts.appDir, "dist");
189
155
  const outFile = opts.outFile || "app.js";
@@ -191,8 +157,6 @@ async function bundleApp(opts) {
191
157
  if (!existsSync2(outDir)) {
192
158
  mkdirSync(outDir, { recursive: true });
193
159
  }
194
- copyClientRuntime(opts.appDir, opts.monorepoRoot);
195
- copyTransportWasm(opts.appDir, opts.monorepoRoot);
196
160
  const alias = {};
197
161
  if (opts.monorepoRoot) {
198
162
  const serverPkg = join2(opts.monorepoRoot, "js/packages/magnetic-server/src");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magneticjs/cli",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Magnetic CLI — build, dev, and deploy server-driven UI apps",
5
5
  "type": "module",
6
6
  "bin": {
@@ -11,12 +11,12 @@
11
11
  "dev": "tsx src/cli.ts",
12
12
  "postinstall": "node scripts/install-server.js || true"
13
13
  },
14
- "files": ["dist", "src", "scripts", "wasm"],
14
+ "files": ["dist", "src", "scripts"],
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
18
  "dependencies": {
19
- "@magneticjs/server": "^0.1.1",
19
+ "@magneticjs/server": "^0.1.3",
20
20
  "esbuild": "^0.27.3"
21
21
  },
22
22
  "devDependencies": {
@@ -28,7 +28,7 @@ const versionFile = join(binDir, '.version');
28
28
 
29
29
  // Server binary version — decoupled from npm package version.
30
30
  // Only bump this when a new binary is uploaded to GitHub Releases.
31
- const SERVER_VERSION = '0.1.0';
31
+ const SERVER_VERSION = '0.2.0';
32
32
 
33
33
  // Check if installed binary matches current server version
34
34
  if (existsSync(binPath) && existsSync(versionFile)) {
package/src/bundler.ts CHANGED
@@ -2,9 +2,8 @@
2
2
  // Takes generated bridge code and bundles it into an IIFE for V8
3
3
 
4
4
  import { build } from 'esbuild';
5
- import { join, resolve, dirname } from 'node:path';
6
- import { mkdirSync, existsSync, writeFileSync, statSync, readdirSync, readFileSync, copyFileSync } from 'node:fs';
7
- import { createRequire } from 'node:module';
5
+ import { join, resolve } from 'node:path';
6
+ import { mkdirSync, existsSync, statSync, readdirSync, readFileSync } from 'node:fs';
8
7
 
9
8
  export interface BundleOptions {
10
9
  /** Absolute path to the app directory */
@@ -26,62 +25,6 @@ export interface BundleResult {
26
25
  sizeBytes: number;
27
26
  }
28
27
 
29
- /**
30
- * Copy a framework asset into the app's public/ directory.
31
- * Searches monorepo, npm-installed @magneticjs/server, and CLI's own wasm/ dir.
32
- */
33
- function copyFrameworkAsset(filename: string, appDir: string, monorepoRoot?: string): boolean {
34
- const publicDir = join(appDir, 'public');
35
- const dest = join(publicDir, filename);
36
-
37
- // Already there — skip
38
- if (existsSync(dest)) return true;
39
-
40
- const candidates: string[] = [];
41
-
42
- // Monorepo paths
43
- if (monorepoRoot) {
44
- candidates.push(join(monorepoRoot, 'js/packages/magnetic-server/wasm', filename));
45
- if (filename === 'magnetic.js') {
46
- candidates.push(join(monorepoRoot, 'js/packages/sdk-web-runtime/dist/magnetic.min.js'));
47
- }
48
- }
49
-
50
- // npm-installed @magneticjs/server
51
- try {
52
- const require = createRequire(join(appDir, 'package.json'));
53
- const serverPkg = require.resolve('@magneticjs/server');
54
- candidates.push(join(dirname(serverPkg), '..', 'wasm', filename));
55
- } catch {}
56
-
57
- // CLI's own bundled copy (sibling to dist/)
58
- candidates.push(join(import.meta.dirname || __dirname, '..', 'wasm', filename));
59
-
60
- for (const src of candidates) {
61
- if (existsSync(src)) {
62
- mkdirSync(publicDir, { recursive: true });
63
- copyFileSync(src, dest);
64
- return true;
65
- }
66
- }
67
-
68
- return false;
69
- }
70
-
71
- /**
72
- * Copy transport.wasm into the app's public/ directory.
73
- */
74
- export function copyTransportWasm(appDir: string, monorepoRoot?: string): boolean {
75
- return copyFrameworkAsset('transport.wasm', appDir, monorepoRoot);
76
- }
77
-
78
- /**
79
- * Copy magnetic.js client runtime into the app's public/ directory.
80
- */
81
- export function copyClientRuntime(appDir: string, monorepoRoot?: string): boolean {
82
- return copyFrameworkAsset('magnetic.js', appDir, monorepoRoot);
83
- }
84
-
85
28
  /**
86
29
  * Bundle the generated bridge code into an IIFE for V8 consumption.
87
30
  * Uses esbuild with stdin so no temp file is needed.
@@ -95,10 +38,6 @@ export async function bundleApp(opts: BundleOptions): Promise<BundleResult> {
95
38
  mkdirSync(outDir, { recursive: true });
96
39
  }
97
40
 
98
- // Ensure framework assets are in public/
99
- copyClientRuntime(opts.appDir, opts.monorepoRoot);
100
- copyTransportWasm(opts.appDir, opts.monorepoRoot);
101
-
102
41
  // Resolve @magneticjs/server — in monorepo use actual path, otherwise npm package
103
42
  const alias: Record<string, string> = {};
104
43
  if (opts.monorepoRoot) {
package/wasm/magnetic.js DELETED
@@ -1 +0,0 @@
1
- (function(d) {var M = self.Magnetic = {};var root = null;var es = null;var wasm = null;var status = "disconnected";var queue = [];var keys = {};var deb = {};var lastHash = "";var enc = new TextEncoder();M.status = function() { return status; };M.connect = function(url, mount) {root = typeof mount == "string" ? d.querySelector(mount) : mount;es = new EventSource(url);es.onmessage = function(ev) {try {var raw = ev.data;if (wasm && wasm.store) {var bytes = enc.encode(raw);if (bytes.length <= 16384) {new Uint8Array(wasm.memory.buffer).set(bytes, wasm.input_ptr());if (wasm.store(bytes.length) === 0) return;}} else {var h = fnv(raw);if (h === lastHash) return;lastHash = h;}apply(JSON.parse(raw));} catch(e) { console.error("[magnetic] SSE error:", e); }};es.onerror = function() {if (wasm) status = "offline";};status = "connected";bind();};M.disconnect = function() {if (es) { es.close(); es = null; }status = "disconnected";};function apply(snap) {if (!root || !snap || !snap.root) return;var n = snap.root;if (n.key && keys[n.key] && keys[n.key].parentNode === root) {patch(keys[n.key], n);return;}root.textContent = "";root.appendChild(create(n));}M._apply = apply;function create(n) {var el = d.createElement(n.tag);if (n.key) { el.dataset.key = n.key; keys[n.key] = el; }setAttrs(el, n);if (n.events) for (var v in n.events) el.dataset["a_" + v] = n.events[v];if (n.text != null) el.textContent = n.text;if (n.children) for (var i = 0; i < n.children.length; i++) el.appendChild(create(n.children[i]));return el;}function patch(el, n) {setAttrs(el, n);if (n.events) {for (var v in n.events) el.dataset["a_" + v] = n.events[v];}var da = el.dataset;for (var dk in da) {if (dk.indexOf("a_") === 0) {var ev = dk.slice(2);if (!n.events || !(ev in n.events)) delete da[dk];}}if (n.children) {reconcile(el, n.children);} else if (n.text != null && n.tag != "input" && n.tag != "textarea") {el.textContent = n.text;} else if (!n.children && n.text == null && n.tag != "input" && n.tag != "textarea") {while (el.firstChild) {purgeKeys(el.firstChild);el.removeChild(el.firstChild);}}}function purgeKeys(el) {var k = el.dataset ? el.dataset.key : null;if (k) delete keys[k];var ch = el.firstChild;while (ch) { purgeKeys(ch); ch = ch.nextSibling; }}function reconcile(parent, descs) {var i, c, el, k;var newEls = [];var wantKeys = {};for (i = 0; i < descs.length; i++) {c = descs[i];if (c.key && keys[c.key]) {el = keys[c.key];patch(el, c);wantKeys[c.key] = true;} else {el = create(c);if (c.key) wantKeys[c.key] = true;}newEls.push(el);}var ch = parent.firstChild;while (ch) {var nx = ch.nextSibling;k = ch.dataset ? ch.dataset.key : null;if (!k || !wantKeys[k]) {purgeKeys(ch);parent.removeChild(ch);}ch = nx;}for (i = 0; i < newEls.length; i++) {if (parent.childNodes[i] !== newEls[i]) {parent.insertBefore(newEls[i], parent.childNodes[i] || null);}}}function setAttrs(el, n) {if (n.attrs) for (var k in n.attrs) el.setAttribute(k, n.attrs[k]);}function bind() {d.addEventListener("click", function(e) {var t = e.target.closest("[data-a_click]");if (t) { e.preventDefault(); send(t.dataset.a_click, {}); }});d.addEventListener("submit", function(e) {var t = e.target.closest("[data-a_submit]");if (t) {e.preventDefault();var p = {}, f = new FormData(t);f.forEach(function(v, k) { p[k] = v; });send(t.dataset.a_submit, p);t.querySelectorAll("input").forEach(function(i) { i.value = ""; });}});d.addEventListener("input", function(e) {var t = e.target.closest("[data-a_input]");if (t) {var a = t.dataset.a_input;clearTimeout(deb[a]);deb[a] = setTimeout(function() { send(a, { value: t.value }); }, 300);}});}M.send = send;function send(action, payload) {if (action.indexOf("navigate:") === 0) {var path = action.slice(9);history.pushState({}, "", path);action = "navigate";payload = { path: path };}var body = JSON.stringify({ action: action, payload: payload });fetch("/actions/" + encodeURIComponent(action), {method: "POST",headers: { "Content-Type": "application/json" },body: body}).then(function(r) { return r.text(); }).then(function(raw) {if (!raw || raw[0] !== "{") return;if (wasm && wasm.store) {var bytes = enc.encode(raw);if (bytes.length <= 16384) {new Uint8Array(wasm.memory.buffer).set(bytes, wasm.input_ptr());wasm.store(bytes.length);}} else {lastHash = fnv(raw);}try { apply(JSON.parse(raw)); } catch(e) {}}).catch(function() {});if (status != "connected") queue.push(body);}self.addEventListener("popstate", function() {send("navigate", { path: location.pathname + location.search });});M.loadWasm = function(url) {if (wasm !== null) return;wasm = 0;fetch(url).then(function(r) { return r.arrayBuffer(); }).then(function(b) { return WebAssembly.instantiate(b, {}); }).then(function(result) {wasm = result.instance.exports;while (queue.length) {var q = JSON.parse(queue.shift());send(q.action, q.payload);}}).catch(function() { wasm = null; });};function fnv(s) {var h = 0x811c9dc5;for (var i = 0; i < s.length; i++) {h ^= s.charCodeAt(i);h = Math.imul(h, 0x01000193);}return h;}})(document);
Binary file