@reticlehq/next 2.3.0 → 2.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.
Files changed (2) hide show
  1. package/index.cjs +57 -0
  2. package/package.json +2 -2
package/index.cjs CHANGED
@@ -13,6 +13,7 @@ const path = require('node:path');
13
13
  const PAIRING_TOKEN_DIR_ENV = 'RETICLE_PAIRING_TOKEN_DIR';
14
14
  const PAIRING_TOKEN_FILE = 'pairing-token';
15
15
 
16
+
16
17
  /**
17
18
  * Read the daemon's auto-provisioned pairing token (~/.reticle/pairing-token, or the
18
19
  * RETICLE_PAIRING_TOKEN_DIR override). Node-side only. Returns undefined if the daemon hasn't started
@@ -32,6 +33,56 @@ function readPairingToken() {
32
33
  }
33
34
  }
34
35
 
36
+ /**
37
+ * The stamping loader, addressed by package export so both bundlers can resolve it. Turbopack takes
38
+ * loaders by module id, not by absolute path.
39
+ */
40
+ const LOADER_MODULE = '@reticlehq/next/loader';
41
+
42
+ /**
43
+ * The top-level `turbopack` config key is stable from Next 15.3; before that it was
44
+ * `experimental.turbo`, and an unknown top-level key makes Next print an "Invalid next.config.js
45
+ * options detected" warning on every boot. Older Next also defaults to webpack, so it does not need
46
+ * the key at all — emitting it would be pure noise in somebody's terminal.
47
+ * @returns {boolean}
48
+ */
49
+ function supportsTurbopackKey() {
50
+ try {
51
+ const { version } = require('next/package.json');
52
+ const [major, minor] = String(version).split('.').map((n) => parseInt(n, 10));
53
+ if (!Number.isFinite(major)) return true; // unreadable version: assume modern, matching npm's default
54
+ if (major > 15) return true;
55
+ return major === 15 && Number.isFinite(minor) && minor >= 3;
56
+ } catch {
57
+ return true;
58
+ }
59
+ }
60
+
61
+ /**
62
+ * Turbopack rules mirroring the webpack pre-loader.
63
+ *
64
+ * Next 16 made Turbopack the DEFAULT, and a config carrying a `webpack` key with no `turbopack` key
65
+ * is a hard startup error there ("This build is using Turbopack, with a webpack config and no
66
+ * turbopack config") — so `withReticle` killed `next dev` outright for every new Next app. Emitting
67
+ * both keys means whichever bundler is running finds its own wiring and neither errors on the other.
68
+ * @param {Record<string, unknown> | undefined} existing
69
+ */
70
+ function turbopackConfig(existing) {
71
+ const rule = { loaders: [LOADER_MODULE] };
72
+ const prev = existing !== undefined && existing !== null ? existing : {};
73
+ const prevRules = prev.rules !== undefined && prev.rules !== null ? prev.rules : {};
74
+ return {
75
+ ...prev,
76
+ rules: {
77
+ ...prevRules,
78
+ // No `as:` — the loader only stamps attributes, so the module type is unchanged. Naming the
79
+ // type here makes Turbopack rewrite the module id (./x.tsx → ./x.tsx.tsx) and every import breaks.
80
+ '*.tsx': rule,
81
+ '*.jsx': rule,
82
+ },
83
+ };
84
+ }
85
+
35
86
  /**
36
87
  * @param {import('next').NextConfig} [nextConfig]
37
88
  * @returns {import('next').NextConfig}
@@ -44,12 +95,18 @@ function withReticle(nextConfig = {}) {
44
95
  const token = readPairingToken();
45
96
  return {
46
97
  ...nextConfig,
98
+ ...(supportsTurbopackKey() ? { turbopack: turbopackConfig(nextConfig.turbopack) } : {}),
47
99
  // Expose the token to the client bundle as process.env.NEXT_PUBLIC_RETICLE_TOKEN (Next's convention
48
100
  // for client-readable env), so a dev-only client connect can present it. Omitted when the daemon
49
101
  // hasn't provisioned one yet — the client then connects without it and the page reloads once it has.
50
102
  env: {
51
103
  ...nextConfig.env,
52
104
  ...(token !== undefined ? { NEXT_PUBLIC_RETICLE_TOKEN: token } : {}),
105
+ // The project root, so the SDK can report React's absolute `_debugSource.fileName` as a
106
+ // repo-relative path. Passed via `env` rather than a webpack DefinePlugin because Turbopack — the
107
+ // Next 16 default — never runs the webpack branch, and a source pointer that only works on one
108
+ // of the two bundlers is worse than one that works on neither.
109
+ NEXT_PUBLIC_RETICLE_ROOT: process.cwd(),
53
110
  },
54
111
  webpack(config, ctx) {
55
112
  config.module = config.module || { rules: [] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reticlehq/next",
3
- "version": "2.3.0",
3
+ "version": "2.4.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.3.0"
41
+ "@reticlehq/babel-plugin": "2.4.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "next": ">=13"