Skip to content

Commit

Permalink
Use global.__requireContext directly
Browse files Browse the repository at this point in the history
  • Loading branch information
Hypnosphi committed Nov 25, 2019
1 parent 54a1c0c commit 76c3f3a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions addons/storyshots/storyshots-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"@types/glob": "^7.1.1",
"@types/jest": "^24.0.16",
"@types/jest-specific-snapshot": "^0.5.3",
"babel-plugin-require-context-hook": "^1.0.0",
"core-js": "^3.0.1",
"glob": "^7.1.3",
"global": "^4.3.2",
Expand Down
10 changes: 8 additions & 2 deletions addons/storyshots/storyshots-core/src/frameworks/configure.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import fs from 'fs';
import path from 'path';
import { toRequireContext } from '@storybook/core/server';
import registerRequireContextHook from 'babel-plugin-require-context-hook/register';
import global from 'global';
import { ClientApi } from './Loader';
import { StoryshotsOptions } from '../api/StoryshotsOptions';

registerRequireContextHook();

const isFile = (file: string): boolean => {
try {
return fs.lstatSync(file).isFile();
Expand Down Expand Up @@ -67,8 +71,10 @@ function getConfigPathParts(input: string): Output {
output.stories = stories.map(
(pattern: string | { path: string; recursive: boolean; match: string }) => {
const { path: basePath, recursive, match } = toRequireContext(pattern);
return require.context(
path.resolve(configDir, basePath),
// eslint-disable-next-line no-underscore-dangle
return global.__requireContext(
configDir,
basePath,
recursive,
new RegExp(match.slice(1, -1))
);
Expand Down
1 change: 1 addition & 0 deletions addons/storyshots/storyshots-core/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ declare module 'jest-preset-angular/*';
declare module 'preact-render-to-json';
declare module 'react-test-renderer*';
declare module '@storybook/core/server';
declare module 'babel-plugin-require-context-hook/register';

0 comments on commit 76c3f3a

Please sign in to comment.