@storybook/core-common 6.4.0-beta.3 → 6.4.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.globToRegex = globToRegex;
7
+
8
+ var _micromatch = require("micromatch");
9
+
10
+ function globToRegex(glob) {
11
+ var regex = (0, _micromatch.makeRe)(glob, {
12
+ fastpaths: false,
13
+ noglobstar: false,
14
+ bash: false
15
+ });
16
+
17
+ if (!regex.source.startsWith('^')) {
18
+ throw new Error(`Invalid glob: >> ${glob} >> ${regex}`);
19
+ }
20
+
21
+ if (!glob.startsWith('./')) {
22
+ return regex;
23
+ } // makeRe is sort of funny. If you pass it a directory starting with `./` it
24
+ // creates a matcher that expects files with no prefix (e.g. `src/file.js`)
25
+ // but if you pass it a directory that starts with `../` it expects files that
26
+ // start with `../`. Let's make it consistent.
27
+ // Globs starting `**` require special treatment due to the regex they
28
+ // produce, specifically a negative look-ahead
29
+
30
+
31
+ return new RegExp(['^\\.', glob.startsWith('./**') ? '' : '\\/', regex.source.substring(1)].join(''));
32
+ }
@@ -3,12 +3,22 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.normalizeStories = exports.normalizeDirectory = exports.normalizeStoriesEntry = void 0;
6
+ exports.normalizeStories = exports.normalizeStoriesEntry = void 0;
7
7
 
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
 
10
10
  var _path = _interopRequireDefault(require("path"));
11
11
 
12
+ var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
13
+
14
+ var _tsDedent = _interopRequireDefault(require("ts-dedent"));
15
+
16
+ var _micromatch = require("micromatch");
17
+
18
+ var _slash = _interopRequireDefault(require("slash"));
19
+
20
+ var _globToRegexp = require("./glob-to-regexp");
21
+
12
22
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
23
 
14
24
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
@@ -17,11 +27,24 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
17
27
 
18
28
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
19
29
 
20
- var DEFAULT_FILES = '*.stories.@(mdx|tsx|ts|jsx|js)';
21
- var DEFAULT_TITLE_PREFIX = ''; // Escaping regexes for glob regexes is fun
22
- // Mathing things like '../**/*.stories.mdx'
30
+ var DEFAULT_TITLE_PREFIX = '';
31
+ var DEFAULT_FILES = '**/*.stories.@(mdx|tsx|ts|jsx|js)'; // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
32
+
33
+ var fixBadGlob = (0, _utilDeprecate.default)(function (match) {
34
+ return match.input.replace(match[1], `@${match[1]}`);
35
+ }, (0, _tsDedent.default)`
36
+ You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
37
+ `);
23
38
 
24
- var GLOB_REGEX = /^(?<directory>[^*]*)\/\*\*\/(?<files>\*\..*)/;
39
+ var detectBadGlob = function (val) {
40
+ var match = val.match(/\.(\([^)]+\))/);
41
+
42
+ if (match) {
43
+ return fixBadGlob(match);
44
+ }
45
+
46
+ return val;
47
+ };
25
48
 
