@vitejs/plugin-rsc 0.5.21 → 0.5.22

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 (47) hide show
  1. package/dist/browser-CUMAmYC3.d.ts +6 -0
  2. package/dist/browser.d.ts +2 -2
  3. package/dist/browser.js +1 -3
  4. package/dist/{chunk-f2BShn47.js → chunk-BYIdrdsR.js} +8 -14
  5. package/dist/cjs-BdahOUyh.js +115 -0
  6. package/dist/core/browser.d.ts +1 -5
  7. package/dist/core/browser.js +3 -5
  8. package/dist/core/plugin.js +1 -2
  9. package/dist/core/rsc.d.ts +1 -1
  10. package/dist/core/rsc.js +4 -6
  11. package/dist/core/ssr.d.ts +1 -1
  12. package/dist/core/ssr.js +3 -5
  13. package/dist/{dist-yW9-EeG1.js → dist-rz-Bnebz.js} +1 -2
  14. package/dist/{encryption-utils-Bk5eKdu6.js → encryption-utils-BblioYEx.js} +1 -2
  15. package/dist/{server-action-B2zS9t-J.d.ts → index-2GoUFmVR.d.ts} +34 -1
  16. package/dist/index-D2a5dlVU.d.ts +70 -0
  17. package/dist/index.d.ts +1 -3
  18. package/dist/index.js +2 -6
  19. package/dist/{picocolors-B0A1T24z.js → picocolors-B6RAUUd2.js} +2 -5
  20. package/dist/plugin-DGxRH4Nv.d.ts +185 -0
  21. package/dist/plugin-DMfc_Eqq.js +1944 -0
  22. package/dist/plugin.d.ts +2 -179
  23. package/dist/plugin.js +2 -1468
  24. package/dist/plugins/cjs.js +2 -64
  25. package/dist/react/browser.d.ts +6 -6
  26. package/dist/react/browser.js +1 -3
  27. package/dist/react/rsc.d.ts +7 -6
  28. package/dist/react/rsc.js +2 -6
  29. package/dist/react/ssr.d.ts +2 -1
  30. package/dist/react/ssr.js +1 -3
  31. package/dist/rsc.d.ts +1 -3
  32. package/dist/rsc.js +2 -4
  33. package/dist/scope-DKCDtt0O.js +211 -0
  34. package/dist/{shared-Dhw3vs8e.js → shared-BViDMJTQ.js} +2 -3
  35. package/dist/{shared-d80_k_tn.js → shared-DeahDSXi.js} +1 -2
  36. package/dist/ssr.d.ts +1 -3
  37. package/dist/ssr.js +2 -4
  38. package/dist/transforms/index.d.ts +2 -2
  39. package/dist/transforms/index.js +367 -3
  40. package/dist/utils/encryption-runtime.js +3 -5
  41. package/dist/utils/rpc.js +1 -3
  42. package/package.json +9 -10
  43. package/dist/cjs-v2jRTNln.js +0 -59
  44. package/dist/import-environment-B994HXEc.d.ts +0 -11
  45. package/dist/index-BIbdRBfk.d.ts +0 -26
  46. package/dist/server-action-JkEy-6yW.js +0 -344
  47. package/dist/validate-import-DJumtHRw.js +0 -498
