@sightmap/react 0.6.0 → 0.8.0

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/vite.d.ts CHANGED
@@ -1,11 +1,24 @@
1
1
  import { Plugin } from 'vite';
2
+ import { S as SightmapSnapshot } from './runtime-types-Cvx7dsB4.js';
3
+ import '@sightmap/sightmap';
2
4
 
3
- type SightmapPluginOptions = {
4
- /** Project root. Defaults to `process.cwd()`. */
5
- projectRoot?: string;
6
- /** Output directory relative to projectRoot. Defaults to `.sightmap`. */
7
- outputDir?: string;
8
- };
9
- declare function sightmapVitePlugin(options?: SightmapPluginOptions): Plugin;
5
+ interface SightmapPluginOptions {
6
+ /**
7
+ * When true, the plugin prepends `import "@sightmap/react";` to the app
8
+ * entry (matched by filename ending in `main.tsx|tsx|jsx|ts|js` under
9
+ * the project's `src/` or `app/`). This guarantees the bippy hook
10
+ * installs before react-dom imports.
11
+ */
12
+ autoInject?: boolean;
13
+ }
14
+ interface SnapshotCache {
15
+ set(s: SightmapSnapshot): void;
16
+ get(): SightmapSnapshot | null;
17
+ }
18
+ interface SightmapVitePlugin extends Plugin {
19
+ /** Test-only handle for unit tests. Stable contract: don't use in production. */
20
+ __test_cache: SnapshotCache;
21
+ }
22
+ declare function sightmap(options?: SightmapPluginOptions): SightmapVitePlugin;
10
23
 
