From 95a76ad7904f78433e994703b8a9239d5308a426 Mon Sep 17 00:00:00 2001 From: Shawn Erquhart Date: Fri, 27 Jul 2018 14:26:03 -0400 Subject: [PATCH] fix: log accurate version by distribution (#1531) --- packages/netlify-cms-core/src/bootstrap.js | 6 +++- packages/netlify-cms-core/webpack.config.js | 6 ++++ .../netlify-cms/scripts/deprecate-old-dist.js | 2 +- packages/netlify-cms/webpack.config.js | 30 +++++++++++++------ scripts/webpack.js | 3 -- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/packages/netlify-cms-core/src/bootstrap.js b/packages/netlify-cms-core/src/bootstrap.js index fc33fea2..75a3c608 100644 --- a/packages/netlify-cms-core/src/bootstrap.js +++ b/packages/netlify-cms-core/src/bootstrap.js @@ -20,7 +20,11 @@ function bootstrap(opts = {}) { /** * Log the version number. */ - console.log(`Netlify CMS version ${NETLIFY_CMS_VERSION}`); + if (NETLIFY_CMS_VERSION) { + console.log(`netlify-cms ${NETLIFY_CMS_VERSION}`); + } else if (NETLIFY_CMS_CORE_VERSION) { + console.log(`netlify-cms-core ${NETLIFY_CMS_CORE_VERSION}`); + } /** * Get DOM element where app will mount. diff --git a/packages/netlify-cms-core/webpack.config.js b/packages/netlify-cms-core/webpack.config.js index 343ca50d..a0e93cbe 100644 --- a/packages/netlify-cms-core/webpack.config.js +++ b/packages/netlify-cms-core/webpack.config.js @@ -1,4 +1,6 @@ const path = require('path'); +const webpack = require('webpack'); +const pkg = require('./package.json'); const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin'); const { getConfig, rules, plugins } = require('../../scripts/webpack.js'); @@ -47,6 +49,10 @@ module.exports = { ...Object.entries(plugins) .filter(([ key ]) => key !== 'friendlyErrors') .map(([ _, plugin ]) => plugin()), + new webpack.DefinePlugin({ + NETLIFY_CMS_VERSION: null, + NETLIFY_CMS_CORE_VERSION: JSON.stringify(`${pkg.version}${isProduction ? '' : '-dev'}`), + }), new FriendlyErrorsWebpackPlugin({ compilationSuccessInfo: { messages: ['Netlify CMS is now running at http://localhost:8080'], diff --git a/packages/netlify-cms/scripts/deprecate-old-dist.js b/packages/netlify-cms/scripts/deprecate-old-dist.js index 66da9f5a..0d755c26 100644 --- a/packages/netlify-cms/scripts/deprecate-old-dist.js +++ b/packages/netlify-cms/scripts/deprecate-old-dist.js @@ -1 +1 @@ -console.warn('The `cms.js` file is deprecated and will be removed in the next major release. Please use `netlify-cms.js` instead.'); +console.warn('You seem to be loading Netlify CMS by fetching `dist/cms.js` from a CDN. That file is deprecated and will be removed in the next major release. Please use `dist/netlify-cms.js` instead.') diff --git a/packages/netlify-cms/webpack.config.js b/packages/netlify-cms/webpack.config.js index c19dd54b..fc56c5dd 100644 --- a/packages/netlify-cms/webpack.config.js +++ b/packages/netlify-cms/webpack.config.js @@ -1,26 +1,38 @@ const path = require('path'); +const webpack = require('webpack'); +const pkg = require('./package.json'); const coreWebpackConfig = require('../netlify-cms-core/webpack.config.js'); +const isProduction = process.env.NODE_ENV === 'production'; + +const baseConfig = { + ...coreWebpackConfig, + context: path.join(__dirname, 'src'), + entry: './index.js', + plugins: [ + ...coreWebpackConfig.plugins.filter(plugin => !plugin instanceof webpack.DefinePlugin), + new webpack.DefinePlugin({ + NETLIFY_CMS_VERSION: JSON.stringify(`${pkg.version}${isProduction ? '' : '-dev'}`), + NETLIFY_CMS_CORE_VERSION: null, + }), + ], +}; + module.exports = [ - { - ...coreWebpackConfig, - context: path.join(__dirname, 'src'), - entry: './index.js', - }, + baseConfig, /** * Output the same script a second time, but named `cms.js`, and with a * deprecation notice. */ { - ...coreWebpackConfig, - context: path.join(__dirname, 'src'), + ...baseConfig, entry: [ - ...coreWebpackConfig.entry, path.join(__dirname, 'scripts/deprecate-old-dist.js'), + baseConfig.entry, ], output: { - ...coreWebpackConfig.output, + ...baseConfig.output, filename: 'dist/cms.js', }, }, diff --git a/scripts/webpack.js b/scripts/webpack.js index a21637ab..b57845a0 100644 --- a/scripts/webpack.js +++ b/scripts/webpack.js @@ -25,9 +25,6 @@ const rules = () => ({ const plugins = () => { return { - define: () => new webpack.DefinePlugin({ - NETLIFY_CMS_VERSION: JSON.stringify(`${pkg.version}${isProduction ? '' : '-dev'}`), - }), ignoreEsprima: () => new webpack.IgnorePlugin(/^esprima$/, /js-yaml/), ignoreMomentOptionalDeps: () => new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), friendlyErrors: () => new FriendlyErrorsWebpackPlugin(),