Repository: styleguidist/react-styleguidist
Pull request #1367 (2019-05-17 20:09:25)

Fix build if assetsDir is an array
copy-webpack-plugin is not allowing `from` to be as an array.
If we still want to use `from` and support array format for
assetsDir, then we should pass an array of objects {from: ...} to
copy-webpack-plugin

iss: #1320

codecov-io: # [Codecov](https://codecov.io/gh/styleguidist/react-styleguidist/pull/1367?src=pr&el=h1) Report
> Merging [#1367](https://codecov.io/gh/styleguidist/react-styleguidist/pull/1367?src=pr&el=desc) into [master](https://codecov.io/gh/styleguidist/react-styleguidist/commit/010761b5752ac43841aa54837c5562eddd8f9d82?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

| [Impacted Files](https://codecov.io/gh/styleguidist/react-styleguidist/pull/1367?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/scripts/make-webpack-config.js](https://codecov.io/gh/styleguidist/react-styleguidist/pull/1367/diff?src=pr&el=tree#diff-c3JjL3NjcmlwdHMvbWFrZS13ZWJwYWNrLWNvbmZpZy5qcw==) | `100% <100%> (ø)` | :arrow_up: |


Patch:
diff --git a/src/loaders/utils/getSections.js b/src/loaders/utils/getSections.js
index 05845ee0..9d1bbdd1 100644
--- a/src/loaders/utils/getSections.js
+++ b/src/loaders/utils/getSections.js
@@ -65,7 +65,7 @@ function processSection(section, config, parentDepth) {
 		usageMode: section.usageMode || config.usageMode,
 		sectionDepth,
 		description: section.description,
-		slug: slugger.slug(section.name),
+		slug: `section-${slugger.slug(section.name)}`,
 		sections: getSections(section.sections || [], config, sectionDepth),
 		filepath: contentRelativePath,
 		href: section.href,
diff --git a/src/scripts/make-webpack-config.js b/src/scripts/make-webpack-config.js
index 4d6cb14e..2737bd44 100644
--- a/src/scripts/make-webpack-config.js
+++ b/src/scripts/make-webpack-config.js
@@ -1,4 +1,5 @@
 const path = require('path');
+const castArray = require('lodash/castArray');
 const webpack = require('webpack');
 const TerserPlugin = require('terser-webpack-plugin');
 const MiniHtmlWebpackPlugin = require('mini-html-webpack-plugin');
@@ -92,13 +93,7 @@ module.exports = function(config, env) {
 					verbose: config.verbose === true,
 				}),
 				new CopyWebpackPlugin(
-					config.assetsDir
-						? [
-								{
-									from: config.assetsDir,
-								},
-						  ]
-						: []
+					config.assetsDir ? castArray(config.assetsDir).map(dir => ({ from: dir })) : []
 				),
 			],
 			optimization: {


Test patch:
diff --git a/src/loaders/utils/__tests__/__snapshots__/getSections.spec.js.snap b/src/loaders/utils/__tests__/__snapshots__/getSections.spec.js.snap
index db060d2d..57e4fa20 100644
--- a/src/loaders/utils/__tests__/__snapshots__/getSections.spec.js.snap
+++ b/src/loaders/utils/__tests__/__snapshots__/getSections.spec.js.snap
@@ -15,7 +15,7 @@ Array [
     "name": "Readme",
     "sectionDepth": 0,
     "sections": Array [],
-    "slug": "readme-1",
+    "slug": "section-readme-1",
     "usageMode": "collapse",
   },
   Object {
@@ -97,7 +97,7 @@ Array [
     "name": "Components",
     "sectionDepth": 0,
     "sections": Array [],
-    "slug": "components-1",
+    "slug": "section-components-1",
     "usageMode": "collapse",
   },
   Object {
@@ -179,7 +179,7 @@ Array [
     "name": "Ignore",
     "sectionDepth": 0,
     "sections": Array [],
-    "slug": "ignore-1",
+    "slug": "section-ignore-1",
     "usageMode": "collapse",
   },
 ]
@@ -265,7 +265,7 @@ Object {
   "name": "Components",
   "sectionDepth": 0,
   "sections": Array [],
-  "slug": "components",
+  "slug": "section-components",
   "usageMode": "collapse",
 }
 `;
@@ -284,7 +284,7 @@ Object {
   "name": "Readme",
   "sectionDepth": 0,
   "sections": Array [],
-  "slug": "readme",
+  "slug": "section-readme",
   "usageMode": "collapse",
 }
 `;
@@ -369,7 +369,7 @@ Object {
   "name": "Ignore",
   "sectionDepth": 0,
   "sections": Array [],
-  "slug": "ignore",
+  "slug": "section-ignore",
   "usageMode": "collapse",
 }
 `;
diff --git a/src/scripts/__tests__/make-webpack-config.spec.js b/src/scripts/__tests__/make-webpack-config.spec.js
index 7824e659..0ecc341a 100644
--- a/src/scripts/__tests__/make-webpack-config.spec.js
+++ b/src/scripts/__tests__/make-webpack-config.spec.js
@@ -114,6 +114,11 @@ it('should set from with assetsDir in CopyWebpackPlugin', () => {
 	expect(CopyWebpackPlugin).toHaveBeenCalledWith([{ from: '/assets/' }]); //([
 });
 
+it('should set array of from with assetsDir array in CopyWebpackPlugin', () => {
+	makeWebpackConfig({ ...styleguideConfig, assetsDir: ['/assets1/', '/assets2/'] }, 'production');
+	expect(CopyWebpackPlugin).toHaveBeenCalledWith([{ from: '/assets1/' }, { from: '/assets2/' }]);
+});
+
 it('should add CopyWebpackPlugin to plugins in production', () => {
 	makeWebpackConfig({ ...styleguideConfig }, 'production');
 	expect(CopyWebpackPlugin).toHaveBeenCalledWith([]);