bun-plugin-stx 0.2.5 → 0.2.8

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.
@@ -282,6 +282,18 @@ function stxPlugin(userOptions) {
282
282
  ...userOptions
283
283
  };
284
284
  const allDependencies = new Set;
285
+ if (!build.config.root && build.config.entrypoints?.length) {
286
+ const dirs = build.config.entrypoints.map((e) => path2.dirname(path2.resolve(e)));
287
+ const commonRoot = dirs.reduce((a, b) => {
288
+ const aParts = a.split(path2.sep);
289
+ const bParts = b.split(path2.sep);
290
+ let i = 0;
291
+ while (i < aParts.length && i < bParts.length && aParts[i] === bParts[i])
292
+ i++;
293
+ return aParts.slice(0, i).join(path2.sep);
294
+ });
295
+ build.config.root = commonRoot;
296
+ }
285
297
  const webComponentsPath = options.webComponents?.enabled ? `./${path2.relative(path2.dirname(build.config?.outdir || "dist"), options.webComponents.outputDir || "dist/web-components")}` : "/web-components";
286
298
  const builtComponents = [];
287
299
  if (options.webComponents?.enabled) {
@@ -295,12 +307,13 @@ function stxPlugin(userOptions) {
295
307
  console.error("Failed to build web components:", error);
296
308
  }
297
309
  }
298
- build.onLoad({ filter: /\.md$/ }, async ({ path: filePath }) => {
310
+ build.onLoad({ filter: /\.md$/ }, async (args) => {
311
+ const filePath = args.path;
299
312
  try {
300
313
  const { content: htmlContent, data: frontmatter } = await readMarkdownFile(filePath, options);
301
314
  const jsContent = `// ${filePath}
302
- var content = ${JSON.stringify(htmlContent)};
303
- var data = ${JSON.stringify(frontmatter)};
315
+ const content = ${JSON.stringify(htmlContent)};
316
+ const data = ${JSON.stringify(frontmatter)};
304
317
 
305
318
  export { content, data };
306
319
  export { content as default };
@@ -313,8 +326,8 @@ export { content as default };
313
326
  console.error("Markdown Processing Error:", error);
314
327
  const errorContent = generateErrorPage("Markdown Processing Error", error.message || "Unknown error", filePath);
315
328
  const jsContent = `// ${filePath}
316
- var content = ${JSON.stringify(errorContent)};
317
- var data = {};
329
+ const content = ${JSON.stringify(errorContent)};
330
+ const data = {};
318
331
 
319
332
  export { content, data };
320
333
  export { content as default };
@@ -325,7 +338,8 @@ export { content as default };
325
338
  };
326
339
  }
327
340
  });
328
- build.onLoad({ filter: /\.(jsx|tsx)$/ }, async ({ path: filePath }) => {
341
+ build.onLoad({ filter: /\.(jsx|tsx)$/ }, async (args) => {
342
+ const filePath = args.path;
329
343
  try {
330
344
  const source = await Bun.file(filePath).text();
331
345
  const loader = filePath.endsWith(".tsx") ? "tsx" : "jsx";
@@ -372,7 +386,7 @@ export { content as default };
372
386
  const serverScripts = [];
373
387
  const signalsScripts = [];
374
388
  let scriptMatch;
375
- const usesSignalsAPI = (content2) => /\b(?:state|derived|effect|batch)\s*\(/.test(content2);
389
+ const usesSignalsAPI = (content2) => /\b(?:state|derived|effect|batch|ref|reactive|computed|watch|watchEffect)\s*(?:<[^>]*>)?\s*\(/.test(content2);
376
390
  while ((scriptMatch = scriptRegex.exec(content)) !== null) {
377
391
  const attrs = scriptMatch[1];
378
392
  const scriptContent = scriptMatch[2];