xanix 0.0.0 → 1.0.0
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/BaseDocument.d.ts +3 -0
- package/dist/BaseDocument.js +8 -0
- package/dist/Document.d.ts +7 -0
- package/dist/Document.js +7 -0
- package/dist/bin/bundler/buildCache.d.ts +11 -0
- package/dist/bin/bundler/buildCache.js +129 -0
- package/dist/bin/bundler/buildClient.d.ts +3 -0
- package/dist/bin/bundler/buildClient.js +41 -0
- package/dist/bin/bundler/buildServer.d.ts +7 -0
- package/dist/bin/bundler/buildServer.js +55 -0
- package/dist/bin/bundler/cacheNpmModules.d.ts +11 -0
- package/dist/bin/bundler/cacheNpmModules.js +157 -0
- package/dist/bin/bundler/config/output.d.ts +14 -0
- package/dist/bin/bundler/config/output.js +48 -0
- package/dist/bin/bundler/generateClientEntries.d.ts +3 -0
- package/dist/bin/bundler/generateClientEntries.js +59 -0
- package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +4 -0
- package/dist/bin/bundler/plugins/XanixAssets/index.js +22 -0
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +6 -0
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +350 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.d.ts +11 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.js +156 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.d.ts +6 -0
- package/dist/bin/bundler/plugins/XanixEntryFinder/index.js +36 -0
- package/dist/bin/bundler/plugins/XanixEnv.d.ts +15 -0
- package/dist/bin/bundler/plugins/XanixEnv.js +46 -0
- package/dist/bin/bundler/plugins/XanixHydrate.d.ts +3 -0
- package/dist/bin/bundler/plugins/XanixHydrate.js +34 -0
- package/dist/bin/bundler/plugins/XanixReactRefresh.d.ts +2 -0
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +126 -0
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.d.ts +5 -0
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +22 -0
- package/dist/bin/bundler/plugins/XanixTransform/index.d.ts +5 -0
- package/dist/bin/bundler/plugins/XanixTransform/index.js +19 -0
- package/dist/bin/bundler/plugins/XanixTransform/transformer.d.ts +16 -0
- package/dist/bin/bundler/plugins/XanixTransform/transformer.js +631 -0
- package/dist/bin/bundler/plugins/XanixWatchChange copy.d.ts +10 -0
- package/dist/bin/bundler/plugins/XanixWatchChange copy.js +30 -0
- package/dist/bin/bundler/plugins/XanixWatchChange.d.ts +9 -0
- package/dist/bin/bundler/plugins/XanixWatchChange.js +27 -0
- package/dist/bin/bundler/plugins/XanixWatchChangeClient.d.ts +7 -0
- package/dist/bin/bundler/plugins/XanixWatchChangeClient.js +15 -0
- package/dist/bin/bundler/plugins/commonjs.d.ts +3 -0
- package/dist/bin/bundler/plugins/commonjs.js +10 -0
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +9 -0
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +27 -0
- package/dist/bin/bundler/plugins/nodeResolve.d.ts +3 -0
- package/dist/bin/bundler/plugins/nodeResolve.js +10 -0
- package/dist/bin/bundler/plugins/pathResolver.d.ts +5 -0
- package/dist/bin/bundler/plugins/pathResolver.js +57 -0
- package/dist/bin/bundler/plugins/plugins.d.ts +8 -0
- package/dist/bin/bundler/plugins/plugins.js +75 -0
- package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +3 -0
- package/dist/bin/bundler/plugins/rollupEsbuild.js +14 -0
- package/dist/bin/bundler/plugins/xanixServerData.d.ts +6 -0
- package/dist/bin/bundler/plugins/xanixServerData.js +224 -0
- package/dist/bin/bundler/plugins/xanixTsconfigAlias.d.ts +6 -0
- package/dist/bin/bundler/plugins/xanixTsconfigAlias.js +51 -0
- package/dist/bin/bundler/plugins/xanixUseDataId.d.ts +4 -0
- package/dist/bin/bundler/plugins/xanixUseDataId.js +93 -0
- package/dist/bin/bundler/watchClient.d.ts +8 -0
- package/dist/bin/bundler/watchClient.js +54 -0
- package/dist/bin/bundler/watchServer.d.ts +10 -0
- package/dist/bin/bundler/watchServer.js +84 -0
- package/dist/bin/cli/build.d.ts +2 -0
- package/dist/bin/cli/build.js +18 -0
- package/dist/bin/cli/dev.d.ts +2 -0
- package/dist/bin/cli/dev.js +103 -0
- package/dist/bin/cli/start.d.ts +2 -0
- package/dist/bin/cli/start.js +19 -0
- package/dist/bin/include/entry.d.ts +3 -0
- package/dist/bin/include/entry.js +28 -0
- package/dist/bin/include/logger.d.ts +10 -0
- package/dist/bin/include/logger.js +11 -0
- package/dist/bin/include/manifest.d.ts +3 -0
- package/dist/bin/include/manifest.js +13 -0
- package/dist/bin/include/utils.d.ts +2 -0
- package/dist/bin/include/utils.js +14 -0
- package/dist/bin/index.d.ts +2 -0
- package/dist/bin/index.js +26 -0
- package/dist/bin/types.d.ts +12 -0
- package/dist/bin/types.js +1 -0
- package/dist/client/components/Body.d.ts +5 -0
- package/dist/client/components/Body.js +10 -0
- package/dist/client/components/Document/context.d.ts +3 -0
- package/dist/client/components/Document/context.js +14 -0
- package/dist/client/components/Document/index.d.ts +8 -0
- package/dist/client/components/Document/index.js +6 -0
- package/dist/client/components/Head copy.d.ts +5 -0
- package/dist/client/components/Head copy.js +8 -0
- package/dist/client/components/Head.d.ts +5 -0
- package/dist/client/components/Head.js +10 -0
- package/dist/client/components/Link.d.ts +6 -0
- package/dist/client/components/Link.js +10 -0
- package/dist/client/context/RouteContext.d.ts +8 -0
- package/dist/client/context/RouteContext.js +16 -0
- package/dist/client/hooks/usePageProps.d.ts +1 -0
- package/dist/client/hooks/usePageProps.js +2 -0
- package/dist/client/hooks/useRoute.d.ts +1 -0
- package/dist/client/hooks/useRoute.js +2 -0
- package/dist/client/hooks/useSearchParams.d.ts +1 -0
- package/dist/client/hooks/useSearchParams.js +2 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +2 -0
- package/dist/client/navigation.d.ts +4 -0
- package/dist/client/navigation.js +14 -0
- package/dist/client/refresh.d.ts +7 -0
- package/dist/client/refresh.js +15 -0
- package/dist/client/runtime.d.ts +10 -0
- package/dist/client/runtime.js +98 -0
- package/dist/client-runtime.d.ts +10 -0
- package/dist/client-runtime.js +113 -0
- package/dist/components/BaseDocument.d.ts +3 -0
- package/dist/components/BaseDocument.js +8 -0
- package/dist/components/Body.d.ts +5 -0
- package/dist/components/Body.js +8 -0
- package/dist/components/Document/Document.d.ts +16 -0
- package/dist/components/Document/Document.js +15 -0
- package/dist/components/Document/context.d.ts +17 -0
- package/dist/components/Document/context.js +13 -0
- package/dist/components/Document/index.d.ts +7 -0
- package/dist/components/Document/index.js +10 -0
- package/dist/components/Document.d.ts +7 -0
- package/dist/components/Document.js +9 -0
- package/dist/components/DocumentContext/DocumentContext.d.ts +15 -0
- package/dist/components/DocumentContext/DocumentContext.js +18 -0
- package/dist/components/DocumentContext/context.d.ts +11 -0
- package/dist/components/DocumentContext/context.js +14 -0
- package/dist/components/DocumentContext/index.d.ts +15 -0
- package/dist/components/DocumentContext/index.js +18 -0
- package/dist/components/DocumentContext.d.ts +19 -0
- package/dist/components/DocumentContext.js +6 -0
- package/dist/components/DocumentProvider.d.ts +13 -0
- package/dist/components/DocumentProvider.js +7 -0
- package/dist/components/Head.d.ts +5 -0
- package/dist/components/Head.js +42 -0
- package/dist/components/Link.d.ts +7 -0
- package/dist/components/Link.js +28 -0
- package/dist/components/Script.d.ts +3 -0
- package/dist/components/Script.js +5 -0
- package/dist/dataLoader.d.ts +11 -0
- package/dist/dataLoader.js +46 -0
- package/dist/document/BaseDocument.d.ts +3 -0
- package/dist/document/BaseDocument.js +8 -0
- package/dist/document/Body.d.ts +5 -0
- package/dist/document/Body.js +9 -0
- package/dist/document/Document/Document.d.ts +7 -0
- package/dist/document/Document/Document.js +10 -0
- package/dist/document/Document/context.d.ts +17 -0
- package/dist/document/Document/context.js +13 -0
- package/dist/document/Document/index.d.ts +7 -0
- package/dist/document/Document/index.js +10 -0
- package/dist/document/Document.d.ts +7 -0
- package/dist/document/Document.js +10 -0
- package/dist/document/DocumentContext.d.ts +17 -0
- package/dist/document/DocumentContext.js +6 -0
- package/dist/document/Head.d.ts +5 -0
- package/dist/document/Head.js +40 -0
- package/dist/document/Link.d.ts +7 -0
- package/dist/document/Link.js +28 -0
- package/dist/document/Script.d.ts +3 -0
- package/dist/document/Script.js +5 -0
- package/dist/document/context.d.ts +17 -0
- package/dist/document/context.js +13 -0
- package/dist/document/index.d.ts +8 -0
- package/dist/document/index.js +7 -0
- package/dist/document/useDocument.d.ts +2 -0
- package/dist/document/useDocument.js +10 -0
- package/dist/hooks/useCookies.d.ts +2 -0
- package/dist/hooks/useCookies.js +11 -0
- package/dist/hooks/useData.d.ts +18 -0
- package/dist/hooks/useData.js +69 -0
- package/dist/hooks/useDocument.d.ts +2 -0
- package/dist/hooks/useDocument.js +10 -0
- package/dist/hooks/useHeaders.d.ts +2 -0
- package/dist/hooks/useHeaders.js +9 -0
- package/dist/hooks/useLocation.d.ts +2 -0
- package/dist/hooks/useLocation.js +25 -0
- package/dist/hooks/usePage.d.ts +5 -0
- package/dist/hooks/usePage.js +9 -0
- package/dist/hooks/useParams.d.ts +2 -0
- package/dist/hooks/useParams.js +6 -0
- package/dist/hooks/usePathname.d.ts +2 -0
- package/dist/hooks/usePathname.js +9 -0
- package/dist/hooks/useRequest.d.ts +2 -0
- package/dist/hooks/useRequest.js +8 -0
- package/dist/hooks/useSearchParams.d.ts +12 -0
- package/dist/hooks/useSearchParams.js +66 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +27 -0
- package/dist/loader.d.ts +11 -0
- package/dist/loader.js +16 -0
- package/dist/navigate.d.ts +7 -0
- package/dist/navigate.js +31 -0
- package/dist/navigation/index.d.ts +2 -0
- package/dist/navigation/index.js +2 -0
- package/dist/navigation/navigate.d.ts +7 -0
- package/dist/navigation/navigate.js +31 -0
- package/dist/navigation/useLocation.d.ts +1 -0
- package/dist/navigation/useLocation.js +22 -0
- package/dist/router/index.d.ts +1 -0
- package/dist/router/index.js +1 -0
- package/dist/router/useParams.d.ts +9 -0
- package/dist/router/useParams.js +50 -0
- package/dist/router/useSearchParams .d.ts +9 -0
- package/dist/router/useSearchParams .js +50 -0
- package/dist/router/useSearchParams.d.ts +11 -0
- package/dist/router/useSearchParams.js +80 -0
- package/dist/server/index.d.ts +0 -0
- package/dist/server/index.js +1 -0
- package/dist/server/page.d.ts +9 -0
- package/dist/server/page.js +60 -0
- package/dist/server/readManifest.d.ts +14 -0
- package/dist/server/readManifest.js +8 -0
- package/dist/server/runtime/createServer.d.ts +12 -0
- package/dist/server/runtime/createServer.js +48 -0
- package/dist/server/runtime/index.d.ts +3 -0
- package/dist/server/runtime/index.js +3 -0
- package/dist/server/runtime/readManifest.d.ts +14 -0
- package/dist/server/runtime/readManifest.js +8 -0
- package/dist/server/runtime/xanixPage.d.ts +9 -0
- package/dist/server/runtime/xanixPage.js +87 -0
- package/dist/types.d.ts +12 -0
- package/dist/types.js +7 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.js +27 -0
- package/dist/xanix.d.ts +3 -0
- package/dist/xanix.js +40 -0
- package/package.json +73 -13
- package/src/xanix-env.d.ts +79 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { parse } from "@babel/parser";
|
|
4
|
+
import traverse from "@babel/traverse";
|
|
5
|
+
import generate from "@babel/generator";
|
|
6
|
+
import * as t from "@babel/types";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import { getClientRuntimeFile } from "../../include/utils.js";
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const root = process.cwd();
|
|
11
|
+
export default function xanixReactRefresh() {
|
|
12
|
+
return {
|
|
13
|
+
name: "xanix-react-refresh",
|
|
14
|
+
load(id) {
|
|
15
|
+
if (path.resolve(id) !== getClientRuntimeFile()) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const code = fs.readFileSync(id, "utf8");
|
|
19
|
+
const refreshCode = `
|
|
20
|
+
import * as RefreshRuntime from "react-refresh/runtime";
|
|
21
|
+
|
|
22
|
+
${code}
|
|
23
|
+
|
|
24
|
+
if (typeof window !== "undefined") {
|
|
25
|
+
RefreshRuntime.injectIntoGlobalHook(window);
|
|
26
|
+
|
|
27
|
+
window.$RefreshReg$ = RefreshRuntime.register;
|
|
28
|
+
window.$RefreshSig$ = () => (type) => type;
|
|
29
|
+
|
|
30
|
+
const ws = new WebSocket("ws://localhost:8080");
|
|
31
|
+
|
|
32
|
+
ws.onmessage = async (event) => {
|
|
33
|
+
const files = JSON.parse(event.data);
|
|
34
|
+
|
|
35
|
+
for (const file of files) {
|
|
36
|
+
if (!file.endsWith(".js")) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const url =
|
|
41
|
+
getImportUrl(file.replace(/\\.js$/, "")) +
|
|
42
|
+
"?t=" +
|
|
43
|
+
Date.now();
|
|
44
|
+
|
|
45
|
+
await import(url);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
RefreshRuntime.performReactRefresh();
|
|
49
|
+
ws.send("reload")
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
return {
|
|
54
|
+
code: refreshCode,
|
|
55
|
+
map: null,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
transform(code, id) {
|
|
59
|
+
if (path.resolve(id) === getClientRuntimeFile()) {
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
if (id.includes("node_modules") || id.includes("xanix\\dist")) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (!/\.(tsx?|jsx?)$/.test(id)) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const ast = parse(code, {
|
|
69
|
+
sourceType: "module",
|
|
70
|
+
plugins: ["typescript", "jsx"],
|
|
71
|
+
});
|
|
72
|
+
const registrations = [];
|
|
73
|
+
traverse(ast, {
|
|
74
|
+
FunctionDeclaration(path) {
|
|
75
|
+
const node = path.node;
|
|
76
|
+
if (!node.id) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const name = node.id.name;
|
|
80
|
+
if (!isReactComponent(name)) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
registrations.push(createRegistration(name, id));
|
|
84
|
+
},
|
|
85
|
+
VariableDeclarator(path) {
|
|
86
|
+
const node = path.node;
|
|
87
|
+
if (!t.isIdentifier(node.id)) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const name = node.id.name;
|
|
91
|
+
if (!isReactComponent(name)) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (!t.isArrowFunctionExpression(node.init) &&
|
|
95
|
+
!t.isFunctionExpression(node.init)) {
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
registrations.push(createRegistration(name, id));
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
if (registrations.length === 0) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
ast.program.body.push(...registrations);
|
|
105
|
+
const result = generate(ast, {
|
|
106
|
+
sourceMaps: true,
|
|
107
|
+
sourceFileName: id,
|
|
108
|
+
}, code);
|
|
109
|
+
return {
|
|
110
|
+
code: result.code,
|
|
111
|
+
map: result.map,
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
function isReactComponent(name) {
|
|
117
|
+
return /^[A-Z]/.test(name);
|
|
118
|
+
}
|
|
119
|
+
function createRegistration(name, filename) {
|
|
120
|
+
const relative = path.relative(root, filename).replaceAll("\\", "/");
|
|
121
|
+
const componentId = `${relative}:${name}`;
|
|
122
|
+
return t.expressionStatement(t.callExpression(t.identifier("$RefreshReg$"), [
|
|
123
|
+
t.identifier(name),
|
|
124
|
+
t.stringLiteral(componentId),
|
|
125
|
+
]));
|
|
126
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { XanixClientEntry } from "../../../types";
|
|
2
|
+
import type { Plugin } from "rollup";
|
|
3
|
+
import { CacheMetadata } from "../../cacheNpmModules.js";
|
|
4
|
+
declare function XanixResolveCacheDeps(metadata: CacheMetadata, entries: XanixClientEntry[]): Plugin;
|
|
5
|
+
export default XanixResolveCacheDeps;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import BuildCache from "../../cacheNpmModules.js";
|
|
3
|
+
function XanixResolveCacheDeps(metadata, entries) {
|
|
4
|
+
return {
|
|
5
|
+
name: "xanix:cached-deps",
|
|
6
|
+
async resolveId(source) {
|
|
7
|
+
if (source.startsWith(".") || path.isAbsolute(source)) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
const dependency = metadata.get(source);
|
|
11
|
+
if (dependency) {
|
|
12
|
+
return { id: `/.xanix/cache/${dependency.file}`, external: true };
|
|
13
|
+
}
|
|
14
|
+
const buildCache = await BuildCache(entries);
|
|
15
|
+
const newDependency = buildCache.get(source);
|
|
16
|
+
if (newDependency) {
|
|
17
|
+
return { id: `/.xanix/cache/${newDependency.file}`, external: true };
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export default XanixResolveCacheDeps;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { transformer } from "./transformer.js";
|
|
2
|
+
export function XanixTransform(option) {
|
|
3
|
+
return {
|
|
4
|
+
name: "xanix-transform",
|
|
5
|
+
async transform(code, id) {
|
|
6
|
+
if (id.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(id)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const result = transformer(code, id, option.mode);
|
|
10
|
+
if (!result) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
code: result.code,
|
|
15
|
+
map: result.map,
|
|
16
|
+
};
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as t from "@babel/types";
|
|
2
|
+
export interface XanixTransformResult {
|
|
3
|
+
code: string;
|
|
4
|
+
map: any;
|
|
5
|
+
}
|
|
6
|
+
export declare function resolveFile(file: string): string;
|
|
7
|
+
export declare function resolveComponentFile(importer: string, importPath: string): string;
|
|
8
|
+
export declare function createPageId(file: string): string;
|
|
9
|
+
export declare function getJSXComponentName(node: t.JSXElement): string | null;
|
|
10
|
+
export declare function findComponentImport(ast: t.File, componentName: string): {
|
|
11
|
+
file: string;
|
|
12
|
+
export: string;
|
|
13
|
+
declaration: t.ImportDeclaration;
|
|
14
|
+
specifier: t.ImportSpecifier | t.ImportDefaultSpecifier;
|
|
15
|
+
} | null;
|
|
16
|
+
export declare function transformer(code: string, id: string, mode: "watch" | "start"): XanixTransformResult | null;
|