@bleedingdev/tanstack-redact 0.2.1 → 0.3.2

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 (120) hide show
  1. package/dist/bundler-core/resolution.d.ts +31 -0
  2. package/dist/bundler-core/resolution.js +80 -0
  3. package/dist/bundler-core/resolution.js.map +7 -0
  4. package/dist/bundler-core/selection.d.ts +89 -0
  5. package/dist/bundler-core/selection.js +103 -0
  6. package/dist/bundler-core/selection.js.map +7 -0
  7. package/dist/core/devtools.d.ts +1 -1
  8. package/dist/core/devtools.js +1 -0
  9. package/dist/core/devtools.js.map +2 -2
  10. package/dist/core/functions.js +1 -0
  11. package/dist/core/functions.js.map +2 -2
  12. package/dist/core/internal.d.ts +5 -4
  13. package/dist/core/internal.js +4 -3
  14. package/dist/core/internal.js.map +2 -2
  15. package/dist/core/types.d.ts +2 -2
  16. package/dist/core/types.js +1 -0
  17. package/dist/core/types.js.map +1 -1
  18. package/dist/dom/devtools.d.ts +5 -5
  19. package/dist/dom/devtools.js +1 -0
  20. package/dist/dom/devtools.js.map +2 -2
  21. package/dist/dom/dispatcher.d.ts +1 -1
  22. package/dist/dom/dispatcher.js +1 -0
  23. package/dist/dom/dispatcher.js.map +3 -3
  24. package/dist/dom/document-metadata.d.ts +1 -1
  25. package/dist/dom/document-metadata.js +3 -1
  26. package/dist/dom/document-metadata.js.map +2 -2
  27. package/dist/dom/dom.js +1 -1
  28. package/dist/dom/dom.js.map +2 -2
  29. package/dist/dom/features/class/full.js +25 -32
  30. package/dist/dom/features/class/full.js.map +2 -2
  31. package/dist/dom/features/class/stub.js +1 -0
  32. package/dist/dom/features/class/stub.js.map +2 -2
  33. package/dist/dom/features/hydration/full.d.ts +6 -6
  34. package/dist/dom/features/hydration/full.js +20 -29
  35. package/dist/dom/features/hydration/full.js.map +2 -2
  36. package/dist/dom/features/hydration/stub.d.ts +7 -2
  37. package/dist/dom/features/hydration/stub.js +1 -0
  38. package/dist/dom/features/hydration/stub.js.map +2 -2
  39. package/dist/dom/features/lazy/full.js +1 -0
  40. package/dist/dom/features/lazy/full.js.map +2 -2
  41. package/dist/dom/features/suspense/full.d.ts +4 -1
  42. package/dist/dom/features/suspense/full.js +22 -161
  43. package/dist/dom/features/suspense/full.js.map +2 -2
  44. package/dist/dom/features/suspense-hydration/full.d.ts +8 -0
  45. package/dist/dom/features/suspense-hydration/full.js +147 -0
  46. package/dist/dom/features/suspense-hydration/full.js.map +7 -0
  47. package/dist/dom/features/suspense-hydration/index.d.ts +1 -0
  48. package/dist/dom/features/suspense-hydration/index.js +2 -0
  49. package/dist/dom/features/suspense-hydration/index.js.map +7 -0
  50. package/dist/dom/features/suspense-hydration/stub.d.ts +2 -0
  51. package/dist/dom/features/suspense-hydration/stub.js +9 -0
  52. package/dist/dom/features/suspense-hydration/stub.js.map +7 -0
  53. package/dist/dom/features/suspense-runtime/stub.js +1 -0
  54. package/dist/dom/features/suspense-runtime/stub.js.map +2 -2
  55. package/dist/dom/profiling.d.ts +36 -0
  56. package/dist/dom/profiling.js +9 -0
  57. package/dist/dom/profiling.js.map +7 -0
  58. package/dist/dom/react-ids.js +1 -0
  59. package/dist/dom/react-ids.js.map +2 -2
  60. package/dist/dom/reconcile.d.ts +4 -5
  61. package/dist/dom/reconcile.js +102 -144
  62. package/dist/dom/reconcile.js.map +2 -2
  63. package/dist/dom/resources.js +1 -0
  64. package/dist/dom/resources.js.map +2 -2
  65. package/dist/dom/root-internal.d.ts +1 -1
  66. package/dist/dom/root-internal.js +4 -3
  67. package/dist/dom/root-internal.js.map +2 -2
  68. package/dist/dom/root.d.ts +2 -2
  69. package/dist/dom/root.js +1 -0
  70. package/dist/dom/root.js.map +2 -2
  71. package/dist/dom/synthetic-event.js +6 -4
  72. package/dist/dom/synthetic-event.js.map +2 -2
  73. package/dist/dom/transitions.d.ts +1 -1
  74. package/dist/dom/transitions.js +1 -0
  75. package/dist/dom/transitions.js.map +2 -2
  76. package/dist/react/action-scope.d.ts +1 -1
  77. package/dist/react/action-scope.js +1 -0
  78. package/dist/react/action-scope.js.map +2 -2
  79. package/dist/rspack/index.d.ts +2 -0
  80. package/dist/rspack/index.js +6 -0
  81. package/dist/rspack/index.js.map +7 -0
  82. package/dist/server/bootstrap-script.js +1 -0
  83. package/dist/server/bootstrap-script.js.map +2 -2
  84. package/dist/server/dispatcher.js +11 -20
  85. package/dist/server/dispatcher.js.map +2 -2
  86. package/dist/server/insertion-context.js +9 -16
  87. package/dist/server/insertion-context.js.map +7 -0
  88. package/dist/server/stream-ids.js +1 -0
  89. package/dist/server/stream-ids.js.map +7 -0
  90. package/dist/server/stream.d.ts +1 -2
  91. package/dist/server/stream.js +106 -122
  92. package/dist/server/stream.js.map +2 -2
  93. package/dist/server/walk.js +69 -72
  94. package/dist/server/walk.js.map +3 -3
  95. package/dist/vite/index.d.ts +5 -99
  96. package/dist/vite/index.js +56 -179
  97. package/dist/vite/index.js.map +2 -2
  98. package/dist/webpack/index.d.ts +46 -0
  99. package/dist/webpack/index.js +102 -0
  100. package/dist/webpack/index.js.map +7 -0
  101. package/dist/webpack/react18-loader.cjs +25 -0
  102. package/package.json +17 -3
  103. package/src/bundler-core/resolution.ts +131 -0
  104. package/src/bundler-core/selection.ts +192 -0
  105. package/src/core/internal.ts +2 -1
  106. package/src/core/types.ts +3 -2
  107. package/src/dom/dom.ts +1 -1
  108. package/src/dom/features/class/full.ts +26 -34
  109. package/src/dom/features/suspense/full.ts +7 -165
  110. package/src/dom/features/suspense-hydration/full.ts +166 -0
  111. package/src/dom/features/suspense-hydration/index.ts +1 -0
  112. package/src/dom/features/suspense-hydration/stub.ts +2 -0
  113. package/src/dom/profiling.ts +6 -0
  114. package/src/dom/reconcile.ts +16 -6
  115. package/src/dom/synthetic-event.ts +9 -4
  116. package/src/rspack/index.ts +2 -0
  117. package/src/server/stream.ts +15 -14
  118. package/src/vite/index.ts +55 -317
  119. package/src/webpack/index.ts +108 -0
  120. package/src/webpack/react18-loader.cjs +25 -0
@@ -1,165 +1,10 @@
1
- import { existsSync, readFileSync, realpathSync } from "node:fs";
1
+ import { readFileSync, realpathSync } from "node:fs";
2
2
  import { dirname, resolve as resolvePath } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { adaptReact18 } from "./react18.js";
