ferrovue 0.6.0 → 0.7.0
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 +106 -13
- package/dist/args.d.ts +28 -0
- package/dist/args.js +69 -0
- package/dist/attrs.js +3 -0
- package/dist/calls.js +5 -2
- package/dist/children.js +18 -3
- package/dist/cli.js +80 -81
- package/dist/client-render.d.ts +23 -0
- package/dist/client-render.js +143 -0
- package/dist/client.d.ts +65 -6
- package/dist/client.js +269 -27
- package/dist/compiler.d.ts +9 -5
- package/dist/compiler.js +48 -14
- package/dist/component.d.ts +7 -3
- package/dist/component.js +37 -25
- package/dist/conformance.d.ts +24 -3
- package/dist/conformance.js +58 -7
- package/dist/constants.js +4 -2
- package/dist/context.d.ts +51 -4
- package/dist/context.js +173 -5
- package/dist/diagnostics.d.ts +6 -4
- package/dist/diagnostics.js +7 -3
- package/dist/editor.d.ts +18 -0
- package/dist/editor.js +59 -0
- package/dist/errors.d.ts +45 -3
- package/dist/errors.js +33 -3
- package/dist/expr.d.ts +2 -0
- package/dist/expr.js +91 -12
- package/dist/fallthrough.d.ts +1 -0
- package/dist/fallthrough.js +10 -2
- package/dist/files.d.ts +13 -0
- package/dist/files.js +49 -0
- package/dist/fixture.d.ts +3 -3
- package/dist/hydration.d.ts +12 -1
- package/dist/hydration.js +47 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/inputs.d.ts +24 -0
- package/dist/inputs.js +40 -0
- package/dist/link-router.d.ts +6 -2
- package/dist/link-router.js +7 -4
- package/dist/lists.d.ts +12 -1
- package/dist/lists.js +76 -2
- package/dist/model.d.ts +9 -1
- package/dist/model.js +2 -0
- package/dist/page-routes.d.ts +1 -0
- package/dist/paths.d.ts +5 -0
- package/dist/paths.js +7 -0
- package/dist/plugin.d.ts +2 -0
- package/dist/plugins/css-modules.d.ts +39 -0
- package/dist/plugins/css-modules.js +135 -0
- package/dist/plugins/head.js +4 -4
- package/dist/plugins/i18n.js +5 -12
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/provide.js +4 -2
- package/dist/plugins/router.js +3 -2
- package/dist/plugins/scoped.d.ts +10 -0
- package/dist/plugins/scoped.js +17 -4
- package/dist/plugins/shared-types.js +2 -1
- package/dist/plugins/stores.js +7 -6
- package/dist/rust.d.ts +9 -1
- package/dist/rust.js +38 -15
- package/dist/schema.d.ts +25 -0
- package/dist/schema.js +73 -0
- package/dist/script.js +12 -5
- package/dist/slots.js +2 -0
- package/dist/ssr.js +42 -4
- package/dist/styles.d.ts +5 -1
- package/dist/styles.js +131 -4
- package/dist/testing.d.ts +2 -1
- package/dist/testing.js +1 -1
- package/dist/typescript.d.ts +11 -1
- package/dist/typescript.js +124 -33
- package/dist/vite.d.ts +18 -10
- package/dist/vite.js +106 -51
- package/dist/volar.d.ts +15 -0
- package/dist/volar.js +87 -0
- package/package.json +27 -7
- package/schema.json +333 -0
package/dist/inputs.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Config } from "./context.ts";
|
|
2
|
+
/** What a run reads, as absolute paths: what `ferrovue --watch` and the Vite plugin regenerate on. */
|
|
3
|
+
export interface Inputs {
|
|
4
|
+
/** The configuration file, the routes file, and every `.ts` file the last run read types or
|
|
5
|
+
* constants from. */
|
|
6
|
+
files: Set<string>;
|
|
7
|
+
/** The directories whose files of one kind are read: components, stores, locale messages, and
|
|
8
|
+
* the pages, nested folders included. */
|
|
9
|
+
dirs: {
|
|
10
|
+
dir: string;
|
|
11
|
+
ext: string;
|
|
12
|
+
deep: boolean;
|
|
13
|
+
}[];
|
|
14
|
+
/** The output directory, which is never an input. */
|
|
15
|
+
out: string | null;
|
|
16
|
+
}
|
|
17
|
+
/** The inputs of a run of `config`, which is `null` when the configuration file cannot be read and
|
|
18
|
+
* the file alone is watched. Call it once a run is over: the type files are those the run read. */
|
|
19
|
+
export declare function inputsOf(root: string, configFile: string, config: Config | null): Inputs;
|
|
20
|
+
/** Whether a change to `file`, an absolute path, can change what is generated. A directory of
|
|
21
|
+
* inputs itself counts, as one renamed away or back. */
|
|
22
|
+
export declare function affects(inputs: Inputs, file: string): boolean;
|
|
23
|
+
/** Every path to watch for the inputs: their files and directories. */
|
|
24
|
+
export declare function watched(inputs: Inputs): string[];
|
package/dist/inputs.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { dirname, resolve, sep } from "node:path";
|
|
2
|
+
import { ctx } from "./context.js";
|
|
3
|
+
import { pagesFolder } from "./file-routes.js";
|
|
4
|
+
/** The inputs of a run of `config`, which is `null` when the configuration file cannot be read and
|
|
5
|
+
* the file alone is watched. Call it once a run is over: the type files are those the run read. */
|
|
6
|
+
export function inputsOf(root, configFile, config) {
|
|
7
|
+
const inputs = { files: new Set([resolve(root, configFile)]), dirs: [], out: null };
|
|
8
|
+
if (!config)
|
|
9
|
+
return inputs;
|
|
10
|
+
const at = (path) => resolve(root, path);
|
|
11
|
+
inputs.out = at(config.out);
|
|
12
|
+
inputs.dirs.push({ dir: at(config.components), ext: ".vue", deep: false });
|
|
13
|
+
if (config.stores)
|
|
14
|
+
inputs.dirs.push({ dir: at(config.stores), ext: ".ts", deep: false });
|
|
15
|
+
if (config.i18n)
|
|
16
|
+
inputs.dirs.push({ dir: at(config.i18n.messages), ext: ".json", deep: false });
|
|
17
|
+
const pages = pagesFolder(config);
|
|
18
|
+
if (pages !== null)
|
|
19
|
+
inputs.dirs.push({ dir: at(pages), ext: ".vue", deep: true });
|
|
20
|
+
const routes = config.router?.routes ?? config.routes;
|
|
21
|
+
if (typeof routes === "string")
|
|
22
|
+
inputs.files.add(at(routes));
|
|
23
|
+
if (ctx.rootDir === root)
|
|
24
|
+
for (const file of ctx.typeRead)
|
|
25
|
+
inputs.files.add(file);
|
|
26
|
+
return inputs;
|
|
27
|
+
}
|
|
28
|
+
/** Whether a change to `file`, an absolute path, can change what is generated. A directory of
|
|
29
|
+
* inputs itself counts, as one renamed away or back. */
|
|
30
|
+
export function affects(inputs, file) {
|
|
31
|
+
if (inputs.files.has(file))
|
|
32
|
+
return true;
|
|
33
|
+
if (inputs.out !== null && (file === inputs.out || file.startsWith(inputs.out + sep)))
|
|
34
|
+
return false;
|
|
35
|
+
return inputs.dirs.some(({ dir, ext, deep }) => file === dir || (file.endsWith(ext) && (deep ? file.startsWith(dir + sep) : dirname(file) === dir)));
|
|
36
|
+
}
|
|
37
|
+
/** Every path to watch for the inputs: their files and directories. */
|
|
38
|
+
export function watched(inputs) {
|
|
39
|
+
return [...inputs.files, ...inputs.dirs.map((d) => d.dir)];
|
|
40
|
+
}
|
package/dist/link-router.d.ts
CHANGED
|
@@ -12,8 +12,12 @@ export interface LinkRouterOptions {
|
|
|
12
12
|
linkActiveClass?: string;
|
|
13
13
|
/** As `router.linkExactActiveClass` in `ferrovue.config.json`. */
|
|
14
14
|
linkExactActiveClass?: string;
|
|
15
|
-
/** The
|
|
16
|
-
*
|
|
15
|
+
/** The location of the page the router is for, as an `href` with the base (the one `navigate`
|
|
16
|
+
* is given): the page a navigation goes to, which the browser's location is not yet. The
|
|
17
|
+
* browser's location by default. */
|
|
18
|
+
location?: string;
|
|
19
|
+
/** The history the router reads its first location from. By default a memory history at
|
|
20
|
+
* `location`: the router neither writes to the browser's history nor listens to it. */
|
|
17
21
|
history?: RouterHistory;
|
|
18
22
|
}
|
|
19
23
|
/** A router for `<RouterLink>` and `useRoute()` alone, for an application whose own navigation
|
package/dist/link-router.js
CHANGED
|
@@ -2,12 +2,15 @@ import { createMemoryHistory, createRouter, isNavigationFailure, NavigationFailu
|
|
|
2
2
|
import { routeRecords } from "./routes.js";
|
|
3
3
|
export { routeRecords } from "./routes.js";
|
|
4
4
|
const Empty = { render: () => null };
|
|
5
|
-
function pageHistory(base) {
|
|
5
|
+
function pageHistory(base, location) {
|
|
6
6
|
const history = createMemoryHistory(base);
|
|
7
|
-
const
|
|
7
|
+
const href = location ?? window.location.pathname + window.location.search + window.location.hash;
|
|
8
|
+
const end = href.search(/[?#]/);
|
|
9
|
+
const pathname = end < 0 ? href : href.slice(0, end);
|
|
10
|
+
const rest = end < 0 ? "" : href.slice(end);
|
|
8
11
|
const prefix = history.base;
|
|
9
12
|
const path = prefix && pathname.toLowerCase().startsWith(prefix.toLowerCase()) ? pathname.slice(prefix.length) || "/" : pathname;
|
|
10
|
-
history.replace(path +
|
|
13
|
+
history.replace(path + rest);
|
|
11
14
|
return history;
|
|
12
15
|
}
|
|
13
16
|
/** A router for `<RouterLink>` and `useRoute()` alone, for an application whose own navigation
|
|
@@ -16,7 +19,7 @@ function pageHistory(base) {
|
|
|
16
19
|
* click included, is handed to `navigate` and aborted, so the router stays on that page. Build one
|
|
17
20
|
* for each page the application shows. */
|
|
18
21
|
export function linkRouter(routes, options) {
|
|
19
|
-
const history = options.history ?? pageHistory(options.base);
|
|
22
|
+
const history = options.history ?? pageHistory(options.base, options.location);
|
|
20
23
|
const router = createRouter({
|
|
21
24
|
history,
|
|
22
25
|
routes: routeRecords(routes, Empty),
|
package/dist/lists.d.ts
CHANGED
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { type N, type Scope, type Ty, type Val } from "./model.ts";
|
|
1
|
+
import { type Component, type N, type Scope, type Ty, type Val } from "./model.ts";
|
|
2
2
|
export declare function items(v: Val): string;
|
|
3
3
|
export declare function computed(iter: string, of: Ty, lone?: boolean): Val;
|
|
4
4
|
export declare function collected(v: Val): string;
|
|
5
|
+
export declare function sliced(v: Val): string;
|
|
6
|
+
export declare function untypedEmpty(v: Val): boolean;
|
|
7
|
+
export declare function typedEmpty(comp: Component, of: Ty): Val;
|
|
5
8
|
export declare function heldList(name: string, of: Ty, lone?: boolean): Val;
|
|
6
9
|
export declare function arrow(s: Scope, fn: N, list: Val, of: Ty, byRef: boolean, method: string, body: (inner: Scope) => string): {
|
|
7
10
|
closure: string;
|
|
8
11
|
enumerate: boolean;
|
|
9
12
|
};
|
|
13
|
+
/** Is `n` the global `Boolean` (`.filter(Boolean)`, `Boolean(x)`), which no name in the component shadows? */
|
|
14
|
+
export declare function isBoolean(s: Scope, n: N): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* An array literal some of whose items may be absent, filtered by `Boolean`
|
|
17
|
+
* (`[name, title].filter(Boolean)`): the items that are present, as a list. `null` when none may
|
|
18
|
+
* be absent, which is an ordinary array literal.
|
|
19
|
+
*/
|
|
20
|
+
export declare function presentLiteral(s: Scope, n: N): Val | null;
|
|
10
21
|
export declare function listMethod(s: Scope, target: Val, method: string, args: N[], n: N): Val | null;
|
|
11
22
|
export declare function objectCall(s: Scope, method: string, args: N[], n: N): Val;
|
|
12
23
|
export declare function computedListMethod(s: Scope, target: Val, method: string, args: N[], n: N): Val | null;
|
package/dist/lists.js
CHANGED
|
@@ -2,9 +2,10 @@ import { BOOL, fail, FLOAT, INT, opt, sameTy, STR } from "./model.js";
|
|
|
2
2
|
import { ctx } from "./context.js";
|
|
3
3
|
import { expr, fieldVal } from "./expr.js";
|
|
4
4
|
import { cond } from "./narrowing.js";
|
|
5
|
+
import { localTy } from "./rust.js";
|
|
5
6
|
import { asF64, isNumber } from "./numbers.js";
|
|
6
7
|
import { asCow, isTemporary, lonely, meet, yieldsCow } from "./strings.js";
|
|
7
|
-
import { atom, binary, operand, strArg, UNARY } from "./parens.js";
|
|
8
|
+
import { atom, bare, binary, operand, strArg, UNARY } from "./parens.js";
|
|
8
9
|
const COW = "std::borrow::Cow::<str>";
|
|
9
10
|
function itemsTy(s, v, n) {
|
|
10
11
|
if (v.ty.k !== "list")
|
|
@@ -32,6 +33,15 @@ export function collected(v) {
|
|
|
32
33
|
const of = v.ty.k === "list" ? v.ty.of : v.ty;
|
|
33
34
|
return `${items(v)}${of.k === "str" ? `.map(|v| ${COW}::Owned(v.into_owned()))` : ""}.collect::<Vec<_>>()`;
|
|
34
35
|
}
|
|
36
|
+
export function sliced(v) {
|
|
37
|
+
return v.slice ? v.code : `&${atom(v.code)}[..]`;
|
|
38
|
+
}
|
|
39
|
+
export function untypedEmpty(v) {
|
|
40
|
+
return v.ty.k === "list" && v.ty.of.k === "undef";
|
|
41
|
+
}
|
|
42
|
+
export function typedEmpty(comp, of) {
|
|
43
|
+
return { code: `<&[${localTy(of, comp)}]>::default()`, ty: { k: "list", of }, slice: true };
|
|
44
|
+
}
|
|
35
45
|
export function heldList(name, of, lone) {
|
|
36
46
|
const iter = of.k === "str" ? `${name}.iter().map(|v| ${COW}::Borrowed(&**v))` : `${name}.iter().copied()`;
|
|
37
47
|
return { code: name, ty: { k: "list", of }, iter, ...(lone ? { lone } : {}) };
|
|
@@ -44,7 +54,7 @@ function itemVal(of, param, byRef, lone) {
|
|
|
44
54
|
export function arrow(s, fn, list, of, byRef, method, body) {
|
|
45
55
|
const comp = s.comp;
|
|
46
56
|
if (fn?.type !== "ArrowFunctionExpression" || fn.async || fn.params.length > 2) {
|
|
47
|
-
fail(comp, "FV0805", `\`.${method}()\` takes an arrow function of the item, and of its index: \`x => …\`, \`(x, i) =>
|
|
57
|
+
fail(comp, "FV0805", `\`.${method}()\` takes an arrow function of the item, and of its index: \`x => …\`, \`(x, i) => …\`, or \`Boolean\``, fn);
|
|
48
58
|
}
|
|
49
59
|
if (fn.body.type === "BlockStatement")
|
|
50
60
|
fail(comp, "FV0806", `\`.${method}()\` takes an arrow function whose body is an expression, without \`{ return … }\``, fn);
|
|
@@ -113,10 +123,74 @@ function mapped(s, v, n) {
|
|
|
113
123
|
return fail(s.comp, "FV0810", `\`.map()\` makes a list of strings, numbers, booleans or objects, not ${v.ty.k === "opt" ? "optional values" : "these"}`, n);
|
|
114
124
|
}
|
|
115
125
|
}
|
|
126
|
+
/** Is `n` the global `Boolean` (`.filter(Boolean)`, `Boolean(x)`), which no name in the component shadows? */
|
|
127
|
+
export function isBoolean(s, n) {
|
|
128
|
+
return n?.type === "Identifier" && n.name === "Boolean" && ![s.locals, s.setup, s.helpers, s.clientOnly].some((names) => names.has(n.name));
|
|
129
|
+
}
|
|
130
|
+
// JavaScript calls `Boolean` with the item alone, and it returns the item's truthiness: it is
|
|
131
|
+
// `x => x` where a condition is wanted, and `x => !!x` for `.map()`.
|
|
132
|
+
function booleanArrow(n, method) {
|
|
133
|
+
const item = { ...n, name: "fv$item" };
|
|
134
|
+
const not = (argument) => ({ ...n, type: "UnaryExpression", operator: "!", prefix: true, argument });
|
|
135
|
+
return { ...n, type: "ArrowFunctionExpression", async: false, params: [item], body: method === "map" ? not(not(item)) : item };
|
|
136
|
+
}
|
|
137
|
+
// The items of a list of optional values that are present, as a list of the values: what
|
|
138
|
+
// `.filter(Boolean)` keeps of it, before it drops the falsy ones.
|
|
139
|
+
function present(target) {
|
|
140
|
+
if (target.ty.k !== "list" || target.ty.of.k !== "opt" || target.iter !== undefined)
|
|
141
|
+
return null;
|
|
142
|
+
const of = target.ty.of.of;
|
|
143
|
+
const list = atom(target.code);
|
|
144
|
+
switch (of.k) {
|
|
145
|
+
case "str":
|
|
146
|
+
return computed(`${list}.iter().filter_map(|v| v.as_deref()).map(${COW}::Borrowed)`, of, target.lone);
|
|
147
|
+
case "int":
|
|
148
|
+
case "float":
|
|
149
|
+
case "bool":
|
|
150
|
+
return computed(`${list}.iter().filter_map(|v| *v)`, of);
|
|
151
|
+
case "struct":
|
|
152
|
+
case "child":
|
|
153
|
+
return computed(`${list}.iter().filter_map(|v| v.as_ref())`, of);
|
|
154
|
+
default:
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* An array literal some of whose items may be absent, filtered by `Boolean`
|
|
160
|
+
* (`[name, title].filter(Boolean)`): the items that are present, as a list. `null` when none may
|
|
161
|
+
* be absent, which is an ordinary array literal.
|
|
162
|
+
*/
|
|
163
|
+
export function presentLiteral(s, n) {
|
|
164
|
+
const comp = s.comp;
|
|
165
|
+
const values = n.elements.map((el) => {
|
|
166
|
+
if (!el || el.type === "SpreadElement")
|
|
167
|
+
fail(comp, "FV0610", "an array literal holds plain values", n);
|
|
168
|
+
return expr(s, el);
|
|
169
|
+
});
|
|
170
|
+
if (!values.some((v) => v.ty.k === "opt" || v.ty.k === "null" || v.ty.k === "undef"))
|
|
171
|
+
return null;
|
|
172
|
+
const kept = values.filter((v) => v.ty.k !== "null" && v.ty.k !== "undef");
|
|
173
|
+
const of = kept.map((v) => (v.ty.k === "opt" ? v.ty.of : v.ty))[0];
|
|
174
|
+
if (of === undefined)
|
|
175
|
+
return computed("std::iter::empty::<bool>()", BOOL);
|
|
176
|
+
if (!["str", "int", "float", "bool"].includes(of.k) || kept.some((v) => !sameTy(v.ty.k === "opt" ? v.ty.of : v.ty, of))) {
|
|
177
|
+
fail(comp, "FV0611", "an array literal holds strings, numbers or booleans, all of one type, each of which may be absent", n);
|
|
178
|
+
}
|
|
179
|
+
const options = kept.map((v) => (v.ty.k === "opt" ? bare(v.code) : `Some(${bare(v.code)})`));
|
|
180
|
+
const flat = `[${options.join(", ")}].into_iter().flatten()`;
|
|
181
|
+
return computed(of.k === "str" ? `${flat}.map(${COW}::Borrowed)` : flat, of, kept.some((v) => v.lone));
|
|
182
|
+
}
|
|
116
183
|
export function listMethod(s, target, method, args, n) {
|
|
117
184
|
const comp = s.comp;
|
|
118
185
|
if (!["filter", "map", "some", "every", "find", "findIndex", "slice"].includes(method))
|
|
119
186
|
return null;
|
|
187
|
+
if (args.length === 1 && isBoolean(s, args[0])) {
|
|
188
|
+
const kept = method === "filter" ? present(target) : null;
|
|
189
|
+
const of = itemsTy(s, kept ?? target, n);
|
|
190
|
+
if (method === "filter" && (of.k === "struct" || of.k === "child"))
|
|
191
|
+
return kept ?? computed(items(target), of, target.lone);
|
|
192
|
+
return listMethod(s, kept ?? target, method, [booleanArrow(args[0], method)], n);
|
|
193
|
+
}
|
|
120
194
|
const of = itemsTy(s, target, n);
|
|
121
195
|
const it = items(target);
|
|
122
196
|
if (method === "slice") {
|
package/dist/model.d.ts
CHANGED
|
@@ -49,6 +49,7 @@ export interface Struct {
|
|
|
49
49
|
name: string;
|
|
50
50
|
fields: Field[];
|
|
51
51
|
slot?: true;
|
|
52
|
+
refused?: Map<string, GenError>;
|
|
52
53
|
}
|
|
53
54
|
export interface Val {
|
|
54
55
|
code: string;
|
|
@@ -58,6 +59,7 @@ export interface Val {
|
|
|
58
59
|
iter?: string;
|
|
59
60
|
lone?: boolean;
|
|
60
61
|
held?: string;
|
|
62
|
+
slice?: boolean;
|
|
61
63
|
num?: number;
|
|
62
64
|
format?: {
|
|
63
65
|
text: string;
|
|
@@ -114,8 +116,14 @@ export interface Component {
|
|
|
114
116
|
};
|
|
115
117
|
templateAst?: N;
|
|
116
118
|
attrsDropped?: N;
|
|
119
|
+
cssVarsAt?: N[];
|
|
117
120
|
props: Struct;
|
|
118
121
|
structs: Map<string, Struct>;
|
|
122
|
+
typeDecls: Map<string, {
|
|
123
|
+
members: N[];
|
|
124
|
+
node: N;
|
|
125
|
+
}>;
|
|
126
|
+
reached: Set<string>;
|
|
119
127
|
trustedName: string | null;
|
|
120
128
|
inlineName: string | null;
|
|
121
129
|
floatName: string | null;
|
|
@@ -165,7 +173,7 @@ export interface Scope {
|
|
|
165
173
|
loop?: {
|
|
166
174
|
item: string;
|
|
167
175
|
over: string;
|
|
168
|
-
};
|
|
176
|
+
} | undefined;
|
|
169
177
|
plugins: Map<Plugin, unknown>;
|
|
170
178
|
}
|
|
171
179
|
export type Origin = "source" | "template";
|
package/dist/model.js
CHANGED
|
@@ -100,6 +100,8 @@ export function blankComponent(name, module, file, structs = new Map()) {
|
|
|
100
100
|
file,
|
|
101
101
|
props: { name: "Props", fields: [] },
|
|
102
102
|
structs,
|
|
103
|
+
typeDecls: new Map(),
|
|
104
|
+
reached: new Set(),
|
|
103
105
|
trustedName: null,
|
|
104
106
|
inlineName: null,
|
|
105
107
|
floatName: null,
|
package/dist/page-routes.d.ts
CHANGED
|
@@ -6,4 +6,5 @@ export declare const routes: RouteRecordRaw[];
|
|
|
6
6
|
/** The same routes as a routes file lists them, with `view: false` on a folder: what `routeRecords`
|
|
7
7
|
* and `linkRouter` take, for a client whose pages the server renders. */
|
|
8
8
|
declare const entries: RouteEntry[];
|
|
9
|
+
export type { RouteEntry };
|
|
9
10
|
export default entries;
|
package/dist/paths.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as nodePath from "node:path";
|
|
2
|
+
/** `path.relative`, written with `/` on every platform. A path the compiler writes into generated
|
|
3
|
+
* code, a diagnostic or a key, or compares with a configured folder such as `out`, reads the same
|
|
4
|
+
* on Windows as elsewhere. `path` is Node's own, and `path.win32` in a test. */
|
|
5
|
+
export declare function relativePath(from: string, to: string, path?: Pick<typeof nodePath, "relative" | "sep">): string;
|
package/dist/paths.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as nodePath from "node:path";
|
|
2
|
+
/** `path.relative`, written with `/` on every platform. A path the compiler writes into generated
|
|
3
|
+
* code, a diagnostic or a key, or compares with a configured folder such as `out`, reads the same
|
|
4
|
+
* on Windows as elsewhere. `path` is Node's own, and `path.win32` in a test. */
|
|
5
|
+
export function relativePath(from, to, path = nodePath) {
|
|
6
|
+
return path.relative(from, to).split(path.sep).join("/");
|
|
7
|
+
}
|
package/dist/plugin.d.ts
CHANGED
|
@@ -55,6 +55,8 @@ export interface Plugin<Run = unknown, Local = unknown> {
|
|
|
55
55
|
id: string;
|
|
56
56
|
scoped: boolean;
|
|
57
57
|
slotted: boolean;
|
|
58
|
+
ssrCssVars: string[];
|
|
59
|
+
isProd: boolean;
|
|
58
60
|
};
|
|
59
61
|
importedType?(comp: Component, file: string, name: string, local: string): boolean;
|
|
60
62
|
struct?(ty: StructTy): {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { SFCDescriptor, SFCStyleBlock } from "@vue/compiler-sfc";
|
|
2
|
+
import { type Component } from "../model.ts";
|
|
3
|
+
import { type CssModulesConfig } from "../context.ts";
|
|
4
|
+
import { type Plugin } from "../plugin.ts";
|
|
5
|
+
declare module "../model.ts" {
|
|
6
|
+
interface PluginTys {
|
|
7
|
+
cssModule: {
|
|
8
|
+
k: "cssModule";
|
|
9
|
+
name: string;
|
|
10
|
+
tokens: Record<string, string>;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** A class's name in a CSS module, from its name as written and the module's id. */
|
|
15
|
+
export type NameGenerator = (local: string, file: string) => string;
|
|
16
|
+
interface CssModulesRun {
|
|
17
|
+
names: NameGenerator | null;
|
|
18
|
+
modules: Map<Component, Map<string, Record<string, string>>>;
|
|
19
|
+
}
|
|
20
|
+
interface CssModulesScope {
|
|
21
|
+
useCssModule: string | null;
|
|
22
|
+
}
|
|
23
|
+
/** The id Vite gives a `<style module>` block, as `@vitejs/plugin-vue` requests it, which postcss-modules
|
|
24
|
+
* names its classes from. */
|
|
25
|
+
export declare function styleRequest(file: string, index: number, style: SFCStyleBlock, id: string): string;
|
|
26
|
+
/** The classes, keyframes and values a CSS module exports, by name, as postcss-modules names them
|
|
27
|
+
* with `names`. */
|
|
28
|
+
export declare function moduleTokens(css: string, from: string, names: NameGenerator): Record<string, string>;
|
|
29
|
+
/** The classes each `<style module>` of a component exports, by the name a template reads them by
|
|
30
|
+
* (`$style`, or the module's own name), as Vite names them with `names` when plugin-vue gives the
|
|
31
|
+
* component the id `id`. Vite reads the block as written, before plugin-vue compiles it. A later
|
|
32
|
+
* module of the same name replaces an earlier one, as in plugin-vue. `refuse` is given each block
|
|
33
|
+
* whose classes cannot be named so, with why. */
|
|
34
|
+
export declare function componentModules(descriptor: SFCDescriptor, file: string, id: string, names: NameGenerator, refuse: (style: SFCStyleBlock, why: string) => never): Map<string, Record<string, string>>;
|
|
35
|
+
/** How Vite names a CSS module's classes with `css.modules` set as `config` is, from `context`, the
|
|
36
|
+
* directory Vite runs in. */
|
|
37
|
+
export declare function scopedNames(config: CssModulesConfig, context: string): NameGenerator;
|
|
38
|
+
export declare const cssModules: Plugin<CssModulesRun, CssModulesScope>;
|
|
39
|
+
export {};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { resolve as resolvePath, sep } from "node:path";
|
|
2
|
+
import genericNames from "generic-names";
|
|
3
|
+
import postcss, {} from "postcss";
|
|
4
|
+
import extractImports from "postcss-modules-extract-imports";
|
|
5
|
+
import localByDefault from "postcss-modules-local-by-default";
|
|
6
|
+
import modulesScope from "postcss-modules-scope";
|
|
7
|
+
import modulesValues from "postcss-modules-values";
|
|
8
|
+
import { fail, rustStr, sourceAt, STR, UNDEF } from "../model.js";
|
|
9
|
+
import { CONFIG_FILE } from "../context.js";
|
|
10
|
+
import { runOf, scopeOf } from "../plugin.js";
|
|
11
|
+
import { scopeHash } from "./scoped.js";
|
|
12
|
+
const IGNORED_ATTRS = new Set(["id", "index", "src", "type", "lang", "module", "scoped", "generic"]);
|
|
13
|
+
/** The id Vite gives a `<style module>` block, as `@vitejs/plugin-vue` requests it, which postcss-modules
|
|
14
|
+
* names its classes from. */
|
|
15
|
+
export function styleRequest(file, index, style, id) {
|
|
16
|
+
let query = "";
|
|
17
|
+
for (const [name, value] of Object.entries(style.attrs)) {
|
|
18
|
+
if (!IGNORED_ATTRS.has(name))
|
|
19
|
+
query += `&${encodeURIComponent(name)}${value ? `=${encodeURIComponent(value)}` : ""}`;
|
|
20
|
+
}
|
|
21
|
+
return `${resolvePath(file).split(sep).join("/")}?vue&type=style&index=${index}${style.scoped ? `&scoped=${id}` : ""}${query}&lang.module.css`;
|
|
22
|
+
}
|
|
23
|
+
/** The classes, keyframes and values a CSS module exports, by name, as postcss-modules names them
|
|
24
|
+
* with `names`. */
|
|
25
|
+
export function moduleTokens(css, from, names) {
|
|
26
|
+
const root = postcss([modulesValues, localByDefault({ mode: "local" }), extractImports, modulesScope({ generateScopedName: (local, file) => names(local, file), exportGlobals: false })]).process(css, { from }).root;
|
|
27
|
+
const tokens = {};
|
|
28
|
+
root.each((node) => {
|
|
29
|
+
if (node.type !== "rule")
|
|
30
|
+
return;
|
|
31
|
+
if (node.selector.startsWith(":import("))
|
|
32
|
+
throw new Error("it imports from another file");
|
|
33
|
+
if (node.selector !== ":export")
|
|
34
|
+
return;
|
|
35
|
+
node.each((decl) => {
|
|
36
|
+
if (decl.type === "decl")
|
|
37
|
+
tokens[decl.prop] = decl.value;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return tokens;
|
|
41
|
+
}
|
|
42
|
+
function blockAt(source, block) {
|
|
43
|
+
return sourceAt(source, source.lastIndexOf("<style", block.loc.start.offset));
|
|
44
|
+
}
|
|
45
|
+
/** The classes each `<style module>` of a component exports, by the name a template reads them by
|
|
46
|
+
* (`$style`, or the module's own name), as Vite names them with `names` when plugin-vue gives the
|
|
47
|
+
* component the id `id`. Vite reads the block as written, before plugin-vue compiles it. A later
|
|
48
|
+
* module of the same name replaces an earlier one, as in plugin-vue. `refuse` is given each block
|
|
49
|
+
* whose classes cannot be named so, with why. */
|
|
50
|
+
export function componentModules(descriptor, file, id, names, refuse) {
|
|
51
|
+
const found = new Map();
|
|
52
|
+
for (const [index, style] of descriptor.styles.entries()) {
|
|
53
|
+
if (!style.module)
|
|
54
|
+
continue;
|
|
55
|
+
if (style.src)
|
|
56
|
+
refuse(style, "`<style module src>`: ferrovue names the classes of a module written in the component");
|
|
57
|
+
if (style.lang !== undefined && style.lang !== "css")
|
|
58
|
+
refuse(style, `\`<style module lang="${style.lang}">\`: ferrovue names the classes of a plain CSS module, which no preprocessor changes`);
|
|
59
|
+
let tokens;
|
|
60
|
+
try {
|
|
61
|
+
tokens = moduleTokens(style.content, styleRequest(file, index, style, id), names);
|
|
62
|
+
}
|
|
63
|
+
catch (e) {
|
|
64
|
+
refuse(style, `\`<style module>\` whose classes ferrovue cannot name: ${e instanceof Error ? e.message.split("\n")[0] : String(e)}`);
|
|
65
|
+
}
|
|
66
|
+
found.set(typeof style.module === "string" ? style.module : "$style", tokens);
|
|
67
|
+
}
|
|
68
|
+
return found;
|
|
69
|
+
}
|
|
70
|
+
/** How Vite names a CSS module's classes with `css.modules` set as `config` is, from `context`, the
|
|
71
|
+
* directory Vite runs in. */
|
|
72
|
+
export function scopedNames(config, context) {
|
|
73
|
+
return genericNames(config.generateScopedName, { context, hashPrefix: config.hashPrefix ?? "" });
|
|
74
|
+
}
|
|
75
|
+
function readModules(comp, descriptor, file, source) {
|
|
76
|
+
const run = runOf(cssModules);
|
|
77
|
+
const module = descriptor.styles.find((st) => st.module);
|
|
78
|
+
if (!module)
|
|
79
|
+
return;
|
|
80
|
+
if (run.names === null) {
|
|
81
|
+
fail(comp, "FV1005", `\`<style module>\` takes its class names from Vite's \`css.modules\`: set \`cssModules\` in ${CONFIG_FILE} as Vite's \`css.modules.generateScopedName\` is set, or use a global or scoped \`<style>\``, blockAt(source, module));
|
|
82
|
+
}
|
|
83
|
+
run.modules.set(comp, componentModules(descriptor, file, scopeHash(file, source), run.names, (style, why) => fail(comp, "FV1014", why, blockAt(source, style))));
|
|
84
|
+
}
|
|
85
|
+
function moduleOf(comp, name) {
|
|
86
|
+
const tokens = runOf(cssModules).modules.get(comp)?.get(name);
|
|
87
|
+
return tokens ? { code: "()", ty: { k: "cssModule", name, tokens } } : null;
|
|
88
|
+
}
|
|
89
|
+
export const cssModules = {
|
|
90
|
+
name: "css-modules",
|
|
91
|
+
configure: (config, root) => {
|
|
92
|
+
const m = config.cssModules;
|
|
93
|
+
const context = resolvePath(root, m?.context ?? config.viteRoot ?? ".");
|
|
94
|
+
return { names: m ? scopedNames(m, context) : null, modules: new Map() };
|
|
95
|
+
},
|
|
96
|
+
sfc: readModules,
|
|
97
|
+
scope: () => ({ useCssModule: null }),
|
|
98
|
+
scriptImport(s, st, from) {
|
|
99
|
+
if (from !== "vue")
|
|
100
|
+
return false;
|
|
101
|
+
for (const sp of st.specifiers) {
|
|
102
|
+
if (sp.type === "ImportSpecifier" && (sp.imported.name ?? sp.imported.value) === "useCssModule")
|
|
103
|
+
scopeOf(cssModules, s).useCssModule = sp.local.name;
|
|
104
|
+
}
|
|
105
|
+
return false;
|
|
106
|
+
},
|
|
107
|
+
scriptBinding(s, d) {
|
|
108
|
+
const callee = scopeOf(cssModules, s).useCssModule;
|
|
109
|
+
const init = d.init;
|
|
110
|
+
if (callee === null || init?.type !== "CallExpression" || init.callee.type !== "Identifier" || init.callee.name !== callee)
|
|
111
|
+
return false;
|
|
112
|
+
const arg = init.arguments[0];
|
|
113
|
+
if (init.arguments.length > 1 || (arg && arg.type !== "StringLiteral"))
|
|
114
|
+
fail(s.comp, "FV1015", "`useCssModule` takes the name of a `<style module>` as a string literal, or nothing for `$style`", init);
|
|
115
|
+
const name = arg?.value ?? "$style";
|
|
116
|
+
const v = moduleOf(s.comp, name);
|
|
117
|
+
if (!v)
|
|
118
|
+
fail(s.comp, "FV1015", `\`useCssModule(${arg ? JSON.stringify(name) : ""})\` names no \`<style module${name === "$style" ? "" : `="${name}"`}>\` of this component, where Vue gives an empty object`, init);
|
|
119
|
+
if (d.id.type !== "Identifier")
|
|
120
|
+
fail(s.comp, "FV1015", "`useCssModule()` is bound to a name, as `const classes = useCssModule()`", d);
|
|
121
|
+
s.setup.set(d.id.name, v);
|
|
122
|
+
return true;
|
|
123
|
+
},
|
|
124
|
+
global: (s, name) => moduleOf(s.comp, name),
|
|
125
|
+
member(_s, base, prop) {
|
|
126
|
+
if (base.ty.k !== "cssModule")
|
|
127
|
+
return null;
|
|
128
|
+
const value = Object.hasOwn(base.ty.tokens, prop) ? base.ty.tokens[prop] : undefined;
|
|
129
|
+
return value === undefined ? { code: "None", ty: UNDEF } : { code: rustStr(value), ty: STR };
|
|
130
|
+
},
|
|
131
|
+
values: {
|
|
132
|
+
describe: (ty) => (ty.k === "cssModule" ? `the CSS module \`${ty.name}\`` : undefined),
|
|
133
|
+
unbindable: (ty) => (ty.k === "cssModule" ? { what: `the CSS module \`${ty.name}\``, fix: `bind one of its classes, as \`${ty.name}.name\`` } : undefined),
|
|
134
|
+
},
|
|
135
|
+
};
|
package/dist/plugins/head.js
CHANGED
|
@@ -18,8 +18,8 @@ const POSITIONS = new Set(["head", "bodyClose", "bodyOpen"]);
|
|
|
18
18
|
const PRIORITIES = new Set(["critical", "high", "low"]);
|
|
19
19
|
const STRATEGIES = new Set(["replace", "merge"]);
|
|
20
20
|
const OBJECT_KEYS = new Set(Object.getOwnPropertyNames(Object.prototype));
|
|
21
|
-
const META_NAMESPACES = ["twitter", "fediverse"];
|
|
22
|
-
const PROPERTY_NAMESPACES = ["og", "book", "article", "profile", "fb", "payment"];
|
|
21
|
+
const META_NAMESPACES = new Set(["twitter", "fediverse"]);
|
|
22
|
+
const PROPERTY_NAMESPACES = new Set(["og", "book", "article", "profile", "fb", "payment"]);
|
|
23
23
|
const HTTP_EQUIV_KEYS = new Set(["contentType", "defaultStyle", "xUaCompatible", "refresh", "contentSecurityPolicy"]);
|
|
24
24
|
const META_ALIASES = {
|
|
25
25
|
articleExpirationTime: "article:expiration_time",
|
|
@@ -49,7 +49,7 @@ function fixKeyCase(key) {
|
|
|
49
49
|
if (prefix === -1)
|
|
50
50
|
return updated;
|
|
51
51
|
const ns = updated.slice(0, prefix);
|
|
52
|
-
return META_NAMESPACES.
|
|
52
|
+
return META_NAMESPACES.has(ns) || PROPERTY_NAMESPACES.has(ns) ? key.replace(/([A-Z])/g, ":$1").toLowerCase() : updated;
|
|
53
53
|
}
|
|
54
54
|
/** The meta tag `useSeoMeta` writes for a key with a string value: the attribute it sets, and the
|
|
55
55
|
* name it gives (`ogTitle` is `property="og:title"`). */
|
|
@@ -61,7 +61,7 @@ export function seoMetaKey(key) {
|
|
|
61
61
|
return ["http-equiv", name];
|
|
62
62
|
const fixed = fixKeyCase(key);
|
|
63
63
|
const colon = fixed.indexOf(":");
|
|
64
|
-
return [colon !== -1 && PROPERTY_NAMESPACES.
|
|
64
|
+
return [colon !== -1 && PROPERTY_NAMESPACES.has(fixed.slice(0, colon)) ? "property" : "name", name];
|
|
65
65
|
}
|
|
66
66
|
function keyOf(comp, p) {
|
|
67
67
|
if (p.type !== "ObjectProperty" || p.computed) {
|
package/dist/plugins/i18n.js
CHANGED
|
@@ -1,25 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { basename, join } from "node:path";
|
|
1
|
+
import { basename, posix } from "node:path";
|
|
3
2
|
import { createParser } from "@intlify/message-compiler";
|
|
4
3
|
import { fail, failIn, rustStr, STR } from "../model.js";
|
|
5
4
|
import { expr } from "../expr.js";
|
|
6
5
|
import { bare, strArg } from "../parens.js";
|
|
7
6
|
import { header } from "../rust.js";
|
|
7
|
+
import { listDir, readJsonFile } from "../files.js";
|
|
8
8
|
import { runOf, scopeOf } from "../plugin.js";
|
|
9
9
|
const MODIFIERS = new Set(["upper", "lower", "capitalize"]);
|
|
10
10
|
function readLocales(root, config) {
|
|
11
|
-
const
|
|
12
|
-
const files = readdirSync(dir).filter((f) => f.endsWith(".json")).toSorted();
|
|
11
|
+
const files = listDir(root, config.messages, "i18n.messages").filter((f) => f.endsWith(".json")).toSorted();
|
|
13
12
|
const parser = createParser({});
|
|
14
13
|
const locales = files.map((f) => {
|
|
15
|
-
const file = join(config.messages, f);
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
data = JSON.parse(readFileSync(join(dir, f), "utf8"));
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
failIn(file, "FV1401", e.message);
|
|
22
|
-
}
|
|
14
|
+
const file = posix.join(config.messages, f);
|
|
15
|
+
const data = readJsonFile(root, file, { invalid: "FV1401" });
|
|
23
16
|
const messages = new Map();
|
|
24
17
|
const nested = new Map();
|
|
25
18
|
const flat = new Map();
|
package/dist/plugins/index.js
CHANGED
|
@@ -9,4 +9,5 @@ import { clientOnly } from "./client-only.js";
|
|
|
9
9
|
import { twinsPlugin } from "./twins.js";
|
|
10
10
|
import { provideInject } from "./provide.js";
|
|
11
11
|
import { head } from "./head.js";
|
|
12
|
-
|
|
12
|
+
import { cssModules } from "./css-modules.js";
|
|
13
|
+
export const PLUGINS = [router, piniaStores, sharedTypes, i18n, teleport, scoped, clientOnly, twinsPlugin, provideInject, head, cssModules];
|
package/dist/plugins/provide.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { relative } from "node:path";
|
|
2
1
|
import { absence, blankComponent, camelize, fail, nothing, opt, sameTy, snake } from "../model.js";
|
|
3
2
|
import { ctx } from "../context.js";
|
|
4
3
|
import {} from "../constants.js";
|
|
@@ -8,6 +7,7 @@ import { slotFieldBorrows, slotFieldTy, slotFieldValue } from "../slots.js";
|
|
|
8
7
|
import { fieldInit, ownInto } from "../children.js";
|
|
9
8
|
import { setupSource } from "../script.js";
|
|
10
9
|
import { header } from "../rust.js";
|
|
10
|
+
import { relativePath } from "../paths.js";
|
|
11
11
|
import { heldStr, isTemporary } from "../strings.js";
|
|
12
12
|
import { runOf, scopeOf, slotFieldsOf } from "../plugin.js";
|
|
13
13
|
const REF_CALLS = new Set(["ref", "shallowRef", "computed", "toRef", "customRef", "defineModel"]);
|
|
@@ -104,7 +104,7 @@ function keyOf(comp, n, script) {
|
|
|
104
104
|
const file = imported ? resolveImport(comp.file, imported.from) : null;
|
|
105
105
|
const decl = file !== null ? ctx.constDecls.get(file)?.get(imported.name) : undefined;
|
|
106
106
|
if (decl?.exported && decl.node.type === "VariableDeclarator" && symbolInit(decl.node.init)) {
|
|
107
|
-
const rel =
|
|
107
|
+
const rel = relativePath(ctx.rootDir, file);
|
|
108
108
|
return keyNamed(comp, n, `${rel}#${imported.name}`, `\`${imported.name}\``, rel, snake(imported.name), () => declaredOf(decl));
|
|
109
109
|
}
|
|
110
110
|
}
|
|
@@ -246,6 +246,8 @@ function structLiteral(s, key, obj, reactive, what) {
|
|
|
246
246
|
fail(s.comp, "FV1612", `an object ${what} holds plain keys and values: a function goes under a key of its own`, p);
|
|
247
247
|
const name = p.key.type === "Identifier" ? p.key.name : String(p.key.value);
|
|
248
248
|
const field = st.fields.find((f) => camelize(f.js) === camelize(name));
|
|
249
|
+
if (!field && st.refused?.has(name))
|
|
250
|
+
continue;
|
|
249
251
|
if (!field)
|
|
250
252
|
fail(s.comp, "FV1612", `\`${st.name}\` has no field \`${name}\``, p);
|
|
251
253
|
if (p.value.type === "ArrowFunctionExpression" || p.value.type === "FunctionExpression")
|
package/dist/plugins/router.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync
|
|
1
|
+
import { readdirSync } from "node:fs";
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { BOOL, fail, failIn, GenError, opt, rustStr, STR } from "../model.js";
|
|
4
4
|
import { CONFIG_FILE } from "../context.js";
|
|
@@ -7,6 +7,7 @@ import { boolOf, pathOf } from "../narrowing.js";
|
|
|
7
7
|
import { atom, bare, not, strArg } from "../parens.js";
|
|
8
8
|
import { runOf, scopeOf } from "../plugin.js";
|
|
9
9
|
import { header } from "../rust.js";
|
|
10
|
+
import { readJsonFile } from "../files.js";
|
|
10
11
|
import { allPages, fileRoutes } from "../file-routes.js";
|
|
11
12
|
import { scopeIdOf } from "./scoped.js";
|
|
12
13
|
import { routerLink } from "./router-link.js";
|
|
@@ -86,7 +87,7 @@ function readPages(root, config, pages) {
|
|
|
86
87
|
return routes;
|
|
87
88
|
}
|
|
88
89
|
export function readRoutes(root, file) {
|
|
89
|
-
const raw =
|
|
90
|
+
const raw = readJsonFile(root, file, { missing: "FV1246", invalid: "FV1247" });
|
|
90
91
|
if (!Array.isArray(raw))
|
|
91
92
|
throw new GenError("FV1232", `${file} lists the routes in an array`, { file });
|
|
92
93
|
const read = (list, parent) => list.map((r) => {
|