zylaris 1.0.2
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/LICENSE +21 -0
- package/README.md +558 -0
- package/Zylaris.js.png +0 -0
- package/examples/default/index.html +13 -0
- package/examples/default/package.json +23 -0
- package/examples/default/src/app/about/page.tsx +18 -0
- package/examples/default/src/app/counter/page.tsx +22 -0
- package/examples/default/src/app/global.css +225 -0
- package/examples/default/src/app/layout.tsx +33 -0
- package/examples/default/src/app/page.tsx +14 -0
- package/examples/default/src/entry-client.tsx +87 -0
- package/examples/default/src/entry-server.tsx +52 -0
- package/examples/default/src/router.ts +60 -0
- package/examples/default/tsconfig.json +28 -0
- package/examples/default/zylaris.config.ts +24 -0
- package/package.json +34 -0
- package/packages/adapter/package.json +59 -0
- package/packages/adapter/src/adapters/bun.ts +215 -0
- package/packages/adapter/src/adapters/cloudflare.ts +278 -0
- package/packages/adapter/src/adapters/deno.ts +219 -0
- package/packages/adapter/src/adapters/netlify.ts +274 -0
- package/packages/adapter/src/adapters/node.ts +155 -0
- package/packages/adapter/src/adapters/static.ts +134 -0
- package/packages/adapter/src/adapters/vercel.ts +239 -0
- package/packages/adapter/src/index.ts +115 -0
- package/packages/adapter/src/lib/builder.ts +361 -0
- package/packages/adapter/src/types.ts +191 -0
- package/packages/adapter/tsconfig.json +8 -0
- package/packages/cli/package.json +43 -0
- package/packages/cli/src/bin.ts +107 -0
- package/packages/cli/src/commands/build.ts +197 -0
- package/packages/cli/src/commands/create.ts +222 -0
- package/packages/cli/src/commands/deploy.ts +90 -0
- package/packages/cli/src/commands/dev.ts +108 -0
- package/packages/cli/src/index.ts +6 -0
- package/packages/cli/tsconfig.json +9 -0
- package/packages/compiler/package.json +39 -0
- package/packages/compiler/src/index.ts +210 -0
- package/packages/compiler/src/jit.ts +187 -0
- package/packages/compiler/tsconfig.json +9 -0
- package/packages/core/package.json +55 -0
- package/packages/core/src/components.test.ts +125 -0
- package/packages/core/src/components.ts +181 -0
- package/packages/core/src/config.ts +204 -0
- package/packages/core/src/hooks.ts +142 -0
- package/packages/core/src/index.ts +59 -0
- package/packages/core/src/jsx-runtime.ts +46 -0
- package/packages/core/tsconfig.json +16 -0
- package/packages/dev-server/package.json +51 -0
- package/packages/dev-server/src/index.ts +306 -0
- package/packages/dev-server/src/jit-middleware.ts +78 -0
- package/packages/dev-server/tsconfig.json +9 -0
- package/packages/plugins/package.json +44 -0
- package/packages/plugins/src/cdn/loader.ts +275 -0
- package/packages/plugins/src/index.ts +238 -0
- package/packages/plugins/src/loaders/auto-import.ts +219 -0
- package/packages/plugins/src/loaders/external.ts +332 -0
- package/packages/plugins/src/transforms/index.ts +407 -0
- package/packages/plugins/src/types.ts +296 -0
- package/packages/plugins/tsconfig.json +8 -0
- package/packages/reactivity/package.json +36 -0
- package/packages/reactivity/src/computed.d.ts +3 -0
- package/packages/reactivity/src/computed.d.ts.map +1 -0
- package/packages/reactivity/src/computed.js +64 -0
- package/packages/reactivity/src/computed.js.map +1 -0
- package/packages/reactivity/src/computed.test.ts +83 -0
- package/packages/reactivity/src/computed.ts +69 -0
- package/packages/reactivity/src/index.d.ts +6 -0
- package/packages/reactivity/src/index.d.ts.map +1 -0
- package/packages/reactivity/src/index.js +7 -0
- package/packages/reactivity/src/index.js.map +1 -0
- package/packages/reactivity/src/index.ts +18 -0
- package/packages/reactivity/src/resource.d.ts +6 -0
- package/packages/reactivity/src/resource.d.ts.map +1 -0
- package/packages/reactivity/src/resource.js +43 -0
- package/packages/reactivity/src/resource.js.map +1 -0
- package/packages/reactivity/src/resource.test.ts +70 -0
- package/packages/reactivity/src/resource.ts +59 -0
- package/packages/reactivity/src/signal.d.ts +7 -0
- package/packages/reactivity/src/signal.d.ts.map +1 -0
- package/packages/reactivity/src/signal.js +145 -0
- package/packages/reactivity/src/signal.js.map +1 -0
- package/packages/reactivity/src/signal.test.ts +130 -0
- package/packages/reactivity/src/signal.ts +207 -0
- package/packages/reactivity/src/store.d.ts +4 -0
- package/packages/reactivity/src/store.d.ts.map +1 -0
- package/packages/reactivity/src/store.js +62 -0
- package/packages/reactivity/src/store.js.map +1 -0
- package/packages/reactivity/src/store.test.ts +38 -0
- package/packages/reactivity/src/store.ts +111 -0
- package/packages/reactivity/src/types.d.ts +43 -0
- package/packages/reactivity/src/types.d.ts.map +1 -0
- package/packages/reactivity/src/types.js +3 -0
- package/packages/reactivity/src/types.js.map +1 -0
- package/packages/reactivity/src/types.ts +43 -0
- package/packages/reactivity/tsconfig.json +9 -0
- package/packages/router/package.json +44 -0
- package/packages/router/src/components.tsx +150 -0
- package/packages/router/src/fs-router.ts +163 -0
- package/packages/router/src/index.ts +22 -0
- package/packages/router/src/router.test.ts +111 -0
- package/packages/router/src/router.ts +112 -0
- package/packages/router/src/types.ts +69 -0
- package/packages/router/tsconfig.json +10 -0
- package/packages/server/package.json +41 -0
- package/packages/server/src/action.test.ts +102 -0
- package/packages/server/src/action.ts +201 -0
- package/packages/server/src/api.ts +143 -0
- package/packages/server/src/index.ts +18 -0
- package/packages/server/src/types.ts +72 -0
- package/packages/server/tsconfig.json +9 -0
- package/pnpm-workspace.yaml +4 -0
- package/scripts/publish.ps1 +138 -0
- package/scripts/publish.sh +142 -0
- package/tsconfig.json +28 -0
- package/turbo.json +24 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zylaris Plugins System
|
|
3
|
+
* Use any JavaScript library with ease
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export type {
|
|
7
|
+
LibraryFormat,
|
|
8
|
+
LibrarySource,
|
|
9
|
+
CDNProvider,
|
|
10
|
+
PluginContext,
|
|
11
|
+
Transform,
|
|
12
|
+
LibraryConfig,
|
|
13
|
+
AutoImportConfig,
|
|
14
|
+
CDNOptions,
|
|
15
|
+
ExternalConfig,
|
|
16
|
+
ComponentAdapter,
|
|
17
|
+
WebComponentConfig,
|
|
18
|
+
Plugin,
|
|
19
|
+
ImportMap,
|
|
20
|
+
ImportMapEntry,
|
|
21
|
+
ResolveResult,
|
|
22
|
+
BundleAnalysis,
|
|
23
|
+
PluginPreset,
|
|
24
|
+
LoaderOptions,
|
|
25
|
+
RegistrySearchResult,
|
|
26
|
+
} from './types.js';
|
|
27
|
+
|
|
28
|
+
// Auto-import
|
|
29
|
+
export {
|
|
30
|
+
createAutoImport,
|
|
31
|
+
autoImportPresets,
|
|
32
|
+
createAutoImportFromDeps,
|
|
33
|
+
generateDTS,
|
|
34
|
+
} from './loaders/auto-import.js';
|
|
35
|
+
|
|
36
|
+
// CDN Loader
|
|
37
|
+
export {
|
|
38
|
+
generateCDNUrl,
|
|
39
|
+
createImportMap,
|
|
40
|
+
generateScriptTag,
|
|
41
|
+
generateImportMapScript,
|
|
42
|
+
resolveFromCDN,
|
|
43
|
+
CDNCache,
|
|
44
|
+
fetchModule,
|
|
45
|
+
transformImportsToCDN,
|
|
46
|
+
cdnPlugin,
|
|
47
|
+
} from './cdn/loader.js';
|
|
48
|
+
|
|
49
|
+
// External Dependencies
|
|
50
|
+
export {
|
|
51
|
+
prebundleDependencies,
|
|
52
|
+
generateOptimizedImportMap,
|
|
53
|
+
createExternalResolver,
|
|
54
|
+
DependencyGraph,
|
|
55
|
+
estimateBundleImpact,
|
|
56
|
+
} from './loaders/external.js';
|
|
57
|
+
|
|
58
|
+
// Transforms
|
|
59
|
+
export {
|
|
60
|
+
transformUMDToESM,
|
|
61
|
+
transformCJSToESM,
|
|
62
|
+
transformAMDToESM,
|
|
63
|
+
transformSystemJSToESM,
|
|
64
|
+
detectFormat,
|
|
65
|
+
autoTransformToESM,
|
|
66
|
+
reactAdapter,
|
|
67
|
+
vueAdapter,
|
|
68
|
+
svelteAdapter,
|
|
69
|
+
generateWebComponentWrapper,
|
|
70
|
+
optimizeImports,
|
|
71
|
+
treeShake,
|
|
72
|
+
} from './transforms/index.js';
|
|
73
|
+
|
|
74
|
+
import type { LoaderOptions, Plugin } from './types.js';
|
|
75
|
+
import { createAutoImport } from './loaders/auto-import.js';
|
|
76
|
+
import { cdnPlugin } from './cdn/loader.js';
|
|
77
|
+
import { createExternalResolver } from './loaders/external.js';
|
|
78
|
+
|
|
79
|
+
/** Create plugin system */
|
|
80
|
+
export function createPluginSystem(options: LoaderOptions = {}): Plugin[] {
|
|
81
|
+
const plugins: Plugin[] = [];
|
|
82
|
+
|
|
83
|
+
// Auto-import plugin
|
|
84
|
+
if (options.autoImports && options.autoImports.length > 0) {
|
|
85
|
+
plugins.push({
|
|
86
|
+
name: 'auto-import',
|
|
87
|
+
transform: createAutoImport(options.autoImports),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// CDN plugin
|
|
92
|
+
if (options.cdn && options.libraries) {
|
|
93
|
+
plugins.push({
|
|
94
|
+
name: 'cdn-loader',
|
|
95
|
+
configureBuild: (buildOptions) => {
|
|
96
|
+
const cdn = cdnPlugin(options.libraries!, options.cdn);
|
|
97
|
+
// Add to esbuild plugins
|
|
98
|
+
return {
|
|
99
|
+
...buildOptions,
|
|
100
|
+
plugins: [...(buildOptions.plugins || []), cdn],
|
|
101
|
+
};
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// External resolver
|
|
107
|
+
if (options.external) {
|
|
108
|
+
const isExternal = createExternalResolver(options.external);
|
|
109
|
+
plugins.push({
|
|
110
|
+
name: 'external-resolver',
|
|
111
|
+
resolveId: (id: string): string | null => {
|
|
112
|
+
if (isExternal(id)) {
|
|
113
|
+
return id;
|
|
114
|
+
}
|
|
115
|
+
return null;
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Custom transforms
|
|
121
|
+
if (options.transforms) {
|
|
122
|
+
for (const transform of options.transforms) {
|
|
123
|
+
plugins.push({
|
|
124
|
+
name: transform.name,
|
|
125
|
+
transform,
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return plugins;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** Plugin presets */
|
|
134
|
+
export const presets = {
|
|
135
|
+
/** React integration */
|
|
136
|
+
react: (): LoaderOptions => ({
|
|
137
|
+
autoImports: [
|
|
138
|
+
{
|
|
139
|
+
from: 'react',
|
|
140
|
+
imports: ['useState', 'useEffect', 'useCallback', 'useMemo'],
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
adapters: [
|
|
144
|
+
{
|
|
145
|
+
framework: 'react',
|
|
146
|
+
transform: (code: string) => code,
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
}),
|
|
150
|
+
|
|
151
|
+
/** Vue integration */
|
|
152
|
+
vue: (): LoaderOptions => ({
|
|
153
|
+
autoImports: [
|
|
154
|
+
{
|
|
155
|
+
from: 'vue',
|
|
156
|
+
imports: ['ref', 'reactive', 'computed', 'watch', 'onMounted'],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
adapters: [
|
|
160
|
+
{
|
|
161
|
+
framework: 'vue',
|
|
162
|
+
transform: (code: string) => code,
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
}),
|
|
166
|
+
|
|
167
|
+
/** CDN-only mode */
|
|
168
|
+
cdn: (libraries: string[]): LoaderOptions => ({
|
|
169
|
+
cdn: {
|
|
170
|
+
provider: 'esm.sh',
|
|
171
|
+
},
|
|
172
|
+
libraries: libraries.map(name => ({
|
|
173
|
+
name,
|
|
174
|
+
source: 'cdn',
|
|
175
|
+
})),
|
|
176
|
+
external: {
|
|
177
|
+
external: libraries,
|
|
178
|
+
},
|
|
179
|
+
}),
|
|
180
|
+
|
|
181
|
+
/** Zero-config defaults */
|
|
182
|
+
recommended: (): LoaderOptions => ({
|
|
183
|
+
autoImports: [
|
|
184
|
+
{
|
|
185
|
+
from: 'zylaris',
|
|
186
|
+
imports: ['signal', 'computed', 'createEffect', 'Show', 'For'],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
cdn: {
|
|
190
|
+
provider: 'esm.sh',
|
|
191
|
+
},
|
|
192
|
+
external: {
|
|
193
|
+
prebundle: [],
|
|
194
|
+
},
|
|
195
|
+
}),
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
/** Helper to use any library */
|
|
199
|
+
export async function useLibrary(
|
|
200
|
+
name: string,
|
|
201
|
+
options: {
|
|
202
|
+
from?: 'npm' | 'cdn';
|
|
203
|
+
cdn?: import('./types.js').CDNProvider;
|
|
204
|
+
version?: string;
|
|
205
|
+
} = {}
|
|
206
|
+
): Promise<unknown> {
|
|
207
|
+
const { from = 'npm' } = options;
|
|
208
|
+
|
|
209
|
+
if (from === 'cdn') {
|
|
210
|
+
const { generateCDNUrl, fetchModule } = await import('./cdn/loader.js');
|
|
211
|
+
const url = generateCDNUrl(name, {
|
|
212
|
+
provider: options.cdn || 'esm.sh',
|
|
213
|
+
version: options.version,
|
|
214
|
+
});
|
|
215
|
+
const module = await fetchModule(url);
|
|
216
|
+
|
|
217
|
+
// Create data URL for dynamic import
|
|
218
|
+
const blob = new Blob([module], { type: 'application/javascript' });
|
|
219
|
+
const dataUrl = URL.createObjectURL(blob);
|
|
220
|
+
|
|
221
|
+
return import(dataUrl);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
// NPM import
|
|
225
|
+
return import(name);
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Define plugin configuration */
|
|
229
|
+
export function definePlugins(options: LoaderOptions): LoaderOptions {
|
|
230
|
+
return options;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export default {
|
|
234
|
+
createPluginSystem,
|
|
235
|
+
presets,
|
|
236
|
+
useLibrary,
|
|
237
|
+
definePlugins,
|
|
238
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Auto-Import System
|
|
3
|
+
* Automatically import libraries without manual import statements
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createUnimport, type Import } from 'unimport';
|
|
7
|
+
import type { AutoImportConfig, Transform } from '../types.js';
|
|
8
|
+
|
|
9
|
+
/** Create auto-import transform */
|
|
10
|
+
export function createAutoImport(config: AutoImportConfig[]): Transform {
|
|
11
|
+
const unimports: Import[] = [];
|
|
12
|
+
|
|
13
|
+
for (const item of config) {
|
|
14
|
+
// Named imports
|
|
15
|
+
if (item.imports) {
|
|
16
|
+
for (const name of item.imports) {
|
|
17
|
+
unimports.push({
|
|
18
|
+
name,
|
|
19
|
+
from: item.from,
|
|
20
|
+
as: name,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Default import
|
|
26
|
+
if (item.defaultImport) {
|
|
27
|
+
unimports.push({
|
|
28
|
+
name: 'default',
|
|
29
|
+
from: item.from,
|
|
30
|
+
as: item.defaultImport,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Namespace import
|
|
35
|
+
if (item.namespaceImport) {
|
|
36
|
+
unimports.push({
|
|
37
|
+
name: '*',
|
|
38
|
+
from: item.from,
|
|
39
|
+
as: item.namespaceImport,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
name: 'auto-import',
|
|
46
|
+
test: (id: string) => {
|
|
47
|
+
// Apply to JS/TS files only
|
|
48
|
+
return /\.(tsx?|jsx?|mjs|vue|svelte)$/.test(id);
|
|
49
|
+
},
|
|
50
|
+
handler: async (code: string, id: string) => {
|
|
51
|
+
const ctx = createUnimport({
|
|
52
|
+
imports: unimports,
|
|
53
|
+
presets: [
|
|
54
|
+
{
|
|
55
|
+
from: 'zylaris',
|
|
56
|
+
imports: ['signal', 'computed', 'createEffect', 'batch'],
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
await ctx.init();
|
|
62
|
+
const result = await ctx.injectImports(code, id);
|
|
63
|
+
return result.code || code;
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Preset configurations for popular libraries */
|
|
69
|
+
export const autoImportPresets = {
|
|
70
|
+
/** Vue 3 Composition API */
|
|
71
|
+
vue: (): AutoImportConfig[] => [
|
|
72
|
+
{
|
|
73
|
+
from: 'vue',
|
|
74
|
+
imports: [
|
|
75
|
+
'ref', 'reactive', 'computed', 'watch', 'watchEffect',
|
|
76
|
+
'onMounted', 'onUnmounted', 'onUpdated',
|
|
77
|
+
'provide', 'inject', 'useSlots', 'useAttrs'
|
|
78
|
+
],
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
|
|
82
|
+
/** React hooks */
|
|
83
|
+
react: (): AutoImportConfig[] => [
|
|
84
|
+
{
|
|
85
|
+
from: 'react',
|
|
86
|
+
imports: [
|
|
87
|
+
'useState', 'useEffect', 'useCallback', 'useMemo',
|
|
88
|
+
'useRef', 'useContext', 'useReducer', 'useLayoutEffect'
|
|
89
|
+
],
|
|
90
|
+
},
|
|
91
|
+
],
|
|
92
|
+
|
|
93
|
+
/** SolidJS primitives */
|
|
94
|
+
solid: (): AutoImportConfig[] => [
|
|
95
|
+
{
|
|
96
|
+
from: 'solid-js',
|
|
97
|
+
imports: [
|
|
98
|
+
'createSignal', 'createEffect', 'createMemo', 'createResource',
|
|
99
|
+
'onMount', 'onCleanup', 'useContext'
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
|
|
104
|
+
/** Zylaris framework */
|
|
105
|
+
zylaris: (): AutoImportConfig[] => [
|
|
106
|
+
{
|
|
107
|
+
from: 'zylaris',
|
|
108
|
+
imports: [
|
|
109
|
+
'signal', 'computed', 'resource', 'createEffect', 'batch',
|
|
110
|
+
'Show', 'For', 'Switch', 'Match', 'Suspense'
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
|
|
115
|
+
/** Utility libraries */
|
|
116
|
+
lodash: (): AutoImportConfig[] => [
|
|
117
|
+
{
|
|
118
|
+
from: 'lodash-es',
|
|
119
|
+
imports: [
|
|
120
|
+
'debounce', 'throttle', 'cloneDeep', 'merge', 'omit', 'pick',
|
|
121
|
+
'groupBy', 'orderBy', 'uniqueId', 'isEqual', 'isEmpty'
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
|
|
126
|
+
/** Date utilities */
|
|
127
|
+
date: (): AutoImportConfig[] => [
|
|
128
|
+
{
|
|
129
|
+
from: 'date-fns',
|
|
130
|
+
imports: [
|
|
131
|
+
'format', 'parseISO', 'addDays', 'subDays', 'isBefore', 'isAfter'
|
|
132
|
+
],
|
|
133
|
+
},
|
|
134
|
+
],
|
|
135
|
+
|
|
136
|
+
/** Validation */
|
|
137
|
+
zod: (): AutoImportConfig[] => [
|
|
138
|
+
{
|
|
139
|
+
from: 'zod',
|
|
140
|
+
imports: ['z'],
|
|
141
|
+
defaultImport: 'z',
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
|
|
145
|
+
/** All common utils */
|
|
146
|
+
utils: (): AutoImportConfig[] => [
|
|
147
|
+
...autoImportPresets.lodash(),
|
|
148
|
+
...autoImportPresets.date(),
|
|
149
|
+
],
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/** Create auto-import from package.json dependencies */
|
|
153
|
+
export async function createAutoImportFromDeps(
|
|
154
|
+
packageJsonPath: string = 'package.json'
|
|
155
|
+
): Promise<AutoImportConfig[]> {
|
|
156
|
+
const fs = await import('fs/promises');
|
|
157
|
+
|
|
158
|
+
try {
|
|
159
|
+
const content = await fs.readFile(packageJsonPath, 'utf-8');
|
|
160
|
+
const pkg = JSON.parse(content);
|
|
161
|
+
const deps = { ...pkg.dependencies, ...pkg.devDependencies };
|
|
162
|
+
const configs: AutoImportConfig[] = [];
|
|
163
|
+
|
|
164
|
+
for (const [name] of Object.entries(deps)) {
|
|
165
|
+
// Check if we have a preset for this package
|
|
166
|
+
const preset = findPresetForPackage(name);
|
|
167
|
+
if (preset) {
|
|
168
|
+
configs.push(...preset());
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return configs;
|
|
173
|
+
} catch {
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Find preset for package */
|
|
179
|
+
function findPresetForPackage(name: string): (() => AutoImportConfig[]) | null {
|
|
180
|
+
const presetMap: Record<string, () => AutoImportConfig[]> = {
|
|
181
|
+
'vue': autoImportPresets.vue,
|
|
182
|
+
'react': autoImportPresets.react,
|
|
183
|
+
'solid-js': autoImportPresets.solid,
|
|
184
|
+
'zylaris': autoImportPresets.zylaris,
|
|
185
|
+
'lodash-es': autoImportPresets.lodash,
|
|
186
|
+
'date-fns': autoImportPresets.date,
|
|
187
|
+
'zod': autoImportPresets.zod,
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return presetMap[name] || null;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Generate TypeScript declarations for auto-imports */
|
|
194
|
+
export function generateDTS(configs: AutoImportConfig[]): string {
|
|
195
|
+
const lines: string[] = [];
|
|
196
|
+
|
|
197
|
+
for (const config of configs) {
|
|
198
|
+
if (config.imports) {
|
|
199
|
+
for (const name of config.imports) {
|
|
200
|
+
lines.push(` const ${name}: typeof import('${config.from}')['${name}']`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
if (config.defaultImport) {
|
|
204
|
+
lines.push(` const ${config.defaultImport}: typeof import('${config.from}')['default']`);
|
|
205
|
+
}
|
|
206
|
+
if (config.namespaceImport) {
|
|
207
|
+
lines.push(` const ${config.namespaceImport}: typeof import('${config.from}')`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return `// Auto-generated by @zylaris/plugins
|
|
212
|
+
export {}
|
|
213
|
+
declare global {
|
|
214
|
+
${lines.join('\n')}
|
|
215
|
+
}
|
|
216
|
+
`;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export default createAutoImport;
|