From db593fa6ba419b541686cf57fab9ed08a0203b46 Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Mon, 12 Aug 2024 16:51:00 +0200 Subject: [PATCH 1/2] Builder-Vite: Add null character prefix to virtual file IDs in code generator plugin --- .../src/plugins/code-generator-plugin.ts | 12 ++++++------ code/builders/builder-vite/src/virtual-file-names.ts | 8 ++++---- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/code/builders/builder-vite/src/plugins/code-generator-plugin.ts b/code/builders/builder-vite/src/plugins/code-generator-plugin.ts index ac0fe2a3b970..f841c47cf7e5 100644 --- a/code/builders/builder-vite/src/plugins/code-generator-plugin.ts +++ b/code/builders/builder-vite/src/plugins/code-generator-plugin.ts @@ -70,33 +70,33 @@ export function codeGeneratorPlugin(options: Options): Plugin { }, resolveId(source) { if (source === virtualFileId) { - return `\0${virtualFileId}`; + return virtualFileId; } if (source === iframePath) { return iframeId; } if (source === virtualStoriesFile) { - return `\0${virtualStoriesFile}`; + return virtualStoriesFile; } if (source === virtualPreviewFile) { return virtualPreviewFile; } if (source === virtualAddonSetupFile) { - return `\0${virtualAddonSetupFile}`; + return virtualAddonSetupFile; } return undefined; }, async load(id, config) { - if (id === `\0${virtualStoriesFile}`) { + if (id === virtualStoriesFile) { return generateImportFnScriptCode(options); } - if (id === `\0${virtualAddonSetupFile}`) { + if (id === virtualAddonSetupFile) { return generateAddonSetupCode(); } - if (id === `\0${virtualFileId}`) { + if (id === virtualFileId) { return generateModernIframeScriptCode(options, projectRoot); } diff --git a/code/builders/builder-vite/src/virtual-file-names.ts b/code/builders/builder-vite/src/virtual-file-names.ts index 0da0c5517dec..48e7a907f9ae 100644 --- a/code/builders/builder-vite/src/virtual-file-names.ts +++ b/code/builders/builder-vite/src/virtual-file-names.ts @@ -1,4 +1,4 @@ -export const virtualFileId = '/virtual:/@storybook/builder-vite/vite-app.js'; -export const virtualStoriesFile = '/virtual:/@storybook/builder-vite/storybook-stories.js'; -export const virtualPreviewFile = '/virtual:/@storybook/builder-vite/preview-entry.js'; -export const virtualAddonSetupFile = '/virtual:/@storybook/builder-vite/setup-addons.js'; +export const virtualFileId = '\0virtual:/@storybook/builder-vite/vite-app.js'; +export const virtualStoriesFile = '\0virtual:/@storybook/builder-vite/storybook-stories.js'; +export const virtualPreviewFile = '\0virtual:/@storybook/builder-vite/preview-entry.js'; +export const virtualAddonSetupFile = '\0virtual:/@storybook/builder-vite/setup-addons.js'; From 8066f72833802dc26fbe75025fd01cffefde944a Mon Sep 17 00:00:00 2001 From: Valentin Palkovic Date: Tue, 13 Aug 2024 09:16:27 +0200 Subject: [PATCH 2/2] Builder-Vite: Add null character prefix to virtual file IDs in code generator plugin --- .../src/plugins/code-generator-plugin.ts | 16 ++++++++++------ .../builder-vite/src/virtual-file-names.ts | 8 ++++---- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/code/builders/builder-vite/src/plugins/code-generator-plugin.ts b/code/builders/builder-vite/src/plugins/code-generator-plugin.ts index f841c47cf7e5..562d333e155a 100644 --- a/code/builders/builder-vite/src/plugins/code-generator-plugin.ts +++ b/code/builders/builder-vite/src/plugins/code-generator-plugin.ts @@ -15,6 +15,10 @@ import { virtualStoriesFile, } from '../virtual-file-names'; +function resolvedVirtualPath(path: string): string { + return `\0${path}`; +} + export function codeGeneratorPlugin(options: Options): Plugin { const iframePath = require.resolve('@storybook/builder-vite/input/iframe.html'); let iframeId: string; @@ -70,33 +74,33 @@ export function codeGeneratorPlugin(options: Options): Plugin { }, resolveId(source) { if (source === virtualFileId) { - return virtualFileId; + return resolvedVirtualPath(virtualFileId); } if (source === iframePath) { return iframeId; } if (source === virtualStoriesFile) { - return virtualStoriesFile; + return resolvedVirtualPath(virtualStoriesFile); } if (source === virtualPreviewFile) { return virtualPreviewFile; } if (source === virtualAddonSetupFile) { - return virtualAddonSetupFile; + return resolvedVirtualPath(virtualAddonSetupFile); } return undefined; }, async load(id, config) { - if (id === virtualStoriesFile) { + if (id === resolvedVirtualPath(virtualStoriesFile)) { return generateImportFnScriptCode(options); } - if (id === virtualAddonSetupFile) { + if (id === resolvedVirtualPath(virtualAddonSetupFile)) { return generateAddonSetupCode(); } - if (id === virtualFileId) { + if (id === resolvedVirtualPath(virtualFileId)) { return generateModernIframeScriptCode(options, projectRoot); } diff --git a/code/builders/builder-vite/src/virtual-file-names.ts b/code/builders/builder-vite/src/virtual-file-names.ts index 48e7a907f9ae..1cca87308a47 100644 --- a/code/builders/builder-vite/src/virtual-file-names.ts +++ b/code/builders/builder-vite/src/virtual-file-names.ts @@ -1,4 +1,4 @@ -export const virtualFileId = '\0virtual:/@storybook/builder-vite/vite-app.js'; -export const virtualStoriesFile = '\0virtual:/@storybook/builder-vite/storybook-stories.js'; -export const virtualPreviewFile = '\0virtual:/@storybook/builder-vite/preview-entry.js'; -export const virtualAddonSetupFile = '\0virtual:/@storybook/builder-vite/setup-addons.js'; +export const virtualFileId = 'virtual:/@storybook/builder-vite/vite-app.js'; +export const virtualStoriesFile = 'virtual:/@storybook/builder-vite/storybook-stories.js'; +export const virtualPreviewFile = 'virtual:/@storybook/builder-vite/preview-entry.js'; +export const virtualAddonSetupFile = 'virtual:/@storybook/builder-vite/setup-addons.js';