@vertesia/build-tools 1.3.0 → 1.4.0-dev.20260614.160504Z

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.
Files changed (220) hide show
  1. package/README.md +3 -3
  2. package/lib/bin/build.d.ts +35 -0
  3. package/lib/bin/build.d.ts.map +1 -0
  4. package/lib/bin/build.js +79 -0
  5. package/lib/bin/build.js.map +1 -0
  6. package/lib/bin/config.d.ts +24 -0
  7. package/lib/bin/config.d.ts.map +1 -0
  8. package/lib/bin/config.js +91 -0
  9. package/lib/bin/config.js.map +1 -0
  10. package/lib/core/compilers/widget.d.ts +27 -0
  11. package/lib/core/compilers/widget.d.ts.map +1 -0
  12. package/lib/core/compilers/widget.js +37 -0
  13. package/lib/core/compilers/widget.js.map +1 -0
  14. package/lib/{types → core}/parsers/frontmatter.d.ts +1 -1
  15. package/lib/core/parsers/frontmatter.d.ts.map +1 -0
  16. package/lib/{esm → core}/parsers/frontmatter.js +1 -1
  17. package/lib/core/parsers/frontmatter.js.map +1 -0
  18. package/lib/core/transformers/index.d.ts +10 -0
  19. package/lib/core/transformers/index.d.ts.map +1 -0
  20. package/lib/core/transformers/index.js +10 -0
  21. package/lib/core/transformers/index.js.map +1 -0
  22. package/lib/{types/presets → core/transformers}/prompt.d.ts +7 -21
  23. package/lib/core/transformers/prompt.d.ts.map +1 -0
  24. package/lib/{esm/presets → core/transformers}/prompt.js +17 -14
  25. package/lib/core/transformers/prompt.js.map +1 -0
  26. package/lib/core/transformers/raw.d.ts.map +1 -0
  27. package/lib/{esm/presets → core/transformers}/raw.js +2 -2
  28. package/lib/core/transformers/raw.js.map +1 -0
  29. package/lib/core/transformers/skill-collection.d.ts.map +1 -0
  30. package/lib/{esm/presets → core/transformers}/skill-collection.js +5 -12
  31. package/lib/core/transformers/skill-collection.js.map +1 -0
  32. package/lib/core/transformers/skill.d.ts +111 -0
  33. package/lib/core/transformers/skill.d.ts.map +1 -0
  34. package/lib/{esm/presets → core/transformers}/skill.js +70 -51
  35. package/lib/core/transformers/skill.js.map +1 -0
  36. package/lib/core/transformers/template-collection.d.ts.map +1 -0
  37. package/lib/{esm/presets → core/transformers}/template-collection.js +5 -12
  38. package/lib/core/transformers/template-collection.js.map +1 -0
  39. package/lib/{types/presets → core/transformers}/template.d.ts +7 -22
  40. package/lib/core/transformers/template.d.ts.map +1 -0
  41. package/lib/{esm/presets → core/transformers}/template.js +16 -11
  42. package/lib/core/transformers/template.js.map +1 -0
  43. package/lib/{types → core}/types.d.ts +5 -61
  44. package/lib/core/types.d.ts.map +1 -0
  45. package/lib/core/types.js +6 -0
  46. package/lib/{cjs → core}/types.js.map +1 -1
  47. package/lib/core/utils/asset-copy.d.ts.map +1 -0
  48. package/lib/core/utils/asset-copy.js.map +1 -0
  49. package/lib/core/utils/asset-discovery.d.ts.map +1 -0
  50. package/lib/{esm → core}/utils/asset-discovery.js +4 -4
  51. package/lib/core/utils/asset-discovery.js.map +1 -0
  52. package/lib/core/utils/template-asset-discovery.d.ts.map +1 -0
  53. package/lib/{esm → core}/utils/template-asset-discovery.js +3 -7
  54. package/lib/core/utils/template-asset-discovery.js.map +1 -0
  55. package/lib/import-transform/builtins.d.ts +21 -0
  56. package/lib/import-transform/builtins.d.ts.map +1 -0
  57. package/lib/import-transform/builtins.js +50 -0
  58. package/lib/import-transform/builtins.js.map +1 -0
  59. package/lib/import-transform/chunk-emitter.d.ts +24 -0
  60. package/lib/import-transform/chunk-emitter.d.ts.map +1 -0
  61. package/lib/import-transform/chunk-emitter.js +35 -0
  62. package/lib/import-transform/chunk-emitter.js.map +1 -0
  63. package/lib/import-transform/detector.d.ts +24 -0
  64. package/lib/import-transform/detector.d.ts.map +1 -0
  65. package/lib/import-transform/detector.js +34 -0
  66. package/lib/import-transform/detector.js.map +1 -0
  67. package/lib/import-transform/index.d.ts +47 -0
  68. package/lib/import-transform/index.d.ts.map +1 -0
  69. package/lib/import-transform/index.js +115 -0
  70. package/lib/import-transform/index.js.map +1 -0
  71. package/lib/import-transform/patterns.d.ts +25 -0
  72. package/lib/import-transform/patterns.d.ts.map +1 -0
  73. package/lib/import-transform/patterns.js +27 -0
  74. package/lib/import-transform/patterns.js.map +1 -0
  75. package/lib/import-transform/resolver.d.ts +23 -0
  76. package/lib/import-transform/resolver.d.ts.map +1 -0
  77. package/lib/import-transform/resolver.js +30 -0
  78. package/lib/import-transform/resolver.js.map +1 -0
  79. package/lib/import-transform/rewriter.d.ts +21 -0
  80. package/lib/import-transform/rewriter.d.ts.map +1 -0
  81. package/lib/import-transform/rewriter.js +30 -0
  82. package/lib/import-transform/rewriter.js.map +1 -0
  83. package/lib/import-transform/scanner.d.ts +17 -0
  84. package/lib/import-transform/scanner.d.ts.map +1 -0
  85. package/lib/import-transform/scanner.js +46 -0
  86. package/lib/import-transform/scanner.js.map +1 -0
  87. package/lib/index.d.ts +39 -0
  88. package/lib/index.d.ts.map +1 -0
  89. package/lib/index.js +43 -0
  90. package/lib/index.js.map +1 -0
  91. package/lib/vite/api-server.d.ts +54 -0
  92. package/lib/vite/api-server.d.ts.map +1 -0
  93. package/lib/vite/api-server.js +94 -0
  94. package/lib/vite/api-server.js.map +1 -0
  95. package/lib/vite/dev-server.d.ts +42 -0
  96. package/lib/vite/dev-server.d.ts.map +1 -0
  97. package/lib/vite/dev-server.js +111 -0
  98. package/lib/vite/dev-server.js.map +1 -0
  99. package/lib/vite/index.d.ts +15 -0
  100. package/lib/vite/index.d.ts.map +1 -0
  101. package/lib/vite/index.js +15 -0
  102. package/lib/vite/index.js.map +1 -0
  103. package/package.json +38 -28
  104. package/src/bin/build.ts +83 -0
  105. package/src/bin/config.ts +113 -0
  106. package/src/core/compilers/widget.ts +69 -0
  107. package/src/{parsers → core/parsers}/frontmatter.ts +2 -2
  108. package/src/core/transformers/index.ts +27 -0
  109. package/src/{presets → core/transformers}/prompt.ts +35 -32
  110. package/src/{presets → core/transformers}/raw.ts +2 -2
  111. package/src/{presets → core/transformers}/skill-collection.ts +5 -12
  112. package/src/{presets → core/transformers}/skill.ts +119 -99
  113. package/src/{presets → core/transformers}/template-collection.ts +76 -83
  114. package/src/{presets → core/transformers}/template.ts +121 -116
  115. package/src/core/types.ts +71 -0
  116. package/src/{utils → core/utils}/asset-copy.ts +3 -2
  117. package/src/{utils → core/utils}/asset-discovery.ts +5 -5
  118. package/src/{utils → core/utils}/template-asset-discovery.ts +70 -77
  119. package/src/import-transform/builtins.ts +56 -0
  120. package/src/import-transform/chunk-emitter.ts +60 -0
  121. package/src/import-transform/detector.ts +56 -0
  122. package/src/import-transform/index.ts +171 -0
  123. package/src/import-transform/patterns.ts +34 -0
  124. package/src/import-transform/resolver.ts +57 -0
  125. package/src/import-transform/rewriter.ts +48 -0
  126. package/src/import-transform/scanner.ts +55 -0
  127. package/src/index.ts +67 -42
  128. package/src/vite/api-server.ts +142 -0
  129. package/src/vite/dev-server.ts +128 -0
  130. package/src/vite/index.ts +15 -0
  131. package/lib/build-tools.js +0 -2054
  132. package/lib/build-tools.js.map +0 -1
  133. package/lib/cjs/index.js +0 -43
  134. package/lib/cjs/index.js.map +0 -1
  135. package/lib/cjs/package.json +0 -3
  136. package/lib/cjs/parsers/frontmatter.js +0 -25
  137. package/lib/cjs/parsers/frontmatter.js.map +0 -1
  138. package/lib/cjs/plugin.js +0 -150
  139. package/lib/cjs/plugin.js.map +0 -1
  140. package/lib/cjs/presets/index.js +0 -25
  141. package/lib/cjs/presets/index.js.map +0 -1
  142. package/lib/cjs/presets/prompt.js +0 -185
  143. package/lib/cjs/presets/prompt.js.map +0 -1
  144. package/lib/cjs/presets/raw.js +0 -25
  145. package/lib/cjs/presets/raw.js.map +0 -1
  146. package/lib/cjs/presets/skill-collection.js +0 -83
  147. package/lib/cjs/presets/skill-collection.js.map +0 -1
  148. package/lib/cjs/presets/skill.js +0 -272
  149. package/lib/cjs/presets/skill.js.map +0 -1
  150. package/lib/cjs/presets/template-collection.js +0 -80
  151. package/lib/cjs/presets/template-collection.js.map +0 -1
  152. package/lib/cjs/presets/template.js +0 -105
  153. package/lib/cjs/presets/template.js.map +0 -1
  154. package/lib/cjs/types.js +0 -6
  155. package/lib/cjs/utils/asset-copy.js +0 -61
  156. package/lib/cjs/utils/asset-copy.js.map +0 -1
  157. package/lib/cjs/utils/asset-discovery.js +0 -100
  158. package/lib/cjs/utils/asset-discovery.js.map +0 -1
  159. package/lib/cjs/utils/template-asset-discovery.js +0 -63
  160. package/lib/cjs/utils/template-asset-discovery.js.map +0 -1
  161. package/lib/cjs/utils/widget-compiler.js +0 -115
  162. package/lib/cjs/utils/widget-compiler.js.map +0 -1
  163. package/lib/cjs/vite.js +0 -45
  164. package/lib/cjs/vite.js.map +0 -1
  165. package/lib/esm/index.js +0 -26
  166. package/lib/esm/index.js.map +0 -1
  167. package/lib/esm/parsers/frontmatter.js.map +0 -1
  168. package/lib/esm/plugin.js +0 -144
  169. package/lib/esm/plugin.js.map +0 -1
  170. package/lib/esm/presets/index.js +0 -10
  171. package/lib/esm/presets/index.js.map +0 -1
  172. package/lib/esm/presets/prompt.js.map +0 -1
  173. package/lib/esm/presets/raw.js.map +0 -1
  174. package/lib/esm/presets/skill-collection.js.map +0 -1
  175. package/lib/esm/presets/skill.js.map +0 -1
  176. package/lib/esm/presets/template-collection.js.map +0 -1
  177. package/lib/esm/presets/template.js.map +0 -1
  178. package/lib/esm/types.js +0 -5
  179. package/lib/esm/types.js.map +0 -1
  180. package/lib/esm/utils/asset-copy.js.map +0 -1
  181. package/lib/esm/utils/asset-discovery.js.map +0 -1
  182. package/lib/esm/utils/template-asset-discovery.js.map +0 -1
  183. package/lib/esm/utils/widget-compiler.js +0 -76
  184. package/lib/esm/utils/widget-compiler.js.map +0 -1
  185. package/lib/esm/vite.js +0 -42
  186. package/lib/esm/vite.js.map +0 -1
  187. package/lib/types/index.d.ts +0 -24
  188. package/lib/types/index.d.ts.map +0 -1
  189. package/lib/types/parsers/frontmatter.d.ts.map +0 -1
  190. package/lib/types/plugin.d.ts +0 -10
  191. package/lib/types/plugin.d.ts.map +0 -1
  192. package/lib/types/presets/index.d.ts +0 -10
  193. package/lib/types/presets/index.d.ts.map +0 -1
  194. package/lib/types/presets/prompt.d.ts.map +0 -1
  195. package/lib/types/presets/raw.d.ts.map +0 -1
  196. package/lib/types/presets/skill-collection.d.ts.map +0 -1
  197. package/lib/types/presets/skill.d.ts +0 -361
  198. package/lib/types/presets/skill.d.ts.map +0 -1
  199. package/lib/types/presets/template-collection.d.ts.map +0 -1
  200. package/lib/types/presets/template.d.ts.map +0 -1
  201. package/lib/types/types.d.ts.map +0 -1
  202. package/lib/types/utils/asset-copy.d.ts.map +0 -1
  203. package/lib/types/utils/asset-discovery.d.ts.map +0 -1
  204. package/lib/types/utils/template-asset-discovery.d.ts.map +0 -1
  205. package/lib/types/utils/widget-compiler.d.ts +0 -15
  206. package/lib/types/utils/widget-compiler.d.ts.map +0 -1
  207. package/lib/types/vite.d.ts +0 -32
  208. package/lib/types/vite.d.ts.map +0 -1
  209. package/src/plugin.ts +0 -166
  210. package/src/presets/index.ts +0 -10
  211. package/src/types.ts +0 -140
  212. package/src/utils/widget-compiler.ts +0 -98
  213. package/src/vite.ts +0 -45
  214. /package/lib/{types/presets → core/transformers}/raw.d.ts +0 -0
  215. /package/lib/{types/presets → core/transformers}/skill-collection.d.ts +0 -0
  216. /package/lib/{types/presets → core/transformers}/template-collection.d.ts +0 -0
  217. /package/lib/{types → core}/utils/asset-copy.d.ts +0 -0
  218. /package/lib/{esm → core}/utils/asset-copy.js +0 -0
  219. /package/lib/{types → core}/utils/asset-discovery.d.ts +0 -0
  220. /package/lib/{types → core}/utils/template-asset-discovery.d.ts +0 -0
