Skip to content
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

Builder-Vite: Add null character prefix to virtual file IDs in code generator plugin #28867

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions code/builders/builder-vite/src/plugins/code-generator-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,33 +74,33 @@ export function codeGeneratorPlugin(options: Options): Plugin {
},
resolveId(source) {
if (source === virtualFileId) {
return `\0${virtualFileId}`;
return resolvedVirtualPath(virtualFileId);
}
if (source === iframePath) {
return iframeId;
}
if (source === virtualStoriesFile) {
return `\0${virtualStoriesFile}`;
return resolvedVirtualPath(virtualStoriesFile);
}
if (source === virtualPreviewFile) {
return virtualPreviewFile;
}
if (source === virtualAddonSetupFile) {
return `\0${virtualAddonSetupFile}`;
return resolvedVirtualPath(virtualAddonSetupFile);
}

return undefined;
},
async load(id, config) {
if (id === `\0${virtualStoriesFile}`) {
if (id === resolvedVirtualPath(virtualStoriesFile)) {
return generateImportFnScriptCode(options);
}

if (id === `\0${virtualAddonSetupFile}`) {
if (id === resolvedVirtualPath(virtualAddonSetupFile)) {
return generateAddonSetupCode();
}

if (id === `\0${virtualFileId}`) {
if (id === resolvedVirtualPath(virtualFileId)) {
return generateModernIframeScriptCode(options, projectRoot);
}

Expand Down
8 changes: 4 additions & 4 deletions code/builders/builder-vite/src/virtual-file-names.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const virtualFileId = '/virtual:/@storybook/builder-vite/vite-app.js';
export const virtualStoriesFile = '/virtual:/@storybook/builder-vite/storybook-stories.js';
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved
export const virtualPreviewFile = '/virtual:/@storybook/builder-vite/preview-entry.js';
export const virtualAddonSetupFile = '/virtual:/@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';
Loading