@reticlehq/vite-plugin 3.2.0 → 3.4.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.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Which files get a `data-reticle-source` stamp, and how.
3
+ *
4
+ * Split out of index.ts when that file crossed the line cap while gaining the per-file opt-out.
5
+ * This is one concern — a module id comes in, and either a stamper runs on it, nothing does, or the
6
+ * file has asked to be left alone — and it changes for one reason (the source-pointer feature)
7
+ * rather than for the dozen the plugin's lifecycle does. The Svelte stamper is its sibling module;
8
+ * the JSX one is `@reticlehq/babel-plugin`, which also reads the opt-out on its own for the callers
9
+ * that reach it without Vite.
10
+ */
11
+ export declare const NODE_MODULES = "node_modules";
12
+ /** A module id we may stamp at all: not virtual, not a dependency. Extension decides which stamper. */
13
+ export declare function stampableId(id: string): string | null;
14
+ export declare function shouldStamp(id: string): boolean;
15
+ /** A `.svelte` single-file component, which needs the Svelte stamper rather than Babel. */
16
+ export declare function shouldStampSvelte(id: string): boolean;
17
+ export declare function stamp(code: string, id: string): {
18
+ code: string;
19
+ map: string | null;
20
+ } | null;
21
+ /**
22
+ * Has this file asked not to be stamped?
23
+ *
24
+ * Decided ahead of BOTH stampers, so the Svelte path honours the marker too and so the opt-out is
25
+ * announced once regardless of which stamper would have run. Only a file one of them would have
26
+ * touched can opt out — an id that was never stampable has nothing to announce (#853).
27
+ */
28
+ export declare function optsOutOfStamping(code: string, id: string): boolean;
29
+ /**
30
+ * The one line said when a file opts out of source stamping with `@reticle-ignore`.
31
+ *
32
+ * Not silent, on purpose. An opt-out nobody is told about is an opt-out somebody forgets, and the
33
+ * `file:line` it would have produced quietly stops resolving months later with nothing to point at
34
+ * the comment. Said once per file, in the dev-server output where the person who added the comment
35
+ * will see it. Exported for the test that pins the wording.
36
+ */
37
+ export declare function ignoredFileNotice(id: string): string;
@@ -0,0 +1,99 @@
1
+ /**
2
+ * Which files get a `data-reticle-source` stamp, and how.
3
+ *
4
+ * Split out of index.ts when that file crossed the line cap while gaining the per-file opt-out.
5
+ * This is one concern — a module id comes in, and either a stamper runs on it, nothing does, or the
6
+ * file has asked to be left alone — and it changes for one reason (the source-pointer feature)
7
+ * rather than for the dozen the plugin's lifecycle does. The Svelte stamper is its sibling module;
8
+ * the JSX one is `@reticlehq/babel-plugin`, which also reads the opt-out on its own for the callers
9
+ * that reach it without Vite.
10
+ */
11
+ import { transformSync } from '@babel/core';
12
+ import reticleSource from '@reticlehq/babel-plugin';
13
+ import { isSourceStampingIgnored } from '@reticlehq/babel-plugin/ignore';
14
+ import { RETICLE_IGNORE_MARKER } from '@reticlehq/core';
15
+ import { SVELTE_FILE } from './svelte-source.js';
16
+ /** Files we stamp with source info — JSX/TSX only. */
17
+ const JSX_FILE = /\.[jt]sx$/;
18
+ /** Rollup virtual-module ids start with a NUL byte; never transform those. */
19
+ const VIRTUAL_PREFIX = '\0';
20
+ export const NODE_MODULES = 'node_modules';
21
+ /** A module id we may stamp at all: not virtual, not a dependency. Extension decides which stamper. */
22
+ export function stampableId(id) {
23
+ if (id.startsWith(VIRTUAL_PREFIX))
24
+ return null;
25
+ if (id.includes(NODE_MODULES))
26
+ return null;
27
+ // Strip any query suffix (?worker, ?raw,...) before matching the extension.
28
+ return id.split('?')[0] ?? id;
29
+ }
30
+ /**
31
+ * A test file, by the names every JS test runner agrees on.
32
+ *
33
+ * `.test.`/`.spec.` before the extension, or anywhere under a `__tests__` directory. Anchored to a
34
+ * path SEGMENT and a dot so `TestBanner.tsx`, `latest.tsx` and `contest.tsx` stay ordinary
35
+ * components — they are somebody's app, and skipping them would silently cost source mapping.
36
+ */
37
+ const TEST_FILE = /(?:\.(?:test|spec)\.[^./]+$)|(?:^|\/)__tests__\//;
38
+ export function shouldStamp(id) {
39
+ const clean = stampableId(id);
40
+ if (null === clean)
41
+ return false;
42
+ /*
43
+ * A test file is not the app under test.
44
+ *
45
+ * Nothing reads `data-reticle-source` on one — an agent inspects the app's DOM, never a test's —
46
+ * so stamping them is pure cost, charged per file on every run, and reported from the field as
47
+ * nearly doubling a large jsdom suite and failing a test that passed without instrumentation:
48
+ * inserting attributes into JSX is exactly what an assertion on rendered output notices (#995).
49
+ *
50
+ * Cut on the NAME rather than on "are we under Vitest": `vitest-browser.ts` records what happened
51
+ * the last time that was cut on the `VITEST` env var, which also reads true when a Vitest suite
52
+ * boots an app in order to test it. A name check cannot make that mistake.
53
+ */
54
+ if (TEST_FILE.test(clean))
55
+ return false;
56
+ return JSX_FILE.test(clean);
57
+ }
58
+ /** A `.svelte` single-file component, which needs the Svelte stamper rather than Babel. */
59
+ export function shouldStampSvelte(id) {
60
+ const clean = stampableId(id);
61
+ return clean !== null && SVELTE_FILE.test(clean);
62
+ }
63
+ export function stamp(code, id) {
64
+ const out = transformSync(code, {
65
+ filename: id,
66
+ plugins: [reticleSource],
67
+ parserOpts: { plugins: ['jsx', 'typescript'] },
68
+ sourceMaps: true,
69
+ configFile: false,
70
+ babelrc: false,
71
+ });
72
+ if (out?.code === undefined || null === out.code)
73
+ return null;
74
+ return {
75
+ code: out.code,
76
+ map: out.map === undefined || null === out.map ? null : JSON.stringify(out.map),
77
+ };
78
+ }
79
+ /**
80
+ * Has this file asked not to be stamped?
81
+ *
82
+ * Decided ahead of BOTH stampers, so the Svelte path honours the marker too and so the opt-out is
83
+ * announced once regardless of which stamper would have run. Only a file one of them would have
84
+ * touched can opt out — an id that was never stampable has nothing to announce (#853).
85
+ */
86
+ export function optsOutOfStamping(code, id) {
87
+ return (shouldStamp(id) || shouldStampSvelte(id)) && isSourceStampingIgnored(code);
88
+ }
89
+ /**
90
+ * The one line said when a file opts out of source stamping with `@reticle-ignore`.
91
+ *
92
+ * Not silent, on purpose. An opt-out nobody is told about is an opt-out somebody forgets, and the
93
+ * `file:line` it would have produced quietly stops resolving months later with nothing to point at
94
+ * the comment. Said once per file, in the dev-server output where the person who added the comment
95
+ * will see it. Exported for the test that pins the wording.
96
+ */
97
+ export function ignoredFileNotice(id) {
98
+ return `[reticle] ${id} opts out of source stamping (${RETICLE_IGNORE_MARKER} on its first line) — elements in it will have no file:line.`;
99
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reticlehq/vite-plugin",
3
- "version": "3.2.0",
3
+ "version": "3.4.0",
4
4
  "description": "Vite plugin for Reticle: dev-only source-map stamping plus auto-injected reticle.connect(). apply:'serve' guarantees it never ships to production.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -41,15 +41,15 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "@babel/core": "^7.26.0",
44
- "@reticlehq/babel-plugin": "3.2.0",
45
- "@reticlehq/core": "3.2.0"
44
+ "@reticlehq/babel-plugin": "3.4.0",
45
+ "@reticlehq/core": "3.4.0"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@types/babel__core": "^7.20.5",
49
49
  "esbuild": "^0.28.2",
50
- "svelte": "^5.56.10",
50
+ "svelte": "^5.57.1",
51
51
  "vite": "^8",
52
- "@reticlehq/react": "3.2.0"
52
+ "@reticlehq/react": "3.4.0"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "vite": ">=4"