5
- const PRESET_DEFAULTS = {
6
- // Opt-in: everything off. Turn individual features on via `features`.
7
- nano: {
8
- activity: false,
9
- fragmentRefs: false,
10
- viewTransitions: false,
11
- portal: false,
12
- context: false,
13
- suspense: false,
14
- memo: false,
15
- forwardRef: false,
16
- lazy: false,
17
- classComponents: false,
18
- hydration: false
19
- },
20
- // Opt-out: everything on (drop-in React parity). Turn features off via `features`.
21
- full: {
22
- activity: true,
23
- fragmentRefs: true,
24
- viewTransitions: false,
25
- portal: true,
26
- context: true,
27
- suspense: true,
28
- memo: true,
29
- forwardRef: true,
30
- lazy: true,
31
- classComponents: true,
32
- hydration: true
33
- }
34
- };
35
- function resolveFeatures(preset, overrides) {
36
- const p = PRESET_DEFAULTS[preset];
37
- return {
38
- activity: overrides.activity ?? p.activity,
39
- fragmentRefs: overrides.fragmentRefs ?? p.fragmentRefs,
40
- viewTransitions: overrides.viewTransitions ?? p.viewTransitions,
41
- portal: overrides.portal ?? p.portal,
42
- context: overrides.context ?? p.context,
43
- suspense: overrides.suspense ?? p.suspense,
44
- memo: overrides.memo ?? p.memo,
45
- forwardRef: overrides.forwardRef ?? p.forwardRef,
46
- lazy: overrides.lazy ?? p.lazy,
47
- classComponents: overrides.classComponents ?? p.classComponents,
48
- hydration: overrides.hydration ?? p.hydration
49
- };
50
- }
51
- const ALIASES = {
52
- // ---- most-specific first ----
53
- "use-sync-external-store/shim/with-selector": "@tanstack/redact",
54
- "use-sync-external-store/shim/with-selector.js": "@tanstack/redact",
55
- "use-sync-external-store/with-selector": "@tanstack/redact",
56
- "use-sync-external-store/with-selector.js": "@tanstack/redact",
57
- // Explicit file subpaths (react-aria imports `shim/index.js`). Without these,
58
- // dev resolves the raw CJS shim and its named ESM import fails.
59
- "use-sync-external-store/shim/index.js": "@tanstack/redact",
60
- "use-sync-external-store/index.js": "@tanstack/redact",
61
- "use-sync-external-store/shim": "@tanstack/redact",
62
- "use-sync-external-store": "@tanstack/redact",
63
- // React drop-in shim targets. Subpaths first.
64
- "react/jsx-runtime": "@tanstack/redact/jsx-runtime",
65
- "react/jsx-dev-runtime": "@tanstack/redact/jsx-dev-runtime",
66
- "react/compiler-runtime": "@tanstack/redact/compiler-runtime",
67
- "react-dom/client": "@tanstack/redact/dom-client",
68
- "react-dom/server.browser": "@tanstack/redact/server",
69
- "react-dom/server.bun": "@tanstack/redact/server",
70
- "react-dom/server.edge": "@tanstack/redact/server",
71
- "react-dom/server.node": "@tanstack/redact/server",
72
- "react-dom/static.edge": "@tanstack/redact/server",
73
- "react-dom/server": "@tanstack/redact/server",
74
- "react-dom/test-utils": "@tanstack/redact/dom-test-utils",
75
- "react-dom": "@tanstack/redact/dom",
76
- react: "@tanstack/redact",
77
- scheduler: "@tanstack/redact/scheduler",
78
- // Self-aliases so Vite resolves `@tanstack/redact/*` imports to the same
79
- // canonical file path no matter where they originate (worker bundle vs
80
- // deps_ssr pre-bundle vs source). Without these, Cloudflare's
81
- // `noExternal: true` worker config inlines one copy while Vite's
82
- // optimizeDeps pre-bundles another, ending up with two separate
83
- // ReactSharedInternals instances and a null dispatcher in user hooks.
84
- // Subpaths first here too.
85
- "@tanstack/redact/jsx-runtime": "@tanstack/redact/jsx-runtime",
86
- "@tanstack/redact/jsx-dev-runtime": "@tanstack/redact/jsx-dev-runtime",
87
- "@tanstack/redact/compiler-runtime": "@tanstack/redact/compiler-runtime",
88
- "@tanstack/redact/dom-client": "@tanstack/redact/dom-client",
89
- "@tanstack/redact/dom-test-utils": "@tanstack/redact/dom-test-utils",
90
- "@tanstack/redact/server": "@tanstack/redact/server",
91
- "@tanstack/redact/scheduler": "@tanstack/redact/scheduler",
92
- "@tanstack/redact/dom": "@tanstack/redact/dom",
93
- "@tanstack/redact": "@tanstack/redact"
94
- };
95
- function splitSpecifier(specifier) {
96
- if (specifier.startsWith("@")) {
97
- const slash1 = specifier.indexOf("/");
98
- const slash2 = specifier.indexOf("/", slash1 + 1);
99
- if (slash2 < 0)
100
- return { pkg: specifier, sub: "" };
101
- return { pkg: specifier.slice(0, slash2), sub: specifier.slice(slash2 + 1) };
102
- }
103
- const slash = specifier.indexOf("/");
104
- if (slash < 0)
105
- return { pkg: specifier, sub: "" };
106
- return { pkg: specifier.slice(0, slash), sub: specifier.slice(slash + 1) };
107
- }
108
- function findPackageDir(pkg, fromDir) {
109
- let dir = fromDir;
110
- while (true) {
111
- const candidate = resolvePath(dir, "node_modules", pkg);
112
- if (existsSync(resolvePath(candidate, "package.json")))
113
- return candidate;
114
- const parent = dirname(dir);
115
- if (parent === dir)
116
- return null;
117
- dir = parent;
118
- }
119
- }
120
- function resolveExport(packageDir, sub) {
121
- const pkgJsonPath = resolvePath(packageDir, "package.json");
122
- let pkg;
123
- try {
124
- pkg = JSON.parse(readFileSync(pkgJsonPath, "utf8"));
125
- } catch {
126
- return null;
127
- }
128
- const key = sub ? "./" + sub : ".";
129
- const exp = pkg.exports?.[key];
130
- const pick = (v) => {
131
- if (typeof v === "string")
132
- return v;
133
- if (v && typeof v === "object") {
134
- return pick(v.import ?? v.module ?? v.source ?? v.default ?? null);
135
- }
136
- return null;
137
- };
138
- const target = pick(exp);
139
- if (target)
140
- return resolvePath(packageDir, target);
141
- if (!sub) {
142
- const main = pkg.module ?? pkg.main;
143
- if (typeof main === "string")
144
- return resolvePath(packageDir, main);
145
- }
146
- return null;
147
- }
5
+ import { ALIASES, resolveFeatures, isOwnedRuntimeFeature } from "../bundler-core/selection.js";
6
+ import { findPackageDir, resolveSpecifier, resolvePackageDir } from "../bundler-core/resolution.js";
148
7
  const pluginDir = dirname(fileURLToPath(import.meta.url));
