@tanstack/start-plugin-core 1.20.3-alpha.1

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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -0
  3. package/dist/cjs/compilers.cjs +402 -0
  4. package/dist/cjs/compilers.cjs.map +1 -0
  5. package/dist/cjs/compilers.d.cts +21 -0
  6. package/dist/cjs/extractHtmlScripts.cjs +35 -0
  7. package/dist/cjs/extractHtmlScripts.cjs.map +1 -0
  8. package/dist/cjs/extractHtmlScripts.d.cts +4 -0
  9. package/dist/cjs/index.cjs +15 -0
  10. package/dist/cjs/index.cjs.map +1 -0
  11. package/dist/cjs/index.d.cts +7 -0
  12. package/dist/cjs/nitro/build-nitro.cjs +18 -0
  13. package/dist/cjs/nitro/build-nitro.cjs.map +1 -0
  14. package/dist/cjs/nitro/build-nitro.d.cts +2 -0
  15. package/dist/cjs/nitro/build-sitemap.cjs +54 -0
  16. package/dist/cjs/nitro/build-sitemap.cjs.map +1 -0
  17. package/dist/cjs/nitro/build-sitemap.d.cts +9 -0
  18. package/dist/cjs/nitro/dev-server-plugin.cjs +128 -0
  19. package/dist/cjs/nitro/dev-server-plugin.cjs.map +1 -0
  20. package/dist/cjs/nitro/dev-server-plugin.d.cts +5 -0
  21. package/dist/cjs/nitro/nitro-plugin.cjs +128 -0
  22. package/dist/cjs/nitro/nitro-plugin.cjs.map +1 -0
  23. package/dist/cjs/nitro/nitro-plugin.d.cts +3 -0
  24. package/dist/cjs/plugin.cjs +117 -0
  25. package/dist/cjs/plugin.cjs.map +1 -0
  26. package/dist/cjs/plugin.d.cts +2713 -0
  27. package/dist/cjs/prerender.cjs +171 -0
  28. package/dist/cjs/prerender.cjs.map +1 -0
  29. package/dist/cjs/prerender.d.cts +8 -0
  30. package/dist/cjs/queue.cjs +131 -0
  31. package/dist/cjs/queue.cjs.map +1 -0
  32. package/dist/cjs/queue.d.cts +32 -0
  33. package/dist/cjs/routesManifestPlugin.cjs +165 -0
  34. package/dist/cjs/routesManifestPlugin.cjs.map +1 -0
  35. package/dist/cjs/routesManifestPlugin.d.cts +3 -0
  36. package/dist/cjs/schema.cjs +136 -0
  37. package/dist/cjs/schema.cjs.map +1 -0
  38. package/dist/cjs/schema.d.cts +8128 -0
  39. package/dist/cjs/start-compiler-plugin.cjs +72 -0
  40. package/dist/cjs/start-compiler-plugin.cjs.map +1 -0
  41. package/dist/cjs/start-compiler-plugin.d.cts +13 -0
  42. package/dist/cjs/start-server-routes-plugin/config.d.cts +49 -0
  43. package/dist/cjs/start-server-routes-plugin/plugin.cjs +608 -0
  44. package/dist/cjs/start-server-routes-plugin/plugin.cjs.map +1 -0
  45. package/dist/cjs/start-server-routes-plugin/plugin.d.cts +3 -0
  46. package/dist/cjs/start-server-routes-plugin/template.cjs +111 -0
  47. package/dist/cjs/start-server-routes-plugin/template.cjs.map +1 -0
  48. package/dist/cjs/start-server-routes-plugin/template.d.cts +34 -0
  49. package/dist/esm/compilers.d.ts +21 -0
  50. package/dist/esm/compilers.js +384 -0
  51. package/dist/esm/compilers.js.map +1 -0
  52. package/dist/esm/extractHtmlScripts.d.ts +4 -0
  53. package/dist/esm/extractHtmlScripts.js +18 -0
  54. package/dist/esm/extractHtmlScripts.js.map +1 -0
  55. package/dist/esm/index.d.ts +7 -0
  56. package/dist/esm/index.js +15 -0
  57. package/dist/esm/index.js.map +1 -0
  58. package/dist/esm/nitro/build-nitro.d.ts +2 -0
  59. package/dist/esm/nitro/build-nitro.js +18 -0
  60. package/dist/esm/nitro/build-nitro.js.map +1 -0
  61. package/dist/esm/nitro/build-sitemap.d.ts +9 -0
  62. package/dist/esm/nitro/build-sitemap.js +54 -0
  63. package/dist/esm/nitro/build-sitemap.js.map +1 -0
  64. package/dist/esm/nitro/dev-server-plugin.d.ts +5 -0
  65. package/dist/esm/nitro/dev-server-plugin.js +128 -0
  66. package/dist/esm/nitro/dev-server-plugin.js.map +1 -0
  67. package/dist/esm/nitro/nitro-plugin.d.ts +3 -0
  68. package/dist/esm/nitro/nitro-plugin.js +128 -0
  69. package/dist/esm/nitro/nitro-plugin.js.map +1 -0
  70. package/dist/esm/plugin.d.ts +2713 -0
  71. package/dist/esm/plugin.js +117 -0
  72. package/dist/esm/plugin.js.map +1 -0
  73. package/dist/esm/prerender.d.ts +8 -0
  74. package/dist/esm/prerender.js +171 -0
  75. package/dist/esm/prerender.js.map +1 -0
  76. package/dist/esm/queue.d.ts +32 -0
  77. package/dist/esm/queue.js +131 -0
  78. package/dist/esm/queue.js.map +1 -0
  79. package/dist/esm/routesManifestPlugin.d.ts +3 -0
  80. package/dist/esm/routesManifestPlugin.js +165 -0
  81. package/dist/esm/routesManifestPlugin.js.map +1 -0
  82. package/dist/esm/schema.d.ts +8128 -0
  83. package/dist/esm/schema.js +136 -0
  84. package/dist/esm/schema.js.map +1 -0
  85. package/dist/esm/start-compiler-plugin.d.ts +13 -0
  86. package/dist/esm/start-compiler-plugin.js +72 -0
  87. package/dist/esm/start-compiler-plugin.js.map +1 -0
  88. package/dist/esm/start-server-routes-plugin/config.d.ts +49 -0
  89. package/dist/esm/start-server-routes-plugin/plugin.d.ts +3 -0
  90. package/dist/esm/start-server-routes-plugin/plugin.js +608 -0
  91. package/dist/esm/start-server-routes-plugin/plugin.js.map +1 -0
  92. package/dist/esm/start-server-routes-plugin/template.d.ts +34 -0
  93. package/dist/esm/start-server-routes-plugin/template.js +111 -0
  94. package/dist/esm/start-server-routes-plugin/template.js.map +1 -0
  95. package/package.json +72 -0
  96. package/src/compilers.ts +759 -0
  97. package/src/extractHtmlScripts.ts +19 -0
  98. package/src/index.ts +15 -0
  99. package/src/nitro/build-nitro.ts +27 -0
  100. package/src/nitro/build-sitemap.ts +79 -0
  101. package/src/nitro/dev-server-plugin.ts +159 -0
  102. package/src/nitro/nitro-plugin.ts +161 -0
  103. package/src/plugin.ts +145 -0
  104. package/src/prerender.ts +245 -0
  105. package/src/queue.ts +153 -0
  106. package/src/routesManifestPlugin.ts +216 -0
  107. package/src/schema.ts +193 -0
  108. package/src/start-compiler-plugin.ts +111 -0
  109. package/src/start-server-routes-plugin/config.ts +8 -0
  110. package/src/start-server-routes-plugin/plugin.ts +890 -0
  111. package/src/start-server-routes-plugin/template.ts +164 -0