@@ -1,3 +1,367 @@
1
- import { a as hasDirective, c as transformHoistInlineDirective, i as getExportNames, n as transformDirectiveProxyExport, o as transformWrapExport, r as transformProxyExport, s as findDirectives, t as transformServerActionServer } from "../server-action-JkEy-6yW.js";
2
-
3
- export { findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport };
1
+ import { i as tinyassert } from "../dist-rz-Bnebz.js";
2
+ import { a as hasDirective, i as getExportNames, n as extractIdentifiers, o as validateNonAsyncFunction, r as extractNames, t as buildScopeTree } from "../scope-DKCDtt0O.js";
3
+ import MagicString from "magic-string";
4
+ import { walk } from "estree-walker";
5
+ //#region src/transforms/hoist.ts
6
+ function transformHoistInlineDirective(input, ast, { runtime, rejectNonAsyncFunction, ...options }) {
7
+ if (!input.endsWith("\n")) input += "\n";
8
+ const output = new MagicString(input);
9
+ const directive = typeof options.directive === "string" ? exactRegex(options.directive) : options.directive;
10
+ const scopeTree = buildScopeTree(ast);
11
+ const names = [];
12
+ walk(ast, { enter(node, parent) {
13
+ if ((node.type === "FunctionExpression" || node.type === "FunctionDeclaration" || node.type === "ArrowFunctionExpression") && node.body.type === "BlockStatement") {
14
+ const match = matchDirective(node.body.body, directive)?.match;
15
+ if (!match) return;
16
+ if (!node.async && rejectNonAsyncFunction) throw Object.assign(/* @__PURE__ */ new Error(`"${directive}" doesn't allow non async function`), { pos: node.start });
17
+ const declName = node.type === "FunctionDeclaration" && node.id.name;
18
+ const originalName = declName || parent?.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.id.name || "anonymous_server_function";
19
+ const bindVars = getBindVars(node, scopeTree);
20
+ let newParams = [...bindVars.map((b) => b.root), ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
21
+ if (bindVars.length > 0 && options.decode) {
22
+ newParams = ["$$hoist_encoded", ...node.params.map((n) => input.slice(n.start, n.end))].join(", ");
23
+ output.appendLeft(node.body.body[0].start, `const [${bindVars.map((b) => b.root).join(",")}] = ${options.decode("$$hoist_encoded")};\n`);
24
+ }
25
+ const newName = `$$hoist_${names.length}` + (originalName ? `_${originalName}` : "");
26
+ names.push(newName);
27
+ output.update(node.start, node.body.start, `\n;${options.noExport ? "" : "export "}${node.async ? "async " : ""}function ${newName}(${newParams}) `);
28
+ output.appendLeft(node.end, `;\n/* #__PURE__ */ Object.defineProperty(${newName}, "name", { value: ${JSON.stringify(originalName)} });\n`);
29
+ output.move(node.start, node.end, input.length);
30
+ let newCode = `/* #__PURE__ */ ${runtime(newName, newName, { directiveMatch: match })}`;
31
+ if (bindVars.length > 0) {
32
+ const bindArgs = options.encode ? options.encode("[" + bindVars.map((b) => b.expr).join(", ") + "]") : bindVars.map((b) => b.expr).join(", ");
33
+ newCode = `${newCode}.bind(null, ${bindArgs})`;
34
+ }
35
+ if (declName) {
36
+ newCode = `const ${declName} = ${newCode};`;
37
+ if (parent?.type === "ExportDefaultDeclaration") {
38
+ output.remove(parent.start, node.start);
39
+ newCode = `${newCode}\nexport default ${declName};`;
40
+ }
41
+ }
42
+ output.appendLeft(node.start, newCode);
43
+ }
44
+ } });
45
+ return {
46
+ output,
47
+ names
48
+ };
49
+ }
50
+ const exactRegex = (s) => new RegExp("^" + s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&") + "$");
51
+ function matchDirective(body, directive) {
52
+ for (const stmt of body) if (stmt.type === "ExpressionStatement" && stmt.expression.type === "Literal" && typeof stmt.expression.value === "string") {
53
+ const match = stmt.expression.value.match(directive);
54
+ if (match) return {
55
+ match,
56
+ node: stmt.expression
57
+ };
58
+ }
59
+ }
60
+ function findDirectives(ast, directive) {
61
+ const directiveRE = exactRegex(directive);
62
+ const nodes = [];
63
+ walk(ast, { enter(node) {
64
+ if (node.type === "Program" || node.type === "BlockStatement") {
65
+ const match = matchDirective(node.body, directiveRE);
66
+ if (match) nodes.push(match.node);
67
+ }
68
+ } });
69
+ return nodes;
70
+ }
71
+ function getBindVars(fn, scopeTree) {
72
+ const fnScope = scopeTree.nodeScope.get(fn);
73
+ const ancestorScopes = fnScope.getAncestorScopes();
74
+ const bindReferences = (scopeTree.scopeToReferences.get(fnScope) ?? []).filter((id) => {
75
+ const scope = scopeTree.referenceToDeclaredScope.get(id);
76
+ return scope && scope !== scopeTree.moduleScope && ancestorScopes.has(scope);
77
+ });
78
+ const accessMap = {};
79
+ for (const id of bindReferences) {
80
+ const name = id.name;
81
+ const node = scopeTree.referenceToNode.get(id);
82
+ if (node.type === "Identifier") {
83
+ accessMap[name] = { kind: "bare" };
84
+ continue;
85
+ }
86
+ accessMap[name] ??= {
87
+ kind: "paths",
88
+ paths: []
89
+ };
90
+ const entry = accessMap[name];
91
+ if (entry.kind === "paths") {
92
+ const path = memberExpressionToPath(node);
93
+ if (!entry.paths.some((existing) => existing.key === path.key)) entry.paths.push(path);
94
+ }
95
+ }
96
+ const result = [];
97
+ for (const [root, entry] of Object.entries(accessMap)) {
98
+ if (entry.kind === "bare") {
99
+ result.push({
100
+ root,
101
+ expr: root
102
+ });
103
+ continue;
104
+ }
105
+ result.push({
106
+ root,
107
+ expr: synthesizePartialObject(root, entry.paths)
108
+ });
109
+ }
110
+ return result;
111
+ }
112
+ function memberExpressionToPath(node) {
113
+ const segments = [];
114
+ let current = node;
115
+ while (current.type === "MemberExpression") {
116
+ tinyassert(current.property.type === "Identifier");
117
+ segments.unshift(current.property.name);
118
+ tinyassert(current.object.type === "Identifier" || current.object.type === "MemberExpression");
119
+ current = current.object;
120
+ }
121
+ return {
122
+ key: segments.join("."),
123
+ segments
124
+ };
125
+ }
126
+ function synthesizePartialObject(root, bindPaths) {
127
+ const trie = /* @__PURE__ */ new Map();
128
+ const paths = dedupeByPrefix(bindPaths.map((p) => p.segments));
129
+ for (const path of paths) {
130
+ let node = trie;
131
+ for (let i = 0; i < path.length; i++) {
132
+ const segment = path[i];
133
+ let child = node.get(segment);
134
+ if (!child) {
135
+ child = /* @__PURE__ */ new Map();
136
+ node.set(segment, child);
137
+ }
138
+ node = child;
139
+ }
140
+ }
141
+ function serialize(node, segments) {
142
+ if (node.size === 0) return root + segments.map((segment) => `.${segment}`).join("");
143
+ const entries = [];
144
+ for (const [key, child] of node) {
145
+ const safeKey = key === "__proto__" ? `["__proto__"]` : key;
146
+ entries.push(`${safeKey}: ${serialize(child, [...segments, key])}`);
147
+ }
148
+ return `{ ${entries.join(", ")} }`;
149
+ }
150
+ return serialize(trie, []);
151
+ }
152
+ function dedupeByPrefix(paths) {
153
+ const sorted = [...paths].sort((a, b) => a.length - b.length);
154
+ const result = [];
155
+ for (const path of sorted) if (!result.some((existingPath) => existingPath.every((segment, i) => segment === path[i]))) result.push(path);
156
+ return result;
157
+ }
158
+ //#endregion
159
+ //#region src/transforms/wrap-export.ts
160
+ function transformWrapExport(input, ast, options) {
161
+ const output = new MagicString(input);
162
+ const exportNames = [];
163
+ const toAppend = [];
164
+ const filter = options.filter ?? (() => true);
165
+ function wrapSimple(start, end, exports) {
166
+ exportNames.push(...exports.map((e) => e.name));
167
+ const newCode = exports.map((e) => [filter(e.name, e.meta) && `${e.name} = /* #__PURE__ */ ${options.runtime(e.name, e.name, e.meta)};\n`, `export { ${e.name} };\n`]).flat().filter(Boolean).join("");
168
+ output.update(start, end, newCode);
169
+ output.move(start, end, input.length);
170
+ }
171
+ function wrapExport(name, exportName, meta = {}) {
172
+ exportNames.push(exportName);
173
+ if (!filter(exportName, meta)) {
174
+ toAppend.push(`export { ${name} as ${exportName} }`);
175
+ return;
176
+ }
177
+ toAppend.push(`const $$wrap_${name} = /* #__PURE__ */ ${options.runtime(name, exportName, meta)}`, `export { $$wrap_${name} as ${exportName} }`);
178
+ }
179
+ for (const node of ast.body) {
180
+ if (node.type === "ExportNamedDeclaration") if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
181
+ /**
182
+ * export function foo() {}
183
+ */
184
+ validateNonAsyncFunction(options, node.declaration);
185
+ const name = node.declaration.id.name;
186
+ wrapSimple(node.start, node.declaration.start, [{
187
+ name,
188
+ meta: {
189
+ isFunction: true,
190
+ declName: name
191
+ }
192
+ }]);
193
+ } else if (node.declaration.type === "VariableDeclaration") {
194
+ /**
195
+ * export const foo = 1, bar = 2
196
+ */
197
+ for (const decl of node.declaration.declarations) if (decl.init) validateNonAsyncFunction(options, decl.init);
198
+ if (node.declaration.kind === "const") output.update(node.declaration.start, node.declaration.start + 5, "let");
199
+ const names = node.declaration.declarations.flatMap((decl) => extractNames(decl.id));
200
+ let isFunction = false;
201
+ if (node.declaration.declarations.length === 1) {
202
+ const decl = node.declaration.declarations[0];
203
+ isFunction = decl.id.type === "Identifier" && (decl.init?.type === "ArrowFunctionExpression" || decl.init?.type === "FunctionExpression");
204
+ }
205
+ wrapSimple(node.start, node.declaration.start, names.map((name) => ({
206
+ name,
207
+ meta: {
208
+ isFunction,
209
+ declName: name
210
+ }
211
+ })));
212
+ } else node.declaration;
213
+ else if (node.source) {
214
+ /**
215
+ * export { foo, bar as car } from './foo'
216
+ */
217
+ output.remove(node.start, node.end);
218
+ for (const spec of node.specifiers) {
219
+ tinyassert(spec.local.type === "Identifier");
220
+ tinyassert(spec.exported.type === "Identifier");
221
+ const name = spec.local.name;
222
+ toAppend.push(`import { ${name} as $$import_${name} } from ${node.source.raw}`);
223
+ wrapExport(`$$import_${name}`, spec.exported.name);
224
+ }
225
+ } else {
226
+ /**
227
+ * export { foo, bar as car }
228
+ */
229
+ output.remove(node.start, node.end);
230
+ for (const spec of node.specifiers) {
231
+ tinyassert(spec.local.type === "Identifier");
232
+ tinyassert(spec.exported.type === "Identifier");
233
+ wrapExport(spec.local.name, spec.exported.name);
234
+ }
235
+ }
236
+ /**
237
+ * export * from './foo'
238
+ */
239
+ if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw Object.assign(/* @__PURE__ */ new Error("unsupported ExportAllDeclaration"), { pos: node.start });
240
+ /**
241
+ * export default function foo() {}
242
+ * export default class Foo {}
243
+ * export default () => {}
244
+ */
245
+ if (node.type === "ExportDefaultDeclaration") {
246
+ validateNonAsyncFunction(options, node.declaration);
247
+ let localName;
248
+ let isFunction = false;
249
+ let declName;
250
+ let defaultExportIdentifierName;
251
+ if ((node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") && node.declaration.id) {
252
+ localName = node.declaration.id.name;
253
+ output.remove(node.start, node.declaration.start);
254
+ isFunction = node.declaration.type === "FunctionDeclaration";
255
+ declName = node.declaration.id.name;
256
+ } else {
257
+ localName = "$$default";
258
+ output.update(node.start, node.declaration.start, "const $$default = ");
259
+ if (node.declaration.type === "Identifier") defaultExportIdentifierName = node.declaration.name;
260
+ }
261
+ wrapExport(localName, "default", {
262
+ isFunction,
263
+ declName,
264
+ defaultExportIdentifierName
265
+ });
266
+ }
267
+ }
268
+ if (toAppend.length > 0) output.append([
269
+ "",
270
+ ...toAppend,
271
+ ""
272
+ ].join(";\n"));
273
+ return {
274
+ exportNames,
275
+ output
276
+ };
277
+ }
278
+ //#endregion
279
+ //#region src/transforms/proxy-export.ts
280
+ function transformDirectiveProxyExport(ast, options) {
281
+ if (!hasDirective(ast.body, options.directive)) return;
282
+ return transformProxyExport(ast, options);
283
+ }
284
+ function transformProxyExport(ast, options) {
285
+ if (options.keep && typeof options.code !== "string") throw new Error("`keep` option requires `code`");
286
+ const output = new MagicString(options.code ?? " ".repeat(ast.end));
287
+ const exportNames = [];
288
+ function createExport(node, names) {
289
+ exportNames.push(...names);
290
+ const newCode = names.map((name) => (name === "default" ? `export default` : `export const ${name} =`) + ` /* #__PURE__ */ ${options.runtime(name)};\n`).join("");
291
+ output.update(node.start, node.end, newCode);
292
+ }
293
+ for (const node of ast.body) {
294
+ if (node.type === "ExportNamedDeclaration") {
295
+ if (node.declaration) if (node.declaration.type === "FunctionDeclaration" || node.declaration.type === "ClassDeclaration") {
296
+ /**
297
+ * export function foo() {}
298
+ */
299
+ validateNonAsyncFunction(options, node.declaration);
300
+ createExport(node, [node.declaration.id.name]);
301
+ } else if (node.declaration.type === "VariableDeclaration") {
302
+ /**
303
+ * export const foo = 1, bar = 2
304
+ */
305
+ for (const decl of node.declaration.declarations) if (decl.init) validateNonAsyncFunction(options, decl.init);
306
+ if (options.keep && options.code) {
307
+ if (node.declaration.declarations.length === 1) {
308
+ const decl = node.declaration.declarations[0];
309
+ if (decl.id.type === "Identifier" && decl.init) {
310
+ const name = decl.id.name;
311
+ const value = options.code.slice(decl.init.start, decl.init.end);
312
+ const newCode = `export const ${name} = /* #__PURE__ */ ${options.runtime(name, { value })};`;
313
+ output.update(node.start, node.end, newCode);
314
+ exportNames.push(name);
315
+ continue;
316
+ }
317
+ }
318
+ }
319
+ createExport(node, node.declaration.declarations.flatMap((decl) => extractNames(decl.id)));
320
+ } else node.declaration;
321
+ else {
322
+ /**
323
+ * export { foo, bar as car } from './foo'
324
+ * export { foo, bar as car }
325
+ */
326
+ const names = [];
327
+ for (const spec of node.specifiers) {
328
+ tinyassert(spec.exported.type === "Identifier");
329
+ names.push(spec.exported.name);
330
+ }
331
+ createExport(node, names);
332
+ }
333
+ continue;
334
+ }
335
+ /**
336
+ * export * from './foo'
337
+ */
338
+ if (!options.ignoreExportAllDeclaration && node.type === "ExportAllDeclaration") throw new Error("unsupported ExportAllDeclaration");
339
+ /**
340
+ * export default function foo() {}
341
+ * export default class Foo {}
342
+ * export default () => {}
343
+ */
344
+ if (node.type === "ExportDefaultDeclaration") {
345
+ validateNonAsyncFunction(options, node.declaration);
346
+ createExport(node, ["default"]);
347
+ continue;
348
+ }
349
+ if (options.keep) continue;
350
+ output.remove(node.start, node.end);
351
+ }
352
+ return {
353
+ exportNames,
354
+ output
355
+ };
356
+ }
357
+ //#endregion
358
+ //#region src/transforms/server-action.ts
359
+ function transformServerActionServer(input, ast, options) {
360
+ if (hasDirective(ast.body, "use server")) return transformWrapExport(input, ast, options);
361
+ return transformHoistInlineDirective(input, ast, {
362
+ ...options,
363
+ directive: "use server"
364
+ });
365
+ }
366
+ //#endregion
367
+ export { extractIdentifiers, extractNames, findDirectives, getExportNames, hasDirective, transformDirectiveProxyExport, transformHoistInlineDirective, transformProxyExport, transformServerActionServer, transformWrapExport, validateNonAsyncFunction };
@@ -1,8 +1,7 @@
1
- import { r as once } from "../dist-yW9-EeG1.js";
2
- import { a as fromBase64, i as encryptBuffer, n as concatArrayStream, r as decryptBuffer, t as arrayToStream } from "../encryption-utils-Bk5eKdu6.js";
1
+ import { r as once } from "../dist-rz-Bnebz.js";
2
+ import { a as fromBase64, i as encryptBuffer, n as concatArrayStream, r as decryptBuffer, t as arrayToStream } from "../encryption-utils-BblioYEx.js";
3
3
  import { createFromReadableStream, renderToReadableStream } from "../react/rsc.js";
4
4
  import encryptionKeySource from "virtual:vite-rsc/encryption-key";
5
-
6
5
  //#region src/utils/encryption-runtime.ts
7
6
  async function encryptActionBoundArgs(originalValue) {
8
7
  return encryptBuffer(await concatArrayStream(renderToReadableStream(originalValue)), await getEncryptionKey());
@@ -15,6 +14,5 @@ const getEncryptionKey = /* @__PURE__ */ once(async () => {
15
14
  const resolved = await encryptionKeySource();
16
15
  return await crypto.subtle.importKey("raw", fromBase64(resolved), { name: "AES-GCM" }, true, ["encrypt", "decrypt"]);
17
16
  });
18
-
19
17
  //#endregion
20
- export { decryptActionBoundArgs, encryptActionBoundArgs };
18
+ export { decryptActionBoundArgs, encryptActionBoundArgs };
package/dist/utils/rpc.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { decode, encode } from "turbo-stream";
2
-
3
2
  //#region src/utils/rpc.ts
4
3
  const decodePlugins = [(type, ...rest) => {
5
4
  switch (type) {
@@ -86,6 +85,5 @@ function createRpcClient(options) {
86
85
  return (...args) => callRpc(p, args);
87
86
  } });
88
87
  }
89
-
90
88
  //#endregion
91
- export { createRpcClient, createRpcServer };
89
+ export { createRpcClient, createRpcServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-rsc",
3
- "version": "0.5.21",
3
+ "version": "0.5.22",
4
4
  "description": "React Server Components (RSC) support for Vite.",
5
5
  "keywords": [
6
6
  "react",
@@ -39,22 +39,21 @@
39
39
  "prepack": "tsdown"
40
40
  },
41
41
  "dependencies": {
42
- "@rolldown/pluginutils": "1.0.0-rc.5",
42
+ "@rolldown/pluginutils": "1.0.0-rc.13",
43
43
  "es-module-lexer": "^2.0.0",
44
44
  "estree-walker": "^3.0.3",
45
45
  "magic-string": "^0.30.21",
46
- "periscopic": "^4.0.2",
47
- "srvx": "^0.11.7",
46
+ "srvx": "^0.11.15",
48
47
  "strip-literal": "^3.1.0",
49
- "turbo-stream": "^3.1.0",
50
- "vitefu": "^1.1.1"
48
+ "turbo-stream": "^3.2.0",
49
+ "vitefu": "^1.1.3"
51
50
  },
52
51
  "devDependencies": {
53
52
  "@hiogawa/utils": "^1.7.0",
54
- "@playwright/test": "^1.58.2",
53
+ "@playwright/test": "^1.59.1",
55
54
  "@tsconfig/strictest": "^2.0.8",
56
55
  "@types/estree": "^1.0.8",
57
- "@types/node": "^24.10.13",
56
+ "@types/node": "^24.12.2",
58
57
  "@types/react": "^19.2.14",
59
58
  "@types/react-dom": "^19.2.3",
60
59
  "@vitejs/plugin-react": "workspace:*",
@@ -64,8 +63,8 @@
64
63
  "react": "^19.2.4",
65
64
  "react-dom": "^19.2.4",
66
65
  "react-server-dom-webpack": "^19.2.4",
67
- "tinyexec": "^1.0.2",
68
- "tsdown": "^0.20.3"
66
+ "tinyexec": "^1.0.4",
67
+ "tsdown": "^0.21.7"
69
68
  },
70
69
  "peerDependencies": {
71
70
  "react": "*",
@@ -1,59 +0,0 @@
1
- import path from "node:path";
2
- import { fileURLToPath, pathToFileURL } from "node:url";
3
- import MagicString from "magic-string";
4
- import { walk } from "estree-walker";
5
- import { analyze } from "periscopic";
6
-
7
- //#region src/transforms/cjs.ts
8
- function __cjs_interop__(m) {
9
- return m.__cjs_module_runner_transform || "default" in m && Object.keys(m).every((k) => k === "default" || m[k] === m.default[k]) ? m.default : m;
10
- }
11
- const CJS_INTEROP_HELPER = __cjs_interop__.toString().replace(/\n\s*/g, "");
12
- function transformCjsToEsm(code, ast, options) {
13
- const output = new MagicString(code);
14
- const analyzed = analyze(ast);
15
- const parentNodes = [];
16
- const hoistedCodes = [];
17
- let hoistIndex = 0;
18
- walk(ast, {
19
- enter(node) {
20
- parentNodes.push(node);
21
- if (node.type === "CallExpression" && node.callee.type === "Identifier" && node.callee.name === "require" && node.arguments.length === 1) {
22
- let isTopLevel = true;
23
- for (const parent of parentNodes) {
24
- if (parent.type === "FunctionExpression" || parent.type === "FunctionDeclaration" || parent.type === "ArrowFunctionExpression") isTopLevel = false;
25
- const scope = analyzed.map.get(parent);
26
- if (scope && scope.declarations.has("require")) return;
27
- }
28
- if (isTopLevel) {
29
- output.update(node.start, node.callee.end, "(__cjs_interop__(await import");
30
- output.appendRight(node.end, "))");
31
- } else {
32
- const hoisted = `__cjs_to_esm_hoist_${hoistIndex}`;
33
- const importee = code.slice(node.arguments[0].start, node.arguments[0].end);
34
- hoistedCodes.push(`const ${hoisted} = __cjs_interop__(await import(${importee}));\n`);
35
- output.update(node.start, node.end, hoisted);
36
- hoistIndex++;
37
- }
38
- }
39
- },
40
- leave() {
41
- parentNodes.pop();
42
- }
43
- });
44
- for (const hoisted of hoistedCodes.reverse()) output.prepend(hoisted);
45
- if (output.hasChanged()) output.prepend(`${CJS_INTEROP_HELPER}\n`);
46
- output.prepend(`let exports = {}; const module = { exports };\n`);
47
- const __filename = fileURLToPath(pathToFileURL(options.id).href);
48
- const __dirname = path.dirname(__filename);
49
- output.prepend(`let __filename = ${JSON.stringify(__filename)}; let __dirname = ${JSON.stringify(__dirname)};\n`);
50
- output.append(`
51
- ;__vite_ssr_exportAll__(module.exports);
52
- export default module.exports;
53
- export const __cjs_module_runner_transform = true;
54
- `);
55
- return { output };
56
- }
57
-
58
- //#endregion
59
- export { transformCjsToEsm as t };
@@ -1,11 +0,0 @@
1
- import { Plugin, ResolvedConfig } from "vite";
2
-
3
- //#region src/plugins/import-environment.d.ts
4
- type EnvironmentImportMeta = {
5
- resolvedId: string;
6
- targetEnv: string;
7
- sourceEnv: string;
8
- specifier: string;
9
- };
10
- //#endregion
11
- export { EnvironmentImportMeta as t };
@@ -1,26 +0,0 @@
1
- //#region src/types/index.d.ts
2
- interface ImportManifestEntry {
3
- id: string;
4
- name: string;
5
- chunks: string[];
6
- async?: boolean;
7
- }
8
- interface BundlerConfig {
9
- [bundlerId: string]: ImportManifestEntry;
10
- }
11
- type ModuleMap = {
12
- [id: string]: {
13
- [exportName: string]: ImportManifestEntry;
14
- };
15
- };
16
- interface ServerConsumerManifest {
17
- moduleMap?: ModuleMap;
18
- serverModuleMap?: BundlerConfig;
19
- moduleLoading?: {
20
- prefix: string;
21
- crossOriign?: string;
22
- };
23
- }
24
- type CallServerCallback = (id: string, args: unknown[]) => unknown;
25
- //#endregion
26
- export { ServerConsumerManifest as i, CallServerCallback as n, ModuleMap as r, BundlerConfig as t };