@reticlehq/vite-plugin 3.7.0 → 3.8.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/dist/announce.d.ts +2 -0
- package/dist/announce.js +13 -0
- package/dist/index.cjs +5849 -3930
- package/dist/index.js +15 -6
- package/dist/project-id.js +25 -4
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -2,11 +2,11 @@ import { existsSync, readFileSync } from 'node:fs';
|
|
|
2
2
|
import { missingTokenWarning } from './token/missing-token.js';
|
|
3
3
|
import { ensurePairingToken } from './token/ensure-token.js';
|
|
4
4
|
import { homedir } from 'node:os';
|
|
5
|
-
import { join } from 'node:path';
|
|
6
|
-
import { RETICLE_RENDER_PREHOOK, ReticleDir, ReticleEnv, RETICLE_ROOT_GLOBAL, RETICLE_SDK_VERSION_GLOBAL, } from '@reticlehq/core';
|
|
5
|
+
import { isAbsolute, join, resolve, sep } from 'node:path';
|
|
6
|
+
import { RETICLE_RENDER_PREHOOK, ReticleDir, ReticleEnv, RETICLE_ROOT_GLOBAL, RETICLE_SDK_VERSION_GLOBAL, resolveStateDir, } from '@reticlehq/core';
|
|
7
7
|
import { readConfiguredTestIdAttribute, resolveProjectId } from './project-id.js';
|
|
8
8
|
import { resolveDaemonPort } from './discover-port.js';
|
|
9
|
-
import { announceDevServer } from './announce.js';
|
|
9
|
+
import { announceDevServer, announcedUrl } from './announce.js';
|
|
10
10
|
import { stampSvelte } from './svelte-source.js';
|
|
11
11
|
import { NODE_MODULES, ignoredFileNotice, optsOutOfStamping, shouldStamp, shouldStampSvelte, stamp, } from './stamping.js';
|
|
12
12
|
import { resolvableChain, sdkPackageVersion, sdkBuildFingerprint, viteMajor, optimizerOptionsKey, optimizerOptions, } from './installed.js';
|
|
@@ -135,8 +135,17 @@ function isHtmlEntry(id, specifier, root) {
|
|
|
135
135
|
* undefined if the daemon hasn't started yet (the page reloads once it has). Exported for testing.
|
|
136
136
|
*/
|
|
137
137
|
export function readPairingToken() {
|
|
138
|
-
|
|
139
|
-
|
|
138
|
+
let dir;
|
|
139
|
+
try {
|
|
140
|
+
// The daemon's rule: a relative folder is resolved against the working folder, and a Windows
|
|
141
|
+
// path on POSIX is not used. Both warn, so the two sides agree on one token file.
|
|
142
|
+
dir = resolveStateDir(process.env[ReticleEnv.PAIRING_TOKEN_DIR], join(homedir(), ReticleDir.ROOT), { isAbsolute, resolve, sep }, (warning) => console.warn(`[reticle] ${warning}`));
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
// Only a home folder that is not absolute gets here. The dev server still starts.
|
|
146
|
+
console.warn(`[reticle] ${error instanceof Error ? error.message : String(error)}`);
|
|
147
|
+
return undefined;
|
|
148
|
+
}
|
|
140
149
|
// Read-or-CREATE, matching the daemon. Reading alone meant a dev server started before the daemon
|
|
141
150
|
// baked in an empty token and every page it served was refused — with the SDK loading and the
|
|
142
151
|
// socket opening, so nothing looked broken. See ensure-token for the bisect.
|
|
@@ -568,7 +577,7 @@ export function reticle(options = {}) {
|
|
|
568
577
|
port,
|
|
569
578
|
pid: process.pid,
|
|
570
579
|
root: opts.root ?? process.cwd(),
|
|
571
|
-
url: server.resolvedUrls?.local[0]
|
|
580
|
+
url: announcedUrl(process.env, server.resolvedUrls?.local[0], port),
|
|
572
581
|
...(opts.sdkVersion === undefined || 0 === opts.sdkVersion.length
|
|
573
582
|
? {}
|
|
574
583
|
: { sdkVersion: opts.sdkVersion }),
|
package/dist/project-id.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { createHash } from 'node:crypto';
|
|
10
10
|
import { dirname, join } from 'node:path';
|
|
11
11
|
import { readFileSync } from 'node:fs';
|
|
12
|
-
import { PROJECT_ID_HASH_LENGTH, TESTID_ATTR_PATTERN, projectIdFrom } from '@reticlehq/core';
|
|
12
|
+
import { PROJECT_ID_HASH_LENGTH, TESTID_ATTR_PATTERN, mainCheckoutTwin, projectIdFrom, } from '@reticlehq/core';
|
|
13
13
|
/** The project config `reticle init` writes, and the id of record it carries. */
|
|
14
14
|
const RETICLE_CONFIG_BASENAME = '.reticle.json';
|
|
15
15
|
export { slugifyPackageName } from '@reticlehq/core';
|
|
@@ -76,6 +76,27 @@ function readNearestField(startDir, basename, field, readFile, maxDepth, accept)
|
|
|
76
76
|
}
|
|
77
77
|
return undefined;
|
|
78
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* A field of the nearest `.reticle.json`, else of the main checkout's when `startDir` is in a git
|
|
81
|
+
* worktree that has none (it is git-ignored, or not committed yet). Every worktree of a project is
|
|
82
|
+
* the same project: one id, one daemon port.
|
|
83
|
+
*/
|
|
84
|
+
function readConfigField(startDir, field, readFile, accept) {
|
|
85
|
+
const own = readNearestField(startDir, RETICLE_CONFIG_BASENAME, field, readFile, MAX_CONFIG_SEARCH_DEPTH, accept);
|
|
86
|
+
if (own !== undefined)
|
|
87
|
+
return own;
|
|
88
|
+
const twin = mainCheckoutTwin(startDir, (path) => {
|
|
89
|
+
try {
|
|
90
|
+
return readFile(path);
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return twin === undefined
|
|
97
|
+
? undefined
|
|
98
|
+
: readNearestField(twin, RETICLE_CONFIG_BASENAME, field, readFile, MAX_CONFIG_SEARCH_DEPTH, accept);
|
|
99
|
+
}
|
|
79
100
|
/** Read the `name` from the nearest package.json at or above `startDir`, or undefined if none. */
|
|
80
101
|
function readNearestPackageName(startDir, readFile = readFileOrThrow) {
|
|
81
102
|
return readNearestField(startDir, 'package.json', 'name', readFile, MAX_PACKAGE_SEARCH_DEPTH, nonEmptyString);
|
|
@@ -87,7 +108,7 @@ function readNearestPackageName(startDir, readFile = readFileOrThrow) {
|
|
|
87
108
|
* through `init` — it is not a second opinion, and where the two disagree the config wins.
|
|
88
109
|
*/
|
|
89
110
|
export function readConfiguredProjectId(startDir, readFile = readFileOrThrow) {
|
|
90
|
-
return
|
|
111
|
+
return readConfigField(startDir, 'projectId', readFile, nonEmptyString);
|
|
91
112
|
}
|
|
92
113
|
/**
|
|
93
114
|
* Read the daemon port `reticle init --port` recorded in the nearest `.reticle.json`, or undefined.
|
|
@@ -97,7 +118,7 @@ export function readConfiguredProjectId(startDir, readFile = readFileOrThrow) {
|
|
|
97
118
|
* project's daemon — and the bridge refused it.
|
|
98
119
|
*/
|
|
99
120
|
export function readConfiguredPort(startDir, readFile = readFileOrThrow) {
|
|
100
|
-
return
|
|
121
|
+
return readConfigField(startDir, 'port', readFile, tcpPort);
|
|
101
122
|
}
|
|
102
123
|
/**
|
|
103
124
|
* Read `testIdAttribute` from the nearest `.reticle.json`, or undefined: the attribute this project
|
|
@@ -106,7 +127,7 @@ export function readConfiguredPort(startDir, readFile = readFileOrThrow) {
|
|
|
106
127
|
* already agree on, so the plugin forwards it to `connect()` rather than asking for it twice.
|
|
107
128
|
*/
|
|
108
129
|
export function readConfiguredTestIdAttribute(startDir, readFile = readFileOrThrow) {
|
|
109
|
-
return
|
|
130
|
+
return readConfigField(startDir, 'testIdAttribute', readFile, (value) => 'string' === typeof value && TESTID_ATTR_PATTERN.test(value) ? value : undefined);
|
|
110
131
|
}
|
|
111
132
|
/**
|
|
112
133
|
* Resolve the projectId for a plugin instance, most-local statement of intent first: an explicit
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reticlehq/vite-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.8.1",
|
|
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.
|
|
45
|
-
"@reticlehq/core": "3.
|
|
44
|
+
"@reticlehq/babel-plugin": "3.8.1",
|
|
45
|
+
"@reticlehq/core": "3.8.1"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@types/babel__core": "^7.20.5",
|
|
49
49
|
"esbuild": "^0.28.2",
|
|
50
50
|
"svelte": "^5.57.1",
|
|
51
51
|
"vite": "^8",
|
|
52
|
-
"@reticlehq/react": "3.
|
|
52
|
+
"@reticlehq/react": "3.8.1"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
55
|
"vite": ">=4"
|