Skip to content

Commit

Permalink
Fix svelte-stories-loader in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
j3rem1e committed Aug 30, 2023
1 parent c68b02c commit fbd55de
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions src/parser/svelte-stories-loader.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import dedent from 'dedent';
import { extractStories } from './extract-stories.js';
import { fileURLToPath } from 'url';
import { readFileSync } from 'fs';

const parser = fileURLToPath(new URL('./collect-stories.js', import.meta.url))
.replace(/\\/g, "\\\\"); // For Windows paths;
.replace(/\\/g, '/'); // For Windows paths;

// From https://github.com/sveltejs/svelte/blob/8db3e8d0297e052556f0b6dde310ef6e197b8d18/src/compiler/compile/utils/get_name_from_filename.ts
// Copied because it is not exported from the compiler
Expand Down Expand Up @@ -57,9 +56,7 @@ function transformSvelteStories(code: string) {

const codeWithoutDefaultExport = code.replace('export default ', '//export default');

// throws dedent expression is not callable.
// @ts-ignore
return dedent`${codeWithoutDefaultExport}
return `${codeWithoutDefaultExport}
const { default: parser } = require('${parser}');
const __storiesMetaData = parser(${componentName}, ${JSON.stringify(storiesDef)});
export default __storiesMetaData.meta;
Expand Down

0 comments on commit fbd55de

Please sign in to comment.