Skip to content

Commit

Permalink
Fix issue with absolute path imports and improve importers error message
Browse files Browse the repository at this point in the history
  • Loading branch information
svallory committed Feb 16, 2024
1 parent 47c14f6 commit e574c36
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions code/builders/builder-vite/src/codegen-importfn-script.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ async function toImportFn(stories: string[], indexersMatchers: RegExp[]) {
);
}

return ` '${toImportPath(relativePath)}': async () => import('/@fs/${file}')`;
return [
` '${toImportPath(relativePath)}': async () => import('/@fs/${file}'),`,
` '${file}': async () => import('/@fs/${file}')`,
].join('\n');
});

return `
Expand All @@ -54,11 +57,12 @@ async function toImportFn(stories: string[], indexersMatchers: RegExp[]) {
}
if (!(path in importers)) {
throw new Error(\`No importer defined for "\${path}"\`)
throw new Error(\`No importer defined for "\${path}". Existing importers: \${Object.keys(importers)}\`);
}
return importers[path]();
}
`;
`;
}

export async function generateImportFnScriptCode(options: Options) {
Expand Down

0 comments on commit e574c36

Please sign in to comment.