@analogjs/vite-plugin-nitro 2.7.2-beta.2 → 2.7.2-beta.4
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.
package/package.json
CHANGED
|
@@ -19,7 +19,8 @@ export type ServerFnHandlerModule = {
|
|
|
19
19
|
*
|
|
20
20
|
* Scope is `<projectRoot>/<sourceRoot>/**\/*.server.ts` because the RFC allows a
|
|
21
21
|
* server function to live in any `.server.ts` module, including existing page
|
|
22
|
-
* server files.
|
|
22
|
+
* server files. Only modules defining a server function that the client
|
|
23
|
+
* transform can rewrite participate.
|
|
23
24
|
* Angular SSR config (`app.config.server.ts`) is excluded — it is not a route or
|
|
24
25
|
* function module and must not be pulled into the dispatch bundle.
|
|
25
26
|
*
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { parseSync } from 'oxc-parser';
|
|
1
3
|
import { resolve } from 'node:path';
|
|
2
4
|
import { globSync } from 'tinyglobby';
|
|
3
5
|
import { normalizePath } from 'vite';
|
|
@@ -22,7 +24,8 @@ const EXCLUDED_SERVER_FILES = [/\/app\.config\.server\.ts$/];
|
|
|
22
24
|
*
|
|
23
25
|
* Scope is `<projectRoot>/<sourceRoot>/**\/*.server.ts` because the RFC allows a
|
|
24
26
|
* server function to live in any `.server.ts` module, including existing page
|
|
25
|
-
* server files.
|
|
27
|
+
* server files. Only modules defining a server function that the client
|
|
28
|
+
* transform can rewrite participate.
|
|
26
29
|
* Angular SSR config (`app.config.server.ts`) is excluded — it is not a route or
|
|
27
30
|
* function module and must not be pulled into the dispatch bundle.
|
|
28
31
|
*
|
|
@@ -42,6 +45,42 @@ export function getServerFnHandlers({ workspaceRoot, sourceRoot, rootDir, additi
|
|
|
42
45
|
file.slice(sourceRootDir.length).includes('/'))
|
|
43
46
|
.filter((file) => (seen.has(file) ? false : (seen.add(file), true)))
|
|
44
47
|
.sort()
|
|
48
|
+
.filter(definesServerFn)
|
|
45
49
|
.map((file) => ({ file }));
|
|
46
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Match the client scrub's supported server-function declaration shape. The
|
|
53
|
+
* scrub deliberately falls back to the conventional `serverFn` name when the
|
|
54
|
+
* function is re-exported through a local barrel, so discovery must make the
|
|
55
|
+
* same choice or the browser receives a proxy without a dispatch route.
|
|
56
|
+
*/
|
|
57
|
+
function definesServerFn(file) {
|
|
58
|
+
const code = readFileSync(file, 'utf8');
|
|
59
|
+
if (!code.includes('serverFn'))
|
|
60
|
+
return false;
|
|
61
|
+
const { program } = parseSync(file, code);
|
|
62
|
+
const localNames = new Set();
|
|
63
|
+
for (const node of program.body) {
|
|
64
|
+
if (node.type !== 'ImportDeclaration' ||
|
|
65
|
+
node.source.value !== '@analogjs/router/server') {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
for (const specifier of node.specifiers) {
|
|
69
|
+
if (specifier.type === 'ImportSpecifier' &&
|
|
70
|
+
(specifier.imported.type === 'Identifier'
|
|
71
|
+
? specifier.imported.name
|
|
72
|
+
: specifier.imported.value) === 'serverFn') {
|
|
73
|
+
localNames.add(specifier.local.name);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
if (localNames.size === 0)
|
|
78
|
+
localNames.add('serverFn');
|
|
79
|
+
return program.body.some((node) => node.type === 'ExportNamedDeclaration' &&
|
|
80
|
+
node.declaration?.type === 'VariableDeclaration' &&
|
|
81
|
+
node.declaration.declarations.some((declarator) => declarator.id?.type === 'Identifier' &&
|
|
82
|
+
declarator.init?.type === 'CallExpression' &&
|
|
83
|
+
declarator.init.callee?.type === 'Identifier' &&
|
|
84
|
+
localNames.has(declarator.init.callee.name)));
|
|
85
|
+
}
|
|
47
86
|
//# sourceMappingURL=get-server-fn-handlers.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-server-fn-handlers.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-nitro/src/lib/utils/get-server-fn-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAcrC;;;;;;;;GAQG;AACH,MAAM,qBAAqB,GAAa,CAAC,4BAA4B,CAAC,CAAC;AAEvE
|
|
1
|
+
{"version":3,"file":"get-server-fn-handlers.js","sourceRoot":"","sources":["../../../../../../packages/vite-plugin-nitro/src/lib/utils/get-server-fn-handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAcrC;;;;;;;;GAQG;AACH,MAAM,qBAAqB,GAAa,CAAC,4BAA4B,CAAC,CAAC;AAEvE;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,mBAAmB,CAAC,EAClC,aAAa,EACb,UAAU,EACV,OAAO,EACP,sBAAsB,GACE;IACxB,MAAM,IAAI,GAAG,aAAa,CAAC,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC,CAAC;IAE5D,MAAM,KAAK,GAAG,QAAQ,CACpB;QACE,GAAG,IAAI,IAAI,UAAU,iBAAiB;QACtC,GAAG,CAAC,sBAAsB,IAAI,EAAE,CAAC,CAAC,GAAG,CACnC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,aAAa,GAAG,GAAG,iBAAiB,CACjD;KACF,EACD,EAAE,GAAG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAC9B,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,a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