Skip to content

Commit 4a10a85

Browse files
committed
add recursive scanning to the package
1 parent c7fad62 commit 4a10a85

2 files changed

Lines changed: 22 additions & 9 deletions

File tree

build/vite-plugin-openscript.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,29 @@ function scanComponents(dir, basePath = "") {
169169
* Generate TypeScript definition file for IDE autocomplete
170170
*/
171171
function generateTypeDefinitions(root, componentsDir, components) {
172-
const dtsPath = path.resolve(root, "src/openscript-components.d.ts");
172+
// Place d.ts in the parent directory of componentsDir
173+
const componentsAbsDir = path.resolve(root, componentsDir);
174+
const dtsDir = path.dirname(componentsAbsDir);
175+
const dtsPath = path.resolve(dtsDir, "openscript-components.d.ts");
173176

174177
const imports = components
175-
.map(
176-
(c) =>
177-
`import type ${c.name} from './${componentsDir}/${c.path.replace(
178-
".js",
179-
""
180-
)}';`
181-
)
178+
.map((c) => {
179+
const componentAbsPath = path.resolve(componentsAbsDir, c.path);
180+
let relativePath = path.relative(dtsDir, componentAbsPath);
181+
182+
// Normalize to forward slashes
183+
relativePath = normalizePath(relativePath);
184+
185+
// Remove extension
186+
relativePath = relativePath.replace(/\.\w+$/, "");
187+
188+
// Ensure it starts with ./ or ../
189+
if (!relativePath.startsWith(".") && !relativePath.startsWith("/")) {
190+
relativePath = "./" + relativePath;
191+
}
192+
193+
return `import type ${c.name} from '${relativePath}';`;
194+
})
182195
.join("\n");
183196

184197
const properties = components

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "modular-openscriptjs",
3-
"version": "1.0.12",
3+
"version": "1.0.14",
44
"description": "OpenScriptJs Framework - A lightweight, reactive JavaScript framework for building modern web applications",
55
"type": "module",
66
"main": "./dist/modular-openscriptjs.umd.js",

0 commit comments

Comments
 (0)