@webmate-studio/builder 0.2.30 → 0.2.32
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/build-service.js +15 -2
- package/package.json +1 -1
- package/src/bundler.js +13 -4
package/build-service.js
CHANGED
|
@@ -73,11 +73,17 @@ function injectSvelteOptions(filename, content, componentMetadata) {
|
|
|
73
73
|
// SwiperTest.svelte → swiper-test
|
|
74
74
|
// MyAwesomeComponent.svelte → my-awesome-component
|
|
75
75
|
const componentName = filename.replace('.svelte', '');
|
|
76
|
-
|
|
76
|
+
let tagName = componentName
|
|
77
77
|
.replace(/([A-Z])/g, '-$1') // Insert hyphen before capital letters
|
|
78
78
|
.toLowerCase()
|
|
79
79
|
.replace(/^-/, ''); // Remove leading hyphen
|
|
80
80
|
|
|
81
|
+
// Svelte requires custom element names to be hyphenated
|
|
82
|
+
// If there's no hyphen, add a prefix to make it valid
|
|
83
|
+
if (!tagName.includes('-')) {
|
|
84
|
+
tagName = 'wm-' + tagName; // e.g., "button" → "wm-button"
|
|
85
|
+
}
|
|
86
|
+
|
|
81
87
|
// Generate props definition from component.json
|
|
82
88
|
const props = {};
|
|
83
89
|
if (componentMetadata.props) {
|
|
@@ -168,9 +174,10 @@ async function buildComponent(payload) {
|
|
|
168
174
|
const islandsDir = join(tmpDir, 'islands');
|
|
169
175
|
await mkdir(islandsDir, { recursive: true });
|
|
170
176
|
|
|
177
|
+
// FIRST: Write ALL island files to disk (for cross-imports)
|
|
178
|
+
// Some islands may import other files from the islands/ directory
|
|
171
179
|
for (const island of islands) {
|
|
172
180
|
const inputPath = join(islandsDir, island.file);
|
|
173
|
-
const outputPath = join(islandsDir, island.file.replace(/\.(jsx?|tsx?|svelte|vue)$/, '.js'));
|
|
174
181
|
|
|
175
182
|
// Auto-inject <svelte:options> for Svelte islands
|
|
176
183
|
let content = island.content;
|
|
@@ -180,6 +187,12 @@ async function buildComponent(payload) {
|
|
|
180
187
|
|
|
181
188
|
// Write source file
|
|
182
189
|
await writeFile(inputPath, content);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
// SECOND: Bundle each island
|
|
193
|
+
for (const island of islands) {
|
|
194
|
+
const inputPath = join(islandsDir, island.file);
|
|
195
|
+
const outputPath = join(islandsDir, island.file.replace(/\.(jsx?|tsx?|svelte|vue)$/, '.js'));
|
|
183
196
|
|
|
184
197
|
console.log(`[Build Service] Bundling ${island.file}...`);
|
|
185
198
|
|
package/package.json
CHANGED
package/src/bundler.js
CHANGED
|
@@ -202,9 +202,16 @@ export async function bundleComponentIslands(componentDir, outputDir) {
|
|
|
202
202
|
return { islands: [], success: true };
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
// Find all
|
|
205
|
+
// Find all island files (JS, JSX, Svelte, Vue, etc.)
|
|
206
206
|
const files = await fs.readdir(islandsDir);
|
|
207
|
-
const islandFiles = files.filter((f) =>
|
|
207
|
+
const islandFiles = files.filter((f) =>
|
|
208
|
+
f.endsWith('.js') ||
|
|
209
|
+
f.endsWith('.jsx') ||
|
|
210
|
+
f.endsWith('.svelte') ||
|
|
211
|
+
f.endsWith('.vue') ||
|
|
212
|
+
f.endsWith('.ts') ||
|
|
213
|
+
f.endsWith('.tsx')
|
|
214
|
+
);
|
|
208
215
|
|
|
209
216
|
if (islandFiles.length === 0) {
|
|
210
217
|
return { islands: [], success: true };
|
|
@@ -217,7 +224,9 @@ export async function bundleComponentIslands(componentDir, outputDir) {
|
|
|
217
224
|
|
|
218
225
|
for (const islandFile of islandFiles) {
|
|
219
226
|
const inputPath = path.join(islandsDir, islandFile);
|
|
220
|
-
|
|
227
|
+
// Output file is always .js regardless of input extension (.svelte, .jsx, etc.)
|
|
228
|
+
const outputFile = islandFile.replace(/\.(svelte|jsx|vue|tsx?)$/, '.js');
|
|
229
|
+
const outputPath = path.join(outputDir, outputFile);
|
|
221
230
|
|
|
222
231
|
console.log(pc.dim(` Bundling ${islandFile}...`));
|
|
223
232
|
|
|
@@ -233,7 +242,7 @@ export async function bundleComponentIslands(componentDir, outputDir) {
|
|
|
233
242
|
}
|
|
234
243
|
|
|
235
244
|
results.push({
|
|
236
|
-
file:
|
|
245
|
+
file: outputFile, // Use output filename (.js) instead of input filename
|
|
237
246
|
...result
|
|
238
247
|
});
|
|
239
248
|
}
|