@olenbetong/appframe-vite 5.1.29 → 5.1.31
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/lib/build.d.ts +1 -1
- package/lib/build.js +3 -3
- package/lib/devServer.d.ts +1 -1
- package/lib/devServer.js +19 -14
- package/lib/index.d.ts +1 -1
- package/lib/localization.d.ts +1 -1
- package/lib/localization.js +4 -3
- package/package.json +9 -8
package/lib/build.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { UserConfig } from "vite";
|
|
1
|
+
import type { UserConfig } from "vite";
|
|
2
2
|
export declare function addAppframeBuildConfig(config: UserConfig): Promise<UserConfig>;
|
package/lib/build.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
3
|
import { visualizer } from "rollup-plugin-visualizer";
|
|
4
4
|
import { viteExternalsPlugin } from "vite-plugin-externals";
|
|
@@ -20,10 +20,10 @@ export async function addAppframeBuildConfig(config) {
|
|
|
20
20
|
}));
|
|
21
21
|
}
|
|
22
22
|
let entry = resolve(process.cwd(), "./src/index.tsx");
|
|
23
|
-
if (!(
|
|
23
|
+
if (!existsSync(resolve(entry))) {
|
|
24
24
|
entry = resolve(process.cwd(), "./src/index.ts");
|
|
25
25
|
}
|
|
26
|
-
if (!(
|
|
26
|
+
if (!existsSync(resolve(entry))) {
|
|
27
27
|
entry = resolve(process.cwd(), "./src/index.js");
|
|
28
28
|
}
|
|
29
29
|
config.build.rollupOptions = {
|
package/lib/devServer.d.ts
CHANGED
package/lib/devServer.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Client } from "@olenbetong/appframe-data";
|
|
2
2
|
import dotenv from "dotenv";
|
|
3
|
-
import { exists } from "node:fs/promises";
|
|
4
3
|
import { JSDOM } from "jsdom";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
5
|
import { mkdir, readFile, stat, writeFile } from "node:fs/promises";
|
|
6
6
|
import { resolve } from "node:path";
|
|
7
7
|
import { importJson } from "./importJson.js";
|
|
@@ -56,10 +56,10 @@ export function getProxyRoutes() {
|
|
|
56
56
|
*/
|
|
57
57
|
async function transformArticleHtml(html) {
|
|
58
58
|
let entry;
|
|
59
|
-
if (
|
|
59
|
+
if (existsSync(resolve(process.cwd(), "./src/index.tsx"))) {
|
|
60
60
|
entry = "/src/index.tsx";
|
|
61
61
|
}
|
|
62
|
-
else if (
|
|
62
|
+
else if (existsSync(resolve(process.cwd(), "./src/index.ts"))) {
|
|
63
63
|
entry = "/src/index.ts";
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
@@ -70,7 +70,8 @@ async function transformArticleHtml(html) {
|
|
|
70
70
|
let dom = new JSDOM(html);
|
|
71
71
|
let nodesToRemove = [];
|
|
72
72
|
let mainScriptAdded = false;
|
|
73
|
-
dom.window.document.querySelectorAll("script")
|
|
73
|
+
let scriptTags = dom.window.document.querySelectorAll("script");
|
|
74
|
+
for (let script of scriptTags) {
|
|
74
75
|
if (script.src?.startsWith(`/file/article/script/${article}/main`)) {
|
|
75
76
|
let mainScript = dom.window.document.createElement("script");
|
|
76
77
|
mainScript.type = "module";
|
|
@@ -96,27 +97,31 @@ async function transformArticleHtml(html) {
|
|
|
96
97
|
localizeScript.textContent = `Object.assign(af.article.i18n, ${JSON.stringify(cachedStrings)})`;
|
|
97
98
|
script.insertAdjacentElement("afterend", localizeScript);
|
|
98
99
|
}
|
|
99
|
-
}
|
|
100
|
+
}
|
|
100
101
|
if (!mainScriptAdded) {
|
|
101
102
|
let mainScript = dom.window.document.createElement("script");
|
|
102
103
|
mainScript.type = "module";
|
|
103
104
|
mainScript.src = entry;
|
|
104
105
|
dom.window.document.body.appendChild(mainScript);
|
|
105
106
|
}
|
|
106
|
-
dom.window.document.querySelectorAll("link")
|
|
107
|
+
let linkTags = dom.window.document.querySelectorAll("link");
|
|
108
|
+
for (let link of linkTags) {
|
|
107
109
|
if (link.rel === "stylesheet" && link.href?.startsWith(`/file/article/style/${article}`)) {
|
|
108
110
|
nodesToRemove.push(link);
|
|
109
111
|
}
|
|
110
112
|
else if (link.rel === "prefetch" && link.href?.startsWith(`/file/article`)) {
|
|
111
113
|
nodesToRemove.push(link);
|
|
112
114
|
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
|
|
115
|
+
}
|
|
116
|
+
for (let node of nodesToRemove) {
|
|
117
|
+
node.remove();
|
|
118
|
+
}
|
|
119
|
+
let anchors = dom.window.document.querySelectorAll("a");
|
|
120
|
+
for (let anchor of anchors) {
|
|
116
121
|
if (anchor.href?.startsWith("/") && !anchor.href?.startsWith(`/${article}`)) {
|
|
117
122
|
anchor.href = `https://${hostname}${anchor.href}`;
|
|
118
123
|
}
|
|
119
|
-
}
|
|
124
|
+
}
|
|
120
125
|
return dom.serialize();
|
|
121
126
|
}
|
|
122
127
|
async function getArticleHtml() {
|
|
@@ -136,7 +141,7 @@ async function getArticleHtml() {
|
|
|
136
141
|
const cachePath = resolve(process.cwd(), "./node_modules/.appframe");
|
|
137
142
|
const cacheFile = resolve(cachePath, "./index.html");
|
|
138
143
|
async function getCacheAge() {
|
|
139
|
-
if (
|
|
144
|
+
if (existsSync(cacheFile)) {
|
|
140
145
|
let file = await stat(cacheFile);
|
|
141
146
|
let age = (Date.now() - file.mtime.getTime()) / 1000;
|
|
142
147
|
return age;
|
|
@@ -158,7 +163,7 @@ async function getCachedOrArticleHtml(skipCache = false) {
|
|
|
158
163
|
}
|
|
159
164
|
if (!html) {
|
|
160
165
|
html = await getArticleHtml();
|
|
161
|
-
if (!(
|
|
166
|
+
if (!existsSync(cacheFile)) {
|
|
162
167
|
await mkdir(cachePath, { recursive: true });
|
|
163
168
|
}
|
|
164
169
|
await writeFile(cacheFile, html, { encoding: "utf-8" });
|
|
@@ -171,10 +176,10 @@ export function createDevMiddleware(vite) {
|
|
|
171
176
|
let url = req.originalUrl;
|
|
172
177
|
let article = appPkg.appframe.article.id;
|
|
173
178
|
let isLogin = article === "login";
|
|
174
|
-
let isRootArticle = isLogin ? url === "/" : url?.startsWith(
|
|
179
|
+
let isRootArticle = isLogin ? url === "/" : url?.startsWith(`/${appPkg.appframe.article.id}`);
|
|
175
180
|
if (!isRootArticle && Array.isArray(appPkg.appframe.article.altNames)) {
|
|
176
181
|
for (let name of appPkg.appframe.article.altNames) {
|
|
177
|
-
if (url?.startsWith(
|
|
182
|
+
if (url?.startsWith(`/${name}`)) {
|
|
178
183
|
isRootArticle = true;
|
|
179
184
|
break;
|
|
180
185
|
}
|
package/lib/index.d.ts
CHANGED
package/lib/localization.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Connect } from "vite";
|
|
1
|
+
import type { Connect } from "vite";
|
|
2
2
|
export declare function addStringToCache(text: string, translation: string): void;
|
|
3
3
|
export declare const localizeMiddleware: Connect.NextHandleFunction;
|
|
4
4
|
export declare function getStringCache(): {
|
package/lib/localization.js
CHANGED
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
* handler that generates the article HTML, we then get the cached strings,
|
|
11
11
|
* and add a script that adds the strings to the client cache.
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import { existsSync } from "node:fs";
|
|
14
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
14
15
|
import { resolve } from "node:path";
|
|
15
16
|
import { getLoginInfo } from "./devServer.js";
|
|
16
17
|
import { importJson } from "./importJson.js";
|
|
@@ -25,14 +26,14 @@ function debounce(callback, delay = 300) {
|
|
|
25
26
|
const stringCache = new Map();
|
|
26
27
|
const cachePath = resolve(process.cwd(), "./node_modules/.appframe");
|
|
27
28
|
const cacheFile = resolve(cachePath, "./localizeCache.json");
|
|
28
|
-
if (
|
|
29
|
+
if (existsSync(cacheFile)) {
|
|
29
30
|
let cache = await importJson(cacheFile, true);
|
|
30
31
|
for (let text in cache) {
|
|
31
32
|
stringCache.set(text, cache[text]);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
async function saveCacheToFile() {
|
|
35
|
-
if (!(
|
|
36
|
+
if (!existsSync(cacheFile)) {
|
|
36
37
|
await mkdir(cachePath, { recursive: true });
|
|
37
38
|
}
|
|
38
39
|
let data = JSON.stringify(Object.fromEntries(stringCache));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/appframe-vite",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.31",
|
|
4
4
|
"description": "Tools to use and deploy Vite applications to Appframe",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -19,27 +19,28 @@
|
|
|
19
19
|
"author": "Bjørnar Vister Hansen <bvh@olenbetong.no>",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@olenbetong/appframe-data": "1.0.
|
|
22
|
+
"@olenbetong/appframe-data": "1.0.12",
|
|
23
23
|
"body-parser": "^2.2.0",
|
|
24
24
|
"chalk": "^5.4.1",
|
|
25
25
|
"chokidar": "^4.0.3",
|
|
26
|
-
"dotenv": "^16.
|
|
27
|
-
"jsdom": "^26.
|
|
26
|
+
"dotenv": "^16.5.0",
|
|
27
|
+
"jsdom": "^26.1.0",
|
|
28
28
|
"rollup-plugin-visualizer": "^5.14.0",
|
|
29
29
|
"vite-plugin-externals": "^0.6.2"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/jsdom": "^21.1.7",
|
|
33
|
-
"
|
|
34
|
-
"
|
|
33
|
+
"@types/node": "^22.14.1",
|
|
34
|
+
"typescript": "^5.8.3",
|
|
35
|
+
"vite": "^6.3.3"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"vite": ">=5.0.0"
|
|
38
39
|
},
|
|
39
40
|
"optionalDependencies": {
|
|
40
41
|
"@types/tcp-port-used": "^1.0.4",
|
|
41
|
-
"open": "^10.1.
|
|
42
|
+
"open": "^10.1.1",
|
|
42
43
|
"tcp-port-used": "^1.0.2"
|
|
43
44
|
},
|
|
44
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "bc10814d960b65e6959fb8506259e4d369f094ab"
|
|
45
46
|
}
|