@slotform/vite 0.0.0-stage → 0.1.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.
@@ -0,0 +1,83 @@
1
+ // The merge rule of `vite.slots.clientHeaders`: docs/architecture/plugins/vite.md, "Content-Security-Policy".
2
+ import { createHash } from "node:crypto";
3
+ const CSP = "content-security-policy";
4
+ // Header names are case-insensitive: the slot compares them folded.
5
+ export function headerKey(name) {
6
+ return name.toLowerCase();
7
+ }
8
+ // `name source source…` separated by `;`. A directive name compares
9
+ // case-insensitively and keeps its first spelling; an empty segment is
10
+ // dropped. A repeated directive inside one policy is ignored by browsers
11
+ // after its first, so the first wins here too.
12
+ function parse(policy) {
13
+ const out = [];
14
+ const seen = new Set();
15
+ for (const segment of policy.split(";")) {
16
+ const [name, ...sources] = segment.trim().split(/\s+/);
17
+ if (!name)
18
+ continue;
19
+ const id = name.toLowerCase();
20
+ if (seen.has(id))
21
+ continue;
22
+ seen.add(id);
23
+ out.push({ name, sources });
24
+ }
25
+ return out;
26
+ }
27
+ const isNone = (source) => source.toLowerCase() === "'none'";
28
+ // Sources of one directive, unioned in first-seen order. `'none'` means "no
29
+ // source": alone it stays, beside real sources it drops.
30
+ function unionSources(a, b) {
31
+ const union = [];
32
+ for (const source of [...a, ...b]) {
33
+ if (!union.includes(source))
34
+ union.push(source);
35
+ }
36
+ const real = union.filter((source) => !isNone(source));
37
+ return real.length > 0 ? real : union;
38
+ }
39
+ export function mergeCsp(a, b) {
40
+ const merged = new Map();
41
+ for (const directive of [...parse(a), ...parse(b)]) {
42
+ const id = directive.name.toLowerCase();
43
+ const held = merged.get(id);
44
+ merged.set(id, held === undefined
45
+ ? directive
46
+ : {
47
+ name: held.name,
48
+ sources: unionSources(held.sources, directive.sources),
49
+ });
50
+ }
51
+ return [...merged.values()]
52
+ .map((d) => [d.name, ...d.sources].join(" "))
53
+ .join("; ");
54
+ }
55
+ // The CSP source for an inline script: the base64 SHA-256 of its text, which
56
+ // is what a browser hashes (the element's text content, byte for byte).
57
+ export function scriptHash(script) {
58
+ return `'sha256-${createHash("sha256").update(script, "utf8").digest("base64")}'`;
59
+ }
60
+ // The directives a browser checks a `<script>` element against, in order: the
61
+ // first one a policy names decides.
62
+ const SCRIPT_ELEMENT = ["script-src-elem", "script-src", "default-src"];
63
+ // `'unsafe-inline'` allows every inline script only while no hash or nonce
64
+ // stands beside it; a hash added beside it revokes it.
65
+ const allowsEveryInline = (sources) => sources.some((s) => s.toLowerCase() === "'unsafe-inline'") &&
66
+ !sources.some((s) => /^'(?:sha256|sha384|sha512|nonce)-/i.test(s));
67
+ // `policy` with `source` added to the directive that decides a `<script>`
68
+ // element. A policy that names none of them restricts no script, and one whose
69
+ // deciding directive allows every inline script already allows this one: both
70
+ // come back as they are.
71
+ export function allowScript(policy, source) {
72
+ const directives = parse(policy);
73
+ const deciding = SCRIPT_ELEMENT.map((name) => directives.find((d) => d.name.toLowerCase() === name)).find((d) => d !== undefined);
74
+ if (deciding === undefined || allowsEveryInline(deciding.sources))
75
+ return policy;
76
+ return mergeCsp(policy, `${deciding.name} ${source}`);
77
+ }
78
+ // The slot's `merge`: a CSP combines, any other header declines (undefined),
79
+ // which leaves the duplicate a conflict.
80
+ export function mergeClientHeader(a, b, key) {
81
+ return key === CSP ? mergeCsp(a, b) : undefined;
82
+ }
83
+ //# sourceMappingURL=csp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csp.js","sourceRoot":"","sources":["../../src/node/csp.ts"],"names":[],"mappings":"AAAA,8GAA8G;AAE9G,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,GAAG,GAAG,yBAAyB,CAAC;AAEtC,oEAAoE;AACpE,MAAM,UAAU,SAAS,CAAC,IAAY;IACrC,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;AAC3B,CAAC;AAOD,oEAAoE;AACpE,uEAAuE;AACvE,yEAAyE;AACzE,+CAA+C;AAC/C,SAAS,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,OAAiB,EAAE,EAAE,CAC/C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,KAAK,iBAAiB,CAAC;IAC1D,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,oCAAoC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpE,0EAA0E;AAC1E,+EAA+E;AAC/E,8EAA8E;AAC9E,yBAAyB;AACzB,MAAM,UAAU,WAAW,CAAC,MAAc,EAAE,MAAc;IACzD,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,MAAM,QAAQ,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAC5C,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,CACrD,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC;IAC/B,IAAI,QAAQ,KAAK,SAAS,IAAI,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC;QAChE,OAAO,MAAM,CAAC;IACf,OAAO,QAAQ,CAAC,MAAM,EAAE,GAAG,QAAQ,CAAC,IAAI,IAAI,MAAM,EAAE,CAAC,CAAC;AACvD,CAAC;AAED,6EAA6E;AAC7E,yCAAyC;AACzC,MAAM,UAAU,iBAAiB,CAChC,CAAS,EACT,CAAS,EACT,GAAW;IAEX,OAAO,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;AACjD,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from "vite";
2
+ export declare function importsOf(source: string): string[];
3
+ export declare function excludedImports(excluded: readonly string[], root: string, skip?: ReadonlySet<string>): string[];
4
+ export declare function excludedImportsPlugin(): Plugin;
5
+ //# sourceMappingURL=excluded.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excluded.d.ts","sourceRoot":"","sources":["../../src/node/excluded.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAuEnC,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAIlD;AAkBD,wBAAgB,eAAe,CAC9B,QAAQ,EAAE,SAAS,MAAM,EAAE,EAC3B,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE,WAAW,CAAC,MAAM,CAAa,GACnC,MAAM,EAAE,CAgDV;AAID,wBAAgB,qBAAqB,IAAI,MAAM,CAc9C"}
@@ -0,0 +1,156 @@
1
+ import { existsSync, readFileSync, realpathSync, statSync } from "node:fs";
2
+ import { builtinModules } from "node:module";
3
+ import { dirname, join, resolve } from "node:path";
4
+ import { z } from "zod";
5
+ // Why the optimizer needs these includes: docs/architecture/plugins/vite.md, "Singletons and the optimizer".
6
+ const SOURCE = /^\.\/src\/.+\.(?:[cm]?[jt]sx?)$/;
7
+ const SUFFIXES = ["", ".ts", ".tsx", ".js", ".mjs", "/index.ts", "/index.js"];
8
+ const BUILTINS = new Set(builtinModules);
9
+ // The first directory up from `from` that holds `node_modules/<name>`.
10
+ function findPackage(name, from) {
11
+ for (let dir = resolve(from);; dir = dirname(dir)) {
12
+ const found = join(dir, "node_modules", name);
13
+ if (existsSync(join(found, "package.json")))
14
+ return realpathSync(found);
15
+ if (dirname(dir) === dir)
16
+ return undefined;
17
+ }
18
+ }
19
+ // A malformed `exports` (a string or array shorthand) reads as no subpaths.
20
+ const manifestSchema = z.object({
21
+ exports: z.record(z.string(), z.unknown()).optional().catch(undefined),
22
+ });
23
+ // A subpath's file: a string target, or the `default`/`import` of a condition map.
24
+ function targetOf(value) {
25
+ if (typeof value === "string")
26
+ return value;
27
+ if (value && typeof value === "object") {
28
+ return targetOf(Reflect.get(value, "default") ?? Reflect.get(value, "import"));
29
+ }
30
+ return undefined;
31
+ }
32
+ // The file a relative specifier names: as written, with a suffix, or a `.js`
33
+ // spelling of a TypeScript source.
34
+ function localFile(from, specifier) {
35
+ const base = resolve(dirname(from), specifier);
36
+ const stem = base.replace(/\.[cm]?js$/, "");
37
+ return [base, stem]
38
+ .flatMap((path) => SUFFIXES.map((suffix) => path + suffix))
39
+ .find((path) => {
40
+ try {
41
+ return statSync(path).isFile();
42
+ }
43
+ catch (err) {
44
+ if (isAbsent(err))
45
+ return false;
46
+ throw err;
47
+ }
48
+ });
49
+ }
50
+ // A missing path, or a file where a directory should be: the not-found answers.
51
+ function isAbsent(err) {
52
+ const code = err instanceof Error && "code" in err ? err.code : undefined;
53
+ return code === "ENOENT" || code === "ENOTDIR";
54
+ }
55
+ function read(file) {
56
+ try {
57
+ return readFileSync(file, "utf8");
58
+ }
59
+ catch (err) {
60
+ if (isAbsent(err))
61
+ return "";
62
+ throw err;
63
+ }
64
+ }
65
+ const COMMENTS = /\/\*[\s\S]*?\*\/|(?<![:"'`\\])\/\/.*$/gm;
66
+ const IMPORTS = /(?:\b(?:import|export)(?!\s+type\b)[^'"`;]*?\bfrom\s*|\bimport\s*\(?\s*)["']([^"']+)["']/g;
67
+ // The module specifiers a file writes: static and dynamic imports, re-exports.
68
+ export function importsOf(source) {
69
+ return [...source.replace(COMMENTS, "").matchAll(IMPORTS)].flatMap((match) => match[1] ? [match[1]] : []);
70
+ }
71
+ function packageOf(specifier) {
72
+ const parts = specifier.split("/");
73
+ return specifier.startsWith("@")
74
+ ? parts.slice(0, 2).join("/")
75
+ : (parts[0] ?? "");
76
+ }
77
+ // What the raw source of each excluded entry imports from outside it, for
78
+ // `optimizeDeps.include`. An entry is a package (all its raw source exports
79
+ // `./src/*`) or one of its subpaths (that export alone). A file's own package
80
+ // is followed into where the entry is the whole package, and otherwise named
81
+ // as it is (the optimizer bundles that subpath and what it imports); any other
82
+ // package is `entry package > specifier`. A package that is not installed, an
83
+ // import that does not resolve from the importer (an optional peer that is
84
+ // absent) and the names in `skip` (the app's singletons, which its own scan
85
+ // finds) are left out.
86
+ export function excludedImports(excluded, root, skip = new Set()) {
87
+ const found = new Set();
88
+ for (const entry of excluded) {
89
+ const name = packageOf(entry);
90
+ const dir = findPackage(name, root);
91
+ if (!dir)
92
+ continue;
93
+ const manifest = manifestSchema.parse(JSON.parse(read(join(dir, "package.json")) || "{}"));
94
+ const subpaths = manifest.exports ?? {};
95
+ const whole = entry === name;
96
+ const isExcluded = (specifier) => excluded.some((e) => specifier === e || specifier.startsWith(`${e}/`));
97
+ const files = new Set();
98
+ const visit = (file) => {
99
+ if (files.has(file))
100
+ return;
101
+ files.add(file);
102
+ for (const specifier of importsOf(read(file))) {
103
+ if (specifier.startsWith(".")) {
104
+ const own = localFile(file, specifier);
105
+ if (own)
106
+ visit(own);
107
+ continue;
108
+ }
109
+ if (specifier.startsWith("node:") || BUILTINS.has(specifier))
110
+ continue;
111
+ // A `virtual:` module is served by a Vite plugin: no file to read.
112
+ if (specifier.startsWith("virtual:"))
113
+ continue;
114
+ const owner = packageOf(specifier);
115
+ if (owner === name) {
116
+ if (whole) {
117
+ const target = targetOf(subpaths[`.${specifier.slice(name.length)}`]);
118
+ if (target)
119
+ visit(join(dir, target));
120
+ }
121
+ else if (!isExcluded(specifier))
122
+ found.add(specifier);
123
+ continue;
124
+ }
125
+ if (isExcluded(specifier) || skip.has(owner))
126
+ continue;
127
+ if (findPackage(owner, dir))
128
+ found.add(`${name} > ${specifier}`);
129
+ }
130
+ };
131
+ const seeds = whole
132
+ ? Object.values(subpaths)
133
+ .map(targetOf)
134
+ .filter((target) => target && SOURCE.test(target))
135
+ : [targetOf(subpaths[`.${entry.slice(name.length)}`])];
136
+ for (const target of seeds)
137
+ if (target)
138
+ visit(join(dir, target));
139
+ }
140
+ return [...found].sort();
141
+ }
142
+ // Adds `excludedImports` of the config's `optimizeDeps.exclude` to
143
+ // `optimizeDeps.include`, so the optimizer bundles them at start.
144
+ export function excludedImportsPlugin() {
145
+ return {
146
+ name: "fcalell:excluded-imports",
147
+ config: (config) => {
148
+ const exclude = config.optimizeDeps?.exclude ?? [];
149
+ if (exclude.length === 0)
150
+ return undefined;
151
+ const include = excludedImports(exclude, config.root ?? process.cwd(), new Set(config.resolve?.dedupe ?? []));
152
+ return include.length > 0 ? { optimizeDeps: { include } } : undefined;
153
+ },
154
+ };
155
+ }
156
+ //# sourceMappingURL=excluded.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"excluded.js","sourceRoot":"","sources":["../../src/node/excluded.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,6GAA6G;AAE7G,MAAM,MAAM,GAAG,iCAAiC,CAAC;AACjD,MAAM,QAAQ,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;AAC9E,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,CAAC;AAEzC,uEAAuE;AACvE,SAAS,WAAW,CAAC,IAAY,EAAE,IAAY;IAC9C,KAAK,IAAI,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,GAAI,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,EAAE,IAAI,CAAC,CAAC;QAC9C,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC;YAAE,OAAO,YAAY,CAAC,KAAK,CAA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AC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ export type { ServerProxyEntry, ViteConfigValues } from "../types.ts";
2
+ export { renderViteConfig } from "./codegen.ts";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { renderViteConfig } from "./codegen.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/node/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Plugin } from "vite";
2
+ export { excludedImportsPlugin } from "./excluded.ts";
3
+ export declare function providersPlugin(): Plugin;
4
+ export declare function schemaPlugin(): Plugin;
5
+ //# sourceMappingURL=preset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset.d.ts","sourceRoot":"","sources":["../../src/node/preset.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAEnC,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAyBtD,wBAAgB,eAAe,IAAI,MAAM,CAMxC;AAGD,wBAAgB,YAAY,IAAI,MAAM,CAMrC"}
@@ -0,0 +1,35 @@
1
+ import { existsSync } from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import { GENERATED_DIR } from "@slotform/cli";
4
+ export { excludedImportsPlugin } from "./excluded.js";
5
+ // A virtual module served by the generated file once `slotform generate` wrote
6
+ // it, by `fallback` before. The path resolves against the working directory,
7
+ // the consumer root every `slotform` command runs Vite from.
8
+ function virtualModule(id, file, fallback) {
9
+ const resolved = `\0${id}`;
10
+ const path = resolve(file);
11
+ return {
12
+ name: `fcalell:${id.replace("virtual:", "")}`,
13
+ resolveId(source) {
14
+ if (source !== id)
15
+ return null;
16
+ if (existsSync(path))
17
+ return path;
18
+ return resolved;
19
+ },
20
+ load(source) {
21
+ if (source !== resolved)
22
+ return null;
23
+ return fallback;
24
+ },
25
+ };
26
+ }
27
+ // `virtual:slotform-providers` and its pass-through stub: docs/architecture/plugins/vite.md, "Preset".
28
+ export function providersPlugin() {
29
+ return virtualModule("virtual:slotform-providers", `${GENERATED_DIR}/virtual-providers.tsx`, "export default function Providers(props) {\n\treturn props.children;\n}\n");
30
+ }
31
+ // `virtual:slotform-schema`: docs/architecture/plugins/vite.md, "Preset".
32
+ export function schemaPlugin() {
33
+ return virtualModule("virtual:slotform-schema", `${GENERATED_DIR}/schema.ts`, "export const SCHEMA = {};\n");
34
+ }
35
+ //# sourceMappingURL=preset.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset.js","sourceRoot":"","sources":["../../src/node/preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAG9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAEtD,+EAA+E;AAC/E,6EAA6E;AAC7E,6DAA6D;AAC7D,SAAS,aAAa,CAAC,EAAU,EAAE,IAAY,EAAE,QAAgB;IAChE,MAAM,QAAQ,GAAG,KAAK,EAAE,EAAE,CAAC;IAC3B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,OAAO;QACN,IAAI,EAAE,WAAW,EAAE,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE;QAE7C,SAAS,CAAC,MAAM;YACf,IAAI,MAAM,KAAK,EAAE;gBAAE,OAAO,IAAI,CAAC;YAC/B,IAAI,UAAU,CAAC,IAAI,CAAC;gBAAE,OAAO,IAAI,CAAC;YAClC,OAAO,QAAQ,CAAC;QACjB,CAAC;QAED,IAAI,CAAC,MAAM;YACV,IAAI,MAAM,KAAK,QAAQ;gBAAE,OAAO,IAAI,CAAC;YACrC,OAAO,QAAQ,CAAC;QACjB,CAAC;KACD,CAAC;AACH,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,eAAe;IAC9B,OAAO,aAAa,CACnB,4BAA4B,EAC5B,GAAG,aAAa,wBAAwB,EACxC,2EAA2E,CAC3E,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,YAAY;IAC3B,OAAO,aAAa,CACnB,yBAAyB,EACzB,GAAG,aAAa,YAAY,EAC5B,6BAA6B,CAC7B,CAAC;AACH,CAAC"}
@@ -0,0 +1,38 @@
1
+ import type { TsExpression, TsImportSpec } from "@slotform/cli/ast";
2
+ import { z } from "zod";
3
+ export declare const viteOptionsSchema: z.ZodObject<{
4
+ port: z.ZodOptional<z.ZodNumber>;
5
+ restart: z.ZodOptional<z.ZodEnum<{
6
+ always: "always";
7
+ never: "never";
8
+ "on-crash": "on-crash";
9
+ }>>;
10
+ maxRestarts: z.ZodOptional<z.ZodNumber>;
11
+ }, z.core.$strip>;
12
+ export type ViteOptions = z.input<typeof viteOptionsSchema>;
13
+ export interface ServerProxyEntry {
14
+ path: string;
15
+ target: string;
16
+ ws?: boolean;
17
+ }
18
+ export interface AppPlugin {
19
+ call: TsExpression;
20
+ imports: TsImportSpec[];
21
+ }
22
+ export interface ViteConfigValues {
23
+ configImports: TsImportSpec[];
24
+ pluginCalls: TsExpression[];
25
+ resolveAliases: Array<{
26
+ find: string;
27
+ replacement: string;
28
+ }>;
29
+ resolveDedupe: string[];
30
+ optimizeExclude: string[];
31
+ devServerPort: number;
32
+ outDir: string;
33
+ serverProxy: ServerProxyEntry[];
34
+ fsAllow: TsExpression[];
35
+ watchIgnored: string[];
36
+ clientHeaders: Record<string, string>;
37
+ }
38
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAQxB,eAAO,MAAM,iBAAiB;;;;;;;;iBAI5B,CAAC;AAEH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAG5D,MAAM,WAAW,gBAAgB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,CAAC,EAAE,OAAO,CAAC;CACb;AAGD,MAAM,WAAW,SAAS;IACzB,IAAI,EAAE,YAAY,CAAC;IACnB,OAAO,EAAE,YAAY,EAAE,CAAC;CACxB;AAKD,MAAM,WAAW,gBAAgB;IAChC,aAAa,EAAE,YAAY,EAAE,CAAC;IAC9B,WAAW,EAAE,YAAY,EAAE,CAAC;IAC5B,cAAc,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAE7D,aAAa,EAAE,MAAM,EAAE,CAAC;IAExB,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,aAAa,EAAE,MAAM,CAAC;IAEtB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,gBAAgB,EAAE,CAAC;IAKhC,OAAO,EAAE,YAAY,EAAE,CAAC;IAGxB,YAAY,EAAE,MAAM,EAAE,CAAC;IAEvB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC"}
package/dist/types.js ADDED
@@ -0,0 +1,12 @@
1
+ import { z } from "zod";
2
+ // Restart policy for vite's dev process. Defaults to "never" because vite
3
+ // already handles HMR; restarting on crash usually masks the underlying bug.
4
+ // Exposed so a consumer can opt into "on-crash" / "always" if they have a
5
+ // reason (e.g. flaky upstream dependency).
6
+ const restartPolicySchema = z.enum(["never", "on-crash", "always"]);
7
+ export const viteOptionsSchema = z.object({
8
+ port: z.number().int().min(1).max(65535).optional(),
9
+ restart: restartPolicySchema.optional(),
10
+ maxRestarts: z.number().int().min(0).optional(),
11
+ });
12
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,0EAA0E;AAC1E,6EAA6E;AAC7E,0EAA0E;AAC1E,2CAA2C;AAC3C,MAAM,mBAAmB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC,CAAC;AAEpE,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,CAAC,MAAM,CAAC;IACzC,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,QAAQ,EAAE;IACnD,OAAO,EAAE,mBAAmB,CAAC,QAAQ,EAAE;IACvC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE;CAC/C,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,73 @@
1
1
  {
2
2
  "name": "@slotform/vite",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "The Vite lifecycle plugin for slotform, framework-agnostic: renders .slotform/vite.config.ts from what other plugins contribute, runs vite for dev and build, and serves the providers and schema virtual modules.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/fcalell/slotform.git",
9
+ "directory": "plugins/vite"
10
+ },
11
+ "homepage": "https://github.com/fcalell/slotform/tree/master/plugins/vite#readme",
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "engines": {
16
+ "node": ">=24.14.0"
17
+ },
18
+ "type": "module",
19
+ "sideEffects": false,
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "./csp": {
26
+ "types": "./dist/node/csp.d.ts",
27
+ "default": "./dist/node/csp.js"
28
+ },
29
+ "./node": {
30
+ "types": "./dist/node/index.d.ts",
31
+ "default": "./dist/node/index.js"
32
+ },
33
+ "./preset": {
34
+ "types": "./dist/node/preset.d.ts",
35
+ "default": "./dist/node/preset.js"
36
+ }
37
+ },
38
+ "files": [
39
+ "dist",
40
+ "src",
41
+ "README.md",
42
+ "LICENSE",
43
+ "!src/**/*.test.ts",
44
+ "!src/**/__fixtures__",
45
+ "!dist/**/*.test.*"
46
+ ],
47
+ "peerDependencies": {
48
+ "vite": "^8.3.8",
49
+ "zod": "^4.6.7"
50
+ },
51
+ "peerDependenciesMeta": {
52
+ "vite": {
53
+ "optional": true
54
+ }
55
+ },
56
+ "dependencies": {
57
+ "@slotform/cli": "^0.1.0",
58
+ "@slotform/api": "^0.1.0"
59
+ },
60
+ "devDependencies": {
61
+ "@slotform/typescript-config": "^0.1.0",
62
+ "@types/node": "^26.6.6",
63
+ "typescript": "^7.0.2",
64
+ "vite": "^8.3.8",
65
+ "zod": "^4.6.7"
66
+ },
67
+ "scripts": {
68
+ "build": "tsc -p tsconfig.build.json",
69
+ "check-types": "tsc --noEmit --pretty",
70
+ "test": "node --test 'src/**/*.test.ts'",
71
+ "clear": "rm -rf dist node_modules .turbo"
72
+ }
6
73
  }