sveltekit-client-hints
Advanced tools
| export type Config = { | ||
| base_cookie_name?: string; | ||
| generate_dts?: boolean; | ||
| functions: Record<string, () => string>; | ||
| }; | ||
| export declare function sveltekit_client_hints({ functions, base_cookie_name, generate_dts }: Config): { | ||
| name: string; | ||
| resolveId(this: import("rollup").PluginContext, source: string): string | undefined; | ||
| load(this: import("rollup").PluginContext, id: string): string | undefined; | ||
| }; |
| import { writeFile } from 'node:fs/promises'; | ||
| import { resolve, join } from 'node:path'; | ||
| export function sveltekit_client_hints({ functions, base_cookie_name = 'client-hints-', generate_dts = true }) { | ||
| const virtual_name = 'virtual:sveltekit-client-hint'; | ||
| const resolved_virtual_name = `\0${virtual_name}`; | ||
| if (generate_dts) { | ||
| const types = `declare global { | ||
| namespace App { | ||
| interface Locals { | ||
| ${Object.keys(functions) | ||
| .map((hint) => `\t\t\t${hint}: string | undefined;`) | ||
| .join('\n')} | ||
| } | ||
| } | ||
| } | ||
| export {};`; | ||
| writeFile(resolve(join(process.cwd(), 'src', 'sveltekit-client-hints.d.ts')), types); | ||
| } | ||
| return { | ||
| name: 'vite-sveltekit-early-hint-plugin', | ||
| resolveId(source) { | ||
| if (source === virtual_name) { | ||
| return resolved_virtual_name; | ||
| } | ||
| }, | ||
| load(id) { | ||
| if (id === resolved_virtual_name) { | ||
| return ` | ||
| export const base_cookie_name = "${base_cookie_name}"; | ||
| export const config = ${JSON.stringify(functions, (key, value) => { | ||
| if (typeof value === 'function') { | ||
| const to_return = value.toString(); | ||
| if (to_return.startsWith(`${key}()`)) { | ||
| return `function ${to_return}`; | ||
| } | ||
| return to_return; | ||
| } | ||
| return value; | ||
| })};`; | ||
| } | ||
| } | ||
| }; | ||
| } |
+0
-10
| import type { Handle } from '@sveltejs/kit'; | ||
| export declare const handle: Handle; | ||
| export type Config = { | ||
| base_cookie_name?: string; | ||
| generate_dts?: boolean; | ||
| functions: Record<string, () => string>; | ||
| }; | ||
| export declare function sveltekit_client_hints({ functions, base_cookie_name, generate_dts }: Config): { | ||
| name: string; | ||
| resolveId(this: import("rollup").PluginContext, source: string): string | undefined; | ||
| load(this: import("rollup").PluginContext, id: string): string | undefined; | ||
| }; |
+0
-44
| import { config, base_cookie_name } from 'virtual:sveltekit-client-hint'; | ||
| import { writeFile } from 'node:fs/promises'; | ||
| import { resolve, join } from 'node:path'; | ||
| const basic_html = ` | ||
@@ -38,43 +36,1 @@ <script> | ||
| }; | ||
| export function sveltekit_client_hints({ functions, base_cookie_name = 'client-hints-', generate_dts = true }) { | ||
| const virtual_name = 'virtual:sveltekit-client-hint'; | ||
| const resolved_virtual_name = `\0${virtual_name}`; | ||
| if (generate_dts) { | ||
| const types = `declare global { | ||
| namespace App { | ||
| interface Locals { | ||
| ${Object.keys(functions) | ||
| .map((hint) => `\t\t\t${hint}: string | undefined;`) | ||
| .join('\n')} | ||
| } | ||
| } | ||
| } | ||
| export {};`; | ||
| writeFile(resolve(join(process.cwd(), 'src', 'sveltekit-client-hints.d.ts')), types); | ||
| } | ||
| return { | ||
| name: 'vite-sveltekit-early-hint-plugin', | ||
| resolveId(source) { | ||
| if (source === virtual_name) { | ||
| return resolved_virtual_name; | ||
| } | ||
| }, | ||
| load(id) { | ||
| if (id === resolved_virtual_name) { | ||
| return ` | ||
| export const base_cookie_name = "${base_cookie_name}"; | ||
| export const config = ${JSON.stringify(functions, (key, value) => { | ||
| if (typeof value === 'function') { | ||
| const to_return = value.toString(); | ||
| if (to_return.startsWith(`${key}()`)) { | ||
| return `function ${to_return}`; | ||
| } | ||
| return to_return; | ||
| } | ||
| return value; | ||
| })};`; | ||
| } | ||
| } | ||
| }; | ||
| } |
+1
-1
| { | ||
| "name": "sveltekit-client-hints", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "exports": { | ||
@@ -5,0 +5,0 @@ ".": { |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
6
50%