xanix 1.0.5 → 1.0.7
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/buildClient.js +3 -3
- package/dist/bin/bundler/buildServer.js +2 -3
- package/dist/bin/bundler/cacheNpmModules.js +8 -2
- package/dist/bin/bundler/config/output.js +9 -1
- package/dist/bin/bundler/plugins/XanixDocument/index.d.ts +2 -0
- package/dist/bin/bundler/plugins/XanixDocument/index.js +35 -0
- package/dist/bin/bundler/plugins/XanixEnv.js +13 -3
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +33 -33
- package/dist/bin/bundler/plugins/XanixTransform/transformer copy.d.ts +16 -0
- package/dist/bin/bundler/plugins/XanixTransform/transformer copy.js +631 -0
- package/dist/bin/bundler/plugins/plugins.js +3 -1
- package/dist/bin/bundler/watchClient.js +3 -3
- package/dist/bin/bundler/watchServer.js +2 -3
- package/dist/bin/include/utils.d.ts +3 -0
- package/dist/bin/include/utils.js +17 -0
- package/dist/bin/index.js +0 -0
- package/dist/client-runtime.js +17 -15
- package/dist/components/BaseDocument.d.ts +1 -1
- package/dist/components/BaseDocument.js +1 -3
- package/dist/components/Body.js +3 -1
- package/dist/components/Document.js +3 -1
- package/dist/components/Head.d.ts +1 -1
- package/dist/components/Head.js +37 -34
- package/dist/components/Link.d.ts +1 -1
- package/dist/components/Link.js +23 -18
- package/dist/dataLoader.d.ts +1 -1
- package/dist/dataLoader.js +14 -5
- package/dist/hooks/useData.d.ts +2 -6
- package/dist/hooks/useData.js +1 -1
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/navigate.js +11 -8
- package/dist/server/runtime/xanixPage.js +1 -4
- package/dist/types/assets.d.ts +34 -0
- package/dist/types/express.d.ts +12 -0
- package/dist/types/globals.d.ts +27 -0
- package/dist/types/xanix-virtual.d.ts +26 -0
- package/package.json +75 -73
- package/dist/BaseDocument.d.ts +0 -3
- package/dist/BaseDocument.js +0 -8
- package/dist/bin/bundler/buildCache.d.ts +0 -11
- package/dist/bin/bundler/buildCache.js +0 -112
- package/dist/bin/bundler/plugins/XanixAssets/index.d.ts +0 -4
- package/dist/bin/bundler/plugins/XanixAssets/index.js +0 -22
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.d.ts +0 -6
- package/dist/bin/bundler/plugins/XanixBrowserCodeRemover.js +0 -350
- package/dist/bin/bundler/plugins/XanixHydrate.d.ts +0 -3
- package/dist/bin/bundler/plugins/XanixHydrate.js +0 -34
- package/dist/bin/bundler/plugins/commonjs.d.ts +0 -3
- package/dist/bin/bundler/plugins/commonjs.js +0 -10
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.d.ts +0 -9
- package/dist/bin/bundler/plugins/dep-XanixWatchChange.js +0 -27
- package/dist/bin/bundler/plugins/nodeResolve.d.ts +0 -3
- package/dist/bin/bundler/plugins/nodeResolve.js +0 -10
- package/dist/bin/bundler/plugins/rollupEsbuild.d.ts +0 -3
- package/dist/bin/bundler/plugins/rollupEsbuild.js +0 -14
- package/dist/bin/cli/start copy.d.ts +0 -2
- package/dist/bin/cli/start copy.js +0 -34
- package/dist/client/client-runtime.d.ts +0 -10
- package/dist/client/client-runtime.js +0 -98
- package/dist/client/context/RouteContext.d.ts +0 -8
- package/dist/client/context/RouteContext.js +0 -16
- package/dist/client/hooks/usePageProps.d.ts +0 -1
- package/dist/client/hooks/usePageProps.js +0 -2
- package/dist/client/hooks/useRoute.d.ts +0 -1
- package/dist/client/hooks/useRoute.js +0 -2
- package/dist/client/hooks/useSearchParams.d.ts +0 -1
- package/dist/client/hooks/useSearchParams.js +0 -2
- package/dist/client/index.d.ts +0 -2
- package/dist/client/index.js +0 -2
- package/dist/client/navigation.d.ts +0 -3
- package/dist/client/navigation.js +0 -27
- package/dist/client/runtime.d.ts +0 -10
- package/dist/client/runtime.js +0 -98
- package/dist/components/Document/context.d.ts +0 -11
- package/dist/components/Document/context.js +0 -14
- package/dist/components/Document/index.d.ts +0 -8
- package/dist/components/Document/index.js +0 -6
- package/dist/document/BaseDocument.d.ts +0 -3
- package/dist/document/BaseDocument.js +0 -8
- package/dist/document/Body.d.ts +0 -5
- package/dist/document/Body.js +0 -8
- package/dist/document/Document.d.ts +0 -7
- package/dist/document/Document.js +0 -9
- package/dist/document/DocumentContext.d.ts +0 -18
- package/dist/document/DocumentContext.js +0 -6
- package/dist/document/Head.d.ts +0 -5
- package/dist/document/Head.js +0 -41
- package/dist/document/Link.d.ts +0 -7
- package/dist/document/Link.js +0 -28
- package/dist/document/Script.d.ts +0 -3
- package/dist/document/Script.js +0 -5
- package/dist/document/index.d.ts +0 -8
- package/dist/document/index.js +0 -7
- package/dist/document/useDocument.d.ts +0 -2
- package/dist/document/useDocument.js +0 -10
- package/dist/hooks/useCookie.d.ts +0 -2
- package/dist/hooks/useCookie.js +0 -13
- package/dist/hooks/useRequest copy.d.ts +0 -2
- package/dist/hooks/useRequest copy.js +0 -8
- package/dist/navigation/index.d.ts +0 -2
- package/dist/navigation/index.js +0 -2
- package/dist/navigation/navigate.d.ts +0 -7
- package/dist/navigation/navigate.js +0 -31
- package/dist/navigation/useLocation.d.ts +0 -1
- package/dist/navigation/useLocation.js +0 -22
- package/dist/router/index.d.ts +0 -3
- package/dist/router/index.js +0 -3
- package/dist/router/useParams.d.ts +0 -1
- package/dist/router/useParams.js +0 -5
- package/dist/router/usePathname.d.ts +0 -1
- package/dist/router/usePathname.js +0 -8
- package/dist/router/useSearchParams.d.ts +0 -11
- package/dist/router/useSearchParams.js +0 -74
- package/dist/runtime/createServer.d.ts +0 -12
- package/dist/runtime/createServer.js +0 -40
- package/dist/runtime/index.d.ts +0 -12
- package/dist/runtime/index.js +0 -40
- package/dist/runtime/readManifest.d.ts +0 -14
- package/dist/runtime/readManifest.js +0 -8
- package/dist/runtime/xanixPage.d.ts +0 -9
- package/dist/runtime/xanixPage.js +0 -62
- package/dist/server/createServer.d.ts +0 -12
- package/dist/server/createServer.js +0 -40
- package/dist/server/page.d.ts +0 -9
- package/dist/server/page.js +0 -62
- package/dist/server/readManifest.d.ts +0 -14
- package/dist/server/readManifest.js +0 -8
- package/dist/server/runtime copy.d.ts +0 -12
- package/dist/server/runtime copy.js +0 -40
- package/dist/server/runtime.d.ts +0 -12
- package/dist/server/runtime.js +0 -40
- package/dist/server/xanixPage.d.ts +0 -9
- package/dist/server/xanixPage.js +0 -62
- package/dist/types.d.ts +0 -12
- package/dist/types.js +0 -7
- package/dist/utils/index.d.ts +0 -0
- package/dist/utils/index.js +0 -1
- package/dist/xanix.d.ts +0 -3
- package/dist/xanix.js +0 -40
- package/xanix-env.d.ts +0 -79
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { rollup } from "rollup";
|
|
2
2
|
import fs from "node:fs";
|
|
3
3
|
import bundlerOutput, { outDir } from "./config/output.js";
|
|
4
|
-
import {
|
|
4
|
+
import { getClientRuntimeFile, getClientRuntimeFileName, } from "../include/utils.js";
|
|
5
5
|
import { xanixDefaultPlugins } from "./plugins/plugins.js";
|
|
6
6
|
const buildClient = async (entries) => {
|
|
7
7
|
const input = {};
|
|
8
8
|
for (const entry of entries) {
|
|
9
9
|
input[entry.name] = entry.file;
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
input[
|
|
11
|
+
const runtimeFileName = getClientRuntimeFileName("production");
|
|
12
|
+
input[runtimeFileName] = getClientRuntimeFile();
|
|
13
13
|
fs.rmSync(outDir.client, {
|
|
14
14
|
recursive: true,
|
|
15
15
|
force: true,
|
|
@@ -4,7 +4,6 @@ import bundlerOutput, { outDir } from "./config/output.js";
|
|
|
4
4
|
import fs from "node:fs";
|
|
5
5
|
import { createManifest } from "../include/manifest.js";
|
|
6
6
|
import generateClientEntries from "./generateClientEntries.js";
|
|
7
|
-
import { getDocumentFile } from "../include/utils.js";
|
|
8
7
|
import { xanixDefaultPlugins } from "./plugins/plugins.js";
|
|
9
8
|
const root = process.cwd();
|
|
10
9
|
const BuildServer = async ({ rootEntry, onBuildEnd }) => {
|
|
@@ -19,7 +18,6 @@ const BuildServer = async ({ rootEntry, onBuildEnd }) => {
|
|
|
19
18
|
await createManifest(entries);
|
|
20
19
|
const input = {
|
|
21
20
|
index: path.resolve(root, rootEntry),
|
|
22
|
-
"xanix-document": await getDocumentFile(),
|
|
23
21
|
};
|
|
24
22
|
const build = await rollup({
|
|
25
23
|
input,
|
|
@@ -43,7 +41,8 @@ const BuildServer = async ({ rootEntry, onBuildEnd }) => {
|
|
|
43
41
|
path.isAbsolute(id) ||
|
|
44
42
|
id === "@" ||
|
|
45
43
|
id.startsWith("@/") ||
|
|
46
|
-
id.startsWith("xanix")
|
|
44
|
+
id.startsWith("xanix") ||
|
|
45
|
+
id === "virtual:xanix-document") {
|
|
47
46
|
return false;
|
|
48
47
|
}
|
|
49
48
|
return true;
|
|
@@ -6,6 +6,7 @@ import { createRequire } from "node:module";
|
|
|
6
6
|
import { getClientRuntimeFile, getDocumentFile } from "../include/utils.js";
|
|
7
7
|
import esbuild from "rollup-plugin-esbuild";
|
|
8
8
|
import url from "@rollup/plugin-url";
|
|
9
|
+
import XanixDocument from "./plugins/XanixDocument/index.js";
|
|
9
10
|
const require = createRequire(import.meta.url);
|
|
10
11
|
const GenerateGraph = async (entries) => {
|
|
11
12
|
const collector = new Map();
|
|
@@ -41,6 +42,7 @@ const GenerateGraph = async (entries) => {
|
|
|
41
42
|
fileName: "assets/[name]-[hash][extname]",
|
|
42
43
|
emitFiles: false,
|
|
43
44
|
}),
|
|
45
|
+
XanixDocument(),
|
|
44
46
|
esbuild({
|
|
45
47
|
target: "es2022",
|
|
46
48
|
jsx: "automatic",
|
|
@@ -51,7 +53,8 @@ const GenerateGraph = async (entries) => {
|
|
|
51
53
|
if (id.startsWith(".") ||
|
|
52
54
|
path.isAbsolute(id) ||
|
|
53
55
|
id === "@" ||
|
|
54
|
-
id.startsWith("@/")
|
|
56
|
+
id.startsWith("@/") ||
|
|
57
|
+
id === "virtual:xanix-document") {
|
|
55
58
|
return false;
|
|
56
59
|
}
|
|
57
60
|
collector.set(id, {
|
|
@@ -96,7 +99,9 @@ const buildWrappers = (input) => {
|
|
|
96
99
|
"default" in mod;
|
|
97
100
|
namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
98
101
|
}
|
|
99
|
-
catch {
|
|
102
|
+
catch (err) {
|
|
103
|
+
console.log(err);
|
|
104
|
+
}
|
|
100
105
|
const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
|
|
101
106
|
if (hasDefault) {
|
|
102
107
|
lines.push(`export default __mod.default;`);
|
|
@@ -104,6 +109,7 @@ const buildWrappers = (input) => {
|
|
|
104
109
|
else {
|
|
105
110
|
lines.push(`export default __mod;`);
|
|
106
111
|
}
|
|
112
|
+
lines.push("");
|
|
107
113
|
for (const exportName of namedExports) {
|
|
108
114
|
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
109
115
|
lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
|
|
@@ -37,8 +37,16 @@ const server = (opt) => {
|
|
|
37
37
|
format: "esm",
|
|
38
38
|
sourcemap: opt.isDev ?? true,
|
|
39
39
|
entryFileNames: "[name].js",
|
|
40
|
-
chunkFileNames: "chunks/[
|
|
40
|
+
chunkFileNames: "chunks/[name].js",
|
|
41
41
|
assetFileNames: "assets/[hash][extname]",
|
|
42
|
+
// manualChunks(id) {
|
|
43
|
+
// const filename = path.basename(id);
|
|
44
|
+
// return filename.split(".")[0];
|
|
45
|
+
// return "vendor";
|
|
46
|
+
// if (id.includes("virtual:xanix-document")) {
|
|
47
|
+
// return "vendor";
|
|
48
|
+
// }
|
|
49
|
+
// },
|
|
42
50
|
};
|
|
43
51
|
};
|
|
44
52
|
const bundlerOutput = {
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
const __dirname = fileURLToPath(import.meta.url);
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
|
+
const VIRTUAL_ID = "virtual:xanix-document";
|
|
8
|
+
const RESOLVED_ID = "\0virtual:xanix-document";
|
|
9
|
+
export default function xanixDocument() {
|
|
10
|
+
const root = process.cwd();
|
|
11
|
+
const userDocument = path.resolve(root, "Document.tsx");
|
|
12
|
+
const baseDocument = require.resolve("../../../../../dist/components/BaseDocument.js");
|
|
13
|
+
return {
|
|
14
|
+
name: "xanix-document",
|
|
15
|
+
resolveId(id) {
|
|
16
|
+
if (id === VIRTUAL_ID) {
|
|
17
|
+
return RESOLVED_ID;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
},
|
|
21
|
+
load(id) {
|
|
22
|
+
if (id !== RESOLVED_ID) {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
const document = fs.existsSync(userDocument)
|
|
26
|
+
? userDocument
|
|
27
|
+
: baseDocument;
|
|
28
|
+
return `
|
|
29
|
+
import Document from ${JSON.stringify(document)};
|
|
30
|
+
|
|
31
|
+
export default Document;
|
|
32
|
+
`;
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import dotenv from "dotenv";
|
|
4
4
|
import replace from "@rollup/plugin-replace";
|
|
5
|
+
import { getClientRuntimeFileName, getDocumentFileName, } from "../../include/utils.js";
|
|
5
6
|
export default function XanixEnvPlugin(options = {}) {
|
|
6
7
|
const root = process.cwd();
|
|
7
8
|
const mode = options.mode ?? "development";
|
|
@@ -31,13 +32,22 @@ export default function XanixEnvPlugin(options = {}) {
|
|
|
31
32
|
}
|
|
32
33
|
const envs = {
|
|
33
34
|
"process.env.NODE_ENV": JSON.stringify(mode),
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
...(isClient ? clientEnv : serverEnv),
|
|
36
|
+
__XANIX_CLIENT_RUNTIME_FILE_NAME__: JSON.stringify(getClientRuntimeFileName(mode)),
|
|
37
|
+
__XANIX_DOCUMENT_FILE_NAME__: JSON.stringify(getDocumentFileName(mode)),
|
|
38
|
+
// XANIX Data
|
|
39
|
+
XANIXDT: JSON.stringify("globalThis.$XANIXDT"),
|
|
36
40
|
__XANIX_CLIENT__: JSON.stringify(isClient),
|
|
37
41
|
__XANIX_SERVER__: JSON.stringify(!isClient),
|
|
38
42
|
__XANIX_DEV__: JSON.stringify(mode === "development"),
|
|
39
43
|
__XANIX_PROD__: JSON.stringify(mode === "production"),
|
|
40
|
-
|
|
44
|
+
XANIX_NAVIGATE: JSON.stringify("xanix:navigate"),
|
|
45
|
+
XANIX_NAVIGATE_START: JSON.stringify("xanix:navigate:start"),
|
|
46
|
+
XANIX_NAVIGATE_END: JSON.stringify("xanix:navigate:end"),
|
|
47
|
+
XANIX_NAVIGATE_RELOAD: JSON.stringify("xanix:navigate:reload"),
|
|
48
|
+
XANIX_PRELOAD: JSON.stringify("xanix:preload"),
|
|
49
|
+
XANIX_PRELOAD_START: JSON.stringify("xanix:preload:start"),
|
|
50
|
+
XANIX_PRELOAD_END: JSON.stringify("xanix:preload:end"),
|
|
41
51
|
};
|
|
42
52
|
return replace({
|
|
43
53
|
preventAssignment: true,
|
|
@@ -16,39 +16,39 @@ export default function xanixReactRefresh() {
|
|
|
16
16
|
return null;
|
|
17
17
|
}
|
|
18
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
|
-
}
|
|
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
52
|
`;
|
|
53
53
|
return {
|
|
54
54
|
code: refreshCode,
|
|
@@ -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;
|