xanix 1.0.5 → 1.0.8
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/{buildCache.js → cacheNpmModules copy.js } +71 -21
- package/dist/bin/bundler/cacheNpmModules.js +9 -5
- 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 +10 -3
- package/dist/bin/bundler/plugins/XanixReactRefresh.js +29 -36
- 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 +2 -1
- package/dist/bin/include/utils.js +9 -6
- package/dist/bin/index.js +0 -0
- package/dist/client-runtime.js +15 -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 +11 -5
- package/dist/hooks/useData.d.ts +2 -6
- package/dist/hooks/useData.js +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -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 +26 -0
- package/dist/types/xanix-virtual.d.ts +26 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +4 -0
- package/package.json +79 -73
- package/dist/BaseDocument.d.ts +0 -3
- package/dist/BaseDocument.js +0 -8
- 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
- /package/dist/bin/bundler/{buildCache.d.ts → cacheNpmModules copy.d.ts} +0 -0
|
@@ -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;
|
|
@@ -1,31 +1,59 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { rollup } from "rollup";
|
|
3
|
+
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
3
4
|
import { build } from "esbuild";
|
|
4
5
|
import { createRequire } from "node:module";
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
6
|
+
import { getClientRuntimeFile, getDocumentFile } from "../include/utils.js";
|
|
7
|
+
import esbuild from "rollup-plugin-esbuild";
|
|
8
|
+
import url from "@rollup/plugin-url";
|
|
9
|
+
import XanixDocument from "./plugins/XanixDocument/index.js";
|
|
8
10
|
const require = createRequire(import.meta.url);
|
|
9
11
|
const GenerateGraph = async (entries) => {
|
|
10
12
|
const collector = new Map();
|
|
11
|
-
const input =
|
|
13
|
+
const input = [];
|
|
12
14
|
for (const entry of entries) {
|
|
13
|
-
input
|
|
15
|
+
input.push(entry.file);
|
|
14
16
|
}
|
|
15
|
-
input
|
|
16
|
-
input
|
|
17
|
+
input.push(getClientRuntimeFile());
|
|
18
|
+
input.push(await getDocumentFile());
|
|
17
19
|
const bundle = await rollup({
|
|
18
20
|
input,
|
|
19
21
|
plugins: [
|
|
20
|
-
|
|
21
|
-
|
|
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,
|
|
22
43
|
}),
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
XanixDocument(),
|
|
45
|
+
esbuild({
|
|
46
|
+
target: "es2022",
|
|
47
|
+
jsx: "automatic",
|
|
48
|
+
tsconfig: false,
|
|
25
49
|
}),
|
|
26
50
|
],
|
|
27
51
|
external(id) {
|
|
28
|
-
if (id.startsWith(".") ||
|
|
52
|
+
if (id.startsWith(".") ||
|
|
53
|
+
path.isAbsolute(id) ||
|
|
54
|
+
id === "@" ||
|
|
55
|
+
id.startsWith("@/") ||
|
|
56
|
+
id === "virtual:xanix-document") {
|
|
29
57
|
return false;
|
|
30
58
|
}
|
|
31
59
|
collector.set(id, {
|
|
@@ -61,22 +89,38 @@ const buildWrappers = (input) => {
|
|
|
61
89
|
for (const [name, resolved] of Object.entries(input)) {
|
|
62
90
|
const key = `${name}?cjs-wrapper`;
|
|
63
91
|
let namedExports = [];
|
|
92
|
+
let hasDefault = false;
|
|
64
93
|
try {
|
|
65
94
|
const mod = require(resolved);
|
|
66
|
-
|
|
95
|
+
hasDefault =
|
|
96
|
+
mod &&
|
|
97
|
+
(typeof mod === "object" || typeof mod === "function") &&
|
|
98
|
+
"default" in mod;
|
|
99
|
+
namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
// console.log(err);
|
|
103
|
+
}
|
|
104
|
+
const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
|
|
105
|
+
if (hasDefault) {
|
|
106
|
+
lines.push(`export default __mod.default;`);
|
|
67
107
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
108
|
+
else {
|
|
109
|
+
lines.push(`export default __mod;`);
|
|
110
|
+
}
|
|
111
|
+
lines.push("");
|
|
112
|
+
for (const exportName of namedExports) {
|
|
113
|
+
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
114
|
+
lines.push(`export const ${exportName} = __mod[${JSON.stringify(exportName)}];`);
|
|
115
|
+
}
|
|
75
116
|
}
|
|
76
117
|
wrappers.set(key, lines.join("\n"));
|
|
77
118
|
wrappedInput[name] = key;
|
|
78
119
|
}
|
|
79
|
-
return {
|
|
120
|
+
return {
|
|
121
|
+
wrappers,
|
|
122
|
+
wrappedInput,
|
|
123
|
+
};
|
|
80
124
|
};
|
|
81
125
|
const bundleDeps = async (input, outdir) => {
|
|
82
126
|
const { wrappers, wrappedInput } = buildWrappers(input);
|
|
@@ -91,6 +135,12 @@ const bundleDeps = async (input, outdir) => {
|
|
|
91
135
|
chunkNames: "chunks/[hash]",
|
|
92
136
|
platform: "browser",
|
|
93
137
|
sourcemap: true,
|
|
138
|
+
define: {
|
|
139
|
+
__XANIX_CLIENT__: "true",
|
|
140
|
+
__XANIX_SERVER__: "false",
|
|
141
|
+
__XANIX_DEV__: "true",
|
|
142
|
+
__XANIX_PROD__: "false",
|
|
143
|
+
},
|
|
94
144
|
plugins: [makeCjsWrapperPlugin(wrappers)],
|
|
95
145
|
});
|
|
96
146
|
};
|
|
@@ -3,9 +3,10 @@ import { rollup } from "rollup";
|
|
|
3
3
|
import { nodeResolve } from "@rollup/plugin-node-resolve";
|
|
4
4
|
import { build } from "esbuild";
|
|
5
5
|
import { createRequire } from "node:module";
|
|
6
|
-
import { getClientRuntimeFile
|
|
6
|
+
import { getClientRuntimeFile } 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();
|
|
@@ -14,11 +15,9 @@ const GenerateGraph = async (entries) => {
|
|
|
14
15
|
input.push(entry.file);
|
|
15
16
|
}
|
|
16
17
|
input.push(getClientRuntimeFile());
|
|
17
|
-
input.push(await getDocumentFile());
|
|
18
18
|
const bundle = await rollup({
|
|
19
19
|
input,
|
|
20
20
|
plugins: [
|
|
21
|
-
// XanixTsconfigAlias(),
|
|
22
21
|
nodeResolve({
|
|
23
22
|
extensions: [".mjs", ".js", ".jsx", ".json", ".ts", ".tsx"],
|
|
24
23
|
}),
|
|
@@ -41,6 +40,7 @@ const GenerateGraph = async (entries) => {
|
|
|
41
40
|
fileName: "assets/[name]-[hash][extname]",
|
|
42
41
|
emitFiles: false,
|
|
43
42
|
}),
|
|
43
|
+
XanixDocument(),
|
|
44
44
|
esbuild({
|
|
45
45
|
target: "es2022",
|
|
46
46
|
jsx: "automatic",
|
|
@@ -51,7 +51,8 @@ const GenerateGraph = async (entries) => {
|
|
|
51
51
|
if (id.startsWith(".") ||
|
|
52
52
|
path.isAbsolute(id) ||
|
|
53
53
|
id === "@" ||
|
|
54
|
-
id.startsWith("@/")
|
|
54
|
+
id.startsWith("@/") ||
|
|
55
|
+
id === "virtual:xanix-document") {
|
|
55
56
|
return false;
|
|
56
57
|
}
|
|
57
58
|
collector.set(id, {
|
|
@@ -96,7 +97,9 @@ const buildWrappers = (input) => {
|
|
|
96
97
|
"default" in mod;
|
|
97
98
|
namedExports = Object.keys(mod).filter((key) => key !== "__esModule" && key !== "default");
|
|
98
99
|
}
|
|
99
|
-
catch {
|
|
100
|
+
catch (err) {
|
|
101
|
+
// console.log(err);
|
|
102
|
+
}
|
|
100
103
|
const lines = [`import * as __mod from ${JSON.stringify(resolved)};`];
|
|
101
104
|
if (hasDefault) {
|
|
102
105
|
lines.push(`export default __mod.default;`);
|
|
@@ -104,6 +107,7 @@ const buildWrappers = (input) => {
|
|
|
104
107
|
else {
|
|
105
108
|
lines.push(`export default __mod;`);
|
|
106
109
|
}
|
|
110
|
+
lines.push("");
|
|
107
111
|
for (const exportName of namedExports) {
|
|
108
112
|
if (/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
|
|
109
113
|
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 } 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,19 @@ 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)),
|
|
36
37
|
__XANIX_CLIENT__: JSON.stringify(isClient),
|
|
37
38
|
__XANIX_SERVER__: JSON.stringify(!isClient),
|
|
38
39
|
__XANIX_DEV__: JSON.stringify(mode === "development"),
|
|
39
40
|
__XANIX_PROD__: JSON.stringify(mode === "production"),
|
|
40
|
-
|
|
41
|
+
XANIX_NAVIGATE: JSON.stringify("xanix:navigate"),
|
|
42
|
+
XANIX_NAVIGATE_START: JSON.stringify("xanix:navigate:start"),
|
|
43
|
+
XANIX_NAVIGATE_END: JSON.stringify("xanix:navigate:end"),
|
|
44
|
+
XANIX_NAVIGATE_RELOAD: JSON.stringify("xanix:navigate:reload"),
|
|
45
|
+
XANIX_PRELOAD: JSON.stringify("xanix:preload"),
|
|
46
|
+
XANIX_PRELOAD_START: JSON.stringify("xanix:preload:start"),
|
|
47
|
+
XANIX_PRELOAD_END: JSON.stringify("xanix:preload:end"),
|
|
41
48
|
};
|
|
42
49
|
return replace({
|
|
43
50
|
preventAssignment: true,
|
|
@@ -4,9 +4,7 @@ import { parse } from "@babel/parser";
|
|
|
4
4
|
import traverse from "@babel/traverse";
|
|
5
5
|
import generate from "@babel/generator";
|
|
6
6
|
import * as t from "@babel/types";
|
|
7
|
-
import { createRequire } from "node:module";
|
|
8
7
|
import { getClientRuntimeFile } from "../../include/utils.js";
|
|
9
|
-
const require = createRequire(import.meta.url);
|
|
10
8
|
const root = process.cwd();
|
|
11
9
|
export default function xanixReactRefresh() {
|
|
12
10
|
return {
|
|
@@ -16,39 +14,34 @@ export default function xanixReactRefresh() {
|
|
|
16
14
|
return null;
|
|
17
15
|
}
|
|
18
16
|
const code = fs.readFileSync(id, "utf8");
|
|
19
|
-
const refreshCode = `
|
|
20
|
-
import * as RefreshRuntime from "react-refresh/runtime";
|
|
21
|
-
|
|
22
|
-
${code}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
RefreshRuntime.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
RefreshRuntime.performReactRefresh();
|
|
49
|
-
ws.send("reload")
|
|
50
|
-
};
|
|
51
|
-
}
|
|
17
|
+
const refreshCode = `
|
|
18
|
+
import * as RefreshRuntime from "react-refresh/runtime";
|
|
19
|
+
|
|
20
|
+
${code}
|
|
21
|
+
|
|
22
|
+
RefreshRuntime.injectIntoGlobalHook(window);
|
|
23
|
+
window.$RefreshReg$ = RefreshRuntime.register;
|
|
24
|
+
window.$RefreshSig$ = () => (type) => type;
|
|
25
|
+
const ws = new WebSocket("ws://localhost:8080");
|
|
26
|
+
ws.onmessage = async (event) => {
|
|
27
|
+
const files = JSON.parse(event.data);
|
|
28
|
+
|
|
29
|
+
for (const file of files) {
|
|
30
|
+
if (!file.endsWith(".js")) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const url =
|
|
35
|
+
getImportUrl(file.replace(/\\.js$/, "")) +
|
|
36
|
+
"?t=" +
|
|
37
|
+
Date.now();
|
|
38
|
+
|
|
39
|
+
await import(url);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
RefreshRuntime.performReactRefresh();
|
|
43
|
+
ws.send("reload")
|
|
44
|
+
};
|
|
52
45
|
`;
|
|
53
46
|
return {
|
|
54
47
|
code: refreshCode,
|
|
@@ -59,7 +52,7 @@ if (typeof window !== "undefined") {
|
|
|
59
52
|
if (path.resolve(id) === getClientRuntimeFile()) {
|
|
60
53
|
return null;
|
|
61
54
|
}
|
|
62
|
-
if (id.includes("node_modules")
|
|
55
|
+
if (id.includes("node_modules")) {
|
|
63
56
|
return null;
|
|
64
57
|
}
|
|
65
58
|
if (!/\.(tsx?|jsx?)$/.test(id)) {
|
|
@@ -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;
|