@storybook/core-common 6.4.0-beta.21 → 6.4.0-beta.25

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.
@@ -3,12 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.globToRegex = globToRegex;
6
+ exports.globToRegexp = globToRegexp;
7
7
 
8
- var _micromatch = require("micromatch");
8
+ var _picomatch = require("picomatch");
9
9
 
10
- function globToRegex(glob) {
11
- var regex = (0, _micromatch.makeRe)(glob, {
10
+ function globToRegexp(glob) {
11
+ var regex = (0, _picomatch.makeRe)(glob, {
12
12
  fastpaths: false,
13
13
  noglobstar: false,
14
14
  bash: false
@@ -13,7 +13,7 @@ var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
13
13
 
14
14
  var _tsDedent = _interopRequireDefault(require("ts-dedent"));
15
15
 
16
- var _micromatch = require("micromatch");
16
+ var _picomatch = require("picomatch");
17
17
 
18
18
  var _slash = _interopRequireDefault(require("slash"));
19
19
 
@@ -77,7 +77,7 @@ var normalizeStoriesEntry = function (entry, {
77
77
  }
78
78
  } else {
79
79
  var fixedEntry = detectBadGlob(entry);
80
- var globResult = (0, _micromatch.scan)(fixedEntry);
80
+ var globResult = (0, _picomatch.scan)(fixedEntry);
81
81
 
82
82
  var _directory = globResult.isGlob ? globResult.prefix + globResult.base : _path.default.dirname(fixedEntry);
83
83
 
@@ -117,7 +117,7 @@ var normalizeStoriesEntry = function (entry, {
117
117
 
118
118
  directory = directory.replace(/\/$/, ''); // Now make the importFn matcher.
119
119
 
120
- var importPathMatcher = (0, _globToRegexp.globToRegex)(`${directory}/${files}`);
120
+ var importPathMatcher = (0, _globToRegexp.globToRegexp)(`${directory}/${files}`);
121
121
  return _objectSpread(_objectSpread({}, specifierWithoutMatcher), {}, {
122
122
  directory: directory,
123
123
  importPathMatcher: importPathMatcher
@@ -3,22 +3,35 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.webpackIncludeRegexp = webpackIncludeRegexp;
6
7
  exports.toImportFnPart = toImportFnPart;
7
8
  exports.toImportFn = toImportFn;
8
9
 
9
10
  var _tsDedent = _interopRequireDefault(require("ts-dedent"));
10
11
 
12
+ var _globToRegexp = require("./glob-to-regexp");
13
+
11
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
15
 
13
- function toImportFnPart(specifier) {
16
+ function webpackIncludeRegexp(specifier) {
14
17
  var directory = specifier.directory,
15
- importPathMatcher = specifier.importPathMatcher; // It appears webpack passes *something* similar to the absolute path to the file
18
+ files = specifier.files; // It appears webpack passes *something* similar to the absolute path to the file
16
19
  // 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.
20
+ // We don't want to include the absolute path in our bundle, so we will just pull any leading
21
+ // `./` or `../` off our directory and match on that.
19
22
  // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
23
+ // NOTE: directory is "slashed" so will contain only `/` (no `\`), even on windows
20
24
 
21
- var webpackIncludeRegex = new RegExp(importPathMatcher.source.replace(/^\^\\\.*/, ''));
25
+ var directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, '/');
26
+ var webpackIncludeGlob = ['.', '..'].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`;
27
+ var webpackIncludeRegexpWithCaret = (0, _globToRegexp.globToRegexp)(webpackIncludeGlob); // picomatch is creating an exact match, but we are only matching the end of the filename
28
+
29
+ return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ''));
30
+ }
31
+
32
+ function toImportFnPart(specifier) {
33
+ var directory = specifier.directory,
34
+ importPathMatcher = specifier.importPathMatcher;
22
35
  return (0, _tsDedent.default)`
23
36
  async (path) => {
24
37
  if (!${importPathMatcher}.exec(path)) {
@@ -27,7 +40,8 @@ function toImportFnPart(specifier) {
27
40
 
28
41
  const pathRemainder = path.substring(${directory.length + 1});
29
42
  return import(
30
- /* webpackInclude: ${webpackIncludeRegex} */
43
+ /* webpackChunkName: "[request]" */
44
+ /* webpackInclude: ${webpackIncludeRegexp(specifier)} */
31
45
  '${directory}/' + pathRemainder
32
46
  );
33
47
  }
@@ -12,7 +12,7 @@ var toRequireContext = function (specifier) {
12
12
  files = specifier.files; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
13
13
  // For `require.context()` we want the same thing, relative to directory
14
14
 
15
- var match = (0, _globToRegexp.globToRegex)(`./${files}`);
15
+ var match = (0, _globToRegexp.globToRegexp)(`./${files}`);
16
16
  return {
17
17
  path: directory,
18
18
  recursive: !!files.match(/^\*{1,2}\//),
@@ -1,5 +1,5 @@
1
- import { makeRe } from 'micromatch';
2
- export function globToRegex(glob) {
1
+ import { makeRe } from 'picomatch';
2
+ export function globToRegexp(glob) {
3
3
  var regex = makeRe(glob, {
4
4
  fastpaths: false,
5
5
  noglobstar: false,
@@ -8,9 +8,9 @@ import fs from 'fs';
8
8
  import path from 'path';
9
9
  import deprecate from 'util-deprecate';
10
10
  import dedent from 'ts-dedent';
11
- import { scan } from 'micromatch';
11
+ import { scan } from 'picomatch';
12
12
  import slash from 'slash';
13
- import { globToRegex } from './glob-to-regexp';
13
+ import { globToRegexp } from './glob-to-regexp';
14
14
  var DEFAULT_TITLE_PREFIX = '';
15
15
  var DEFAULT_FILES = '**/*.stories.@(mdx|tsx|ts|jsx|js)'; // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
16
16
 
@@ -99,7 +99,7 @@ export var normalizeStoriesEntry = function (entry, {
99
99
 
100
100
  directory = directory.replace(/\/$/, ''); // Now make the importFn matcher.
101
101
 
102
- var importPathMatcher = globToRegex(`${directory}/${files}`);
102
+ var importPathMatcher = globToRegexp(`${directory}/${files}`);
103
103
  return _objectSpread(_objectSpread({}, specifierWithoutMatcher), {}, {
104
104
  directory: directory,
105
105
  importPathMatcher: importPathMatcher
@@ -1,13 +1,23 @@
1
1
  import dedent from 'ts-dedent';
2
- export function toImportFnPart(specifier) {
2
+ import { globToRegexp } from './glob-to-regexp';
3
+ export function webpackIncludeRegexp(specifier) {
3
4
  var directory = specifier.directory,
4
- importPathMatcher = specifier.importPathMatcher; // It appears webpack passes *something* similar to the absolute path to the file
5
+ files = specifier.files; // It appears webpack passes *something* similar to the absolute path to the file
5
6
  // 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.
7
+ // We don't want to include the absolute path in our bundle, so we will just pull any leading
8
+ // `./` or `../` off our directory and match on that.
8
9
  // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
10
+ // NOTE: directory is "slashed" so will contain only `/` (no `\`), even on windows
11
+
12
+ var directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, '/');
13
+ var webpackIncludeGlob = ['.', '..'].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`;
14
+ var webpackIncludeRegexpWithCaret = globToRegexp(webpackIncludeGlob); // picomatch is creating an exact match, but we are only matching the end of the filename
9
15
 
10
- var webpackIncludeRegex = new RegExp(importPathMatcher.source.replace(/^\^\\\.*/, ''));
16
+ return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ''));
17
+ }
18
+ export function toImportFnPart(specifier) {
19
+ var directory = specifier.directory,
20
+ importPathMatcher = specifier.importPathMatcher;
11
21
  return dedent`
12
22
  async (path) => {
13
23
  if (!${importPathMatcher}.exec(path)) {
@@ -16,7 +26,8 @@ export function toImportFnPart(specifier) {
16
26
 
17
27
  const pathRemainder = path.substring(${directory.length + 1});
18
28
  return import(
19
- /* webpackInclude: ${webpackIncludeRegex} */
29
+ /* webpackChunkName: "[request]" */
30
+ /* webpackInclude: ${webpackIncludeRegexp(specifier)} */
20
31
  '${directory}/' + pathRemainder
21
32
  );
22
33
  }
@@ -1,10 +1,10 @@
1
- import { globToRegex } from './glob-to-regexp';
1
+ import { globToRegexp } from './glob-to-regexp';
2
2
  export var toRequireContext = function (specifier) {
3
3
  var directory = specifier.directory,
4
4
  files = specifier.files; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
5
5
  // For `require.context()` we want the same thing, relative to directory
6
6
 
7
- var match = globToRegex(`./${files}`);
7
+ var match = globToRegexp(`./${files}`);
8
8
  return {
9
9
  path: directory,
10
10
  recursive: !!files.match(/^\*{1,2}\//),
@@ -1,5 +1,5 @@
1
- import { makeRe } from 'micromatch';
2
- export function globToRegex(glob) {
1
+ import { makeRe } from 'picomatch';
2
+ export function globToRegexp(glob) {
3
3
  var regex = makeRe(glob, {
4
4
  fastpaths: false,
5
5
  noglobstar: false,
@@ -8,9 +8,9 @@ import fs from 'fs';
8
8
  import path from 'path';
9
9
  import deprecate from 'util-deprecate';
10
10
  import dedent from 'ts-dedent';
11
- import { scan } from 'micromatch';
11
+ import { scan } from 'picomatch';
12
12
  import slash from 'slash';
13
- import { globToRegex } from './glob-to-regexp';
13
+ import { globToRegexp } from './glob-to-regexp';
14
14
  var DEFAULT_TITLE_PREFIX = '';
15
15
  var DEFAULT_FILES = '**/*.stories.@(mdx|tsx|ts|jsx|js)'; // LEGACY support for bad glob patterns we had in SB 5 - remove in SB7
16
16
 
@@ -99,7 +99,7 @@ export var normalizeStoriesEntry = function (entry, {
99
99
 
100
100
  directory = directory.replace(/\/$/, ''); // Now make the importFn matcher.
101
101
 
102
- var importPathMatcher = globToRegex(`${directory}/${files}`);
102
+ var importPathMatcher = globToRegexp(`${directory}/${files}`);
103
103
  return _objectSpread(_objectSpread({}, specifierWithoutMatcher), {}, {
104
104
  directory: directory,
105
105
  importPathMatcher: importPathMatcher
@@ -1,13 +1,23 @@
1
1
  import dedent from 'ts-dedent';
2
- export function toImportFnPart(specifier) {
2
+ import { globToRegexp } from './glob-to-regexp';
3
+ export function webpackIncludeRegexp(specifier) {
3
4
  var directory = specifier.directory,
4
- importPathMatcher = specifier.importPathMatcher; // It appears webpack passes *something* similar to the absolute path to the file
5
+ files = specifier.files; // It appears webpack passes *something* similar to the absolute path to the file
5
6
  // 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.
7
+ // We don't want to include the absolute path in our bundle, so we will just pull any leading
8
+ // `./` or `../` off our directory and match on that.
8
9
  // It's imperfect as it could match extra things in extremely unusual cases, but it'll do for now.
10
+ // NOTE: directory is "slashed" so will contain only `/` (no `\`), even on windows
11
+
12
+ var directoryWithoutLeadingDots = directory.replace(/^(\.+\/)+/, '/');
13
+ var webpackIncludeGlob = ['.', '..'].includes(directory) ? files : `${directoryWithoutLeadingDots}/${files}`;
14
+ var webpackIncludeRegexpWithCaret = globToRegexp(webpackIncludeGlob); // picomatch is creating an exact match, but we are only matching the end of the filename
9
15
 
10
- var webpackIncludeRegex = new RegExp(importPathMatcher.source.replace(/^\^\\\.*/, ''));
16
+ return new RegExp(webpackIncludeRegexpWithCaret.source.replace(/^\^/, ''));
17
+ }
18
+ export function toImportFnPart(specifier) {
19
+ var directory = specifier.directory,
20
+ importPathMatcher = specifier.importPathMatcher;
11
21
  return dedent`
12
22
  async (path) => {
13
23
  if (!${importPathMatcher}.exec(path)) {
@@ -16,7 +26,8 @@ export function toImportFnPart(specifier) {
16
26
 
17
27
  const pathRemainder = path.substring(${directory.length + 1});
18
28
  return import(
19
- /* webpackInclude: ${webpackIncludeRegex} */
29
+ /* webpackChunkName: "[request]" */
30
+ /* webpackInclude: ${webpackIncludeRegexp(specifier)} */
20
31
  '${directory}/' + pathRemainder
21
32
  );
22
33
  }
@@ -1,10 +1,10 @@
1
- import { globToRegex } from './glob-to-regexp';
1
+ import { globToRegexp } from './glob-to-regexp';
2
2
  export var toRequireContext = function (specifier) {
3
3
  var directory = specifier.directory,
4
4
  files = specifier.files; // The importPathMatcher is a `./`-prefixed matcher that includes the directory
5
5
  // For `require.context()` we want the same thing, relative to directory
6
6
 
7
- var match = globToRegex(`./${files}`);
7
+ var match = globToRegexp(`./${files}`);
8
8
  return {
9
9
  path: directory,
10
10
  recursive: !!files.match(/^\*{1,2}\//),
@@ -1 +1 @@
1
- export declare function globToRegex(glob: string): RegExp;
1
+ export declare function globToRegexp(glob: string): RegExp;
@@ -1,3 +1,4 @@
1
1
  import { NormalizedStoriesSpecifier } from '../types';
2
+ export declare function webpackIncludeRegexp(specifier: NormalizedStoriesSpecifier): RegExp;
2
3
  export declare function toImportFnPart(specifier: NormalizedStoriesSpecifier): string;
3
4
  export declare function toImportFn(stories: NormalizedStoriesSpecifier[]): string;
@@ -1 +1 @@
1
- export declare function globToRegex(glob: string): RegExp;
1
+ export declare function globToRegexp(glob: string): RegExp;
@@ -1,3 +1,4 @@
1
1
  import type { NormalizedStoriesSpecifier } from '../types';
2
+ export declare function webpackIncludeRegexp(specifier: NormalizedStoriesSpecifier): RegExp;
2
3
  export declare function toImportFnPart(specifier: NormalizedStoriesSpecifier): string;
3
4
  export declare function toImportFn(stories: NormalizedStoriesSpecifier[]): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/core-common",
3
- "version": "6.4.0-beta.21",
3
+ "version": "6.4.0-beta.25",
4
4
  "description": "Storybook framework-agnostic API",
5
5
  "keywords": [
6
6
  "storybook"
@@ -61,9 +61,8 @@
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.21",
64
+ "@storybook/node-logger": "6.4.0-beta.25",
65
65
  "@storybook/semver": "^7.3.2",
66
- "@types/micromatch": "^4.0.1",
67
66
  "@types/node": "^14.0.10",
68
67
  "@types/pretty-hrtime": "^1.0.0",
69
68
  "babel-loader": "^8.0.0",
@@ -81,7 +80,7 @@
81
80
  "interpret": "^2.2.0",
82
81
  "json5": "^2.1.3",
83
82
  "lazy-universal-dotenv": "^3.0.1",
84
- "micromatch": "^4.0.2",
83
+ "picomatch": "^2.3.0",
85
84
  "pkg-dir": "^5.0.0",
86
85
  "pretty-hrtime": "^1.0.3",
87
86
  "resolve-from": "^5.0.0",
@@ -96,6 +95,7 @@
96
95
  "@types/compression": "^1.7.0",
97
96
  "@types/interpret": "^1.1.1",
98
97
  "@types/mock-fs": "^4.13.0",
98
+ "@types/picomatch": "^2.3.0",
99
99
  "mock-fs": "^4.13.0"
100
100
  },
101
101
  "peerDependencies": {
@@ -110,6 +110,6 @@
110
110
  "publishConfig": {
111
111
  "access": "public"
112
112
  },
113
- "gitHead": "eb83ef6aefb6791324e2c70567bdc128cef09d92",
113
+ "gitHead": "5bf101067e5b9387ce092301bea6ab4ee432f777",
114
114
  "sbmodern": "dist/modern/index.js"
115
115
  }