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,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Head from "./document/Head.js";
|
|
3
|
+
import Body from "./document/Body.js";
|
|
4
|
+
import Document from "./document/Document.js";
|
|
5
|
+
const BaseDocument = ({ document, children }) => {
|
|
6
|
+
return (_jsxs(Document, { document: document, children: [_jsxs(Head, { children: [_jsx("meta", { charSet: "UTF-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" })] }), _jsx(Body, { children: children })] }));
|
|
7
|
+
};
|
|
8
|
+
export default BaseDocument;
|
package/dist/Document.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import Head from "./components/Head.js";
|
|
3
|
+
import Body from "./components/Body.js";
|
|
4
|
+
const Document = ({ document, children }) => {
|
|
5
|
+
return (_jsxs(Document, { document: document, children: [_jsxs(Head, { children: [_jsx("meta", { charSet: "UTF-8" }), _jsx("meta", { name: "viewport", content: "width=device-width, initial-scale=1.0" })] }), _jsx(Body, { children: children })] }));
|
|
6
|
+
};
|
|
7
|
+
export default Document;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 BuildCache: (entries: XanixClientEntry[]) => Promise<CacheMetadata>;
|
|
11
|
+
export default BuildCache;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { rollup } from "rollup";
|
|
3
|
+
import { build } from "esbuild";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { getDocumentFile } from "../include/utils.js";
|
|
6
|
+
import esbuild from "rollup-plugin-esbuild";
|
|
7
|
+
import url from "@rollup/plugin-url";
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
const GenerateGraph = async (entries) => {
|
|
10
|
+
const collector = new Map();
|
|
11
|
+
const input = {};
|
|
12
|
+
for (const entry of entries) {
|
|
13
|
+
input[entry.name] = entry.file;
|
|
14
|
+
}
|
|
15
|
+
input["xanix-runtime"] = require.resolve("xanix/runtime");
|
|
16
|
+
input["xanix-document"] = await getDocumentFile();
|
|
17
|
+
const bundle = await rollup({
|
|
18
|
+
input,
|
|
19
|
+
plugins: [
|
|
20
|
+
url({
|
|
21
|
+
include: [
|
|
22
|
+
"**/*.jpg",
|
|
23
|
+
"**/*.jpeg",
|
|
24
|
+
"**/*.png",
|
|
25
|
+
"**/*.gif",
|
|
26
|
+
"**/*.webp",
|
|
27
|
+
"**/*.svg",
|
|
28
|
+
"**/*.ico",
|
|
29
|
+
"**/*.woff",
|
|
30
|
+
"**/*.woff2",
|
|
31
|
+
"**/*.ttf",
|
|
32
|
+
"**/*.eot",
|
|
33
|
+
],
|
|
34
|
+
limit: 0,
|
|
35
|
+
fileName: "assets/[name]-[hash][extname]",
|
|
36
|
+
emitFiles: true,
|
|
37
|
+
}),
|
|
38
|
+
esbuild({
|
|
39
|
+
target: "es2022",
|
|
40
|
+
jsx: "automatic",
|
|
41
|
+
tsconfig: false,
|
|
42
|
+
}),
|
|
43
|
+
],
|
|
44
|
+
external(id) {
|
|
45
|
+
if (id.startsWith(".") || path.isAbsolute(id)) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
collector.set(id, {
|
|
49
|
+
source: id,
|
|
50
|
+
resolved: require.resolve(id, {
|
|
51
|
+
paths: [process.cwd()],
|
|
52
|
+
}),
|
|
53
|
+
packageName: id,
|
|
54
|
+
});
|
|
55
|
+
return true;
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
await bundle.close();
|
|
59
|
+
return collector;
|
|
60
|
+
};
|
|
61
|
+
// Wraps each CJS dep in a virtual ESM file that re-exports named exports detected via require()
|
|
62
|
+
const makeCjsWrapperPlugin = (wrappers) => ({
|
|
63
|
+
name: "cjs-named-exports",
|
|
64
|
+
setup(build) {
|
|
65
|
+
build.onResolve({ filter: /\?cjs-wrapper$/ }, (args) => ({
|
|
66
|
+
path: args.path,
|
|
67
|
+
namespace: "cjs-wrapper",
|
|
68
|
+
}));
|
|
69
|
+
build.onLoad({ filter: /.*/, namespace: "cjs-wrapper" }, (args) => {
|
|
70
|
+
const contents = wrappers.get(args.path);
|
|
71
|
+
return { contents, resolveDir: process.cwd() };
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
const buildWrappers = (input) => {
|
|
76
|
+
const wrappers = new Map();
|
|
77
|
+
const wrappedInput = {};
|
|
78
|
+
for (const [name, resolved] of Object.entries(input)) {
|
|
79
|
+
const key = `${name}?cjs-wrapper`;
|
|
80
|
+
let namedExports = [];
|
|
81
|
+
try {
|
|
82
|
+
const mod = require(resolved);
|
|
83
|
+
namedExports = Object.keys(mod).filter((k) => k !== "__esModule" && k !== "default");
|
|
84
|
+
}
|
|
85
|
+
catch { }
|
|
86
|
+
const lines = [
|
|
87
|
+
`import __mod from ${JSON.stringify(resolved)};`,
|
|
88
|
+
`export default __mod;`,
|
|
89
|
+
];
|
|
90
|
+
if (namedExports.length > 0) {
|
|
91
|
+
lines.push(`export const { ${namedExports.join(", ")} } = __mod;`);
|
|
92
|
+
}
|
|
93
|
+
wrappers.set(key, lines.join("\n"));
|
|
94
|
+
wrappedInput[name] = key;
|
|
95
|
+
}
|
|
96
|
+
return { wrappers, wrappedInput };
|
|
97
|
+
};
|
|
98
|
+
const bundleDeps = async (input, outdir) => {
|
|
99
|
+
const { wrappers, wrappedInput } = buildWrappers(input);
|
|
100
|
+
await build({
|
|
101
|
+
entryPoints: wrappedInput,
|
|
102
|
+
bundle: true,
|
|
103
|
+
splitting: true,
|
|
104
|
+
format: "esm",
|
|
105
|
+
target: "es2022",
|
|
106
|
+
outdir,
|
|
107
|
+
entryNames: "[name]",
|
|
108
|
+
chunkNames: "chunks/[hash]",
|
|
109
|
+
platform: "browser",
|
|
110
|
+
sourcemap: true,
|
|
111
|
+
plugins: [makeCjsWrapperPlugin(wrappers)],
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
const metadata = new Map();
|
|
115
|
+
const BuildCache = async (entries) => {
|
|
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(process.cwd(), ".xanix/cache");
|
|
126
|
+
await bundleDeps(input, cacheDir);
|
|
127
|
+
return metadata;
|
|
128
|
+
};
|
|
129
|
+
export default BuildCache;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { rollup } from "rollup";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import bundlerOutput, { outDir } from "./config/output.js";
|
|
4
|
+
import { getDocumentFile, getClientRuntimeFile } from "../include/utils.js";
|
|
5
|
+
import { xanixDefaultPlugins } from "./plugins/plugins.js";
|
|
6
|
+
const buildClient = async (entries) => {
|
|
7
|
+
const input = {};
|
|
8
|
+
for (const entry of entries) {
|
|
9
|
+
input[entry.name] = entry.file;
|
|
10
|
+
}
|
|
11
|
+
input["xanix-runtime"] = getClientRuntimeFile();
|
|
12
|
+
input["xanix-document"] = await getDocumentFile();
|
|
13
|
+
fs.rmSync(outDir.client, {
|
|
14
|
+
recursive: true,
|
|
15
|
+
force: true,
|
|
16
|
+
});
|
|
17
|
+
fs.mkdirSync(outDir.client, {
|
|
18
|
+
recursive: true,
|
|
19
|
+
});
|
|
20
|
+
const build = await rollup({
|
|
21
|
+
input,
|
|
22
|
+
treeshake: true,
|
|
23
|
+
onwarn(warning, warn) {
|
|
24
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" &&
|
|
25
|
+
warning.message.includes('"use client"')) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
warn(warning);
|
|
29
|
+
},
|
|
30
|
+
plugins: [
|
|
31
|
+
...xanixDefaultPlugins({
|
|
32
|
+
target: "client",
|
|
33
|
+
development: false,
|
|
34
|
+
assetExternal: true,
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
await build.write(bundlerOutput.client(entries, { isDev: false }));
|
|
39
|
+
await build.close();
|
|
40
|
+
};
|
|
41
|
+
export default buildClient;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { XanixClientEntry } from "../types.js";
|
|
2
|
+
export type WatcherOptions = {
|
|
3
|
+
rootEntry: string;
|
|
4
|
+
onBuildEnd: (entries: XanixClientEntry[]) => Promise<void>;
|
|
5
|
+
};
|
|
6
|
+
declare const BuildServer: ({ rootEntry, onBuildEnd }: WatcherOptions) => Promise<void>;
|
|
7
|
+
export default BuildServer;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { rollup } from "rollup";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import bundlerOutput, { outDir } from "./config/output.js";
|
|
4
|
+
import fs from "node:fs";
|
|
5
|
+
import { createManifest } from "../include/manifest.js";
|
|
6
|
+
import generateClientEntries from "./generateClientEntries.js";
|
|
7
|
+
import { getDocumentFile } from "../include/utils.js";
|
|
8
|
+
import { xanixDefaultPlugins } from "./plugins/plugins.js";
|
|
9
|
+
const root = process.cwd();
|
|
10
|
+
const BuildServer = async ({ rootEntry, onBuildEnd }) => {
|
|
11
|
+
fs.rmSync(outDir.server, {
|
|
12
|
+
recursive: true,
|
|
13
|
+
force: true,
|
|
14
|
+
});
|
|
15
|
+
fs.mkdirSync(outDir.server, {
|
|
16
|
+
recursive: true,
|
|
17
|
+
});
|
|
18
|
+
const entries = await generateClientEntries();
|
|
19
|
+
await createManifest(entries);
|
|
20
|
+
const input = {
|
|
21
|
+
index: path.resolve(root, rootEntry),
|
|
22
|
+
"xanix-document": await getDocumentFile(),
|
|
23
|
+
};
|
|
24
|
+
const build = await rollup({
|
|
25
|
+
input,
|
|
26
|
+
treeshake: true,
|
|
27
|
+
onwarn(warning, warn) {
|
|
28
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" &&
|
|
29
|
+
warning.message.includes('"use client"')) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
warn(warning);
|
|
33
|
+
},
|
|
34
|
+
plugins: [
|
|
35
|
+
...xanixDefaultPlugins({
|
|
36
|
+
target: "server",
|
|
37
|
+
development: false,
|
|
38
|
+
assetExternal: false,
|
|
39
|
+
}),
|
|
40
|
+
],
|
|
41
|
+
external(id) {
|
|
42
|
+
if (id.startsWith(".") ||
|
|
43
|
+
path.isAbsolute(id) ||
|
|
44
|
+
id === "@" ||
|
|
45
|
+
id.startsWith("@/")) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return true;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
await build.write(bundlerOutput.server());
|
|
52
|
+
await build.close();
|
|
53
|
+
await onBuildEnd(entries);
|
|
54
|
+
};
|
|
55
|
+
export default BuildServer;
|
|
@@ -0,0 +1,11 @@
|
|
|
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 BuildCache: (entries: XanixClientEntry[]) => Promise<CacheMetadata>;
|
|
11
|
+
export default BuildCache;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { rollup } from "rollup";
|
|
3
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
4
|
+
import { build } from "esbuild";
|
|
5
|
+
import { createRequire } from "node:module";
|
|
6
|
+
import { getClientRuntimeFile, getDocumentFile } from "../include/utils.js";
|
|
7
|
+
import esbuild from "rollup-plugin-esbuild";
|
|
8
|
+
import url from "@rollup/plugin-url";
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const GenerateGraph = async (entries) => {
|
|
11
|
+
const collector = new Map();
|
|
12
|
+
const input = [];
|
|
13
|
+
for (const entry of entries) {
|
|
14
|
+
input.push(entry.file);
|
|
15
|
+
}
|
|
16
|
+
input.push(getClientRuntimeFile());
|
|
17
|
+
input.push(await getDocumentFile());
|
|
18
|
+
const bundle = await rollup({
|
|
19
|
+
input,
|
|
20
|
+
plugins: [
|
|
21
|
+
// XanixTsconfigAlias(),
|
|
22
|
+
nodeResolve({
|
|
23
|
+
extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
|
|
24
|
+
}),
|
|
25
|
+
url({
|
|
26
|
+
include: [
|
|
27
|
+
"**/*.jpg",
|
|
28
|
+
"**/*.jpeg",
|
|
29
|
+
"**/*.png",
|
|
30
|
+
"**/*.gif",
|
|
31
|
+
"**/*.webp",
|
|
32
|
+
"**/*.svg",
|
|
33
|
+
"**/*.ico",
|
|
34
|
+
"**/*.woff",
|
|
35
|
+
"**/*.woff2",
|
|
36
|
+
"**/*.ttf",
|
|
37
|
+
"**/*.eot",
|
|
38
|
+
"**/*.css",
|
|
39
|
+
],
|
|
40
|
+
limit: 0,
|
|
41
|
+
fileName: "assets/[name]-[hash][extname]",
|
|
42
|
+
emitFiles: false,
|
|
43
|
+
}),
|
|
44
|
+
esbuild({
|
|
45
|
+
target: "es2022",
|
|
46
|
+
jsx: "automatic",
|
|
47
|
+
tsconfig: false,
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
external(id) {
|
|
51
|
+
if (id.startsWith(".") ||
|
|
52
|
+
path.isAbsolute(id) ||
|
|
53
|
+
id === "@" ||
|
|
54
|
+
id.startsWith("@/")) {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
collector.set(id, {
|
|
58
|
+
source: id,
|
|
59
|
+
resolved: require.resolve(id, {
|
|
60
|
+
paths: [process.cwd()],
|
|
61
|
+
}),
|
|
62
|
+
packageName: id,
|
|
63
|
+
});
|
|
64
|
+
return true;
|
|
65
|
+
},
|
|
66
|
+
});
|
|
67
|
+
await bundle.close();
|
|
68
|
+
return collector;
|
|
69
|
+
};
|
|
70
|
+
// Wraps each CJS dep in a virtual ESM file that re-exports named exports detected via require()
|
|
71
|
+
const makeCjsWrapperPlugin = (wrappers) => ({
|
|
72
|
+
name: "cjs-named-exports",
|
|
73
|
+
setup(build) {
|
|
74
|
+
build.onResolve({ filter: /\?cjs-wrapper$/ }, (args) => ({
|
|
75
|
+
path: args.path,
|
|
76
|
+
namespace: "cjs-wrapper",
|
|
77
|
+
}));
|
|
78
|
+
build.onLoad({ filter: /.*/, namespace: "cjs-wrapper" }, (args) => {
|
|
79
|
+
const contents = wrappers.get(args.path);
|
|
80
|
+
return { contents, resolveDir: process.cwd() };
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
const buildWrappers = (input) => {
|
|
85
|
+
const wrappers = new Map();
|
|
86
|
+
const wrappedInput = {};
|
|
87
|
+
for (const [name, resolved] of Object.entries(input)) {
|
|
88
|
+
const key = `${name}?cjs-wrapper`;
|
|
89
|
+
let namedExports = [];
|
|
90
|
+
let hasDefault = false;
|
|
91
|
+
try {
|
|
92
|
+
const mod = require(resolved);
|
|
93
|
+
hasDefault =
|
|
94
|
+
mod &&
|
|
95
|
+
(typeof mod === "object" || typeof mod === "function") &&
|
|
96
|
+
"default" in mod;
|
|
97
|
+
namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
98
|
+
}
|
|
99
|
+
catch { }
|
|
100
|
+
const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
|
|
101
|
+
if (hasDefault) {
|
|
102
|
+
lines.push(`export default __mod.default;`);
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
lines.push(`export default __mod;`);
|
|
106
|
+
}
|
|
107
|
+
for (const exportName of namedExports) {
|
|
108
|
+
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
109
|
+
lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
wrappers.set(key, lines.join("\n"));
|
|
113
|
+
wrappedInput[name] = key;
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
wrappers,
|
|
117
|
+
wrappedInput,
|
|
118
|
+
};
|
|
119
|
+
};
|
|
120
|
+
const bundleDeps = async (input, outdir) => {
|
|
121
|
+
const { wrappers, wrappedInput } = buildWrappers(input);
|
|
122
|
+
await build({
|
|
123
|
+
entryPoints: wrappedInput,
|
|
124
|
+
bundle: true,
|
|
125
|
+
splitting: true,
|
|
126
|
+
format: "esm",
|
|
127
|
+
target: "es2022",
|
|
128
|
+
outdir,
|
|
129
|
+
entryNames: "[name]",
|
|
130
|
+
chunkNames: "chunks/[hash]",
|
|
131
|
+
platform: "browser",
|
|
132
|
+
sourcemap: true,
|
|
133
|
+
define: {
|
|
134
|
+
__XANIX_CLIENT__: "true",
|
|
135
|
+
__XANIX_SERVER__: "false",
|
|
136
|
+
__XANIX_DEV__: "true",
|
|
137
|
+
__XANIX_PROD__: "false",
|
|
138
|
+
},
|
|
139
|
+
plugins: [makeCjsWrapperPlugin(wrappers)],
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
const metadata = new Map();
|
|
143
|
+
const BuildCache = async (entries) => {
|
|
144
|
+
const input = {};
|
|
145
|
+
const dependencies = await GenerateGraph(entries);
|
|
146
|
+
for (const dependency of dependencies.values()) {
|
|
147
|
+
const entryName = dependency.source.replace(/^@/, "").replace(/\//g, "-");
|
|
148
|
+
input[entryName] = dependency.resolved;
|
|
149
|
+
metadata.set(dependency.source, {
|
|
150
|
+
file: `${entryName}.js`,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
const cacheDir = path.resolve(process.cwd(), ".xanix/cache");
|
|
154
|
+
await bundleDeps(input, cacheDir);
|
|
155
|
+
return metadata;
|
|
156
|
+
};
|
|
157
|
+
export default BuildCache;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OutputOptions } from "rollup";
|
|
2
|
+
import { XanixClientEntry } from "../../types";
|
|
3
|
+
export declare const outDir: {
|
|
4
|
+
server: string;
|
|
5
|
+
client: string;
|
|
6
|
+
};
|
|
7
|
+
type Options = {
|
|
8
|
+
isDev?: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare const bundlerOutput: {
|
|
11
|
+
client: (entries: XanixClientEntry[], { isDev }: Options) => OutputOptions;
|
|
12
|
+
server: () => OutputOptions;
|
|
13
|
+
};
|
|
14
|
+
export default bundlerOutput;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
const root = process.cwd();
|
|
3
|
+
export const outDir = {
|
|
4
|
+
server: path.resolve(root, ".xanix"),
|
|
5
|
+
client: path.resolve(root, ".xanix/client"),
|
|
6
|
+
};
|
|
7
|
+
const client = (entries, { isDev }) => {
|
|
8
|
+
const _entries = {};
|
|
9
|
+
for (const entry of entries) {
|
|
10
|
+
_entries[entry.name] = entry;
|
|
11
|
+
}
|
|
12
|
+
const opt = {
|
|
13
|
+
dir: outDir.client,
|
|
14
|
+
format: "esm",
|
|
15
|
+
entryFileNames: (id) => {
|
|
16
|
+
const entry = _entries[id.name];
|
|
17
|
+
if (entry) {
|
|
18
|
+
return `${entry.id}.js`;
|
|
19
|
+
}
|
|
20
|
+
return `[name].js`;
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
if (isDev) {
|
|
24
|
+
opt.sourcemap = true;
|
|
25
|
+
opt.preserveModules = true;
|
|
26
|
+
opt.preserveModulesRoot = process.cwd();
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
opt.chunkFileNames = "chunks/[hash].js";
|
|
30
|
+
opt.assetFileNames = "assets/[name]-[hash][extname]";
|
|
31
|
+
}
|
|
32
|
+
return opt;
|
|
33
|
+
};
|
|
34
|
+
const server = () => {
|
|
35
|
+
return {
|
|
36
|
+
dir: outDir.server,
|
|
37
|
+
format: "esm",
|
|
38
|
+
sourcemap: false,
|
|
39
|
+
entryFileNames: "[name].js",
|
|
40
|
+
chunkFileNames: "chunks/[hash].js",
|
|
41
|
+
assetFileNames: "assets/[hash][extname]",
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const bundlerOutput = {
|
|
45
|
+
client,
|
|
46
|
+
server,
|
|
47
|
+
};
|
|
48
|
+
export default bundlerOutput;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { rollup } from "rollup";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { XanixEntryFinder } from "./plugins/XanixEntryFinder/index.js";
|
|
4
|
+
import url from "@rollup/plugin-url";
|
|
5
|
+
import esbuild from "rollup-plugin-esbuild";
|
|
6
|
+
import XanixTsconfigAlias from "./plugins/XanixTsconfigAlias.js";
|
|
7
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
8
|
+
const root = process.cwd();
|
|
9
|
+
const generateClientEntries = async () => {
|
|
10
|
+
const entries = new Map();
|
|
11
|
+
const bundle = await rollup({
|
|
12
|
+
input: path.resolve(root, "index.tsx"),
|
|
13
|
+
plugins: [
|
|
14
|
+
XanixTsconfigAlias(),
|
|
15
|
+
nodeResolve({
|
|
16
|
+
extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
|
|
17
|
+
}),
|
|
18
|
+
XanixEntryFinder({
|
|
19
|
+
entries,
|
|
20
|
+
}),
|
|
21
|
+
url({
|
|
22
|
+
include: [
|
|
23
|
+
"**/*.jpg",
|
|
24
|
+
"**/*.jpeg",
|
|
25
|
+
"**/*.png",
|
|
26
|
+
"**/*.gif",
|
|
27
|
+
"**/*.webp",
|
|
28
|
+
"**/*.svg",
|
|
29
|
+
"**/*.ico",
|
|
30
|
+
"**/*.woff",
|
|
31
|
+
"**/*.woff2",
|
|
32
|
+
"**/*.ttf",
|
|
33
|
+
"**/*.eot",
|
|
34
|
+
"**/*.css",
|
|
35
|
+
],
|
|
36
|
+
limit: 0,
|
|
37
|
+
fileName: "assets/[name]-[hash][extname]",
|
|
38
|
+
emitFiles: true,
|
|
39
|
+
}),
|
|
40
|
+
esbuild({
|
|
41
|
+
target: "es2022",
|
|
42
|
+
jsx: "automatic",
|
|
43
|
+
tsconfig: false,
|
|
44
|
+
}),
|
|
45
|
+
],
|
|
46
|
+
external(id) {
|
|
47
|
+
if (id.startsWith(".") ||
|
|
48
|
+
path.isAbsolute(id) ||
|
|
49
|
+
id === "@" ||
|
|
50
|
+
id.startsWith("@/")) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
await bundle.close();
|
|
57
|
+
return Array.from(entries.values());
|
|
58
|
+
};
|
|
59
|
+
export default generateClientEntries;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import url from "@rollup/plugin-url";
|
|
2
|
+
const xanixAssets = (options) => {
|
|
3
|
+
return url({
|
|
4
|
+
include: [
|
|
5
|
+
"**/*.jpg",
|
|
6
|
+
"**/*.jpeg",
|
|
7
|
+
"**/*.png",
|
|
8
|
+
"**/*.gif",
|
|
9
|
+
"**/*.webp",
|
|
10
|
+
"**/*.svg",
|
|
11
|
+
"**/*.ico",
|
|
12
|
+
"**/*.woff",
|
|
13
|
+
"**/*.woff2",
|
|
14
|
+
"**/*.ttf",
|
|
15
|
+
"**/*.eot",
|
|
16
|
+
],
|
|
17
|
+
limit: 0,
|
|
18
|
+
fileName: "assets/[name]-[hash][extname]",
|
|
19
|
+
emitFiles: !(options?.external ?? false),
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
export default xanixAssets;
|