Skip to content

Commit

Permalink
bypass source-loader if no exports
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jan 17, 2020
1 parent b83dcc9 commit 018b6d2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
@@ -0,0 +1,8 @@
export default {
title: 'Core/Re-export source loader',
};

const Story1 = () => 'story1';
const Story2 = () => 'story2';

export { Story1, Story2 };
17 changes: 14 additions & 3 deletions lib/source-loader/src/server/build.js
Expand Up @@ -3,7 +3,16 @@ import { getRidOfUselessFilePrefixes } from './dependencies-lookup/getRidOfUsele

export function transform(inputSource) {
return readStory(this, inputSource)
.then(getRidOfUselessFilePrefixes)
.then(sourceObject => {
// if source-loader had trouble parsing the story exports, return the original story
// example is
// const myStory = () => xxx
// export { myStory }
if (!sourceObject.source || sourceObject.source.length === 0) {
return { source: inputSource };
}
return getRidOfUselessFilePrefixes(sourceObject);
})
.then(
({
prefix,
Expand All @@ -15,7 +24,8 @@ export function transform(inputSource) {
localDependencies,
idsToFrameworks,
}) => {
const preamble = `
const preamble = prefix
? `
/* eslint-disable */
// @ts-nocheck
// @ts-ignore
Expand All @@ -36,7 +46,8 @@ var __MODULE_DEPENDENCIES__ = ${JSON.stringify(dependencies)};
var __LOCAL_DEPENDENCIES__ = ${JSON.stringify(localDependencies)};
// @ts-ignore
var __IDS_TO_FRAMEWORKS__ = ${JSON.stringify(idsToFrameworks)};
`;
`
: '';
return `${preamble}\n${source}`;
}
);
Expand Down

0 comments on commit 018b6d2

Please sign in to comment.