-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix svelte-stories-loader in Windows #133
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||||
|
@@ -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} | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why remove dedent? if we remove it I think you'll need to remove the comments on the lines above this as well as the import There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a regression with dedent from Storybook v7. It doesn't handle correctly quoted backslash. I have added an example in the referenced issue. Note that the vite loader doesn't use dedent either. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably. However here where are not generating invalid javacsript. at worst the source will have invalid breaking line, but we really need dedent here. In fact, this issue is not related to windows and is caused by this commit: 02ce02a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it would help to upgrade this project from dedent 1.2 to the latest version (1.5.1 if I recall correctly) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you're ok with this, let's create a new issue to improve the rendering of the source snippet. I'd like to close this PR, it's the last issue for upgrading my stack to Svelte 4 & Storybook 7.4 ^^ |
||||
const { default: parser } = require('${parser}'); | ||||
const __storiesMetaData = parser(${componentName}, ${JSON.stringify(storiesDef)}); | ||||
export default __storiesMetaData.meta; | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe call
path.posix
instead