xanix 1.0.9 → 1.0.11
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 +4 -3
- package/dist/bin/bundler/buildServer.js +4 -3
- package/dist/bin/bundler/cacheNpmModules.js +2 -1
- package/dist/bin/bundler/config/output.d.ts +0 -4
- package/dist/bin/bundler/config/output.js +3 -7
- package/dist/bin/bundler/plugins/XanixEntryFinder/finder.js +2 -1
- package/dist/bin/bundler/plugins/XanixPageTransform/index.d.ts +2 -0
- package/dist/bin/bundler/plugins/XanixPageTransform/index.js +19 -0
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer.d.ts +16 -0
- package/dist/bin/bundler/plugins/XanixPageTransform/transformer.js +501 -0
- package/dist/bin/bundler/plugins/XanixPageTransform.d.ts +0 -0
- package/dist/bin/bundler/plugins/XanixPageTransform.js +1 -0
- package/dist/bin/bundler/plugins/XanixResolveCacheDeps/index.js +6 -2
- package/dist/bin/bundler/plugins/XanixServerTransform.d.ts +5 -0
- package/dist/bin/bundler/plugins/XanixServerTransform.js +130 -0
- package/dist/bin/bundler/plugins/XanixTransform/index.d.ts +1 -4
- package/dist/bin/bundler/plugins/XanixTransform/index.js +2 -2
- package/dist/bin/bundler/plugins/XanixTransform/transformer.d.ts +1 -1
- package/dist/bin/bundler/plugins/XanixTransform/transformer.js +1 -131
- package/dist/bin/bundler/plugins/plugins.js +4 -3
- package/dist/bin/bundler/watchClient.js +4 -3
- package/dist/bin/bundler/watchServer.js +4 -4
- package/dist/bin/cli/dev.js +2 -2
- package/dist/bin/cli/start.js +2 -2
- package/dist/bin/include/manifest.js +2 -1
- package/dist/client-runtime.js +2 -1
- package/dist/components/Head.js +2 -1
- package/dist/dirs.d.ts +0 -0
- package/dist/dirs.js +1 -0
- package/dist/hooks/useData.js +2 -1
- package/dist/index.d.ts +1 -0
- package/dist/outdir.d.ts +8 -0
- package/dist/outdir.js +9 -0
- package/dist/outdirs.d.ts +8 -0
- package/dist/outdirs.js +9 -0
- package/dist/server/runtime/createServer.js +7 -6
- package/dist/server/runtime/readManifest.js +2 -1
- package/dist/types/globals.d.ts +0 -1
- package/package.json +1 -1
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { parse } from "@babel/parser";
|
|
2
|
+
import traverse from "@babel/traverse";
|
|
3
|
+
import generate from "@babel/generator";
|
|
4
|
+
import * as t from "@babel/types";
|
|
5
|
+
const RUNTIME_IMPORT = "xanix/runtime";
|
|
6
|
+
function findExpressServer(ast) {
|
|
7
|
+
let appName = null;
|
|
8
|
+
traverse(ast, {
|
|
9
|
+
CallExpression(path) {
|
|
10
|
+
const node = path.node;
|
|
11
|
+
// Find:
|
|
12
|
+
// app.listen(...)
|
|
13
|
+
if (!t.isMemberExpression(node.callee) ||
|
|
14
|
+
!t.isIdentifier(node.callee.property, {
|
|
15
|
+
name: "listen",
|
|
16
|
+
}) ||
|
|
17
|
+
!t.isIdentifier(node.callee.object)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const variableName = node.callee.object.name;
|
|
21
|
+
// Find the binding of `app`
|
|
22
|
+
const binding = path.scope.getBinding(variableName);
|
|
23
|
+
if (!binding || !binding.path.isVariableDeclarator()) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const init = binding.path.node.init;
|
|
27
|
+
// Confirm:
|
|
28
|
+
// const app = express();
|
|
29
|
+
if (t.isCallExpression(init) &&
|
|
30
|
+
t.isIdentifier(init.callee, {
|
|
31
|
+
name: "express",
|
|
32
|
+
})) {
|
|
33
|
+
appName = variableName;
|
|
34
|
+
path.stop();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
});
|
|
38
|
+
return appName;
|
|
39
|
+
}
|
|
40
|
+
function injectRuntimeImport(ast) {
|
|
41
|
+
let runtimeImport = null;
|
|
42
|
+
for (const statement of ast.program.body) {
|
|
43
|
+
if (t.isImportDeclaration(statement) &&
|
|
44
|
+
statement.source.value === RUNTIME_IMPORT) {
|
|
45
|
+
runtimeImport = statement;
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (runtimeImport) {
|
|
50
|
+
const exists = runtimeImport.specifiers.some((specifier) => t.isImportSpecifier(specifier) &&
|
|
51
|
+
t.isIdentifier(specifier.imported, {
|
|
52
|
+
name: "createXanixServer",
|
|
53
|
+
}));
|
|
54
|
+
if (!exists) {
|
|
55
|
+
runtimeImport.specifiers.push(t.importSpecifier(t.identifier("createXanixServer"), t.identifier("createXanixServer")));
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
ast.program.body.unshift(t.importDeclaration([
|
|
60
|
+
t.importSpecifier(t.identifier("createXanixServer"), t.identifier("createXanixServer")),
|
|
61
|
+
], t.stringLiteral(RUNTIME_IMPORT)));
|
|
62
|
+
}
|
|
63
|
+
export default function XanixServerTransform(options) {
|
|
64
|
+
return {
|
|
65
|
+
name: "xanix-server-transform",
|
|
66
|
+
transform(code, id) {
|
|
67
|
+
// Ignore node_modules
|
|
68
|
+
if (id.includes("node_modules")) {
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
// Only process JS/TS files
|
|
72
|
+
if (!/\.[cm]?[jt]sx?$/.test(id)) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
let ast;
|
|
76
|
+
try {
|
|
77
|
+
ast = parse(code, {
|
|
78
|
+
sourceType: "module",
|
|
79
|
+
plugins: ["typescript", "jsx"],
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
// Find the REAL server app
|
|
86
|
+
const appName = findExpressServer(ast);
|
|
87
|
+
if (!appName) {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
let changed = false;
|
|
91
|
+
traverse(ast, {
|
|
92
|
+
VariableDeclarator(path) {
|
|
93
|
+
const node = path.node;
|
|
94
|
+
// Only transform:
|
|
95
|
+
// const app = express()
|
|
96
|
+
if (!t.isIdentifier(node.id, {
|
|
97
|
+
name: appName,
|
|
98
|
+
})) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (!t.isCallExpression(node.init) ||
|
|
102
|
+
!t.isIdentifier(node.init.callee, {
|
|
103
|
+
name: "express",
|
|
104
|
+
})) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
node.init = t.callExpression(t.identifier("createXanixServer"), [
|
|
108
|
+
t.objectExpression([
|
|
109
|
+
t.objectProperty(t.identifier("mode"), t.stringLiteral(options.mode)),
|
|
110
|
+
]),
|
|
111
|
+
]);
|
|
112
|
+
changed = true;
|
|
113
|
+
path.stop();
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
if (!changed) {
|
|
117
|
+
return null;
|
|
118
|
+
}
|
|
119
|
+
injectRuntimeImport(ast);
|
|
120
|
+
const output = generate(ast, {
|
|
121
|
+
sourceMaps: true,
|
|
122
|
+
sourceFileName: id,
|
|
123
|
+
}, code);
|
|
124
|
+
return {
|
|
125
|
+
code: output.code,
|
|
126
|
+
map: output.map,
|
|
127
|
+
};
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { transformer } from "./transformer.js";
|
|
2
|
-
export function XanixTransform(
|
|
2
|
+
export function XanixTransform() {
|
|
3
3
|
return {
|
|
4
4
|
name: "xanix-transform",
|
|
5
5
|
async transform(code, id) {
|
|
6
6
|
if (id.includes("node_modules") || !/\.(tsx?|jsx?)$/.test(id)) {
|
|
7
7
|
return null;
|
|
8
8
|
}
|
|
9
|
-
const result = transformer(code, id
|
|
9
|
+
const result = transformer(code, id);
|
|
10
10
|
if (!result) {
|
|
11
11
|
return null;
|
|
12
12
|
}
|
|
@@ -13,4 +13,4 @@ export declare function findComponentImport(ast: t.File, componentName: string):
|
|
|
13
13
|
declaration: t.ImportDeclaration;
|
|
14
14
|
specifier: t.ImportSpecifier | t.ImportDefaultSpecifier;
|
|
15
15
|
} | null;
|
|
16
|
-
export declare function transformer(code: string, id: string
|
|
16
|
+
export declare function transformer(code: string, id: string): XanixTransformResult | null;
|
|
@@ -309,109 +309,6 @@ function jsxToComponentAndProps(jsx) {
|
|
|
309
309
|
props,
|
|
310
310
|
};
|
|
311
311
|
}
|
|
312
|
-
/**
|
|
313
|
-
* Find:
|
|
314
|
-
*
|
|
315
|
-
* const app = express();
|
|
316
|
-
* const exp = express();
|
|
317
|
-
* const server = express();
|
|
318
|
-
*
|
|
319
|
-
* Returns the variable name.
|
|
320
|
-
*/
|
|
321
|
-
function findExpressAppVariable(ast) {
|
|
322
|
-
for (const statement of ast.program.body) {
|
|
323
|
-
if (!t.isVariableDeclaration(statement)) {
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
|
-
for (const declaration of statement.declarations) {
|
|
327
|
-
if (!t.isIdentifier(declaration.id)) {
|
|
328
|
-
continue;
|
|
329
|
-
}
|
|
330
|
-
if (!t.isCallExpression(declaration.init)) {
|
|
331
|
-
continue;
|
|
332
|
-
}
|
|
333
|
-
if (!t.isIdentifier(declaration.init.callee, {
|
|
334
|
-
name: "express",
|
|
335
|
-
})) {
|
|
336
|
-
continue;
|
|
337
|
-
}
|
|
338
|
-
return declaration.id.name;
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
return null;
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Replace:
|
|
345
|
-
*
|
|
346
|
-
* const app = express();
|
|
347
|
-
*
|
|
348
|
-
* with:
|
|
349
|
-
*
|
|
350
|
-
* const app = createXanixServer({
|
|
351
|
-
* mode: "watch"
|
|
352
|
-
* });
|
|
353
|
-
*/
|
|
354
|
-
function transformExpressAppTocreateXanixServer(ast, args) {
|
|
355
|
-
const expressVariable = findExpressAppVariable(ast);
|
|
356
|
-
if (!expressVariable) {
|
|
357
|
-
return false;
|
|
358
|
-
}
|
|
359
|
-
for (const statement of ast.program.body) {
|
|
360
|
-
if (!t.isVariableDeclaration(statement)) {
|
|
361
|
-
continue;
|
|
362
|
-
}
|
|
363
|
-
for (const declaration of statement.declarations) {
|
|
364
|
-
if (!t.isIdentifier(declaration.id)) {
|
|
365
|
-
continue;
|
|
366
|
-
}
|
|
367
|
-
if (declaration.id.name !== expressVariable) {
|
|
368
|
-
continue;
|
|
369
|
-
}
|
|
370
|
-
if (!t.isCallExpression(declaration.init)) {
|
|
371
|
-
continue;
|
|
372
|
-
}
|
|
373
|
-
if (!t.isIdentifier(declaration.init.callee, {
|
|
374
|
-
name: "express",
|
|
375
|
-
})) {
|
|
376
|
-
continue;
|
|
377
|
-
}
|
|
378
|
-
declaration.init = t.callExpression(t.identifier("createXanixServer"), [
|
|
379
|
-
t.objectExpression([
|
|
380
|
-
t.objectProperty(t.identifier("mode"), t.stringLiteral(args.mode)),
|
|
381
|
-
]),
|
|
382
|
-
]);
|
|
383
|
-
return true;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return false;
|
|
387
|
-
}
|
|
388
|
-
/**
|
|
389
|
-
* Remove:
|
|
390
|
-
*
|
|
391
|
-
* import express from "express";
|
|
392
|
-
*
|
|
393
|
-
* once express() has been replaced by
|
|
394
|
-
* createXanixServer().
|
|
395
|
-
*
|
|
396
|
-
* Also handles:
|
|
397
|
-
*
|
|
398
|
-
* import express, { Router } from "express";
|
|
399
|
-
*/
|
|
400
|
-
function removeExpressImport(ast) {
|
|
401
|
-
for (const statement of ast.program.body) {
|
|
402
|
-
if (!t.isImportDeclaration(statement)) {
|
|
403
|
-
continue;
|
|
404
|
-
}
|
|
405
|
-
if (statement.source.value !== "express") {
|
|
406
|
-
continue;
|
|
407
|
-
}
|
|
408
|
-
statement.specifiers = statement.specifiers.filter((specifier) => {
|
|
409
|
-
return !(t.isImportDefaultSpecifier(specifier) &&
|
|
410
|
-
specifier.local.name === "express");
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
removeEmptyImportDeclarations(ast);
|
|
414
|
-
}
|
|
415
312
|
function hasRuntimeImport(ast, name) {
|
|
416
313
|
for (const statement of ast.program.body) {
|
|
417
314
|
if (!t.isImportDeclaration(statement)) {
|
|
@@ -449,7 +346,7 @@ function injectRuntimeImport(ast, name) {
|
|
|
449
346
|
// No runtime import exists yet
|
|
450
347
|
ast.program.body.unshift(t.importDeclaration([t.importSpecifier(t.identifier(name), t.identifier(name))], t.stringLiteral(RUNTIME_IMPORT)));
|
|
451
348
|
}
|
|
452
|
-
export function transformer(code, id
|
|
349
|
+
export function transformer(code, id) {
|
|
453
350
|
const ast = parse(code, {
|
|
454
351
|
sourceType: "module",
|
|
455
352
|
plugins: ["typescript", "jsx"],
|
|
@@ -586,33 +483,6 @@ export function transformer(code, id, mode) {
|
|
|
586
483
|
if (!changed) {
|
|
587
484
|
return null;
|
|
588
485
|
}
|
|
589
|
-
/**
|
|
590
|
-
* Change:
|
|
591
|
-
*
|
|
592
|
-
* const app = express();
|
|
593
|
-
*
|
|
594
|
-
* into:
|
|
595
|
-
*
|
|
596
|
-
* const app = createXanixServer();
|
|
597
|
-
*/
|
|
598
|
-
const serverTransformed = transformExpressAppTocreateXanixServer(ast, {
|
|
599
|
-
mode,
|
|
600
|
-
});
|
|
601
|
-
if (serverTransformed) {
|
|
602
|
-
/**
|
|
603
|
-
* Remove:
|
|
604
|
-
*
|
|
605
|
-
* import express from "express";
|
|
606
|
-
*/
|
|
607
|
-
removeExpressImport(ast);
|
|
608
|
-
/**
|
|
609
|
-
* Add:
|
|
610
|
-
*
|
|
611
|
-
* import { createXanixServer }
|
|
612
|
-
* from "xanix/runtime";
|
|
613
|
-
*/
|
|
614
|
-
injectRuntimeImport(ast, "createXanixServer");
|
|
615
|
-
}
|
|
616
486
|
/**
|
|
617
487
|
* Add:
|
|
618
488
|
*
|
|
@@ -6,10 +6,11 @@ import json from "@rollup/plugin-json";
|
|
|
6
6
|
import esbuild from "rollup-plugin-esbuild";
|
|
7
7
|
import url from "@rollup/plugin-url";
|
|
8
8
|
import path from "path";
|
|
9
|
-
import
|
|
9
|
+
import XanixPageTransform from "./XanixPageTransform/index.js";
|
|
10
10
|
import xanixReactRefresh from "./XanixReactRefresh.js";
|
|
11
11
|
import XanixEnvPlugin from "./XanixEnv.js";
|
|
12
12
|
import xanixUseDataId from "./xanixUseDataId.js";
|
|
13
|
+
import XanixServerTransform from "./XanixServerTransform.js";
|
|
13
14
|
export function xanixDefaultPlugins(options = {}) {
|
|
14
15
|
const target = options.target ?? "client";
|
|
15
16
|
const development = options.development ?? true;
|
|
@@ -17,8 +18,8 @@ export function xanixDefaultPlugins(options = {}) {
|
|
|
17
18
|
const isServer = target === "server";
|
|
18
19
|
let _plugins = [];
|
|
19
20
|
if (isServer) {
|
|
20
|
-
_plugins.push(
|
|
21
|
-
|
|
21
|
+
_plugins.push(XanixPageTransform());
|
|
22
|
+
_plugins.push(XanixServerTransform({ mode: development ? "watch" : "start" }));
|
|
22
23
|
}
|
|
23
24
|
else {
|
|
24
25
|
if (development) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { watch } from "rollup";
|
|
2
|
-
import bundlerOutput
|
|
2
|
+
import bundlerOutput from "./config/output.js";
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import BuildCache from "./cacheNpmModules.js";
|
|
5
5
|
import XanixResolveCacheDeps from "./plugins/XanixResolveCacheDeps/index.js";
|
|
6
6
|
import { getClientRuntimeFile, getClientRuntimeFileName, } from "../include/utils.js";
|
|
7
7
|
import { xanixDefaultPlugins } from "./plugins/plugins.js";
|
|
8
|
+
import outdirs from "../../outdirs.js";
|
|
8
9
|
const WatchClient = async (entries, options) => {
|
|
9
10
|
const input = {};
|
|
10
11
|
for (const entry of entries) {
|
|
@@ -12,11 +13,11 @@ const WatchClient = async (entries, options) => {
|
|
|
12
13
|
}
|
|
13
14
|
const runtimeFileName = getClientRuntimeFileName("development");
|
|
14
15
|
input[runtimeFileName] = getClientRuntimeFile();
|
|
15
|
-
fs.rmSync(
|
|
16
|
+
fs.rmSync(outdirs.client, {
|
|
16
17
|
recursive: true,
|
|
17
18
|
force: true,
|
|
18
19
|
});
|
|
19
|
-
fs.mkdirSync(
|
|
20
|
+
fs.mkdirSync(outdirs.client, {
|
|
20
21
|
recursive: true,
|
|
21
22
|
});
|
|
22
23
|
let buildCache;
|
|
@@ -3,16 +3,17 @@ import path from "node:path";
|
|
|
3
3
|
import fs from "node:fs";
|
|
4
4
|
import { createManifest, readManifest } from "../include/manifest.js";
|
|
5
5
|
import generateClientEntries from "./generateClientEntries.js";
|
|
6
|
-
import bundlerOutput
|
|
6
|
+
import bundlerOutput from "./config/output.js";
|
|
7
7
|
import { entriesEqual } from "../include/entry.js";
|
|
8
8
|
import { xanixDefaultPlugins } from "./plugins/plugins.js";
|
|
9
|
+
import outdirs from "../../outdirs.js";
|
|
9
10
|
const root = process.cwd();
|
|
10
11
|
const watchServer = async ({ rootEntry, onChange, onBuildEnd, onServerChange, onClientEntryChange, }) => {
|
|
11
|
-
fs.rmSync(
|
|
12
|
+
fs.rmSync(outdirs.server, {
|
|
12
13
|
recursive: true,
|
|
13
14
|
force: true,
|
|
14
15
|
});
|
|
15
|
-
fs.mkdirSync(
|
|
16
|
+
fs.mkdirSync(outdirs.server, {
|
|
16
17
|
recursive: true,
|
|
17
18
|
});
|
|
18
19
|
const entries = await generateClientEntries();
|
|
@@ -31,7 +32,6 @@ const watchServer = async ({ rootEntry, onChange, onBuildEnd, onServerChange, on
|
|
|
31
32
|
assetExternal: false,
|
|
32
33
|
onChange: (entry) => {
|
|
33
34
|
changedFiles.add(entry);
|
|
34
|
-
return onChange?.(entry);
|
|
35
35
|
},
|
|
36
36
|
}),
|
|
37
37
|
],
|
package/dist/bin/cli/dev.js
CHANGED
|
@@ -5,14 +5,14 @@ import watchClient from "../bundler/watchClient.js";
|
|
|
5
5
|
import pc from "picocolors";
|
|
6
6
|
import logger from "../include/logger.js";
|
|
7
7
|
import { getEntries } from "../include/entry.js";
|
|
8
|
-
import { outDir } from "../bundler/config/output.js";
|
|
9
8
|
import { WebSocketServer } from "ws";
|
|
9
|
+
import outdirs from "../../outdirs.js";
|
|
10
10
|
const root = process.cwd();
|
|
11
11
|
let child;
|
|
12
12
|
function start() {
|
|
13
13
|
child?.kill();
|
|
14
14
|
return new Promise((resolve) => {
|
|
15
|
-
const filePath = path.join(
|
|
15
|
+
const filePath = path.join(outdirs.server, "index.js");
|
|
16
16
|
child = spawn(process.execPath, [filePath], {
|
|
17
17
|
stdio: !child ? "inherit" : "pipe",
|
|
18
18
|
});
|
package/dist/bin/cli/start.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { spawn } from "child_process";
|
|
3
|
-
import
|
|
3
|
+
import outdirs from "../../outdirs.js";
|
|
4
4
|
let child;
|
|
5
5
|
const start = async () => {
|
|
6
|
-
const filePath = path.join(
|
|
6
|
+
const filePath = path.join(outdirs.server, "index.js");
|
|
7
7
|
child = spawn(process.execPath, [filePath], {
|
|
8
8
|
stdio: "inherit",
|
|
9
9
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import fs from "node:fs";
|
|
3
|
+
import outdirs from "../../outdirs.js";
|
|
3
4
|
let readedManifest = null;
|
|
4
5
|
export const createManifest = async (entries) => {
|
|
5
6
|
const manifest = {
|
|
@@ -7,7 +8,7 @@ export const createManifest = async (entries) => {
|
|
|
7
8
|
entries: [...entries.values()],
|
|
8
9
|
};
|
|
9
10
|
readedManifest = manifest;
|
|
10
|
-
const outDir = path.resolve(process.cwd(),
|
|
11
|
+
const outDir = path.resolve(process.cwd(), outdirs.root);
|
|
11
12
|
fs.writeFileSync(path.resolve(outDir, "client-manifest.json"), JSON.stringify(manifest, null, 2));
|
|
12
13
|
};
|
|
13
14
|
export const readManifest = async () => readedManifest;
|
package/dist/client-runtime.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createRoot } from "react-dom/client";
|
|
3
|
+
import outdirs from "./outdirs.js";
|
|
3
4
|
const pages = new Map();
|
|
4
5
|
const ROOT_KEY = "__xanix_root__";
|
|
5
6
|
export const getPath = () => {
|
|
6
7
|
const { pathname, search } = window.location;
|
|
7
8
|
return search ? `${pathname}${search}` : pathname;
|
|
8
9
|
};
|
|
9
|
-
export const getImportUrl = (pageId) =>
|
|
10
|
+
export const getImportUrl = (pageId) => `/${outdirs.client}/${pageId}.js`;
|
|
10
11
|
function getRoot() {
|
|
11
12
|
let ele = document.body;
|
|
12
13
|
if (!ele) {
|
package/dist/components/Head.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect } from "react";
|
|
3
3
|
import useDocument from "../hooks/useDocument.js";
|
|
4
|
+
import outdirs from "../outdirs.js";
|
|
4
5
|
const Head = ({ children }) => {
|
|
5
6
|
const { title, meta, pageId, props, params, pageData } = useDocument();
|
|
6
7
|
if (__XANIX_CLIENT__) {
|
|
@@ -39,7 +40,7 @@ const Head = ({ children }) => {
|
|
|
39
40
|
request: null,
|
|
40
41
|
})};
|
|
41
42
|
`,
|
|
42
|
-
} }), _jsx("script", { type: "module", src:
|
|
43
|
+
} }), _jsx("script", { type: "module", src: `/${outdirs.client}/${__XANIX_CLIENT_RUNTIME_FILE_NAME__}.js` })] }));
|
|
43
44
|
}
|
|
44
45
|
};
|
|
45
46
|
export default Head;
|
package/dist/dirs.d.ts
ADDED
|
File without changes
|
package/dist/dirs.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
package/dist/hooks/useData.js
CHANGED
|
@@ -2,6 +2,7 @@ import usePage from "./usePage.js";
|
|
|
2
2
|
import React, { useEffect, useRef } from "react";
|
|
3
3
|
import useDocument from "./useDocument.js";
|
|
4
4
|
import loader from "../dataLoader.js";
|
|
5
|
+
import outdirs from "../outdirs.js";
|
|
5
6
|
const useData = (_callback, _args) => {
|
|
6
7
|
return {};
|
|
7
8
|
};
|
|
@@ -31,7 +32,7 @@ useData.register = (xanixId, callback) => {
|
|
|
31
32
|
const init = useRef(false);
|
|
32
33
|
const reload = async () => {
|
|
33
34
|
setLoading(true);
|
|
34
|
-
const res = await fetch(
|
|
35
|
+
const res = await fetch(`/${outdirs.root}/__data__/${xanixId}`, {
|
|
35
36
|
method: "POST",
|
|
36
37
|
headers: {
|
|
37
38
|
"Content-Type": "application/json",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/// <reference path="./types/globals.d.ts" />
|
|
2
2
|
/// <reference path="./types/express.d.ts" />
|
|
3
3
|
/// <reference path="./types/assets.d.ts" />
|
|
4
|
+
/// <reference path="./types/xanix-virtual.d.ts" />
|
|
4
5
|
|
|
5
6
|
import Link from "./components/Link.js";
|
|
6
7
|
import Document, { DocumentProps } from "./components/Document.js";
|
package/dist/outdir.d.ts
ADDED
package/dist/outdir.js
ADDED
package/dist/outdirs.js
ADDED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import dataLoader from "../../dataLoader.js";
|
|
3
|
+
import outdirs from "../../outdirs.js";
|
|
3
4
|
function createXanixServer({ mode }) {
|
|
4
5
|
const app = express();
|
|
5
6
|
if (mode === "watch") {
|
|
6
|
-
app.use(
|
|
7
|
-
app.use(
|
|
8
|
-
app.use(
|
|
7
|
+
app.use(`/${outdirs.client}`, express.static(`${outdirs.client}`));
|
|
8
|
+
app.use(`/assets`, express.static(outdirs.assets));
|
|
9
|
+
app.use(`/${outdirs.cache}`, express.static(`${outdirs.cache}`));
|
|
9
10
|
}
|
|
10
11
|
else {
|
|
11
|
-
app.use(
|
|
12
|
+
app.use(`/${outdirs.client}`, express.static(`${outdirs.client}`, {
|
|
12
13
|
maxAge: "1y",
|
|
13
14
|
immutable: true,
|
|
14
15
|
etag: true,
|
|
15
16
|
}));
|
|
16
|
-
app.use(
|
|
17
|
+
app.use(`/assets`, express.static(outdirs.assets, {
|
|
17
18
|
maxAge: "1y",
|
|
18
19
|
immutable: true,
|
|
19
20
|
etag: true,
|
|
20
21
|
}));
|
|
21
22
|
}
|
|
22
|
-
app.post(
|
|
23
|
+
app.post(`/${outdirs.root}/__data__/:xanixId`, express.json(), async (req, res) => {
|
|
23
24
|
const { xanixId } = req.params;
|
|
24
25
|
const args = req.body;
|
|
25
26
|
const data = await dataLoader.result(xanixId, args);
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import outdirs from "../../outdirs";
|
|
3
4
|
async function readManifest() {
|
|
4
|
-
const manifestPath = path.resolve(process.cwd(),
|
|
5
|
+
const manifestPath = path.resolve(process.cwd(), outdirs.root, "client-manifest.json");
|
|
5
6
|
const source = await fs.readFile(manifestPath, "utf8");
|
|
6
7
|
return JSON.parse(source);
|
|
7
8
|
}
|
package/dist/types/globals.d.ts
CHANGED