@xfe-repo/web-app 2.0.0-beta.1 → 2.0.0-beta.3
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/README.md +60 -2
- package/deploy/.drone.yml +7 -0
- package/deploy/Dockerfile +3 -2
- package/dist/cli.js +486 -187
- package/dist/cli.mjs +475 -175
- package/dist/config.d.mts +11 -1
- package/dist/config.d.ts +11 -1
- package/dist/config.js +68 -10
- package/dist/config.mjs +59 -4
- package/dist/framework.js +88 -44
- package/dist/framework.mjs +47 -3
- package/dist/node-dev.d.mts +2 -0
- package/dist/node-dev.d.ts +2 -0
- package/dist/node-dev.js +356 -0
- package/dist/node-dev.mjs +331 -0
- package/dist/node.d.mts +27 -0
- package/dist/node.d.ts +27 -0
- package/dist/node.js +379 -0
- package/dist/node.mjs +342 -0
- package/dist/react-router-config.js +50 -7
- package/dist/react-router-config.mjs +46 -5
- package/dist/vite.d.mts +1 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +55 -10
- package/dist/vite.mjs +46 -1
- package/package.json +6 -2
package/dist/vite.mjs
CHANGED
|
@@ -5,9 +5,12 @@ import { reactRouter } from "@react-router/dev/vite";
|
|
|
5
5
|
import { defineConfig, loadEnv } from "vite";
|
|
6
6
|
|
|
7
7
|
// src/config.ts
|
|
8
|
-
import path from "path";
|
|
9
8
|
import fs from "fs";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import { fileURLToPath } from "url";
|
|
10
11
|
import yaml from "yaml";
|
|
12
|
+
var DEFAULT_BUILD_DIRECTORY = "dist";
|
|
13
|
+
var protectedDirectories = /* @__PURE__ */ new Set(["src", "types", "public", "node_modules", ".git"]);
|
|
11
14
|
var loadXfeConfig = (root = process.cwd()) => {
|
|
12
15
|
const xfeConfigPath = path.join(root, "xfe.json");
|
|
13
16
|
if (!fs.existsSync(xfeConfigPath)) {
|
|
@@ -19,8 +22,49 @@ var loadXfeConfig = (root = process.cwd()) => {
|
|
|
19
22
|
if (renderMode !== void 0 && renderMode !== "client" && renderMode !== "server") {
|
|
20
23
|
throw new Error("xfe.json.webapp.renderMode \u53EA\u80FD\u4E3A client \u6216 server");
|
|
21
24
|
}
|
|
25
|
+
getBuildDirectory(root, config.webapp);
|
|
26
|
+
getServerEntry(root, config.webapp);
|
|
22
27
|
return config;
|
|
23
28
|
};
|
|
29
|
+
var getBuildDirectory = (projectRoot, webapp = {}) => {
|
|
30
|
+
const configured = webapp?.buildDirectory === void 0 ? DEFAULT_BUILD_DIRECTORY : webapp.buildDirectory;
|
|
31
|
+
if (typeof configured !== "string" || !configured.trim() || /[\0\r\n]/.test(configured)) {
|
|
32
|
+
throw new Error("xfe.json.webapp.buildDirectory \u5FC5\u987B\u662F\u975E\u7A7A\u7684\u5355\u884C\u5B57\u7B26\u4E32");
|
|
33
|
+
}
|
|
34
|
+
const directory = configured.trim().replaceAll("\\", "/");
|
|
35
|
+
const root = path.resolve(projectRoot);
|
|
36
|
+
const output = path.resolve(root, directory);
|
|
37
|
+
const relative = path.relative(root, output);
|
|
38
|
+
const [firstDirectory = ""] = relative.split(path.sep);
|
|
39
|
+
const escapesProject = path.isAbsolute(directory) || Boolean(path.win32.parse(directory).root) || firstDirectory === "..";
|
|
40
|
+
const overwritesInput = !relative || protectedDirectories.has(firstDirectory.toLowerCase());
|
|
41
|
+
if (escapesProject || overwritesInput) {
|
|
42
|
+
throw new Error("xfe.json.webapp.buildDirectory \u5FC5\u987B\u662F\u9879\u76EE\u5185\u72EC\u7ACB\u7684\u8F93\u51FA\u76EE\u5F55\uFF0C\u4E0D\u80FD\u8986\u76D6\u9879\u76EE\u3001\u6E90\u7801\u6216\u4F9D\u8D56");
|
|
43
|
+
}
|
|
44
|
+
let currentDirectory = root;
|
|
45
|
+
for (const segment of relative.split(path.sep)) {
|
|
46
|
+
currentDirectory = path.join(currentDirectory, segment);
|
|
47
|
+
if (fs.lstatSync(currentDirectory, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
48
|
+
throw new Error("xfe.json.webapp.buildDirectory \u4E0D\u80FD\u7ECF\u8FC7\u7B26\u53F7\u94FE\u63A5\uFF0C\u4EE5\u514D\u6E05\u7406\u5176\u4ED6\u76EE\u5F55");
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return output;
|
|
52
|
+
};
|
|
53
|
+
var getServerEntry = (projectRoot, webapp = {}) => {
|
|
54
|
+
const entry = webapp?.serverEntry;
|
|
55
|
+
if (entry === void 0) return;
|
|
56
|
+
if (typeof entry !== "string" || !entry.trim() || /[\0\r\n]/.test(entry)) {
|
|
57
|
+
throw new Error("xfe.json.webapp.serverEntry \u5FC5\u987B\u662F\u9879\u76EE\u5185\u7684 TypeScript / JavaScript \u76F8\u5BF9\u8DEF\u5F84");
|
|
58
|
+
}
|
|
59
|
+
const normalized = entry.trim().replaceAll("\\", "/");
|
|
60
|
+
const absolute = path.resolve(projectRoot, normalized);
|
|
61
|
+
const relative = path.relative(path.resolve(projectRoot), absolute);
|
|
62
|
+
const outside = Boolean(path.win32.parse(normalized).root) || relative.split(path.sep)[0] === "..";
|
|
63
|
+
if (outside || !/\.(?:[jt]sx?|m[jt]s)$/.test(relative)) {
|
|
64
|
+
throw new Error("xfe.json.webapp.serverEntry \u5FC5\u987B\u662F\u9879\u76EE\u5185\u7684 TypeScript / JavaScript \u76F8\u5BF9\u8DEF\u5F84");
|
|
65
|
+
}
|
|
66
|
+
return absolute;
|
|
67
|
+
};
|
|
24
68
|
|
|
25
69
|
// src/vite.ts
|
|
26
70
|
var chromeDevToolsConfigPath = "/.well-known/appspecific/com.chrome.devtools.json";
|
|
@@ -52,6 +96,7 @@ var vite_default = defineConfig(({ mode }) => {
|
|
|
52
96
|
const { webapp = {} } = loadXfeConfig(projectRoot);
|
|
53
97
|
const publicEnv = (key) => process.env[key] || env[key] || "";
|
|
54
98
|
return {
|
|
99
|
+
...webapp.serverEntry ? { base: path2.posix.join(webapp.basename || "/", "/") } : {},
|
|
55
100
|
plugins: [frameworkPlugin(webapp.renderMode === "client"), reactRouter()],
|
|
56
101
|
build: { emptyOutDir: true },
|
|
57
102
|
envDir: projectRoot,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-app",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.3",
|
|
4
4
|
"bin": {
|
|
5
5
|
"xfe-web": "./bin/index.js"
|
|
6
6
|
},
|
|
@@ -17,8 +17,10 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@react-router/dev": "8.3.0",
|
|
20
|
+
"@react-router/express": "8.3.0",
|
|
20
21
|
"@react-router/serve": "8.3.0",
|
|
21
22
|
"@types/node": "^22.0.0",
|
|
23
|
+
"esbuild": "^0.27.7",
|
|
22
24
|
"express": "5.2.1",
|
|
23
25
|
"isbot": "^5.1.36",
|
|
24
26
|
"less": "^4.1.3",
|
|
@@ -26,6 +28,7 @@
|
|
|
26
28
|
"typescript": "~5.9.3",
|
|
27
29
|
"vite": "^8.2.1",
|
|
28
30
|
"yaml": "^2.4.2",
|
|
31
|
+
"tsx": "4.23.15",
|
|
29
32
|
"@xfe-repo/eslint-config": "2.0.0-beta.1",
|
|
30
33
|
"@xfe-repo/web-router": "2.0.0-beta.1",
|
|
31
34
|
"@xfe-repo/typescript-config": "2.0.0-beta.1"
|
|
@@ -44,6 +47,7 @@
|
|
|
44
47
|
"build": "tsup",
|
|
45
48
|
"dev": "tsup --watch",
|
|
46
49
|
"lint": "eslint \"src/**/*.ts*\" --fix",
|
|
47
|
-
"clean": "rm -rf .turbo coverage dist node_modules"
|
|
50
|
+
"clean": "rm -rf .turbo coverage dist node_modules",
|
|
51
|
+
"test": "pnpm build && node --test test/*.test.cjs"
|
|
48
52
|
}
|
|
49
53
|
}
|