xanix 1.0.19 → 1.0.21
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/dist/bin/bundler/cache/buildCache.js +9 -11
- package/dist/bin/bundler/cache/index.js +70 -116
- package/dist/bin/bundler/cache/utils.d.ts +3 -2
- package/dist/bin/bundler/cache/utils.js +27 -24
- package/dist/bin/bundler/client/build.js +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction copy.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction copy.js +32 -0
- package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformCacheFunction.js +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformCreateSession.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformCreateSession.js +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformDevModule.d.ts +13 -0
- package/dist/bin/bundler/client/plugins/Transformer/{transformModuleCache.js → TransformDevModule.js} +6 -18
- package/dist/bin/bundler/client/plugins/Transformer/TransformServerFunction.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/TransformServerFunction.js +1 -1
- package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionReplacer.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionReplacer.js +32 -0
- package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionTransformer.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/cacheFunctionTransformer.js +32 -0
- package/dist/bin/bundler/client/plugins/Transformer/serverFunctionReplacer.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/serverFunctionReplacer.js +32 -0
- package/dist/bin/bundler/client/plugins/Transformer/useServerReplacer.d.ts +3 -0
- package/dist/bin/bundler/client/plugins/Transformer/useServerReplacer.js +42 -0
- package/dist/bin/bundler/client/plugins/Transformer.js +4 -2
- package/dist/bin/bundler/client/plugins/XanixAppRoot.d.ts +2 -0
- package/dist/bin/bundler/client/plugins/XanixAppRoot.js +46 -0
- package/dist/bin/bundler/client/plugins/XanixPage.js +30 -0
- package/dist/bin/bundler/client/plugins/XanixPages.js +8 -8
- package/dist/bin/bundler/client/plugins/replacer/cacheFunctionReplacer.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/replacer/cacheFunctionReplacer.js +5 -1
- package/dist/bin/bundler/client/plugins/replacer/serverFunctionReplacer.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/replacer/serverFunctionReplacer.js +5 -1
- package/dist/bin/bundler/client/plugins/replacer/useServerReplacer.d.ts +1 -1
- package/dist/bin/bundler/client/plugins/replacer/useServerReplacer.js +7 -3
- package/dist/bin/bundler/server/build.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction copy.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction copy.js +32 -0
- package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformCacheFunction.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformCreateSession.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformCreateSession.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpressFunction.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpressFunction.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformPage.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformServerFunction.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/TransformServerFunction.js +1 -1
- package/dist/bin/bundler/server/plugins/Transformer/cacheFunctionReplacer.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/cacheFunctionReplacer.js +32 -0
- package/dist/bin/bundler/server/plugins/Transformer/expressFunctionReplace.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/expressFunctionReplace.js +24 -0
- package/dist/bin/bundler/server/plugins/Transformer/pageReplacer.d.ts +4 -0
- package/dist/bin/bundler/server/plugins/Transformer/pageReplacer.js +31 -0
- package/dist/bin/bundler/server/plugins/Transformer/serverFunctionReplacer.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/serverFunctionReplacer.js +32 -0
- package/dist/bin/bundler/server/plugins/Transformer/useServerReplacer.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/Transformer/useServerReplacer.js +42 -0
- package/dist/bin/bundler/server/plugins/Transformer copy.js +3 -3
- package/dist/bin/bundler/server/plugins/Transformer.js +2 -2
- package/dist/bin/bundler/server/plugins/replacer/cacheFunctionReplacer.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/replacer/cacheFunctionReplacer.js +5 -1
- package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer copy.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer copy.js +26 -0
- package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer.d.ts +1 -1
- package/dist/bin/bundler/server/plugins/replacer/serverFunctionReplacer.js +5 -1
- package/dist/bin/bundler/server/plugins/replacer/serverReplacer.d.ts +3 -0
- package/dist/bin/bundler/server/plugins/replacer/serverReplacer.js +26 -0
- package/dist/bin/bundler/server/plugins/replacer/useServerReplacer.d.ts +2 -2
- package/dist/bin/bundler/server/plugins/replacer/useServerReplacer.js +9 -5
- package/dist/bin/cli/dev.js +85 -71
- package/dist/bin/cli/start/index.d.ts +4 -1
- package/dist/bin/cli/start/index.js +60 -9
- package/dist/bin/finder/callbackReplacer.d.ts +2 -0
- package/dist/bin/finder/callbackReplacer.js +52 -0
- package/dist/bin/finder/findImport.d.ts +9 -0
- package/dist/bin/finder/findImport.js +50 -0
- package/dist/bin/finder/findImports.d.ts +16 -0
- package/dist/bin/finder/findImports.js +45 -0
- package/dist/bin/finder/findPage.d.ts +9 -0
- package/dist/bin/finder/findPage.js +30 -0
- package/dist/bin/finder/importFinder.d.ts +9 -0
- package/dist/bin/finder/importFinder.js +50 -0
- package/dist/bin/finder/pageFinder.d.ts +9 -0
- package/dist/bin/finder/pageFinder.js +30 -0
- package/dist/bin/finder/stripComments.d.ts +3 -0
- package/dist/bin/finder/stripComments.js +15 -0
- package/dist/bin/include/path.d.ts +5 -1
- package/dist/bin/include/path.js +15 -1
- package/dist/bin/include/sendFinder.d.ts +4 -1
- package/dist/bin/include/sendFinder.js +88 -53
- package/dist/bin/index.js +0 -0
- package/dist/bin/modifier/callbackReplacer.js +35 -80
- package/dist/bin/modifier/findImports.d.ts +16 -0
- package/dist/bin/modifier/findImports.js +45 -0
- package/dist/bin/modifier/importFinder.js +44 -63
- package/dist/bin/modifier/pageFinder.d.ts +1 -1
- package/dist/bin/modifier/pageFinder.js +19 -124
- package/dist/bin/modifier/sendFinder.d.ts +9 -0
- package/dist/bin/modifier/sendFinder.js +135 -0
- package/dist/bin/modifier/sriptCommnet.d.ts +1 -0
- package/dist/bin/modifier/sriptCommnet.js +12 -5
- package/dist/bin/modifier/stripComments.d.ts +3 -0
- package/dist/bin/modifier/stripComments.js +15 -0
- package/dist/bin/plugins/XanixAssets.js +2 -2
- package/dist/bin/plugins/XanixCss.js +13 -13
- package/dist/bin/plugins/XanixDocument.js +4 -4
- package/dist/components/Head.js +1 -1
- package/dist/hooks/encript.d.ts +2 -0
- package/dist/hooks/encript.js +13 -0
- package/dist/hooks/server.js +2 -2
- package/dist/hooks/session.js +2 -2
- package/dist/index.js +0 -0
- package/dist/libs/encoder.d.ts +2 -0
- package/dist/libs/encoder.js +13 -0
- package/dist/libs/encript.d.ts +2 -0
- package/dist/libs/encript.js +30 -0
- package/dist/navigate.js +1 -1
- package/dist/server/express/Router.js +4 -4
- package/dist/server/express/page.d.ts +1 -1
- package/dist/server/express/page.js +1 -1
- package/dist/types/assets.d.ts +72 -72
- package/dist/types/express.d.ts +11 -11
- package/dist/types/globals.d.ts +18 -18
- package/dist/types/xanix-virtual.d.ts +35 -35
- package/package.json +57 -60
- package/dist/bin/bundler/Cache.d.ts +0 -1
- package/dist/bin/bundler/Cache.js +0 -210
- package/dist/bin/bundler/External.d.ts +0 -3
- package/dist/bin/bundler/External.js +0 -6
- package/dist/bin/bundler/buildClient.d.ts +0 -3
- package/dist/bin/bundler/buildClient.js +0 -42
- package/dist/bin/bundler/buildServer.d.ts +0 -7
- package/dist/bin/bundler/buildServer.js +0 -50
- package/dist/bin/bundler/cache/plugin/Transformer.d.ts +0 -3
- package/dist/bin/bundler/cache/plugin/Transformer.js +0 -42
- package/dist/bin/bundler/client/plugins/Transformer/TransformExpress.d.ts +0 -9
- package/dist/bin/bundler/client/plugins/Transformer/TransformExpress.js +0 -26
- package/dist/bin/bundler/client/plugins/Transformer/TransformPage.d.ts +0 -29
- package/dist/bin/bundler/client/plugins/Transformer/TransformPage.js +0 -77
- package/dist/bin/bundler/client/plugins/Transformer/TransformReactContext.d.ts +0 -17
- package/dist/bin/bundler/client/plugins/Transformer/TransformReactContext.js +0 -101
- package/dist/bin/bundler/client/plugins/Transformer/transformModuleCache.d.ts +0 -15
- package/dist/bin/bundler/client/plugins/Transformer copy.d.ts +0 -3
- package/dist/bin/bundler/client/plugins/Transformer copy.js +0 -70
- package/dist/bin/bundler/client/plugins/VirtualDev.d.ts +0 -2
- package/dist/bin/bundler/client/plugins/VirtualDev.js +0 -34
- package/dist/bin/bundler/client/plugins/XanixReactRefresh.d.ts +0 -2
- package/dist/bin/bundler/client/plugins/XanixReactRefresh.js +0 -22
- package/dist/bin/bundler/config/defines.d.ts +0 -20
- package/dist/bin/bundler/config/defines.js +0 -21
- package/dist/bin/bundler/config/external.d.ts +0 -1
- package/dist/bin/bundler/config/external.js +0 -12
- package/dist/bin/bundler/config/loadEnv.d.ts +0 -20
- package/dist/bin/bundler/config/loadEnv.js +0 -48
- package/dist/bin/bundler/config/output.d.ts +0 -10
- package/dist/bin/bundler/config/output.js +0 -52
- package/dist/bin/bundler/externalResolver-dep.d.ts +0 -3
- package/dist/bin/bundler/externalResolver-dep.js +0 -203
- package/dist/bin/bundler/externalResolver.d.ts +0 -3
- package/dist/bin/bundler/externalResolver.js +0 -203
- package/dist/bin/bundler/plugins/TransformServer/TransformExpress.d.ts +0 -9
- package/dist/bin/bundler/plugins/TransformServer/TransformExpress.js +0 -26
- package/dist/bin/bundler/plugins/TransformServer/TransformPage.d.ts +0 -25
- package/dist/bin/bundler/plugins/TransformServer/TransformPage.js +0 -79
- package/dist/bin/bundler/plugins/TransformServer/index.d.ts +0 -3
- package/dist/bin/bundler/plugins/TransformServer/index.js +0 -103
- package/dist/bin/bundler/plugins/XanixAssets.d.ts +0 -5
- package/dist/bin/bundler/plugins/XanixAssets.js +0 -51
- package/dist/bin/bundler/plugins/XanixCacheDeps-dep.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixCacheDeps-dep.js +0 -150
- package/dist/bin/bundler/plugins/XanixCacheDeps.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixCacheDeps.js +0 -150
- package/dist/bin/bundler/plugins/XanixDocument/index.js +0 -53
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.js +0 -149
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.d.ts +0 -6
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.js +0 -37
- package/dist/bin/bundler/plugins/XanixEntryFinder-dep/finder.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixEntryFinder-dep/finder.js +0 -149
- package/dist/bin/bundler/plugins/XanixEntryFinder-dep/index.d.ts +0 -6
- package/dist/bin/bundler/plugins/XanixEntryFinder-dep/index.js +0 -37
- package/dist/bin/bundler/plugins/XanixEnv.d.ts +0 -15
- package/dist/bin/bundler/plugins/XanixEnv.js +0 -44
- package/dist/bin/bundler/plugins/XanixPageTransform/index.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixPageTransform/index.js +0 -62
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer copy.d.ts +0 -18
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer copy.js +0 -414
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer.d.ts +0 -23
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer.js +0 -589
- package/dist/bin/bundler/plugins/XanixReactRefresh copy.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixReactRefresh copy.js +0 -121
- package/dist/bin/bundler/plugins/XanixReactRefresh.d.ts +0 -2
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +0 -170
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/BuildClientCache.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/BuildClientCache.js +0 -129
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index copy.d.ts +0 -15
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index copy.js +0 -228
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.d.ts +0 -7
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +0 -166
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/BuildClientCache.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/BuildClientCache.js +0 -129
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/index.d.ts +0 -5
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps-dep/index.js +0 -26
- package/dist/bin/bundler/plugins/XanixResolver.d.ts +0 -11
- package/dist/bin/bundler/plugins/XanixResolver.js +0 -55
- package/dist/bin/bundler/plugins/XanixServerTransform.d.ts +0 -5
- package/dist/bin/bundler/plugins/XanixServerTransform.js +0 -207
- package/dist/bin/bundler/plugins/XanixTransform.d.ts +0 -3
- package/dist/bin/bundler/plugins/XanixTransform.js +0 -23
- package/dist/bin/bundler/plugins/XanixTsconfigAlias.d.ts +0 -19
- package/dist/bin/bundler/plugins/XanixTsconfigAlias.js +0 -197
- package/dist/bin/bundler/plugins/XanixUseServer.d.ts +0 -7
- package/dist/bin/bundler/plugins/XanixUseServer.js +0 -445
- package/dist/bin/bundler/plugins/plugins.d.ts +0 -9
- package/dist/bin/bundler/plugins/plugins.js +0 -37
- package/dist/bin/bundler/requireCache.d.ts +0 -3
- package/dist/bin/bundler/requireCache.js +0 -85
- package/dist/bin/bundler/server/plugins/ServerAction.d.ts +0 -3
- package/dist/bin/bundler/server/plugins/ServerAction.js +0 -9
- package/dist/bin/bundler/server/plugins/Transformer/ServerAction.d.ts +0 -11
- package/dist/bin/bundler/server/plugins/Transformer/ServerAction.js +0 -28
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpress copy.d.ts +0 -11
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpress copy.js +0 -22
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpress.d.ts +0 -10
- package/dist/bin/bundler/server/plugins/Transformer/TransformExpress.js +0 -19
- package/dist/bin/bundler/server/plugins/Transformer/TransformReactContext.d.ts +0 -17
- package/dist/bin/bundler/server/plugins/Transformer/TransformReactContext.js +0 -101
- package/dist/bin/bundler/server/plugins/Transformer/TransformServerAction copy.d.ts +0 -14
- package/dist/bin/bundler/server/plugins/Transformer/TransformServerAction copy.js +0 -38
- package/dist/bin/bundler/server/types.d.ts +0 -5
- package/dist/bin/bundler/server/types.js +0 -1
- package/dist/bin/bundler/watchClient.d.ts +0 -12
- package/dist/bin/bundler/watchClient.js +0 -104
- package/dist/bin/bundler/watchServer.d.ts +0 -10
- package/dist/bin/bundler/watchServer.js +0 -139
- package/dist/bin/cli/dev/dev.d.ts +0 -2
- package/dist/bin/cli/dev/dev.js +0 -178
- package/dist/bin/cli/start/start.d.ts +0 -2
- package/dist/bin/cli/start/start.js +0 -27
- package/dist/bin/include/entry.d.ts +0 -2
- package/dist/bin/include/entry.js +0 -21
- package/dist/bin/plugins/XanixDocument/XanixDocument.d.ts +0 -2
- package/dist/bin/plugins/XanixDocument/XanixDocument.js +0 -50
- package/dist/bin/plugins/XanixDocument/index.d.ts +0 -2
- package/dist/bin/plugins/XanixDocument/index.js +0 -50
- package/dist/bin/plugins/XanixPageTransform-dep/index.d.ts +0 -2
- package/dist/bin/plugins/XanixPageTransform-dep/index.js +0 -62
- package/dist/bin/plugins/XanixPageTransform-dep/transformer.d.ts +0 -23
- package/dist/bin/plugins/XanixPageTransform-dep/transformer.js +0 -589
- package/dist/bin/plugins/XanixServerTransform.d.ts +0 -5
- package/dist/bin/plugins/XanixServerTransform.js +0 -207
- package/dist/bin/plugins/XanixUseServer.d.ts +0 -7
- package/dist/bin/plugins/XanixUseServer.js +0 -445
- package/dist/bin/plugins/plugins.d.ts +0 -8
- package/dist/bin/plugins/plugins.js +0 -31
- package/dist/components/Script.d.ts +0 -3
- package/dist/components/Script.js +0 -5
- package/dist/dev.d.ts +0 -1
- package/dist/dev.js +0 -25
- package/dist/react/createContext.d.ts +0 -3
- package/dist/react/createContext.js +0 -11
- package/dist/react/index.d.ts +0 -12
- package/dist/react/index.js +0 -3
- package/dist/server/express/Ruter.d.ts +0 -2
- package/dist/server/express/Ruter.js +0 -15
- package/dist/server/runtime/createServer.d.ts +0 -12
- package/dist/server/runtime/createServer.js +0 -62
- package/dist/server/runtime/index.d.ts +0 -3
- package/dist/server/runtime/index.js +0 -3
- package/dist/server/runtime/readManifest.d.ts +0 -14
- package/dist/server/runtime/readManifest.js +0 -9
- package/dist/server/runtime/xanixPage.d.ts +0 -11
- package/dist/server/runtime/xanixPage.js +0 -92
- /package/dist/bin/bundler/{plugins/XanixDocument/index.d.ts → client/plugins/XanixPage.d.ts} +0 -0
- /package/dist/bin/{cli/start/utils.d.ts → bundler/server/plugins/replacer/useServer.d.ts} +0 -0
- /package/dist/bin/{cli/start/utils.js → bundler/server/plugins/replacer/useServer.js} +0 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const useServerReplacer = (code, imports, source) => {
|
|
4
|
+
const importName = `__xanix_server_${Math.random().toString(36).substring(2, 3)}`;
|
|
5
|
+
let codes = [`import { server as ${importName} } from "xanix"`];
|
|
6
|
+
imports.push({
|
|
7
|
+
specifiers: [
|
|
8
|
+
{
|
|
9
|
+
imported: "server",
|
|
10
|
+
local: importName,
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
const replacer = (code, cb) => {
|
|
15
|
+
return callbackReplacer(code, cb, (args) => {
|
|
16
|
+
const fn = args[0];
|
|
17
|
+
const argString = args[1] ?? "undefined";
|
|
18
|
+
const options = args[2] || "undefined";
|
|
19
|
+
const varname = `_xserver_${Math.random().toString(36).substring(2, 7)}`;
|
|
20
|
+
const server_code = `const ${varname} = ${importName}(${fn}, ${options});`;
|
|
21
|
+
codes.push(server_code);
|
|
22
|
+
return `${cb}(${varname}, ${argString})`;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
if (source.startsWith(framworkDir)) {
|
|
26
|
+
code = replacer(code, `useServer`);
|
|
27
|
+
}
|
|
28
|
+
if (!imports.length)
|
|
29
|
+
return code;
|
|
30
|
+
for (let _import of imports) {
|
|
31
|
+
if (_import.namespace) {
|
|
32
|
+
code = replacer(code, `${_import.namespace}.useServer`);
|
|
33
|
+
}
|
|
34
|
+
for (let sp of _import.specifiers) {
|
|
35
|
+
if (sp.imported === "useServer") {
|
|
36
|
+
code = replacer(code, sp.local);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return codes.join("\n") + "\n" + code;
|
|
41
|
+
};
|
|
42
|
+
export default useServerReplacer;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import stripComments from "../../../
|
|
1
|
+
import stripComments from "../../../finder/stripComments.js";
|
|
2
2
|
import TransformCacheFunction from "./transformer/TransformCacheFunction.js";
|
|
3
3
|
import TransformCreateSession from "./transformer/TransformCreateSession.js";
|
|
4
|
-
import importFinder from "../../../
|
|
4
|
+
import importFinder from "../../../finder/findImport.js";
|
|
5
5
|
import TransformServerFunction from "./transformer/TransformServerFunction.js";
|
|
6
6
|
import { uuid, frameworkDir } from "../../../include/utils.js";
|
|
7
7
|
const XanixTransformer = () => {
|
|
8
8
|
return {
|
|
9
9
|
name: "xanix-transform",
|
|
10
10
|
async transform(code, id) {
|
|
11
|
+
if (!/\.[jt]sx?$/.test(id))
|
|
12
|
+
return null;
|
|
11
13
|
const xanixImports = importFinder(code, "xanix");
|
|
12
14
|
if (xanixImports.length || id.startsWith(frameworkDir)) {
|
|
13
15
|
const uid = uuid(id, 12);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { getManifest } from "../../../include/manifest.js";
|
|
2
|
+
const VIRTUAL_ID = "virtual:xanix-pages";
|
|
3
|
+
const RESOLVED_ID = "\0virtual:xanix-pages";
|
|
4
|
+
export default function XanixAppRoot() {
|
|
5
|
+
return {
|
|
6
|
+
name: "xanix-pages",
|
|
7
|
+
resolveId(id) {
|
|
8
|
+
if (id === VIRTUAL_ID) {
|
|
9
|
+
return RESOLVED_ID;
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
},
|
|
13
|
+
async load(id) {
|
|
14
|
+
if (id !== RESOLVED_ID) {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
const clients = await getManifest();
|
|
18
|
+
const pages = [];
|
|
19
|
+
for (const client of clients) {
|
|
20
|
+
pages.push(`
|
|
21
|
+
loaders[${JSON.stringify(client.id)}] = () =>
|
|
22
|
+
import(${JSON.stringify(client.resolved)});
|
|
23
|
+
|
|
24
|
+
pages[${JSON.stringify(client.id)}] = React.lazy(
|
|
25
|
+
loaders[${JSON.stringify(client.id)}]
|
|
26
|
+
);
|
|
27
|
+
`);
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
code: `
|
|
31
|
+
import React from "react";
|
|
32
|
+
|
|
33
|
+
const pages = {};
|
|
34
|
+
const loaders = {};
|
|
35
|
+
|
|
36
|
+
${pages.join("\n")}
|
|
37
|
+
|
|
38
|
+
export { loaders };
|
|
39
|
+
export default pages;
|
|
40
|
+
`,
|
|
41
|
+
map: null,
|
|
42
|
+
moduleType: "js",
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
const VIRTUAL_ID = "virtual:xanix-app-root";
|
|
4
|
+
const RESOLVED_ID = "\0virtual:xanix-app-root";
|
|
5
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
6
|
+
export default function xanixDocument() {
|
|
7
|
+
const root = process.cwd();
|
|
8
|
+
const userDocument = path.resolve(root, "Document.tsx");
|
|
9
|
+
const baseDocument = path.resolve(__dirname, "../../components/BaseDocument.js");
|
|
10
|
+
return {
|
|
11
|
+
name: "xanix-document",
|
|
12
|
+
resolveId(id) {
|
|
13
|
+
if (id === VIRTUAL_ID) {
|
|
14
|
+
return RESOLVED_ID;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
},
|
|
18
|
+
load(id) {
|
|
19
|
+
if (id !== RESOLVED_ID) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
code: `
|
|
24
|
+
|
|
25
|
+
`,
|
|
26
|
+
map: null,
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -17,17 +17,17 @@ export default function XanixAppRoot() {
|
|
|
17
17
|
const clients = await getManifest();
|
|
18
18
|
const pages = [];
|
|
19
19
|
for (const client of clients) {
|
|
20
|
-
pages.push(`
|
|
21
|
-
pages[${JSON.stringify(client.id)}] = () =>
|
|
22
|
-
import(${JSON.stringify(client.resolved)});
|
|
20
|
+
pages.push(`
|
|
21
|
+
pages[${JSON.stringify(client.id)}] = () =>
|
|
22
|
+
import(${JSON.stringify(client.resolved)});
|
|
23
23
|
`);
|
|
24
24
|
}
|
|
25
25
|
return {
|
|
26
|
-
code: `
|
|
27
|
-
import React from "react";
|
|
28
|
-
const pages = {};
|
|
29
|
-
${pages.join("\n")}
|
|
30
|
-
export default pages;
|
|
26
|
+
code: `
|
|
27
|
+
import React from "react";
|
|
28
|
+
const pages = {};
|
|
29
|
+
${pages.join("\n")}
|
|
30
|
+
export default pages;
|
|
31
31
|
`,
|
|
32
32
|
map: null,
|
|
33
33
|
moduleType: "js",
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ImportInfo } from "../../../../modifier/importFinder.js";
|
|
2
|
-
declare const cacheFunctionReplacer: (code: string, imports: ImportInfo[], uid: string) => string;
|
|
2
|
+
declare const cacheFunctionReplacer: (code: string, imports: ImportInfo[], uid: string, source: string) => string;
|
|
3
3
|
export default cacheFunctionReplacer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
-
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const cacheFunctionReplacer = (code, imports, uid, source) => {
|
|
3
4
|
let count = 0;
|
|
4
5
|
const replacer = (code, cb) => {
|
|
5
6
|
const replacedCode = callbackReplacer(code, cb, (args) => {
|
|
@@ -13,6 +14,9 @@ const cacheFunctionReplacer = (code, imports, uid) => {
|
|
|
13
14
|
code = replacedCode;
|
|
14
15
|
return code;
|
|
15
16
|
};
|
|
17
|
+
if (source.startsWith(framworkDir)) {
|
|
18
|
+
code = replacer(code, `cache`);
|
|
19
|
+
}
|
|
16
20
|
for (let _import of imports) {
|
|
17
21
|
if (_import.namespace) {
|
|
18
22
|
code = replacer(code, `${_import.namespace}.cache`);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ImportInfo } from "../../../../modifier/importFinder.js";
|
|
2
|
-
declare const serverFunctionReplacer: (code: string, imports: ImportInfo[], uid: string) => string;
|
|
2
|
+
declare const serverFunctionReplacer: (code: string, imports: ImportInfo[], uid: string, source: string) => string;
|
|
3
3
|
export default serverFunctionReplacer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
-
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const serverFunctionReplacer = (code, imports, uid, source) => {
|
|
3
4
|
let count = 0;
|
|
4
5
|
const replacer = (code, cb) => {
|
|
5
6
|
const replacedCode = callbackReplacer(code, cb, (args) => {
|
|
@@ -13,6 +14,9 @@ const serverFunctionReplacer = (code, imports, uid) => {
|
|
|
13
14
|
code = replacedCode;
|
|
14
15
|
return code;
|
|
15
16
|
};
|
|
17
|
+
if (source.startsWith(framworkDir)) {
|
|
18
|
+
code = replacer(code, `server`);
|
|
19
|
+
}
|
|
16
20
|
for (let _import of imports) {
|
|
17
21
|
if (_import.namespace) {
|
|
18
22
|
code = replacer(code, `${_import.namespace}.server`);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ImportInfo } from "../../../../modifier/importFinder";
|
|
2
|
-
declare const useServerReplacer: (code: string, imports: ImportInfo[]) => string;
|
|
2
|
+
declare const useServerReplacer: (code: string, imports: ImportInfo[], source: string) => string;
|
|
3
3
|
export default useServerReplacer;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
return code;
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const useServerReplacer = (code, imports, source) => {
|
|
5
4
|
const importName = `__xanix_server_${Math.random().toString(36).substring(2, 3)}`;
|
|
6
5
|
let codes = [`import { server as ${importName} } from "xanix"`];
|
|
7
6
|
imports.push({
|
|
@@ -23,6 +22,11 @@ const useServerReplacer = (code, imports) => {
|
|
|
23
22
|
return `${cb}(${varname}, ${argString})`;
|
|
24
23
|
});
|
|
25
24
|
};
|
|
25
|
+
if (source.startsWith(framworkDir)) {
|
|
26
|
+
code = replacer(code, `useServer`);
|
|
27
|
+
}
|
|
28
|
+
if (!imports.length)
|
|
29
|
+
return code;
|
|
26
30
|
for (let _import of imports) {
|
|
27
31
|
if (_import.namespace) {
|
|
28
32
|
code = replacer(code, `${_import.namespace}.useServer`);
|
|
@@ -82,7 +82,7 @@ const BuildServer = async ({ rootEntry, onBuildEnd }) => {
|
|
|
82
82
|
dir: outdirs.server,
|
|
83
83
|
format: "esm",
|
|
84
84
|
entryFileNames: "index.js",
|
|
85
|
-
chunkFileNames: "chunks/[hash].js",
|
|
85
|
+
chunkFileNames: "chunks/[hash]s.js",
|
|
86
86
|
assetFileNames: "assets/[name][extname]",
|
|
87
87
|
minify: true,
|
|
88
88
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const TransformCacheFunction = (code, imports, uid, source) => {
|
|
4
|
+
let count = 0;
|
|
5
|
+
const replacer = (code, cb) => {
|
|
6
|
+
const replacedCode = callbackReplacer(code, cb, (args) => {
|
|
7
|
+
if (args[2])
|
|
8
|
+
return;
|
|
9
|
+
const id = uid + count++;
|
|
10
|
+
const fn = args[0];
|
|
11
|
+
const options = args[1] || "undefined";
|
|
12
|
+
return `${cb}(${fn}, ${options}, "${id}");`;
|
|
13
|
+
});
|
|
14
|
+
code = replacedCode;
|
|
15
|
+
return code;
|
|
16
|
+
};
|
|
17
|
+
if (source.startsWith(framworkDir)) {
|
|
18
|
+
code = replacer(code, `cache`);
|
|
19
|
+
}
|
|
20
|
+
for (let _import of imports) {
|
|
21
|
+
if (_import.namespace) {
|
|
22
|
+
code = replacer(code, `${_import.namespace}.cache`);
|
|
23
|
+
}
|
|
24
|
+
for (let sp of _import.specifiers) {
|
|
25
|
+
if (sp.imported === "cache") {
|
|
26
|
+
code = replacer(code, sp.local);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return code;
|
|
31
|
+
};
|
|
32
|
+
export default TransformCacheFunction;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ImportInfo } from "../../../../
|
|
1
|
+
import { ImportInfo } from "../../../../finder/findImport.js";
|
|
2
2
|
declare const TransformCacheFunction: (code: string, imports: ImportInfo[], uid: string, source: string) => string;
|
|
3
3
|
export default TransformCacheFunction;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import callbackReplacer from "../../../../
|
|
1
|
+
import callbackReplacer from "../../../../finder/callbackReplacer.js";
|
|
2
2
|
import { frameworkDir } from "../../../../include/utils.js";
|
|
3
3
|
const TransformCacheFunction = (code, imports, uid, source) => {
|
|
4
4
|
let count = 0;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ImportInfo } from "../../../../
|
|
1
|
+
import { ImportInfo } from "../../../../finder/findImport.js";
|
|
2
2
|
declare const TransformCreateSession: (code: string, imports: ImportInfo[], uid: string, source: string) => string;
|
|
3
3
|
export default TransformCreateSession;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { frameworkDir } from "../../../../include/utils.js";
|
|
2
|
-
import callbackReplacer from "../../../../
|
|
2
|
+
import callbackReplacer from "../../../../finder/callbackReplacer.js";
|
|
3
3
|
const TransformCreateSession = (code, imports, uid, source) => {
|
|
4
4
|
let count = 0;
|
|
5
5
|
const replacer = (code, cb) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import crypto from "node:crypto";
|
|
2
|
-
import pageFinder from "../../../../
|
|
2
|
+
import pageFinder from "../../../../finder/findPage.js";
|
|
3
3
|
import { normalizePath } from "../../../../include/utils.js";
|
|
4
4
|
const uid = (source) => {
|
|
5
5
|
return crypto.createHash("sha256").update(source).digest("hex").slice(0, 12);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ImportInfo } from "../../../../
|
|
1
|
+
import { ImportInfo } from "../../../../finder/findImport.js";
|
|
2
2
|
declare const TransformServerFunction: (code: string, imports: ImportInfo[], uid: string, source: string) => string;
|
|
3
3
|
export default TransformServerFunction;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { frameworkDir } from "../../../../include/utils.js";
|
|
2
|
-
import callbackReplacer from "../../../../
|
|
2
|
+
import callbackReplacer from "../../../../finder/callbackReplacer.js";
|
|
3
3
|
const TransformServerFunction = (code, imports, uid, source) => {
|
|
4
4
|
let count = 0;
|
|
5
5
|
const replacer = (code, cb) => {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const cacheFunctionReplacer = (code, imports, uid, source) => {
|
|
4
|
+
let count = 0;
|
|
5
|
+
const replacer = (code, cb) => {
|
|
6
|
+
const replacedCode = callbackReplacer(code, cb, (args) => {
|
|
7
|
+
if (args[2])
|
|
8
|
+
return;
|
|
9
|
+
const id = uid + count++;
|
|
10
|
+
const fn = args[0];
|
|
11
|
+
const options = args[1] || "undefined";
|
|
12
|
+
return `${cb}(${fn}, ${options}, "${id}");`;
|
|
13
|
+
});
|
|
14
|
+
code = replacedCode;
|
|
15
|
+
return code;
|
|
16
|
+
};
|
|
17
|
+
if (source.startsWith(framworkDir)) {
|
|
18
|
+
code = replacer(code, `cache`);
|
|
19
|
+
}
|
|
20
|
+
for (let _import of imports) {
|
|
21
|
+
if (_import.namespace) {
|
|
22
|
+
code = replacer(code, `${_import.namespace}.cache`);
|
|
23
|
+
}
|
|
24
|
+
for (let sp of _import.specifiers) {
|
|
25
|
+
if (sp.imported === "cache") {
|
|
26
|
+
code = replacer(code, sp.local);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return code;
|
|
31
|
+
};
|
|
32
|
+
export default cacheFunctionReplacer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
+
const expressFunctionReplace = (code, imports) => {
|
|
3
|
+
if (!imports.length)
|
|
4
|
+
return code;
|
|
5
|
+
const importName = `__xanix_express_${Math.random().toString(36).substring(2, 3)}`;
|
|
6
|
+
let found = false;
|
|
7
|
+
for (let _import of imports) {
|
|
8
|
+
for (let specifier of _import.specifiers) {
|
|
9
|
+
if (specifier.imported === "default") {
|
|
10
|
+
code = callbackReplacer(code, specifier.local, (args) => {
|
|
11
|
+
if (args[0] === `"xanix"`)
|
|
12
|
+
return;
|
|
13
|
+
found = true;
|
|
14
|
+
return `${importName}("express")`;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (found) {
|
|
20
|
+
code = `import { xanix as ${importName} } from "xanix";\n` + code;
|
|
21
|
+
}
|
|
22
|
+
return code;
|
|
23
|
+
};
|
|
24
|
+
export default expressFunctionReplace;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { TransformPluginContext } from "rolldown";
|
|
2
|
+
import { XanixClientEntry } from "../../../../types.js";
|
|
3
|
+
declare const pageReplacer: (importer: string, code: string, context: TransformPluginContext, entries: Map<string, XanixClientEntry>) => Promise<string>;
|
|
4
|
+
export default pageReplacer;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import pageFinder from "../../../../modifier/pageFinder.js";
|
|
3
|
+
import { normalizePath } from "../../../../include/utils.js";
|
|
4
|
+
const uid = (source) => {
|
|
5
|
+
return crypto.createHash("sha256").update(source).digest("hex").slice(0, 12);
|
|
6
|
+
};
|
|
7
|
+
const pageReplacer = async (importer, code, context, entries) => {
|
|
8
|
+
if (!/\.send\(/.test(code)) {
|
|
9
|
+
return code;
|
|
10
|
+
}
|
|
11
|
+
const pages = pageFinder(code).sort((a, b) => b.start - a.start);
|
|
12
|
+
for (const page of pages) {
|
|
13
|
+
const resolved = await context.resolve(page.source, importer, {
|
|
14
|
+
skipSelf: true,
|
|
15
|
+
});
|
|
16
|
+
if (resolved) {
|
|
17
|
+
const id = uid(resolved.id);
|
|
18
|
+
entries.set(id, {
|
|
19
|
+
id,
|
|
20
|
+
source: page.source,
|
|
21
|
+
resolved: normalizePath(resolved.id),
|
|
22
|
+
});
|
|
23
|
+
code =
|
|
24
|
+
code.slice(0, page.start) +
|
|
25
|
+
`${page.identifier}.send(${page.args[0]}, "${id}")` +
|
|
26
|
+
code.slice(page.end);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return code;
|
|
30
|
+
};
|
|
31
|
+
export default pageReplacer;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const serverFunctionReplacer = (code, imports, uid, source) => {
|
|
4
|
+
let count = 0;
|
|
5
|
+
const replacer = (code, cb) => {
|
|
6
|
+
const replacedCode = callbackReplacer(code, cb, (args) => {
|
|
7
|
+
if (args[2])
|
|
8
|
+
return;
|
|
9
|
+
const id = uid + count++;
|
|
10
|
+
const fn = args[0];
|
|
11
|
+
const options = args[1] || "undefined";
|
|
12
|
+
return `${cb}(${fn}, ${options}, "${id}");`;
|
|
13
|
+
});
|
|
14
|
+
code = replacedCode;
|
|
15
|
+
return code;
|
|
16
|
+
};
|
|
17
|
+
if (source.startsWith(framworkDir)) {
|
|
18
|
+
code = replacer(code, `server`);
|
|
19
|
+
}
|
|
20
|
+
for (let _import of imports) {
|
|
21
|
+
if (_import.namespace) {
|
|
22
|
+
code = replacer(code, `${_import.namespace}.server`);
|
|
23
|
+
}
|
|
24
|
+
for (let sp of _import.specifiers) {
|
|
25
|
+
if (sp.imported === "server") {
|
|
26
|
+
code = replacer(code, sp.local);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return code;
|
|
31
|
+
};
|
|
32
|
+
export default serverFunctionReplacer;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
2
|
+
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
3
|
+
const useServerReplacer = (code, imports, source) => {
|
|
4
|
+
const importName = `__xanix_server_${Math.random().toString(36).substring(2, 4)}`;
|
|
5
|
+
let codes = [`import { server as ${importName} } from "xanix"`];
|
|
6
|
+
imports.push({
|
|
7
|
+
specifiers: [
|
|
8
|
+
{
|
|
9
|
+
imported: "server",
|
|
10
|
+
local: importName,
|
|
11
|
+
},
|
|
12
|
+
],
|
|
13
|
+
});
|
|
14
|
+
const replacer = (code, cb) => {
|
|
15
|
+
return callbackReplacer(code, cb, (args) => {
|
|
16
|
+
const fn = args[0];
|
|
17
|
+
const argString = args[1] ?? "undefined";
|
|
18
|
+
const options = args[2] || "undefined";
|
|
19
|
+
const varname = `_use_server_${Math.random().toString(36).substring(2, 6)}`;
|
|
20
|
+
const server_code = `const ${varname} = ${importName}(${fn}, ${options});`;
|
|
21
|
+
codes.push(server_code);
|
|
22
|
+
return `${cb}(${varname}, ${argString})`;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
if (source.startsWith(framworkDir)) {
|
|
26
|
+
code = replacer(code, `useServer`);
|
|
27
|
+
}
|
|
28
|
+
if (!imports.length)
|
|
29
|
+
return code;
|
|
30
|
+
for (let _import of imports) {
|
|
31
|
+
if (_import.namespace) {
|
|
32
|
+
code = replacer(code, `${_import.namespace}.useServer`);
|
|
33
|
+
}
|
|
34
|
+
for (let sp of _import.specifiers) {
|
|
35
|
+
if (sp.imported === "useServer") {
|
|
36
|
+
code = replacer(code, sp.local);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return codes.join("\n") + "\n" + code;
|
|
41
|
+
};
|
|
42
|
+
export default useServerReplacer;
|
|
@@ -72,9 +72,9 @@ const XanixTransformer = ({ onChangeManifest } = {}) => {
|
|
|
72
72
|
code = code.slice(0, start) + value + code.slice(end);
|
|
73
73
|
}
|
|
74
74
|
let needImport = !transformUseServer.serverImported;
|
|
75
|
-
const useServerCode = `
|
|
76
|
-
${needImport ? 'import * as __xanix from "xanix";' : ""}
|
|
77
|
-
${transformUseServer.serverCodes.join("\n")}
|
|
75
|
+
const useServerCode = `
|
|
76
|
+
${needImport ? 'import * as __xanix from "xanix";' : ""}
|
|
77
|
+
${transformUseServer.serverCodes.join("\n")}
|
|
78
78
|
`;
|
|
79
79
|
if (transformServer.foundServer) {
|
|
80
80
|
code = `import { xanix } from "xanix";\n` + code;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import stripComments from "../../../
|
|
1
|
+
import stripComments from "../../../finder/stripComments.js";
|
|
2
2
|
import { uuid } from "../../../include/utils.js";
|
|
3
3
|
import TransformServerFunction from "./transformer/TransformServerFunction.js";
|
|
4
4
|
import TransformCacheFunction from "./transformer/TransformCacheFunction.js";
|
|
5
5
|
import { createManifest, getManifest } from "../../../include/manifest.js";
|
|
6
|
-
import importFinder from "../../../
|
|
6
|
+
import importFinder from "../../../finder/findImport.js";
|
|
7
7
|
import expressFunctionReplace from "./transformer/TransformExpressFunction.js";
|
|
8
8
|
import pageReplacer from "./transformer/TransformPage.js";
|
|
9
9
|
import { frameworkDir } from "../../../include/utils.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { ImportInfo } from "../../../../modifier/importFinder.js";
|
|
2
|
-
declare const cacheFunctionReplacer: (code: string, imports: ImportInfo[], uid: string) => string;
|
|
2
|
+
declare const cacheFunctionReplacer: (code: string, imports: ImportInfo[], uid: string, source: string) => string;
|
|
3
3
|
export default cacheFunctionReplacer;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
-
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const cacheFunctionReplacer = (code, imports, uid, source) => {
|
|
3
4
|
let count = 0;
|
|
4
5
|
const replacer = (code, cb) => {
|
|
5
6
|
const replacedCode = callbackReplacer(code, cb, (args) => {
|
|
@@ -13,6 +14,9 @@ const cacheFunctionReplacer = (code, imports, uid) => {
|
|
|
13
14
|
code = replacedCode;
|
|
14
15
|
return code;
|
|
15
16
|
};
|
|
17
|
+
if (source.startsWith(framworkDir)) {
|
|
18
|
+
code = replacer(code, `cache`);
|
|
19
|
+
}
|
|
16
20
|
for (let _import of imports) {
|
|
17
21
|
if (_import.namespace) {
|
|
18
22
|
code = replacer(code, `${_import.namespace}.cache`);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
+
const serverFunctionReplacer = (code, imports, uid) => {
|
|
3
|
+
let count = 0;
|
|
4
|
+
const replacer = (code, cb) => {
|
|
5
|
+
const replacedCode = callbackReplacer(code, cb, (args) => {
|
|
6
|
+
const id = uid + count++;
|
|
7
|
+
const fn = args[0];
|
|
8
|
+
const options = args[1] || "undefined";
|
|
9
|
+
return `${cb}(${fn}, ${options}, "${id}");`;
|
|
10
|
+
});
|
|
11
|
+
code = replacedCode;
|
|
12
|
+
return code;
|
|
13
|
+
};
|
|
14
|
+
for (let _import of imports) {
|
|
15
|
+
if (_import.namespace) {
|
|
16
|
+
code = replacer(code, `${_import.namespace}.server`);
|
|
17
|
+
}
|
|
18
|
+
for (let sp of _import.specifiers) {
|
|
19
|
+
if (sp.imported === "server") {
|
|
20
|
+
code = replacer(code, sp.local);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
return code;
|
|
25
|
+
};
|
|
26
|
+
export default serverFunctionReplacer;
|