@@ -0,0 +1,384 @@
1
+ import * as babel from "@babel/core";
2
+ import * as t from "@babel/types";
3
+ import { codeFrameColumns } from "@babel/code-frame";
4
+ import { findReferencedIdentifiers, deadCodeElimination } from "babel-dead-code-elimination";
5
+ import { parseAst, generateFromAst } from "@tanstack/router-utils";
6
+ function compileStartOutputFactory(framework) {
7
+ return function compileStartOutput(opts) {
8
+ const ast = parseAst(opts);
9
+ const doDce = opts.dce ?? true;
10
+ const refIdents = doDce ? findReferencedIdentifiers(ast) : void 0;
11
+ babel.traverse(ast, {
12
+ Program: {
13
+ enter(programPath) {
14
+ const identifiers = {
15
+ createServerFileRoute: {
16
+ name: "createServerFileRoute",
17
+ handleCallExpression: handleCreateServerFileRouteCallExpressionFactory(framework),
18
+ paths: []
19
+ },
20
+ createServerFn: {
21
+ name: "createServerFn",
22
+ handleCallExpression: handleCreateServerFnCallExpression,
23
+ paths: []
24
+ },
25
+ createMiddleware: {
26
+ name: "createMiddleware",
27
+ handleCallExpression: handleCreateMiddlewareCallExpression,
28
+ paths: []
29
+ },
30
+ serverOnly: {
31
+ name: "serverOnly",
32
+ handleCallExpression: handleServerOnlyCallExpression,
33
+ paths: []
34
+ },
35
+ clientOnly: {
36
+ name: "clientOnly",
37
+ handleCallExpression: handleClientOnlyCallExpression,
38
+ paths: []
39
+ },
40
+ createIsomorphicFn: {
41
+ name: "createIsomorphicFn",
42
+ handleCallExpression: handleCreateIsomorphicFnCallExpression,
43
+ paths: []
44
+ }
45
+ };
46
+ const identifierKeys = Object.keys(identifiers);
47
+ programPath.traverse({
48
+ ImportDeclaration: (path) => {
49
+ if (path.node.source.value !== "@tanstack/react-start" && path.node.source.value !== "@tanstack/solid-start") {
50
+ return;
51
+ }
52
+ path.node.specifiers.forEach((specifier) => {
53
+ identifierKeys.forEach((identifierKey) => {
54
+ const identifier = identifiers[identifierKey];
55
+ if (specifier.type === "ImportSpecifier" && specifier.imported.type === "Identifier") {
56
+ if (specifier.imported.name === identifierKey) {
57
+ identifier.name = specifier.local.name;
58
+ }
59
+ }
60
+ if (specifier.type === "ImportNamespaceSpecifier") {
61
+ identifier.name = `${specifier.local.name}.${identifierKey}`;
62
+ }
63
+ });
64
+ });
65
+ },
66
+ CallExpression: (path) => {
67
+ identifierKeys.forEach((identifierKey) => {
68
+ var _a;
69
+ if (t.isIdentifier(path.node.callee) && path.node.callee.name === identifiers[identifierKey].name) {
70
+ if (((_a = path.scope.getBinding(identifiers[identifierKey].name)) == null ? void 0 : _a.path.node.type) === "FunctionDeclaration") {
71
+ return;
72
+ }
73
+ return identifiers[identifierKey].paths.push(path);
74
+ }
75
+ if (t.isMemberExpression(path.node.callee)) {
76
+ if (t.isIdentifier(path.node.callee.object) && t.isIdentifier(path.node.callee.property)) {
77
+ const callname = [
78
+ path.node.callee.object.name,
79
+ path.node.callee.property.name
80
+ ].join(".");
81
+ if (callname === identifiers[identifierKey].name) {
82
+ identifiers[identifierKey].paths.push(path);
83
+ }
84
+ }
85
+ }
86
+ return;
87
+ });
88
+ }
89
+ });
90
+ identifierKeys.forEach((identifierKey) => {
91
+ identifiers[identifierKey].paths.forEach((path) => {
92
+ identifiers[identifierKey].handleCallExpression(
93
+ path,
94
+ opts
95
+ );
96
+ });
97
+ });
98
+ }
99
+ }
100
+ });
101
+ if (doDce) {
102
+ deadCodeElimination(ast, refIdents);
103
+ }
104
+ return generateFromAst(ast, {
105
+ sourceMaps: true,
106
+ sourceFileName: opts.filename,
107
+ filename: opts.filename
108
+ });
109
+ };
110
+ }
111
+ function handleCreateServerFileRouteCallExpressionFactory(factory) {
112
+ return function handleCreateServerFileRouteCallExpression(path, opts) {
113
+ const PACKAGES = { start: `@tanstack/${factory}-start/server` };
114
+ let highestParent = path;
115
+ while (highestParent.parentPath && !highestParent.parentPath.isProgram()) {
116
+ highestParent = highestParent.parentPath;
117
+ }
118
+ const programPath = highestParent.parentPath;
119
+ if (opts.env === "client") {
120
+ highestParent.remove();
121
+ return;
122
+ }
123
+ let isCreateServerFileRouteImported = false;
124
+ programPath.traverse({
125
+ ImportDeclaration(importPath) {
126
+ const importSource = importPath.node.source.value;
127
+ if (importSource === PACKAGES.start) {
128
+ const specifiers = importPath.node.specifiers;
129
+ isCreateServerFileRouteImported = specifiers.some((specifier) => {
130
+ return t.isImportSpecifier(specifier) && t.isIdentifier(specifier.imported) && specifier.imported.name === "createServerFileRoute";
131
+ });
132
+ }
133
+ }
134
+ });
135
+ if (!isCreateServerFileRouteImported) {
136
+ const importDeclaration = t.importDeclaration(
137
+ [
138
+ t.importSpecifier(
139
+ t.identifier("createServerFileRoute"),
140
+ t.identifier("createServerFileRoute")
141
+ )
142
+ ],
143
+ t.stringLiteral(PACKAGES.start)
144
+ );
145
+ programPath.node.body.unshift(importDeclaration);
146
+ }
147
+ };
148
+ }
149
+ const handleServerOnlyCallExpression = buildEnvOnlyCallExpressionHandler("server");
150
+ const handleClientOnlyCallExpression = buildEnvOnlyCallExpressionHandler("client");
151
+ function handleCreateServerFnCallExpression(path, opts) {
152
+ var _a;
153
+ const calledOptions = path.node.arguments[0] ? path.get("arguments.0") : null;
154
+ const shouldValidateClient = !!(calledOptions == null ? void 0 : calledOptions.node.properties.find((prop) => {
155
+ return t.isObjectProperty(prop) && t.isIdentifier(prop.key) && prop.key.name === "validateClient" && t.isBooleanLiteral(prop.value) && prop.value.value === true;
156
+ }));
157
+ const callExpressionPaths = {
158
+ middleware: null,
159
+ validator: null,
160
+ handler: null
161
+ };
162
+ const validMethods = Object.keys(callExpressionPaths);
163
+ const rootCallExpression = getRootCallExpression(path);
164
+ if (!rootCallExpression.parentPath.isVariableDeclarator()) {
165
+ throw new Error("createServerFn must be assigned to a variable!");
166
+ }
167
+ const variableDeclarator = rootCallExpression.parentPath.node;
168
+ const existingVariableName = variableDeclarator.id.name;
169
+ rootCallExpression.traverse({
170
+ MemberExpression(memberExpressionPath) {
171
+ if (t.isIdentifier(memberExpressionPath.node.property)) {
172
+ const name = memberExpressionPath.node.property.name;
173
+ if (validMethods.includes(name) && memberExpressionPath.parentPath.isCallExpression()) {
174
+ callExpressionPaths[name] = memberExpressionPath.parentPath;
175
+ }
176
+ }
177
+ }
178
+ });
179
+ if (callExpressionPaths.validator) {
180
+ const innerInputExpression = callExpressionPaths.validator.node.arguments[0];
181
+ if (!innerInputExpression) {
182
+ throw new Error(
183
+ "createServerFn().validator() must be called with a validator!"
184
+ );
185
+ }
186
+ if (opts.env === "client" && !shouldValidateClient && t.isMemberExpression(callExpressionPaths.validator.node.callee)) {
187
+ callExpressionPaths.validator.replaceWith(
188
+ callExpressionPaths.validator.node.callee.object
189
+ );
190
+ }
191
+ }
192
+ const handlerFnPath = (_a = callExpressionPaths.handler) == null ? void 0 : _a.get(
193
+ "arguments.0"
194
+ );
195
+ if (!callExpressionPaths.handler || !handlerFnPath.node) {
196
+ throw codeFrameError(
197
+ opts.code,
198
+ path.node.callee.loc,
199
+ `createServerFn must be called with a "handler" property!`
200
+ );
201
+ }
202
+ const handlerFn = handlerFnPath.node;
203
+ if (t.isIdentifier(handlerFn)) {
204
+ if (opts.env === "client") {
205
+ const binding = handlerFnPath.scope.getBinding(handlerFn.name);
206
+ if (binding) {
207
+ binding.path.remove();
208
+ }
209
+ }
210
+ }
211
+ handlerFnPath.replaceWith(
212
+ t.arrowFunctionExpression(
213
+ [t.identifier("opts"), t.identifier("signal")],
214
+ t.blockStatement(
215
+ // Everything in here is server-only, since the client
216
+ // will strip out anything in the 'use server' directive.
217
+ [
218
+ t.returnStatement(
219
+ t.callExpression(
220
+ t.identifier(`${existingVariableName}.__executeServer`),
221
+ [t.identifier("opts"), t.identifier("signal")]
222
+ )
223
+ )
224
+ ],
225
+ [t.directive(t.directiveLiteral("use server"))]
226
+ )
227
+ )
228
+ );
229
+ if (opts.env === "server") {
230
+ callExpressionPaths.handler.node.arguments.push(handlerFn);
231
+ }
232
+ }
233
+ function handleCreateMiddlewareCallExpression(path, opts) {
234
+ var _a;
235
+ const rootCallExpression = getRootCallExpression(path);
236
+ const callExpressionPaths = {
237
+ middleware: null,
238
+ validator: null,
239
+ client: null,
240
+ server: null
241
+ };
242
+ const validMethods = Object.keys(callExpressionPaths);
243
+ rootCallExpression.traverse({
244
+ MemberExpression(memberExpressionPath) {
245
+ if (t.isIdentifier(memberExpressionPath.node.property)) {
246
+ const name = memberExpressionPath.node.property.name;
247
+ if (validMethods.includes(name) && memberExpressionPath.parentPath.isCallExpression()) {
248
+ callExpressionPaths[name] = memberExpressionPath.parentPath;
249
+ }
250
+ }
251
+ }
252
+ });
253
+ if (callExpressionPaths.validator) {
254
+ const innerInputExpression = callExpressionPaths.validator.node.arguments[0];
255
+ if (!innerInputExpression) {
256
+ throw new Error(
257
+ "createMiddleware().validator() must be called with a validator!"
258
+ );
259
+ }
260
+ if (opts.env === "client") {
261
+ if (t.isMemberExpression(callExpressionPaths.validator.node.callee)) {
262
+ callExpressionPaths.validator.replaceWith(
263
+ callExpressionPaths.validator.node.callee.object
264
+ );
265
+ }
266
+ }
267
+ }
268
+ const serverFnPath = (_a = callExpressionPaths.server) == null ? void 0 : _a.get(
269
+ "arguments.0"
270
+ );
271
+ if (callExpressionPaths.server && serverFnPath.node && opts.env === "client") {
272
+ if (t.isMemberExpression(callExpressionPaths.server.node.callee)) {
273
+ callExpressionPaths.server.replaceWith(
274
+ callExpressionPaths.server.node.callee.object
275
+ );
276
+ }
277
+ }
278
+ }
279
+ function buildEnvOnlyCallExpressionHandler(env) {
280
+ return function envOnlyCallExpressionHandler(path, opts) {
281
+ const isEnvMatch = env === "client" ? opts.env === "client" : opts.env === "server";
282
+ if (isEnvMatch) {
283
+ const innerInputExpression = path.node.arguments[0];
284
+ if (!t.isExpression(innerInputExpression)) {
285
+ throw new Error(
286
+ `${env}Only() functions must be called with a function!`
287
+ );
288
+ }
289
+ path.replaceWith(innerInputExpression);
290
+ return;
291
+ }
292
+ path.replaceWith(
293
+ t.arrowFunctionExpression(
294
+ [],
295
+ t.blockStatement([
296
+ t.throwStatement(
297
+ t.newExpression(t.identifier("Error"), [
298
+ t.stringLiteral(
299
+ `${env}Only() functions can only be called on the ${env}!`
300
+ )
301
+ ])
302
+ )
303
+ ])
304
+ )
305
+ );
306
+ };
307
+ }
308
+ function handleCreateIsomorphicFnCallExpression(path, opts) {
309
+ const rootCallExpression = getRootCallExpression(path);
310
+ const callExpressionPaths = {
311
+ client: null,
312
+ server: null
313
+ };
314
+ const validMethods = Object.keys(callExpressionPaths);
315
+ rootCallExpression.traverse({
316
+ MemberExpression(memberExpressionPath) {
317
+ if (t.isIdentifier(memberExpressionPath.node.property)) {
318
+ const name = memberExpressionPath.node.property.name;
319
+ if (validMethods.includes(name) && memberExpressionPath.parentPath.isCallExpression()) {
320
+ callExpressionPaths[name] = memberExpressionPath.parentPath;
321
+ }
322
+ }
323
+ }
324
+ });
325
+ if (validMethods.every(
326
+ (method) => !callExpressionPaths[method]
327
+ )) {
328
+ const variableId = rootCallExpression.parentPath.isVariableDeclarator() ? rootCallExpression.parentPath.node.id : null;
329
+ console.warn(
330
+ "createIsomorphicFn called without a client or server implementation!",
331
+ "This will result in a no-op function.",
332
+ "Variable name:",
333
+ t.isIdentifier(variableId) ? variableId.name : "unknown"
334
+ );
335
+ }
336
+ const envCallExpression = callExpressionPaths[opts.env];
337
+ if (!envCallExpression) {
338
+ rootCallExpression.replaceWith(
339
+ t.arrowFunctionExpression([], t.blockStatement([]))
340
+ );
341
+ return;
342
+ }
343
+ const innerInputExpression = envCallExpression.node.arguments[0];
344
+ if (!t.isExpression(innerInputExpression)) {
345
+ throw new Error(
346
+ `createIsomorphicFn().${opts.env}(func) must be called with a function!`
347
+ );
348
+ }
349
+ rootCallExpression.replaceWith(innerInputExpression);
350
+ }
351
+ function getRootCallExpression(path) {
352
+ let rootCallExpression = path;
353
+ while (rootCallExpression.parentPath.isMemberExpression()) {
354
+ const parent = rootCallExpression.parentPath;
355
+ if (parent.parentPath.isCallExpression()) {
356
+ rootCallExpression = parent.parentPath;
357
+ }
358
+ }
359
+ return rootCallExpression;
360
+ }
361
+ function codeFrameError(code, loc, message) {
362
+ const frame = codeFrameColumns(
363
+ code,
364
+ {
365
+ start: loc.start,
366
+ end: loc.end
367
+ },
368
+ {
369
+ highlightCode: true,
370
+ message
371
+ }
372
+ );
373
+ return new Error(frame);
374
+ }
375
+ export {
376
+ compileStartOutputFactory,
377
+ getRootCallExpression,
378
+ handleClientOnlyCallExpression,
379
+ handleCreateIsomorphicFnCallExpression,
380
+ handleCreateMiddlewareCallExpression,
381
+ handleCreateServerFnCallExpression,
382
+ handleServerOnlyCallExpression
383
+ };
384
+ //# sourceMappingURL=compilers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compilers.js","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 createServerFileRoute: IdentifierConfig\n createServerFn: IdentifierConfig\n createMiddleware: IdentifierConfig\n serverOnly: IdentifierConfig\n clientOnly: IdentifierConfig\n createIsomorphicFn: IdentifierConfig\n } = {\n createServerFileRoute: {\n name: 'createServerFileRoute',\n handleCallExpression:\n handleCreateServerFileRouteCallExpressionFactory(framework),\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 (\n path.node.source.value !== '@tanstack/react-start' &&\n path.node.source.value !== '@tanstack/solid-start'\n ) {\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) {\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 // // Find the root call expression and all of the methods that are called on it\n // const rootCallExpression = getRootCallExpression(path)\n\n // const callExpressionPaths = {\n // validator: null as babel.NodePath<t.CallExpression> | null,\n // middleware: null as babel.NodePath<t.CallExpression> | null,\n // methods: 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 // const manifest = { middleware: false, methods: {} as any }\n\n // Object.entries(callExpressionPaths).forEach(([key, callPath]) => {\n // if (callPath && t.isMemberExpression(callPath.node.callee)) {\n // if (key === 'middleware') {\n // manifest.middleware = true\n // } else if (key === 'methods') {\n // // Get the methods object from the methods call\n // const methodsArg = callPath.node.arguments[0]\n\n // // Handle the case where methods is a function that returns an object\n // if (\n // t.isArrowFunctionExpression(methodsArg) &&\n // t.isObjectExpression(methodsArg.body)\n // ) {\n // methodsArg.body.properties.forEach((prop) => {\n // if (t.isObjectProperty(prop) && t.isIdentifier(prop.key)) {\n // const methodName = prop.key.name\n // manifest.methods[methodName] = {\n // middleware: false,\n // }\n\n // // Check if this method has a middleware\n // if (t.isCallExpression(prop.value)) {\n // const method = prop.value\n // method.arguments.forEach((arg) => {\n // if (t.isObjectExpression(arg)) {\n // arg.properties.forEach((methodProp) => {\n // if (\n // t.isObjectProperty(methodProp) &&\n // t.isIdentifier(methodProp.key)\n // ) {\n // if (methodProp.key.name === 'middleware') {\n // manifest.methods[methodName].middleware = true\n // }\n // }\n // })\n // }\n // })\n // }\n // }\n // })\n // }\n // // Handle the case where methods is a direct object\n // else if (t.isObjectExpression(methodsArg)) {\n // methodsArg.properties.forEach((prop) => {\n // if (t.isObjectProperty(prop) && t.isIdentifier(prop.key)) {\n // const methodName = prop.key.name\n // manifest.methods[methodName] = {\n // middleware: false,\n // }\n // }\n // })\n // }\n // }\n\n // if (opts.env === 'client') {\n // callPath.replaceWith(callPath.node.callee.object)\n // }\n // }\n // })\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 // path.replaceWith(\n // t.callExpression(t.identifier('createServerFileRoute'), [\n // t.identifier('undefined'),\n // t.callExpression(\n // t.memberExpression(t.identifier('Object'), t.identifier('assign')),\n // [\n // t.objectExpression(\n // path.node.arguments\n // .map((arg) => {\n // if (t.isIdentifier(arg)) {\n // return t.objectProperty(t.identifier(arg.name), arg)\n // }\n // // Handle other cases or return a default value if necessary\n // return null // or throw an error, or handle accordingly\n // })\n // .filter(\n // (property): property is t.ObjectProperty => property !== null,\n // ),\n // ),\n // t.objectExpression([\n // t.objectProperty(\n // t.identifier('manifest'),\n // t.valueToNode(manifest),\n // ),\n // ]),\n // ],\n // ),\n // ]),\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 === 'createServerFileRoute'\n )\n })\n }\n },\n })\n\n if (!isCreateServerFileRouteImported) {\n const importDeclaration = t.importDeclaration(\n [\n t.importSpecifier(\n t.identifier('createServerFileRoute'),\n t.identifier('createServerFileRoute'),\n ),\n ],\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":[],"mappings":";;;;;AAaO,SAAS,0BACd,WACA;AACO,SAAA,SAAS,mBAAmB,MAAuC;AAClE,UAAA,MAAM,SAAS,IAAI;AAEnB,UAAA,QAAQ,KAAK,OAAO;AAE1B,UAAM,YAAY,QAAQ,0BAA0B,GAAG,IAAI;AAE3D,UAAM,SAAS,KAAK;AAAA,MAClB,SAAS;AAAA,QACP,MAAM,aAAa;AACjB,gBAAM,cAOF;AAAA,YACF,uBAAuB;AAAA,cACrB,MAAM;AAAA,cACN,sBACE,iDAAiD,SAAS;AAAA,cAC5D,OAAO,CAAA;AAAA,YACT;AAAA,YACA,gBAAgB;AAAA,cACd,MAAM;AAAA,cACN,sBAAsB;AAAA,cACtB,OAAO,CAAA;AAAA,YACT;AAAA,YACA,kBAAkB;AAAA,cAChB,MAAM;AAAA,cACN,sBAAsB;AAAA,cACtB,OAAO,CAAA;AAAA,YACT;AAAA,YACA,YAAY;AAAA,cACV,MAAM;AAAA,cACN,sBAAsB;AAAA,cACtB,OAAO,CAAA;AAAA,YACT;AAAA,YACA,YAAY;AAAA,cACV,MAAM;AAAA,cACN,sBAAsB;AAAA,cACtB,OAAO,CAAA;AAAA,YACT;AAAA,YACA,oBAAoB;AAAA,cAClB,MAAM;AAAA,cACN,sBAAsB;AAAA,cACtB,OAAO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AAW,qBAAA,IAC7C,mBAAmB,WAAW,KAAK,KACnC;AACI,YAAA;AAAA,MACN;AAAA,MACA;AAAA,MACA;AAAA,MACA,EAAE,aAAa,UAAU,IAAI,WAAW,OAAO;AAAA,IACjD;AAAA,EAAA;AAGI,QAAA,oBAAoB,oBAAoB,KAAK,GAAG;AAEtD,MAAI,CAAC,mBAAmB;AAEH,uBAAA;AAAA,MACjB,EAAE,wBAAwB,CAAA,GAAI,EAAE,eAAe,CAAA,CAAE,CAAC;AAAA,IACpD;AACA;AAAA,EAAA;AAGF,QAAM,uBAAuB,kBAAkB,KAAK,UAAU,CAAC;AAE/D,MAAI,CAAC,EAAE,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,QAAQ;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;"}
@@ -0,0 +1,4 @@
1
+ export declare function extractHtmlScripts(html: string): Array<{
2
+ content?: string;
3
+ src?: string;
4
+ }>;
@@ -0,0 +1,18 @@
1
+ import * as cheerio from "cheerio";
2
+ function extractHtmlScripts(html) {
3
+ const $ = cheerio.load(html);
4
+ const scripts = [];
5
+ $("script").each((_, element) => {
6
+ const src = $(element).attr("src");
7
+ const content = $(element).html() ?? void 0;
8
+ scripts.push({
9
+ src,
10
+ content
11
+ });
12
+ });
13
+ return scripts;
14
+ }
15
+ export {
16
+ extractHtmlScripts
17
+ };
18
+ //# sourceMappingURL=extractHtmlScripts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractHtmlScripts.js","sources":["../../src/extractHtmlScripts.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":[],"mappings":";AAEO,SAAS,mBACd,MAC2C;AACrC,QAAA,IAAI,QAAQ,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;"}
@@ -0,0 +1,7 @@
1
+ export type { CompileOptions, IdentifierConfig } from './compilers.js';
2
+ export { compileStartOutputFactory } from './compilers.js';
3
+ export type { PagesJson } from './nitro/build-sitemap.js';
4
+ export { buildSitemap } from './nitro/build-sitemap.js';
5
+ export { createTanStackConfig, createTanStackStartOptionsSchema, pageSchema, } from './schema.js';
6
+ export { TanStackStartVitePluginCore } from './plugin.js';
7
+ export { TanStackStartServerRoutesVite } from './start-server-routes-plugin/plugin.js';
@@ -0,0 +1,15 @@
1
+ import { compileStartOutputFactory } from "./compilers.js";
2
+ import { buildSitemap } from "./nitro/build-sitemap.js";
3
+ import { createTanStackConfig, createTanStackStartOptionsSchema, pageSchema } from "./schema.js";
4
+ import { TanStackStartVitePluginCore } from "./plugin.js";
5
+ import { TanStackStartServerRoutesVite } from "./start-server-routes-plugin/plugin.js";
6
+ export {
7
+ TanStackStartServerRoutesVite,
8
+ TanStackStartVitePluginCore,
9
+ buildSitemap,
10
+ compileStartOutputFactory,
11
+ createTanStackConfig,
12
+ createTanStackStartOptionsSchema,
13
+ pageSchema
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;"}
@@ -0,0 +1,2 @@
1
+ import { Nitro } from 'nitropack';
2
+ export declare function buildNitroEnvironment(nitro: Nitro, build: () => Promise<any>): Promise<void>;
@@ -0,0 +1,18 @@
1
+ import { promises } from "node:fs";
2
+ import path from "node:path";
3
+ import { prepare, copyPublicAssets } from "nitropack";
4
+ async function buildNitroEnvironment(nitro, build) {
5
+ await prepare(nitro);
6
+ await copyPublicAssets(nitro);
7
+ await build();
8
+ const publicDir = nitro.options.output.publicDir;
9
+ const viteDir = path.resolve(publicDir, ".vite");
10
+ if (await promises.stat(viteDir).catch(() => false)) {
11
+ await promises.rm(viteDir, { recursive: true, force: true });
12
+ }
13
+ await nitro.close();
14
+ }
15
+ export {
16
+ buildNitroEnvironment
17
+ };
18
+ //# sourceMappingURL=build-nitro.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-nitro.js","sources":["../../../src/nitro/build-nitro.ts"],"sourcesContent":["import { promises as fsp } from 'node:fs'\nimport path from 'node:path'\nimport { copyPublicAssets, prepare } from 'nitropack'\nimport type { Nitro } from 'nitropack'\n\nexport async function buildNitroEnvironment(\n nitro: Nitro,\n build: () => Promise<any>,\n) {\n await prepare(nitro)\n await copyPublicAssets(nitro)\n await build()\n\n const publicDir = nitro.options.output.publicDir\n\n // As a part of the build process, the `.vite/` directory\n // is copied over from `.tanstack-start/build/client-dist/`\n // to the `publicDir` (e.g. `.output/public/`).\n // This directory (containing the vite manifest) should not be\n // included in the final build, so we remove it here.\n const viteDir = path.resolve(publicDir, '.vite')\n if (await fsp.stat(viteDir).catch(() => false)) {\n await fsp.rm(viteDir, { recursive: true, force: true })\n }\n\n await nitro.close()\n}\n"],"names":["fsp"],"mappings":";;;AAKsB,eAAA,sBACpB,OACA,OACA;AACA,QAAM,QAAQ,KAAK;AACnB,QAAM,iBAAiB,KAAK;AAC5B,QAAM,MAAM;AAEN,QAAA,YAAY,MAAM,QAAQ,OAAO;AAOvC,QAAM,UAAU,KAAK,QAAQ,WAAW,OAAO;AAC3C,MAAA,MAAMA,SAAI,KAAK,OAAO,EAAE,MAAM,MAAM,KAAK,GAAG;AACxC,UAAAA,SAAI,GAAG,SAAS,EAAE,WAAW,MAAM,OAAO,MAAM;AAAA,EAAA;AAGxD,QAAM,MAAM,MAAM;AACpB;"}
@@ -0,0 +1,9 @@
1
+ export type PagesJson = {
2
+ page: string;
3
+ lastMod: string;
4
+ };
5
+ export declare function buildSitemap({ host, routes, outputDir, }: {
6
+ host: string;
7
+ routes: Array<string | undefined> | (() => Promise<Array<string | undefined>>);
8
+ outputDir: string;
9
+ }): Promise<void>;
@@ -0,0 +1,54 @@
1
+ import { writeFileSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { create } from "xmlbuilder2";
4
+ async function buildSitemap({
5
+ host,
6
+ routes,
7
+ outputDir
8
+ }) {
9
+ const routeList = await optionHasRoutes(routes);
10
+ if (routeList.length) {
11
+ const slash = checkSlash(host);
12
+ const sitemapData = routeList.map((page) => ({
13
+ page: `${host}${slash}${page.replace(/^\/+/g, "")}`,
14
+ lastMod: (/* @__PURE__ */ new Date()).toISOString().split("T")[0]
15
+ }));
16
+ const sitemap = createXml("urlset");
17
+ for (const item of sitemapData) {
18
+ const page = sitemap.ele("url");
19
+ page.ele("loc").txt(item.page);
20
+ page.ele("lastmod").txt(item.lastMod);
21
+ }
22
+ const mapPath = `${resolve(outputDir)}/sitemap.xml`;
23
+ try {
24
+ console.log(`Writing sitemap at ${mapPath}`);
25
+ writeFileSync(mapPath, sitemap.end({ prettyPrint: true }));
26
+ } catch (e) {
27
+ console.error(`Unable to write file at ${mapPath}`, e);
28
+ }
29
+ }
30
+ }
31
+ function createXml(elementName) {
32
+ return create({ version: "1.0", encoding: "UTF-8" }).ele(elementName, {
33
+ xmlns: "https://www.sitemaps.org/schemas/sitemap/0.9"
34
+ }).com(`This file was automatically generated by Analog.`);
35
+ }
36
+ function checkSlash(host) {
37
+ const finalChar = host.slice(-1);
38
+ return finalChar === "/" ? "" : "/";
39
+ }
40
+ async function optionHasRoutes(routes) {
41
+ let routeList;
42
+ if (typeof routes === "function") {
43
+ routeList = await routes();
44
+ } else if (Array.isArray(routes)) {
45
+ routeList = routes;
46
+ } else {
47
+ routeList = [];
48
+ }
49
+ return routeList.filter(Boolean);
50
+ }
51
+ export {
52
+ buildSitemap
53
+ };
54
+ //# sourceMappingURL=build-sitemap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"build-sitemap.js","sources":["../../../src/nitro/build-sitemap.ts"],"sourcesContent":["import { writeFileSync } from 'node:fs'\nimport { resolve } from 'node:path'\nimport { create } from 'xmlbuilder2'\nimport type { XMLBuilder } from 'xmlbuilder2/lib/interfaces'\n\nexport type PagesJson = {\n page: string\n lastMod: string\n}\n\nexport async function buildSitemap({\n host,\n routes,\n outputDir,\n}: {\n host: string\n routes: Array<string | undefined> | (() => Promise<Array<string | undefined>>)\n outputDir: string\n}) {\n const routeList: Array<string> = await optionHasRoutes(routes)\n\n if (routeList.length) {\n const slash = checkSlash(host)\n const sitemapData: Array<PagesJson> = routeList.map((page: string) => ({\n page: `${host}${slash}${page.replace(/^\\/+/g, '')}`,\n lastMod: new Date().toISOString().split('T')[0]!,\n }))\n\n const sitemap = createXml('urlset')\n\n for (const item of sitemapData) {\n const page = sitemap.ele('url')\n page.ele('loc').txt(item.page)\n page.ele('lastmod').txt(item.lastMod)\n }\n\n const mapPath = `${resolve(outputDir)}/sitemap.xml`\n try {\n console.log(`Writing sitemap at ${mapPath}`)\n writeFileSync(mapPath, sitemap.end({ prettyPrint: true }))\n } catch (e) {\n console.error(`Unable to write file at ${mapPath}`, e)\n }\n }\n}\n\nfunction createXml(elementName: 'urlset' | 'sitemapindex'): XMLBuilder {\n return create({ version: '1.0', encoding: 'UTF-8' })\n .ele(elementName, {\n xmlns: 'https://www.sitemaps.org/schemas/sitemap/0.9',\n })\n .com(`This file was automatically generated by Analog.`)\n}\n\nfunction checkSlash(host: string): string {\n const finalChar = host.slice(-1)\n return finalChar === '/' ? '' : '/'\n}\n\nasync function optionHasRoutes(\n routes:\n | Array<string | undefined>\n | (() => Promise<Array<string | undefined>>),\n): Promise<Array<string>> {\n let routeList: Array<string | undefined>\n\n if (typeof routes === 'function') {\n // returns an array or undefined\n routeList = await routes()\n } else if (Array.isArray(routes)) {\n // returns an array of strings\n routeList = routes\n } else {\n // default it to an empty of array\n routeList = []\n }\n\n return routeList.filter(Boolean) as Array<string>\n}\n"],"names":[],"mappings":";;;AAUA,eAAsB,aAAa;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AACF,GAIG;AACK,QAAA,YAA2B,MAAM,gBAAgB,MAAM;AAE7D,MAAI,UAAU,QAAQ;AACd,UAAA,QAAQ,WAAW,IAAI;AAC7B,UAAM,cAAgC,UAAU,IAAI,CAAC,UAAkB;AAAA,MACrE,MAAM,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,QAAQ,SAAS,EAAE,CAAC;AAAA,MACjD,8BAAa,KAAK,GAAE,cAAc,MAAM,GAAG,EAAE,CAAC;AAAA,IAAA,EAC9C;AAEI,UAAA,UAAU,UAAU,QAAQ;AAElC,eAAW,QAAQ,aAAa;AACxB,YAAA,OAAO,QAAQ,IAAI,KAAK;AAC9B,WAAK,IAAI,KAAK,EAAE,IAAI,KAAK,IAAI;AAC7B,WAAK,IAAI,SAAS,EAAE,IAAI,KAAK,OAAO;AAAA,IAAA;AAGtC,UAAM,UAAU,GAAG,QAAQ,SAAS,CAAC;AACjC,QA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