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.
- package/dist/commands/build.js +3 -0
- package/dist/commands/dev.js +3 -0
- package/dist/server/meta-parser.js +8 -6
- package/dist/vite.js +8 -0
- package/package.json +1 -1
package/dist/commands/build.js
CHANGED
package/dist/commands/dev.js
CHANGED
|
@@ -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
|
-
|
|
89
|
-
|
|
90
|
-
if (!componentName)
|
|
88
|
+
const componentValue = typeof meta.component === 'string' ? meta.component : null;
|
|
89
|
+
if (!componentValue)
|
|
91
90
|
return null;
|
|
92
|
-
//
|
|
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
|
-
|
|
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;
|