26
49
  var isDirectory = function (configDir, entry) {
27
50
  try {
@@ -31,87 +54,81 @@ var isDirectory = function (configDir, entry) {
31
54
  }
32
55
  };
33
56
 
34
- var normalizeStoriesEntry = function (entry, configDir) {
35
- var glob;
36
- var directory;
37
- var files;
38
- var titlePrefix;
57
+ var normalizeStoriesEntry = function (entry, {
58
+ configDir: configDir,
59
+ workingDir: workingDir
60
+ }) {
61
+ var specifierWithoutMatcher;
39
62
 
40
63
  if (typeof entry === 'string') {
41
- if (!entry.includes('**') && isDirectory(configDir, entry)) {
42
- directory = entry;
43
- files = DEFAULT_FILES;
44
- titlePrefix = DEFAULT_TITLE_PREFIX;
45
- } else {
46
- var match = entry.match(GLOB_REGEX);
47
-
48
- if (match) {
49
- directory = match.groups.directory;
50
- files = match.groups.files;
51
- titlePrefix = DEFAULT_TITLE_PREFIX;
64
+ if (!entry.includes('*')) {
65
+ if (isDirectory(configDir, entry)) {
66
+ specifierWithoutMatcher = {
67
+ titlePrefix: DEFAULT_TITLE_PREFIX,
68
+ directory: entry,
69
+ files: DEFAULT_FILES
70
+ };
52
71
  } else {
53
- glob = entry;
72
+ specifierWithoutMatcher = {
73
+ titlePrefix: DEFAULT_TITLE_PREFIX,
74
+ directory: _path.default.dirname(entry),
75
+ files: _path.default.basename(entry)
76
+ };
54
77
  }
55
- }
56
- } else {
57
- directory = entry.directory;
58
- files = entry.files || DEFAULT_FILES;
59
- titlePrefix = entry.titlePrefix || DEFAULT_TITLE_PREFIX;
60
- }
78
+ } else {
79
+ var fixedEntry = detectBadGlob(entry);
80
+ var globResult = (0, _micromatch.scan)(fixedEntry);
61
81
 
62
- if (typeof glob !== 'undefined') {
63
- return {
64
- glob: glob,
65
- specifier: undefined
66
- };
67
- }
82
+ var _directory = globResult.isGlob ? globResult.prefix + globResult.base : _path.default.dirname(fixedEntry);
83
+
84
+ var filesFallback = _directory !== '.' ? fixedEntry.substr(_directory.length + 1) : fixedEntry;
68
85
 
69
- return {
70
- glob: `${directory}/**/${files}`,
71
- specifier: {
72
- directory: directory,
73
- titlePrefix: titlePrefix,
74
- files: files
86
+ var _files = globResult.isGlob ? globResult.glob : filesFallback;
87
+
88
+ specifierWithoutMatcher = {
89
+ titlePrefix: DEFAULT_TITLE_PREFIX,
90
+ directory: _directory,
91
+ files: _files
92
+ };
75
93
  }
76
- };
77
- };
94
+ } else {
95
+ specifierWithoutMatcher = _objectSpread({
96
+ titlePrefix: DEFAULT_TITLE_PREFIX,
97
+ files: DEFAULT_FILES
98
+ }, entry);
99
+ } // We are going to be doing everything with node importPaths which use
100
+ // URL format, i.e. `/` as a separator, so let's make sure we've normalized
78
101
 
79
- exports.normalizeStoriesEntry = normalizeStoriesEntry;
80
102
 
81
- /**
82
- * Stories entries are specified relative to the configDir. Webpack filenames are produced relative to the
83
- * current working directory. This function rewrites the specifier.directory relative to the current working
84
- * directory.
85
- */
86
- var normalizeDirectory = function (entry, {
87
- configDir: configDir,
88
- workingDir: workingDir
89
- }) {
90
- if (!entry.specifier) return entry;
91
- var directory = entry.specifier.directory;
103
+ var files = (0, _slash.default)(specifierWithoutMatcher.files); // At this stage `directory` is relative to `main.js` (the config dir)
104
+ // We want to work relative to the working dir, so we transform it here.
92
105
 
93
- var directoryFromConfig = _path.default.resolve(configDir, directory);
106
+ var _specifierWithoutMatc = specifierWithoutMatcher,
107
+ directoryRelativeToConfig = _specifierWithoutMatc.directory;
94
108
 
95
- var directoryFromWorking = _path.default.relative(workingDir, directoryFromConfig); // relative('/foo', '/foo/src') => 'src'
96
- // but we want `./src`to match webpack's file names
109
+ var absoluteDirectory = _path.default.resolve(configDir, directoryRelativeToConfig);
97
110
 
111
+ var directory = (0, _slash.default)(_path.default.relative(workingDir, absoluteDirectory)); // relative('/foo', '/foo/src') => 'src'
112
+ // but we want `./src` to match importPaths
98
113
 
99
- if (!directoryFromWorking.startsWith('.')) {
100
- directoryFromWorking = `.${_path.default.sep}${directoryFromWorking}`;
114
+ if (!directory.startsWith('.')) {
115
+ directory = `./${directory}`;
101
116
  }
102
117
 
103
- return _objectSpread(_objectSpread({}, entry), {}, {
104
- specifier: _objectSpread(_objectSpread({}, entry.specifier), {}, {
105
- directory: directoryFromWorking
106
- })
118
+ directory = directory.replace(/\/$/, ''); // Now make the importFn matcher.
119
+
120
+ var importPathMatcher = (0, _globToRegexp.globToRegex)(`${directory}/${files}`);
121
+ return _objectSpread(_objectSpread({}, specifierWithoutMatcher), {}, {
122
+ directory: directory,
123
+ importPathMatcher: importPathMatcher
107
124
  });
108
125
  };
109
126
 
110
- exports.normalizeDirectory = normalizeDirectory;
127
+ exports.normalizeStoriesEntry = normalizeStoriesEntry;
111
128
 
112
129
  var normalizeStories = function (entries, options) {
113
130
  return entries.map(function (entry) {
114
- return normalizeDirectory(normalizeStoriesEntry(entry, options.configDir), options);
131
+ return normalizeStoriesEntry(entry, options);
115
132
  });
116
133
  };
117
134
 
@@ -35,6 +35,7 @@ var useProgressReporting = async function (router, startTime, options) {
35
35
  reportProgress = function (progress) {
36
36
  if (closed || response.writableEnded) return;
37
37
  response.write(`data: ${JSON.stringify(progress)}\n\n`);
38
+ response.flush();
38
39
  if (progress.value === 1) close();
39
40
  };
40
41
  });
@@ -8,30 +8,27 @@ exports.toImportFn = toImportFn;
8
8
 
9
9
  var _tsDedent = _interopRequireDefault(require("ts-dedent"));
10
10
 
11
- var _ = require("..");
12
-
13
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
12
 
15
- function toImportFnPart(entry) {
16
- var _toRequireContext = (0, _.toRequireContext)(entry.glob),
17
- base = _toRequireContext.path,
18
- regex = _toRequireContext.regex;
13
+ function toImportFnPart(specifier) {
14
+ var directory = specifier.directory,
15
+ importPathMatcher = specifier.importPathMatcher; // It appears webpack passes *something* similar to the absolute path to the file
16
+ // on disk (prefixed with something unknown) to the matcher.
17
+ // We don't want to include the absolute path in our bundle, so we will just pull the
18
+ // '^' and any leading '.' off the regexp and match on that.
19
+ // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
19
20
 
20
- var webpackIncludeRegex = new RegExp(regex.source.substring(1));
21
+ var webpackIncludeRegex = new RegExp(importPathMatcher.source.replace(/^\^\\\.*/, ''));
21
22
  return (0, _tsDedent.default)`
22
23
  async (path) => {
23
- const pathBase = path.substring(0, ${base.length + 1});
24
- if (pathBase !== '${base}/') {
24
+ if (!${importPathMatcher}.exec(path)) {
25
25
  return;
26
26
  }
27
27
 
28
- const pathRemainder = path.substring(${base.length + 1});
29
- if (!${regex}.exec(pathRemainder)) {
30
- return;
31
- }
28
+ const pathRemainder = path.substring(${directory.length + 1});
32
29
  return import(
33
30
  /* webpackInclude: ${webpackIncludeRegex} */
34
- '${base}/' + pathRemainder
31
+ '${directory}/' + pathRemainder
35
32
  );
36
33
  }
37
34
 
@@ -5,92 +5,30 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.toRequireContextString = exports.toRequireContext = void 0;
7
7
 
8
- var _micromatch = require("micromatch");
9
-
10
- var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
11
-
12
- var _tsDedent = _interopRequireDefault(require("ts-dedent"));
13
-
14
- var _path = _interopRequireDefault(require("path"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
19
- var fixBadGlob = (0, _utilDeprecate.default)(function (match) {
20
- return match.input.replace(match[1], `@${match[1]}`);
21
- }, (0, _tsDedent.default)`
22
- You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
23
- `);
24
-
25
- var detectBadGlob = function (val) {
26
- var match = val.match(/\.(\([^)]+\))/);
27
-
28
- if (match) {
29
- return fixBadGlob(match);
30
- }
31
-
32
- return val;
33
- };
34
-
35
- var isObject = function (val) {
36
- return val != null && typeof val === 'object' && Array.isArray(val) === false;
37
- };
38
-
39
- var toRequireContext = function (input) {
40
- var fixedInput = detectBadGlob(input);
41
-
42
- switch (true) {
43
- case typeof input === 'string':
44
- {
45
- var globResult = (0, _micromatch.scan)(fixedInput);
46
- var base = globResult.isGlob ? globResult.prefix + globResult.base : _path.default.dirname(fixedInput);
47
- var globFallback = base !== '.' ? fixedInput.substr(base.length + 1) : fixedInput;
48
- var glob = globResult.isGlob ? globResult.glob : globFallback;
49
- var regex = (0, _micromatch.makeRe)(glob, {
50
- fastpaths: false,
51
- noglobstar: false,
52
- bash: false
53
- });
54
- var source = regex.source;
55
-
56
- if (source.startsWith('^')) {
57
- // webpack's require.context matches against paths starting `./`
58
- // Globs starting `**` require special treatment due to the regex they
59
- // produce, specifically a negative look-ahead
60
- var match = ['^\\.', glob.startsWith('**') ? '' : '\\/', source.substring(1)].join('');
61
- var recursive = glob.includes('**') || glob.split('/').length > 1;
62
- return {
63
- path: base,
64
- recursive: recursive,
65
- match: match,
66
- regex: regex
67
- };
68
- }
69
-
70
- throw new Error(`Invalid glob: >> ${input} >> ${regex}`);
71
- }
72
-
73
- case isObject(input):
74
- {
75
- return input;
76
- }
77
-
78
- default:
79
- {
80
- throw new Error('the provided input cannot be transformed into a require.context');
81
- }
82
- }
8
+ var _globToRegexp = require("./glob-to-regexp");
9
+
10
+ var toRequireContext = function (specifier) {
11
+ var directory = specifier.directory,
12
+ files = specifier.files; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
13
+ // For `require.context()` we want the same thing, relative to directory
14
+
15
+ var match = (0, _globToRegexp.globToRegex)(`./${files}`);
16
+ return {
17
+ path: directory,
18
+ recursive: !!files.match(/^\*{1,2}\//),
19
+ match: match
20
+ };
83
21
  };
84
22
 
85
23
  exports.toRequireContext = toRequireContext;
86
24
 
87
- var toRequireContextString = function (input) {
88
- var _toRequireContext = toRequireContext(input),
25
+ var toRequireContextString = function (specifier) {
26
+ var _toRequireContext = toRequireContext(specifier),
89
27
  p = _toRequireContext.path,
90
28
  r = _toRequireContext.recursive,
91
29
  m = _toRequireContext.match;
92
30
 
93
- var result = `require.context('${p}', ${r}, /${m}/)`;
31
+ var result = `require.context('${p}', ${r}, ${m})`;
94
32
  return result;
95
33
  };
96
34
 
@@ -0,0 +1,24 @@
1
+ import { makeRe } from 'micromatch';
2
+ export function globToRegex(glob) {
3
+ var regex = makeRe(glob, {
4
+ fastpaths: false,
5
+ noglobstar: false,
6
+ bash: false
7
+ });
8
+
9
+ if (!regex.source.startsWith('^')) {
10
+ throw new Error(`Invalid glob: >> ${glob} >> ${regex}`);
11
+ }
12
+
13
+ if (!glob.startsWith('./')) {
14
+ return regex;
15
+ } // makeRe is sort of funny. If you pass it a directory starting with `./` it
16
+ // creates a matcher that expects files with no prefix (e.g. `src/file.js`)
17
+ // but if you pass it a directory that starts with `../` it expects files that
18
+ // start with `../`. Let's make it consistent.
19
+ // Globs starting `**` require special treatment due to the regex they
20
+ // produce, specifically a negative look-ahead
21
+
22
+
23
+ return new RegExp(['^\\.', glob.startsWith('./**') ? '' : '\\/', regex.source.substring(1)].join(''));
24
+ }
@@ -6,11 +6,29 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  import fs from 'fs';
8
8
  import path from 'path';
9
- var DEFAULT_FILES = '*.stories.@(mdx|tsx|ts|jsx|js)';
10
- var DEFAULT_TITLE_PREFIX = ''; // Escaping regexes for glob regexes is fun
11
- // Mathing things like '../**/*.stories.mdx'
9
+ import deprecate from 'util-deprecate';
10
+ import dedent from 'ts-dedent';
11
+ import { scan } from 'micromatch';
12
+ import slash from 'slash';
13
+ import { globToRegex } from './glob-to-regexp';
14
+ var DEFAULT_TITLE_PREFIX = '';
15
+ var DEFAULT_FILES = '**/*.stories.@(mdx|tsx|ts|jsx|js)'; // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
12
16
 
13
- var GLOB_REGEX = /^(?<directory>[^*]*)\/\*\*\/(?<files>\*\..*)/;
17
+ var fixBadGlob = deprecate(function (match) {
18
+ return match.input.replace(match[1], `@${match[1]}`);
19
+ }, dedent`
20
+ You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
21
+ `);
22
+
23
+ var detectBadGlob = function (val) {
24
+ var match = val.match(/\.(\([^)]+\))/);
25
+
26
+ if (match) {
27
+ return fixBadGlob(match);
28
+ }
29
+
30
+ return val;
31
+ };
14
32
 
15
33
  var isDirectory = function (configDir, entry) {
16
34
  try {
@@ -20,78 +38,75 @@ var isDirectory = function (configDir, entry) {
20
38
  }
21
39
  };
22
40
 
23
- export var normalizeStoriesEntry = function (entry, configDir) {
24
- var glob;
25
- var directory;
26
- var files;
27
- var titlePrefix;
41
+ export var normalizeStoriesEntry = function (entry, {
42
+ configDir: configDir,
43
+ workingDir: workingDir
44
+ }) {
45
+ var specifierWithoutMatcher;
28
46
 
29
47
  if (typeof entry === 'string') {
30
- if (!entry.includes('**') && isDirectory(configDir, entry)) {
31
- directory = entry;
32
- files = DEFAULT_FILES;
33
- titlePrefix = DEFAULT_TITLE_PREFIX;
34
- } else {
35
- var match = entry.match(GLOB_REGEX);
36
-
37
- if (match) {
38
- directory = match.groups.directory;
39
- files = match.groups.files;
40
- titlePrefix = DEFAULT_TITLE_PREFIX;
48
+ if (!entry.includes('*')) {
49
+ if (isDirectory(configDir, entry)) {
50
+ specifierWithoutMatcher = {
51
+ titlePrefix: DEFAULT_TITLE_PREFIX,
52
+ directory: entry,
53
+ files: DEFAULT_FILES
54
+ };
41
55
  } else {
42
- glob = entry;
56
+ specifierWithoutMatcher = {
57
+ titlePrefix: DEFAULT_TITLE_PREFIX,
58
+ directory: path.dirname(entry),
59
+ files: path.basename(entry)
60
+ };
43
61
  }
62
+ } else {
63
+ var fixedEntry = detectBadGlob(entry);
64
+ var globResult = scan(fixedEntry);
65
+
66
+ var _directory = globResult.isGlob ? globResult.prefix + globResult.base : path.dirname(fixedEntry);
67
+
68
+ var filesFallback = _directory !== '.' ? fixedEntry.substr(_directory.length + 1) : fixedEntry;
69
+
70
+ var _files = globResult.isGlob ? globResult.glob : filesFallback;
71
+
72
+ specifierWithoutMatcher = {
73
+ titlePrefix: DEFAULT_TITLE_PREFIX,
74
+ directory: _directory,
75
+ files: _files
76
+ };
44
77
  }
45
78
  } else {
46
- directory = entry.directory;
47
- files = entry.files || DEFAULT_FILES;
48
- titlePrefix = entry.titlePrefix || DEFAULT_TITLE_PREFIX;
49
- }
79
+ specifierWithoutMatcher = _objectSpread({
80
+ titlePrefix: DEFAULT_TITLE_PREFIX,
81
+ files: DEFAULT_FILES
82
+ }, entry);
83
+ } // We are going to be doing everything with node importPaths which use
84
+ // URL format, i.e. `/` as a separator, so let's make sure we've normalized
50
85
 
51
- if (typeof glob !== 'undefined') {
52
- return {
53
- glob: glob,
54
- specifier: undefined
55
- };
56
- }
57
86
 
58
- return {
59
- glob: `${directory}/**/${files}`,
60
- specifier: {
61
- directory: directory,
62
- titlePrefix: titlePrefix,
63
- files: files
64
- }
65
- };
66
- };
87
+ var files = slash(specifierWithoutMatcher.files); // At this stage `directory` is relative to `main.js` (the config dir)
88
+ // We want to work relative to the working dir, so we transform it here.
67
89
 
68
- /**
69
- * Stories entries are specified relative to the configDir. Webpack filenames are produced relative to the
70
- * current working directory. This function rewrites the specifier.directory relative to the current working
71
- * directory.
72
- */
73
- export var normalizeDirectory = function (entry, {
74
- configDir: configDir,
75
- workingDir: workingDir
76
- }) {
77
- if (!entry.specifier) return entry;
78
- var directory = entry.specifier.directory;
79
- var directoryFromConfig = path.resolve(configDir, directory);
80
- var directoryFromWorking = path.relative(workingDir, directoryFromConfig); // relative('/foo', '/foo/src') => 'src'
81
- // but we want `./src`to match webpack's file names
82
-
83
- if (!directoryFromWorking.startsWith('.')) {
84
- directoryFromWorking = `.${path.sep}${directoryFromWorking}`;
90
+ var _specifierWithoutMatc = specifierWithoutMatcher,
91
+ directoryRelativeToConfig = _specifierWithoutMatc.directory;
92
+ var absoluteDirectory = path.resolve(configDir, directoryRelativeToConfig);
93
+ var directory = slash(path.relative(workingDir, absoluteDirectory)); // relative('/foo', '/foo/src') => 'src'
94
+ // but we want `./src` to match importPaths
95
+
96
+ if (!directory.startsWith('.')) {
97
+ directory = `./${directory}`;
85
98
  }
86
99
 
87
- return _objectSpread(_objectSpread({}, entry), {}, {
88
- specifier: _objectSpread(_objectSpread({}, entry.specifier), {}, {
89
- directory: directoryFromWorking
90
- })
100
+ directory = directory.replace(/\/$/, ''); // Now make the importFn matcher.
101
+
102
+ var importPathMatcher = globToRegex(`${directory}/${files}`);
103
+ return _objectSpread(_objectSpread({}, specifierWithoutMatcher), {}, {
104
+ directory: directory,
105
+ importPathMatcher: importPathMatcher
91
106
  });
92
107
  };
93
108
  export var normalizeStories = function (entries, options) {
94
109
  return entries.map(function (entry) {
95
- return normalizeDirectory(normalizeStoriesEntry(entry, options.configDir), options);
110
+ return normalizeStoriesEntry(entry, options);
96
111
  });
97
112
  };
@@ -26,6 +26,7 @@ export var useProgressReporting = async function (router, startTime, options) {
26
26
  reportProgress = function (progress) {
27
27
  if (closed || response.writableEnded) return;
28
28
  response.write(`data: ${JSON.stringify(progress)}\n\n`);
29
+ response.flush();
29
30
  if (progress.value === 1) close();
30
31
  };
31
32
  });
@@ -1,25 +1,23 @@
1
1
  import dedent from 'ts-dedent';
2
- import { toRequireContext } from '..';
3
- export function toImportFnPart(entry) {
4
- var _toRequireContext = toRequireContext(entry.glob),
5
- base = _toRequireContext.path,
6
- regex = _toRequireContext.regex;
2
+ export function toImportFnPart(specifier) {
3
+ var directory = specifier.directory,
4
+ importPathMatcher = specifier.importPathMatcher; // It appears webpack passes *something* similar to the absolute path to the file
5
+ // on disk (prefixed with something unknown) to the matcher.
6
+ // We don't want to include the absolute path in our bundle, so we will just pull the
7
+ // '^' and any leading '.' off the regexp and match on that.
8
+ // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
7
9
 
8
- var webpackIncludeRegex = new RegExp(regex.source.substring(1));
10
+ var webpackIncludeRegex = new RegExp(importPathMatcher.source.replace(/^\^\\\.*/, ''));
9
11
  return dedent`
10
12
  async (path) => {
11
- const pathBase = path.substring(0, ${base.length + 1});
12
- if (pathBase !== '${base}/') {
13
+ if (!${importPathMatcher}.exec(path)) {
13
14
  return;
14
15
  }
15
16
 
16
- const pathRemainder = path.substring(${base.length + 1});
17
- if (!${regex}.exec(pathRemainder)) {
18
- return;
19
- }
17
+ const pathRemainder = path.substring(${directory.length + 1});
20
18
  return import(
21
19
  /* webpackInclude: ${webpackIncludeRegex} */
22
- '${base}/' + pathRemainder
20
+ '${directory}/' + pathRemainder
23
21
  );
24
22
  }
25
23
 
@@ -1,79 +1,22 @@
1
- import { makeRe, scan } from 'micromatch';
2
- import deprecate from 'util-deprecate';
3
- import dedent from 'ts-dedent';
4
- import path from 'path'; // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
5
-
6
- var fixBadGlob = deprecate(function (match) {
7
- return match.input.replace(match[1], `@${match[1]}`);
8
- }, dedent`
9
- You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
10
- `);
11
-
12
- var detectBadGlob = function (val) {
13
- var match = val.match(/\.(\([^)]+\))/);
14
-
15
- if (match) {
16
- return fixBadGlob(match);
17
- }
18
-
19
- return val;
20
- };
21
-
22
- var isObject = function (val) {
23
- return val != null && typeof val === 'object' && Array.isArray(val) === false;
24
- };
25
-
26
- export var toRequireContext = function (input) {
27
- var fixedInput = detectBadGlob(input);
28
-
29
- switch (true) {
30
- case typeof input === 'string':
31
- {
32
- var globResult = scan(fixedInput);
33
- var base = globResult.isGlob ? globResult.prefix + globResult.base : path.dirname(fixedInput);
34
- var globFallback = base !== '.' ? fixedInput.substr(base.length + 1) : fixedInput;
35
- var glob = globResult.isGlob ? globResult.glob : globFallback;
36
- var regex = makeRe(glob, {
37
- fastpaths: false,
38
- noglobstar: false,
39
- bash: false
40
- });
41
- var source = regex.source;
42
-
43
- if (source.startsWith('^')) {
44
- // webpack's require.context matches against paths starting `./`
45
- // Globs starting `**` require special treatment due to the regex they
46
- // produce, specifically a negative look-ahead
47
- var match = ['^\\.', glob.startsWith('**') ? '' : '\\/', source.substring(1)].join('');
48
- var recursive = glob.includes('**') || glob.split('/').length > 1;
49
- return {
50
- path: base,
51
- recursive: recursive,
52
- match: match,
53
- regex: regex
54
- };
55
- }
56
-
57
- throw new Error(`Invalid glob: >> ${input} >> ${regex}`);
58
- }
59
-
60
- case isObject(input):
61
- {
62
- return input;
63
- }
64
-
65
- default:
66
- {
67
- throw new Error('the provided input cannot be transformed into a require.context');
68
- }
69
- }
1
+ import { globToRegex } from './glob-to-regexp';
2
+ export var toRequireContext = function (specifier) {
3
+ var directory = specifier.directory,
4
+ files = specifier.files; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
5
+ // For `require.context()` we want the same thing, relative to directory
6
+
7
+ var match = globToRegex(`./${files}`);
8
+ return {
9
+ path: directory,
10
+ recursive: !!files.match(/^\*{1,2}\//),
11
+ match: match
12
+ };
70
13
  };
71
- export var toRequireContextString = function (input) {
72
- var _toRequireContext = toRequireContext(input),
14
+ export var toRequireContextString = function (specifier) {
15
+ var _toRequireContext = toRequireContext(specifier),
73
16
  p = _toRequireContext.path,
74
17
  r = _toRequireContext.recursive,
75
18
  m = _toRequireContext.match;
76
19
 
77
- var result = `require.context('${p}', ${r}, /${m}/)`;
20
+ var result = `require.context('${p}', ${r}, ${m})`;
78
21
  return result;
79
22
  };
@@ -0,0 +1,24 @@
1
+ import { makeRe } from 'micromatch';
2
+ export function globToRegex(glob) {
3
+ var regex = makeRe(glob, {
4
+ fastpaths: false,
5
+ noglobstar: false,
6
+ bash: false
7
+ });
8
+
9
+ if (!regex.source.startsWith('^')) {
10
+ throw new Error(`Invalid glob: >> ${glob} >> ${regex}`);
11
+ }
12
+
13
+ if (!glob.startsWith('./')) {
14
+ return regex;
15
+ } // makeRe is sort of funny. If you pass it a directory starting with `./` it
16
+ // creates a matcher that expects files with no prefix (e.g. `src/file.js`)
17
+ // but if you pass it a directory that starts with `../` it expects files that
18
+ // start with `../`. Let's make it consistent.
19
+ // Globs starting `**` require special treatment due to the regex they
20
+ // produce, specifically a negative look-ahead
21
+
22
+
23
+ return new RegExp(['^\\.', glob.startsWith('./**') ? '' : '\\/', regex.source.substring(1)].join(''));
24
+ }
@@ -6,11 +6,29 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  import fs from 'fs';
8
8
  import path from 'path';
9
- var DEFAULT_FILES = '*.stories.@(mdx|tsx|ts|jsx|js)';
10
- var DEFAULT_TITLE_PREFIX = ''; // Escaping regexes for glob regexes is fun
11
- // Mathing things like '../**/*.stories.mdx'
9
+ import deprecate from 'util-deprecate';
10
+ import dedent from 'ts-dedent';
11
+ import { scan } from 'micromatch';
12
+ import slash from 'slash';
13
+ import { globToRegex } from './glob-to-regexp';
14
+ var DEFAULT_TITLE_PREFIX = '';
15
+ var DEFAULT_FILES = '**/*.stories.@(mdx|tsx|ts|jsx|js)'; // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
12
16
 
13
- var GLOB_REGEX = /^(?<directory>[^*]*)\/\*\*\/(?<files>\*\..*)/;
17
+ var fixBadGlob = deprecate(function (match) {
18
+ return match.input.replace(match[1], `@${match[1]}`);
19
+ }, dedent`
20
+ You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
21
+ `);
22
+
23
+ var detectBadGlob = function (val) {
24
+ var match = val.match(/\.(\([^)]+\))/);
25
+
26
+ if (match) {
27
+ return fixBadGlob(match);
28
+ }
29
+
30
+ return val;
31
+ };
14
32
 
15
33
  var isDirectory = function (configDir, entry) {
16
34
  try {
@@ -20,78 +38,75 @@ var isDirectory = function (configDir, entry) {
20
38
  }
21
39
  };
22
40
 
23
- export var normalizeStoriesEntry = function (entry, configDir) {
24
- var glob;
25
- var directory;
26
- var files;
27
- var titlePrefix;
41
+ export var normalizeStoriesEntry = function (entry, {
42
+ configDir: configDir,
43
+ workingDir: workingDir
44
+ }) {
45
+ var specifierWithoutMatcher;
28
46
 
29
47
  if (typeof entry === 'string') {
30
- if (!entry.includes('**') && isDirectory(configDir, entry)) {
31
- directory = entry;
32
- files = DEFAULT_FILES;
33
- titlePrefix = DEFAULT_TITLE_PREFIX;
34
- } else {
35
- var match = entry.match(GLOB_REGEX);
36
-
37
- if (match) {
38
- directory = match.groups.directory;
39
- files = match.groups.files;
40
- titlePrefix = DEFAULT_TITLE_PREFIX;
48
+ if (!entry.includes('*')) {
49
+ if (isDirectory(configDir, entry)) {
50
+ specifierWithoutMatcher = {
51
+ titlePrefix: DEFAULT_TITLE_PREFIX,
52
+ directory: entry,
53
+ files: DEFAULT_FILES
54
+ };
41
55
  } else {
42
- glob = entry;
56
+ specifierWithoutMatcher = {
57
+ titlePrefix: DEFAULT_TITLE_PREFIX,
58
+ directory: path.dirname(entry),
59
+ files: path.basename(entry)
60
+ };
43
61
  }
62
+ } else {
63
+ var fixedEntry = detectBadGlob(entry);
64
+ var globResult = scan(fixedEntry);
65
+
66
+ var _directory = globResult.isGlob ? globResult.prefix + globResult.base : path.dirname(fixedEntry);
67
+
68
+ var filesFallback = _directory !== '.' ? fixedEntry.substr(_directory.length + 1) : fixedEntry;
69
+
70
+ var _files = globResult.isGlob ? globResult.glob : filesFallback;
71
+
72
+ specifierWithoutMatcher = {
73
+ titlePrefix: DEFAULT_TITLE_PREFIX,
74
+ directory: _directory,
75
+ files: _files
76
+ };
44
77
  }
45
78
  } else {
46
- directory = entry.directory;
47
- files = entry.files || DEFAULT_FILES;
48
- titlePrefix = entry.titlePrefix || DEFAULT_TITLE_PREFIX;
49
- }
79
+ specifierWithoutMatcher = _objectSpread({
80
+ titlePrefix: DEFAULT_TITLE_PREFIX,
81
+ files: DEFAULT_FILES
82
+ }, entry);
83
+ } // We are going to be doing everything with node importPaths which use
84
+ // URL format, i.e. `/` as a separator, so let's make sure we've normalized
50
85
 
51
- if (typeof glob !== 'undefined') {
52
- return {
53
- glob: glob,
54
- specifier: undefined
55
- };
56
- }
57
86
 
58
- return {
59
- glob: `${directory}/**/${files}`,
60
- specifier: {
61
- directory: directory,
62
- titlePrefix: titlePrefix,
63
- files: files
64
- }
65
- };
66
- };
87
+ var files = slash(specifierWithoutMatcher.files); // At this stage `directory` is relative to `main.js` (the config dir)
88
+ // We want to work relative to the working dir, so we transform it here.
67
89
 
68
- /**
69
- * Stories entries are specified relative to the configDir. Webpack filenames are produced relative to the
70
- * current working directory. This function rewrites the specifier.directory relative to the current working
71
- * directory.
72
- */
73
- export var normalizeDirectory = function (entry, {
74
- configDir: configDir,
75
- workingDir: workingDir
76
- }) {
77
- if (!entry.specifier) return entry;
78
- var directory = entry.specifier.directory;
79
- var directoryFromConfig = path.resolve(configDir, directory);
80
- var directoryFromWorking = path.relative(workingDir, directoryFromConfig); // relative('/foo', '/foo/src') => 'src'
81
- // but we want `./src`to match webpack's file names
82
-
83
- if (!directoryFromWorking.startsWith('.')) {
84
- directoryFromWorking = `.${path.sep}${directoryFromWorking}`;
90
+ var _specifierWithoutMatc = specifierWithoutMatcher,
91
+ directoryRelativeToConfig = _specifierWithoutMatc.directory;
92
+ var absoluteDirectory = path.resolve(configDir, directoryRelativeToConfig);
93
+ var directory = slash(path.relative(workingDir, absoluteDirectory)); // relative('/foo', '/foo/src') => 'src'
94
+ // but we want `./src` to match importPaths
95
+
96
+ if (!directory.startsWith('.')) {
97
+ directory = `./${directory}`;
85
98
  }
86
99
 
87
- return _objectSpread(_objectSpread({}, entry), {}, {
88
- specifier: _objectSpread(_objectSpread({}, entry.specifier), {}, {
89
- directory: directoryFromWorking
90
- })
100
+ directory = directory.replace(/\/$/, ''); // Now make the importFn matcher.
101
+
102
+ var importPathMatcher = globToRegex(`${directory}/${files}`);
103
+ return _objectSpread(_objectSpread({}, specifierWithoutMatcher), {}, {
104
+ directory: directory,
105
+ importPathMatcher: importPathMatcher
91
106
  });
92
107
  };
93
108
  export var normalizeStories = function (entries, options) {
94
109
  return entries.map(function (entry) {
95
- return normalizeDirectory(normalizeStoriesEntry(entry, options.configDir), options);
110
+ return normalizeStoriesEntry(entry, options);
96
111
  });
97
112
  };
@@ -26,6 +26,7 @@ export var useProgressReporting = async function (router, startTime, options) {
26
26
  reportProgress = function (progress) {
27
27
  if (closed || response.writableEnded) return;
28
28
  response.write(`data: ${JSON.stringify(progress)}\n\n`);
29
+ response.flush();
29
30
  if (progress.value === 1) close();
30
31
  };
31
32
  });
@@ -1,25 +1,23 @@
1
1
  import dedent from 'ts-dedent';
2
- import { toRequireContext } from '..';
3
- export function toImportFnPart(entry) {
4
- var _toRequireContext = toRequireContext(entry.glob),
5
- base = _toRequireContext.path,
6
- regex = _toRequireContext.regex;
2
+ export function toImportFnPart(specifier) {
3
+ var directory = specifier.directory,
4
+ importPathMatcher = specifier.importPathMatcher; // It appears webpack passes *something* similar to the absolute path to the file
5
+ // on disk (prefixed with something unknown) to the matcher.
6
+ // We don't want to include the absolute path in our bundle, so we will just pull the
7
+ // '^' and any leading '.' off the regexp and match on that.
8
+ // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
7
9
 
8
- var webpackIncludeRegex = new RegExp(regex.source.substring(1));
10
+ var webpackIncludeRegex = new RegExp(importPathMatcher.source.replace(/^\^\\\.*/, ''));
9
11
  return dedent`
10
12
  async (path) => {
11
- const pathBase = path.substring(0, ${base.length + 1});
12
- if (pathBase !== '${base}/') {
13
+ if (!${importPathMatcher}.exec(path)) {
13
14
  return;
14
15
  }
15
16
 
16
- const pathRemainder = path.substring(${base.length + 1});
17
- if (!${regex}.exec(pathRemainder)) {
18
- return;
19
- }
17
+ const pathRemainder = path.substring(${directory.length + 1});
20
18
  return import(
21
19
  /* webpackInclude: ${webpackIncludeRegex} */
22
- '${base}/' + pathRemainder
20
+ '${directory}/' + pathRemainder
23
21
  );
24
22
  }
25
23
 
@@ -1,79 +1,22 @@
1
- import { makeRe, scan } from 'micromatch';
2
- import deprecate from 'util-deprecate';
3
- import dedent from 'ts-dedent';
4
- import path from 'path'; // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
5
-
6
- var fixBadGlob = deprecate(function (match) {
7
- return match.input.replace(match[1], `@${match[1]}`);
8
- }, dedent`
9
- You have specified an invalid glob, we've attempted to fix it, please ensure that the glob you specify is valid. See: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#correct-globs-in-mainjs
10
- `);
11
-
12
- var detectBadGlob = function (val) {
13
- var match = val.match(/\.(\([^)]+\))/);
14
-
15
- if (match) {
16
- return fixBadGlob(match);
17
- }
18
-
19
- return val;
20
- };
21
-
22
- var isObject = function (val) {
23
- return val != null && typeof val === 'object' && Array.isArray(val) === false;
24
- };
25
-
26
- export var toRequireContext = function (input) {
27
- var fixedInput = detectBadGlob(input);
28
-
29
- switch (true) {
30
- case typeof input === 'string':
31
- {
32
- var globResult = scan(fixedInput);
33
- var base = globResult.isGlob ? globResult.prefix + globResult.base : path.dirname(fixedInput);
34
- var globFallback = base !== '.' ? fixedInput.substr(base.length + 1) : fixedInput;
35
- var glob = globResult.isGlob ? globResult.glob : globFallback;
36
- var regex = makeRe(glob, {
37
- fastpaths: false,
38
- noglobstar: false,
39
- bash: false
40
- });
41
- var source = regex.source;
42
-
43
- if (source.startsWith('^')) {
44
- // webpack's require.context matches against paths starting `./`
45
- // Globs starting `**` require special treatment due to the regex they
46
- // produce, specifically a negative look-ahead
47
- var match = ['^\\.', glob.startsWith('**') ? '' : '\\/', source.substring(1)].join('');
48
- var recursive = glob.includes('**') || glob.split('/').length > 1;
49
- return {
50
- path: base,
51
- recursive: recursive,
52
- match: match,
53
- regex: regex
54
- };
55
- }
56
-
57
- throw new Error(`Invalid glob: >> ${input} >> ${regex}`);
58
- }
59
-
60
- case isObject(input):
61
- {
62
- return input;
63
- }
64
-
65
- default:
66
- {
67
- throw new Error('the provided input cannot be transformed into a require.context');
68
- }
69
- }
1
+ import { globToRegex } from './glob-to-regexp';
2
+ export var toRequireContext = function (specifier) {
3
+ var directory = specifier.directory,
4
+ files = specifier.files; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
5
+ // For `require.context()` we want the same thing, relative to directory
6
+
7
+ var match = globToRegex(`./${files}`);
8
+ return {
9
+ path: directory,
10
+ recursive: !!files.match(/^\*{1,2}\//),
11
+ match: match
12
+ };
70
13
  };
71
- export var toRequireContextString = function (input) {
72
- var _toRequireContext = toRequireContext(input),
14
+ export var toRequireContextString = function (specifier) {
15
+ var _toRequireContext = toRequireContext(specifier),
73
16
  p = _toRequireContext.path,
74
17
  r = _toRequireContext.recursive,
75
18
  m = _toRequireContext.match;
76
19
 
77
- var result = `require.context('${p}', ${r}, /${m}/)`;
20
+ var result = `require.context('${p}', ${r}, ${m})`;
78
21
  return result;
79
22
  };
@@ -191,15 +191,25 @@ export interface TypescriptOptions {
191
191
  reactDocgenTypescriptOptions: PluginOptions;
192
192
  }
193
193
  interface StoriesSpecifier {
194
+ /**
195
+ * When auto-titling, what to prefix all generated titles with (default: '')
196
+ */
197
+ titlePrefix?: string;
198
+ /**
199
+ * Where to start looking for story files
200
+ */
194
201
  directory: string;
202
+ /**
203
+ * What does the filename of a story file look like?
204
+ * (a glob, relative to directory, no leading `./`)
205
+ * If unset, we use `** / *.stories.@(mdx|tsx|ts|jsx|js)` (no spaces)
206
+ */
195
207
  files?: string;
196
- titlePrefix?: string;
197
208
  }
198
209
  export declare type StoriesEntry = string | StoriesSpecifier;
199
- export interface NormalizedStoriesSpecifier {
200
- glob: string;
201
- specifier?: StoriesSpecifier;
202
- }
210
+ export declare type NormalizedStoriesSpecifier = Required<StoriesSpecifier> & {
211
+ importPathMatcher: RegExp;
212
+ };
203
213
  /**
204
214
  * The interface for Storybook configuration in `main.ts` files.
205
215
  */
@@ -0,0 +1 @@
1
+ export declare function globToRegex(glob: string): RegExp;
@@ -1,14 +1,8 @@
1
1
  import { StoriesEntry, NormalizedStoriesSpecifier } from '../types';
2
- export declare const normalizeStoriesEntry: (entry: StoriesEntry, configDir: string) => NormalizedStoriesSpecifier;
2
+ export declare const normalizeStoriesEntry: (entry: StoriesEntry, { configDir, workingDir }: NormalizeOptions) => NormalizedStoriesSpecifier;
3
3
  interface NormalizeOptions {
4
4
  configDir: string;
5
5
  workingDir: string;
6
6
  }
7
- /**
8
- * Stories entries are specified relative to the configDir. Webpack filenames are produced relative to the
9
- * current working directory. This function rewrites the specifier.directory relative to the current working
10
- * directory.
11
- */
12
- export declare const normalizeDirectory: (entry: NormalizedStoriesSpecifier, { configDir, workingDir }: NormalizeOptions) => NormalizedStoriesSpecifier;
13
7
  export declare const normalizeStories: (entries: StoriesEntry[], options: NormalizeOptions) => NormalizedStoriesSpecifier[];
14
8
  export {};
@@ -1,3 +1,3 @@
1
1
  import { NormalizedStoriesSpecifier } from '../types';
2
- export declare function toImportFnPart(entry: NormalizedStoriesSpecifier): string;
2
+ export declare function toImportFnPart(specifier: NormalizedStoriesSpecifier): string;
3
3
  export declare function toImportFn(stories: NormalizedStoriesSpecifier[]): string;
@@ -1,2 +1,7 @@
1
- export declare const toRequireContext: (input: any) => any;
2
- export declare const toRequireContextString: (input: any) => string;
1
+ import { NormalizedStoriesSpecifier } from '../types';
2
+ export declare const toRequireContext: (specifier: NormalizedStoriesSpecifier) => {
3
+ path: string;
4
+ recursive: boolean;
5
+ match: RegExp;
6
+ };
7
+ export declare const toRequireContextString: (specifier: NormalizedStoriesSpecifier) => string;
@@ -187,15 +187,25 @@ export interface TypescriptOptions {
187
187
  reactDocgenTypescriptOptions: PluginOptions;
188
188
  }
189
189
  interface StoriesSpecifier {
190
+ /**
191
+ * When auto-titling, what to prefix all generated titles with (default: '')
192
+ */
193
+ titlePrefix?: string;
194
+ /**
195
+ * Where to start looking for story files
196
+ */
190
197
  directory: string;
198
+ /**
199
+ * What does the filename of a story file look like?
200
+ * (a glob, relative to directory, no leading `./`)
201
+ * If unset, we use `** / *.stories.@(mdx|tsx|ts|jsx|js)` (no spaces)
202
+ */
191
203
  files?: string;
192
- titlePrefix?: string;
193
204
  }
194
205
  export declare type StoriesEntry = string | StoriesSpecifier;
195
- export interface NormalizedStoriesSpecifier {
196
- glob: string;
197
- specifier?: StoriesSpecifier;
198
- }
206
+ export declare type NormalizedStoriesSpecifier = Required<StoriesSpecifier> & {
207
+ importPathMatcher: RegExp;
208
+ };
199
209
  /**
200
210
  * The interface for Storybook configuration in `main.ts` files.
201
211
  */
@@ -0,0 +1 @@
1
+ export declare function globToRegex(glob: string): RegExp;
@@ -1,14 +1,8 @@
1
1
  import type { StoriesEntry, NormalizedStoriesSpecifier } from '../types';
2
- export declare const normalizeStoriesEntry: (entry: StoriesEntry, configDir: string) => NormalizedStoriesSpecifier;
2
+ export declare const normalizeStoriesEntry: (entry: StoriesEntry, { configDir, workingDir }: NormalizeOptions) => NormalizedStoriesSpecifier;
3
3
  interface NormalizeOptions {
4
4
  configDir: string;
5
5
  workingDir: string;
6
6
  }
7
- /**
8
- * Stories entries are specified relative to the configDir. Webpack filenames are produced relative to the
9
- * current working directory. This function rewrites the specifier.directory relative to the current working
10
- * directory.
11
- */
12
- export declare const normalizeDirectory: (entry: NormalizedStoriesSpecifier, { configDir, workingDir }: NormalizeOptions) => NormalizedStoriesSpecifier;
13
7
  export declare const normalizeStories: (entries: StoriesEntry[], options: NormalizeOptions) => NormalizedStoriesSpecifier[];
14
8
  export {};
@@ -1,3 +1,3 @@
1
1
  import type { NormalizedStoriesSpecifier } from '../types';
2
- export declare function toImportFnPart(entry: NormalizedStoriesSpecifier): string;
2
+ export declare function toImportFnPart(specifier: NormalizedStoriesSpecifier): string;
3
3
  export declare function toImportFn(stories: NormalizedStoriesSpecifier[]): string;
@@ -1,2 +1,7 @@
1
- export declare const toRequireContext: (input: any) => any;
2
- export declare const toRequireContextString: (input: any) => string;
1
+ import { NormalizedStoriesSpecifier } from '../types';
2
+ export declare const toRequireContext: (specifier: NormalizedStoriesSpecifier) => {
3
+ path: string;
4
+ recursive: boolean;
5
+ match: RegExp;
6
+ };
7
+ export declare const toRequireContextString: (specifier: NormalizedStoriesSpecifier) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/core-common",
3
- "version": "6.4.0-beta.3",
3
+ "version": "6.4.0-beta.7",
4
4
  "description": "Storybook framework-agnostic API",
5
5
  "keywords": [
6
6
  "storybook"
@@ -61,7 +61,7 @@
61
61
  "@babel/preset-react": "^7.12.10",
62
62
  "@babel/preset-typescript": "^7.12.7",
63
63
  "@babel/register": "^7.12.1",
64
- "@storybook/node-logger": "6.4.0-beta.3",
64
+ "@storybook/node-logger": "6.4.0-beta.7",
65
65
  "@storybook/semver": "^7.3.2",
66
66
  "@types/micromatch": "^4.0.1",
67
67
  "@types/node": "^14.0.10",
@@ -85,12 +85,14 @@
85
85
  "pkg-dir": "^5.0.0",
86
86
  "pretty-hrtime": "^1.0.3",
87
87
  "resolve-from": "^5.0.0",
88
+ "slash": "^3.0.0",
88
89
  "ts-dedent": "^2.0.0",
89
90
  "util-deprecate": "^1.0.2",
90
91
  "webpack": "4"
91
92
  },
92
93
  "devDependencies": {
93
94
  "@storybook/react-docgen-typescript-plugin": "1.0.2-canary.253f8c1.0",
95
+ "@types/compression": "^1.7.0",
94
96
  "@types/interpret": "^1.1.1",
95
97
  "@types/mock-fs": "^4.13.0",
96
98
  "mock-fs": "^4.13.0"
@@ -107,6 +109,6 @@
107
109
  "publishConfig": {
108
110
  "access": "public"
109
111
  },
110
- "gitHead": "0fc9200599c97a5797c5af886792200cd29e2046",
112
+ "gitHead": "5c16acd21a956f16a7b24900a9bf38b674646217",
111
113
  "sbmodern": "dist/modern/index.js"
112
114
  }
package/typings.d.ts CHANGED
@@ -1,6 +1,15 @@
1
+ import('@types/compression');
2
+
1
3
  declare module 'lazy-universal-dotenv';
2
4
  declare module 'pnp-webpack-plugin';
3
5
  declare module '@storybook/semver';
6
+
7
+ declare namespace jest {
8
+ interface Matchers<R> {
9
+ toMatchPaths(paths: string[]): R;
10
+ }
11
+ }
12
+
4
13
  declare module 'file-system-cache' {
5
14
  export interface Options {
6
15
  basePath?: string;