svelte-origin 0.0.0 → 1.0.0-next.15

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.

Potentially problematic release.


This version of svelte-origin might be problematic. Click here for more details.

@@ -0,0 +1,143 @@
1
+ /**
2
+ * Unified Vite/Rollup/Rolldown plugin for svelte-origin
3
+ *
4
+ * This plugin transforms macro syntax in:
5
+ * - .svelte.ts/.svelte.js files (origin definitions)
6
+ * - .svelte files (component scripts using $attrs.origin, $attrs.for, etc.)
7
+ *
8
+ * Works with Vite, Rollup, and Rolldown.
9
+ *
10
+ * NOTE: For best compatibility (especially with rolldown-vite), use the
11
+ * Svelte preprocessor instead of or in addition to this plugin:
12
+ *
13
+ * ```js
14
+ * // svelte.config.js
15
+ * import { svelteOriginPreprocess } from 'svelte-origin/preprocess'
16
+ *
17
+ * export default {
18
+ * preprocess: [
19
+ * svelteOriginPreprocess(), // MUST come first
20
+ * vitePreprocess()
21
+ * ]
22
+ * }
23
+ * ```
24
+ */
25
+ import { parseOriginSchemaFromSource, findImportPath, type ParsedOriginSchema, type ParsedAttrInfo, type SchemaResolver } from './transform/schema';
26
+ type Plugin = {
27
+ name: string;
28
+ enforce?: 'pre' | 'post';
29
+ resolveId?: (id: string, importer?: string) => Promise<string | null | undefined | {
30
+ id: string;
31
+ external?: boolean;
32
+ }> | string | null | undefined | {
33
+ id: string;
34
+ external?: boolean;
35
+ };
36
+ load?: (id: string) => Promise<{
37
+ code: string;
38
+ map?: any;
39
+ } | string | null | undefined> | {
40
+ code: string;
41
+ map?: any;
42
+ } | string | null | undefined;
43
+ transform?: (code: string, id: string) => Promise<{
44
+ code: string;
45
+ map?: any;
46
+ } | null | undefined> | {
47
+ code: string;
48
+ map?: any;
49
+ } | null | undefined;
50
+ };
51
+ export interface SvelteOriginPluginOptions {
52
+ /**
53
+ * File extensions to process for origin definitions
54
+ * @default ['.svelte.ts', '.svelte.js', '.origin.svelte.ts']
55
+ */
56
+ extensions?: string[];
57
+ /**
58
+ * Enable debug logging
59
+ * @default false
60
+ */
61
+ debug?: boolean;
62
+ /**
63
+ * Output transformed code to .transformed.txt files for debugging
64
+ * @default false
65
+ */
66
+ outputTransformed?: boolean;
67
+ /**
68
+ * Directory to output transformed files (relative to file or absolute)
69
+ * @default same directory as source file
70
+ */
71
+ outputDir?: string;
72
+ /**
73
+ * Manual alias mappings for resolving non-relative imports.
74
+ * These have the highest priority and override auto-detected aliases.
75
+ *
76
+ * @example
77
+ * aliases: {
78
+ * '$lib': 'src/lib',
79
+ * '$components': 'src/lib/components'
80
+ * }
81
+ */
82
+ aliases?: Record<string, string>;
83
+ /**
84
+ * Project root for resolving relative alias paths
85
+ * @default process.cwd()
86
+ */
87
+ root?: string;
88
+ /**
89
+ * Whether to auto-detect aliases from tsconfig.json and svelte.config.js
90
+ *
91
+ * When enabled (default), the plugin will:
92
+ * 1. Read tsconfig.json (and any configs it extends) for compilerOptions.paths
93
+ * 2. Read .svelte-kit/tsconfig.json for SvelteKit-generated paths
94
+ * 3. Read svelte.config.js for kit.alias configuration
95
+ *
96
+ * Manual aliases always take priority over auto-detected ones.
97
+ *
98
+ * @default true
99
+ */
100
+ autoDetectAliases?: boolean;
101
+ /**
102
+ * Path to tsconfig.json (relative to root or absolute).
103
+ * Only used when autoDetectAliases is true.
104
+ */
105
+ tsconfig?: string;
106
+ /**
107
+ * Path to svelte.config.js (relative to root or absolute).
108
+ * Only used when autoDetectAliases is true.
109
+ */
110
+ svelteConfig?: string;
111
+ }
112
+ /**
113
+ * Create a unified plugin for svelte-origin macros.
114
+ * Works with Vite, Rollup, and Rolldown.
115
+ *
116
+ * @example
117
+ * // vite.config.ts
118
+ * import { svelteOrigin } from 'svelte-origin/plugin'
119
+ * import { sveltekit } from '@sveltejs/kit/vite'
120
+ *
121
+ * export default {
122
+ * plugins: [
123
+ * svelteOrigin(),
124
+ * sveltekit()
125
+ * ]
126
+ * }
127
+ *
128
+ * @example
129
+ * // rollup.config.js
130
+ * import { svelteOrigin } from 'svelte-origin/plugin'
131
+ * import svelte from 'rollup-plugin-svelte'
132
+ *
133
+ * export default {
134
+ * plugins: [
135
+ * svelteOrigin(),
136
+ * svelte()
137
+ * ]
138
+ * }
139
+ */
140
+ export declare function svelteOrigin(options?: SvelteOriginPluginOptions): Plugin;
141
+ export default svelteOrigin;
142
+ export { findImportPath, parseOriginSchemaFromSource };
143
+ export type { ParsedOriginSchema, SchemaResolver, ParsedAttrInfo };