Skip to content

Commit

Permalink
Fix: Do not expect react-script to be in devDependencies (fix #526)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapegin committed Jul 5, 2017
1 parent 967eb0f commit da64422
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 53 deletions.
10 changes: 8 additions & 2 deletions scripts/__tests__/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,15 @@ it('should return webpackConfig option as is', () => {
});

it('should return webpackConfig with user webpack config', () => {
process.chdir('test/apps/cra');
process.chdir('test/apps/basic');
const result = getConfig();
expect(result.webpackConfig).toEqual({ cra: true });
expect(result.webpackConfig).toEqual(
expect.objectContaining({
module: {
loaders: expect.any(Array),
},
})
);
});

it('should allow no webpack config', () => {
Expand Down
4 changes: 2 additions & 2 deletions scripts/__tests__/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ describe('makeWebpackConfig', () => {
});

it('should merge Create React App Webpack config', () => {
process.chdir('test/apps/cra');
process.chdir('test/apps/basic');
const api = styleguidist();
const result = api.makeWebpackConfig();

expect(result).toBeTruthy();
expect(result.cra).toBeTruthy();
expect(result.module).toBeTruthy();
});

it('should add json-loader', () => {
Expand Down
15 changes: 10 additions & 5 deletions scripts/utils/__tests__/findUserWebpackConfig.spec.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import findUserWebpackConfig from '../findUserWebpackConfig';

const cwd = process.cwd();
afterEach(() => {
process.chdir(cwd);
});
afterEach(() => process.chdir(cwd));

it('should return path to Create React App Webpack config', () => {
process.chdir('test/apps/cra');
const result = findUserWebpackConfig();
const result = findUserWebpackConfig(a => a);
expect(result).toMatch(/^react-scripts\//);
});

it('should return an absolute path to user Webpack config located in project root folder', () => {
process.chdir('test/apps/basic');

const result = findUserWebpackConfig();
expect(result).toMatch(/^\//);
expect(result).toMatch(/webpack.config.js$/);
});

it('should return false if there is no webpack config', () => {
process.chdir('test/apps/no-webpack');

const result = findUserWebpackConfig();
expect(result).toBeFalsy();
});
18 changes: 0 additions & 18 deletions scripts/utils/__tests__/isCreateReactApp.spec.js

This file was deleted.

25 changes: 13 additions & 12 deletions scripts/utils/findUserWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const fs = require('fs');
const path = require('path');
const isCreateReactApp = require('./isCreateReactApp');

const CREATE_REACT_APP_WEBPACK_CONFIG = 'react-scripts/config/webpack.config.dev';
const USER_WEBPACK_CONFIG_NAMES = ['webpack.config.js', 'webpackfile.js'];
Expand All @@ -14,19 +13,21 @@ const absolutize = filePath => path.resolve(process.cwd(), filePath);
* Fixed location for Create React App or webpack.config.js in the root directory.
* Returns false if config not found.
*
* @param {Function} resolve
* @return {string|boolean}
*/
module.exports = function findUserWebpackConfig() {
// Create React App
if (isCreateReactApp()) {
return CREATE_REACT_APP_WEBPACK_CONFIG;
}

// Check in the root folder
for (const configFile of USER_WEBPACK_CONFIG_NAMES) {
const absoluteConfigFile = absolutize(configFile);
if (fs.existsSync(absoluteConfigFile)) {
return absoluteConfigFile;
module.exports = function findUserWebpackConfig(resolve) {
resolve = resolve || require.resolve;
try {
// Create React App
return resolve(CREATE_REACT_APP_WEBPACK_CONFIG);
} catch (err) {
// Check in the root folder
for (const configFile of USER_WEBPACK_CONFIG_NAMES) {
const absoluteConfigFile = absolutize(configFile);
if (fs.existsSync(absoluteConfigFile)) {
return absoluteConfigFile;
}
}
}

Expand Down
14 changes: 0 additions & 14 deletions scripts/utils/isCreateReactApp.js

This file was deleted.

0 comments on commit da64422

Please sign in to comment.