From 276c56ff417f63473a5b76982a818c4a306e6e86 Mon Sep 17 00:00:00 2001 From: Hypnosphi Date: Sun, 4 Mar 2018 14:29:43 +0300 Subject: [PATCH] Use WatchMissingNodeModulesPlugin from react-dev-utils package --- .../src/server/config/webpack.config.js | 3 +- .../src/server/config/webpack.config.js | 3 +- app/react-native/package.json | 1 + app/react-native/src/server/config/utils.js | 2 ++ .../src/server/config/webpack.config.js | 4 ++- app/react/src/server/config/webpack.config.js | 3 +- app/vue/src/server/config/webpack.config.js | 3 +- lib/core/server.js | 2 -- .../config/WatchMissingNodeModulesPlugin.js | 34 ------------------- 9 files changed, 14 insertions(+), 41 deletions(-) delete mode 100644 lib/core/src/server/config/WatchMissingNodeModulesPlugin.js diff --git a/app/angular/src/server/config/webpack.config.js b/app/angular/src/server/config/webpack.config.js index 1e2d4360b827..30132bde3eda 100644 --- a/app/angular/src/server/config/webpack.config.js +++ b/app/angular/src/server/config/webpack.config.js @@ -2,9 +2,10 @@ import path from 'path'; import webpack from 'webpack'; import Dotenv from 'dotenv-webpack'; import InterpolateHtmlPlugin from 'react-dev-utils/InterpolateHtmlPlugin'; +import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; -import { WatchMissingNodeModulesPlugin, managerPath } from '@storybook/core/server'; +import { managerPath } from '@storybook/core/server'; import { includePaths, excludePaths, nodeModulesPaths, loadEnv, nodePaths } from './utils'; import babelLoaderConfig from './babel'; diff --git a/app/polymer/src/server/config/webpack.config.js b/app/polymer/src/server/config/webpack.config.js index 6a4644f4ee44..2e4880bc76b2 100644 --- a/app/polymer/src/server/config/webpack.config.js +++ b/app/polymer/src/server/config/webpack.config.js @@ -2,10 +2,11 @@ import path from 'path'; import webpack from 'webpack'; import Dotenv from 'dotenv-webpack'; import InterpolateHtmlPlugin from 'react-dev-utils/InterpolateHtmlPlugin'; +import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; import CopyWebpackPlugin from 'copy-webpack-plugin'; -import { WatchMissingNodeModulesPlugin, managerPath } from '@storybook/core/server'; +import { managerPath } from '@storybook/core/server'; import { includePaths, excludePaths, nodeModulesPaths, loadEnv, nodePaths } from './utils'; import { getPreviewHeadHtml, getManagerHeadHtml } from '../utils'; diff --git a/app/react-native/package.json b/app/react-native/package.json index c905b6a0c033..0c6b159c1091 100644 --- a/app/react-native/package.json +++ b/app/react-native/package.json @@ -53,6 +53,7 @@ "json5": "^0.5.1", "markdown-loader": "^2.0.2", "prop-types": "^15.6.1", + "react-dev-utils": "^5.0.0", "react-native-compat": "^1.0.0", "react-native-iphone-x-helper": "^1.0.2", "shelljs": "^0.8.1", diff --git a/app/react-native/src/server/config/utils.js b/app/react-native/src/server/config/utils.js index b05edcddcee3..b71c33df1a9c 100644 --- a/app/react-native/src/server/config/utils.js +++ b/app/react-native/src/server/config/utils.js @@ -10,3 +10,5 @@ export const OccurenceOrderPlugin = export const includePaths = [path.resolve('./')]; export const excludePaths = [path.resolve('./node_modules')]; + +export const nodeModulesPaths = path.resolve('./node_modules'); diff --git a/app/react-native/src/server/config/webpack.config.js b/app/react-native/src/server/config/webpack.config.js index 7739a77e6aba..0f0cf073a73c 100644 --- a/app/react-native/src/server/config/webpack.config.js +++ b/app/react-native/src/server/config/webpack.config.js @@ -1,8 +1,9 @@ import path from 'path'; import webpack from 'webpack'; +import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; -import { OccurenceOrderPlugin, includePaths, excludePaths } from './utils'; +import { OccurenceOrderPlugin, includePaths, excludePaths, nodeModulesPaths } from './utils'; const getConfig = options => ({ devtool: '#cheap-module-eval-source-map', @@ -25,6 +26,7 @@ const getConfig = options => ({ new OccurenceOrderPlugin(), new webpack.HotModuleReplacementPlugin(), new CaseSensitivePathsPlugin(), + new WatchMissingNodeModulesPlugin(nodeModulesPaths), ], module: { rules: [ diff --git a/app/react/src/server/config/webpack.config.js b/app/react/src/server/config/webpack.config.js index 2b29ad8e58ad..138a68d0ea27 100644 --- a/app/react/src/server/config/webpack.config.js +++ b/app/react/src/server/config/webpack.config.js @@ -2,9 +2,10 @@ import path from 'path'; import webpack from 'webpack'; import Dotenv from 'dotenv-webpack'; import InterpolateHtmlPlugin from 'react-dev-utils/InterpolateHtmlPlugin'; +import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; -import { WatchMissingNodeModulesPlugin, managerPath } from '@storybook/core/server'; +import { managerPath } from '@storybook/core/server'; import { includePaths, excludePaths, nodeModulesPaths, loadEnv, nodePaths } from './utils'; import babelLoaderConfig from './babel'; diff --git a/app/vue/src/server/config/webpack.config.js b/app/vue/src/server/config/webpack.config.js index b06d1ffc1368..eec173319fe4 100644 --- a/app/vue/src/server/config/webpack.config.js +++ b/app/vue/src/server/config/webpack.config.js @@ -2,9 +2,10 @@ import path from 'path'; import webpack from 'webpack'; import Dotenv from 'dotenv-webpack'; import InterpolateHtmlPlugin from 'react-dev-utils/InterpolateHtmlPlugin'; +import WatchMissingNodeModulesPlugin from 'react-dev-utils/WatchMissingNodeModulesPlugin'; import CaseSensitivePathsPlugin from 'case-sensitive-paths-webpack-plugin'; import HtmlWebpackPlugin from 'html-webpack-plugin'; -import { WatchMissingNodeModulesPlugin, managerPath } from '@storybook/core/server'; +import { managerPath } from '@storybook/core/server'; import { includePaths, excludePaths, nodeModulesPaths, loadEnv, nodePaths } from './utils'; import { getPreviewHeadHtml, getManagerHeadHtml } from '../utils'; diff --git a/lib/core/server.js b/lib/core/server.js index ee376d90f3a8..74d6da067adb 100644 --- a/lib/core/server.js +++ b/lib/core/server.js @@ -1,10 +1,8 @@ const assign = require('babel-runtime/core-js/object/assign').default; const defaultWebpackConfig = require('./dist/server/config/defaults/webpack.config'); -const WatchMissingNodeModulesPlugin = require('./dist/server/config/WatchMissingNodeModulesPlugin'); const buildStatic = require('./dist/server/build-static'); const buildDev = require('./dist/server/build-dev'); module.exports = assign({}, defaultWebpackConfig, buildStatic, buildDev, { - WatchMissingNodeModulesPlugin, managerPath: require.resolve('./dist/client/manager'), }); diff --git a/lib/core/src/server/config/WatchMissingNodeModulesPlugin.js b/lib/core/src/server/config/WatchMissingNodeModulesPlugin.js deleted file mode 100644 index 962bbb97ff45..000000000000 --- a/lib/core/src/server/config/WatchMissingNodeModulesPlugin.js +++ /dev/null @@ -1,34 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * All rights reserved. - * - * This source code is licensed under the BSD-style license found in the - * LICENSE file in the root directory of this source tree. An additional grant - * of patent rights can be found in the PATENTS file in the same directory. - */ -// @remove-on-eject-end - -// This Webpack plugin ensures `npm install ` forces a project rebuild. -// We’re not sure why this isn't Webpack's default behavior. -// See https://github.com/facebookincubator/create-react-app/issues/186. - -function WatchMissingNodeModulesPlugin(nodeModulesPath) { - this.nodeModulesPath = nodeModulesPath; -} - -WatchMissingNodeModulesPlugin.prototype.apply = function apply(compiler) { - compiler.plugin('emit', (compilation, callback) => { - const missingDeps = compilation.missingDependencies; - const { nodeModulesPath } = this; - - // If any missing files are expected to appear in node_modules... - if (missingDeps.some(file => file.indexOf(nodeModulesPath) !== -1)) { - // ...tell webpack to watch node_modules recursively until they appear. - compilation.contextDependencies.push(nodeModulesPath); - } - - callback(); - }); -}; - -module.exports = WatchMissingNodeModulesPlugin;