Merge pull request #8971 from storybookjs/revert-require-ts

Don't try to require .ts files from dist
This commit is contained in:
Filipp Riabchun 2019-11-26 23:13:22 +01:00 committed by GitHub
commit 469bae66c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 16 additions and 18 deletions

View File

@ -4,7 +4,7 @@ import path from 'path';
import { Loader } from './Loader';
import { StoryshotsOptions } from '../api/StoryshotsOptions';
const loaderScriptName = 'loader';
const loaderScriptName = 'loader.js';
const isDirectory = (source: string) => fs.lstatSync(source).isDirectory();
@ -13,13 +13,7 @@ function getLoaders(): Loader[] {
.readdirSync(__dirname)
.map(name => path.join(__dirname, name))
.filter(isDirectory)
.reduce((acc, framework) => {
const filename = path.join(framework, loaderScriptName);
const jsFile = `${filename}.js`;
const tsFile = `${filename}.ts`;
return acc.concat([jsFile, tsFile]);
}, [] as string[])
.map(framework => path.join(framework, loaderScriptName))
.filter(fs.existsSync)
.map(loader => require(loader).default);
}

View File

@ -1,7 +1,7 @@
import path from 'path';
import { mount } from 'enzyme';
import toJson from 'enzyme-to-json';
import initStoryshots, { Stories2SnapsConverter } from '../src';
import initStoryshots, { Stories2SnapsConverter } from '../dist';
import { TIMEOUT, EXPECTED_VALUE } from './required_with_context/Async.stories';
initStoryshots({

View File

@ -1,5 +1,5 @@
import path from 'path';
import initStoryshots, { multiSnapshotWithOptions, Stories2SnapsConverter } from '../src';
import initStoryshots, { multiSnapshotWithOptions, Stories2SnapsConverter } from '../dist';
class AnotherStories2SnapsConverter extends Stories2SnapsConverter {
getSnapshotFileName(context) {

View File

@ -2,7 +2,7 @@ import path from 'path';
import { mount } from 'enzyme';
import { createSerializer as enzymeSerializer } from 'enzyme-to-json';
import { createSerializer as emotionSerializer } from 'jest-emotion';
import initStoryshots from '../src';
import initStoryshots from '../dist';
initStoryshots({
framework: 'react',

View File

@ -1,5 +1,5 @@
import path from 'path';
import initStoryshots, { renderOnly } from '../src';
import initStoryshots, { renderOnly } from '../dist';
initStoryshots({
framework: 'react',

View File

@ -1,5 +1,5 @@
import path from 'path';
import initStoryshots, { renderWithOptions } from '../src';
import initStoryshots, { renderWithOptions } from '../dist';
initStoryshots({
framework: 'react',

View File

@ -1,5 +1,5 @@
import path from 'path';
import initStoryshots, { shallowSnapshot } from '../src';
import initStoryshots, { shallowSnapshot } from '../dist';
initStoryshots({
framework: 'react',

View File

@ -1,5 +1,5 @@
import path from 'path';
import initStoryshots, { shallowSnapshot } from '../src';
import initStoryshots, { shallowSnapshot } from '../dist';
initStoryshots({
framework: 'react',

View File

@ -1,5 +1,5 @@
import path from 'path';
import initStoryshots, { snapshotWithOptions } from '../src';
import initStoryshots, { snapshotWithOptions } from '../dist';
initStoryshots({
framework: 'react',

View File

@ -1,5 +1,5 @@
import path from 'path';
import initStoryshots, { multiSnapshotWithOptions, Stories2SnapsConverter } from '../src';
import initStoryshots, { multiSnapshotWithOptions, Stories2SnapsConverter } from '../dist';
initStoryshots({
framework: 'react',

View File

@ -1,5 +1,5 @@
import path from 'path';
import initStoryshots, { multiSnapshotWithOptions } from '../src';
import initStoryshots, { multiSnapshotWithOptions } from '../dist';
jest.mock('@storybook/node-logger');

View File

@ -27,6 +27,10 @@ function cleanup() {
// https://github.com/babel/babel/issues/6226
if (fs.existsSync(path.join(process.cwd(), 'dist'))) {
const files = shell.find('dist').filter(filePath => {
// Remove all copied TS files (but not the .d.ts)
if (/\.tsx?$/.test(filePath) && !/\.d\.ts$/.test(filePath)) {
return true;
}
if (fs.lstatSync(filePath).isDirectory()) {
return false;
}