xanix 1.0.20 → 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
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { rolldown } from "rolldown";
|
|
2
|
-
import { walk } from "oxc-walker";
|
|
3
|
-
import TransformExpress from "./TransformExpress.js";
|
|
4
|
-
import TransformPage from "./TransformPage.js";
|
|
5
|
-
import loadEnv from "../../config/loadEnv.js";
|
|
6
|
-
import { getClientRuntimeFile, getClientRuntimeFileName, } from "../../../include/utils.js";
|
|
7
|
-
import { xanixDefaultPlugins } from "../plugins.js";
|
|
8
|
-
import bundlerOutput from "../../config/output.js";
|
|
9
|
-
function getParserLanguage(id) {
|
|
10
|
-
const cleanId = id.split("?")[0];
|
|
11
|
-
if (cleanId.endsWith(".tsx"))
|
|
12
|
-
return "tsx";
|
|
13
|
-
if (cleanId.endsWith(".ts"))
|
|
14
|
-
return "ts";
|
|
15
|
-
if (cleanId.endsWith(".jsx"))
|
|
16
|
-
return "jsx";
|
|
17
|
-
return "js";
|
|
18
|
-
}
|
|
19
|
-
const XanixTransform = () => {
|
|
20
|
-
let entries = [];
|
|
21
|
-
return {
|
|
22
|
-
name: "xanix-transform",
|
|
23
|
-
async transform(code, id) {
|
|
24
|
-
if (id.includes("node_modules")) {
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
const lang = getParserLanguage(id);
|
|
28
|
-
if (lang !== "tsx" && lang !== "jsx") {
|
|
29
|
-
return null;
|
|
30
|
-
}
|
|
31
|
-
const ast = this.parse(code, { lang });
|
|
32
|
-
const transformExpress = new TransformExpress();
|
|
33
|
-
const transformPage = new TransformPage();
|
|
34
|
-
walk(ast, {
|
|
35
|
-
enter(node) {
|
|
36
|
-
transformExpress.transform(node);
|
|
37
|
-
transformPage.transform(node);
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
let replacements = [
|
|
41
|
-
...transformExpress.replacements,
|
|
42
|
-
...transformPage.replacements,
|
|
43
|
-
];
|
|
44
|
-
for (let entry of transformPage.entries) {
|
|
45
|
-
const resolved = await this.resolve(entry.source, id, {
|
|
46
|
-
skipSelf: true,
|
|
47
|
-
});
|
|
48
|
-
entry.resolved = resolved?.id ?? "";
|
|
49
|
-
entries.push(entry);
|
|
50
|
-
}
|
|
51
|
-
const sorted = replacements.sort((a, b) => b.start - a.start);
|
|
52
|
-
for (const { start, end, value } of sorted) {
|
|
53
|
-
code = code.slice(0, start) + value + code.slice(end);
|
|
54
|
-
}
|
|
55
|
-
return {
|
|
56
|
-
code,
|
|
57
|
-
map: null,
|
|
58
|
-
};
|
|
59
|
-
},
|
|
60
|
-
async generateBundle() {
|
|
61
|
-
const input = {};
|
|
62
|
-
for (let entry of entries) {
|
|
63
|
-
input[entry.name] = entry.resolved;
|
|
64
|
-
}
|
|
65
|
-
const runtimeFileName = getClientRuntimeFileName("development");
|
|
66
|
-
input[runtimeFileName] = getClientRuntimeFile();
|
|
67
|
-
const build = await rolldown({
|
|
68
|
-
input,
|
|
69
|
-
treeshake: true,
|
|
70
|
-
tsconfig: true,
|
|
71
|
-
checks: {
|
|
72
|
-
moduleLevelDirective: false,
|
|
73
|
-
},
|
|
74
|
-
resolve: {
|
|
75
|
-
extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
|
|
76
|
-
conditionNames: ["browser", "import", "module", "default"],
|
|
77
|
-
},
|
|
78
|
-
transform: {
|
|
79
|
-
target: "es2022",
|
|
80
|
-
jsx: {
|
|
81
|
-
runtime: "automatic",
|
|
82
|
-
// refresh: true,
|
|
83
|
-
},
|
|
84
|
-
define: await loadEnv({
|
|
85
|
-
mode: "development",
|
|
86
|
-
isClient: true,
|
|
87
|
-
}),
|
|
88
|
-
},
|
|
89
|
-
plugins: [
|
|
90
|
-
...xanixDefaultPlugins({
|
|
91
|
-
WebSocketPort: 3000,
|
|
92
|
-
target: "client",
|
|
93
|
-
development: true,
|
|
94
|
-
assetExternal: true,
|
|
95
|
-
}),
|
|
96
|
-
],
|
|
97
|
-
});
|
|
98
|
-
await build.write(bundlerOutput.client(entries, { isDev: true }));
|
|
99
|
-
await build.close();
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
};
|
|
103
|
-
export default XanixTransform;
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import crypto from "node:crypto";
|
|
4
|
-
const ASSET_RE = /\.(png|jpe?g|gif|svg|webp|avif|ico|bmp|mp4|webm|ogg|mp3|wav|woff2?|ttf|otf)$/i;
|
|
5
|
-
export default function xanixAssets(options = {}) {
|
|
6
|
-
const emit = options.emit ?? true;
|
|
7
|
-
return {
|
|
8
|
-
name: "xanix-assets",
|
|
9
|
-
resolveId(source, importer) {
|
|
10
|
-
if (!importer) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
if (!ASSET_RE.test(source)) {
|
|
14
|
-
return null;
|
|
15
|
-
}
|
|
16
|
-
if (source.startsWith(".") || source.startsWith("/")) {
|
|
17
|
-
return path.resolve(path.dirname(importer), source);
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
},
|
|
21
|
-
load(id) {
|
|
22
|
-
if (!ASSET_RE.test(id)) {
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
if (!fs.existsSync(id)) {
|
|
26
|
-
return null;
|
|
27
|
-
}
|
|
28
|
-
const source = fs.readFileSync(id);
|
|
29
|
-
const ext = path.extname(id);
|
|
30
|
-
const basename = path.basename(id, ext);
|
|
31
|
-
const hash = crypto
|
|
32
|
-
.createHash("sha256")
|
|
33
|
-
.update(source)
|
|
34
|
-
.digest("hex")
|
|
35
|
-
.slice(0, 8);
|
|
36
|
-
const fileName = `${basename}-${hash}${ext}`;
|
|
37
|
-
if (emit) {
|
|
38
|
-
this.emitFile({
|
|
39
|
-
type: "asset",
|
|
40
|
-
name: fileName,
|
|
41
|
-
originalFileName: id,
|
|
42
|
-
source,
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
return {
|
|
46
|
-
code: `export default ${JSON.stringify(fileName)};`,
|
|
47
|
-
moduleSideEffects: false,
|
|
48
|
-
};
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { rollup } from "rollup";
|
|
4
|
-
import outdirs from "../../../outdirs.js";
|
|
5
|
-
import XanixEnvPlugin from "./XanixEnv.js";
|
|
6
|
-
import nodeResolve from "@rollup/plugin-node-resolve";
|
|
7
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
8
|
-
import json from "@rollup/plugin-json";
|
|
9
|
-
import XanixDocument from "./XanixDocument/index.js";
|
|
10
|
-
import esbuild from "rollup-plugin-esbuild";
|
|
11
|
-
import defines from "../config/defines.js";
|
|
12
|
-
import fs from "node:fs";
|
|
13
|
-
import { pathToFileURL } from "node:url";
|
|
14
|
-
const require = createRequire(import.meta.url);
|
|
15
|
-
const cacheDir = outdirs.cache;
|
|
16
|
-
const filename = (source) => source.replace(/^@/, "").replace(/\//g, "-");
|
|
17
|
-
const cached = new Map();
|
|
18
|
-
function resolveFrom(source, fromDir) {
|
|
19
|
-
return require.resolve(source, { paths: [fromDir] });
|
|
20
|
-
}
|
|
21
|
-
async function getRealExportedKeys(resolvedEntry) {
|
|
22
|
-
try {
|
|
23
|
-
const mod = await import(pathToFileURL(resolvedEntry).href);
|
|
24
|
-
const hasDefault = mod &&
|
|
25
|
-
(typeof mod === "object" || typeof mod === "function") &&
|
|
26
|
-
"default" in mod;
|
|
27
|
-
const names = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
28
|
-
return { modules: names, hasDefault };
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return { modules: [], hasDefault: false }; // native ESM or require failure — no shim possible/needed
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Marks a dependency's transitive deps external using their BARE specifier
|
|
36
|
-
* (e.g. "react", not "./react.js"). This lets @rollup/plugin-commonjs
|
|
37
|
-
* resolve them normally via node resolution for its interop/named-exports
|
|
38
|
-
* shim — resolving a real bare specifier always succeeds, unlike resolving
|
|
39
|
-
* a synthetic relative path that doesn't exist on disk. The actual path
|
|
40
|
-
* rewrite to "./react.js" happens afterward via output.paths, not here.
|
|
41
|
-
*/
|
|
42
|
-
const resolver = (externalsUsed) => {
|
|
43
|
-
return {
|
|
44
|
-
name: "xanix-cache-deps-resolver",
|
|
45
|
-
async resolveId(source, importer) {
|
|
46
|
-
if (source.startsWith(".") || path.isAbsolute(source)) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const fromDir = importer ? path.dirname(importer) : process.cwd();
|
|
50
|
-
let resolved;
|
|
51
|
-
try {
|
|
52
|
-
resolved = resolveFrom(source, fromDir);
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
await bundleCache(source, resolved);
|
|
58
|
-
externalsUsed.add(source);
|
|
59
|
-
// Bare id, external — commonjs plugin can resolve this for real.
|
|
60
|
-
return { id: source, external: true };
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
const bundleCache = (source, resolvedEntry) => {
|
|
65
|
-
if (cached.has(source))
|
|
66
|
-
return cached.get(source);
|
|
67
|
-
const promise = (async () => {
|
|
68
|
-
const file = filename(source);
|
|
69
|
-
const input = resolvedEntry ?? resolveFrom(source, process.cwd());
|
|
70
|
-
const externalsUsed = new Set();
|
|
71
|
-
const isClient = true;
|
|
72
|
-
const mode = "development";
|
|
73
|
-
const build = await rollup({
|
|
74
|
-
input,
|
|
75
|
-
plugins: [
|
|
76
|
-
resolver(externalsUsed),
|
|
77
|
-
XanixEnvPlugin({ mode, isClient }),
|
|
78
|
-
nodeResolve({
|
|
79
|
-
browser: isClient,
|
|
80
|
-
preferBuiltins: !isClient,
|
|
81
|
-
extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
|
|
82
|
-
}),
|
|
83
|
-
commonjs(),
|
|
84
|
-
json(),
|
|
85
|
-
XanixDocument(),
|
|
86
|
-
esbuild({
|
|
87
|
-
target: isClient ? "es2022" : "node20",
|
|
88
|
-
jsx: "automatic",
|
|
89
|
-
tsconfig: false,
|
|
90
|
-
define: defines({ mode, isClient }),
|
|
91
|
-
}),
|
|
92
|
-
],
|
|
93
|
-
});
|
|
94
|
-
const paths = {};
|
|
95
|
-
for (const dep of externalsUsed) {
|
|
96
|
-
paths[dep] = `./${filename(dep)}.js`;
|
|
97
|
-
}
|
|
98
|
-
await build.write({
|
|
99
|
-
dir: cacheDir,
|
|
100
|
-
format: "esm",
|
|
101
|
-
entryFileNames: `${file}.internal.js`,
|
|
102
|
-
exports: "named",
|
|
103
|
-
paths,
|
|
104
|
-
});
|
|
105
|
-
const { modules, hasDefault } = await getRealExportedKeys(resolvedEntry ?? input);
|
|
106
|
-
const lines = [`import __mod from './${file}.internal.js';`];
|
|
107
|
-
if (hasDefault) {
|
|
108
|
-
lines.push(`export default __mod.default;`);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
lines.push(`export default __mod;`);
|
|
112
|
-
}
|
|
113
|
-
for (const exportName of modules) {
|
|
114
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
115
|
-
lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}] || __mod.default[${JSON.stringify(exportName)}]`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
await fs.promises.writeFile(path.join(cacheDir, `${file}.js`), lines.join("\n") + "\n", "utf8");
|
|
119
|
-
})();
|
|
120
|
-
cached.set(source, promise);
|
|
121
|
-
return promise;
|
|
122
|
-
};
|
|
123
|
-
export default function XanixCachedDeps() {
|
|
124
|
-
return {
|
|
125
|
-
name: "xanix-cache-deps",
|
|
126
|
-
async resolveId(source, importer) {
|
|
127
|
-
if (source.startsWith(".") || path.isAbsolute(source)) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
const fromDir = importer ? path.dirname(importer) : process.cwd();
|
|
131
|
-
let resolved;
|
|
132
|
-
try {
|
|
133
|
-
resolved = resolveFrom(source, fromDir);
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
await bundleCache(source, resolved);
|
|
139
|
-
// Same principle applies here if this outer build also runs through
|
|
140
|
-
// a commonjs plugin: prefer returning a bare-style external id and
|
|
141
|
-
// supplying `paths` on the OUTER build's output config (in
|
|
142
|
-
// WatchClient / bundlerOutput.client) rather than baking "../cache/x.js"
|
|
143
|
-
// directly into the id.
|
|
144
|
-
return {
|
|
145
|
-
id: `/${outdirs.cache}/${filename(source)}.js`,
|
|
146
|
-
external: true,
|
|
147
|
-
};
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
}
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { rollup } from "rollup";
|
|
4
|
-
import outdirs from "../../../outdirs.js";
|
|
5
|
-
import XanixEnvPlugin from "./XanixEnv.js";
|
|
6
|
-
import nodeResolve from "@rollup/plugin-node-resolve";
|
|
7
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
8
|
-
import json from "@rollup/plugin-json";
|
|
9
|
-
import XanixDocument from "./XanixDocument/index.js";
|
|
10
|
-
import esbuild from "rollup-plugin-esbuild";
|
|
11
|
-
import defines from "../config/defines.js";
|
|
12
|
-
import fs from "node:fs";
|
|
13
|
-
import { pathToFileURL } from "node:url";
|
|
14
|
-
const require = createRequire(import.meta.url);
|
|
15
|
-
const cacheDir = outdirs.cache;
|
|
16
|
-
const filename = (source) => source.replace(/^@/, "").replace(/\//g, "-");
|
|
17
|
-
const cached = new Map();
|
|
18
|
-
function resolveFrom(source, fromDir) {
|
|
19
|
-
return require.resolve(source, { paths: [fromDir] });
|
|
20
|
-
}
|
|
21
|
-
async function getRealExportedKeys(resolvedEntry) {
|
|
22
|
-
try {
|
|
23
|
-
const mod = await import(pathToFileURL(resolvedEntry).href);
|
|
24
|
-
const hasDefault = mod &&
|
|
25
|
-
(typeof mod === "object" || typeof mod === "function") &&
|
|
26
|
-
"default" in mod;
|
|
27
|
-
const names = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
28
|
-
return { modules: names, hasDefault };
|
|
29
|
-
}
|
|
30
|
-
catch {
|
|
31
|
-
return { modules: [], hasDefault: false }; // native ESM or require failure — no shim possible/needed
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Marks a dependency's transitive deps external using their BARE specifier
|
|
36
|
-
* (e.g. "react", not "./react.js"). This lets @rollup/plugin-commonjs
|
|
37
|
-
* resolve them normally via node resolution for its interop/named-exports
|
|
38
|
-
* shim — resolving a real bare specifier always succeeds, unlike resolving
|
|
39
|
-
* a synthetic relative path that doesn't exist on disk. The actual path
|
|
40
|
-
* rewrite to "./react.js" happens afterward via output.paths, not here.
|
|
41
|
-
*/
|
|
42
|
-
const resolver = (externalsUsed) => {
|
|
43
|
-
return {
|
|
44
|
-
name: "xanix-cache-deps-resolver",
|
|
45
|
-
async resolveId(source, importer) {
|
|
46
|
-
if (source.startsWith(".") || path.isAbsolute(source)) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
const fromDir = importer ? path.dirname(importer) : process.cwd();
|
|
50
|
-
let resolved;
|
|
51
|
-
try {
|
|
52
|
-
resolved = resolveFrom(source, fromDir);
|
|
53
|
-
}
|
|
54
|
-
catch {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
await bundleCache(source, resolved);
|
|
58
|
-
externalsUsed.add(source);
|
|
59
|
-
// Bare id, external — commonjs plugin can resolve this for real.
|
|
60
|
-
return { id: source, external: true };
|
|
61
|
-
},
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
const bundleCache = (source, resolvedEntry) => {
|
|
65
|
-
if (cached.has(source))
|
|
66
|
-
return cached.get(source);
|
|
67
|
-
const promise = (async () => {
|
|
68
|
-
const file = filename(source);
|
|
69
|
-
const input = resolvedEntry ?? resolveFrom(source, process.cwd());
|
|
70
|
-
const externalsUsed = new Set();
|
|
71
|
-
const isClient = true;
|
|
72
|
-
const mode = "development";
|
|
73
|
-
const build = await rollup({
|
|
74
|
-
input,
|
|
75
|
-
plugins: [
|
|
76
|
-
resolver(externalsUsed),
|
|
77
|
-
XanixEnvPlugin({ mode, isClient }),
|
|
78
|
-
nodeResolve({
|
|
79
|
-
browser: isClient,
|
|
80
|
-
preferBuiltins: !isClient,
|
|
81
|
-
extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
|
|
82
|
-
}),
|
|
83
|
-
commonjs(),
|
|
84
|
-
json(),
|
|
85
|
-
XanixDocument(),
|
|
86
|
-
esbuild({
|
|
87
|
-
target: isClient ? "es2022" : "node20",
|
|
88
|
-
jsx: "automatic",
|
|
89
|
-
tsconfig: false,
|
|
90
|
-
define: defines({ mode, isClient }),
|
|
91
|
-
}),
|
|
92
|
-
],
|
|
93
|
-
});
|
|
94
|
-
const paths = {};
|
|
95
|
-
for (const dep of externalsUsed) {
|
|
96
|
-
paths[dep] = `./${filename(dep)}.js`;
|
|
97
|
-
}
|
|
98
|
-
await build.write({
|
|
99
|
-
dir: cacheDir,
|
|
100
|
-
format: "esm",
|
|
101
|
-
entryFileNames: `${file}.internal.js`,
|
|
102
|
-
exports: "named",
|
|
103
|
-
paths,
|
|
104
|
-
});
|
|
105
|
-
const { modules, hasDefault } = await getRealExportedKeys(resolvedEntry ?? input);
|
|
106
|
-
const lines = [`import __mod from './${file}.internal.js';`];
|
|
107
|
-
if (hasDefault) {
|
|
108
|
-
lines.push(`export default __mod.default;`);
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
lines.push(`export default __mod;`);
|
|
112
|
-
}
|
|
113
|
-
for (const exportName of modules) {
|
|
114
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
115
|
-
lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}] || __mod.default[${JSON.stringify(exportName)}]`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
await fs.promises.writeFile(path.join(cacheDir, `${file}.js`), lines.join("\n") + "\n", "utf8");
|
|
119
|
-
})();
|
|
120
|
-
cached.set(source, promise);
|
|
121
|
-
return promise;
|
|
122
|
-
};
|
|
123
|
-
export default function XanixCachedDeps() {
|
|
124
|
-
return {
|
|
125
|
-
name: "xanix-cache-deps",
|
|
126
|
-
async resolveId(source, importer) {
|
|
127
|
-
if (source.startsWith(".") || path.isAbsolute(source)) {
|
|
128
|
-
return null;
|
|
129
|
-
}
|
|
130
|
-
const fromDir = importer ? path.dirname(importer) : process.cwd();
|
|
131
|
-
let resolved;
|
|
132
|
-
try {
|
|
133
|
-
resolved = resolveFrom(source, fromDir);
|
|
134
|
-
}
|
|
135
|
-
catch {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
await bundleCache(source, resolved);
|
|
139
|
-
// Same principle applies here if this outer build also runs through
|
|
140
|
-
// a commonjs plugin: prefer returning a bare-style external id and
|
|
141
|
-
// supplying `paths` on the OUTER build's output config (in
|
|
142
|
-
// WatchClient / bundlerOutput.client) rather than baking "../cache/x.js"
|
|
143
|
-
// directly into the id.
|
|
144
|
-
return {
|
|
145
|
-
id: `/${outdirs.cache}/${filename(source)}.js`,
|
|
146
|
-
external: true,
|
|
147
|
-
};
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import { createRequire } from "node:module";
|
|
4
|
-
const require = createRequire(import.meta.url);
|
|
5
|
-
const VIRTUAL_ID = "virtual:xanix-document";
|
|
6
|
-
const RESOLVED_ID = "\0virtual:xanix-document";
|
|
7
|
-
export default function xanixDocument() {
|
|
8
|
-
const root = process.cwd();
|
|
9
|
-
const userDocument = path.resolve(root, "document.tsx");
|
|
10
|
-
const baseDocument = require.resolve("../../../../../dist/components/BaseDocument.js");
|
|
11
|
-
return {
|
|
12
|
-
name: "xanix-document",
|
|
13
|
-
resolveId(id) {
|
|
14
|
-
if (id === VIRTUAL_ID) {
|
|
15
|
-
return RESOLVED_ID;
|
|
16
|
-
}
|
|
17
|
-
return null;
|
|
18
|
-
},
|
|
19
|
-
load(id) {
|
|
20
|
-
if (id !== RESOLVED_ID) {
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
23
|
-
const documentFile = fs.existsSync(userDocument)
|
|
24
|
-
? userDocument
|
|
25
|
-
: baseDocument;
|
|
26
|
-
const source = fs.readFileSync(documentFile, "utf8");
|
|
27
|
-
const hasMetadata = /\bexport\s+(?:const|let|var|function|class)\s+metadata\b/.test(source) || /\bexport\s*\{[^}]*\bmetadata\b[^}]*\}/.test(source);
|
|
28
|
-
const importPath = path.resolve(documentFile).replaceAll("\\", "/");
|
|
29
|
-
if (hasMetadata) {
|
|
30
|
-
return {
|
|
31
|
-
code: `
|
|
32
|
-
import Document, * as DocumentModule from ${JSON.stringify(importPath)};
|
|
33
|
-
|
|
34
|
-
export const metadata = DocumentModule.metadata;
|
|
35
|
-
|
|
36
|
-
export default Document;
|
|
37
|
-
`,
|
|
38
|
-
map: null,
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
return {
|
|
42
|
-
code: `
|
|
43
|
-
import Document from ${JSON.stringify(importPath)};
|
|
44
|
-
|
|
45
|
-
export const metadata = async () => ({});
|
|
46
|
-
|
|
47
|
-
export default Document;
|
|
48
|
-
`,
|
|
49
|
-
map: null,
|
|
50
|
-
};
|
|
51
|
-
},
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as t from "@babel/types";
|
|
2
|
-
import { XanixClientEntry } from "../../../types";
|
|
3
|
-
export declare function resolveFile(file: string): string;
|
|
4
|
-
export declare function resolveComponentFile(importer: string, importPath: string): string;
|
|
5
|
-
export declare function createClientId(file: string): string;
|
|
6
|
-
export declare function getJSXComponentName(node: t.JSXElement): string | null;
|
|
7
|
-
export declare function findComponentImport(ast: t.File, componentName: string): {
|
|
8
|
-
file: string;
|
|
9
|
-
export: string;
|
|
10
|
-
} | null;
|
|
11
|
-
export declare function entryFinder(code: string, id: string): XanixClientEntry[];
|
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import crypto from "node:crypto";
|
|
4
|
-
import { parse } from "@babel/parser";
|
|
5
|
-
import traverse from "@babel/traverse";
|
|
6
|
-
import * as t from "@babel/types";
|
|
7
|
-
import { normalizePath } from "../../../include/utils.js";
|
|
8
|
-
const SOURCE_EXTENSIONS = [".tsx", ".ts", ".jsx", ".js", ".mjs", ".cjs"];
|
|
9
|
-
export function resolveFile(file) {
|
|
10
|
-
const absolute = path.resolve(file);
|
|
11
|
-
if (fs.existsSync(absolute)) {
|
|
12
|
-
const stat = fs.statSync(absolute);
|
|
13
|
-
if (stat.isFile()) {
|
|
14
|
-
return absolute;
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
for (const ext of SOURCE_EXTENSIONS) {
|
|
18
|
-
const candidate = `${absolute}${ext}`;
|
|
19
|
-
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
20
|
-
return path.resolve(candidate);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
if (fs.existsSync(absolute) && fs.statSync(absolute).isDirectory()) {
|
|
24
|
-
for (const ext of SOURCE_EXTENSIONS) {
|
|
25
|
-
const candidate = path.join(absolute, `index${ext}`);
|
|
26
|
-
if (fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
|
|
27
|
-
return path.resolve(candidate);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return absolute;
|
|
32
|
-
}
|
|
33
|
-
export function resolveComponentFile(importer, importPath) {
|
|
34
|
-
if (!importPath.startsWith(".")) {
|
|
35
|
-
return importPath;
|
|
36
|
-
}
|
|
37
|
-
const base = path.resolve(path.dirname(importer), importPath);
|
|
38
|
-
return resolveFile(base);
|
|
39
|
-
}
|
|
40
|
-
export function createClientId(file) {
|
|
41
|
-
return `c_${crypto
|
|
42
|
-
.createHash("sha256")
|
|
43
|
-
.update(path.normalize(file))
|
|
44
|
-
.digest("hex")
|
|
45
|
-
.slice(0, 12)}`;
|
|
46
|
-
}
|
|
47
|
-
export function getJSXComponentName(node) {
|
|
48
|
-
const name = node.openingElement.name;
|
|
49
|
-
if (t.isJSXIdentifier(name)) {
|
|
50
|
-
return name.name;
|
|
51
|
-
}
|
|
52
|
-
if (t.isJSXMemberExpression(name)) {
|
|
53
|
-
if (t.isJSXIdentifier(name.object) && t.isJSXIdentifier(name.property)) {
|
|
54
|
-
return `${name.object.name}.${name.property.name}`;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
export function findComponentImport(ast, componentName) {
|
|
60
|
-
for (const node of ast.program.body) {
|
|
61
|
-
if (!t.isImportDeclaration(node)) {
|
|
62
|
-
continue;
|
|
63
|
-
}
|
|
64
|
-
for (const specifier of node.specifiers) {
|
|
65
|
-
if (t.isImportDefaultSpecifier(specifier) &&
|
|
66
|
-
specifier.local.name === componentName) {
|
|
67
|
-
return {
|
|
68
|
-
file: node.source.value,
|
|
69
|
-
export: "default",
|
|
70
|
-
};
|
|
71
|
-
}
|
|
72
|
-
if (t.isImportSpecifier(specifier) &&
|
|
73
|
-
specifier.local.name === componentName) {
|
|
74
|
-
const imported = specifier.imported;
|
|
75
|
-
return {
|
|
76
|
-
file: node.source.value,
|
|
77
|
-
export: t.isIdentifier(imported) ? imported.name : imported.value,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
export function entryFinder(code, id) {
|
|
85
|
-
const ast = parse(code, {
|
|
86
|
-
sourceType: "module",
|
|
87
|
-
plugins: ["typescript", "jsx"],
|
|
88
|
-
});
|
|
89
|
-
const entries = new Map();
|
|
90
|
-
traverse(ast, {
|
|
91
|
-
CallExpression(callPath) {
|
|
92
|
-
const call = callPath.node;
|
|
93
|
-
/*
|
|
94
|
-
* Find:
|
|
95
|
-
*
|
|
96
|
-
* res.send(<Home />);
|
|
97
|
-
*/
|
|
98
|
-
if (!t.isMemberExpression(call.callee)) {
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
if (!t.isIdentifier(call.callee.property, {
|
|
102
|
-
name: "send",
|
|
103
|
-
})) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
const argument = call.arguments[0];
|
|
107
|
-
if (!argument || !t.isJSXElement(argument)) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const functionPath = callPath.getFunctionParent();
|
|
111
|
-
if (!functionPath) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
const params = functionPath.node.params;
|
|
115
|
-
if (params.length < 2) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
const requestParam = params[0];
|
|
119
|
-
const responseParam = params[1];
|
|
120
|
-
if (!t.isIdentifier(requestParam) || !t.isIdentifier(responseParam)) {
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
const componentName = getJSXComponentName(argument);
|
|
124
|
-
if (!componentName) {
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
const componentImport = findComponentImport(ast, componentName);
|
|
128
|
-
if (!componentImport) {
|
|
129
|
-
return;
|
|
130
|
-
}
|
|
131
|
-
const componentImportPath = componentImport.file;
|
|
132
|
-
const componentFile = resolveComponentFile(id, componentImportPath);
|
|
133
|
-
if (!path.isAbsolute(componentFile)) {
|
|
134
|
-
return;
|
|
135
|
-
}
|
|
136
|
-
const normalizedFile = normalizePath(componentFile);
|
|
137
|
-
const clientId = createClientId(normalizedFile);
|
|
138
|
-
const entry = {
|
|
139
|
-
id: clientId,
|
|
140
|
-
name: componentName,
|
|
141
|
-
file: normalizedFile,
|
|
142
|
-
path: componentImportPath,
|
|
143
|
-
export: componentImport.export,
|
|
144
|
-
};
|
|
145
|
-
entries.set(clientId, entry);
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
return Array.from(entries.values());
|
|
149
|
-
}
|