Skip to content

Commit 99ee52c

Browse files
committed
Fix: Fix incorrect default glob pattern (was introduced in #404, fixes #461)
1 parent 15e37d2 commit 99ee52c

File tree

6 files changed

+36
-17
lines changed

6 files changed

+36
-17
lines changed

docs/Components.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Components
44

5-
By default Styleguidist will search components using this [glob pattern](https://github.com/isaacs/node-glob#glob-primer): `src/components/**/*.jsx?`. It will pick up paths like `src/components/Button.js`, `src/components/Button/Button.js` or `src/components/Button/index.js`. It will also ignore test files (`__tests__` folder and file names containing `.test.js`, `.test.jsx`, `.spec.js` and `.spec.jsx`). If it doesn’t work for you, create a `styleguide.config.js` file in your project’s root folder and configure the patterns to fit your project structure.
5+
By default Styleguidist will search components using this [glob pattern](https://github.com/isaacs/node-glob#glob-primer): `src/components/**/*.{js,jsx}`. It will pick up paths like `src/components/Button.js`, `src/components/Button/Button.js` or `src/components/Button/index.js`. It will also ignore test files (`__tests__` folder and file names containing `.test.js`, `.test.jsx`, `.spec.js` and `.spec.jsx`). If it doesn’t work for you, create a `styleguide.config.js` file in your project’s root folder and configure the patterns to fit your project structure.
66

77
For example, if your components look like `components/Button/Button.js` + `components/Button/index.js` (meaning you need to skip `index.js`, otherwise the component will be loaded twice):
88

docs/Configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Styleguidist uses [Bublé](https://buble.surge.sh/guide/) to run ES6 code on the
1616

1717
#### `components`
1818

19-
Type: `String` or `Function`, default: `src/components/**/*.jsx?`
19+
Type: `String` or `Function`, default: `src/components/**/*.{js,jsx}`
2020

2121
- when `String`: a [glob pattern](https://github.com/isaacs/node-glob#glob-primer) that matches all your component modules.
2222
- when `Function`: a function that returns an array of module paths.

examples/cra/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"node": ">=4"
1717
},
1818
"devDependencies": {
19-
"react-scripts": "^0.8.4",
20-
"react-styleguidist": "^5.0.0",
21-
"webpack": "^1.14.0"
19+
"react-scripts": "^1.0.0",
20+
"react-styleguidist": "^5.3.0",
21+
"webpack": "^2.6.0"
2222
},
2323
"dependencies": {
24-
"dog-names": "~1.0.2",
25-
"react": "~15.4.1",
26-
"react-dom": "~15.4.1"
24+
"dog-names": "^1.0.2",
25+
"react": "^15.5.0",
26+
"react-dom": "^15.5.0"
2727
},
2828
"scripts": {
2929
"start": "react-scripts start",

loaders/__tests__/styleguide-loader.spec.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import vm from 'vm';
22
import path from 'path';
33
import { readFileSync } from 'fs';
4-
import noop from 'lodash/noop';
54
import styleguideLoader from '../styleguide-loader';
5+
import getConfig from '../../scripts/config';
66

77
const file = './test/components/Button/Button.js';
88

@@ -18,14 +18,33 @@ it('should return valid, parsable JS', () => {
1818
getExampleFilename: () => 'Readme.md',
1919
getComponentPathLine: filepath => filepath,
2020
},
21-
addContextDependency: noop,
21+
addContextDependency: () => {},
2222
},
2323
readFileSync(file, 'utf8')
2424
);
2525
expect(result).toBeTruthy();
2626
expect(() => new vm.Script(result)).not.toThrow();
2727
});
2828

29+
it('should return correct component paths: default glob pattern', () => {
30+
const result = styleguideLoader.pitch.call(
31+
{
32+
request: file,
33+
_styleguidist: {
34+
...getConfig(),
35+
configDir: path.resolve(__dirname, '../../examples/cra'),
36+
},
37+
addContextDependency: () => {},
38+
},
39+
readFileSync(file, 'utf8')
40+
);
41+
expect(result).toBeTruthy();
42+
expect(() => new vm.Script(result)).not.toThrow();
43+
expect(result).toMatch(`'filepath': 'src/components/Button.js'`);
44+
expect(result).toMatch(`'filepath': 'src/components/Placeholder.js'`);
45+
expect(result).toMatch(`'filepath': 'src/components/RandomButton.js'`);
46+
});
47+
2948
it('should return correct component paths: glob', () => {
3049
const result = styleguideLoader.pitch.call(
3150
{
@@ -36,7 +55,7 @@ it('should return correct component paths: glob', () => {
3655
getExampleFilename: () => 'Readme.md',
3756
getComponentPathLine: filepath => filepath,
3857
},
39-
addContextDependency: noop,
58+
addContextDependency: () => {},
4059
},
4160
readFileSync(file, 'utf8')
4261
);
@@ -63,7 +82,7 @@ it('should return correct component paths: function returning absolute paths', (
6382
getExampleFilename: () => 'Readme.md',
6483
getComponentPathLine: filepath => filepath,
6584
},
66-
addContextDependency: noop,
85+
addContextDependency: () => {},
6786
},
6887
readFileSync(file, 'utf8')
6988
);
@@ -90,7 +109,7 @@ it('should return correct component paths: function returning relative paths', (
90109
getExampleFilename: () => 'Readme.md',
91110
getComponentPathLine: filepath => filepath,
92111
},
93-
addContextDependency: noop,
112+
addContextDependency: () => {},
94113
},
95114
readFileSync(file, 'utf8')
96115
);
@@ -118,7 +137,7 @@ it('should filter out components without examples if skipComponentsWithoutExampl
118137
getExampleFilename: componentPath => path.join(path.dirname(componentPath), 'Readme.md'),
119138
getComponentPathLine: filepath => filepath,
120139
},
121-
addContextDependency: noop,
140+
addContextDependency: () => {},
122141
},
123142
readFileSync(file, 'utf8')
124143
);

scripts/__tests__/config.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ it('should use components option as the first sections if there’s no sections
134134
it('should use default components option both components and sections options weren’t specified', () => {
135135
const result = getConfig();
136136
expect(result.sections).toHaveLength(1);
137-
expect(result.sections[0].components).toMatch('.js');
137+
expect(result.sections[0].components).toMatch('**');
138138
});
139139

140140
it('should ignore components option there’s sections options', () => {

scripts/schemas/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
/* eslint-disable no-console */
77

8-
const DEFAULT_COMPONENTS_PATTERN = 'src/@(components|Components)/**/*.jsx?';
8+
const DEFAULT_COMPONENTS_PATTERN = 'src/@(components|Components)/**/*.{js,jsx}';
99

1010
const fs = require('fs');
1111
const path = require('path');
@@ -31,7 +31,7 @@ module.exports = {
3131
// `components` is a shortcut for { sections: [{ components }] }, see `sections` below
3232
components: {
3333
type: ['string', 'function'],
34-
example: 'components/**/[A-Z]*.jsx?',
34+
example: 'components/**/[A-Z]*.js',
3535
},
3636
context: {
3737
type: 'object',

0 commit comments

Comments
 (0)