Skip to content

Commit

Permalink
Storysource: Allow to co-exist with csf-plugin/addon-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
shilman committed Jan 26, 2023
1 parent 1e14da3 commit 8bae863
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
1 change: 0 additions & 1 deletion code/addons/storysource/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function webpack(
{
test: [/\.stories\.(jsx?$|tsx?$)/],
...rule,
enforce: 'pre',
use: [
{
loader: require.resolve('@storybook/source-loader'),
Expand Down
8 changes: 7 additions & 1 deletion code/lib/source-loader/src/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { readFile } from 'fs/promises';
import { readStory } from './dependencies-lookup/readAsObject';
import { sanitizeSource } from './abstract-syntax-tree/generate-helpers';

export async function transform(inputSource) {
const sourceObject = await readStory(this, inputSource);
Expand All @@ -13,11 +15,15 @@ export async function transform(inputSource) {

const { source, sourceJson, addsMap } = sourceObject;

// We do this so the source we display doesn't get clobbered by csf-plugin
const rawSource = await readFile(this.resourcePath, 'utf-8');
const rawJson = sanitizeSource(rawSource);

const preamble = `
/* eslint-disable */
// @ts-nocheck
// @ts-expect-error (Converted from ts-ignore)
var __STORY__ = ${sourceJson};
var __STORY__ = ${rawJson};
// @ts-expect-error (Converted from ts-ignore)
var __LOCATIONS_MAP__ = ${JSON.stringify(addsMap, null, 2).trim()};
`;
Expand Down

0 comments on commit 8bae863

Please sign in to comment.