@reticlehq/next 2.12.0 → 2.13.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/index.cjs +37 -12
- package/package.json +2 -2
package/index.cjs
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
const fs = require('node:fs');
|
|
8
8
|
const os = require('node:os');
|
|
9
9
|
const path = require('node:path');
|
|
10
|
+
const crypto = require('node:crypto');
|
|
10
11
|
|
|
11
12
|
// Kept in sync with @reticlehq/core (ReticleDir / ReticleEnv). This package is plain CJS tooling and
|
|
12
13
|
// deliberately has no ESM/TS dependency on core, so the two constants are mirrored here.
|
|
@@ -25,24 +26,47 @@ const RETICLE_CLIENT_HOST = 'localhost';
|
|
|
25
26
|
const RETICLE_WS_PATH = '/reticle';
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
|
-
* Read the
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* Read the pairing token, or create it — whichever process gets there first.
|
|
30
|
+
*
|
|
31
|
+
* The token used to be read ONCE, when next.config was evaluated. Start `next dev` before the
|
|
32
|
+
* daemon and that value was empty, every page was refused, and a reload could not help: there was
|
|
33
|
+
* no token page-side to pick up. The comment that claimed "the client then connects without a token
|
|
34
|
+
* and the page reloads once it has" was false for Next.
|
|
35
|
+
*
|
|
36
|
+
* Same mint as the daemon (24 random bytes, 0600 file, never overwrite). An existing token is
|
|
37
|
+
* reused so a plugin-injected page keeps working after the daemon bounces.
|
|
38
|
+
* @param {string} dir
|
|
32
39
|
* @returns {string | undefined}
|
|
33
40
|
*/
|
|
34
|
-
function
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
41
|
+
function ensurePairingToken(dir) {
|
|
42
|
+
const file = path.join(dir, PAIRING_TOKEN_FILE);
|
|
43
|
+
try {
|
|
44
|
+
const existing = fs.readFileSync(file, 'utf8').trim();
|
|
45
|
+
if (existing.length > 0) return existing;
|
|
46
|
+
} catch {
|
|
47
|
+
/* missing or unreadable — fall through and create one */
|
|
48
|
+
}
|
|
38
49
|
try {
|
|
39
|
-
const token =
|
|
40
|
-
|
|
50
|
+
const token = crypto.randomBytes(24).toString('hex');
|
|
51
|
+
fs.mkdirSync(dir, { recursive: true, mode: 0o700 });
|
|
52
|
+
fs.writeFileSync(file, token, { encoding: 'utf8', mode: 0o600 });
|
|
53
|
+
fs.chmodSync(file, 0o600);
|
|
54
|
+
return token;
|
|
41
55
|
} catch {
|
|
42
56
|
return undefined;
|
|
43
57
|
}
|
|
44
58
|
}
|
|
45
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Read or mint the daemon's auto-provisioned pairing token (~/.reticle/pairing-token, or the
|
|
62
|
+
* RETICLE_PAIRING_TOKEN_DIR override). Node-side only. Minting here is what makes `next dev` before
|
|
63
|
+
* the daemon still authenticate.
|
|
64
|
+
* @returns {string | undefined}
|
|
65
|
+
*/
|
|
66
|
+
function readPairingToken() {
|
|
67
|
+
return ensurePairingToken(reticleHomeDir());
|
|
68
|
+
}
|
|
69
|
+
|
|
46
70
|
/**
|
|
47
71
|
* Find the live daemon serving THIS project and return its websocket URL.
|
|
48
72
|
*
|
|
@@ -249,8 +273,9 @@ function withReticle(nextConfig = {}) {
|
|
|
249
273
|
...nextConfig,
|
|
250
274
|
...(supportsTurbopackKey() ? { turbopack: turbopackConfig(nextConfig.turbopack) } : {}),
|
|
251
275
|
// Expose the token to the client bundle as process.env.NEXT_PUBLIC_RETICLE_TOKEN (Next's convention
|
|
252
|
-
// for client-readable env), so a dev-only client connect can present it.
|
|
253
|
-
//
|
|
276
|
+
// for client-readable env), so a dev-only client connect can present it. Minted here if the file
|
|
277
|
+
// is missing: Next evaluates this once, so an empty value is frozen and a reload cannot pick a
|
|
278
|
+
// later token up. Omitted only when the directory is unwritable.
|
|
254
279
|
env: {
|
|
255
280
|
...nextConfig.env,
|
|
256
281
|
...(token !== undefined ? { NEXT_PUBLIC_RETICLE_TOKEN: token } : {}),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reticlehq/next",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.13.0",
|
|
4
4
|
"description": "Next.js helper for Reticle: keeps SWC, adds source-file mapping via a dev-only webpack pre-loader (data-reticle-source).",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Reticle contributors",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@babel/core": "^7.26.0",
|
|
41
|
-
"@reticlehq/babel-plugin": "2.
|
|
41
|
+
"@reticlehq/babel-plugin": "2.13.0"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"next": ">=13"
|