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
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import fs from "node:fs";
|
|
3
|
-
import { getClientRuntimeFile } from "../../include/utils.js";
|
|
4
|
-
const root = process.cwd();
|
|
5
|
-
function getLanguage(id) {
|
|
6
|
-
const filename = id.split("?")[0];
|
|
7
|
-
if (filename.endsWith(".tsx")) {
|
|
8
|
-
return "tsx";
|
|
9
|
-
}
|
|
10
|
-
if (filename.endsWith(".ts")) {
|
|
11
|
-
return "ts";
|
|
12
|
-
}
|
|
13
|
-
if (filename.endsWith(".jsx")) {
|
|
14
|
-
return "jsx";
|
|
15
|
-
}
|
|
16
|
-
return "js";
|
|
17
|
-
}
|
|
18
|
-
function isReactComponent(name) {
|
|
19
|
-
return /^[A-Z][A-Za-z0-9_$]*$/.test(name);
|
|
20
|
-
}
|
|
21
|
-
function walk(node, callback) {
|
|
22
|
-
if (!node || typeof node !== "object") {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
if (Array.isArray(node)) {
|
|
26
|
-
for (const child of node) {
|
|
27
|
-
walk(child, callback);
|
|
28
|
-
}
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const current = node;
|
|
32
|
-
callback(current);
|
|
33
|
-
for (const key of Object.keys(current)) {
|
|
34
|
-
if (key === "parent" ||
|
|
35
|
-
key === "loc" ||
|
|
36
|
-
key === "range" ||
|
|
37
|
-
key === "tokens" ||
|
|
38
|
-
key === "comments") {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
const value = current[key];
|
|
42
|
-
if (value && typeof value === "object") {
|
|
43
|
-
walk(value, callback);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function collectRegistrations(program, filename) {
|
|
48
|
-
const registrations = [];
|
|
49
|
-
walk(program, (node) => {
|
|
50
|
-
if (node.type === "FunctionDeclaration") {
|
|
51
|
-
const id = node.id;
|
|
52
|
-
if (!id || id.type !== "Identifier" || !id.name) {
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
const name = id.name;
|
|
56
|
-
if (!isReactComponent(name)) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
registrations.push(createRegistration(name, filename));
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (node.type !== "VariableDeclarator") {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
const id = node.id;
|
|
66
|
-
const init = node.init;
|
|
67
|
-
if (!id || id.type !== "Identifier" || !id.name) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!init) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
if (init.type !== "ArrowFunctionExpression" &&
|
|
74
|
-
init.type !== "FunctionExpression") {
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const name = id.name;
|
|
78
|
-
if (!isReactComponent(name)) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
registrations.push(createRegistration(name, filename));
|
|
82
|
-
});
|
|
83
|
-
return registrations;
|
|
84
|
-
}
|
|
85
|
-
function createRegistration(name, filename) {
|
|
86
|
-
const relative = path
|
|
87
|
-
.relative(root, filename.split("?")[0])
|
|
88
|
-
.replaceAll("\\", "/");
|
|
89
|
-
const componentId = `${relative}:${name}`;
|
|
90
|
-
return `$RefreshReg$(${name}, ${JSON.stringify(componentId)});`;
|
|
91
|
-
}
|
|
92
|
-
export default function xanixReactRefresh(webSocketPort) {
|
|
93
|
-
return {
|
|
94
|
-
name: "xanix-react-refresh",
|
|
95
|
-
load(id) {
|
|
96
|
-
if (path.resolve(id) !== getClientRuntimeFile()) {
|
|
97
|
-
return null;
|
|
98
|
-
}
|
|
99
|
-
const code = fs.readFileSync(id, "utf8");
|
|
100
|
-
const refreshCode = `
|
|
101
|
-
|
|
102
|
-
import RefreshRuntime from "react-refresh/runtime";
|
|
103
|
-
RefreshRuntime.injectIntoGlobalHook(window);
|
|
104
|
-
window.$RefreshReg$ = (type, id) => {
|
|
105
|
-
RefreshRuntime.register(type, id);
|
|
106
|
-
};
|
|
107
|
-
window.$RefreshSig$ = () => (type) => type;
|
|
108
|
-
|
|
109
|
-
const ws = new WebSocket(
|
|
110
|
-
${JSON.stringify(`ws://localhost:${49152}`)}
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
ws.onmessage = async (event) => {
|
|
114
|
-
const files = JSON.parse(event.data);
|
|
115
|
-
|
|
116
|
-
for (const file of files) {
|
|
117
|
-
if (!file.endsWith(".js")) {
|
|
118
|
-
continue;
|
|
119
|
-
}
|
|
120
|
-
const url =
|
|
121
|
-
getImportUrl(
|
|
122
|
-
file.replace(/\.js$/, "")
|
|
123
|
-
) +
|
|
124
|
-
"?t=" +
|
|
125
|
-
Date.now();
|
|
126
|
-
|
|
127
|
-
await import(url);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
RefreshRuntime.performReactRefresh();
|
|
131
|
-
|
|
132
|
-
ws.send("reload");
|
|
133
|
-
};
|
|
134
|
-
${code}
|
|
135
|
-
|
|
136
|
-
`;
|
|
137
|
-
return {
|
|
138
|
-
code: refreshCode,
|
|
139
|
-
map: null,
|
|
140
|
-
};
|
|
141
|
-
},
|
|
142
|
-
transform: {
|
|
143
|
-
filter: {
|
|
144
|
-
id: /^(?!.*node_modules[\\/]).*\.[cm]?[jt]sx?$/,
|
|
145
|
-
},
|
|
146
|
-
handler(code, id) {
|
|
147
|
-
const resolvedId = path.resolve(id);
|
|
148
|
-
if (resolvedId === getClientRuntimeFile()) {
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
const filename = id.split("?")[0];
|
|
152
|
-
if (!/\.(tsx?|jsx?)$/.test(filename)) {
|
|
153
|
-
return null;
|
|
154
|
-
}
|
|
155
|
-
const program = this.parse(code, {
|
|
156
|
-
lang: getLanguage(filename),
|
|
157
|
-
});
|
|
158
|
-
const registrations = collectRegistrations(program, filename);
|
|
159
|
-
if (registrations.length === 0) {
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
const registrationCode = `\n\n${registrations.join("\n")}\n`;
|
|
163
|
-
return {
|
|
164
|
-
code: code + registrationCode,
|
|
165
|
-
map: null,
|
|
166
|
-
};
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
};
|
|
170
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { XanixClientEntry } from "../../../types";
|
|
2
|
-
export type DependencyInfo = {
|
|
3
|
-
source: string;
|
|
4
|
-
resolved: string;
|
|
5
|
-
packageName: string;
|
|
6
|
-
};
|
|
7
|
-
export type CacheMetadata = Map<string, {
|
|
8
|
-
file: string;
|
|
9
|
-
}>;
|
|
10
|
-
declare const BuildClientCache: (entries: XanixClientEntry[], metadata?: CacheMetadata) => Promise<CacheMetadata>;
|
|
11
|
-
export default BuildClientCache;
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { rollup } from "rollup";
|
|
3
|
-
import { build } from "esbuild";
|
|
4
|
-
import { builtinModules, createRequire } from "node:module";
|
|
5
|
-
import { getClientRuntimeFile } from "../../../include/utils.js";
|
|
6
|
-
import outdirs from "../../../../outdirs.js";
|
|
7
|
-
import { xanixCachePlugins } from "../plugins.js";
|
|
8
|
-
import defines from "../../config/defines.js";
|
|
9
|
-
import { pathToFileURL } from "node:url";
|
|
10
|
-
import external from "../../config/external.js";
|
|
11
|
-
const require = createRequire(import.meta.url);
|
|
12
|
-
const nodeBuiltins = new Set(builtinModules.flatMap((id) => [id, `node:${id}`]));
|
|
13
|
-
const GenerateGraph = async (entries) => {
|
|
14
|
-
const collector = new Map();
|
|
15
|
-
const input = [];
|
|
16
|
-
for (const entry of entries) {
|
|
17
|
-
input.push(entry.file);
|
|
18
|
-
}
|
|
19
|
-
input.push(getClientRuntimeFile());
|
|
20
|
-
const bundle = await rollup({
|
|
21
|
-
input,
|
|
22
|
-
plugins: [...xanixCachePlugins()],
|
|
23
|
-
external(id) {
|
|
24
|
-
if (nodeBuiltins.has(id)) {
|
|
25
|
-
return true;
|
|
26
|
-
}
|
|
27
|
-
if (!external(id)) {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
collector.set(id, {
|
|
31
|
-
source: id,
|
|
32
|
-
resolved: require.resolve(id, {
|
|
33
|
-
paths: [process.cwd()],
|
|
34
|
-
}),
|
|
35
|
-
packageName: id,
|
|
36
|
-
});
|
|
37
|
-
return true;
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
await bundle.close();
|
|
41
|
-
return collector;
|
|
42
|
-
};
|
|
43
|
-
// Wraps each CJS dep in a virtual ESM file that re-exports named exports detected via require()
|
|
44
|
-
const makeCjsWrapperPlugin = (wrappers) => ({
|
|
45
|
-
name: "cjs-named-exports",
|
|
46
|
-
setup(build) {
|
|
47
|
-
build.onResolve({ filter: /\?cjs-wrapper$/ }, (args) => ({
|
|
48
|
-
path: args.path,
|
|
49
|
-
namespace: "cjs-wrapper",
|
|
50
|
-
}));
|
|
51
|
-
build.onLoad({ filter: /.*/, namespace: "cjs-wrapper" }, (args) => {
|
|
52
|
-
const contents = wrappers.get(args.path);
|
|
53
|
-
return { contents, resolveDir: process.cwd() };
|
|
54
|
-
});
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
const buildWrappers = async (input) => {
|
|
58
|
-
const wrappers = new Map();
|
|
59
|
-
const wrappedInput = {};
|
|
60
|
-
for (const [name, resolved] of Object.entries(input)) {
|
|
61
|
-
const key = `${name}?cjs-wrapper`;
|
|
62
|
-
let namedExports = [];
|
|
63
|
-
let hasDefault = false;
|
|
64
|
-
try {
|
|
65
|
-
// Node: inspect the actual module
|
|
66
|
-
const mod = await import(pathToFileURL(resolved).href);
|
|
67
|
-
hasDefault =
|
|
68
|
-
mod &&
|
|
69
|
-
(typeof mod === "object" || typeof mod === "function") &&
|
|
70
|
-
"default" in mod;
|
|
71
|
-
namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
72
|
-
}
|
|
73
|
-
catch (err) {
|
|
74
|
-
console.log(`Failed to inspect ${name}:`, err);
|
|
75
|
-
}
|
|
76
|
-
// esbuild: use a normal filesystem path
|
|
77
|
-
const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
|
|
78
|
-
if (hasDefault) {
|
|
79
|
-
lines.push(`export default __mod.default;`);
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
lines.push(`export default __mod;`);
|
|
83
|
-
}
|
|
84
|
-
for (const exportName of namedExports) {
|
|
85
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
86
|
-
lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
wrappers.set(key, lines.join("\n"));
|
|
90
|
-
wrappedInput[name] = key;
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
wrappers,
|
|
94
|
-
wrappedInput,
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
const bundleDeps = async (input, outdir) => {
|
|
98
|
-
const { wrappers, wrappedInput } = await buildWrappers(input);
|
|
99
|
-
await build({
|
|
100
|
-
entryPoints: wrappedInput,
|
|
101
|
-
bundle: true,
|
|
102
|
-
splitting: true,
|
|
103
|
-
format: "esm",
|
|
104
|
-
target: "es2022",
|
|
105
|
-
outdir,
|
|
106
|
-
entryNames: "[name]",
|
|
107
|
-
chunkNames: "chunks/[hash]",
|
|
108
|
-
platform: "browser",
|
|
109
|
-
sourcemap: true,
|
|
110
|
-
define: defines({ mode: "development", isClient: true }),
|
|
111
|
-
plugins: [makeCjsWrapperPlugin(wrappers)],
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
// const metadata: CacheMetadata = new Map();
|
|
115
|
-
const BuildClientCache = async (entries, metadata = new Map()) => {
|
|
116
|
-
const input = {};
|
|
117
|
-
const dependencies = await GenerateGraph(entries);
|
|
118
|
-
for (const dependency of dependencies.values()) {
|
|
119
|
-
const entryName = dependency.source.replace(/^@/, "").replace(/\//g, "-");
|
|
120
|
-
input[entryName] = dependency.resolved;
|
|
121
|
-
metadata.set(dependency.source, {
|
|
122
|
-
file: `${entryName}.js`,
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
const cacheDir = path.resolve(outdirs.server, "cache");
|
|
126
|
-
await bundleDeps(input, cacheDir);
|
|
127
|
-
return metadata;
|
|
128
|
-
};
|
|
129
|
-
export default BuildClientCache;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type Plugin } from "rolldown";
|
|
2
|
-
export type CacheDepsPluginOptions = {
|
|
3
|
-
/** Directory where built dependency bundles + manifest.json are written. */
|
|
4
|
-
cacheDir: string;
|
|
5
|
-
/** Return true for ids that should be pulled from the dep cache instead of bundled inline. */
|
|
6
|
-
isExternal: (id: string) => boolean;
|
|
7
|
-
/** URL prefix the dev server serves cacheDir under. Default "/__cache__/". */
|
|
8
|
-
publicPath?: string;
|
|
9
|
-
/** esbuild-style define map applied when building each cached dep. */
|
|
10
|
-
define?: Record<string, string>;
|
|
11
|
-
/** Log every resolveId decision to the console. Use temporarily to diagnose why nothing's caching. */
|
|
12
|
-
debug?: boolean;
|
|
13
|
-
};
|
|
14
|
-
export declare const cacheDepsPlugin: (options: CacheDepsPluginOptions) => Plugin;
|
|
15
|
-
export default cacheDepsPlugin;
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs";
|
|
2
|
-
import path from "node:path";
|
|
3
|
-
import crypto from "node:crypto";
|
|
4
|
-
import { rolldown } from "rolldown";
|
|
5
|
-
import { builtinModules, createRequire } from "node:module";
|
|
6
|
-
import { pathToFileURL } from "node:url";
|
|
7
|
-
const require = createRequire(import.meta.url);
|
|
8
|
-
const nodeBuiltins = new Set(builtinModules.flatMap((id) => [id, `node:${id}`]));
|
|
9
|
-
const readManifest = (cacheDir) => {
|
|
10
|
-
const file = path.join(cacheDir, "manifest.json");
|
|
11
|
-
try {
|
|
12
|
-
return JSON.parse(fs.readFileSync(file, "utf8"));
|
|
13
|
-
}
|
|
14
|
-
catch {
|
|
15
|
-
return {};
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
const writeManifest = (cacheDir, manifest) => {
|
|
19
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
20
|
-
fs.writeFileSync(path.join(cacheDir, "manifest.json"), JSON.stringify(manifest, null, 2));
|
|
21
|
-
};
|
|
22
|
-
// Cheap, fast fingerprint: mtime + size of the resolved entry file.
|
|
23
|
-
const fingerprint = (resolved) => {
|
|
24
|
-
const stat = fs.statSync(resolved);
|
|
25
|
-
return `${stat.size}-${stat.mtimeMs}`;
|
|
26
|
-
};
|
|
27
|
-
const entryNameFor = (source) => source.replace(/^@/, "").replace(/\//g, "-");
|
|
28
|
-
// Ids owned by other plugins: virtual modules (foo:bar convention), rollup's
|
|
29
|
-
// null-byte convention (\0foo), or anything else that isn't a real bare npm
|
|
30
|
-
// specifier. require.resolve() can never find these on disk — don't try.
|
|
31
|
-
const isVirtualId = (id) => id.startsWith("\0") || /^[a-zA-Z][\w+.-]*:/.test(id);
|
|
32
|
-
// Inspects the resolved CJS/ESM module and generates a small ESM shim that
|
|
33
|
-
// re-exports its default + named exports, so rolldown always sees a clean ESM entry.
|
|
34
|
-
const makeEsmShim = async (resolved) => {
|
|
35
|
-
let namedExports = [];
|
|
36
|
-
let hasDefault = false;
|
|
37
|
-
try {
|
|
38
|
-
const mod = await import(pathToFileURL(resolved).href);
|
|
39
|
-
hasDefault =
|
|
40
|
-
mod &&
|
|
41
|
-
(typeof mod === "object" || typeof mod === "function") &&
|
|
42
|
-
"default" in mod;
|
|
43
|
-
namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
44
|
-
}
|
|
45
|
-
catch (err) {
|
|
46
|
-
console.warn(`[cache-deps] failed to inspect ${resolved}:`, err);
|
|
47
|
-
}
|
|
48
|
-
const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
|
|
49
|
-
lines.push(hasDefault ? `export default __mod.default;` : `export default __mod;`);
|
|
50
|
-
for (const exportName of namedExports) {
|
|
51
|
-
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
52
|
-
lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return lines.join("\n");
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Builds and resolves cached dependency bundles for a rolldown build.
|
|
59
|
-
*
|
|
60
|
-
* Key property: when a cached package itself imports another package that
|
|
61
|
-
* `isExternal` also matches (e.g. a UI lib importing "react"), that nested
|
|
62
|
-
* import is NOT inlined into the package's bundle. It's resolved through
|
|
63
|
-
* this same cache, so every consumer — the app and every cached dep alike —
|
|
64
|
-
* shares exactly one built copy of "react". That's what prevents duplicate-
|
|
65
|
-
* React ("Invalid hook call" / "Cannot read properties of null (reading
|
|
66
|
-
* 'useContext')") bugs.
|
|
67
|
-
*/
|
|
68
|
-
class DepCache {
|
|
69
|
-
constructor(cacheDir, isExternal, define, publicPath) {
|
|
70
|
-
this.cacheDir = cacheDir;
|
|
71
|
-
this.isExternal = isExternal;
|
|
72
|
-
this.define = define;
|
|
73
|
-
this.publicPath = publicPath;
|
|
74
|
-
this.inflight = new Map();
|
|
75
|
-
this.building = new Set();
|
|
76
|
-
fs.mkdirSync(cacheDir, { recursive: true });
|
|
77
|
-
this.manifest = readManifest(cacheDir);
|
|
78
|
-
}
|
|
79
|
-
/** Resolves `source` (imported from `importerDir`) to a cache filename, building if needed.
|
|
80
|
-
* Returns null if `source` isn't resolvable as a real filesystem module (e.g. a virtual id
|
|
81
|
-
* another plugin owns) — caller should defer to the rest of the plugin chain in that case. */
|
|
82
|
-
resolveFile(source, importerDir) {
|
|
83
|
-
let p = this.inflight.get(source);
|
|
84
|
-
if (!p) {
|
|
85
|
-
p = this.build(source, importerDir);
|
|
86
|
-
this.inflight.set(source, p);
|
|
87
|
-
}
|
|
88
|
-
return p;
|
|
89
|
-
}
|
|
90
|
-
async build(source, importerDir) {
|
|
91
|
-
let resolved;
|
|
92
|
-
try {
|
|
93
|
-
resolved = require.resolve(source, { paths: [importerDir] });
|
|
94
|
-
}
|
|
95
|
-
catch {
|
|
96
|
-
return null; // not a real module on disk — not ours to handle
|
|
97
|
-
}
|
|
98
|
-
const key = fingerprint(resolved);
|
|
99
|
-
const cached = this.manifest[source];
|
|
100
|
-
if (cached &&
|
|
101
|
-
cached.key === key &&
|
|
102
|
-
fs.existsSync(path.join(this.cacheDir, cached.file))) {
|
|
103
|
-
return cached.file;
|
|
104
|
-
}
|
|
105
|
-
const entryName = entryNameFor(source);
|
|
106
|
-
const hash = crypto
|
|
107
|
-
.createHash("sha1")
|
|
108
|
-
.update(resolved + key)
|
|
109
|
-
.digest("hex")
|
|
110
|
-
.slice(0, 8);
|
|
111
|
-
const file = `${entryName}.${hash}.js`;
|
|
112
|
-
const outFile = path.join(this.cacheDir, file);
|
|
113
|
-
// Guard against circular "cached package A imports cached package B
|
|
114
|
-
// imports A" — fall back to inlining on the cycle edge instead of
|
|
115
|
-
// deadlocking on inflight promises.
|
|
116
|
-
const isCycle = this.building.has(source);
|
|
117
|
-
this.building.add(source);
|
|
118
|
-
try {
|
|
119
|
-
await this.bundle(source, resolved, outFile, !isCycle);
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
console.error(`[cache-deps] failed to build "${source}" (${resolved}) — falling back to inline bundling:`, err);
|
|
123
|
-
return null; // don't kill the whole build; let rolldown bundle it normally
|
|
124
|
-
}
|
|
125
|
-
finally {
|
|
126
|
-
this.building.delete(source);
|
|
127
|
-
}
|
|
128
|
-
this.manifest[source] = { source, resolved, file, key };
|
|
129
|
-
writeManifest(this.cacheDir, this.manifest);
|
|
130
|
-
return file;
|
|
131
|
-
}
|
|
132
|
-
async bundle(source, resolved, outFile, dedupeExternals) {
|
|
133
|
-
const shimId = `\0cache-deps-shim:${source}`;
|
|
134
|
-
const shimCode = await makeEsmShim(resolved);
|
|
135
|
-
const depDir = path.dirname(resolved);
|
|
136
|
-
const plugin = {
|
|
137
|
-
name: "cache-deps-shim",
|
|
138
|
-
resolveId: async (id) => {
|
|
139
|
-
if (id === shimId)
|
|
140
|
-
return shimId;
|
|
141
|
-
if (id.startsWith(".") || id.startsWith("/") || path.isAbsolute(id)) {
|
|
142
|
-
return null; // let rolldown resolve relative/internal files of the package normally
|
|
143
|
-
}
|
|
144
|
-
if (nodeBuiltins.has(id)) {
|
|
145
|
-
return { id, external: true };
|
|
146
|
-
}
|
|
147
|
-
if (isVirtualId(id)) {
|
|
148
|
-
return null;
|
|
149
|
-
}
|
|
150
|
-
if (dedupeExternals && this.isExternal(id)) {
|
|
151
|
-
// Route to the shared cache entry instead of bundling a second copy.
|
|
152
|
-
const file = await this.resolveFile(id, depDir);
|
|
153
|
-
if (file === null)
|
|
154
|
-
return null;
|
|
155
|
-
return { id: this.publicPath + file, external: true };
|
|
156
|
-
}
|
|
157
|
-
return null; // inline this transitive dep (not shared/singleton)
|
|
158
|
-
},
|
|
159
|
-
load(id) {
|
|
160
|
-
if (id === shimId)
|
|
161
|
-
return shimCode;
|
|
162
|
-
return null;
|
|
163
|
-
},
|
|
164
|
-
};
|
|
165
|
-
const bundle = await rolldown({
|
|
166
|
-
input: shimId,
|
|
167
|
-
platform: "browser",
|
|
168
|
-
transform: {
|
|
169
|
-
target: "es2022",
|
|
170
|
-
jsx: {
|
|
171
|
-
runtime: "automatic",
|
|
172
|
-
},
|
|
173
|
-
define: this.define,
|
|
174
|
-
},
|
|
175
|
-
plugins: [plugin],
|
|
176
|
-
});
|
|
177
|
-
await bundle.write({
|
|
178
|
-
file: outFile,
|
|
179
|
-
format: "esm",
|
|
180
|
-
sourcemap: true,
|
|
181
|
-
});
|
|
182
|
-
await bundle.close();
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
export const cacheDepsPlugin = (options) => {
|
|
186
|
-
const { cacheDir, isExternal, define, debug = false } = options;
|
|
187
|
-
const publicPath = options.publicPath ?? "/__cache__/";
|
|
188
|
-
const cache = new DepCache(cacheDir, isExternal, define, publicPath);
|
|
189
|
-
const log = (...args) => {
|
|
190
|
-
if (debug)
|
|
191
|
-
console.log("[cache-deps]", ...args);
|
|
192
|
-
};
|
|
193
|
-
log("initialized, cacheDir =", cacheDir);
|
|
194
|
-
return {
|
|
195
|
-
name: "xanix-cache-deps",
|
|
196
|
-
async resolveId(source, importer) {
|
|
197
|
-
if (!importer) {
|
|
198
|
-
log("skip (entry point):", source);
|
|
199
|
-
return null; // entry points aren't deps
|
|
200
|
-
}
|
|
201
|
-
if (source.startsWith(".") ||
|
|
202
|
-
source.startsWith("/") ||
|
|
203
|
-
path.isAbsolute(source)) {
|
|
204
|
-
return null; // relative/absolute — too noisy to log every one of these
|
|
205
|
-
}
|
|
206
|
-
if (nodeBuiltins.has(source)) {
|
|
207
|
-
return { id: source, external: true };
|
|
208
|
-
}
|
|
209
|
-
if (isVirtualId(source)) {
|
|
210
|
-
log("skip (virtual id):", source);
|
|
211
|
-
return null; // owned by another plugin (virtual:, \0, etc.) — don't touch it
|
|
212
|
-
}
|
|
213
|
-
if (!isExternal(source)) {
|
|
214
|
-
log("skip (isExternal() = false):", source);
|
|
215
|
-
return null; // let it bundle normally into the main output
|
|
216
|
-
}
|
|
217
|
-
log("caching:", source, "from", importer);
|
|
218
|
-
const file = await cache.resolveFile(source, path.dirname(importer));
|
|
219
|
-
if (file === null) {
|
|
220
|
-
log("build failed, falling back to inline:", source);
|
|
221
|
-
return null; // couldn't resolve as a real module — defer to others
|
|
222
|
-
}
|
|
223
|
-
log("cached ->", file);
|
|
224
|
-
return { id: publicPath + file, external: true };
|
|
225
|
-
},
|
|
226
|
-
};
|
|
227
|
-
};
|
|
228
|
-
export default cacheDepsPlugin;
|