vite-plugin-vanjs 0.0.3 → 0.0.4
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 +143 -15
- package/client/global.d.ts +41 -0
- package/client/index.mjs +48 -0
- package/client/package.json +18 -0
- package/client/types.d.ts +34 -0
- package/jsx/global.d.ts +4 -3
- package/jsx/index.mjs +3 -3
- package/jsx/jsx-dev-runtime.mjs +1 -1
- package/jsx/jsx-runtime.mjs +1 -1
- package/jsx/jsx.d.ts +18 -10
- package/jsx/jsx.mjs +3 -2
- package/jsx/package.json +1 -1
- package/jsx/types.d.ts +16 -0
- package/meta/Head.mjs +81 -0
- package/meta/global.d.ts +60 -0
- package/meta/helpers.mjs +52 -0
- package/meta/index.mjs +3 -0
- package/meta/package.json +18 -0
- package/meta/tags.mjs +57 -0
- package/meta/types.d.ts +36 -0
- package/package.json +45 -13
- package/router/a.mjs +50 -0
- package/router/cache.mjs +14 -0
- package/router/global.d.ts +162 -0
- package/router/helpers.mjs +198 -0
- package/router/index.mjs +6 -0
- package/router/lazy.mjs +60 -0
- package/router/package.json +19 -0
- package/router/router.mjs +43 -0
- package/router/routes.mjs +51 -0
- package/router/state.mjs +27 -0
- package/router/types.d.ts +156 -0
- package/server/global.d.ts +49 -0
- package/server/index.mjs +97 -0
- package/server/package.json +20 -0
- package/server/types.d.ts +38 -0
- package/setup/package.json +2 -2
- package/setup/van.d.ts +1 -0
- package/setup/vanX.d.ts +1 -0
- package/setup/vanX.mjs +1 -1
- package/src/index.mjs +9 -8
- package/src/types.d.ts +29 -4
- package/tsconfig.json +14 -2
- package/jsx/index.d.ts +0 -16
- package/jsx/utils.mjs +0 -24
- /package/setup/{index.d.ts → types.d.ts} +0 -0
package/server/index.mjs
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { basename } from "node:path";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @type {typeof import("./types.d.ts").renderToString}
|
|
5
|
+
*/
|
|
6
|
+
export const renderToString = async (inputSource) => {
|
|
7
|
+
const source = typeof inputSource === "function"
|
|
8
|
+
? inputSource()
|
|
9
|
+
: inputSource;
|
|
10
|
+
if (typeof source === "number") {
|
|
11
|
+
return String(source);
|
|
12
|
+
}
|
|
13
|
+
if (typeof source === "string") {
|
|
14
|
+
return source.trim();
|
|
15
|
+
}
|
|
16
|
+
if (typeof source === "boolean") {
|
|
17
|
+
return String(source);
|
|
18
|
+
}
|
|
19
|
+
if (typeof source === "object" && "render" in source) {
|
|
20
|
+
return source.render();
|
|
21
|
+
}
|
|
22
|
+
if (source instanceof Promise) {
|
|
23
|
+
return renderToString(await source);
|
|
24
|
+
}
|
|
25
|
+
/* istanbul ignore else */
|
|
26
|
+
if (Array.isArray(source)) {
|
|
27
|
+
const elements = [];
|
|
28
|
+
for (const el of source) {
|
|
29
|
+
elements.push(await renderToString(el));
|
|
30
|
+
}
|
|
31
|
+
return elements.join("");
|
|
32
|
+
}
|
|
33
|
+
// return String(source)
|
|
34
|
+
|
|
35
|
+
// no source provided
|
|
36
|
+
// @ts-ignore - this is server side code
|
|
37
|
+
console.warn("Render error! Source not recognized: " + source);
|
|
38
|
+
return "";
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @param {string} file
|
|
43
|
+
* @returns {string}
|
|
44
|
+
*/
|
|
45
|
+
function renderPreloadLink(file) {
|
|
46
|
+
if (file.endsWith(".js") || file.endsWith(".mjs")) {
|
|
47
|
+
return `<link rel="modulepreload" as="script" crossorigin href="${file}">`;
|
|
48
|
+
} else if (file.endsWith(".css")) {
|
|
49
|
+
return `<link rel="stylesheet" href="${file}">`;
|
|
50
|
+
} else if (file.endsWith(".woff")) {
|
|
51
|
+
return ` <link rel="preload" href="${file}" as="font" type="font/woff" crossorigin>`;
|
|
52
|
+
} else if (file.endsWith(".woff2")) {
|
|
53
|
+
return ` <link rel="preload" href="${file}" as="font" type="font/woff2" crossorigin>`;
|
|
54
|
+
} else if (file.endsWith(".gif")) {
|
|
55
|
+
return ` <link rel="preload" href="${file}" as="image" type="image/gif">`;
|
|
56
|
+
} else if (file.endsWith(".jpg") || file.endsWith(".jpeg")) {
|
|
57
|
+
return ` <link rel="preload" href="${file}" as="image" type="image/jpeg">`;
|
|
58
|
+
} else if (file.endsWith(".png")) {
|
|
59
|
+
return ` <link rel="preload" href="${file}" as="image" type="image/png">`;
|
|
60
|
+
} else if (file.endsWith(".webp")) {
|
|
61
|
+
return ` <link rel="preload" href="${file}" as="image" type="image/webp">`;
|
|
62
|
+
} else {
|
|
63
|
+
// @ts-ignore - this is server side code
|
|
64
|
+
console.warn("Render error! File format not recognized: " + file);
|
|
65
|
+
return "";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @type {typeof import("./types.d.ts").renderPreloadLinks}
|
|
71
|
+
*/
|
|
72
|
+
export function renderPreloadLinks(modules, manifest) {
|
|
73
|
+
let links = "";
|
|
74
|
+
const seen = new Set();
|
|
75
|
+
modules.forEach((id) => {
|
|
76
|
+
const files = manifest[id];
|
|
77
|
+
/* istanbul ignore else */
|
|
78
|
+
if (files?.length) {
|
|
79
|
+
files.forEach((file) => {
|
|
80
|
+
/* istanbul ignore else */
|
|
81
|
+
if (!seen.has(file)) {
|
|
82
|
+
seen.add(file);
|
|
83
|
+
const filename = basename(file);
|
|
84
|
+
/* istanbul ignore next - impossible to test */
|
|
85
|
+
if (manifest[filename]) {
|
|
86
|
+
for (const depFile of manifest[filename]) {
|
|
87
|
+
links += renderPreloadLink(depFile);
|
|
88
|
+
seen.add(depFile);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
links += renderPreloadLink(file);
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return links;
|
|
97
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "server",
|
|
3
|
+
"main": "./index.mjs",
|
|
4
|
+
"module": "./index.mjs",
|
|
5
|
+
"types": "./types.d.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./types.d.ts",
|
|
10
|
+
"import": "./index.mjs"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"peerDependencies": {
|
|
14
|
+
"vite-plugin-vanjs": "*",
|
|
15
|
+
"mini-van-plate": "*",
|
|
16
|
+
"vanjs-core": "*",
|
|
17
|
+
"vanjs-ext": "*"
|
|
18
|
+
},
|
|
19
|
+
"sideEffects": false
|
|
20
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/// <reference path="global.d.ts" />
|
|
2
|
+
import type { Element as VanElement, TagFunc } from "mini-van-plate/van-plate";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A function that takes a list of files and a manifest and returns a string
|
|
6
|
+
* representing the HTML markup for preload links.
|
|
7
|
+
* @param files the list of files
|
|
8
|
+
* @param manifest the vite manifest
|
|
9
|
+
* @returns HTML string
|
|
10
|
+
*/
|
|
11
|
+
export const renderPreloadLinks: (
|
|
12
|
+
files: string[],
|
|
13
|
+
manifest: Record<string, string[]>,
|
|
14
|
+
) => string;
|
|
15
|
+
|
|
16
|
+
type ValidVanNode =
|
|
17
|
+
| boolean
|
|
18
|
+
| number
|
|
19
|
+
| string
|
|
20
|
+
| VanElement
|
|
21
|
+
| TagFunc;
|
|
22
|
+
|
|
23
|
+
type VanComponent = () => ValidVanNode | ValidVanNode[];
|
|
24
|
+
export type Source =
|
|
25
|
+
| Promise<ValidVanNode>
|
|
26
|
+
| VanComponent
|
|
27
|
+
| (() => VanComponent)
|
|
28
|
+
| ValidVanNode
|
|
29
|
+
| ValidVanNode[]
|
|
30
|
+
| undefined;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* A function that takes a multitude of source types and returns a string
|
|
34
|
+
* representing the HTML output.
|
|
35
|
+
* @param source the source
|
|
36
|
+
* @returns HTML string
|
|
37
|
+
*/
|
|
38
|
+
export const renderToString: (source: Source) => Promise<string>;
|
package/setup/package.json
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"name": "setup",
|
|
3
3
|
"main": "./index.mjs",
|
|
4
4
|
"module": "./index.mjs",
|
|
5
|
-
"types": "./
|
|
5
|
+
"types": "./types.d.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": {
|
|
9
|
-
"types": "./
|
|
9
|
+
"types": "./types.d.ts",
|
|
10
10
|
"import": "./index.mjs"
|
|
11
11
|
},
|
|
12
12
|
"./van": {
|
package/setup/van.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type { Van } from "vanjs-core";
|
package/setup/vanX.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "vanjs-ext";
|
package/setup/vanX.mjs
CHANGED
package/src/index.mjs
CHANGED
|
@@ -10,18 +10,16 @@ export default function VitePluginVanJS() {
|
|
|
10
10
|
enforce: "pre",
|
|
11
11
|
config() {
|
|
12
12
|
return {
|
|
13
|
-
build: {
|
|
14
|
-
optimizeDeps: {
|
|
15
|
-
include: ["vanjs-core", "vanjs-ext", "mini-van-plate"],
|
|
16
|
-
},
|
|
17
|
-
dedupe: ["vanjs-core", "vanjs-ext", "mini-van-plate"],
|
|
18
|
-
},
|
|
19
13
|
resolve: {
|
|
20
14
|
alias: {
|
|
21
|
-
"@vanjs/jsx": resolve(__dirname, "../jsx"),
|
|
22
15
|
"@vanjs/setup": resolve(__dirname, "../setup"),
|
|
23
16
|
"@vanjs/van": resolve(__dirname, "../setup/van"),
|
|
24
17
|
"@vanjs/vanX": resolve(__dirname, "../setup/vanX"),
|
|
18
|
+
"@vanjs/client": resolve(__dirname, "../client"),
|
|
19
|
+
"@vanjs/server": resolve(__dirname, "../server"),
|
|
20
|
+
"@vanjs/meta": resolve(__dirname, "../meta"),
|
|
21
|
+
"@vanjs/router": resolve(__dirname, "../router"),
|
|
22
|
+
"@vanjs/jsx": resolve(__dirname, "../jsx"),
|
|
25
23
|
},
|
|
26
24
|
},
|
|
27
25
|
esbuild: {
|
|
@@ -32,20 +30,23 @@ export default function VitePluginVanJS() {
|
|
|
32
30
|
};
|
|
33
31
|
},
|
|
34
32
|
transform(code, id) {
|
|
35
|
-
let newCode = code;
|
|
33
|
+
let newCode = String(code);
|
|
36
34
|
|
|
37
35
|
const vanCoreReg = /import\s*.*\s*from\s*['"]vanjs-core['"]/g;
|
|
38
36
|
const vanExtReg = /import\s*.*\s*from\s*['"]vanjs-ext['"]/g;
|
|
39
37
|
const isSetupFile = /vite-plugin-vanjs[\\/]setup/.test(id);
|
|
40
38
|
const isVanXFile = /vanjs-ext[\\/]src[\\/]van-x/.test(id);
|
|
41
39
|
|
|
40
|
+
/* istanbul ignore else */
|
|
42
41
|
if (!isSetupFile && !isVanXFile) {
|
|
42
|
+
/* istanbul ignore next - the plugin works, istanbul isn't instrumenting this part properly */
|
|
43
43
|
if (vanCoreReg.test(newCode)) {
|
|
44
44
|
newCode = newCode.replace(
|
|
45
45
|
vanCoreReg,
|
|
46
46
|
(match) => match.replace("vanjs-core", "@vanjs/van"),
|
|
47
47
|
);
|
|
48
48
|
}
|
|
49
|
+
/* istanbul ignore next - the plugin works, istanbul isn't instrumenting this part properly */
|
|
49
50
|
if (vanExtReg.test(newCode)) {
|
|
50
51
|
newCode = newCode.replace(
|
|
51
52
|
vanExtReg,
|
package/src/types.d.ts
CHANGED
|
@@ -1,4 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
export * from "../
|
|
3
|
-
export * from "../
|
|
4
|
-
export
|
|
1
|
+
export * from "../jsx/types";
|
|
2
|
+
export * from "../setup/types";
|
|
3
|
+
export * from "../router/types";
|
|
4
|
+
export * from "../meta/types";
|
|
5
|
+
export * from "../server/types";
|
|
6
|
+
export * from "../client/types";
|
|
7
|
+
|
|
8
|
+
declare const VitePluginVanJS: () => {
|
|
9
|
+
name: "string";
|
|
10
|
+
enforce: "pre" | "post" | undefined;
|
|
11
|
+
apply: "build";
|
|
12
|
+
config(): {
|
|
13
|
+
resolve: {
|
|
14
|
+
alias: Record<string, string>;
|
|
15
|
+
};
|
|
16
|
+
esBuild: {
|
|
17
|
+
jsx: "string";
|
|
18
|
+
jsxFactory: "string";
|
|
19
|
+
jsxFragment: "string";
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
transform(code: string, id?: string): {
|
|
23
|
+
code: string;
|
|
24
|
+
map: null;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export default VitePluginVanJS;
|
|
28
|
+
|
|
29
|
+
export {};
|
package/tsconfig.json
CHANGED
|
@@ -26,8 +26,20 @@
|
|
|
26
26
|
"noEmit": true,
|
|
27
27
|
"checkJs": true,
|
|
28
28
|
"jsx": "preserve",
|
|
29
|
-
"jsxImportSource": "
|
|
29
|
+
"jsxImportSource": "@vanjs/jsx",
|
|
30
|
+
// "types": ["vanjs-core", "vanjs-ext", "mini-van-plate"],
|
|
30
31
|
},
|
|
31
|
-
"include": [
|
|
32
|
+
"include": [
|
|
33
|
+
"./tests/*.ts",
|
|
34
|
+
"./tests/*.tsx",
|
|
35
|
+
"./src/*.ts",
|
|
36
|
+
"./jsx/*.ts",
|
|
37
|
+
"./setup/*.ts",
|
|
38
|
+
"./router/*.ts",
|
|
39
|
+
"./meta/*.ts",
|
|
40
|
+
"./server/*.ts",
|
|
41
|
+
"./client/*.ts",
|
|
42
|
+
// "./tests/vite-env.d.ts"
|
|
43
|
+
],
|
|
32
44
|
"exclude": ["node_modules", "experiments", "coverage"],
|
|
33
45
|
}
|
package/jsx/index.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/// <reference path="global.d.ts" />
|
|
2
|
-
import type { JSX } from "./jsx.d.ts";
|
|
3
|
-
import type { Fragment } from "./fragment.d.ts";
|
|
4
|
-
|
|
5
|
-
declare function jsx(
|
|
6
|
-
type: any,
|
|
7
|
-
props: any,
|
|
8
|
-
): () =>
|
|
9
|
-
| (Node & {
|
|
10
|
-
[key: string]: any;
|
|
11
|
-
})
|
|
12
|
-
| (Node & {
|
|
13
|
-
[key: string]: any;
|
|
14
|
-
})[];
|
|
15
|
-
|
|
16
|
-
export { Fragment, jsx, jsx as jsxDEV, jsx as jsxs };
|
package/jsx/utils.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const setAttribute = (element, key, value) => {
|
|
2
|
-
if (value == null || value === false || value === "") {
|
|
3
|
-
element.removeAttribute(key);
|
|
4
|
-
} else {
|
|
5
|
-
const attr = value === true ? "" : String(value);
|
|
6
|
-
element.setAttribute(key, attr);
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const styleToString = (style) => {
|
|
11
|
-
return typeof style === "string"
|
|
12
|
-
? style
|
|
13
|
-
: typeof style === "object"
|
|
14
|
-
? Object.entries(style).reduce((acc, key) =>
|
|
15
|
-
acc +
|
|
16
|
-
key[0]
|
|
17
|
-
.split(/(?=[A-Z])/)
|
|
18
|
-
.join("-")
|
|
19
|
-
.toLowerCase() +
|
|
20
|
-
":" +
|
|
21
|
-
key[1] +
|
|
22
|
-
";", "")
|
|
23
|
-
: "";
|
|
24
|
-
};
|
|
File without changes
|