11
- export { type SightmapPluginOptions, sightmapVitePlugin as sightmap };
24
+ export { type SightmapPluginOptions, type SightmapVitePlugin, sightmap };
package/dist/vite.js CHANGED
@@ -1,38 +1,63 @@
1
- // src/plugin/dev-middleware.ts
2
- import { join } from "path";
3
- import { loadDirectory } from "@sightmap/sightmap";
4
- function sightmapDevMiddleware(opts) {
5
- return async (req, res, next) => {
6
- if (req.url !== "/__sightmap__/sightmap.json") {
7
- next();
8
- return;
9
- }
10
- try {
11
- const sightmap = await loadDirectory(join(opts.projectRoot, opts.outputDir));
12
- res.statusCode = 200;
13
- res.setHeader("content-type", "application/json");
14
- res.setHeader("cache-control", "no-store");
15
- res.end(JSON.stringify(sightmap));
16
- } catch (err) {
17
- res.statusCode = 500;
18
- res.end(`sightmap dev middleware: ${err.message}`);
1
+ // src/vite.ts
2
+ function sightmap(options = {}) {
3
+ let cached = null;
4
+ const cache = {
5
+ set(s) {
6
+ cached = s;
7
+ },
8
+ get() {
9
+ return cached;
19
10
  }
20
11
  };
21
- }
22
-
23
- // src/plugin/vite.ts
24
- function sightmapVitePlugin(options = {}) {
25
- const projectRoot = options.projectRoot ?? process.cwd();
26
- const outputDir = options.outputDir ?? ".sightmap";
12
+ const ENTRY_PATTERN = /(src|app)\/(main|index|entry\.client)\.(t|j)sx?$/;
13
+ const INJECT_LINE = `import "@sightmap/react";
14
+ `;
27
15
  return {
28
- name: "@sightmap/react:dev-server",
29
- apply: "serve",
16
+ name: "sightmap-react",
30
17
  configureServer(server) {
31
- server.middlewares.use(sightmapDevMiddleware({ projectRoot, outputDir }));
32
- }
18
+ server.middlewares.use("/__sightmap__/snapshot.json", (req, res) => {
19
+ if (req.method === "POST") {
20
+ const chunks = [];
21
+ req.on("data", (c) => chunks.push(c));
22
+ req.on("end", () => {
23
+ try {
24
+ const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
25
+ cache.set(body);
26
+ res.statusCode = 204;
27
+ res.end();
28
+ } catch (e) {
29
+ res.statusCode = 400;
30
+ res.end(`bad json: ${e.message}`);
31
+ }
32
+ });
33
+ return;
34
+ }
35
+ if (req.method === "GET") {
36
+ const snap = cache.get();
37
+ if (!snap) {
38
+ res.statusCode = 404;
39
+ res.end(`{"error":"no snapshot cached yet \u2014 visit a page first"}`);
40
+ return;
41
+ }
42
+ res.statusCode = 200;
43
+ res.setHeader("content-type", "application/json");
44
+ res.end(JSON.stringify(snap));
45
+ return;
46
+ }
47
+ res.statusCode = 405;
48
+ res.end();
49
+ });
50
+ },
51
+ transform(code, id) {
52
+ if (!options.autoInject) return null;
53
+ if (!ENTRY_PATTERN.test(id)) return null;
54
+ if (code.includes("@sightmap/react")) return null;
55
+ return { code: INJECT_LINE + code, map: null };
56
+ },
57
+ __test_cache: cache
33
58
  };
34
59
  }
35
60
  export {
36
- sightmapVitePlugin as sightmap
61
+ sightmap
37
62
  };
38
63
  //# sourceMappingURL=vite.js.map
package/dist/vite.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin/dev-middleware.ts","../src/plugin/vite.ts"],"sourcesContent":["import type { IncomingMessage, ServerResponse } from \"node:http\";\nimport { join } from \"node:path\";\nimport { loadDirectory } from \"@sightmap/sightmap\";\n\nexport function sightmapDevMiddleware(opts: { projectRoot: string; outputDir: string }) {\n return async (req: IncomingMessage, res: ServerResponse, next: (err?: unknown) => void) => {\n if (req.url !== \"/__sightmap__/sightmap.json\") {\n next();\n return;\n }\n try {\n const sightmap = await loadDirectory(join(opts.projectRoot, opts.outputDir));\n res.statusCode = 200;\n res.setHeader(\"content-type\", \"application/json\");\n res.setHeader(\"cache-control\", \"no-store\");\n res.end(JSON.stringify(sightmap));\n } catch (err) {\n res.statusCode = 500;\n res.end(`sightmap dev middleware: ${(err as Error).message}`);\n }\n };\n}\n","// src/plugin/vite.ts\n//\n// Vite plugin for @sightmap/react.\n//\n// In v0.1 (mode B — bootstrap-only codegen), this plugin's only job is to\n// register the dev middleware that serves the merged sightmap at\n// `/__sightmap__/sightmap.json`. Codegen is no longer triggered from any Vite\n// hook; users invoke `sightmap-react gen` explicitly when they want\n// `.sightmap/` files refreshed.\n//\n// The dev middleware reads the on-disk `.sightmap/` directory on each request\n// and returns the merged sightmap as JSON. This powers `<SightmapProvider>`'s\n// fetch loop in development.\n\nimport type { Plugin } from \"vite\";\nimport { sightmapDevMiddleware } from \"./dev-middleware.js\";\n\nexport type SightmapPluginOptions = {\n /** Project root. Defaults to `process.cwd()`. */\n projectRoot?: string;\n /** Output directory relative to projectRoot. Defaults to `.sightmap`. */\n outputDir?: string;\n};\n\nexport function sightmapVitePlugin(options: SightmapPluginOptions = {}): Plugin {\n const projectRoot = options.projectRoot ?? process.cwd();\n const outputDir = options.outputDir ?? \".sightmap\";\n\n return {\n name: \"@sightmap/react:dev-server\",\n apply: \"serve\",\n configureServer(server) {\n server.middlewares.use(sightmapDevMiddleware({ projectRoot, outputDir }));\n },\n };\n}\n"],"mappings":";AACA,SAAS,YAAY;AACrB,SAAS,qBAAqB;AAEvB,SAAS,sBAAsB,MAAkD;AACtF,SAAO,OAAO,KAAsB,KAAqB,SAAkC;AACzF,QAAI,IAAI,QAAQ,+BAA+B;AAC7C,WAAK;AACL;AAAA,IACF;AACA,QAAI;AACF,YAAM,WAAW,MAAM,cAAc,KAAK,KAAK,aAAa,KAAK,SAAS,CAAC;AAC3E,UAAI,aAAa;AACjB,UAAI,UAAU,gBAAgB,kBAAkB;AAChD,UAAI,UAAU,iBAAiB,UAAU;AACzC,UAAI,IAAI,KAAK,UAAU,QAAQ,CAAC;AAAA,IAClC,SAAS,KAAK;AACZ,UAAI,aAAa;AACjB,UAAI,IAAI,4BAA6B,IAAc,OAAO,EAAE;AAAA,IAC9D;AAAA,EACF;AACF;;;ACGO,SAAS,mBAAmB,UAAiC,CAAC,GAAW;AAC9E,QAAM,cAAc,QAAQ,eAAe,QAAQ,IAAI;AACvD,QAAM,YAAY,QAAQ,aAAa;AAEvC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,gBAAgB,QAAQ;AACtB,aAAO,YAAY,IAAI,sBAAsB,EAAE,aAAa,UAAU,CAAC,CAAC;AAAA,IAC1E;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/vite.ts"],"sourcesContent":["import type { Plugin } from \"vite\";\nimport type { SightmapSnapshot } from \"./runtime/types.js\";\n\nexport interface SightmapPluginOptions {\n /**\n * When true, the plugin prepends `import \"@sightmap/react\";` to the app\n * entry (matched by filename ending in `main.tsx|tsx|jsx|ts|js` under\n * the project's `src/` or `app/`). This guarantees the bippy hook\n * installs before react-dom imports.\n */\n autoInject?: boolean;\n}\n\ninterface SnapshotCache {\n set(s: SightmapSnapshot): void;\n get(): SightmapSnapshot | null;\n}\n\nexport interface SightmapVitePlugin extends Plugin {\n /** Test-only handle for unit tests. Stable contract: don't use in production. */\n __test_cache: SnapshotCache;\n}\n\nexport function sightmap(options: SightmapPluginOptions = {}): SightmapVitePlugin {\n let cached: SightmapSnapshot | null = null;\n const cache: SnapshotCache = {\n set(s) { cached = s; },\n get() { return cached; },\n };\n\n const ENTRY_PATTERN = /(src|app)\\/(main|index|entry\\.client)\\.(t|j)sx?$/;\n const INJECT_LINE = `import \"@sightmap/react\";\\n`;\n\n return {\n name: \"sightmap-react\",\n\n configureServer(server) {\n server.middlewares.use(\"/__sightmap__/snapshot.json\", (req, res) => {\n if (req.method === \"POST\") {\n const chunks: Buffer[] = [];\n req.on(\"data\", (c: Buffer) => chunks.push(c));\n req.on(\"end\", () => {\n try {\n const body = JSON.parse(Buffer.concat(chunks).toString(\"utf8\")) as SightmapSnapshot;\n cache.set(body);\n res.statusCode = 204;\n res.end();\n } catch (e) {\n res.statusCode = 400;\n res.end(`bad json: ${(e as Error).message}`);\n }\n });\n return;\n }\n if (req.method === \"GET\") {\n const snap = cache.get();\n if (!snap) {\n res.statusCode = 404;\n res.end(`{\"error\":\"no snapshot cached yet visit a page first\"}`);\n return;\n }\n res.statusCode = 200;\n res.setHeader(\"content-type\", \"application/json\");\n res.end(JSON.stringify(snap));\n return;\n }\n res.statusCode = 405;\n res.end();\n });\n },\n\n transform(code, id) {\n if (!options.autoInject) return null;\n if (!ENTRY_PATTERN.test(id)) return null;\n if (code.includes(\"@sightmap/react\")) return null;\n return { code: INJECT_LINE + code, map: null };\n },\n\n __test_cache: cache,\n };\n}\n"],"mappings":";AAuBO,SAAS,SAAS,UAAiC,CAAC,GAAuB;AAChF,MAAI,SAAkC;AACtC,QAAM,QAAuB;AAAA,IAC3B,IAAI,GAAG;AAAE,eAAS;AAAA,IAAG;AAAA,IACrB,MAAM;AAAE,aAAO;AAAA,IAAQ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  "name": "@sightmap/react",
3
- "version": "0.6.0",
4
- "description": "React framework adapter for the Sightmap spec — SightmapProvider, runtime introspection hook, Vite plugin, and CLI.",
3
+ "version": "0.8.0",
4
+ "description": "React runtime for the Sightmap spec — SightmapProvider, runtime introspection hook, and Vite plugin.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -31,19 +31,8 @@
31
31
  },
