@tanstack/start-plugin-core 1.131.7 → 1.132.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/dist/esm/{nitro-plugin/build-sitemap.d.ts → build-sitemap.d.ts} +3 -3
  2. package/dist/esm/{nitro-plugin/build-sitemap.js → build-sitemap.js} +19 -24
  3. package/dist/esm/build-sitemap.js.map +1 -0
  4. package/dist/esm/compilers.js +7 -10
  5. package/dist/esm/compilers.js.map +1 -1
  6. package/dist/esm/constants.d.ts +6 -2
  7. package/dist/esm/constants.js +7 -10
  8. package/dist/esm/constants.js.map +1 -1
  9. package/dist/esm/debug.js.map +1 -1
  10. package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
  11. package/dist/esm/dev-server-plugin/plugin.d.ts +5 -5
  12. package/dist/esm/dev-server-plugin/plugin.js +117 -79
  13. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  14. package/dist/esm/index.d.ts +1 -1
  15. package/dist/esm/index.js +0 -4
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/load-env-plugin/plugin.d.ts +2 -3
  18. package/dist/esm/load-env-plugin/plugin.js +5 -8
  19. package/dist/esm/load-env-plugin/plugin.js.map +1 -1
  20. package/dist/esm/output-directory.d.ts +3 -0
  21. package/dist/esm/output-directory.js +14 -0
  22. package/dist/esm/output-directory.js.map +1 -0
  23. package/dist/esm/plugin.d.ts +6 -290
  24. package/dist/esm/plugin.js +123 -76
  25. package/dist/esm/plugin.js.map +1 -1
  26. package/dist/esm/post-server-build.d.ts +7 -0
  27. package/dist/esm/post-server-build.js +55 -0
  28. package/dist/esm/post-server-build.js.map +1 -0
  29. package/dist/esm/prerender.d.ts +11 -0
  30. package/dist/esm/{nitro-plugin/prerender.js → prerender.js} +85 -73
  31. package/dist/esm/prerender.js.map +1 -0
  32. package/dist/esm/{nitro-plugin/queue.js → queue.js} +7 -10
  33. package/dist/esm/queue.js.map +1 -0
  34. package/dist/esm/resolve-entries.d.ts +8 -0
  35. package/dist/esm/resolve-entries.js +37 -0
  36. package/dist/esm/resolve-entries.js.map +1 -0
  37. package/dist/esm/schema.d.ts +1369 -6719
  38. package/dist/esm/schema.js +52 -85
  39. package/dist/esm/schema.js.map +1 -1
  40. package/dist/esm/start-compiler-plugin.js +2 -2
  41. package/dist/esm/start-compiler-plugin.js.map +1 -1
  42. package/dist/esm/start-manifest-plugin/plugin.d.ts +1 -1
  43. package/dist/esm/start-manifest-plugin/plugin.js +8 -13
  44. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
  45. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +2 -3
  46. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  47. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +2 -4
  48. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -1
  49. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  50. package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -1
  51. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -1
  52. package/dist/esm/utils.js.map +1 -1
  53. package/package.json +13 -18
  54. package/src/{nitro-plugin/build-sitemap.ts → build-sitemap.ts} +8 -8
  55. package/src/constants.ts +12 -9
  56. package/src/dev-server-plugin/plugin.ts +140 -99
  57. package/src/global.d.ts +0 -2
  58. package/src/index.ts +1 -5
  59. package/src/load-env-plugin/plugin.ts +6 -11
  60. package/src/output-directory.ts +18 -0
  61. package/src/plugin.ts +160 -98
  62. package/src/post-server-build.ts +73 -0
  63. package/src/{nitro-plugin/prerender.ts → prerender.ts} +93 -86
  64. package/src/resolve-entries.ts +52 -0
  65. package/src/schema.ts +88 -121
  66. package/src/start-manifest-plugin/plugin.ts +8 -14
  67. package/dist/cjs/compilers.cjs +0 -416
  68. package/dist/cjs/compilers.cjs.map +0 -1
  69. package/dist/cjs/compilers.d.cts +0 -21
  70. package/dist/cjs/constants.cjs +0 -20
  71. package/dist/cjs/constants.cjs.map +0 -1
  72. package/dist/cjs/constants.d.cts +0 -6
  73. package/dist/cjs/debug.cjs +0 -5
  74. package/dist/cjs/debug.cjs.map +0 -1
  75. package/dist/cjs/debug.d.cts +0 -1
  76. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs +0 -35
  77. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +0 -1
  78. package/dist/cjs/dev-server-plugin/extract-html-scripts.d.cts +0 -4
  79. package/dist/cjs/dev-server-plugin/plugin.cjs +0 -121
  80. package/dist/cjs/dev-server-plugin/plugin.cjs.map +0 -1
  81. package/dist/cjs/dev-server-plugin/plugin.d.cts +0 -5
  82. package/dist/cjs/index.cjs +0 -11
  83. package/dist/cjs/index.cjs.map +0 -1
  84. package/dist/cjs/index.d.cts +0 -3
  85. package/dist/cjs/load-env-plugin/plugin.cjs +0 -34
  86. package/dist/cjs/load-env-plugin/plugin.cjs.map +0 -1
  87. package/dist/cjs/load-env-plugin/plugin.d.cts +0 -3
  88. package/dist/cjs/nitro-plugin/build-sitemap.cjs +0 -138
  89. package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +0 -1
  90. package/dist/cjs/nitro-plugin/build-sitemap.d.cts +0 -31
  91. package/dist/cjs/nitro-plugin/plugin.cjs +0 -187
  92. package/dist/cjs/nitro-plugin/plugin.cjs.map +0 -1
  93. package/dist/cjs/nitro-plugin/plugin.d.cts +0 -3
  94. package/dist/cjs/nitro-plugin/prerender.cjs +0 -178
  95. package/dist/cjs/nitro-plugin/prerender.cjs.map +0 -1
  96. package/dist/cjs/nitro-plugin/prerender.d.cts +0 -8
  97. package/dist/cjs/nitro-plugin/queue.cjs +0 -131
  98. package/dist/cjs/nitro-plugin/queue.cjs.map +0 -1
  99. package/dist/cjs/nitro-plugin/queue.d.cts +0 -32
  100. package/dist/cjs/plugin.cjs +0 -227
  101. package/dist/cjs/plugin.cjs.map +0 -1
  102. package/dist/cjs/plugin.d.cts +0 -300
  103. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +0 -80
  104. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +0 -1
  105. package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +0 -3
  106. package/dist/cjs/schema.cjs +0 -158
  107. package/dist/cjs/schema.cjs.map +0 -1
  108. package/dist/cjs/schema.d.cts +0 -8878
  109. package/dist/cjs/start-compiler-plugin.cjs +0 -78
  110. package/dist/cjs/start-compiler-plugin.cjs.map +0 -1
  111. package/dist/cjs/start-compiler-plugin.d.cts +0 -13
  112. package/dist/cjs/start-manifest-plugin/plugin.cjs +0 -182
  113. package/dist/cjs/start-manifest-plugin/plugin.cjs.map +0 -1
  114. package/dist/cjs/start-manifest-plugin/plugin.d.cts +0 -6
  115. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +0 -39
  116. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +0 -1
  117. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +0 -6
  118. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +0 -121
  119. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +0 -1
  120. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +0 -2
  121. package/dist/cjs/start-router-plugin/plugin.cjs +0 -45
  122. package/dist/cjs/start-router-plugin/plugin.cjs.map +0 -1
  123. package/dist/cjs/start-router-plugin/plugin.d.cts +0 -3
  124. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +0 -73
  125. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +0 -1
  126. package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +0 -6
  127. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +0 -29
  128. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +0 -1
  129. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +0 -3
  130. package/dist/cjs/utils.cjs +0 -18
  131. package/dist/cjs/utils.cjs.map +0 -1
  132. package/dist/cjs/utils.d.cts +0 -8
  133. package/dist/esm/nitro-plugin/build-sitemap.js.map +0 -1
  134. package/dist/esm/nitro-plugin/plugin.d.ts +0 -3
  135. package/dist/esm/nitro-plugin/plugin.js +0 -187
  136. package/dist/esm/nitro-plugin/plugin.js.map +0 -1
  137. package/dist/esm/nitro-plugin/prerender.d.ts +0 -8
  138. package/dist/esm/nitro-plugin/prerender.js.map +0 -1
  139. package/dist/esm/nitro-plugin/queue.js.map +0 -1
  140. package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +0 -3
  141. package/dist/esm/resolve-virtual-entries-plugin/plugin.js +0 -63
  142. package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +0 -1
  143. package/src/nitro-plugin/plugin.ts +0 -252
  144. package/src/resolve-virtual-entries-plugin/plugin.ts +0 -77
  145. /package/dist/esm/{nitro-plugin/queue.d.ts → queue.d.ts} +0 -0
  146. /package/src/{nitro-plugin/queue.ts → queue.ts} +0 -0
