@insitue/swc-source-attr 0.1.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rod Leviton
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,113 @@
1
+ # `@insitue/swc-source-attr`
2
+
3
+ SWC plugin that stamps every JSX element with a `data-insitu-source="file:line:col"`
4
+ attribute so the [InSitue](https://www.insitue.com) cloud agent can resolve in-app bug
5
+ reports to exact source coordinates and open the right pull request automatically.
6
+
7
+ > **Spelling note** — the npm package is `@insitue/*` (with the 'e'); the DOM attribute
8
+ > stays as `data-insitu-source` (no 'e'). The split is intentional: the brand evolves,
9
+ > the wire format doesn't.
10
+
11
+ ## Why you need this
12
+
13
+ In production builds, React strips its component-debugger metadata (`_debugSource`,
14
+ `_debugOwner`, component names get minified). Without an explicit source attribute, the
15
+ [InSitue capture SDK](https://www.npmjs.com/package/@insitue/sdk) can only ship a CSS
16
+ selector + DOM snapshot — and the cloud agent has to guess which file to edit. Confidence
17
+ drops below the resolution threshold and the report routes to `needs_human` instead of
18
+ auto-opening a draft PR.
19
+
20
+ This plugin fixes that by injecting `data-insitu-source` at compile time. Customers using
21
+ it land in the "auto-PR" path; customers without it stay in the "needs human review" path.
22
+
23
+ ## Install
24
+
25
+ ```bash
26
+ pnpm add -D @insitue/swc-source-attr
27
+ # or: npm install --save-dev @insitue/swc-source-attr
28
+ ```
29
+
30
+ ## Wire into Next.js
31
+
32
+ ```js
33
+ // next.config.mjs
34
+ const nextConfig = {
35
+ experimental: {
36
+ swcPlugins: [
37
+ ['@insitue/swc-source-attr', { rootDir: process.cwd() }],
38
+ ],
39
+ },
40
+ };
41
+ export default nextConfig;
42
+ ```
43
+
44
+ That's it. Build your app normally — every JSX element in the output now carries
45
+ `data-insitu-source="<rel-path>:<line>:<col>"`.
46
+
47
+ ## Options
48
+
49
+ | Option | Type | Default | What |
50
+ |---|---|---|---|
51
+ | `rootDir` | `string` | _none_ | Project root, used to make emitted paths relative + portable. Recommend `process.cwd()`. Without it, paths are absolute (still works but leaks your local filesystem layout into the bundle). |
52
+ | `attrName` | `string` | `"data-insitu-source"` | Override only if the default collides with another tool. The [`@insitue/sdk`](https://www.npmjs.com/package/@insitue/sdk) picker reads the default name — if you override here, override the SDK's matching option too. |
53
+ | `exclude` | `string[]` | `[]` | Substrings; files whose path contains any of these are skipped. Cheap substring match — no glob library on the compile hot path. E.g. `["node_modules/", "/generated/"]`. |
54
+
55
+ ## How it behaves
56
+
57
+ - **Idempotent.** Elements that already have `data-insitu-source` are left alone — safe to
58
+ run alongside the [Babel-plugin fallback](https://www.npmjs.com/package/@insitue/sdk)
59
+ during a migration.
60
+ - **Per-file skip via `exclude`.** Whole files matching any exclude substring are skipped
61
+ entirely (the plugin doesn't visit their AST at all).
62
+ - **Paths are POSIX, relative to `rootDir`.** If your `rootDir` is `/Users/you/app` and the
63
+ file is `/Users/you/app/src/components/Button.tsx`, the emitted attribute is
64
+ `data-insitu-source="src/components/Button.tsx:42:8"`. Line is 1-based; column is the
65
+ 0-based byte offset (matches SWC's convention).
66
+
67
+ ## Compatibility
68
+
69
+ This plugin compiles against `swc_core` 50.x — the version Next.js 15.5.x bundles in
70
+ `@next/swc`. SWC's plugin ABI breaks periodically (see SWC's
71
+ [plugin-compat docs](https://swc.rs/docs/plugin/selecting-swc-core)). We pin to the latest
72
+ stable swc_core supported by current Next, and ship patch releases when Next bumps.
73
+
74
+ | `@insitue/swc-source-attr` | `swc_core` | Verified with Next.js |
75
+ |---|---|---|
76
+ | `0.1.x` | `50.2.3` | `15.5.x` |
77
+
78
+ If you hit one of the SWC plugin-host error signatures
79
+ (`failed to invoke plugin`, `out of bounds memory access`,
80
+ `LayoutError called Result::unwrap()`), you're on an incompatible combination — either
81
+ upgrade Next.js to the matching version or fall back to the
82
+ [Babel plugin](https://www.npmjs.com/package/@insitue/sdk) (`@insitue/sdk/babel` — Babel's
83
+ ABI is stable forever, no compat dance).
84
+
85
+ ## What it does, end-to-end
86
+
87
+ ```jsx
88
+ // You write:
89
+ function Button({ children }) {
90
+ return <button className="bg-violet-500">{children}</button>;
91
+ }
92
+
93
+ // SWC + this plugin emit (in your prod bundle):
94
+ function Button({ children }) {
95
+ return (
96
+ <button
97
+ className="bg-violet-500"
98
+ data-insitu-source="src/components/Button.tsx:2:10"
99
+ >
100
+ {children}
101
+ </button>
102
+ );
103
+ }
104
+ ```
105
+
106
+ When a real user clicks that button in your deployed app and reports a bug via the
107
+ `@insitue/sdk` widget, the captured bundle carries the exact `file:line:col`. The cloud
108
+ agent opens `src/components/Button.tsx`, jumps to line 2, edits with full context, runs
109
+ your typecheck + build inside a sandbox, and pushes a draft PR for review.
110
+
111
+ ## License
112
+
113
+ MIT.
Binary file
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@insitue/swc-source-attr",
3
+ "version": "0.1.1",
4
+ "description": "SWC plugin that stamps every JSX element with data-insitu-source=\"file:line:col\" so the InSitue cloud agent can resolve captures to exact source coordinates.",
5
+ "license": "MIT",
6
+ "main": "insitue_swc_source_attr.wasm",
7
+ "files": [
8
+ "insitue_swc_source_attr.wasm",
9
+ "README.md",
10
+ "LICENSE"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/InSitue/insitue.git",
15
+ "directory": "packages/swc-source-attr"
16
+ },
17
+ "homepage": "https://www.insitue.com",
18
+ "bugs": {
19
+ "url": "https://github.com/InSitue/insitue/issues"
20
+ },
21
+ "keywords": [
22
+ "insitue",
23
+ "swc",
24
+ "swc-plugin",
25
+ "babel",
26
+ "source",
27
+ "jsx",
28
+ "instrumentation",
29
+ "react",
30
+ "nextjs"
31
+ ],
32
+ "author": "InSitue (https://www.insitue.com)",
33
+ "publishConfig": {
34
+ "access": "public",
35
+ "registry": "https://registry.npmjs.org/"
36
+ },
37
+ "scripts": {
38
+ "build": "cargo build-wasi && cp target/wasm32-wasip1/release/insitue_swc_source_attr.wasm .",
39
+ "test": "cargo test"
40
+ }
41
+ }