@sightmap/react 0.7.1 → 0.9.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/index.d.ts +13 -2
- package/dist/index.js +349 -5
- package/dist/index.js.map +1 -1
- package/dist/runtime-types-Cvx7dsB4.d.ts +91 -0
- package/dist/runtime-types.d.ts +2 -51
- package/dist/vite.d.ts +21 -8
- package/dist/vite.js +54 -29
- package/dist/vite.js.map +1 -1
- package/package.json +5 -26
- package/dist/cli/index.d.ts +0 -1
- package/dist/cli/index.js +0 -1149
- package/dist/cli/index.js.map +0 -1
- package/dist/plugin/adapters/rr7-declarative.d.ts +0 -6
- package/dist/plugin/adapters/rr7-declarative.js +0 -315
- package/dist/plugin/adapters/rr7-declarative.js.map +0 -1
- package/dist/plugin/adapters/rr7-framework.d.ts +0 -7
- package/dist/plugin/adapters/rr7-framework.js +0 -235
- package/dist/plugin/adapters/rr7-framework.js.map +0 -1
- package/dist/router-adapter-CsmLmHVQ.d.ts +0 -29
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
|
-
|
|
4
|
-
/**
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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,
|
|
24
|
+
export { type SightmapPluginOptions, type SightmapVitePlugin, sightmap };
|
package/dist/vite.js
CHANGED
|
@@ -1,38 +1,63 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
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: "
|
|
29
|
-
apply: "serve",
|
|
16
|
+
name: "sightmap-react",
|
|
30
17
|
configureServer(server) {
|
|
31
|
-
server.middlewares.use(
|
|
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
|
-
|
|
61
|
+
sightmap
|
|
37
62
|
};
|
|
38
63
|
//# sourceMappingURL=vite.js.map
|
package/dist/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
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;AAAA,EACzB;AAEA,QAAM,gBAAgB;AACtB,QAAM,cAAc;AAAA;AAEpB,SAAO;AAAA,IACL,MAAM;AAAA,IAEN,gBAAgB,QAAQ;AACtB,aAAO,YAAY,IAAI,+BAA+B,CAAC,KAAK,QAAQ;AAClE,YAAI,IAAI,WAAW,QAAQ;AACzB,gBAAM,SAAmB,CAAC;AAC1B,cAAI,GAAG,QAAQ,CAAC,MAAc,OAAO,KAAK,CAAC,CAAC;AAC5C,cAAI,GAAG,OAAO,MAAM;AAClB,gBAAI;AACF,oBAAM,OAAO,KAAK,MAAM,OAAO,OAAO,MAAM,EAAE,SAAS,MAAM,CAAC;AAC9D,oBAAM,IAAI,IAAI;AACd,kBAAI,aAAa;AACjB,kBAAI,IAAI;AAAA,YACV,SAAS,GAAG;AACV,kBAAI,aAAa;AACjB,kBAAI,IAAI,aAAc,EAAY,OAAO,EAAE;AAAA,YAC7C;AAAA,UACF,CAAC;AACD;AAAA,QACF;AACA,YAAI,IAAI,WAAW,OAAO;AACxB,gBAAM,OAAO,MAAM,IAAI;AACvB,cAAI,CAAC,MAAM;AACT,gBAAI,aAAa;AACjB,gBAAI,IAAI,8DAAyD;AACjE;AAAA,UACF;AACA,cAAI,aAAa;AACjB,cAAI,UAAU,gBAAgB,kBAAkB;AAChD,cAAI,IAAI,KAAK,UAAU,IAAI,CAAC;AAC5B;AAAA,QACF;AACA,YAAI,aAAa;AACjB,YAAI,IAAI;AAAA,MACV,CAAC;AAAA,IACH;AAAA,IAEA,UAAU,MAAM,IAAI;AAClB,UAAI,CAAC,QAAQ,WAAY,QAAO;AAChC,UAAI,CAAC,cAAc,KAAK,EAAE,EAAG,QAAO;AACpC,UAAI,KAAK,SAAS,iBAAiB,EAAG,QAAO;AAC7C,aAAO,EAAE,MAAM,cAAc,MAAM,KAAK,KAAK;AAAA,IAC/C;AAAA,IAEA,cAAc;AAAA,EAChB;AACF;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sightmap/react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "React
|
|
3
|
+
"version": "0.9.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
|
-
"
|
|
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
61
|
"vite": "^7.0.0",
|
|
83
62
|
"vitest": "^3.0.0",
|
|
84
|
-
"@sightmap/sightmap": "^0.
|
|
63
|
+
"@sightmap/sightmap": "^0.9.0"
|
|
85
64
|
},
|
|
86
65
|
"scripts": {
|
|
87
66
|
"build": "tsup",
|
package/dist/cli/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|