32
32
  "./runtime-types": {
33
33
  "types": "./dist/runtime-types.d.ts"
34
- },
35
- "./adapters/react-router-7": {
36
- "types": "./dist/plugin/adapters/rr7-declarative.d.ts",
37
- "import": "./dist/plugin/adapters/rr7-declarative.js"
38
- },
39
- "./adapters/react-router-7-framework": {
40
- "types": "./dist/plugin/adapters/rr7-framework.d.ts",
41
- "import": "./dist/plugin/adapters/rr7-framework.js"
42
34
  }
43
35
  },
44
- "bin": {
45
- "sightmap-react": "./dist/cli/index.js"
46
- },
47
36
  "files": [
48
37
  "dist",
49
38
  "README.md",
@@ -54,19 +43,10 @@
54
43
  },
55
44
  "peerDependencies": {
56
45
  "@sightmap/sightmap": ">=0.1.0 <1.0.0",
57
- "react": "^19.0.0",
58
- "react-router": "^7.0.0"
59
- },
60
- "peerDependenciesMeta": {
61
- "react-router": {
62
- "optional": true
63
- }
46
+ "react": "^19.0.0"
64
47
  },
65
48
  "dependencies": {
66
- "@swc/core": "^1.10.0",
67
- "commander": "^12.1.0",
68
- "diff": "^8.0.3",
69
- "yaml": "^2.7.0"
49
+ "bippy": "^0.5.40"
70
50
  },
71
51
  "devDependencies": {
72
52
  "@testing-library/react": "^16.1.0",
@@ -76,12 +56,11 @@
76
56
  "jsdom": "^25.0.0",
77
57
  "react": "^19.0.0",
78
58
  "react-dom": "^19.0.0",
79
- "react-router": "^7.0.0",
80
59
  "tsup": "^8.5.1",
81
60
  "typescript": "~5.7.3",
82
- "vite": "^5.4.0",
83
- "vitest": "^2.1.9",
84
- "@sightmap/sightmap": "^0.6.0"
61
+ "vite": "^7.0.0",
62
+ "vitest": "^3.0.0",
63
+ "@sightmap/sightmap": "^0.8.0"
85
64
  },
86
65
  "scripts": {
87
66
  "build": "tsup",
@@ -1 +0,0 @@
1
- #!/usr/bin/env node