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
|
@@ -4,7 +4,7 @@ import outdirs from "../../../outdirs.js";
|
|
|
4
4
|
const VIRTUAL_PREFIX = "\0xanix-cache:";
|
|
5
5
|
const buildCache = async (cached) => {
|
|
6
6
|
const input = {};
|
|
7
|
-
for (const [
|
|
7
|
+
for (const [, { name }] of cached) {
|
|
8
8
|
input[name] = `${VIRTUAL_PREFIX}${name}`;
|
|
9
9
|
}
|
|
10
10
|
const build = await rolldown({
|
|
@@ -49,18 +49,16 @@ const buildCache = async (cached) => {
|
|
|
49
49
|
}
|
|
50
50
|
const resolved = cache.resolved || cache.module;
|
|
51
51
|
if (cache.default) {
|
|
52
|
-
return `
|
|
53
|
-
import * as
|
|
54
|
-
|
|
55
|
-
export
|
|
56
|
-
export { __xanix_namespace };
|
|
52
|
+
return `
|
|
53
|
+
import * as __xmod from ${JSON.stringify(resolved)};
|
|
54
|
+
export default __xmod.default;
|
|
55
|
+
export { __xmod };
|
|
57
56
|
`;
|
|
58
57
|
}
|
|
59
|
-
return `
|
|
60
|
-
import * as
|
|
61
|
-
|
|
62
|
-
export
|
|
63
|
-
export { __xanix_namespace };
|
|
58
|
+
return `
|
|
59
|
+
import * as __xmod from ${JSON.stringify(resolved)};
|
|
60
|
+
export default __xmod;
|
|
61
|
+
export { __xmod };
|
|
64
62
|
`;
|
|
65
63
|
},
|
|
66
64
|
},
|
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { isPackageImport, makeFilename } from "./utils.js";
|
|
2
|
+
import { isPackageImport, makeFilename, readManifest, writeManifest, } from "./utils.js";
|
|
3
3
|
import buildCache from "./buildCache.js";
|
|
4
|
-
import { walk } from "oxc-walker";
|
|
5
4
|
import { builtinModules } from "node:module";
|
|
6
|
-
import { readManifest, writeManifest } from "./manifest.js";
|
|
7
5
|
import logger from "../../include/logger.js";
|
|
8
6
|
import pc from "picocolors";
|
|
7
|
+
import findImports from "../../finder/findImports.js";
|
|
9
8
|
const nodeBuiltins = new Set(builtinModules);
|
|
10
9
|
function isNodeBuiltin(id) {
|
|
11
10
|
const normalized = id.startsWith("node:") ? id.slice(5) : id;
|
|
12
11
|
return nodeBuiltins.has(normalized);
|
|
13
12
|
}
|
|
14
13
|
const require = createRequire(import.meta.url);
|
|
15
|
-
function getParserLanguage(id) {
|
|
16
|
-
const cleanId = id.split("?")[0];
|
|
17
|
-
if (cleanId.endsWith(".tsx"))
|
|
18
|
-
return "tsx";
|
|
19
|
-
if (cleanId.endsWith(".ts"))
|
|
20
|
-
return "ts";
|
|
21
|
-
if (cleanId.endsWith(".jsx"))
|
|
22
|
-
return "jsx";
|
|
23
|
-
return "js";
|
|
24
|
-
}
|
|
25
14
|
function makeImportName(name) {
|
|
26
15
|
return `require_${name.replace(/[^a-zA-Z0-9_$]/g, "_")}`;
|
|
27
16
|
}
|
|
@@ -30,12 +19,6 @@ const XanixCache = () => {
|
|
|
30
19
|
let init = false;
|
|
31
20
|
return {
|
|
32
21
|
name: "__xmod",
|
|
33
|
-
buildStart() {
|
|
34
|
-
cached.clear();
|
|
35
|
-
},
|
|
36
|
-
watchChange() {
|
|
37
|
-
cached.clear();
|
|
38
|
-
},
|
|
39
22
|
async resolveId(source) {
|
|
40
23
|
if (source.startsWith("/__xmod")) {
|
|
41
24
|
return {
|
|
@@ -52,102 +35,68 @@ const XanixCache = () => {
|
|
|
52
35
|
if (!code.includes("import ") && !code.includes("import(")) {
|
|
53
36
|
return null;
|
|
54
37
|
}
|
|
55
|
-
const lang = getParserLanguage(id);
|
|
56
|
-
const ast = this.parse(code, { lang });
|
|
57
38
|
const packages = [];
|
|
58
39
|
let replacements = [];
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
const imported = specifier.imported?.type === "Identifier"
|
|
111
|
-
? specifier.imported.name
|
|
112
|
-
: specifier.imported?.value;
|
|
113
|
-
const local = specifier.local?.name;
|
|
114
|
-
if (!imported || !local) {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
if (imported !== local) {
|
|
118
|
-
if (typeof imported === "string" &&
|
|
119
|
-
!/^[$A-Z_a-z][$\w]*$/.test(imported)) {
|
|
120
|
-
return `${JSON.stringify(imported)}: ${local}`;
|
|
121
|
-
}
|
|
122
|
-
return `${imported}: ${local}`;
|
|
123
|
-
}
|
|
124
|
-
return imported;
|
|
125
|
-
})
|
|
126
|
-
.filter(Boolean)
|
|
127
|
-
.join(", ");
|
|
128
|
-
if (properties) {
|
|
129
|
-
lines.push(`const { ${properties} } = ${namespaceName};`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (!cached.has(source)) {
|
|
135
|
-
cached.set(source, {
|
|
136
|
-
module: source,
|
|
137
|
-
name,
|
|
138
|
-
resolved: "",
|
|
139
|
-
exports: [],
|
|
140
|
-
default: false,
|
|
141
|
-
});
|
|
142
|
-
}
|
|
143
|
-
replacements.push({
|
|
144
|
-
source,
|
|
145
|
-
start: node.start,
|
|
146
|
-
end: node.end,
|
|
147
|
-
value: lines.join("\n"),
|
|
40
|
+
let counter = 0;
|
|
41
|
+
for (const imp of findImports(code)) {
|
|
42
|
+
if (imp.typeOnly)
|
|
43
|
+
continue;
|
|
44
|
+
const source = imp.source;
|
|
45
|
+
if (!isPackageImport(source) || isNodeBuiltin(source))
|
|
46
|
+
continue;
|
|
47
|
+
/*
|
|
48
|
+
* Don't add the same package multiple times
|
|
49
|
+
* when the file imports it more than once.
|
|
50
|
+
*/
|
|
51
|
+
if (!packages.includes(source)) {
|
|
52
|
+
packages.push(source);
|
|
53
|
+
}
|
|
54
|
+
const name = makeFilename(source);
|
|
55
|
+
const cachePath = `/__xmod/${name}.js`;
|
|
56
|
+
const named = imp.named.filter((s) => !s.typeOnly);
|
|
57
|
+
/*
|
|
58
|
+
* Unique per import statement (require_react, require_react1, ...)
|
|
59
|
+
* so the same package imported twice never redeclares a binding.
|
|
60
|
+
*/
|
|
61
|
+
const local = `${makeImportName(name)}${counter++ || ""}`;
|
|
62
|
+
const mod = `_${local}`; // `import * as` keeps this name in the bundle
|
|
63
|
+
const ns = `${mod}.__xmod`;
|
|
64
|
+
const bindings = [];
|
|
65
|
+
if (imp.default)
|
|
66
|
+
bindings.push(local);
|
|
67
|
+
if (imp.namespace || named.length)
|
|
68
|
+
bindings.push(`* as ${mod}`);
|
|
69
|
+
const lines = [
|
|
70
|
+
bindings.length
|
|
71
|
+
? `import ${bindings.join(", ")} from "${cachePath}";`
|
|
72
|
+
: `import "${cachePath}";`,
|
|
73
|
+
];
|
|
74
|
+
if (imp.default)
|
|
75
|
+
lines.push(`const ${imp.default} = ${local};`);
|
|
76
|
+
if (imp.namespace)
|
|
77
|
+
lines.push(`const ${imp.namespace} = ${ns};`);
|
|
78
|
+
if (named.length) {
|
|
79
|
+
const props = named
|
|
80
|
+
.map(({ imported, local }) => imported !== local ? `${imported}: ${local}` : imported)
|
|
81
|
+
.join(", ");
|
|
82
|
+
lines.push(`const { ${props} } = ${ns};`);
|
|
83
|
+
}
|
|
84
|
+
if (!cached.has(source)) {
|
|
85
|
+
cached.set(source, {
|
|
86
|
+
module: source,
|
|
87
|
+
name,
|
|
88
|
+
resolved: "",
|
|
89
|
+
exports: [],
|
|
90
|
+
default: false,
|
|
148
91
|
});
|
|
149
|
-
}
|
|
150
|
-
|
|
92
|
+
}
|
|
93
|
+
replacements.push({
|
|
94
|
+
source,
|
|
95
|
+
start: imp.start,
|
|
96
|
+
end: imp.end,
|
|
97
|
+
value: lines.join("\n"),
|
|
98
|
+
});
|
|
99
|
+
}
|
|
151
100
|
if (!replacements.length) {
|
|
152
101
|
return null;
|
|
153
102
|
}
|
|
@@ -162,7 +111,10 @@ const XanixCache = () => {
|
|
|
162
111
|
continue;
|
|
163
112
|
try {
|
|
164
113
|
const resolved = await this.resolve(source, id);
|
|
165
|
-
if (!resolved?.id
|
|
114
|
+
if (!resolved?.id) {
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
if (!resolved.id.includes("node_modules")) {
|
|
166
118
|
throw new Error(`Resolved module ${resolved.id} is not in node_modules`);
|
|
167
119
|
}
|
|
168
120
|
cache.resolved = resolved.id;
|
|
@@ -196,10 +148,12 @@ const XanixCache = () => {
|
|
|
196
148
|
};
|
|
197
149
|
},
|
|
198
150
|
async generateBundle() {
|
|
151
|
+
const current = new Map(cached);
|
|
152
|
+
cached.clear();
|
|
199
153
|
// write manifest
|
|
200
154
|
const cachedManifest = await readManifest();
|
|
201
155
|
const pmodules = Array.from(cachedManifest.values()).map((m) => m.module);
|
|
202
|
-
const cmodule = Array.from(
|
|
156
|
+
const cmodule = Array.from(current.values()).map((m) => m.module);
|
|
203
157
|
const hasChanges = pmodules.some((m) => !cmodule.includes(m)) ||
|
|
204
158
|
cmodule.some((m) => !pmodules.includes(m));
|
|
205
159
|
if (hasChanges) {
|
|
@@ -207,8 +161,8 @@ const XanixCache = () => {
|
|
|
207
161
|
logger.info(`${pc.yellow("Optimizing dependencies")} `, "[optimize]");
|
|
208
162
|
}
|
|
209
163
|
init = true;
|
|
210
|
-
await buildCache(
|
|
211
|
-
await writeManifest(
|
|
164
|
+
await buildCache(current);
|
|
165
|
+
await writeManifest(current);
|
|
212
166
|
}
|
|
213
167
|
},
|
|
214
168
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import type { CachedMap } from "./types.js";
|
|
1
2
|
export declare function isPackageImport(source: string): boolean;
|
|
2
3
|
export declare const makeFilename: (id: string) => string;
|
|
3
|
-
export declare const writeCacheManifest: (cached: Map<string, string>) => Promise<void>;
|
|
4
|
-
export declare const readCacheManifest: () => Promise<Map<any, any>>;
|
|
5
4
|
export declare function isNodeBuiltin(id: string): boolean;
|
|
5
|
+
export declare const writeManifest: (manifest: CachedMap) => Promise<void>;
|
|
6
|
+
export declare const readManifest: () => Promise<CachedMap>;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
import fs from "fs";
|
|
2
|
-
import path from "path";
|
|
1
|
+
import fs from "fs/promises";
|
|
3
2
|
import { builtinModules } from "node:module";
|
|
3
|
+
import outdirs from "../../../outdirs.js";
|
|
4
|
+
const nodeBuiltins = new Set(builtinModules);
|
|
4
5
|
export function isPackageImport(source) {
|
|
5
|
-
// Relative import
|
|
6
6
|
if (source.startsWith("./") || source.startsWith("../")) {
|
|
7
7
|
return false;
|
|
8
8
|
}
|
|
9
|
-
// Absolute filesystem path
|
|
10
9
|
if (source.startsWith("/") || /^[A-Za-z]:[\\/]/.test(source)) {
|
|
11
10
|
return false;
|
|
12
11
|
}
|
|
13
|
-
// URL / virtual module
|
|
14
12
|
if (source.startsWith("node:") ||
|
|
15
13
|
source.includes(":") ||
|
|
16
14
|
source.startsWith("\0")) {
|
|
17
15
|
return false;
|
|
18
16
|
}
|
|
19
|
-
// Everything else is a bare package specifier
|
|
20
17
|
return true;
|
|
21
18
|
}
|
|
22
19
|
export const makeFilename = (id) => {
|
|
@@ -31,26 +28,32 @@ export const makeFilename = (id) => {
|
|
|
31
28
|
.split("?")[0];
|
|
32
29
|
return id;
|
|
33
30
|
};
|
|
34
|
-
export
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
31
|
+
export function isNodeBuiltin(id) {
|
|
32
|
+
const normalized = id.startsWith("node:") ? id.slice(5) : id;
|
|
33
|
+
return nodeBuiltins.has(normalized);
|
|
34
|
+
}
|
|
35
|
+
const manifestFile = `${outdirs.module_cache}/manifest.json`;
|
|
36
|
+
export const writeManifest = async (manifest) => {
|
|
37
|
+
const data = Array.from(manifest.values());
|
|
38
|
+
for (const item of data) {
|
|
39
|
+
delete item.exports;
|
|
40
|
+
delete item.default;
|
|
41
|
+
delete item.resolved;
|
|
42
|
+
delete item.name;
|
|
39
43
|
}
|
|
40
|
-
await fs.
|
|
44
|
+
await fs.writeFile(manifestFile, JSON.stringify(data, null, 2), "utf-8");
|
|
41
45
|
};
|
|
42
|
-
export const
|
|
43
|
-
|
|
44
|
-
|
|
46
|
+
export const readManifest = async () => {
|
|
47
|
+
try {
|
|
48
|
+
const content = await fs.readFile(manifestFile, "utf-8");
|
|
49
|
+
const parsed = JSON.parse(content);
|
|
50
|
+
let data = new Map();
|
|
51
|
+
for (let p of parsed) {
|
|
52
|
+
data.set(p.module, p);
|
|
53
|
+
}
|
|
54
|
+
return data;
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
45
57
|
return new Map();
|
|
46
58
|
}
|
|
47
|
-
const content = await fs.promises.readFile(file, "utf-8");
|
|
48
|
-
const parsed = JSON.parse(content);
|
|
49
|
-
const map = new Map(Object.entries(parsed));
|
|
50
|
-
return map;
|
|
51
59
|
};
|
|
52
|
-
const nodeBuiltins = new Set(builtinModules);
|
|
53
|
-
export function isNodeBuiltin(id) {
|
|
54
|
-
const normalized = id.startsWith("node:") ? id.slice(5) : id;
|
|
55
|
-
return nodeBuiltins.has(normalized);
|
|
56
|
-
}
|
|
@@ -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,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 TransformCreateSession = (code, imports, uid, source) => {
|
|
4
4
|
let count = 0;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { CachedModule } from "../Transformer.js";
|
|
2
|
+
declare class TransformDevModule {
|
|
3
|
+
replacements: {
|
|
4
|
+
start: number;
|
|
5
|
+
end: number;
|
|
6
|
+
value: string;
|
|
7
|
+
}[];
|
|
8
|
+
packages: string[];
|
|
9
|
+
cached: Map<string, CachedModule>;
|
|
10
|
+
constructor(cached: Map<string, CachedModule>);
|
|
11
|
+
transform(node: any): void;
|
|
12
|
+
}
|
|
13
|
+
export default TransformDevModule;
|
|
@@ -1,25 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isPackageImport, makeFilename } from "../../../cache/utils.js";
|
|
3
|
-
const nodeBuiltins = new Set(builtinModules);
|
|
4
|
-
function isNodeBuiltin(id) {
|
|
5
|
-
const normalized = id.startsWith("node:") ? id.slice(5) : id;
|
|
6
|
-
return nodeBuiltins.has(normalized);
|
|
7
|
-
}
|
|
1
|
+
import { isPackageImport, makeFilename, isNodeBuiltin, } from "../../../cache/utils.js";
|
|
8
2
|
function makeImportName(name) {
|
|
9
3
|
return `require_${name.replace(/[^a-zA-Z0-9_$]/g, "_")}`;
|
|
10
4
|
}
|
|
11
|
-
|
|
12
|
-
const safeName = moduleName
|
|
13
|
-
.replace(/^@/, "")
|
|
14
|
-
.replace(/[\/\\]/g, "_")
|
|
15
|
-
.replace(/[^a-zA-Z0-9_$.-]/g, "_");
|
|
16
|
-
return `/cache/${safeName}.js`;
|
|
17
|
-
}
|
|
18
|
-
class TransformModuleCache {
|
|
5
|
+
class TransformDevModule {
|
|
19
6
|
constructor(cached) {
|
|
7
|
+
this.replacements = [];
|
|
20
8
|
this.packages = [];
|
|
21
9
|
this.replacements = [];
|
|
22
|
-
this.
|
|
10
|
+
this.packages = [];
|
|
23
11
|
this.cached = cached;
|
|
24
12
|
}
|
|
25
13
|
transform(node) {
|
|
@@ -101,7 +89,7 @@ class TransformModuleCache {
|
|
|
101
89
|
* Add the package only once.
|
|
102
90
|
*/
|
|
103
91
|
if (!this.cached.has(source)) {
|
|
104
|
-
|
|
92
|
+
// cacheChanged = true;
|
|
105
93
|
this.cached.set(source, {
|
|
106
94
|
module: source,
|
|
107
95
|
name,
|
|
@@ -117,4 +105,4 @@ class TransformModuleCache {
|
|
|
117
105
|
});
|
|
118
106
|
}
|
|
119
107
|
}
|
|
120
|
-
export default
|
|
108
|
+
export default TransformDevModule;
|
|
@@ -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,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 TransformServerFunction = (code, imports, uid, source) => {
|
|
4
4
|
let count = 0;
|
|
@@ -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,32 @@
|
|
|
1
|
+
import callbackReplacer from "../../../../modifier/callbackReplacer.js";
|
|
2
|
+
import { framworkDir } from "../../../../include/path.js";
|
|
3
|
+
const cacheFunctionTransformer = (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 cacheFunctionTransformer;
|
|
@@ -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}(undefined, ${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;
|