diff --git a/.babelrc.js b/.babelrc.js index b60cfbe892d7..3579315ef8e6 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -54,7 +54,6 @@ module.exports = { }, { test: './lib', - exclude: './addons/storysource/src/loader', presets: [ ['@babel/preset-env', { shippedProposals: true, useBuiltIns: 'usage', corejs: '3' }], '@babel/preset-react', @@ -75,14 +74,11 @@ module.exports = { }, { test: [ - './lib/core/src/server', './lib/node-logger', './lib/codemod', - './lib/source-loader/src', './addons/storyshots', - './addons/storysource/src/loader', - './app/**/src/server/**', - './app/**/src/bin/**', + '**/src/server/**', + '**/src/bin/**', ], presets: [ [ diff --git a/lib/source-loader/package.json b/lib/source-loader/package.json index b1b4172095ca..eef0be94d44d 100644 --- a/lib/source-loader/package.json +++ b/lib/source-loader/package.json @@ -16,8 +16,8 @@ "directory": "lib/source-loader" }, "license": "MIT", - "main": "dist/index.js", - "jsnext:main": "src/index.js", + "main": "dist/server/index.js", + "jsnext:main": "src/server/index.js", "scripts": { "prepare": "node ../../scripts/prepare.js" }, diff --git a/lib/source-loader/preview.js b/lib/source-loader/preview.js new file mode 100644 index 000000000000..6f5b28b4b66e --- /dev/null +++ b/lib/source-loader/preview.js @@ -0,0 +1 @@ +module.exports = require('./dist/client/preview'); diff --git a/lib/source-loader/src/events.js b/lib/source-loader/src/client/events.js similarity index 100% rename from lib/source-loader/src/events.js rename to lib/source-loader/src/client/events.js diff --git a/lib/source-loader/src/preview.js b/lib/source-loader/src/client/preview.js similarity index 100% rename from lib/source-loader/src/preview.js rename to lib/source-loader/src/client/preview.js diff --git a/lib/source-loader/src/index.js b/lib/source-loader/src/index.js deleted file mode 100644 index bc39d9467511..000000000000 --- a/lib/source-loader/src/index.js +++ /dev/null @@ -1,6 +0,0 @@ -import { transform } from './build'; - -export { STORY_EVENT_ID } from './events'; -export { addSource, withSource } from './preview'; - -export default transform; diff --git a/lib/source-loader/src/abstract-syntax-tree/__snapshots__/inject-decorator.test.js.snap b/lib/source-loader/src/server/abstract-syntax-tree/__snapshots__/inject-decorator.test.js.snap similarity index 99% rename from lib/source-loader/src/abstract-syntax-tree/__snapshots__/inject-decorator.test.js.snap rename to lib/source-loader/src/server/abstract-syntax-tree/__snapshots__/inject-decorator.test.js.snap index 5fb6faca66d6..43d321042705 100644 --- a/lib/source-loader/src/abstract-syntax-tree/__snapshots__/inject-decorator.test.js.snap +++ b/lib/source-loader/src/server/abstract-syntax-tree/__snapshots__/inject-decorator.test.js.snap @@ -866,7 +866,7 @@ storiesOf('Foo', module) `; exports[`inject-decorator will not change the source when there are no "storiesOf" functions 1`] = ` -"var addSourceDecorator = require(\\"@storybook/source-loader/dist/preview\\").addSource; +"var addSourceDecorator = require(\\"@storybook/source-loader/preview\\").addSource; while(true) { console.log(\\"it's a kind of magic\\"); }" diff --git a/lib/source-loader/src/abstract-syntax-tree/default-options.js b/lib/source-loader/src/server/abstract-syntax-tree/default-options.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/default-options.js rename to lib/source-loader/src/server/abstract-syntax-tree/default-options.js diff --git a/lib/source-loader/src/abstract-syntax-tree/generate-helpers.js b/lib/source-loader/src/server/abstract-syntax-tree/generate-helpers.js similarity index 98% rename from lib/source-loader/src/abstract-syntax-tree/generate-helpers.js rename to lib/source-loader/src/server/abstract-syntax-tree/generate-helpers.js index 6ca55dbe9440..0aeb8a23394e 100644 --- a/lib/source-loader/src/abstract-syntax-tree/generate-helpers.js +++ b/lib/source-loader/src/server/abstract-syntax-tree/generate-helpers.js @@ -68,7 +68,7 @@ const STORY_DECORATOR_STATEMENT = const ADD_PARAMETERS_STATEMENT = '.addParameters({ storySource: { source: __STORY__, locationsMap: __ADDS_MAP__ } })'; const IMPORT_DECLARATION_FOR_EXPORTED_STORIES_DECORATOR = - 'var addSourceDecorator = require("@storybook/source-loader/dist/preview").addSource;\n'; + 'var addSourceDecorator = require("@storybook/source-loader/preview").addSource;\n'; const applyExportDecoratorStatement = part => ` addSourceDecorator(${part}, {__STORY__, __ADDS_MAP__,__MAIN_FILE_LOCATION__,__MODULE_DEPENDENCIES__,__LOCAL_DEPENDENCIES__,__SOURCE_PREFIX__,__IDS_TO_FRAMEWORKS__});`; diff --git a/lib/source-loader/src/abstract-syntax-tree/inject-decorator.js b/lib/source-loader/src/server/abstract-syntax-tree/inject-decorator.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/inject-decorator.js rename to lib/source-loader/src/server/abstract-syntax-tree/inject-decorator.js diff --git a/lib/source-loader/src/abstract-syntax-tree/inject-decorator.test.js b/lib/source-loader/src/server/abstract-syntax-tree/inject-decorator.test.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/inject-decorator.test.js rename to lib/source-loader/src/server/abstract-syntax-tree/inject-decorator.test.js diff --git a/lib/source-loader/src/abstract-syntax-tree/parse-helpers.js b/lib/source-loader/src/server/abstract-syntax-tree/parse-helpers.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/parse-helpers.js rename to lib/source-loader/src/server/abstract-syntax-tree/parse-helpers.js diff --git a/lib/source-loader/src/abstract-syntax-tree/parsers/index.js b/lib/source-loader/src/server/abstract-syntax-tree/parsers/index.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/parsers/index.js rename to lib/source-loader/src/server/abstract-syntax-tree/parsers/index.js diff --git a/lib/source-loader/src/abstract-syntax-tree/parsers/parser-flow.js b/lib/source-loader/src/server/abstract-syntax-tree/parsers/parser-flow.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/parsers/parser-flow.js rename to lib/source-loader/src/server/abstract-syntax-tree/parsers/parser-flow.js diff --git a/lib/source-loader/src/abstract-syntax-tree/parsers/parser-js.js b/lib/source-loader/src/server/abstract-syntax-tree/parsers/parser-js.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/parsers/parser-js.js rename to lib/source-loader/src/server/abstract-syntax-tree/parsers/parser-js.js diff --git a/lib/source-loader/src/abstract-syntax-tree/parsers/parser-ts.js b/lib/source-loader/src/server/abstract-syntax-tree/parsers/parser-ts.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/parsers/parser-ts.js rename to lib/source-loader/src/server/abstract-syntax-tree/parsers/parser-ts.js diff --git a/lib/source-loader/src/abstract-syntax-tree/traverse-helpers.js b/lib/source-loader/src/server/abstract-syntax-tree/traverse-helpers.js similarity index 100% rename from lib/source-loader/src/abstract-syntax-tree/traverse-helpers.js rename to lib/source-loader/src/server/abstract-syntax-tree/traverse-helpers.js diff --git a/lib/source-loader/src/build.js b/lib/source-loader/src/server/build.js similarity index 91% rename from lib/source-loader/src/build.js rename to lib/source-loader/src/server/build.js index 2edf97ca3fb0..1b0816c825ca 100644 --- a/lib/source-loader/src/build.js +++ b/lib/source-loader/src/server/build.js @@ -15,7 +15,7 @@ export function transform(inputSource) { localDependencies, idsToFrameworks, }) => ` - var withSourceLoader = require('@storybook/source-loader/dist/preview').withSource; + var withSourceLoader = require('@storybook/source-loader/preview').withSource; var __SOURCE_PREFIX__ = "${prefix.replace(/\\([^\\ ])/g, '\\\\$1')}"; var __STORY__ = ${sourceJson}; var __ADDS_MAP__ = ${JSON.stringify(addsMap)}; diff --git a/lib/source-loader/src/dependencies-lookup/getRidOfUselessFilePrefixes.js b/lib/source-loader/src/server/dependencies-lookup/getRidOfUselessFilePrefixes.js similarity index 100% rename from lib/source-loader/src/dependencies-lookup/getRidOfUselessFilePrefixes.js rename to lib/source-loader/src/server/dependencies-lookup/getRidOfUselessFilePrefixes.js diff --git a/lib/source-loader/src/dependencies-lookup/readAsObject.js b/lib/source-loader/src/server/dependencies-lookup/readAsObject.js similarity index 100% rename from lib/source-loader/src/dependencies-lookup/readAsObject.js rename to lib/source-loader/src/server/dependencies-lookup/readAsObject.js diff --git a/lib/source-loader/src/server/index.js b/lib/source-loader/src/server/index.js new file mode 100644 index 000000000000..42166bb122ce --- /dev/null +++ b/lib/source-loader/src/server/index.js @@ -0,0 +1,3 @@ +import { transform } from './build'; + +export default transform;