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,407 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Library Transformers
|
|
3
|
+
* Transform various library formats to work with Zylaris
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { LibraryFormat, ComponentAdapter } from '../types.js';
|
|
7
|
+
import MagicString from 'magic-string';
|
|
8
|
+
|
|
9
|
+
/** Transform UMD/IIFE to ESM */
|
|
10
|
+
export function transformUMDToESM(code: string, globalName: string): string {
|
|
11
|
+
// Check if already ESM
|
|
12
|
+
if (code.includes('export ') || code.includes('import ')) {
|
|
13
|
+
return code;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const s = new MagicString(code);
|
|
17
|
+
|
|
18
|
+
// Detect UMD pattern
|
|
19
|
+
if (code.includes('typeof define') && code.includes('amd')) {
|
|
20
|
+
// AMD/UMD wrapper
|
|
21
|
+
s.append(`\nexport default ${globalName};`);
|
|
22
|
+
s.append(`\nexport { ${globalName} };`);
|
|
23
|
+
} else if (code.includes('module.exports')) {
|
|
24
|
+
// CommonJS
|
|
25
|
+
s.replace(/module\.exports\s*=\s*/, 'export default ');
|
|
26
|
+
s.replace(/exports\.(\w+)\s*=\s*/g, 'export const $1 = ');
|
|
27
|
+
s.replace(/require\(['"]([^'"]+)['"]\)/g, "import('$1')");
|
|
28
|
+
} else if (code.includes('(function (global')) {
|
|
29
|
+
// IIFE
|
|
30
|
+
s.append(`\nexport default ${globalName};`);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return s.toString();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** Transform CJS to ESM */
|
|
37
|
+
export function transformCJSToESM(code: string): string {
|
|
38
|
+
const s = new MagicString(code);
|
|
39
|
+
|
|
40
|
+
// Transform require() to import
|
|
41
|
+
const requireRegex = /(?:const|let|var)\s+(\{?[^}]+}?)\s*=\s*require\(['"]([^'"]+)['"]\);?/g;
|
|
42
|
+
|
|
43
|
+
s.replace(requireRegex, (_match, bindings, source) => {
|
|
44
|
+
if (bindings.startsWith('{')) {
|
|
45
|
+
// Destructured: const { a, b } = require('x')
|
|
46
|
+
return `import ${bindings} from '${source}';`;
|
|
47
|
+
}
|
|
48
|
+
// Default: const x = require('x')
|
|
49
|
+
return `import ${bindings} from '${source}';`;
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
// Transform module.exports
|
|
53
|
+
s.replace(/module\.exports\s*=\s*/, 'export default ');
|
|
54
|
+
s.replace(/module\.exports\.(\w+)\s*=\s*/g, 'export const $1 = ');
|
|
55
|
+
|
|
56
|
+
// Transform exports.x
|
|
57
|
+
s.replace(/exports\.(\w+)\s*=\s*/g, 'export const $1 = ');
|
|
58
|
+
|
|
59
|
+
// Transform __dirname and __filename
|
|
60
|
+
s.replace(/__dirname/g, "new URL('.', import.meta.url).pathname");
|
|
61
|
+
s.replace(/__filename/g, "new URL(import.meta.url).pathname");
|
|
62
|
+
|
|
63
|
+
return s.toString();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** Transform AMD to ESM */
|
|
67
|
+
export function transformAMDToESM(code: string): string {
|
|
68
|
+
const s = new MagicString(code);
|
|
69
|
+
|
|
70
|
+
// Detect define() calls
|
|
71
|
+
const defineRegex = /define\((?:\[[^\]]*\],\s*)?function\s*\([^)]*\)\s*\{/;
|
|
72
|
+
|
|
73
|
+
if (defineRegex.test(code)) {
|
|
74
|
+
// Extract dependencies and factory
|
|
75
|
+
const depsMatch = code.match(/define\(\[([^\]]*)\]/);
|
|
76
|
+
const factoryMatch = code.match(/function\s*\(([^)]*)\)/);
|
|
77
|
+
|
|
78
|
+
if (depsMatch && factoryMatch) {
|
|
79
|
+
const deps = depsMatch[1].split(',').map(d => d.trim().replace(/['"]/g, ''));
|
|
80
|
+
const params = factoryMatch[1].split(',').map(p => p.trim());
|
|
81
|
+
|
|
82
|
+
// Generate imports
|
|
83
|
+
let imports = '';
|
|
84
|
+
deps.forEach((dep, i) => {
|
|
85
|
+
if (dep) {
|
|
86
|
+
const param = params[i] || `_${i}`;
|
|
87
|
+
imports += `import ${param} from '${dep}';\n`;
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
s.replace(/define\([^)]*\)\s*\{/, imports + 'export default (function() {');
|
|
92
|
+
s.append('})();');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return s.toString();
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/** Transform SystemJS to ESM */
|
|
100
|
+
export function transformSystemJSToESM(code: string): string {
|
|
101
|
+
const s = new MagicString(code);
|
|
102
|
+
|
|
103
|
+
// System.register pattern
|
|
104
|
+
s.replace(/System\.register\(\[[^\]]*\],\s*function\s*\([^)]*\)\s*\{/, 'export default (function() {');
|
|
105
|
+
|
|
106
|
+
// Transform setters and execute
|
|
107
|
+
s.replace(/setters:\s*\[[^\]]*\],/, '');
|
|
108
|
+
s.replace(/execute:\s*function\(\)\s*\{/, '');
|
|
109
|
+
|
|
110
|
+
return s.toString();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Detect library format */
|
|
114
|
+
export function detectFormat(code: string): LibraryFormat {
|
|
115
|
+
// Check for ESM
|
|
116
|
+
if (/^\s*(import|export)\s/m.test(code)) {
|
|
117
|
+
return 'esm';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// Check for CommonJS
|
|
121
|
+
if (code.includes('module.exports') || code.includes('require(')) {
|
|
122
|
+
return 'cjs';
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Check for AMD
|
|
126
|
+
if (code.includes('define(') && code.includes('function')) {
|
|
127
|
+
return 'amd';
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Check for SystemJS
|
|
131
|
+
if (code.includes('System.register')) {
|
|
132
|
+
return 'systemjs';
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Check for UMD (has factory function with global check)
|
|
136
|
+
if (code.includes('typeof exports') && code.includes('typeof define')) {
|
|
137
|
+
return 'umd';
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Check for IIFE
|
|
141
|
+
if (/\(function\s*\([^)]*\)\s*\{/.test(code)) {
|
|
142
|
+
return 'iife';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// Default to ESM
|
|
146
|
+
return 'esm';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Auto-transform to ESM */
|
|
150
|
+
export function autoTransformToESM(code: string, globalName?: string): string {
|
|
151
|
+
const format = detectFormat(code);
|
|
152
|
+
|
|
153
|
+
switch (format) {
|
|
154
|
+
case 'cjs':
|
|
155
|
+
return transformCJSToESM(code);
|
|
156
|
+
case 'umd':
|
|
157
|
+
return transformUMDToESM(code, globalName || 'globalThis');
|
|
158
|
+
case 'amd':
|
|
159
|
+
return transformAMDToESM(code);
|
|
160
|
+
case 'systemjs':
|
|
161
|
+
return transformSystemJSToESM(code);
|
|
162
|
+
case 'iife':
|
|
163
|
+
return transformUMDToESM(code, globalName || 'globalThis');
|
|
164
|
+
default:
|
|
165
|
+
return code;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/** React component adapter */
|
|
170
|
+
export const reactAdapter: ComponentAdapter = {
|
|
171
|
+
framework: 'react',
|
|
172
|
+
transform: (_component: string, from: string) => {
|
|
173
|
+
return `
|
|
174
|
+
import React from 'react';
|
|
175
|
+
import ReactDOM from 'react-dom/client';
|
|
176
|
+
import Component from '${from}';
|
|
177
|
+
|
|
178
|
+
export default function ZylarisReactWrapper(props) {
|
|
179
|
+
const containerRef = useRef(null);
|
|
180
|
+
|
|
181
|
+
useEffect(() => {
|
|
182
|
+
if (containerRef.current) {
|
|
183
|
+
const root = ReactDOM.createRoot(containerRef.current);
|
|
184
|
+
root.render(<Component {...props} />);
|
|
185
|
+
return () => root.unmount();
|
|
186
|
+
}
|
|
187
|
+
}, [props]);
|
|
188
|
+
|
|
189
|
+
return <div ref={containerRef} />;
|
|
190
|
+
}
|
|
191
|
+
`;
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
/** Vue component adapter */
|
|
196
|
+
export const vueAdapter: ComponentAdapter = {
|
|
197
|
+
framework: 'vue',
|
|
198
|
+
transform: (_component: string, from: string) => {
|
|
199
|
+
return `
|
|
200
|
+
import { defineComponent, h, ref, onMounted, onUnmounted } from 'vue';
|
|
201
|
+
import VueComponent from '${from}';
|
|
202
|
+
import { createApp } from 'vue';
|
|
203
|
+
|
|
204
|
+
export default defineComponent({
|
|
205
|
+
name: 'ZylarisVueWrapper',
|
|
206
|
+
props: VueComponent.props || {},
|
|
207
|
+
setup(props, { slots }) {
|
|
208
|
+
const container = ref(null);
|
|
209
|
+
let app = null;
|
|
210
|
+
|
|
211
|
+
onMounted(() => {
|
|
212
|
+
if (container.value) {
|
|
213
|
+
app = createApp({
|
|
214
|
+
render: () => h(VueComponent, props, slots)
|
|
215
|
+
});
|
|
216
|
+
app.mount(container.value);
|
|
217
|
+
}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
onUnmounted(() => {
|
|
221
|
+
app?.unmount();
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
return () => h('div', { ref: container });
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
`;
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
/** Svelte component adapter */
|
|
232
|
+
export const svelteAdapter: ComponentAdapter = {
|
|
233
|
+
framework: 'svelte',
|
|
234
|
+
transform: (_component: string, from: string) => {
|
|
235
|
+
return `
|
|
236
|
+
import SvelteComponent from '${from}';
|
|
237
|
+
import { signal, createEffect } from 'zylaris';
|
|
238
|
+
|
|
239
|
+
export default function ZylarisSvelteWrapper(props) {
|
|
240
|
+
const container = signal(null);
|
|
241
|
+
let component = null;
|
|
242
|
+
|
|
243
|
+
createEffect(() => {
|
|
244
|
+
if (container()) {
|
|
245
|
+
component = new SvelteComponent({
|
|
246
|
+
target: container(),
|
|
247
|
+
props: props
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return () => {
|
|
252
|
+
component?.$destroy();
|
|
253
|
+
};
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
return <div ref={container} />;
|
|
257
|
+
}
|
|
258
|
+
`;
|
|
259
|
+
},
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/** Web Component wrapper generator */
|
|
263
|
+
export function generateWebComponentWrapper(
|
|
264
|
+
tagName: string,
|
|
265
|
+
path: string,
|
|
266
|
+
props: Record<string, string> = {}
|
|
267
|
+
): string {
|
|
268
|
+
const propDefs = Object.entries(props)
|
|
269
|
+
.map(([key, type]) => ` ${key}?: ${type};`)
|
|
270
|
+
.join('\n');
|
|
271
|
+
|
|
272
|
+
return `
|
|
273
|
+
import type { JSX } from 'zylaris';
|
|
274
|
+
|
|
275
|
+
declare module 'zylaris' {
|
|
276
|
+
namespace JSX {
|
|
277
|
+
interface IntrinsicElements {
|
|
278
|
+
'${tagName}': {
|
|
279
|
+
${propDefs}
|
|
280
|
+
children?: JSX.Element;
|
|
281
|
+
} & JSX.HTMLAttributes<HTMLElement>;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Lazy load web component
|
|
287
|
+
export async function load${toPascalCase(tagName)}() {
|
|
288
|
+
await import('${path}');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Wrapper component
|
|
292
|
+
export function ${toPascalCase(tagName)}(props: {
|
|
293
|
+
${propDefs}
|
|
294
|
+
children?: any
|
|
295
|
+
}) {
|
|
296
|
+
const Tag = '${tagName}' as any;
|
|
297
|
+
return <Tag {...props} />;
|
|
298
|
+
}
|
|
299
|
+
`;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** Convert kebab-case to PascalCase */
|
|
303
|
+
function toPascalCase(str: string): string {
|
|
304
|
+
return str
|
|
305
|
+
.split('-')
|
|
306
|
+
.map(part => part.charAt(0).toUpperCase() + part.slice(1))
|
|
307
|
+
.join('');
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** Transform imports for tree-shaking */
|
|
311
|
+
export function optimizeImports(
|
|
312
|
+
code: string,
|
|
313
|
+
library: string,
|
|
314
|
+
imports: string[]
|
|
315
|
+
): string {
|
|
316
|
+
const s = new MagicString(code);
|
|
317
|
+
|
|
318
|
+
// Replace default import with named imports
|
|
319
|
+
const defaultImportRegex = new RegExp(
|
|
320
|
+
`import\\s+(\\w+)\\s+from\\s+['"]${library}['"];?`,
|
|
321
|
+
'g'
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
s.replace(defaultImportRegex, () => {
|
|
325
|
+
return `import { ${imports.join(', ')} } from '${library}';`;
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
// Replace usage of default import with named imports
|
|
329
|
+
imports.forEach(name => {
|
|
330
|
+
s.replace(new RegExp(`\\b${library}\\.${name}\\b`, 'g'), name);
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
return s.toString();
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Remove dead code from library */
|
|
337
|
+
export function treeShake(code: string, usedExports: string[]): string {
|
|
338
|
+
const s = new MagicString(code);
|
|
339
|
+
|
|
340
|
+
// Mark unused exports for removal
|
|
341
|
+
const exportRegex = /export\s+(?:const|let|var|function|class)\s+(\w+)/g;
|
|
342
|
+
let match;
|
|
343
|
+
|
|
344
|
+
while ((match = exportRegex.exec(code)) !== null) {
|
|
345
|
+
const exportName = match[1];
|
|
346
|
+
if (!usedExports.includes(exportName)) {
|
|
347
|
+
// Find and remove the export
|
|
348
|
+
const start = match.index;
|
|
349
|
+
const end = findStatementEnd(code, start);
|
|
350
|
+
s.remove(start, end);
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
return s.toString();
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/** Find end of statement */
|
|
358
|
+
function findStatementEnd(code: string, start: number): number {
|
|
359
|
+
let depth = 0;
|
|
360
|
+
let inString = false;
|
|
361
|
+
let stringChar = '';
|
|
362
|
+
|
|
363
|
+
for (let i = start; i < code.length; i++) {
|
|
364
|
+
const char = code[i];
|
|
365
|
+
const prev = code[i - 1];
|
|
366
|
+
|
|
367
|
+
if (inString) {
|
|
368
|
+
if (char === stringChar && prev !== '\\') {
|
|
369
|
+
inString = false;
|
|
370
|
+
}
|
|
371
|
+
} else {
|
|
372
|
+
if (char === '"' || char === "'" || char === '`') {
|
|
373
|
+
inString = true;
|
|
374
|
+
stringChar = char;
|
|
375
|
+
} else if (char === '{' || char === '(' || char === '[') {
|
|
376
|
+
depth++;
|
|
377
|
+
} else if (char === '}' || char === ')' || char === ']') {
|
|
378
|
+
depth--;
|
|
379
|
+
} else if (char === ';' && depth === 0) {
|
|
380
|
+
return i + 1;
|
|
381
|
+
} else if (char === '\n' && depth === 0) {
|
|
382
|
+
// Check if next line is not a continuation
|
|
383
|
+
const nextLine = code.slice(i + 1).trim();
|
|
384
|
+
if (!nextLine.startsWith('.') && !nextLine.startsWith('}')) {
|
|
385
|
+
return i + 1;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return code.length;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export default {
|
|
395
|
+
transformUMDToESM,
|
|
396
|
+
transformCJSToESM,
|
|
397
|
+
transformAMDToESM,
|
|
398
|
+
transformSystemJSToESM,
|
|
399
|
+
detectFormat,
|
|
400
|
+
autoTransformToESM,
|
|
401
|
+
reactAdapter,
|
|
402
|
+
vueAdapter,
|
|
403
|
+
svelteAdapter,
|
|
404
|
+
generateWebComponentWrapper,
|
|
405
|
+
optimizeImports,
|
|
406
|
+
treeShake,
|
|
407
|
+
};
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Plugin System Types
|
|
3
|
+
* Supports: npm packages, CDN libraries, framework components, Web Components
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/** Library format types */
|
|
8
|
+
export type LibraryFormat =
|
|
9
|
+
| 'esm' // ES Modules
|
|
10
|
+
| 'cjs' // CommonJS
|
|
11
|
+
| 'umd' // Universal Module Definition
|
|
12
|
+
| 'iife' // Immediately Invoked Function Expression
|
|
13
|
+
| 'amd' // Asynchronous Module Definition
|
|
14
|
+
| 'systemjs'; // SystemJS
|
|
15
|
+
|
|
16
|
+
/** Source of library */
|
|
17
|
+
export type LibrarySource =
|
|
18
|
+
| 'npm' // npm registry
|
|
19
|
+
| 'cdn' // CDN (esm.sh, unpkg, skypack, etc.)
|
|
20
|
+
| 'local' // Local file
|
|
21
|
+
| 'github'; // GitHub raw
|
|
22
|
+
|
|
23
|
+
/** Build options interface (subset of esbuild.BuildOptions) */
|
|
24
|
+
export interface BuildOptions {
|
|
25
|
+
/** Entry points */
|
|
26
|
+
entryPoints?: string[];
|
|
27
|
+
/** Bundle output */
|
|
28
|
+
bundle?: boolean;
|
|
29
|
+
/** Output format */
|
|
30
|
+
format?: 'iife' | 'cjs' | 'esm';
|
|
31
|
+
/** Output file */
|
|
32
|
+
outfile?: string;
|
|
33
|
+
/** Platform */
|
|
34
|
+
platform?: 'browser' | 'node' | 'neutral';
|
|
35
|
+
/** Target */
|
|
36
|
+
target?: string;
|
|
37
|
+
/** Minify output */
|
|
38
|
+
minify?: boolean;
|
|
39
|
+
/** Generate sourcemap */
|
|
40
|
+
sourcemap?: boolean;
|
|
41
|
+
/** Metafile output */
|
|
42
|
+
metafile?: boolean;
|
|
43
|
+
/** External dependencies */
|
|
44
|
+
external?: string[];
|
|
45
|
+
/** Define replacements */
|
|
46
|
+
define?: Record<string, string>;
|
|
47
|
+
/** Plugins */
|
|
48
|
+
plugins?: unknown[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** CDN Provider */
|
|
52
|
+
export type CDNProvider =
|
|
53
|
+
| 'esm.sh'
|
|
54
|
+
| 'unpkg'
|
|
55
|
+
| 'skypack'
|
|
56
|
+
| 'jspm'
|
|
57
|
+
| 'jsdelivr'
|
|
58
|
+
| 'cdnjs';
|
|
59
|
+
|
|
60
|
+
/** Plugin hook context */
|
|
61
|
+
export interface PluginContext {
|
|
62
|
+
/** Root directory */
|
|
63
|
+
root: string;
|
|
64
|
+
/** Mode: development | production */
|
|
65
|
+
mode: 'development' | 'production';
|
|
66
|
+
/** Environment */
|
|
67
|
+
env: Record<string, string>;
|
|
68
|
+
/** Add external dependency */
|
|
69
|
+
addExternal: (id: string) => void;
|
|
70
|
+
/** Add alias */
|
|
71
|
+
addAlias: (from: string, to: string) => void;
|
|
72
|
+
/** Add transform */
|
|
73
|
+
addTransform: (transform: Transform) => void;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** Transform function */
|
|
77
|
+
export interface Transform {
|
|
78
|
+
/** Transform name */
|
|
79
|
+
name: string;
|
|
80
|
+
/** Test if file should be transformed */
|
|
81
|
+
test: (id: string) => boolean;
|
|
82
|
+
/** Transform handler */
|
|
83
|
+
handler: (code: string, id: string) => Promise<string> | string;
|
|
84
|
+
/** Execution order */
|
|
85
|
+
order?: 'pre' | 'post' | 'normal';
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** Library configuration */
|
|
89
|
+
export interface LibraryConfig {
|
|
90
|
+
/** Library name */
|
|
91
|
+
name: string;
|
|
92
|
+
/** Source */
|
|
93
|
+
source?: LibrarySource;
|
|
94
|
+
/** CDN Provider (if source is cdn) */
|
|
95
|
+
cdn?: CDNProvider;
|
|
96
|
+
/** Version */
|
|
97
|
+
version?: string;
|
|
98
|
+
/** Global variable name (for UMD/IIFE) */
|
|
99
|
+
global?: string;
|
|
100
|
+
/** Entry point */
|
|
101
|
+
entry?: string;
|
|
102
|
+
/** Format */
|
|
103
|
+
format?: LibraryFormat;
|
|
104
|
+
/** Whether to bundle */
|
|
105
|
+
bundle?: boolean;
|
|
106
|
+
/** Side effects */
|
|
107
|
+
sideEffects?: boolean | string[];
|
|
108
|
+
/** CSS to include */
|
|
109
|
+
css?: string | string[];
|
|
110
|
+
/** Auto-import presets */
|
|
111
|
+
autoImport?: AutoImportConfig;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Auto-import configuration */
|
|
115
|
+
export interface AutoImportConfig {
|
|
116
|
+
/** Package name */
|
|
117
|
+
from: string;
|
|
118
|
+
/** Named exports to auto-import */
|
|
119
|
+
imports?: string[];
|
|
120
|
+
/** Default export name */
|
|
121
|
+
defaultImport?: string;
|
|
122
|
+
/** Namespace import */
|
|
123
|
+
namespaceImport?: string;
|
|
124
|
+
/** File patterns to apply */
|
|
125
|
+
include?: string[];
|
|
126
|
+
/** File patterns to exclude */
|
|
127
|
+
exclude?: string[];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** CDN Loader options */
|
|
131
|
+
export interface CDNOptions {
|
|
132
|
+
/** Default CDN provider */
|
|
133
|
+
provider?: CDNProvider;
|
|
134
|
+
/** Version pinning */
|
|
135
|
+
version?: string;
|
|
136
|
+
/** Query parameters */
|
|
137
|
+
query?: Record<string, string>;
|
|
138
|
+
/** Dependencies to bundle */
|
|
139
|
+
deps?: string[];
|
|
140
|
+
/** Whether to minify */
|
|
141
|
+
minify?: boolean;
|
|
142
|
+
/** Target */
|
|
143
|
+
target?: string;
|
|
144
|
+
/** Whether to use bare imports */
|
|
145
|
+
bare?: boolean;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** External dependency optimization */
|
|
149
|
+
export interface ExternalConfig {
|
|
150
|
+
/** Dependencies to externalize */
|
|
151
|
+
external?: string[] | RegExp[];
|
|
152
|
+
/** Dependencies to pre-bundle */
|
|
153
|
+
prebundle?: string[];
|
|
154
|
+
/** Force include (don't externalize) */
|
|
155
|
+
forceInclude?: string[];
|
|
156
|
+
/** CDN URL for externals */
|
|
157
|
+
cdn?: CDNOptions;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** Component library adapter */
|
|
161
|
+
export interface ComponentAdapter {
|
|
162
|
+
/** Framework name */
|
|
163
|
+
framework: 'react' | 'vue' | 'svelte' | 'solid' | 'preact' | 'alpine';
|
|
164
|
+
/** Transform component to Zylaris format */
|
|
165
|
+
transform: (component: string, from: string) => string;
|
|
166
|
+
/** Wrap component for hydration */
|
|
167
|
+
wrap?: (component: string, props?: Record<string, unknown>) => string;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** Web Component config */
|
|
171
|
+
export interface WebComponentConfig {
|
|
172
|
+
/** Tag name */
|
|
173
|
+
tag: string;
|
|
174
|
+
/** Component path */
|
|
175
|
+
path: string;
|
|
176
|
+
/** Whether to lazy load */
|
|
177
|
+
lazy?: boolean;
|
|
178
|
+
/** Props mapping */
|
|
179
|
+
props?: Record<string, string>;
|
|
180
|
+
/** Slots mapping */
|
|
181
|
+
slots?: Record<string, string>;
|
|
182
|
+
/** CSS custom properties */
|
|
183
|
+
cssProperties?: Record<string, string>;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Plugin interface */
|
|
187
|
+
export interface Plugin {
|
|
188
|
+
/** Plugin name */
|
|
189
|
+
name: string;
|
|
190
|
+
/** Plugin version */
|
|
191
|
+
version?: string;
|
|
192
|
+
/** Setup hook */
|
|
193
|
+
setup?: (ctx: PluginContext) => void | Promise<void>;
|
|
194
|
+
/** Transform hook */
|
|
195
|
+
transform?: Transform;
|
|
196
|
+
/** Configure build */
|
|
197
|
+
configureBuild?: (options: BuildOptions) => void;
|
|
198
|
+
/** Resolve ID */
|
|
199
|
+
resolveId?: (id: string, importer?: string) => string | null | Promise<string | null>;
|
|
200
|
+
/** Load module */
|
|
201
|
+
load?: (id: string) => string | null | Promise<string | null>;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** Import map entry */
|
|
205
|
+
export interface ImportMapEntry {
|
|
206
|
+
/** Module specifier */
|
|
207
|
+
specifier: string;
|
|
208
|
+
/** URL or path */
|
|
209
|
+
url: string;
|
|
210
|
+
/** Scope */
|
|
211
|
+
scope?: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** Import map */
|
|
215
|
+
export interface ImportMap {
|
|
216
|
+
imports: Record<string, string>;
|
|
217
|
+
scopes?: Record<string, Record<string, string>>;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** Module resolution result */
|
|
221
|
+
export interface ResolveResult {
|
|
222
|
+
/** Resolved ID */
|
|
223
|
+
id: string;
|
|
224
|
+
/** External flag */
|
|
225
|
+
external?: boolean;
|
|
226
|
+
/** Side effects */
|
|
227
|
+
sideEffects?: boolean;
|
|
228
|
+
/** Synthetic named exports */
|
|
229
|
+
syntheticNamedExports?: boolean;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/** Bundle analysis */
|
|
233
|
+
export interface BundleAnalysis {
|
|
234
|
+
/** Original size */
|
|
235
|
+
original: number;
|
|
236
|
+
/** Bundled size */
|
|
237
|
+
bundled: number;
|
|
238
|
+
/** Gzipped size */
|
|
239
|
+
gzip: number;
|
|
240
|
+
/** Dependencies */
|
|
241
|
+
dependencies: string[];
|
|
242
|
+
/** Duplicated modules */
|
|
243
|
+
duplicates?: string[];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** Plugin preset */
|
|
247
|
+
export interface PluginPreset {
|
|
248
|
+
/** Preset name */
|
|
249
|
+
name: string;
|
|
250
|
+
/** Preset description */
|
|
251
|
+
description?: string;
|
|
252
|
+
/** Plugins */
|
|
253
|
+
plugins: Plugin[];
|
|
254
|
+
/** Default config */
|
|
255
|
+
defaults?: Record<string, unknown>;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/** Loader options */
|
|
259
|
+
export interface LoaderOptions {
|
|
260
|
+
/** Library configs */
|
|
261
|
+
libraries?: LibraryConfig[];
|
|
262
|
+
/** CDN options */
|
|
263
|
+
cdn?: CDNOptions;
|
|
264
|
+
/** External config */
|
|
265
|
+
external?: ExternalConfig;
|
|
266
|
+
/** Auto-imports */
|
|
267
|
+
autoImports?: AutoImportConfig[];
|
|
268
|
+
/** Component adapters */
|
|
269
|
+
adapters?: ComponentAdapter[];
|
|
270
|
+
/** Web components */
|
|
271
|
+
webComponents?: WebComponentConfig[];
|
|
272
|
+
/** Import map */
|
|
273
|
+
importMap?: ImportMap;
|
|
274
|
+
/** Custom transforms */
|
|
275
|
+
transforms?: Transform[];
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Registry search result */
|
|
279
|
+
export interface RegistrySearchResult {
|
|
280
|
+
/** Package name */
|
|
281
|
+
name: string;
|
|
282
|
+
/** Description */
|
|
283
|
+
description?: string;
|
|
284
|
+
/** Version */
|
|
285
|
+
version?: string;
|
|
286
|
+
/** Homepage */
|
|
287
|
+
homepage?: string;
|
|
288
|
+
/** Repository */
|
|
289
|
+
repository?: string;
|
|
290
|
+
/** Weekly downloads */
|
|
291
|
+
downloads?: number;
|
|
292
|
+
/** Formats available */
|
|
293
|
+
formats?: LibraryFormat[];
|
|
294
|
+
/** Has types */
|
|
295
|
+
types?: boolean;
|
|
296
|
+
}
|