Skip to content

Commit 43e19df

Browse files
authored
fix: Fix broken assetsDir due to updated copy-webpack-plugin (styleguidist#1690)
Because copy-webpack-pluign was updated, the assetsDir was broken. We need to update the config being passed to the plugin to make it work again. Update the plugin to latest version 6.1.0 and update the config and tests to make it work. Fixes styleguidist#1676
1 parent a31f348 commit 43e19df

File tree

5 files changed

+44
-24
lines changed

5 files changed

+44
-24
lines changed

package-lock.json

Lines changed: 28 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"clipboard-copy": "^3.1.0",
3939
"clsx": "^1.0.4",
4040
"common-dir": "^3.0.0",
41-
"copy-webpack-plugin": "^6.0.3",
41+
"copy-webpack-plugin": "^6.1.0",
4242
"core-js": "^3.6.4",
4343
"doctrine": "^3.0.0",
4444
"es6-object-assign": "~1.1.0",
@@ -106,7 +106,7 @@
106106
"@testing-library/jest-dom": "^5.3.0",
107107
"@testing-library/react": "^10.0.1",
108108
"@types/buble": "^0.19.2",
109-
"@types/copy-webpack-plugin": "^5.0.0",
109+
"@types/copy-webpack-plugin": "^5.0.2",
110110
"@types/doctrine": "0.0.3",
111111
"@types/enzyme": "^3.10.3",
112112
"@types/escodegen": "0.0.6",

src/loaders/utils/__tests__/highlightCode.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ it('should warn when language not found', () => {
1717
const actual = highlightCode(code, 'pizza');
1818
expect(actual).toBe(code);
1919
expect(warn).toBeCalledWith(
20-
'Syntax highlighting for “pizza” isn’t supported. Supported languages are: markup, xml, html, mathml, svg, css, clike, javascript, js, markdown, md, scss, less, flow, typescript, ts, jsx, tsx, graphql, json, bash, shell, diff.'
20+
'Syntax highlighting for “pizza” isn’t supported. Supported languages are: markup, html, mathml, svg, xml, ssml, atom, rss, css, clike, javascript, js, markdown, md, scss, less, flow, typescript, ts, jsx, tsx, graphql, json, webmanifest, bash, shell, diff.'
2121
);
2222
});
2323

src/scripts/__tests__/make-webpack-config.spec.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,16 @@ it('should enable verbose mode in CleanWebpackPlugin', () => {
117117

118118
it('should set from with assetsDir in CopyWebpackPlugin', () => {
119119
makeWebpackConfig({ ...styleguideConfig, assetsDir: '/assets/' }, 'production');
120-
expect(CopyWebpackPlugin).toHaveBeenCalledWith([{ from: '/assets/' }]); //([
120+
expect(CopyWebpackPlugin).toHaveBeenCalledWith({
121+
patterns: [{ from: '/assets/' }],
122+
});
121123
});
122124

123125
it('should set array of from with assetsDir array in CopyWebpackPlugin', () => {
124126
makeWebpackConfig({ ...styleguideConfig, assetsDir: ['/assets1/', '/assets2/'] }, 'production');
125-
expect(CopyWebpackPlugin).toHaveBeenCalledWith([{ from: '/assets1/' }, { from: '/assets2/' }]);
127+
expect(CopyWebpackPlugin).toHaveBeenCalledWith({
128+
patterns: [{ from: '/assets1/' }, { from: '/assets2/' }],
129+
});
126130
});
127131

128132
it('should merge user webpack config', () => {

src/scripts/make-webpack-config.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,14 @@ export default function(
108108
},
109109
});
110110
if (config.assetsDir && webpackConfig.plugins) {
111+
const copyPatterns = {
112+
patterns: castArray(config.assetsDir).map(dir => ({ from: dir })),
113+
};
111114
webpackConfig.plugins.push(
112-
new CopyWebpackPlugin(castArray(config.assetsDir).map(dir => ({ from: dir })))
115+
// FIXME: Since we don't have the type of [email protected]
116+
// we cast the config as any to make it work. Once the new types are
117+
// released we must remove the cast.
118+
new CopyWebpackPlugin(copyPatterns as any)
113119
);
114120
}
115121
} else {

0 commit comments

Comments
 (0)