@@ -1,416 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const babel = require("@babel/core");
4
- const t = require("@babel/types");
5
- const codeFrame = require("@babel/code-frame");
6
- const babelDeadCodeElimination = require("babel-dead-code-elimination");
7
- const routerUtils = require("@tanstack/router-utils");
8
- function _interopNamespaceDefault(e) {
9
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
- if (e) {
11
- for (const k in e) {
12
- if (k !== "default") {
13
- const d = Object.getOwnPropertyDescriptor(e, k);
14
- Object.defineProperty(n, k, d.get ? d : {
15
- enumerable: true,
16
- get: () => e[k]
17
- });
18
- }
19
- }
20
- }
21
- n.default = e;
22
- return Object.freeze(n);
23
- }
24
- const babel__namespace = /* @__PURE__ */ _interopNamespaceDefault(babel);
25
- const t__namespace = /* @__PURE__ */ _interopNamespaceDefault(t);
26
- function compileStartOutputFactory(framework) {
27
- return function compileStartOutput(opts) {
28
- const ast = routerUtils.parseAst(opts);
29
- const doDce = opts.dce ?? true;
30
- const refIdents = doDce ? babelDeadCodeElimination.findReferencedIdentifiers(ast) : void 0;
31
- babel__namespace.traverse(ast, {
32
- Program: {
33
- enter(programPath) {
34
- const identifiers = {
35
- createServerRootRoute: {
36
- name: "createServerRootRoute",
37
- handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
38
- framework,
39
- "createServerRootRoute"
40
- ),
41
- paths: []
42
- },
43
- createServerRoute: {
44
- name: "createServerRoute",
45
- handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
46
- framework,
47
- "createServerRoute"
48
- ),
49
- paths: []
50
- },
51
- createServerFileRoute: {
52
- name: "createServerFileRoute",
53
- handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(
54
- framework,
55
- "createServerFileRoute"
56
- ),
57
- paths: []
58
- },
59
- createServerFn: {
60
- name: "createServerFn",
61
- handleCallExpression: handleCreateServerFnCallExpression,
62
- paths: []
63
- },
64
- createMiddleware: {
65
- name: "createMiddleware",
66
- handleCallExpression: handleCreateMiddlewareCallExpression,
67
- paths: []
68
- },
69
- serverOnly: {
70
- name: "serverOnly",
71
- handleCallExpression: handleServerOnlyCallExpression,
72
- paths: []
73
- },
74
- clientOnly: {
75
- name: "clientOnly",
76
- handleCallExpression: handleClientOnlyCallExpression,
77
- paths: []
78
- },
79
- createIsomorphicFn: {
80
- name: "createIsomorphicFn",
81
- handleCallExpression: handleCreateIsomorphicFnCallExpression,
82
- paths: []
83
- }
84
- };
85
- const identifierKeys = Object.keys(identifiers);
86
- programPath.traverse({
87
- ImportDeclaration: (path) => {
88
- if (path.node.source.value !== `@tanstack/${framework}-start`) {
89
- return;
90
- }
91
- path.node.specifiers.forEach((specifier) => {
92
- identifierKeys.forEach((identifierKey) => {
93
- const identifier = identifiers[identifierKey];
94
- if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier") {
95
- if (specifier.imported.name === identifierKey) {
96
- identifier.name = specifier.local.name;
97
- }
98
- }
99
- if (specifier.type === "ImportNamespaceSpecifier") {
100
- identifier.name = `${specifier.local.name}.${identifierKey}`;
101
- }
102
- });
103
- });
104
- },
105
- CallExpression: (path) => {
106
- identifierKeys.forEach((identifierKey) => {
107
- var _a;
108
- if (t__namespace.isIdentifier(path.node.callee) && path.node.callee.name === identifiers[identifierKey].name) {
109
- if (((_a = path.scope.getBinding(identifiers[identifierKey].name)) == null ? void 0 : _a.path.node.type) === "FunctionDeclaration") {
110
- return;
111
- }
112
- return identifiers[identifierKey].paths.push(path);
113
- }
114
- if (t__namespace.isMemberExpression(path.node.callee)) {
115
- if (t__namespace.isIdentifier(path.node.callee.object) && t__namespace.isIdentifier(path.node.callee.property)) {
116
- const callname = [
117
- path.node.callee.object.name,
118
- path.node.callee.property.name
119
- ].join(".");
120
- if (callname === identifiers[identifierKey].name) {
121
- identifiers[identifierKey].paths.push(path);
122
- }
123
- }
124
- }
125
- return;
126
- });
127
- }
128
- });
129
- identifierKeys.forEach((identifierKey) => {
130
- identifiers[identifierKey].paths.forEach((path) => {
131
- identifiers[identifierKey].handleCallExpression(
132
- path,
133
- opts
134
- );
135
- });
136
- });
137
- }
138
- }
139
- });
140
- if (doDce) {
141
- babelDeadCodeElimination.deadCodeElimination(ast, refIdents);
142
- }
143
- return routerUtils.generateFromAst(ast, {
144
- sourceMaps: true,
145
- sourceFileName: opts.filename,
146
- filename: opts.filename
147
- });
148
- };
149
- }
150
- function handleCreateServerFileRouteCallExpressionFactory(factory, method) {
151
- return function handleCreateServerFileRouteCallExpression(path, opts) {
152
- const PACKAGES = { start: `@tanstack/${factory}-start/server` };
153
- let highestParent = path;
154
- while (highestParent.parentPath && !highestParent.parentPath.isProgram()) {
155
- highestParent = highestParent.parentPath;
156
- }
157
- const programPath = highestParent.parentPath;
158
- if (opts.env === "client") {
159
- highestParent.remove();
160
- return;
161
- }
162
- let isCreateServerFileRouteImported = false;
163
- programPath.traverse({
164
- ImportDeclaration(importPath) {
165
- const importSource = importPath.node.source.value;
166
- if (importSource === PACKAGES.start) {
167
- const specifiers = importPath.node.specifiers;
168
- isCreateServerFileRouteImported || (isCreateServerFileRouteImported = specifiers.some((specifier) => {
169
- return t__namespace.isImportSpecifier(specifier) && t__namespace.isIdentifier(specifier.imported) && specifier.imported.name === method;
170
- }));
171
- }
172
- }
173
- });
174
- if (!isCreateServerFileRouteImported) {
175
- const importDeclaration = t__namespace.importDeclaration(
176
- [t__namespace.importSpecifier(t__namespace.identifier(method), t__namespace.identifier(method))],
177
- t__namespace.stringLiteral(PACKAGES.start)
178
- );
179
- programPath.node.body.unshift(importDeclaration);
180
- }
181
- };
182
- }
183
- const handleServerOnlyCallExpression = buildEnvOnlyCallExpressionHandler("server");
184
- const handleClientOnlyCallExpression = buildEnvOnlyCallExpressionHandler("client");
185
- function handleCreateServerFnCallExpression(path, opts) {
186
- var _a;
187
- const calledOptions = path.node.arguments[0] ? path.get("arguments.0") : null;
188
- const shouldValidateClient = !!(calledOptions == null ? void 0 : calledOptions.node.properties.find((prop) => {
189
- return t__namespace.isObjectProperty(prop) && t__namespace.isIdentifier(prop.key) && prop.key.name === "validateClient" && t__namespace.isBooleanLiteral(prop.value) && prop.value.value === true;
190
- }));
191
- const callExpressionPaths = {
192
- middleware: null,
193
- validator: null,
194
- handler: null
195
- };
196
- const validMethods = Object.keys(callExpressionPaths);
197
- const rootCallExpression = getRootCallExpression(path);
198
- if (!rootCallExpression.parentPath.isVariableDeclarator()) {
199
- throw new Error("createServerFn must be assigned to a variable!");
200
- }
201
- const variableDeclarator = rootCallExpression.parentPath.node;
202
- const existingVariableName = variableDeclarator.id.name;
203
- rootCallExpression.traverse({
204
- MemberExpression(memberExpressionPath) {
205
- if (t__namespace.isIdentifier(memberExpressionPath.node.property)) {
206
- const name = memberExpressionPath.node.property.name;
207
- if (validMethods.includes(name) && memberExpressionPath.parentPath.isCallExpression()) {
208
- callExpressionPaths[name] = memberExpressionPath.parentPath;
209
- }
210
- }
211
- }
212
- });
213
- if (callExpressionPaths.validator) {
214
- const innerInputExpression = callExpressionPaths.validator.node.arguments[0];
215
- if (!innerInputExpression) {
216
- throw new Error(
217
- "createServerFn().validator() must be called with a validator!"
218
- );
219
- }
220
- if (opts.env === "client" && !shouldValidateClient && t__namespace.isMemberExpression(callExpressionPaths.validator.node.callee)) {
221
- callExpressionPaths.validator.replaceWith(
222
- callExpressionPaths.validator.node.callee.object
223
- );
224
- }
225
- }
226
- const handlerFnPath = (_a = callExpressionPaths.handler) == null ? void 0 : _a.get(
227
- "arguments.0"
228
- );
229
- if (!callExpressionPaths.handler || !handlerFnPath.node) {
230
- throw codeFrameError(
231
- opts.code,
232
- path.node.callee.loc,
233
- `createServerFn must be called with a "handler" property!`
234
- );
235
- }
236
- const handlerFn = handlerFnPath.node;
237
- if (t__namespace.isIdentifier(handlerFn)) {
238
- if (opts.env === "client") {
239
- const binding = handlerFnPath.scope.getBinding(handlerFn.name);
240
- if (binding) {
241
- binding.path.remove();
242
- }
243
- }
244
- }
245
- handlerFnPath.replaceWith(
246
- t__namespace.arrowFunctionExpression(
247
- [t__namespace.identifier("opts"), t__namespace.identifier("signal")],
248
- t__namespace.blockStatement(
249
- // Everything in here is server-only, since the client
250
- // will strip out anything in the 'use server' directive.
251
- [
252
- t__namespace.returnStatement(
253
- t__namespace.callExpression(
254
- t__namespace.identifier(`${existingVariableName}.__executeServer`),
255
- [t__namespace.identifier("opts"), t__namespace.identifier("signal")]
256
- )
257
- )
258
- ],
259
- [t__namespace.directive(t__namespace.directiveLiteral("use server"))]
260
- )
261
- )
262
- );
263
- if (opts.env === "server") {
264
- callExpressionPaths.handler.node.arguments.push(handlerFn);
265
- }
266
- }
267
- function handleCreateMiddlewareCallExpression(path, opts) {
268
- var _a;
269
- const rootCallExpression = getRootCallExpression(path);
270
- const callExpressionPaths = {
271
- middleware: null,
272
- validator: null,
273
- client: null,
274
- server: null
275
- };
276
- const validMethods = Object.keys(callExpressionPaths);
277
- rootCallExpression.traverse({
278
- MemberExpression(memberExpressionPath) {
279
- if (t__namespace.isIdentifier(memberExpressionPath.node.property)) {
280
- const name = memberExpressionPath.node.property.name;
281
- if (validMethods.includes(name) && memberExpressionPath.parentPath.isCallExpression()) {
282
- callExpressionPaths[name] = memberExpressionPath.parentPath;
283
- }
284
- }
285
- }
286
- });
287
- if (callExpressionPaths.validator) {
288
- const innerInputExpression = callExpressionPaths.validator.node.arguments[0];
289
- if (!innerInputExpression) {
290
- throw new Error(
291
- "createMiddleware().validator() must be called with a validator!"
292
- );
293
- }
294
- if (opts.env === "client") {
295
- if (t__namespace.isMemberExpression(callExpressionPaths.validator.node.callee)) {
296
- callExpressionPaths.validator.replaceWith(
297
- callExpressionPaths.validator.node.callee.object
298
- );
299
- }
300
- }
301
- }
302
- const serverFnPath = (_a = callExpressionPaths.server) == null ? void 0 : _a.get(
303
- "arguments.0"
304
- );
305
- if (callExpressionPaths.server && serverFnPath.node && opts.env === "client") {
306
- if (t__namespace.isMemberExpression(callExpressionPaths.server.node.callee)) {
307
- callExpressionPaths.server.replaceWith(
308
- callExpressionPaths.server.node.callee.object
309
- );
310
- }
311
- }
312
- }
313
- function buildEnvOnlyCallExpressionHandler(env) {
314
- return function envOnlyCallExpressionHandler(path, opts) {
315
- const isEnvMatch = env === "client" ? opts.env === "client" : opts.env === "server";
316
- if (isEnvMatch) {
317
- const innerInputExpression = path.node.arguments[0];
318
- if (!t__namespace.isExpression(innerInputExpression)) {
319
- throw new Error(
320
- `${env}Only() functions must be called with a function!`
321
- );
322
- }
323
- path.replaceWith(innerInputExpression);
324
- return;
325
- }
326
- path.replaceWith(
327
- t__namespace.arrowFunctionExpression(
328
- [],
329
- t__namespace.blockStatement([
330
- t__namespace.throwStatement(
331
- t__namespace.newExpression(t__namespace.identifier("Error"), [
332
- t__namespace.stringLiteral(
333
- `${env}Only() functions can only be called on the ${env}!`
334
- )
335
- ])
336
- )
337
- ])
338
- )
339
- );
340
- };
341
- }
342
- function handleCreateIsomorphicFnCallExpression(path, opts) {
343
- const rootCallExpression = getRootCallExpression(path);
344
- const callExpressionPaths = {
345
- client: null,
346
- server: null
347
- };
348
- const validMethods = Object.keys(callExpressionPaths);
349
- rootCallExpression.traverse({
350
- MemberExpression(memberExpressionPath) {
351
- if (t__namespace.isIdentifier(memberExpressionPath.node.property)) {
352
- const name = memberExpressionPath.node.property.name;
353
- if (validMethods.includes(name) && memberExpressionPath.parentPath.isCallExpression()) {
354
- callExpressionPaths[name] = memberExpressionPath.parentPath;
355
- }
356
- }
357
- }
358
- });
359
- if (validMethods.every(
360
- (method) => !callExpressionPaths[method]
361
- )) {
362
- const variableId = rootCallExpression.parentPath.isVariableDeclarator() ? rootCallExpression.parentPath.node.id : null;
363
- console.warn(
364
- "createIsomorphicFn called without a client or server implementation!",
365
- "This will result in a no-op function.",
366
- "Variable name:",
367
- t__namespace.isIdentifier(variableId) ? variableId.name : "unknown"
368
- );
369
- }
370
- const envCallExpression = callExpressionPaths[opts.env];
371
- if (!envCallExpression) {
372
- rootCallExpression.replaceWith(
373
- t__namespace.arrowFunctionExpression([], t__namespace.blockStatement([]))
374
- );
375
- return;
376
- }
377
- const innerInputExpression = envCallExpression.node.arguments[0];
378
- if (!t__namespace.isExpression(innerInputExpression)) {
379
- throw new Error(
380
- `createIsomorphicFn().${opts.env}(func) must be called with a function!`
381
- );
382
- }
383
- rootCallExpression.replaceWith(innerInputExpression);
384
- }
385
- function getRootCallExpression(path) {
386
- let rootCallExpression = path;
387
- while (rootCallExpression.parentPath.isMemberExpression()) {
388
- const parent = rootCallExpression.parentPath;
389
- if (parent.parentPath.isCallExpression()) {
390
- rootCallExpression = parent.parentPath;
391
- }
392
- }
393
- return rootCallExpression;
394
- }
395
- function codeFrameError(code, loc, message) {
396
- const frame = codeFrame.codeFrameColumns(
397
- code,
398
- {
399
- start: loc.start,
400
- end: loc.end
401
- },
402
- {
403
- highlightCode: true,
404
- message
405
- }
406
- );
407
- return new Error(frame);
408
- }
409
- exports.compileStartOutputFactory = compileStartOutputFactory;
410
- exports.getRootCallExpression = getRootCallExpression;
411
- exports.handleClientOnlyCallExpression = handleClientOnlyCallExpression;
412
- exports.handleCreateIsomorphicFnCallExpression = handleCreateIsomorphicFnCallExpression;
413
- exports.handleCreateMiddlewareCallExpression = handleCreateMiddlewareCallExpression;
414
- exports.handleCreateServerFnCallExpression = handleCreateServerFnCallExpression;
415
- exports.handleServerOnlyCallExpression = handleServerOnlyCallExpression;
416
- //# sourceMappingURL=compilers.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"compilers.cjs","sources":["../../src/compilers.ts"],"sourcesContent":["import * as babel from '@babel/core'\nimport * as t from '@babel/types'\nimport { codeFrameColumns } from '@babel/code-frame'\n\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'\n\nexport type CompileStartFrameworkOptions = 'react' | 'solid'\n\nexport function compileStartOutputFactory(\n framework: CompileStartFrameworkOptions,\n) {\n return function compileStartOutput(opts: CompileOptions): GeneratorResult {\n const ast = parseAst(opts)\n\n const doDce = opts.dce ?? true\n // find referenced identifiers *before* we transform anything\n const refIdents = doDce ? findReferencedIdentifiers(ast) : undefined\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n const identifiers: {\n createServerRoute: IdentifierConfig\n createServerFileRoute: IdentifierConfig\n createServerFn: IdentifierConfig\n createMiddleware: IdentifierConfig\n serverOnly: IdentifierConfig\n clientOnly: IdentifierConfig\n createIsomorphicFn: IdentifierConfig\n createServerRootRoute: IdentifierConfig\n } = {\n createServerRootRoute: {\n name: 'createServerRootRoute',\n handleCallExpression:\n handleCreateServerFileRouteCallExpressionFactory(\n framework,\n 'createServerRootRoute',\n ),\n paths: [],\n },\n createServerRoute: {\n name: 'createServerRoute',\n handleCallExpression:\n handleCreateServerFileRouteCallExpressionFactory(\n framework,\n 'createServerRoute',\n ),\n paths: [],\n },\n createServerFileRoute: {\n name: 'createServerFileRoute',\n handleCallExpression:\n handleCreateServerFileRouteCallExpressionFactory(\n framework,\n 'createServerFileRoute',\n ),\n paths: [],\n },\n createServerFn: {\n name: 'createServerFn',\n handleCallExpression: handleCreateServerFnCallExpression,\n paths: [],\n },\n createMiddleware: {\n name: 'createMiddleware',\n handleCallExpression: handleCreateMiddlewareCallExpression,\n paths: [],\n },\n serverOnly: {\n name: 'serverOnly',\n handleCallExpression: handleServerOnlyCallExpression,\n paths: [],\n },\n clientOnly: {\n name: 'clientOnly',\n handleCallExpression: handleClientOnlyCallExpression,\n paths: [],\n },\n createIsomorphicFn: {\n name: 'createIsomorphicFn',\n handleCallExpression: handleCreateIsomorphicFnCallExpression,\n paths: [],\n },\n }\n\n const identifierKeys = Object.keys(identifiers) as Array<\n keyof typeof identifiers\n >\n\n programPath.traverse({\n ImportDeclaration: (path) => {\n if (path.node.source.value !== `@tanstack/${framework}-start`) {\n return\n }\n\n // handle a destructured imports being renamed like \"import { createServerFn as myCreateServerFn } from '@tanstack/react-start';\"\n path.node.specifiers.forEach((specifier) => {\n identifierKeys.forEach((identifierKey) => {\n const identifier = identifiers[identifierKey]\n\n if (\n specifier.type === 'ImportSpecifier' &&\n specifier.imported.type === 'Identifier'\n ) {\n if (specifier.imported.name === identifierKey) {\n identifier.name = specifier.local.name\n }\n }\n\n // handle namespace imports like \"import * as TanStackStart from '@tanstack/react-start';\"\n if (specifier.type === 'ImportNamespaceSpecifier') {\n identifier.name = `${specifier.local.name}.${identifierKey}`\n }\n })\n })\n },\n CallExpression: (path) => {\n identifierKeys.forEach((identifierKey) => {\n // Check to see if the call expression is a call to the\n // identifiers[identifierKey].name\n if (\n t.isIdentifier(path.node.callee) &&\n path.node.callee.name === identifiers[identifierKey].name\n ) {\n // The identifier could be a call to the original function\n // in the source code. If this is case, we need to ignore it.\n // Check the scope to see if the identifier is a function declaration.\n // if it is, then we can ignore it.\n\n if (\n path.scope.getBinding(identifiers[identifierKey].name)?.path\n .node.type === 'FunctionDeclaration'\n ) {\n return\n }\n\n return identifiers[identifierKey].paths.push(path)\n }\n\n if (t.isMemberExpression(path.node.callee)) {\n if (\n t.isIdentifier(path.node.callee.object) &&\n t.isIdentifier(path.node.callee.property)\n ) {\n const callname = [\n path.node.callee.object.name,\n path.node.callee.property.name,\n ].join('.')\n\n if (callname === identifiers[identifierKey].name) {\n identifiers[identifierKey].paths.push(path)\n }\n }\n }\n\n return\n })\n },\n })\n\n identifierKeys.forEach((identifierKey) => {\n identifiers[identifierKey].paths.forEach((path) => {\n identifiers[identifierKey].handleCallExpression(\n path as babel.NodePath<t.CallExpression>,\n opts,\n )\n })\n })\n },\n },\n })\n\n if (doDce) {\n deadCodeElimination(ast, refIdents)\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n }\n}\n\nfunction handleCreateServerFileRouteCallExpressionFactory(\n factory: CompileStartFrameworkOptions,\n method:\n | 'createServerFileRoute'\n | 'createServerRoute'\n | 'createServerRootRoute',\n) {\n return function handleCreateServerFileRouteCallExpression(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n ) {\n const PACKAGES = { start: `@tanstack/${factory}-start/server` }\n\n let highestParent: babel.NodePath<any> = path\n\n while (highestParent.parentPath && !highestParent.parentPath.isProgram()) {\n highestParent = highestParent.parentPath\n }\n\n const programPath = highestParent.parentPath as babel.NodePath<t.Program>\n\n // If we're on the client, remove the entire variable\n if (opts.env === 'client') {\n // console.debug('createServerFileRoute -> manifest:\\n', manifest)\n highestParent.remove()\n return\n }\n\n let isCreateServerFileRouteImported = false as boolean\n\n programPath.traverse({\n ImportDeclaration(importPath) {\n const importSource = importPath.node.source.value\n if (importSource === PACKAGES.start) {\n const specifiers = importPath.node.specifiers\n isCreateServerFileRouteImported ||= specifiers.some((specifier) => {\n return (\n t.isImportSpecifier(specifier) &&\n t.isIdentifier(specifier.imported) &&\n specifier.imported.name === method\n )\n })\n }\n },\n })\n\n if (!isCreateServerFileRouteImported) {\n const importDeclaration = t.importDeclaration(\n [t.importSpecifier(t.identifier(method), t.identifier(method))],\n t.stringLiteral(PACKAGES.start),\n )\n programPath.node.body.unshift(importDeclaration)\n }\n }\n}\n\n// build these once and reuse them\nexport const handleServerOnlyCallExpression =\n buildEnvOnlyCallExpressionHandler('server')\nexport const handleClientOnlyCallExpression =\n buildEnvOnlyCallExpressionHandler('client')\n\nexport type CompileOptions = ParseAstOptions & {\n env: 'server' | 'client'\n dce?: boolean\n filename: string\n}\n\nexport type IdentifierConfig = {\n name: string\n handleCallExpression: (\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n ) => void\n paths: Array<babel.NodePath>\n}\n\nexport function handleCreateServerFnCallExpression(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n) {\n // The function is the 'fn' property of the object passed to createServerFn\n\n // const firstArg = path.node.arguments[0]\n // if (t.isObjectExpression(firstArg)) {\n // // Was called with some options\n // }\n\n // Traverse the member expression and find the call expressions for\n // the validator, handler, and middleware methods. Check to make sure they\n // are children of the createServerFn call expression.\n\n const calledOptions = path.node.arguments[0]\n ? (path.get('arguments.0') as babel.NodePath<t.ObjectExpression>)\n : null\n\n const shouldValidateClient = !!calledOptions?.node.properties.find((prop) => {\n return (\n t.isObjectProperty(prop) &&\n t.isIdentifier(prop.key) &&\n prop.key.name === 'validateClient' &&\n t.isBooleanLiteral(prop.value) &&\n prop.value.value === true\n )\n })\n\n const callExpressionPaths = {\n middleware: null as babel.NodePath<t.CallExpression> | null,\n validator: null as babel.NodePath<t.CallExpression> | null,\n handler: null as babel.NodePath<t.CallExpression> | null,\n }\n\n const validMethods = Object.keys(callExpressionPaths)\n\n const rootCallExpression = getRootCallExpression(path)\n\n // if (debug)\n // console.info(\n // 'Handling createServerFn call expression:',\n // rootCallExpression.toString(),\n // )\n\n // Check if the call is assigned to a variable\n if (!rootCallExpression.parentPath.isVariableDeclarator()) {\n throw new Error('createServerFn must be assigned to a variable!')\n }\n\n // Get the identifier name of the variable\n const variableDeclarator = rootCallExpression.parentPath.node\n const existingVariableName = (variableDeclarator.id as t.Identifier).name\n\n rootCallExpression.traverse({\n MemberExpression(memberExpressionPath) {\n if (t.isIdentifier(memberExpressionPath.node.property)) {\n const name = memberExpressionPath.node.property\n .name as keyof typeof callExpressionPaths\n\n if (\n validMethods.includes(name) &&\n memberExpressionPath.parentPath.isCallExpression()\n ) {\n callExpressionPaths[name] = memberExpressionPath.parentPath\n }\n }\n },\n })\n\n if (callExpressionPaths.validator) {\n const innerInputExpression = callExpressionPaths.validator.node.arguments[0]\n\n if (!innerInputExpression) {\n throw new Error(\n 'createServerFn().validator() must be called with a validator!',\n )\n }\n\n // If we're on the client, and we're not validating the client, remove the validator call expression\n if (\n opts.env === 'client' &&\n !shouldValidateClient &&\n t.isMemberExpression(callExpressionPaths.validator.node.callee)\n ) {\n callExpressionPaths.validator.replaceWith(\n callExpressionPaths.validator.node.callee.object,\n )\n }\n }\n\n // First, we need to move the handler function to a nested function call\n // that is applied to the arguments passed to the server function.\n\n const handlerFnPath = callExpressionPaths.handler?.get(\n 'arguments.0',\n ) as babel.NodePath<any>\n\n if (!callExpressionPaths.handler || !handlerFnPath.node) {\n throw codeFrameError(\n opts.code,\n path.node.callee.loc!,\n `createServerFn must be called with a \"handler\" property!`,\n )\n }\n\n const handlerFn = handlerFnPath.node\n\n // So, the way we do this is we give the handler function a way\n // to access the serverFn ctx on the server via function scope.\n // The 'use server' extracted function will be called with the\n // payload from the client, then use the scoped serverFn ctx\n // to execute the handler function.\n // This way, we can do things like data and middleware validation\n // in the __execute function without having to AST transform the\n // handler function too much itself.\n\n // .handler((optsOut, ctx) => {\n // return ((optsIn) => {\n // 'use server'\n // ctx.__execute(handlerFn, optsIn)\n // })(optsOut)\n // })\n\n // If the handler function is an identifier and we're on the client, we need to\n // remove the bound function from the file.\n // If we're on the server, you can leave it, since it will get referenced\n // as a second argument.\n\n if (t.isIdentifier(handlerFn)) {\n if (opts.env === 'client') {\n // Find the binding for the handler function\n const binding = handlerFnPath.scope.getBinding(handlerFn.name)\n // Remove it\n if (binding) {\n binding.path.remove()\n }\n }\n // If the env is server, just leave it alone\n }\n\n handlerFnPath.replaceWith(\n t.arrowFunctionExpression(\n [t.identifier('opts'), t.identifier('signal')],\n t.blockStatement(\n // Everything in here is server-only, since the client\n // will strip out anything in the 'use server' directive.\n [\n t.returnStatement(\n t.callExpression(\n t.identifier(`${existingVariableName}.__executeServer`),\n [t.identifier('opts'), t.identifier('signal')],\n ),\n ),\n ],\n [t.directive(t.directiveLiteral('use server'))],\n ),\n ),\n )\n\n if (opts.env === 'server') {\n callExpressionPaths.handler.node.arguments.push(handlerFn)\n }\n}\n\nexport function handleCreateMiddlewareCallExpression(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n) {\n const rootCallExpression = getRootCallExpression(path)\n\n // if (debug)\n // console.info(\n // 'Handling createMiddleware call expression:',\n // rootCallExpression.toString(),\n // )\n\n const callExpressionPaths = {\n middleware: null as babel.NodePath<t.CallExpression> | null,\n validator: null as babel.NodePath<t.CallExpression> | null,\n client: null as babel.NodePath<t.CallExpression> | null,\n server: null as babel.NodePath<t.CallExpression> | null,\n }\n\n const validMethods = Object.keys(callExpressionPaths)\n\n rootCallExpression.traverse({\n MemberExpression(memberExpressionPath) {\n if (t.isIdentifier(memberExpressionPath.node.property)) {\n const name = memberExpressionPath.node.property\n .name as keyof typeof callExpressionPaths\n\n if (\n validMethods.includes(name) &&\n memberExpressionPath.parentPath.isCallExpression()\n ) {\n callExpressionPaths[name] = memberExpressionPath.parentPath\n }\n }\n },\n })\n\n if (callExpressionPaths.validator) {\n const innerInputExpression = callExpressionPaths.validator.node.arguments[0]\n\n if (!innerInputExpression) {\n throw new Error(\n 'createMiddleware().validator() must be called with a validator!',\n )\n }\n\n // If we're on the client, remove the validator call expression\n if (opts.env === 'client') {\n if (t.isMemberExpression(callExpressionPaths.validator.node.callee)) {\n callExpressionPaths.validator.replaceWith(\n callExpressionPaths.validator.node.callee.object,\n )\n }\n }\n }\n\n const serverFnPath = callExpressionPaths.server?.get(\n 'arguments.0',\n ) as babel.NodePath<any>\n\n if (\n callExpressionPaths.server &&\n serverFnPath.node &&\n opts.env === 'client'\n ) {\n // If we're on the client, remove the server call expression\n if (t.isMemberExpression(callExpressionPaths.server.node.callee)) {\n callExpressionPaths.server.replaceWith(\n callExpressionPaths.server.node.callee.object,\n )\n }\n }\n}\n\nfunction buildEnvOnlyCallExpressionHandler(env: 'client' | 'server') {\n return function envOnlyCallExpressionHandler(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n ) {\n // if (debug)\n // console.info(`Handling ${env}Only call expression:`, path.toString())\n\n const isEnvMatch =\n env === 'client' ? opts.env === 'client' : opts.env === 'server'\n\n if (isEnvMatch) {\n // extract the inner function from the call expression\n const innerInputExpression = path.node.arguments[0]\n\n if (!t.isExpression(innerInputExpression)) {\n throw new Error(\n `${env}Only() functions must be called with a function!`,\n )\n }\n\n path.replaceWith(innerInputExpression)\n return\n }\n\n // If we're on the wrong environment, replace the call expression\n // with a function that always throws an error.\n path.replaceWith(\n t.arrowFunctionExpression(\n [],\n t.blockStatement([\n t.throwStatement(\n t.newExpression(t.identifier('Error'), [\n t.stringLiteral(\n `${env}Only() functions can only be called on the ${env}!`,\n ),\n ]),\n ),\n ]),\n ),\n )\n }\n}\n\nexport function handleCreateIsomorphicFnCallExpression(\n path: babel.NodePath<t.CallExpression>,\n opts: CompileOptions,\n) {\n const rootCallExpression = getRootCallExpression(path)\n\n // if (debug)\n // console.info(\n // 'Handling createIsomorphicFn call expression:',\n // rootCallExpression.toString(),\n // )\n\n const callExpressionPaths = {\n client: null as babel.NodePath<t.CallExpression> | null,\n server: null as babel.NodePath<t.CallExpression> | null,\n }\n\n const validMethods = Object.keys(callExpressionPaths)\n\n rootCallExpression.traverse({\n MemberExpression(memberExpressionPath) {\n if (t.isIdentifier(memberExpressionPath.node.property)) {\n const name = memberExpressionPath.node.property\n .name as keyof typeof callExpressionPaths\n\n if (\n validMethods.includes(name) &&\n memberExpressionPath.parentPath.isCallExpression()\n ) {\n callExpressionPaths[name] = memberExpressionPath.parentPath\n }\n }\n },\n })\n\n if (\n validMethods.every(\n (method) =>\n !callExpressionPaths[method as keyof typeof callExpressionPaths],\n )\n ) {\n const variableId = rootCallExpression.parentPath.isVariableDeclarator()\n ? rootCallExpression.parentPath.node.id\n : null\n console.warn(\n 'createIsomorphicFn called without a client or server implementation!',\n 'This will result in a no-op function.',\n 'Variable name:',\n t.isIdentifier(variableId) ? variableId.name : 'unknown',\n )\n }\n\n const envCallExpression = callExpressionPaths[opts.env]\n\n if (!envCallExpression) {\n // if we don't have an implementation for this environment, default to a no-op\n rootCallExpression.replaceWith(\n t.arrowFunctionExpression([], t.blockStatement([])),\n )\n return\n }\n\n const innerInputExpression = envCallExpression.node.arguments[0]\n\n if (!t.isExpression(innerInputExpression)) {\n throw new Error(\n `createIsomorphicFn().${opts.env}(func) must be called with a function!`,\n )\n }\n\n rootCallExpression.replaceWith(innerInputExpression)\n}\n\nexport function getRootCallExpression(path: babel.NodePath<t.CallExpression>) {\n // Find the highest callExpression parent\n let rootCallExpression: babel.NodePath<t.CallExpression> = path\n\n // Traverse up the chain of CallExpressions\n while (rootCallExpression.parentPath.isMemberExpression()) {\n const parent = rootCallExpression.parentPath\n if (parent.parentPath.isCallExpression()) {\n rootCallExpression = parent.parentPath\n }\n }\n\n return rootCallExpression\n}\n\nfunction codeFrameError(\n code: string,\n loc: {\n start: { line: number; column: number }\n end: { line: number; column: number }\n },\n message: string,\n) {\n const frame = codeFrameColumns(\n code,\n {\n start: loc.start,\n end: loc.end,\n },\n {\n highlightCode: true,\n message,\n },\n )\n\n return new Error(frame)\n}\n"],"names":["parseAst","findReferencedIdentifiers","babel","t","deadCodeElimination","generateFrom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AU,IAAI,WAAW,OAAO;AAAA,IACjD;AAAA,EAAA;AAGI,QAAA,oBAAoB,oBAAoB,KAAK,GAAG;AAEtD,MAAI,CAAC,mBAAmB;AAEH,uBAAA;AAAA,MACjBA,aAAE,wBAAwB,CAAA,GAAIA,aAAE,eAAe,CAAA,CAAE,CAAC;AAAA,IACpD;AACA;AAAA,EAAA;AAGF,QAAM,uBAAuB,kBAAkB,KAAK,UAAU,CAAC;AAE/D,MAAI,CAACA,aAAE,aAAa,oBAAoB,GAAG;AACzC,UAAM,IAAI;AAAA,MACR,wBAAwB,KAAK,GAAG;AAAA,IAClC;AAAA,EAAA;AAGF,qBAAmB,YAAY,oBAAoB;AACrD;AAEO,SAAS,sBAAsB,MAAwC;AAE5E,MAAI,qBAAuD;AAGpD,SAAA,mBAAmB,WAAW,sBAAsB;AACzD,UAAM,SAAS,mBAAmB;AAC9B,QAAA,OAAO,WAAW,oBAAoB;AACxC,2BAAqB,OAAO;AAAA,IAAA;AAAA,EAC9B;AAGK,SAAA;AACT;AAEA,SAAS,eACP,MACA,KAIA,SACA;AACA,QAAM,QAAQG,UAAA;AAAA,IACZ;AAAA,IACA;AAAA,MACE,OAAO,IAAI;AAAA,MACX,KAAK,IAAI;AAAA,IACX;AAAA,IACA;AAAA,MACE,eAAe;AAAA,MACf;AAAA,IAAA;AAAA,EAEJ;AAEO,SAAA,IAAI,MAAM,KAAK;AACxB;;;;;;;;"}
@@ -1,21 +0,0 @@
1
- import { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils';
2
- import * as babel from '@babel/core';
3
- import * as t from '@babel/types';
4
- export type CompileStartFrameworkOptions = 'react' | 'solid';
5
- export declare function compileStartOutputFactory(framework: CompileStartFrameworkOptions): (opts: CompileOptions) => GeneratorResult;
6
- export declare const handleServerOnlyCallExpression: (path: babel.NodePath<t.CallExpression>, opts: CompileOptions) => void;
7
- export declare const handleClientOnlyCallExpression: (path: babel.NodePath<t.CallExpression>, opts: CompileOptions) => void;
8
- export type CompileOptions = ParseAstOptions & {
9
- env: 'server' | 'client';
10
- dce?: boolean;
11
- filename: string;
12
- };
13
- export type IdentifierConfig = {
14
- name: string;
15
- handleCallExpression: (path: babel.NodePath<t.CallExpression>, opts: CompileOptions) => void;
16
- paths: Array<babel.NodePath>;
17
- };
18
- export declare function handleCreateServerFnCallExpression(path: babel.NodePath<t.CallExpression>, opts: CompileOptions): void;
19
- export declare function handleCreateMiddlewareCallExpression(path: babel.NodePath<t.CallExpression>, opts: CompileOptions): void;
20
- export declare function handleCreateIsomorphicFnCallExpression(path: babel.NodePath<t.CallExpression>, opts: CompileOptions): void;
21
- export declare function getRootCallExpression(path: babel.NodePath<t.CallExpression>): babel.NodePath<t.CallExpression>;
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const path = require("node:path");
4
- const VITE_ENVIRONMENT_NAMES = {
5
- // 'ssr' is chosen as the name for the server environment to ensure backwards compatibility
6
- // with vite plugins that are not compatible with the new vite environment API (e.g. tailwindcss)
7
- server: "ssr",
8
- client: "client"
9
- };
10
- const CLIENT_DIST_DIR = path.join(
11
- ".tanstack",
12
- "start",
13
- "build",
14
- "client-dist"
15
- );
16
- const SSR_ENTRY_FILE = "ssr.mjs";
17
- exports.CLIENT_DIST_DIR = CLIENT_DIST_DIR;
18
- exports.SSR_ENTRY_FILE = SSR_ENTRY_FILE;
19
- exports.VITE_ENVIRONMENT_NAMES = VITE_ENVIRONMENT_NAMES;
20
- //# sourceMappingURL=constants.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.cjs","sources":["../../src/constants.ts"],"sourcesContent":["import path from 'node:path'\n\nexport const VITE_ENVIRONMENT_NAMES = {\n // 'ssr' is chosen as the name for the server environment to ensure backwards compatibility\n // with vite plugins that are not compatible with the new vite environment API (e.g. tailwindcss)\n server: 'ssr',\n client: 'client',\n} as const\n\nexport const CLIENT_DIST_DIR = path.join(\n '.tanstack',\n 'start',\n 'build',\n 'client-dist',\n)\nexport const SSR_ENTRY_FILE = 'ssr.mjs'\n"],"names":[],"mappings":";;;AAEO,MAAM,yBAAyB;AAAA;AAAA;AAAA,EAGpC,QAAQ;AAAA,EACR,QAAQ;AACV;AAEO,MAAM,kBAAkB,KAAK;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACO,MAAM,iBAAiB;;;;"}
@@ -1,6 +0,0 @@
1
- export declare const VITE_ENVIRONMENT_NAMES: {
2
- readonly server: "ssr";
3
- readonly client: "client";
4
- };
5
- export declare const CLIENT_DIST_DIR: string;
6
- export declare const SSR_ENTRY_FILE = "ssr.mjs";
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const debug = process.env.TSR_VITE_DEBUG && ["true", "start-plugin-core"].includes(process.env.TSR_VITE_DEBUG);
4
- exports.debug = debug;
5
- //# sourceMappingURL=debug.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"debug.cjs","sources":["../../src/debug.ts"],"sourcesContent":["export const debug =\n process.env.TSR_VITE_DEBUG &&\n ['true', 'start-plugin-core'].includes(process.env.TSR_VITE_DEBUG)\n"],"names":[],"mappings":";;AAAa,MAAA,QACX,QAAQ,IAAI,kBACZ,CAAC,QAAQ,mBAAmB,EAAE,SAAS,QAAQ,IAAI,cAAc;;"}
@@ -1 +0,0 @@
1
- export declare const debug: boolean | "" | undefined;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const cheerio = require("cheerio");
4
- function _interopNamespaceDefault(e) {
5
- const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
6
- if (e) {
7
- for (const k in e) {
8
- if (k !== "default") {
9
- const d = Object.getOwnPropertyDescriptor(e, k);
10
- Object.defineProperty(n, k, d.get ? d : {
11
- enumerable: true,
12
- get: () => e[k]
13
- });
14
- }
15
- }
16
- }
17
- n.default = e;
18
- return Object.freeze(n);
19
- }
20
- const cheerio__namespace = /* @__PURE__ */ _interopNamespaceDefault(cheerio);
21
- function extractHtmlScripts(html) {
22
- const $ = cheerio__namespace.load(html);
23
- const scripts = [];
24
- $("script").each((_, element) => {
25
- const src = $(element).attr("src");
26
- const content = $(element).html() ?? void 0;
27
- scripts.push({
28
- src,
29
- content
30
- });
31
- });
32
- return scripts;
33
- }
34
- exports.extractHtmlScripts = extractHtmlScripts;
35
- //# sourceMappingURL=extract-html-scripts.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extract-html-scripts.cjs","sources":["../../../src/dev-server-plugin/extract-html-scripts.ts"],"sourcesContent":["import * as cheerio from 'cheerio'\n\nexport function extractHtmlScripts(\n html: string,\n): Array<{ content?: string; src?: string }> {\n const $ = cheerio.load(html)\n const scripts: Array<{ content?: string; src?: string }> = []\n\n $('script').each((_, element) => {\n const src = $(element).attr('src')\n const content = $(element).html() ?? undefined\n scripts.push({\n src,\n content,\n })\n })\n\n return scripts\n}\n"],"names":["cheerio"],"mappings":";;;;;;;;;;;;;;;;;;;;AAEO,SAAS,mBACd,MAC2C;AACrC,QAAA,IAAIA,mBAAQ,KAAK,IAAI;AAC3B,QAAM,UAAqD,CAAC;AAE5D,IAAE,QAAQ,EAAE,KAAK,CAAC,GAAG,YAAY;AAC/B,UAAM,MAAM,EAAE,OAAO,EAAE,KAAK,KAAK;AACjC,UAAM,UAAU,EAAE,OAAO,EAAE,KAAU,KAAA;AACrC,YAAQ,KAAK;AAAA,MACX;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EAAA,CACF;AAEM,SAAA;AACT;;"}
@@ -1,4 +0,0 @@
1
- export declare function extractHtmlScripts(html: string): Array<{
2
- content?: string;
3
- src?: string;
4
- }>;