package/src/plugin.ts DELETED
@@ -1,166 +0,0 @@
1
- /**
2
- * Core Rollup plugin implementation for transforming imports
3
- */
4
-
5
- import type { Plugin } from 'rollup';
6
- import { readFileSync } from 'node:fs';
7
- import path from 'node:path';
8
- import type { PluginConfig, TransformerRule, AssetFile } from './types.js';
9
- import { copyAssets } from './utils/asset-copy.js';
10
- import { compileWidgets } from './utils/widget-compiler.js';
11
- import type { WidgetMetadata } from './utils/asset-discovery.js';
12
-
13
- /**
14
- * Creates a Rollup plugin that transforms imports based on configured rules
15
- */
16
- export function vertesiaImportPlugin(config: PluginConfig): Plugin {
17
- const { transformers, assetsDir = './dist', widgetConfig } = config;
18
-
19
- if (!transformers || transformers.length === 0) {
20
- throw new Error('vertesiaImportPlugin: At least one transformer must be configured');
21
- }
22
-
23
- // Track assets to copy and widgets to compile
24
- const assetsToProcess: AssetFile[] = [];
25
- const widgetsToCompile: WidgetMetadata[] = [];
26
- const shouldCopyAssets = assetsDir !== false;
27
- const shouldCompileWidgets = widgetConfig !== undefined && assetsDir !== false;
28
-
29
- return {
30
- name: 'vertesia-import-plugin',
31
-
32
- /**
33
- * Resolve import IDs to handle pattern-based imports
34
- */
35
- resolveId(source: string, importer: string | undefined) {
36
- // Check if any transformer pattern matches
37
- for (const transformer of transformers) {
38
- if (transformer.pattern.test(source)) {
39
- // Handle relative imports
40
- if (source.startsWith('.') && importer) {
41
- const cleanSource = source.replace(transformer.pattern, '');
42
- // Strip query parameters from importer to get the file path
43
- const cleanImporter = importer.indexOf('?') >= 0
44
- ? importer.substring(0, importer.indexOf('?'))
45
- : importer;
46
- // Always use dirname to get the directory containing the importer
47
- const baseDir = path.dirname(cleanImporter);
48
- const resolved = path.resolve(baseDir, cleanSource);
49
- // Return with the pattern suffix to identify it in load
50
- const suffix = source.match(transformer.pattern)?.[0] || '';
51
- return resolved + suffix;
52
- }
53
- return source;
54
- }
55
- }
56
- return null; // Let other plugins handle it
57
- },
58
-
59
- /**
60
- * Load and transform the file content
61
- */
62
- async load(id: string) {
63
- // Find matching transformer
64
- let matchedTransformer: TransformerRule | undefined;
65
- let cleanId = id;
66
-
67
- for (const transformer of transformers) {
68
- if (transformer.pattern.test(id)) {
69
- matchedTransformer = transformer;
70
- // Remove query parameters to get actual file path
71
- // For example: '/path/file.md?skill' -> '/path/file.md'
72
- // '/path/file.html?raw' -> '/path/file.html'
73
- const queryIndex = id.indexOf('?');
74
- cleanId = queryIndex >= 0 ? id.substring(0, queryIndex) : id;
75
- break;
76
- }
77
- }
78
-
79
- if (!matchedTransformer) {
80
- return null; // Not for us
81
- }
82
-
83
- try {
84
- // Read file content (skip for virtual transforms)
85
- const content = matchedTransformer.virtual
86
- ? ''
87
- : readFileSync(cleanId, 'utf-8');
88
-
89
- // Transform the content
90
- const result = await matchedTransformer.transform(content, cleanId);
91
-
92
- // Collect assets if any
93
- if (result.assets && shouldCopyAssets) {
94
- assetsToProcess.push(...result.assets);
95
- }
96
-
97
- // Collect widgets if any
98
- if (result.widgets && shouldCompileWidgets) {
99
- widgetsToCompile.push(...result.widgets);
100
- }
101
-
102
- // Validate if schema provided
103
- if (matchedTransformer.schema) {
104
- const validation = matchedTransformer.schema.safeParse(result.data);
105
- if (!validation.success) {
106
- const errors = validation.error.errors
107
- .map((err) => ` - ${err.path.join('.')}: ${err.message}`)
108
- .join('\n');
109
- throw new Error(
110
- `Validation failed for ${id}:\n${errors}`
111
- );
112
- }
113
- }
114
-
115
- // Generate code
116
- const imports = result.imports ? result.imports.join('\n') + '\n\n' : '';
117
- if (result.code) {
118
- // Custom code provided - prepend imports
119
- return imports + result.code;
120
- } else {
121
- // Default: export data (escape if string, otherwise stringify as JSON)
122
- const dataJson = JSON.stringify(result.data, null, 2);
123
- return `${imports}export default ${dataJson};`;
124
- }
125
- } catch (error) {
126
- const message = error instanceof Error ? error.message : String(error);
127
- this.error(`Failed to transform ${id}: ${message}`);
128
- }
129
- },
130
-
131
- /**
132
- * Copy assets and compile widgets after all modules are loaded
133
- */
134
- async buildEnd() {
135
- // Copy script assets
136
- if (shouldCopyAssets && assetsToProcess.length > 0) {
137
- try {
138
- const copied = copyAssets(assetsToProcess, assetsDir as string);
139
- console.log(`Copied ${copied} asset file(s) to ${assetsDir}`);
140
- } catch (error) {
141
- const message = error instanceof Error ? error.message : String(error);
142
- this.warn(`Failed to copy assets: ${message}`);
143
- }
144
- }
145
-
146
- // Compile widgets
147
- if (shouldCompileWidgets && widgetsToCompile.length > 0) {
148
- try {
149
- const widgetsDir = config.widgetsDir || 'widgets';
150
- const outputDir = path.join(assetsDir as string, widgetsDir);
151
-
152
- console.log(`Compiling ${widgetsToCompile.length} widget(s)...`);
153
- const compiled = await compileWidgets(
154
- widgetsToCompile,
155
- outputDir,
156
- widgetConfig
157
- );
158
- console.log(`Compiled ${compiled} widget(s) to ${outputDir}`);
159
- } catch (error) {
160
- const message = error instanceof Error ? error.message : String(error);
161
- this.error(`Failed to compile widgets: ${message}`);
162
- }
163
- }
164
- }
165
- };
166
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * Preset transformers for common use cases
3
- */
4
-
5
- export { skillTransformer, SkillDefinitionSchema, SkillPropertiesSchema, type SkillDefinition, type SkillContentType } from './skill.js';
6
- export { skillCollectionTransformer } from './skill-collection.js';
7
- export { templateTransformer, RenderingTemplateDefinitionSchema, type RenderingTemplateDefinition } from './template.js';
8
- export { templateCollectionTransformer } from './template-collection.js';
9
- export { rawTransformer } from './raw.js';
10
- export { promptTransformer, PromptDefinitionSchema, type PromptDefinition, type PromptContentType, PromptRole, TemplateType } from './prompt.js';
package/src/types.ts DELETED
@@ -1,140 +0,0 @@
1
- /**
2
- * Type definitions for the Vertesia Rollup Import Plugin
3
- */
4
-
5
- import type { Plugin } from 'rollup';
6
- import type { z } from 'zod';
7
-
8
- /**
9
- * Asset file to be copied during build
10
- */
11
- export interface AssetFile {
12
- /** Source file path (absolute) */
13
- sourcePath: string;
14
-
15
- /** Relative destination path within assets directory */
16
- destPath: string;
17
-
18
- /** Asset type for categorization */
19
- type: 'script' | 'template';
20
- }
21
-
22
- /**
23
- * Result of a transform function
24
- */
25
- export interface TransformResult {
26
- /** The data to export (can be text or JSON object) */
27
- data: unknown;
28
-
29
- /** Optional: additional imports to inject at the top of the generated module */
30
- imports?: string[];
31
-
32
- /** Optional: custom code to generate instead of default JSON export */
33
- code?: string;
34
-
35
- /** Optional: additional asset files to copy */
36
- assets?: AssetFile[];
37
-
38
- /** Optional: widget metadata for compilation */
39
- widgets?: Array<{ name: string; path: string }>;
40
- }
41
-
42
- /**
43
- * Transform function that converts file content into exportable data
44
- */
45
- export type TransformFunction = (
46
- content: string,
47
- filePath: string
48
- ) => TransformResult | Promise<TransformResult>;
49
-
50
- /**
51
- * Configuration for a single import transformer rule
52
- */
53
- export interface TransformerRule {
54
- /** Pattern to match import paths (e.g., /\.md\?skill$/ or /\?raw$/) */
55
- pattern: RegExp;
56
-
57
- /** Transform function to convert file content */
58
- transform: TransformFunction;
59
-
60
- /** Optional: Zod schema for validation */
61
- schema?: z.ZodType<any>;
62
-
63
- /** Optional: If true, the transformer generates virtual modules (no file to read) */
64
- virtual?: boolean;
65
-
66
- /** Optional: additional options for this transformer */
67
- options?: Record<string, unknown>;
68
- }
69
-
70
- /**
71
- * Widget compilation configuration
72
- */
73
- export interface WidgetConfig {
74
- /**
75
- * External dependencies that should not be bundled
76
- * Default: ['react', 'react-dom', 'react/jsx-runtime']
77
- */
78
- external?: string[];
79
-
80
- /**
81
- * Path to tsconfig.json for widget compilation
82
- * Default: './tsconfig.json'
83
- */
84
- tsconfig?: string;
85
-
86
- /**
87
- * Additional options to pass to @rollup/plugin-typescript
88
- */
89
- typescript?: Record<string, unknown>;
90
-
91
- /**
92
- * Minify widget output
93
- * Default: false
94
- */
95
- minify?: boolean;
96
- }
97
-
98
- /**
99
- * Plugin configuration
100
- */
101
- export interface PluginConfig {
102
- /** Array of transformer rules to apply */
103
- transformers: TransformerRule[];
104
-
105
- /**
106
- * Root directory for asset output (scripts, widgets, etc.)
107
- * - If specified: assets will be copied to this directory
108
- * - If false: asset copying is disabled
109
- * - Default: './dist'
110
- */
111
- assetsDir?: string | false;
112
-
113
- /**
114
- * Directory for script files relative to assetsDir
115
- * Default: 'scripts'
116
- */
117
- scriptsDir?: string;
118
-
119
- /**
120
- * Directory for widget files relative to assetsDir
121
- * Default: 'widgets'
122
- */
123
- widgetsDir?: string;
124
-
125
- /**
126
- * Widget compilation configuration
127
- * If provided, discovered widgets will be automatically compiled
128
- */
129
- widgetConfig?: WidgetConfig;
130
- }
131
-
132
- /**
133
- * Type for transformer presets
134
- */
135
- export type TransformerPreset = TransformerRule;
136
-
137
- /**
138
- * Plugin factory return type
139
- */
140
- export type VertesiaImportPlugin = (config: PluginConfig) => Plugin;
@@ -1,98 +0,0 @@
1
- /**
2
- * Widget compilation utility using Rollup
3
- */
4
-
5
- import { rollup, type RollupOptions, type Plugin } from 'rollup';
6
- import path from 'node:path';
7
- import type { WidgetConfig } from '../types.js';
8
- import type { WidgetMetadata } from './asset-discovery.js';
9
-
10
- /**
11
- * Default external dependencies for widgets
12
- */
13
- const DEFAULT_EXTERNALS = [
14
- 'react',
15
- 'react-dom',
16
- 'react/jsx-runtime',
17
- 'react/jsx-dev-runtime',
18
- 'react-dom/client'
19
- ];
20
-
21
- /**
22
- * Compile widgets using Rollup
23
- *
24
- * @param widgets - Array of widget metadata to compile
25
- * @param outputDir - Directory to write compiled widgets
26
- * @param config - Widget compilation configuration
27
- * @returns Number of widgets compiled
28
- */
29
- export async function compileWidgets(
30
- widgets: WidgetMetadata[],
31
- outputDir: string,
32
- config: WidgetConfig = {}
33
- ): Promise<number> {
34
- if (widgets.length === 0) {
35
- return 0;
36
- }
37
-
38
- const {
39
- external = DEFAULT_EXTERNALS,
40
- tsconfig = './tsconfig.json',
41
- typescript: typescriptOptions = {},
42
- minify = false
43
- } = config;
44
-
45
- // Build each widget separately to get individual bundles
46
- const buildPromises = widgets.map(async (widget) => {
47
- // Dynamically import plugins - use any to bypass TypeScript module resolution issues
48
- const typescript = (await import('@rollup/plugin-typescript' as any)).default as any;
49
- const nodeResolve = (await import('@rollup/plugin-node-resolve' as any)).default as any;
50
- const commonjs = (await import('@rollup/plugin-commonjs' as any)).default as any;
51
-
52
- const plugins: Plugin[] = [
53
- typescript({
54
- tsconfig,
55
- declaration: false,
56
- sourceMap: true,
57
- ...typescriptOptions
58
- }),
59
- nodeResolve({
60
- browser: true,
61
- preferBuiltins: false,
62
- extensions: ['.tsx', '.ts', '.jsx', '.js']
63
- }),
64
- commonjs()
65
- ];
66
-
67
- // Add minification if requested
68
- if (minify) {
69
- const { terser } = await import('rollup-plugin-terser' as any);
70
- plugins.push(
71
- terser({
72
- compress: {
73
- drop_console: false
74
- }
75
- })
76
- );
77
- }
78
-
79
- const rollupConfig: RollupOptions = {
80
- input: widget.path,
81
- output: {
82
- file: path.join(outputDir, `${widget.name}.js`),
83
- format: 'es',
84
- sourcemap: true,
85
- inlineDynamicImports: true
86
- },
87
- external,
88
- plugins
89
- };
90
-
91
- const bundle = await rollup(rollupConfig);
92
- await bundle.write(rollupConfig.output as any);
93
- await bundle.close();
94
- });
95
-
96
- await Promise.all(buildPromises);
97
- return widgets.length;
98
- }
package/src/vite.ts DELETED
@@ -1,45 +0,0 @@
1
- /**
2
- * Vite-specific helpers for tool server development.
3
- *
4
- * Provides a pre-configured Vite plugin that handles SKILL.md, prompt,
5
- * and raw file imports — the same transforms used by rollup at build time.
6
- *
7
- * @example
8
- * ```typescript
9
- * // vite.server.config.ts
10
- * import { defineConfig } from 'vite';
11
- * import devServer from '@hono/vite-dev-server';
12
- * import { vertesiaDevServerPlugin } from '@vertesia/build-tools/vite';
13
- *
14
- * export default defineConfig({
15
- * plugins: [
16
- * vertesiaDevServerPlugin(),
17
- * devServer({ entry: 'tools/server.ts' }),
18
- * ],
19
- * });
20
- * ```
21
- */
22
-
23
- import type { Plugin } from 'rollup';
24
- import { vertesiaImportPlugin } from './plugin.js';
25
- import { skillTransformer, rawTransformer, promptTransformer } from './presets/index.js';
26
- import type { PluginConfig } from './types.js';
27
-
28
- /**
29
- * Creates a pre-configured Vite plugin for tool server dev mode.
30
- * Includes skill, prompt, and raw file transformers with asset copying disabled
31
- * (assets are only needed at build time, not during dev).
32
- *
33
- * @param overrides - Optional overrides for the plugin config
34
- */
35
- export function vertesiaDevServerPlugin(overrides?: Partial<PluginConfig>): Plugin {
36
- return vertesiaImportPlugin({
37
- transformers: [
38
- skillTransformer,
39
- promptTransformer,
40
- rawTransformer,
41
- ],
42
- assetsDir: false,
43
- ...overrides,
44
- });
45
- }
File without changes
File without changes
File without changes