149
- function resolveSpecifier(specifier, fromDir, packageRoots) {
150
- const { pkg, sub } = splitSpecifier(specifier);
151
- const packageDir = packageRoots[pkg] ?? findPackageDir(pkg, pluginDir) ?? findPackageDir(pkg, fromDir);
152
- if (!packageDir)
153
- return null;
154
- const target = resolveExport(packageDir, sub);
155
- if (!target)
156
- return null;
157
- try {
158
- return realpathSync(target);
159
- } catch {
160
- return target;
161
- }
162
- }
163
8
  function pruneOptimizeDepsInclude(optimizeDeps, blocked) {
164
9
  if (!optimizeDeps?.include)
165
10
  return;
@@ -175,19 +20,37 @@ function redact(options = {}) {
175
20
  const optimizeDepsBlocked = new Set(excludeList);
176
21
  const features = resolveFeatures(options.preset ?? "full", options.features ?? {});
177
22
  const resolvedMap = {};
23
+ const client = !options.environments || options.environments.includes("client");
24
+ const ssr = !options.environments || options.environments.includes("ssr");
25
+ const active = (environment, legacySsr) => environment?.name !== "rsc" && (environment?.name === "ssr" || environment?.config?.consumer === "server" || legacySsr ? ssr : client);
178
26
  let done = false;
179
27
  let react18Version;
180
28
  let runtimeRoot;
29
+ const featurePackageDir = options.packageRoots?.["@tanstack/redact"] ?? resolvePath(pluginDir, "../..");
30
+ let featurePackageRoot = resolvePath(featurePackageDir);
31
+ try {
32
+ featurePackageRoot = realpathSync(featurePackageRoot);
33
+ } catch {
34
+ }
35
+ featurePackageRoot = featurePackageRoot.replaceAll("\\", "/").replace(/\/$/, "");
36
+ const isRuntimeFeature = (id) => isOwnedRuntimeFeature(id, featurePackageRoot);
181
37
  function resolveAll(root) {
182
38
  if (done)
183
39
  return;
184
40
  const fromDir = options.resolveFrom ?? root;
185
41
  const packageRoots = options.packageRoots ?? {};
186
42
  for (const [from, to] of entries) {
187
- const resolved = resolveSpecifier(to, fromDir, packageRoots);
43
+ const resolved = resolveSpecifier(to, fromDir, packageRoots, options.resolveFrom !== void 0);
188
44
  if (resolved)
189
45
  resolvedMap[from] = resolved;
190
46
  }
47
+ const selectedDir = resolvePackageDir("@tanstack/redact", fromDir, packageRoots, options.resolveFrom !== void 0);
48
+ if (selectedDir) {
49
+ try {
50
+ featurePackageRoot = realpathSync(selectedDir).replaceAll("\\", "/").replace(/\/$/, "");
51
+ } catch {
52
+ }
53
+ }
191
54
  done = true;
192
55
  }
193
56
  return [{
@@ -199,16 +62,16 @@ function redact(options = {}) {
199
62
  const dedupe = noExt;
200
63
  return {
201
64
  environments: {
202
- client: {
65
+ ...client ? { client: {
203
66
  optimizeDeps: { exclude: excludeList },
204
67
  resolve: { alias: aliasMap, dedupe }
205
- },
206
- ssr: {
68
+ } } : {},
69
+ ...ssr ? { ssr: {
207
70
  optimizeDeps: { exclude: excludeList },
208
71
  resolve: { alias: aliasMap, dedupe, noExternal: noExt }
209
- }
72
+ } } : {}
210
73
  },
211
- ssr: { noExternal: noExt }
74
+ ...ssr ? { ssr: { noExternal: noExt } } : {}
212
75
  };
213
76
  },
214
77
  configResolved(config) {
@@ -232,16 +95,17 @@ function redact(options = {}) {
232
95
  }
233
96
  },
234
97
  async resolveId(id, importer, opts) {
235
- const envName = this?.environment?.name;
236
- if (envName === "rsc")
98
+ if (!active(this?.environment, opts?.ssr))
237
99
  return null;
238
- if (importer && /[\\/]features[\\/]index\.[jt]sx?$/.test(importer)) {
239
- const m = id.match(/^\.\/([a-z-]+)(\/index\.js)?$/);
100
+ const path = id.split(/[?#]/, 1)[0];
101
+ const suffix = id.slice(path.length);
102
+ if (importer && isRuntimeFeature(importer) && /[\\/]features[\\/]index\.[jt]sx?$/.test(importer.split(/[?#]/, 1)[0])) {
103
+ const m = path.match(/^\.\/([a-z-]+)(\/index\.js)?$/);
240
104
  if (m) {
241
105
  const dir = m[1];
242
106
  const name = dir === "forward-ref" ? "forwardRef" : dir === "fragment-refs" ? "fragmentRefs" : dir === "view-transition" ? "viewTransitions" : dir === "class" ? "classComponents" : dir;
243
107
  if (name in features && !features[name]) {
244
- const r = await this.resolve(`./${dir}/stub${m[2] ? ".js" : ""}`, importer, {
108
+ const r = await this.resolve(`./${dir}/stub${m[2] ? ".js" : ""}${suffix}`, importer, {
245
109
  ...opts,
246
110
  skipSelf: true
247
111
  });
@@ -250,22 +114,32 @@ function redact(options = {}) {
250
114
  }
251
115
  }
252
116
  }
253
- const peer = id.match(/[\\/](context|hydration|fragment-refs|view-transition|class|suspense-runtime)(?:[\\/]index\.js)?$/);
254
- const peerKey = peer?.[1] === "suspense-runtime" ? "suspense" : peer?.[1] === "fragment-refs" ? "fragmentRefs" : peer?.[1] === "view-transition" ? "viewTransitions" : peer?.[1] === "class" ? "classComponents" : peer?.[1];
117
+ const peer = path.match(/[\\/](context|hydration|fragment-refs|view-transition|class|suspense-runtime|suspense-hydration)(?:[\\/]index\.js)?$/);
118
+ const peerKey = peer?.[1] === "suspense-hydration" ? "hydration" : peer?.[1] === "suspense-runtime" ? "suspense" : peer?.[1] === "fragment-refs" ? "fragmentRefs" : peer?.[1] === "view-transition" ? "viewTransitions" : peer?.[1] === "class" ? "classComponents" : peer?.[1];
255
119
  if (importer && peer && peerKey && !features[peerKey]) {
256
120
  const r = await this.resolve(id, importer, { ...opts, skipSelf: true });
257
- const resolvedFeature = r?.id.match(/features[\\/](context|hydration|fragment-refs|view-transition|class|suspense-runtime)[\\/]index\.(ts|js)$/);
258
- if (resolvedFeature?.[1] === peer[1]) {
259
- return r.id.replace(/index\.(ts|js)$/, "stub.$1");
121
+ const resolvedFeature = r?.id.match(/features[\\/](context|hydration|fragment-refs|view-transition|class|suspense-runtime|suspense-hydration)[\\/]index\.(ts|js)(?=[?#]|$)/);
122
+ if (r && isRuntimeFeature(r.id) && resolvedFeature?.[1] === peer[1]) {
123
+ return r.id.replace(/index\.(ts|js)(?=[?#]|$)/, "stub.$1");
260
124
  }
261
125
  }
262
126
  return resolvedMap[id] ?? null;
263
127
  }
128
+ }, {
129
+ name: "redact:canonical-imports",
130
+ resolveId: {
131
+ order: "pre",
132
+ handler(id, _importer, opts) {
133
+ if (!active(this.environment, opts?.ssr))
134
+ return null;
135
+ return resolvedMap[id] ?? null;
136
+ }
137
+ }
264
138
  }, {
265
139
  name: "redact:react18",
266
140
  enforce: "post",
267
- transform(code, id) {
268
- if (!react18Version || !runtimeRoot || this?.environment?.name === "rsc")
141
+ transform(code, id, opts) {
142
+ if (!react18Version || !runtimeRoot || !active(this?.environment, opts?.ssr))
269
143
  return null;
270
144
  const path = id.split("?")[0].replaceAll("\\", "/");
271
145
  if (!path.startsWith(runtimeRoot))
@@ -277,9 +151,12 @@ function redact(options = {}) {
277
151
  name: "redact:optimize-deps-guard",
278
152
  enforce: "post",
279
153
  configResolved(config) {
280
- pruneOptimizeDepsInclude(config.optimizeDeps, optimizeDepsBlocked);
281
- pruneOptimizeDepsInclude(config.environments?.client?.optimizeDeps, optimizeDepsBlocked);
282
- pruneOptimizeDepsInclude(config.environments?.ssr?.optimizeDeps, optimizeDepsBlocked);
154
+ if (client) {
155
+ pruneOptimizeDepsInclude(config.optimizeDeps, optimizeDepsBlocked);
156
+ pruneOptimizeDepsInclude(config.environments?.client?.optimizeDeps, optimizeDepsBlocked);
157
+ }
158
+ if (ssr)
159
+ pruneOptimizeDepsInclude(config.environments?.ssr?.optimizeDeps, optimizeDepsBlocked);
283
160
  }
284
161
  }];
285
162
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/vite/index.ts"],
4
- "sourcesContent": ["import { existsSync, readFileSync, realpathSync } from 'node:fs'\nimport { dirname, resolve as resolvePath } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { adaptReact18 } from './react18'\n\nexport type RedactPreset = 'nano' | 'full'\n\n/**\n * Opt-in feature set. Each flag toggles whether the feature's real\n * implementation ships (`true`) or is swapped with a stub module that\n * degrades gracefully (`false`). Missing keys fall back to the preset's\n * default. Adding a feature to this interface propagates to consumer\n * configs as autocompleted options.\n */\nexport interface RedactFeatures {\n /** Activity visibility, retained state and disconnected effects. */\n activity?: boolean\n /** DOM instances, events, focus, layout and observers for Fragment refs. */\n fragmentRefs?: boolean\n /** Experimental native ViewTransition animations. Opt-in until snapshot parity is complete. */\n viewTransitions?: boolean\n /**\n * `createPortal`. When `false`, portal elements render in place as a\n * Fragment (the `container` prop is ignored). `renderPortal` and its\n * deps are stripped from the bundle.\n */\n portal?: boolean\n /**\n * `createContext` / `useContext` / `<Provider>` / `<Consumer>`. When\n * `false`, Providers render as Fragments (value never propagates),\n * Consumers invoke their function-children with the context's default\n * value, and `useContext` returns the default. Provider-walk logic and\n * `renderProvider` are stripped.\n */\n context?: boolean\n /**\n * `<Suspense>` boundaries + streaming hydration. When `false`, Suspense\n * elements render as Fragments (children mount inline, `fallback` is\n * ignored). Thrown thenables still schedule a re-render on settle, so\n * eventual consistency works — just no fallback UI during the pending\n * window. Boundary-handler stack and hydration integration are stripped.\n */\n suspense?: boolean\n /**\n * `React.memo`. When `false`, memoized components still render but without\n * the prop-equality gate — every parent rerender passes through.\n * `shallowEqual` and the force-rerender bypass are stripped.\n */\n memo?: boolean\n /**\n * `React.forwardRef`. When `false`, forwardRef components still render but\n * the ref prop isn't forwarded to the inner function. React 19+ treats\n * refs as normal props on function components anyway, so most apps can\n * drop this. The dispatcher save/restore machinery is stripped.\n */\n forwardRef?: boolean\n /**\n * `React.lazy`. When `false`, lazy elements still resolve if their payload\n * is already available synchronously (e.g. pre-awaited RSC Flight); async\n * resolution throws a clear error. The hydration-deferred-reveal path and\n * Suspense coordination are stripped.\n */\n lazy?: boolean\n /**\n * Class components (`extends Component`). When `false`, class components\n * still render but only honor the core contract: constructor + `render()`\n * + `setState`. Dropped: `contextType`, `getDerivedStateFromProps`,\n * `shouldComponentUpdate`, `componentDidMount`/`Update`/`WillUnmount`,\n * `getDerivedStateFromError`/`componentDidCatch` (error boundaries).\n */\n classComponents?: boolean\n /**\n * SSR hydration (`hydrateRoot`). When `false`, `hydrateRoot` throws\n * (use `createRoot` for SPAs). The HydrationCursor / DOM adoption /\n * streaming-boundary coordination / event-replay / scroll-guard\n * machinery is stripped — the biggest single chunk of reducible code.\n */\n hydration?: boolean\n}\n\ninterface ResolvedFeatures {\n activity: boolean\n fragmentRefs: boolean\n viewTransitions: boolean\n portal: boolean\n context: boolean\n suspense: boolean\n memo: boolean\n forwardRef: boolean\n lazy: boolean\n classComponents: boolean\n hydration: boolean\n}\n\nconst PRESET_DEFAULTS: Record<RedactPreset, ResolvedFeatures> = {\n // Opt-in: everything off. Turn individual features on via `features`.\n nano: {\n activity: false, fragmentRefs: false, viewTransitions: false,\n portal: false, context: false, suspense: false, memo: false,\n forwardRef: false, lazy: false, classComponents: false, hydration: false,\n },\n // Opt-out: everything on (drop-in React parity). Turn features off via `features`.\n full: {\n activity: true, fragmentRefs: true, viewTransitions: false,\n portal: true, context: true, suspense: true, memo: true,\n forwardRef: true, lazy: true, classComponents: true, hydration: true,\n },\n}\n\nfunction resolveFeatures(\n preset: RedactPreset,\n overrides: RedactFeatures,\n): ResolvedFeatures {\n const p = PRESET_DEFAULTS[preset]\n return {\n activity: overrides.activity ?? p.activity,\n fragmentRefs: overrides.fragmentRefs ?? p.fragmentRefs,\n viewTransitions: overrides.viewTransitions ?? p.viewTransitions,\n portal: overrides.portal ?? p.portal,\n context: overrides.context ?? p.context,\n suspense: overrides.suspense ?? p.suspense,\n memo: overrides.memo ?? p.memo,\n forwardRef: overrides.forwardRef ?? p.forwardRef,\n lazy: overrides.lazy ?? p.lazy,\n classComponents: overrides.classComponents ?? p.classComponents,\n hydration: overrides.hydration ?? p.hydration,\n }\n}\n\nexport interface RedactOptions {\n /** Skip aliasing specific specifiers, e.g. if a consumer wants real React somewhere. */\n skip?: ReadonlyArray<string>\n /**\n * Override package resolution root. Defaults to the Vite config root. Useful\n * for monorepos where the plugin lives in a different workspace than the\n * consumer app.\n */\n resolveFrom?: string\n /**\n * Explicit package roots, bypassing node_modules lookup. Keys are package\n * names (e.g. `@tanstack/redact`), values are absolute paths to the package\n * directory. Handy for cross-workspace testing / bring-your-own-build setups.\n */\n packageRoots?: Record<string, string>\n /**\n * Starting point for feature selection. `'full'` (default) turns every\n * feature on — drop-in React parity, opt-out individual features via\n * `features`. `'nano'` turns everything off — opt in to what you need.\n */\n preset?: RedactPreset\n /**\n * Per-feature overrides merged on top of the preset's defaults. Enables\n * fine-grained \"preset minus X\" or \"preset plus Y\" configurations.\n */\n features?: RedactFeatures\n}\n\n// Alias map. ORDER MATTERS — Vite's alias matcher uses first-match against\n// prefix, so more-specific specifiers MUST come before less-specific ones.\n// Without this, `react-dom/server` would prefix-match `react-dom` first and\n// resolve to `@tanstack/redact/dom/server` (wrong) instead of\n// `@tanstack/redact/server`.\n//\n// `use-sync-external-store` aliases are here because its CJS-only React 17\n// compat shim does `var React = require('react')`. That survives Vite's\n// pre-bundling intact and explodes in Cloudflare Workers (no `require`).\n// Modern React has `useSyncExternalStore` built-in, and `@tanstack/redact`\n// additionally exports `useSyncExternalStoreWithSelector` so this alias\n// is safe everywhere.\nconst ALIASES: Record<string, string> = {\n // ---- most-specific first ----\n 'use-sync-external-store/shim/with-selector': '@tanstack/redact',\n 'use-sync-external-store/shim/with-selector.js': '@tanstack/redact',\n 'use-sync-external-store/with-selector': '@tanstack/redact',\n 'use-sync-external-store/with-selector.js': '@tanstack/redact',\n // Explicit file subpaths (react-aria imports `shim/index.js`). Without these,\n // dev resolves the raw CJS shim and its named ESM import fails.\n 'use-sync-external-store/shim/index.js': '@tanstack/redact',\n 'use-sync-external-store/index.js': '@tanstack/redact',\n 'use-sync-external-store/shim': '@tanstack/redact',\n 'use-sync-external-store': '@tanstack/redact',\n\n // React drop-in shim targets. Subpaths first.\n 'react/jsx-runtime': '@tanstack/redact/jsx-runtime',\n 'react/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',\n 'react/compiler-runtime': '@tanstack/redact/compiler-runtime',\n 'react-dom/client': '@tanstack/redact/dom-client',\n 'react-dom/server.browser': '@tanstack/redact/server',\n 'react-dom/server.bun': '@tanstack/redact/server',\n 'react-dom/server.edge': '@tanstack/redact/server',\n 'react-dom/server.node': '@tanstack/redact/server',\n 'react-dom/static.edge': '@tanstack/redact/server',\n 'react-dom/server': '@tanstack/redact/server',\n 'react-dom/test-utils': '@tanstack/redact/dom-test-utils',\n 'react-dom': '@tanstack/redact/dom',\n react: '@tanstack/redact',\n scheduler: '@tanstack/redact/scheduler',\n\n // Self-aliases so Vite resolves `@tanstack/redact/*` imports to the same\n // canonical file path no matter where they originate (worker bundle vs\n // deps_ssr pre-bundle vs source). Without these, Cloudflare's\n // `noExternal: true` worker config inlines one copy while Vite's\n // optimizeDeps pre-bundles another, ending up with two separate\n // ReactSharedInternals instances and a null dispatcher in user hooks.\n // Subpaths first here too.\n '@tanstack/redact/jsx-runtime': '@tanstack/redact/jsx-runtime',\n '@tanstack/redact/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',\n '@tanstack/redact/compiler-runtime': '@tanstack/redact/compiler-runtime',\n '@tanstack/redact/dom-client': '@tanstack/redact/dom-client',\n '@tanstack/redact/dom-test-utils': '@tanstack/redact/dom-test-utils',\n '@tanstack/redact/server': '@tanstack/redact/server',\n '@tanstack/redact/scheduler': '@tanstack/redact/scheduler',\n '@tanstack/redact/dom': '@tanstack/redact/dom',\n '@tanstack/redact': '@tanstack/redact',\n}\n\nfunction splitSpecifier(specifier: string): { pkg: string; sub: string } {\n if (specifier.startsWith('@')) {\n const slash1 = specifier.indexOf('/')\n const slash2 = specifier.indexOf('/', slash1 + 1)\n if (slash2 < 0) return { pkg: specifier, sub: '' }\n return { pkg: specifier.slice(0, slash2), sub: specifier.slice(slash2 + 1) }\n }\n const slash = specifier.indexOf('/')\n if (slash < 0) return { pkg: specifier, sub: '' }\n return { pkg: specifier.slice(0, slash), sub: specifier.slice(slash + 1) }\n}\n\nfunction findPackageDir(pkg: string, fromDir: string): string | null {\n let dir = fromDir\n while (true) {\n const candidate = resolvePath(dir, 'node_modules', pkg)\n if (existsSync(resolvePath(candidate, 'package.json'))) return candidate\n const parent = dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n}\n\nfunction resolveExport(packageDir: string, sub: string): string | null {\n const pkgJsonPath = resolvePath(packageDir, 'package.json')\n let pkg: any\n try {\n pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'))\n } catch {\n return null\n }\n const key = sub ? './' + sub : '.'\n const exp = pkg.exports?.[key]\n // Prefer published JavaScript over TypeScript sources. Dist preserves one\n // file per module, so subpath imports share state and feature boundaries.\n const pick = (v: any): string | null => {\n if (typeof v === 'string') return v\n if (v && typeof v === 'object') {\n return pick(v.import ?? v.module ?? v.source ?? v.default ?? null)\n }\n return null\n }\n const target = pick(exp)\n if (target) return resolvePath(packageDir, target)\n if (!sub) {\n const main = pkg.module ?? pkg.main\n if (typeof main === 'string') return resolvePath(packageDir, main)\n }\n return null\n}\n\n// When installed from npm, `@tanstack/redact` is declared as a `dependency`\n// of consumer apps. Under pnpm's strict mode it ends up nested under the\n// plugin's own `.pnpm/@tanstack+redact@.../node_modules/` rather than\n// hoisted to the consumer's root, so a `findPackageDir` walk starting at\n// the Vite project root won't always find it. Search from the plugin's own\n// directory first (which walks into its nested node_modules), then fall\n// back to the consumer root for hoisted installs.\nconst pluginDir = dirname(fileURLToPath(import.meta.url))\n\nfunction resolveSpecifier(\n specifier: string,\n fromDir: string,\n packageRoots: Record<string, string>,\n): string | null {\n const { pkg, sub } = splitSpecifier(specifier)\n const packageDir =\n packageRoots[pkg] ??\n findPackageDir(pkg, pluginDir) ??\n findPackageDir(pkg, fromDir)\n if (!packageDir) return null\n const target = resolveExport(packageDir, sub)\n if (!target) return null\n // Canonicalize through pnpm symlinks. Under strict pnpm, the package may\n // live nested under `.pnpm/@tanstack+redact@.../node_modules/*`, but each\n // of those is itself a symlink to the flat `.pnpm/@tanstack+redact@.../`\n // entry. Vite's `fetchModule` (used by TanStack Start's server-fn\n // compiler) follows the realpath, so the id seen by the capture-transform\n // differs from the nested id we'd return. That leaves the compiler's\n // moduleCache keyed on the realpath while `getModuleInfo` looks up the\n // nested path → miss → \"could not load module info\". Returning the\n // canonical realpath here keeps the two sides in agreement.\n try {\n return realpathSync(target)\n } catch {\n return target\n }\n}\n\ninterface OptimizeDepsWithInclude {\n include?: Array<string>\n}\n\nfunction pruneOptimizeDepsInclude(\n optimizeDeps: OptimizeDepsWithInclude | undefined,\n blocked: ReadonlySet<string>,\n): void {\n if (!optimizeDeps?.include) return\n\n optimizeDeps.include = optimizeDeps.include.filter((id) => {\n const tailSpecifier = id.split('>').pop()?.trim() ?? id\n return !blocked.has(id) && !blocked.has(tailSpecifier)\n })\n}\n\nexport function redact(options: RedactOptions = {}): any {\n const skip = new Set(options.skip ?? [])\n const entries = Object.entries(ALIASES).filter(([k]) => !skip.has(k))\n const excludeList = entries.map(([k]) => k)\n const optimizeDepsBlocked = new Set(excludeList)\n const features = resolveFeatures(options.preset ?? 'full', options.features ?? {})\n\n const resolvedMap: Record<string, string> = {}\n let done = false\n let react18Version: string | undefined\n let runtimeRoot: string | undefined\n\n function resolveAll(root: string): void {\n if (done) return\n const fromDir = options.resolveFrom ?? root\n const packageRoots = options.packageRoots ?? {}\n for (const [from, to] of entries) {\n const resolved = resolveSpecifier(to, fromDir, packageRoots)\n if (resolved) resolvedMap[from] = resolved\n }\n done = true\n }\n\n return [{\n name: 'redact',\n enforce: 'pre',\n\n config() {\n // Single package — only one name to dedupe / no-external.\n const noExt = ['@tanstack/redact']\n const aliasMap = Object.fromEntries(entries.filter(([from, to]) => from !== to))\n // Dedupe `@tanstack/redact` so Vite resolves it to a single instance\n // even when multiple packages (e.g. @tanstack/react-router and user\n // code) drag it into different parts of the module graph.\n const dedupe = noExt\n // Scope `resolve.alias` to client + ssr environments ONLY. Do NOT set\n // a top-level alias: it would apply to the `rsc` environment too,\n // where `@vitejs/plugin-rsc`'s vendored `react-server-dom-server`\n // imports `react` and needs the *real* React (with the `.d` field on\n // ReactSharedInternals that our shim deliberately doesn't have).\n // Aliasing `react` → `@tanstack/redact` in the RSC env crashes Flight\n // serialization. The Cloudflare vite-plugin's rolldown worker-runner\n // also pre-scans bare specifiers via Vite's alias map (not plugin\n // hooks), but it scans within the *ssr* environment specifically —\n // so per-env `environments.ssr.resolve.alias` covers it. The\n // `enforce: 'pre'` resolveId hook below already skips RSC, so the\n // remaining concern is alias placement. Object form is required —\n // array form is silently ignored by rolldown's worker-runner.\n return {\n environments: {\n client: {\n optimizeDeps: { exclude: excludeList },\n resolve: { alias: aliasMap, dedupe },\n },\n ssr: {\n optimizeDeps: { exclude: excludeList },\n resolve: { alias: aliasMap, dedupe, noExternal: noExt },\n },\n },\n ssr: { noExternal: noExt },\n }\n },\n\n configResolved(config: any) {\n resolveAll(config.root)\n const reactDir = findPackageDir('react', options.resolveFrom ?? config.root)\n if (reactDir) {\n const installedVersion = JSON.parse(readFileSync(resolvePath(reactDir, 'package.json'), 'utf8')).version\n if (/^18\\./.test(installedVersion)) react18Version = installedVersion\n }\n if (resolvedMap.react) {\n runtimeRoot = resolvePath(dirname(resolvedMap.react), '..').replaceAll('\\\\', '/') + '/'\n }\n // With `packageRoots`, package sources live outside the consumer's Vite\n // project root, so the default server.fs.allow list blocks them. Append\n // to the resolved allow list rather than replacing via `config()`, so we\n // keep Vite's defaults (root + node_modules + client runtime).\n const fsAllow = Object.values(options.packageRoots ?? {})\n if (fsAllow.length && config.server?.fs?.allow) {\n for (const p of fsAllow) {\n if (!config.server.fs.allow.includes(p)) {\n config.server.fs.allow.push(p)\n }\n }\n }\n },\n\n async resolveId(this: any, id: string, importer?: string, opts?: any) {\n // Skip the RSC environment — it relies on real React internals via\n // @vitejs/plugin-rsc's vendored react-server-dom. Substituting our\n // shim there breaks Flight serialization. Client + SSR envs still swap.\n const envName = this?.environment?.name\n if (envName === 'rsc') return null\n\n // Feature-flag swap: when the reconciler's `features/index` module\n // imports a feature by relative path, redirect to that feature's stub\n // if the flag is off. The stub registers a graceful-degradation\n // matcher (e.g. Portal → Fragment) so user code keeps working.\n if (importer && /[\\\\/]features[\\\\/]index\\.[jt]sx?$/.test(importer)) {\n const m = id.match(/^\\.\\/([a-z-]+)(\\/index\\.js)?$/)\n if (m) {\n const dir = m[1]!\n const name = (dir === 'forward-ref' ? 'forwardRef' : dir === 'fragment-refs' ? 'fragmentRefs' : dir === 'view-transition' ? 'viewTransitions' : dir === 'class' ? 'classComponents' : dir) as keyof ResolvedFeatures\n if (name in features && !features[name]) {\n const r = await this.resolve(`./${dir}/stub${m[2] ? '.js' : ''}`, importer, {\n ...opts,\n skipSelf: true,\n })\n if (r) return r.id\n }\n }\n }\n\n // Peer imports must use the same feature selection as the registration\n // entrypoint, or an enabled feature can bring a disabled one back in.\n const peer = id.match(/[\\\\/](context|hydration|fragment-refs|view-transition|class|suspense-runtime)(?:[\\\\/]index\\.js)?$/)\n const peerKey = peer?.[1] === 'suspense-runtime' ? 'suspense' : peer?.[1] === 'fragment-refs' ? 'fragmentRefs' : peer?.[1] === 'view-transition' ? 'viewTransitions' : peer?.[1] === 'class' ? 'classComponents' : peer?.[1] as 'context' | 'hydration' | undefined\n if (importer && peer && peerKey && !features[peerKey]) {\n const r = await this.resolve(id, importer, { ...opts, skipSelf: true })\n const resolvedFeature = r?.id.match(/features[\\\\/](context|hydration|fragment-refs|view-transition|class|suspense-runtime)[\\\\/]index\\.(ts|js)$/)\n if (resolvedFeature?.[1] === peer[1]) {\n return r.id.replace(/index\\.(ts|js)$/, 'stub.$1')\n }\n }\n\n return resolvedMap[id] ?? null\n },\n }, {\n name: 'redact:react18',\n enforce: 'post',\n transform(this: any, code: string, id: string) {\n if (!react18Version || !runtimeRoot || this?.environment?.name === 'rsc') return null\n const path = id.split('?')[0]!.replaceAll('\\\\', '/')\n if (!path.startsWith(runtimeRoot)) return null\n const module = path.slice(runtimeRoot.length).replace(/\\.[jt]s$/, '')\n return adaptReact18(code, id, module, react18Version, (source) => this.parse(source))\n },\n }, {\n name: 'redact:optimize-deps-guard',\n enforce: 'post',\n\n configResolved(config: any) {\n // `optimizeDeps.exclude` loses when another plugin force-adds the same\n // ids to `include`. That lets Vite pre-bundle real React next to Redact,\n // producing duplicate dispatcher state. Prune after config settles so\n // Redact's client/SSR shims stay canonical.\n pruneOptimizeDepsInclude(config.optimizeDeps, optimizeDepsBlocked)\n pruneOptimizeDepsInclude(config.environments?.client?.optimizeDeps, optimizeDepsBlocked)\n pruneOptimizeDepsInclude(config.environments?.ssr?.optimizeDeps, optimizeDepsBlocked)\n // Leave `environments.rsc` untouched. RSC depends on real React internals.\n },\n }]\n}\n\nexport default redact\n"],
5
- "mappings": "AAAA,SAAS,YAAY,cAAc,oBAAoB;AACvD,SAAS,SAAS,WAAW,mBAAmB;AAChD,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AA2F7B,MAAM,kBAA0D;;EAE9D,MAAM;IACJ,UAAU;IAAO,cAAc;IAAO,iBAAiB;IACvD,QAAQ;IAAO,SAAS;IAAO,UAAU;IAAO,MAAM;IACtD,YAAY;IAAO,MAAM;IAAO,iBAAiB;IAAO,WAAW;;;EAGrE,MAAM;IACJ,UAAU;IAAM,cAAc;IAAM,iBAAiB;IACrD,QAAQ;IAAM,SAAS;IAAM,UAAU;IAAM,MAAM;IACnD,YAAY;IAAM,MAAM;IAAM,iBAAiB;IAAM,WAAW;;;AAIpE,SAAS,gBACP,QACA,WAAyB;AAEzB,QAAM,IAAI,gBAAgB,MAAM;AAChC,SAAO;IACL,UAAU,UAAU,YAAY,EAAE;IAClC,cAAc,UAAU,gBAAgB,EAAE;IAC1C,iBAAiB,UAAU,mBAAmB,EAAE;IAChD,QAAQ,UAAU,UAAU,EAAE;IAC9B,SAAS,UAAU,WAAW,EAAE;IAChC,UAAU,UAAU,YAAY,EAAE;IAClC,MAAM,UAAU,QAAQ,EAAE;IAC1B,YAAY,UAAU,cAAc,EAAE;IACtC,MAAM,UAAU,QAAQ,EAAE;IAC1B,iBAAiB,UAAU,mBAAmB,EAAE;IAChD,WAAW,UAAU,aAAa,EAAE;;AAExC;AA0CA,MAAM,UAAkC;;EAEtC,8CAA8C;EAC9C,iDAAiD;EACjD,yCAAyC;EACzC,4CAA4C;;;EAG5C,yCAAyC;EACzC,oCAAoC;EACpC,gCAAgC;EAChC,2BAA2B;;EAG3B,qBAAqB;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AQ,WAAW,CAAC,SAAS,OAAO,GAAG;AACrD,cAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,UAAU,EAAE,GAAG,MAAM,UAAU,KAAI,CAAE;AACtE,cAAM,kBAAkB,GAAG,GAAG,MAAM,2GAA2G;AAC/I,YAAI,kBAAkB,CAAC,MAAM,KAAK,CAAC,GAAG;AACpC,iBAAO,EAAE,GAAG,QAAQ,mBAAmB,SAAS;QAClD;MACF;AAEA,aAAO,YAAY,EAAE,KAAK;IAC5B;KACC;IACD,MAAM;IACN,SAAS;IACT,UAAqB,MAAc,IAAU;AAC3C,UAAI,CAAC,kBAAkB,CAAC,eAAe,MAAM,aAAa,SAAS;AAAO,eAAO;AACjF,YAAM,OAAO,GAAG,MAAM,GAAG,EAAE,CAAC,EAAG,WAAW,MAAM,GAAG;AACnD,UAAI,CAAC,KAAK,WAAW,WAAW;AAAG,eAAO;AAC1C,YAAM,SAAS,KAAK,MAAM,YAAY,MAAM,EAAE,QAAQ,YAAY,EAAE;AACpE,aAAO,aAAa,MAAM,IAAI,QAAQ,gBAAgB,CAAC,WAAW,KAAK,MAAM,MAAM,CAAC;IACtF;KACC;IACD,MAAM;IACN,SAAS;IAET,eAAe,QAAW;AAKxB,+BAAyB,OAAO,cAAc,mBAAmB;AACjE,+BAAyB,OAAO,cAAc,QAAQ,cAAc,mBAAmB;AACvF,+BAAyB,OAAO,cAAc,KAAK,cAAc,mBAAmB;IAEtF;GACD;AACH;AAEA,IAAA,eAAe;",
4
+ "sourcesContent": ["import { readFileSync, realpathSync } from 'node:fs'\nimport { dirname, resolve as resolvePath } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { adaptReact18 } from './react18'\n\nimport { ALIASES, resolveFeatures, isOwnedRuntimeFeature } from '../bundler-core/selection'\nimport type { ResolvedFeatures } from '../bundler-core/selection'\nexport type { RedactPreset, RedactFeatures } from '../bundler-core/selection'\n\nimport { findPackageDir, resolveSpecifier, resolvePackageDir } from '../bundler-core/resolution'\nimport type { RedactOptions as CommonRedactOptions } from '../bundler-core/resolution'\n\nexport interface RedactOptions extends CommonRedactOptions {\n /** Select browser and/or SSR replacement. RSC always keeps native React. */\n environments?: ReadonlyArray<'client' | 'ssr'>\n}\nconst pluginDir = dirname(fileURLToPath(import.meta.url))\n\ninterface OptimizeDepsWithInclude {\n include?: Array<string>\n}\n\nfunction pruneOptimizeDepsInclude(\n optimizeDeps: OptimizeDepsWithInclude | undefined,\n blocked: ReadonlySet<string>,\n): void {\n if (!optimizeDeps?.include) return\n\n optimizeDeps.include = optimizeDeps.include.filter((id) => {\n const tailSpecifier = id.split('>').pop()?.trim() ?? id\n return !blocked.has(id) && !blocked.has(tailSpecifier)\n })\n}\n\nexport function redact(options: RedactOptions = {}): any {\n const skip = new Set(options.skip ?? [])\n const entries = Object.entries(ALIASES).filter(([k]) => !skip.has(k))\n const excludeList = entries.map(([k]) => k)\n const optimizeDepsBlocked = new Set(excludeList)\n const features = resolveFeatures(options.preset ?? 'full', options.features ?? {})\n\n const resolvedMap: Record<string, string> = {}\n const client = !options.environments || options.environments.includes('client')\n const ssr = !options.environments || options.environments.includes('ssr')\n const active = (environment: any, legacySsr?: boolean): boolean => environment?.name !== 'rsc' &&\n (environment?.name === 'ssr' || environment?.config?.consumer === 'server' || legacySsr ? ssr : client)\n let done = false\n let react18Version: string | undefined\n let runtimeRoot: string | undefined\n const featurePackageDir = options.packageRoots?.['@tanstack/redact'] ?? resolvePath(pluginDir, '../..')\n let featurePackageRoot = resolvePath(featurePackageDir)\n try { featurePackageRoot = realpathSync(featurePackageRoot) } catch { /* Package may not be built yet. */ }\n featurePackageRoot = featurePackageRoot.replaceAll('\\\\', '/').replace(/\\/$/, '')\n const isRuntimeFeature = (id: string) => isOwnedRuntimeFeature(id, featurePackageRoot)\n\n function resolveAll(root: string): void {\n if (done) return\n const fromDir = options.resolveFrom ?? root\n const packageRoots = options.packageRoots ?? {}\n for (const [from, to] of entries) {\n const resolved = resolveSpecifier(to, fromDir, packageRoots, options.resolveFrom !== undefined)\n if (resolved) resolvedMap[from] = resolved\n }\n const selectedDir = resolvePackageDir('@tanstack/redact', fromDir, packageRoots, options.resolveFrom !== undefined)\n if (selectedDir) {\n try { featurePackageRoot = realpathSync(selectedDir).replaceAll('\\\\', '/').replace(/\\/$/, '') } catch { /* Keep the unbuilt-package fallback. */ }\n }\n done = true\n }\n\n return [{\n name: 'redact',\n enforce: 'pre',\n\n config() {\n // Single package — only one name to dedupe / no-external.\n const noExt = ['@tanstack/redact']\n const aliasMap = Object.fromEntries(entries.filter(([from, to]) => from !== to))\n // Dedupe `@tanstack/redact` so Vite resolves it to a single instance\n // even when multiple packages (e.g. @tanstack/react-router and user\n // code) drag it into different parts of the module graph.\n const dedupe = noExt\n // Scope `resolve.alias` to client + ssr environments ONLY. Do NOT set\n // a top-level alias: it would apply to the `rsc` environment too,\n // where `@vitejs/plugin-rsc`'s vendored `react-server-dom-server`\n // imports `react` and needs the *real* React (with the `.d` field on\n // ReactSharedInternals that our shim deliberately doesn't have).\n // Aliasing `react` → `@tanstack/redact` in the RSC env crashes Flight\n // serialization. The Cloudflare vite-plugin's rolldown worker-runner\n // also pre-scans bare specifiers via Vite's alias map (not plugin\n // hooks), but it scans within the *ssr* environment specifically —\n // so per-env `environments.ssr.resolve.alias` covers it. The\n // `enforce: 'pre'` resolveId hook below already skips RSC, so the\n // remaining concern is alias placement. Object form is required —\n // array form is silently ignored by rolldown's worker-runner.\n return {\n environments: {\n ...(client ? { client: {\n optimizeDeps: { exclude: excludeList },\n resolve: { alias: aliasMap, dedupe },\n } } : {}),\n ...(ssr ? { ssr: {\n optimizeDeps: { exclude: excludeList },\n resolve: { alias: aliasMap, dedupe, noExternal: noExt },\n } } : {}),\n },\n ...(ssr ? { ssr: { noExternal: noExt } } : {}),\n }\n },\n\n configResolved(config: any) {\n resolveAll(config.root)\n const reactDir = findPackageDir('react', options.resolveFrom ?? config.root)\n if (reactDir) {\n const installedVersion = JSON.parse(readFileSync(resolvePath(reactDir, 'package.json'), 'utf8')).version\n if (/^18\\./.test(installedVersion)) react18Version = installedVersion\n }\n if (resolvedMap.react) {\n runtimeRoot = resolvePath(dirname(resolvedMap.react), '..').replaceAll('\\\\', '/') + '/'\n }\n // With `packageRoots`, package sources live outside the consumer's Vite\n // project root, so the default server.fs.allow list blocks them. Append\n // to the resolved allow list rather than replacing via `config()`, so we\n // keep Vite's defaults (root + node_modules + client runtime).\n const fsAllow = Object.values(options.packageRoots ?? {})\n if (fsAllow.length && config.server?.fs?.allow) {\n for (const p of fsAllow) {\n if (!config.server.fs.allow.includes(p)) {\n config.server.fs.allow.push(p)\n }\n }\n }\n },\n\n async resolveId(this: any, id: string, importer?: string, opts?: any) {\n // Skip the RSC environment — it relies on real React internals via\n // @vitejs/plugin-rsc's vendored react-server-dom. Substituting our\n // shim there breaks Flight serialization. Client + SSR envs still swap.\n if (!active(this?.environment, opts?.ssr)) return null\n\n // Feature-flag swap: when the reconciler's `features/index` module\n // imports a feature by relative path, redirect to that feature's stub\n // if the flag is off. The stub registers a graceful-degradation\n // matcher (e.g. Portal → Fragment) so user code keeps working.\n const path = id.split(/[?#]/, 1)[0]!\n const suffix = id.slice(path.length)\n if (importer && isRuntimeFeature(importer) && /[\\\\/]features[\\\\/]index\\.[jt]sx?$/.test(importer.split(/[?#]/, 1)[0]!)) {\n const m = path.match(/^\\.\\/([a-z-]+)(\\/index\\.js)?$/)\n if (m) {\n const dir = m[1]!\n const name = (dir === 'forward-ref' ? 'forwardRef' : dir === 'fragment-refs' ? 'fragmentRefs' : dir === 'view-transition' ? 'viewTransitions' : dir === 'class' ? 'classComponents' : dir) as keyof ResolvedFeatures\n if (name in features && !features[name]) {\n const r = await this.resolve(`./${dir}/stub${m[2] ? '.js' : ''}${suffix}`, importer, {\n ...opts,\n skipSelf: true,\n })\n if (r) return r.id\n }\n }\n }\n\n // Peer imports must use the same feature selection as the registration\n // entrypoint, or an enabled feature can bring a disabled one back in.\n const peer = path.match(/[\\\\/](context|hydration|fragment-refs|view-transition|class|suspense-runtime|suspense-hydration)(?:[\\\\/]index\\.js)?$/)\n const peerKey = peer?.[1] === 'suspense-hydration' ? 'hydration' : peer?.[1] === 'suspense-runtime' ? 'suspense' : peer?.[1] === 'fragment-refs' ? 'fragmentRefs' : peer?.[1] === 'view-transition' ? 'viewTransitions' : peer?.[1] === 'class' ? 'classComponents' : peer?.[1] as 'context' | 'hydration' | undefined\n if (importer && peer && peerKey && !features[peerKey]) {\n const r = await this.resolve(id, importer, { ...opts, skipSelf: true })\n const resolvedFeature = r?.id.match(/features[\\\\/](context|hydration|fragment-refs|view-transition|class|suspense-runtime|suspense-hydration)[\\\\/]index\\.(ts|js)(?=[?#]|$)/)\n if (r && isRuntimeFeature(r.id) && resolvedFeature?.[1] === peer[1]) {\n return r.id.replace(/index\\.(ts|js)(?=[?#]|$)/, 'stub.$1')\n }\n }\n\n return resolvedMap[id] ?? null\n },\n }, {\n name: 'redact:canonical-imports',\n resolveId: {\n order: 'pre',\n handler(this: any, id: string, _importer?: string, opts?: any) {\n if (!active(this.environment, opts?.ssr)) return null\n return resolvedMap[id] ?? null\n },\n },\n }, {\n name: 'redact:react18',\n enforce: 'post',\n transform(this: any, code: string, id: string, opts?: any) {\n if (!react18Version || !runtimeRoot || !active(this?.environment, opts?.ssr)) return null\n const path = id.split('?')[0]!.replaceAll('\\\\', '/')\n if (!path.startsWith(runtimeRoot)) return null\n const module = path.slice(runtimeRoot.length).replace(/\\.[jt]s$/, '')\n return adaptReact18(code, id, module, react18Version, (source) => this.parse(source))\n },\n }, {\n name: 'redact:optimize-deps-guard',\n enforce: 'post',\n\n configResolved(config: any) {\n // `optimizeDeps.exclude` loses when another plugin force-adds the same\n // ids to `include`. That lets Vite pre-bundle real React next to Redact,\n // producing duplicate dispatcher state. Prune after config settles so\n // Redact's client/SSR shims stay canonical.\n if (client) {\n pruneOptimizeDepsInclude(config.optimizeDeps, optimizeDepsBlocked)\n pruneOptimizeDepsInclude(config.environments?.client?.optimizeDeps, optimizeDepsBlocked)\n }\n if (ssr) pruneOptimizeDepsInclude(config.environments?.ssr?.optimizeDeps, optimizeDepsBlocked)\n // Leave `environments.rsc` untouched. RSC depends on real React internals.\n },\n }]\n}\n\nexport default redact\n"],
5
+ "mappings": "AAAA,SAAS,cAAc,oBAAoB;AAC3C,SAAS,SAAS,WAAW,mBAAmB;AAChD,SAAS,qBAAqB;AAC9B,SAAS,oBAAoB;AAE7B,SAAS,SAAS,iBAAiB,6BAA6B;AAIhE,SAAS,gBAAgB,kBAAkB,yBAAyB;AAOpE,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AAMxD,SAAS,yBACP,cACA,SAA4B;AAE5B,MAAI,CAAC,cAAc;AAAS;AAE5B,eAAa,UAAU,aAAa,QAAQ,OAAO,CAAC,OAAM;AACxD,UAAM,gBAAgB,GAAG,MAAM,GAAG,EAAE,IAAG,GAAI,KAAI,KAAM;AACrD,WAAO,CAAC,QAAQ,IAAI,EAAE,KAAK,CAAC,QAAQ,IAAI,aAAa;EACvD,CAAC;AACH;AAEM,SAAU,OAAO,UAAyB,CAAA,GAAE;AAChD,QAAM,OAAO,IAAI,IAAI,QAAQ,QAAQ,CAAA,CAAE;AACvC,QAAM,UAAU,OAAO,QAAQ,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;AACpE,QAAM,cAAc,QAAQ,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1C,QAAM,sBAAsB,IAAI,IAAI,WAAW;AAC/C,QAAM,WAAW,gBAAgB,QAAQ,UAAU,QAAQ,QAAQ,YAAY,CAAA,CAAE;AAEjF,QAAM,cAAsC,CAAA;AAC5C,QAAM,SAAS,CAAC,QAAQ,gBAAgB,QAAQ,aAAa,SAAS,QAAQ;AAC9E,QAAM,MAAM,CAAC,QAAQ,gBAAgB,QAAQ,aAAa,SAAS,KAAK;AACxE,QAAM,SAAS,CAAC,aAAkB,cAAiC,aAAa,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YAAM,OAAO,GAAG,MAAM,GAAG,EAAE,CAAC,EAAG,WAAW,MAAM,GAAG;AACnD,UAAI,CAAC,KAAK,WAAW,WAAW;AAAG,eAAO;AAC1C,YAAM,SAAS,KAAK,MAAM,YAAY,MAAM,EAAE,QAAQ,YAAY,EAAE;AACpE,aAAO,aAAa,MAAM,IAAI,QAAQ,gBAAgB,CAAC,WAAW,KAAK,MAAM,MAAM,CAAC;IACtF;KACC;IACD,MAAM;IACN,SAAS;IAET,eAAe,QAAW;AAKxB,UAAI,QAAQ;AACV,iCAAyB,OAAO,cAAc,mBAAmB;AACjE,iCAAyB,OAAO,cAAc,QAAQ,cAAc,mBAAmB;MACzF;AACA,UAAI;AAAK,iCAAyB,OAAO,cAAc,KAAK,cAAc,mBAAmB;IAE/F;GACD;AACH;AAEA,IAAA,eAAe;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,46 @@
1
+ import type { ResolvedFeatures } from "../bundler-core/selection.js";
2
+ import type { RedactOptions } from "../bundler-core/resolution.js";
3
+ export type { RedactOptions } from "../bundler-core/resolution.js";
4
+ export type { RedactPreset, RedactFeatures } from "../bundler-core/selection.js";
5
+ interface ResourceData {
6
+ resource?: string;
7
+ request?: string;
8
+ userRequest?: string;
9
+ }
10
+ interface ModuleFactory {
11
+ hooks: {
12
+ afterResolve: {
13
+ tap(name: string, callback: (data: {
14
+ createData?: ResourceData;
15
+ }) => void): void;
16
+ };
17
+ };
18
+ }
19
+ type AliasValue = string | false | Array<string | false>;
20
+ interface Compiler {
21
+ context: string;
22
+ options: {
23
+ target?: string | false | ReadonlyArray<string>;
24
+ resolve: {
25
+ alias?: false | Record<string, AliasValue> | Array<{
26
+ name: string;
27
+ alias: AliasValue;
28
+ onlyModule?: boolean;
29
+ }>;
30
+ };
31
+ module: {
32
+ rules: Array<unknown>;
33
+ };
34
+ };
35
+ hooks: {
36
+ normalModuleFactory: {
37
+ tap(name: string, callback: (factory: ModuleFactory) => void): void;
38
+ };
39
+ };
40
+ }
41
+ export declare function selectedFeatureResource(resource: string, root: string, features: ResolvedFeatures): string | null;
42
+ /** Webpack 5 and Rspack 2 integration for browser SPAs. */
43
+ export declare function redact(options?: RedactOptions): {
44
+ apply(compiler: Compiler): void;
45
+ };
46
+ export default redact;
@@ -0,0 +1,102 @@
1
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { ALIASES, resolveFeatures, isOwnedRuntimeFeature } from "../bundler-core/selection.js";
5
+ import { findPackageDir, resolveSpecifier, resolvePackageDir } from "../bundler-core/resolution.js";
6
+ const pluginDir = dirname(fileURLToPath(import.meta.url));
7
+ const directories = {
8
+ activity: "activity",
9
+ "fragment-refs": "fragmentRefs",
10
+ "view-transition": "viewTransitions",
11
+ portal: "portal",
12
+ context: "context",
13
+ suspense: "suspense",
14
+ memo: "memo",
15
+ "forward-ref": "forwardRef",
16
+ lazy: "lazy",
17
+ class: "classComponents",
18
+ hydration: "hydration",
19
+ "suspense-runtime": "suspense",
20
+ "suspense-hydration": "hydration"
21
+ };
22
+ function selectedFeatureResource(resource, root, features) {
23
+ const path = resource.split(/[?#]/, 1)[0];
24
+ if (!existsSync(path))
25
+ return null;
26
+ const canonical = realpathSync(path);
27
+ if (!isOwnedRuntimeFeature(canonical, root))
28
+ return null;
29
+ const directory = canonical.replaceAll("\\", "/").match(/\/dom\/features\/([^/]+)\/index\.js$/)?.[1];
30
+ const feature = directory && directories[directory];
31
+ if (!feature || features[feature])
32
+ return null;
33
+ const stub = resolve(dirname(canonical), "stub.js");
34
+ if (!existsSync(stub))
35
+ throw new Error(`Redact feature stub is missing: ${stub}`);
36
+ return stub + resource.slice(path.length);
37
+ }
38
+ function redact(options = {}) {
39
+ const features = resolveFeatures(options.preset ?? "full", options.features ?? {});
40
+ return {
41
+ apply(compiler) {
42
+ const target = compiler.options.target;
43
+ if (target !== void 0 && target !== "web" && !(Array.isArray(target) && target.includes("web") && target.every((value) => value === "web" || /^es\d+$/.test(value)))) {
44
+ throw new Error('The Redact Webpack/Rspack plugin supports browser SPA targets only. Use target: "web".');
45
+ }
46
+ const from = options.resolveFrom ?? compiler.context;
47
+ const roots = options.packageRoots ?? {};
48
+ const packageDir = resolvePackageDir("@tanstack/redact", from, roots, options.resolveFrom !== void 0);
49
+ if (!packageDir)
50
+ throw new Error("Cannot find the built @tanstack/redact package. Install it before configuring the plugin.");
51
+ const root = realpathSync(packageDir);
52
+ const aliases = [];
53
+ for (const [name, specifier] of Object.entries(ALIASES)) {
54
+ if (options.skip?.includes(name))
55
+ continue;
56
+ const alias = resolveSpecifier(specifier, from, roots, options.resolveFrom !== void 0);
57
+ if (!alias)
58
+ throw new Error(`Cannot resolve Redact alias: ${specifier}`);
59
+ aliases.push({ name, alias, onlyModule: true });
60
+ }
61
+ aliases.push({ name: "@tanstack/redact/features", alias: resolve(root, "dist/dom/features"), onlyModule: false });
62
+ const aliasKey = ({ name, onlyModule }) => name + (onlyModule ? "$" : "");
63
+ const previous = compiler.options.resolve.alias || {};
64
+ compiler.options.resolve.alias = Array.isArray(previous) ? [...aliases, ...previous] : Object.fromEntries([
65
+ ...aliases.map((entry) => [aliasKey(entry), entry.alias]),
66
+ ...Object.entries(previous).filter(([name]) => !aliases.some((alias) => aliasKey(alias) === name))
67
+ ]);
68
+ const reactDir = findPackageDir("react", from);
69
+ const version = reactDir && JSON.parse(readFileSync(resolve(reactDir, "package.json"), "utf8")).version;
70
+ if (typeof version === "string" && /^18\./.test(version)) {
71
+ compiler.options.module.rules.push({
72
+ test: /\.js$/,
73
+ include: (file) => existsSync(file) && realpathSync(file).replaceAll("\\", "/").startsWith(root.replaceAll("\\", "/") + "/dist/"),
74
+ use: [{ loader: resolve(pluginDir, "react18-loader.cjs"), options: { packageRoot: root, version } }]
75
+ });
76
+ }
77
+ compiler.hooks.normalModuleFactory.tap("redact", (factory) => {
78
+ factory.hooks.afterResolve.tap("redact", (data) => {
79
+ const created = data.createData;
80
+ if (!created?.resource)
81
+ return;
82
+ const old = created.resource;
83
+ const next = selectedFeatureResource(old, root, features);
84
+ if (!next)
85
+ return;
86
+ created.resource = next;
87
+ if (created.request)
88
+ created.request = created.request.replace(old, next);
89
+ if (created.userRequest)
90
+ created.userRequest = created.userRequest.replace(old, next);
91
+ });
92
+ });
93
+ }
94
+ };
95
+ }
96
+ var webpack_default = redact;
97
+ export {
98
+ webpack_default as default,
99
+ redact,
100
+ selectedFeatureResource
101
+ };
102
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/webpack/index.ts"],
4
+ "sourcesContent": ["import { existsSync, readFileSync, realpathSync } from 'node:fs'\nimport { dirname, resolve } from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { ALIASES, resolveFeatures, isOwnedRuntimeFeature } from '../bundler-core/selection'\nimport { findPackageDir, resolveSpecifier, resolvePackageDir } from '../bundler-core/resolution'\nimport type { ResolvedFeatures } from '../bundler-core/selection'\nimport type { RedactOptions } from '../bundler-core/resolution'\nexport type { RedactOptions } from '../bundler-core/resolution'\nexport type { RedactPreset, RedactFeatures } from '../bundler-core/selection'\n\nconst pluginDir = dirname(fileURLToPath(import.meta.url))\nconst directories: Record<string, keyof ResolvedFeatures> = {\n activity: 'activity', 'fragment-refs': 'fragmentRefs', 'view-transition': 'viewTransitions',\n portal: 'portal', context: 'context', suspense: 'suspense', memo: 'memo',\n 'forward-ref': 'forwardRef', lazy: 'lazy', class: 'classComponents', hydration: 'hydration',\n 'suspense-runtime': 'suspense', 'suspense-hydration': 'hydration',\n}\n\n// Both compilers expose these hooks. No compiler package is loaded by the plugin.\ninterface ResourceData {\n resource?: string\n request?: string\n userRequest?: string\n}\ninterface ModuleFactory {\n hooks: { afterResolve: { tap(name: string, callback: (data: { createData?: ResourceData }) => void): void } }\n}\ntype AliasValue = string | false | Array<string | false>\n\ninterface Compiler {\n context: string\n options: {\n target?: string | false | ReadonlyArray<string>\n resolve: { alias?: false | Record<string, AliasValue> | Array<{ name: string; alias: AliasValue; onlyModule?: boolean }> }\n module: { rules: Array<unknown> }\n }\n hooks: { normalModuleFactory: { tap(name: string, callback: (factory: ModuleFactory) => void): void } }\n}\n\nexport function selectedFeatureResource(resource: string, root: string, features: ResolvedFeatures): string | null {\n const path = resource.split(/[?#]/, 1)[0]!\n if (!existsSync(path)) return null\n const canonical = realpathSync(path)\n if (!isOwnedRuntimeFeature(canonical, root)) return null\n const directory = canonical.replaceAll('\\\\', '/').match(/\\/dom\\/features\\/([^/]+)\\/index\\.js$/)?.[1]\n const feature = directory && directories[directory]\n if (!feature || features[feature]) return null\n const stub = resolve(dirname(canonical), 'stub.js')\n if (!existsSync(stub)) throw new Error(`Redact feature stub is missing: ${stub}`)\n return stub + resource.slice(path.length)\n}\n\n/** Webpack 5 and Rspack 2 integration for browser SPAs. */\nexport function redact(options: RedactOptions = {}) {\n const features = resolveFeatures(options.preset ?? 'full', options.features ?? {})\n return {\n apply(compiler: Compiler): void {\n const target = compiler.options.target\n if (target !== undefined && target !== 'web' && !(Array.isArray(target) && target.includes('web') && target.every(value => value === 'web' || /^es\\d+$/.test(value)))) {\n throw new Error('The Redact Webpack/Rspack plugin supports browser SPA targets only. Use target: \"web\".')\n }\n const from = options.resolveFrom ?? compiler.context\n const roots = options.packageRoots ?? {}\n const packageDir = resolvePackageDir('@tanstack/redact', from, roots, options.resolveFrom !== undefined)\n if (!packageDir) throw new Error('Cannot find the built @tanstack/redact package. Install it before configuring the plugin.')\n const root = realpathSync(packageDir)\n const aliases: Array<{ name: string; alias: string; onlyModule: boolean }> = []\n for (const [name, specifier] of Object.entries(ALIASES)) {\n if (options.skip?.includes(name)) continue\n const alias = resolveSpecifier(specifier, from, roots, options.resolveFrom !== undefined)\n if (!alias) throw new Error(`Cannot resolve Redact alias: ${specifier}`)\n aliases.push({ name, alias, onlyModule: true })\n }\n aliases.push({ name: '@tanstack/redact/features', alias: resolve(root, 'dist/dom/features'), onlyModule: false })\n const aliasKey = ({ name, onlyModule }: { name: string; onlyModule: boolean }) => name + (onlyModule ? '$' : '')\n const previous = compiler.options.resolve.alias || {}\n compiler.options.resolve.alias = Array.isArray(previous)\n ? [...aliases, ...previous]\n : Object.fromEntries([\n ...aliases.map(entry => [aliasKey(entry), entry.alias]),\n ...Object.entries(previous).filter(([name]) => !aliases.some(alias => aliasKey(alias) === name)),\n ])\n const reactDir = findPackageDir('react', from)\n const version = reactDir && JSON.parse(readFileSync(resolve(reactDir, 'package.json'), 'utf8')).version\n if (typeof version === 'string' && /^18\\./.test(version)) {\n compiler.options.module.rules.push({\n test: /\\.js$/,\n include: (file: string) => existsSync(file) && realpathSync(file).replaceAll('\\\\', '/').startsWith(root.replaceAll('\\\\', '/') + '/dist/'),\n use: [{ loader: resolve(pluginDir, 'react18-loader.cjs'), options: { packageRoot: root, version } }],\n })\n }\n compiler.hooks.normalModuleFactory.tap('redact', factory => {\n factory.hooks.afterResolve.tap('redact', data => {\n const created = data.createData\n if (!created?.resource) return\n const old = created.resource\n const next = selectedFeatureResource(old, root, features)\n if (!next) return\n created.resource = next\n if (created.request) created.request = created.request.replace(old, next)\n if (created.userRequest) created.userRequest = created.userRequest.replace(old, next)\n })\n })\n },\n }\n}\n\nexport default redact\n"],
5
+ "mappings": "AAAA,SAAS,YAAY,cAAc,oBAAoB;AACvD,SAAS,SAAS,eAAe;AACjC,SAAS,qBAAqB;AAC9B,SAAS,SAAS,iBAAiB,6BAA6B;AAChE,SAAS,gBAAgB,kBAAkB,yBAAyB;AAMpE,MAAM,YAAY,QAAQ,cAAc,YAAY,GAAG,CAAC;AACxD,MAAM,cAAsD;EAC1D,UAAU;EAAY,iBAAiB;EAAgB,mBAAmB;EAC1E,QAAQ;EAAU,SAAS;EAAW,UAAU;EAAY,MAAM;EAClE,eAAe;EAAc,MAAM;EAAQ,OAAO;EAAmB,WAAW;EAChF,oBAAoB;EAAY,sBAAsB;;AAwBlD,SAAU,wBAAwB,UAAkB,MAAc,UA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AAU;AACzD,gBAAQ,MAAM,aAAa,IAAI,UAAU,UAAO;AAC9C,gBAAM,UAAU,KAAK;AACrB,cAAI,CAAC,SAAS;AAAU;AACxB,gBAAM,MAAM,QAAQ;AACpB,gBAAM,OAAO,wBAAwB,KAAK,MAAM,QAAQ;AACxD,cAAI,CAAC;AAAM;AACX,kBAAQ,WAAW;AACnB,cAAI,QAAQ;AAAS,oBAAQ,UAAU,QAAQ,QAAQ,QAAQ,KAAK,IAAI;AACxE,cAAI,QAAQ;AAAa,oBAAQ,cAAc,QAAQ,YAAY,QAAQ,KAAK,IAAI;QACtF,CAAC;MACH,CAAC;IACH;;AAEJ;AAEA,IAAA,kBAAe;",
6
+ "names": []
7
+ }
@@ -0,0 +1,25 @@
1
+ const { realpathSync } = require('node:fs')
2
+ const { relative, resolve } = require('node:path')
3
+ const { pathToFileURL } = require('node:url')
4
+ const { parse } = require('acorn')
5
+ const remapping = require('@jridgewell/remapping')
6
+
7
+ module.exports = function(source, inputMap) {
8
+ const done = this.async()
9
+ const { packageRoot, version } = this.getOptions()
10
+ const root = realpathSync(resolve(packageRoot, 'dist'))
11
+ const resource = realpathSync(this.resourcePath)
12
+ const moduleName = relative(root, resource).replaceAll('\\', '/').replace(/\.js$/, '')
13
+ if (!/^18\./.test(version) || moduleName.startsWith('../') || moduleName === '..') {
14
+ done(null, source, inputMap)
15
+ return
16
+ }
17
+ import(pathToFileURL(resolve(root, 'vite/react18.js')).href).then(({ adaptReact18 }) => {
18
+ const result = adaptReact18(source, this.resourcePath, moduleName, version,
19
+ code => parse(code, { ecmaVersion: 'latest', sourceType: 'module' }))
20
+ const map = result && inputMap
21
+ ? remapping([result.map, inputMap], () => null)
22
+ : result ? result.map : inputMap
23
+ done(null, result ? result.code : source, map)
24
+ }).catch(done)
25
+ }