sdocs 0.0.7 → 0.0.9

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.
@@ -29,6 +29,9 @@ export async function buildCommand() {
29
29
  input: inputs,
30
30
  },
31
31
  },
32
+ optimizeDeps: {
33
+ exclude: ['sdocs'],
34
+ },
32
35
  });
33
36
  console.log(`[sdocs] Build complete → dist/`);
34
37
  }
@@ -26,6 +26,9 @@ export async function devCommand() {
26
26
  allow: [cwd],
27
27
  },
28
28
  },
29
+ optimizeDeps: {
30
+ exclude: ['sdocs'],
31
+ },
29
32
  });
30
33
  await server.listen();
31
34
  server.printUrls();
@@ -85,14 +85,16 @@ function extractMetaFields(metaStr) {
85
85
  }
86
86
  /** Resolve the component import path to an absolute path */
87
87
  function resolveComponentPath(meta, imports, docFilePath) {
88
- // meta.component is the identifier name (e.g. 'Button')
89
- const componentName = typeof meta.component === 'string' ? meta.component : null;
90
- if (!componentName)
88
+ const componentValue = typeof meta.component === 'string' ? meta.component : null;
89
+ if (!componentValue)
91
90
  return null;
92
- // Find the import that imports this name
91
+ // If component is a relative path (e.g. './Button.svelte'), resolve directly
92
+ if (componentValue.startsWith('./') || componentValue.startsWith('../')) {
93
+ return resolve(dirname(docFilePath), componentValue);
94
+ }
95
+ // Otherwise it's an identifier (e.g. 'Button') — find matching import
93
96
  for (const imp of imports) {
94
- // Match: import Name from './path'
95
- const match = imp.match(new RegExp(`import\\s+${componentName}\\s+from\\s+['"](.+?)['"]`));
97
+ const match = imp.match(new RegExp(`import\\s+${componentValue}\\s+from\\s+['"](.+?)['"]`));
96
98
  if (match) {
97
99
  const importPath = match[1];
98
100
  return resolve(dirname(docFilePath), importPath);
package/dist/vite.js CHANGED
@@ -184,6 +184,14 @@ export function sdocsPlugin(userConfig) {
184
184
  }
185
185
  }
186
186
  }
187
+ // If component is specified as a path but not imported, auto-add the import
188
+ if (componentPath) {
189
+ const componentName = componentPath.split('/').pop()?.replace('.svelte', '') ?? 'Component';
190
+ const hasImport = imports.some((imp) => imp.includes(componentName));
191
+ if (!hasImport) {
192
+ imports.push(`import ${componentName} from '${componentPath}'`);
193
+ }
194
+ }
187
195
  // Cache resolved imports for iframe component generation
188
196
  docImportsCache.set(filePath, resolveImportsToAbsolute(imports, filePath));
189
197
  let componentData = null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sdocs",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
4
4
  "description": "A lightweight documentation tool for Svelte 5 components",
5
5
  "type": "module",
6
6
  "license": "MIT",