From 239a54d251d14f18665eb581635aa65c3b08b54d Mon Sep 17 00:00:00 2001 From: Swashata Ghosh Date: Tue, 8 Sep 2020 09:28:46 +0530 Subject: [PATCH 1/3] fix: broken assetsDir during build 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. --- package-lock.json | 46 +++++++++++-------- package.json | 4 +- .../__tests__/make-webpack-config.spec.ts | 8 +++- src/scripts/make-webpack-config.ts | 8 +++- 4 files changed, 43 insertions(+), 23 deletions(-) diff --git a/package-lock.json b/package-lock.json index a2e64bab2..632ae4c6c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2617,9 +2617,9 @@ } }, "@types/copy-webpack-plugin": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/@types/copy-webpack-plugin/-/copy-webpack-plugin-5.0.0.tgz", - "integrity": "sha512-yQHocgdgES7W5Q2UyxJ5cj/E6MrV1zq3MZ8jdApS9NJKqax+rux9IE3QAbBmNCGbgivEsejrkIq3Rm76JLubkg==", + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@types/copy-webpack-plugin/-/copy-webpack-plugin-5.0.2.tgz", + "integrity": "sha512-6W39znqAn74ML9jzQ60wbKqpjMU/5LQcqtHEKYfZ645INbGLNzJBuVwSYIVHlYpj6mrZBVd3E2ni7I0DXINw0w==", "dev": true, "requires": { "@types/minimatch": "*", @@ -5198,19 +5198,19 @@ "integrity": "sha1-Z29us8OZl8LuGsOpJP1hJHSPV40=" }, "copy-webpack-plugin": { - "version": "6.0.3", - "resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-6.0.3.tgz", - "integrity": "sha512-q5m6Vz4elsuyVEIUXr7wJdIdePWTubsqVbEMvf1WQnHGv0Q+9yPRu7MtYFPt+GBOXRav9lvIINifTQ1vSCs+eA==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-6.1.0.tgz", + "integrity": "sha512-aWjIuLt1OVQxaDVffnt3bnGmLA8zGgAJaFwPA+a+QYVPh1vhIKjVfh3SbOFLV0kRPvGBITbw17n5CsmiBS4LQQ==", "requires": { - "cacache": "^15.0.4", + "cacache": "^15.0.5", "fast-glob": "^3.2.4", "find-cache-dir": "^3.3.1", "glob-parent": "^5.1.1", "globby": "^11.0.1", "loader-utils": "^2.0.0", "normalize-path": "^3.0.0", - "p-limit": "^3.0.1", - "schema-utils": "^2.7.0", + "p-limit": "^3.0.2", + "schema-utils": "^2.7.1", "serialize-javascript": "^4.0.0", "webpack-sources": "^1.4.3" }, @@ -5220,10 +5220,15 @@ "resolved": "https://registry.npmjs.org/@nodelib/fs.stat/-/fs.stat-2.0.3.tgz", "integrity": "sha512-bQBFruR2TAwoevBEd/NWMoAAtNGzTRgdrqnYCc7dhzfoNvqPzLyqlEQnzZ3kVnNrSp25iyxE00/3h2fqGAGArA==" }, + "@types/json-schema": { + "version": "7.0.6", + "resolved": "https://registry.npmjs.org/@types/json-schema/-/json-schema-7.0.6.tgz", + "integrity": "sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==" + }, "ajv": { - "version": "6.12.3", - "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.3.tgz", - "integrity": "sha512-4K0cK3L1hsqk9xIb2z9vs/XU+PGJZ9PNpJRDS9YLzmNdX6jmVPfamLvTJr0aDAusnHyCHO6MjzlkAsgtqp9teA==", + "version": "6.12.4", + "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.4.tgz", + "integrity": "sha512-eienB2c9qVQs2KWexhkrdMLVDoIQCz5KSeLxwg9Lzk4DOfBtIK9PQwwufcsn1jjGuf9WZmqPMbGxOzfcuphJCQ==", "requires": { "fast-deep-equal": "^3.1.1", "fast-json-stable-stringify": "^2.0.0", @@ -5231,6 +5236,11 @@ "uri-js": "^4.2.2" } }, + "ajv-keywords": { + "version": "3.5.2", + "resolved": "https://registry.npmjs.org/ajv-keywords/-/ajv-keywords-3.5.2.tgz", + "integrity": "sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==" + }, "braces": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", @@ -5430,13 +5440,13 @@ } }, "schema-utils": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-2.7.0.tgz", - "integrity": "sha512-0ilKFI6QQF5nxDZLFn2dMjvc4hjg/Wkg7rHd3jK6/A4a1Hl9VFdQWvgB1UMGoU94pad1P/8N7fMcEnLnSiju8A==", + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-2.7.1.tgz", + "integrity": "sha512-SHiNtMOUGWBQJwzISiVYKu82GiV4QYGePp3odlY1tuKO7gPtphAT5R/py0fA6xtbgLL/RvtJZnU9b8s0F1q0Xg==", "requires": { - "@types/json-schema": "^7.0.4", - "ajv": "^6.12.2", - "ajv-keywords": "^3.4.1" + "@types/json-schema": "^7.0.5", + "ajv": "^6.12.4", + "ajv-keywords": "^3.5.2" } }, "serialize-javascript": { diff --git a/package.json b/package.json index 089bb6878..25c465c23 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "clipboard-copy": "^3.1.0", "clsx": "^1.0.4", "common-dir": "^3.0.0", - "copy-webpack-plugin": "^6.0.3", + "copy-webpack-plugin": "^6.1.0", "core-js": "^3.6.4", "doctrine": "^3.0.0", "es6-object-assign": "~1.1.0", @@ -106,7 +106,7 @@ "@testing-library/jest-dom": "^5.3.0", "@testing-library/react": "^10.0.1", "@types/buble": "^0.19.2", - "@types/copy-webpack-plugin": "^5.0.0", + "@types/copy-webpack-plugin": "^5.0.2", "@types/doctrine": "0.0.3", "@types/enzyme": "^3.10.3", "@types/escodegen": "0.0.6", diff --git a/src/scripts/__tests__/make-webpack-config.spec.ts b/src/scripts/__tests__/make-webpack-config.spec.ts index f9273f6fa..5df8b375c 100644 --- a/src/scripts/__tests__/make-webpack-config.spec.ts +++ b/src/scripts/__tests__/make-webpack-config.spec.ts @@ -117,12 +117,16 @@ it('should enable verbose mode in CleanWebpackPlugin', () => { it('should set from with assetsDir in CopyWebpackPlugin', () => { makeWebpackConfig({ ...styleguideConfig, assetsDir: '/assets/' }, 'production'); - expect(CopyWebpackPlugin).toHaveBeenCalledWith([{ from: '/assets/' }]); //([ + expect(CopyWebpackPlugin).toHaveBeenCalledWith({ + patterns: [{ 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/' }]); + expect(CopyWebpackPlugin).toHaveBeenCalledWith({ + patterns: [{ from: '/assets1/' }, { from: '/assets2/' }], + }); }); it('should merge user webpack config', () => { diff --git a/src/scripts/make-webpack-config.ts b/src/scripts/make-webpack-config.ts index 77b779f4e..d1992dfbc 100644 --- a/src/scripts/make-webpack-config.ts +++ b/src/scripts/make-webpack-config.ts @@ -108,8 +108,14 @@ export default function( }, }); if (config.assetsDir && webpackConfig.plugins) { + const copyPatterns = { + patterns: castArray(config.assetsDir).map(dir => ({ from: dir })), + }; webpackConfig.plugins.push( - new CopyWebpackPlugin(castArray(config.assetsDir).map(dir => ({ from: dir }))) + // since we don't have the type of copy-webpack-plugin@6.0 + // we cast the config as any to make it work. Once the new types are + // released we must remove the cast. + new CopyWebpackPlugin(copyPatterns as any) ); } } else { From f45dfb61deff5b51da483168f322580867f36670 Mon Sep 17 00:00:00 2001 From: Swashata Ghosh Date: Tue, 8 Sep 2020 09:54:24 +0530 Subject: [PATCH 2/3] fix: failing tests in highlightcode spec Error message was updated in code, but not in tests. --- src/loaders/utils/__tests__/highlightCode.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/loaders/utils/__tests__/highlightCode.spec.ts b/src/loaders/utils/__tests__/highlightCode.spec.ts index 2cd58c4d5..22bf714b5 100644 --- a/src/loaders/utils/__tests__/highlightCode.spec.ts +++ b/src/loaders/utils/__tests__/highlightCode.spec.ts @@ -17,7 +17,7 @@ it('should warn when language not found', () => { const actual = highlightCode(code, 'pizza'); expect(actual).toBe(code); expect(warn).toBeCalledWith( - '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.' + '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.' ); }); From bc47d4d4f4b5ee57e957e989ea805006df2a1d7b Mon Sep 17 00:00:00 2001 From: Swashata Ghosh <1623381+swashata@users.noreply.github.com> Date: Tue, 8 Sep 2020 11:11:10 +0530 Subject: [PATCH 3/3] chore: add fixme label to new copy-webpack-plugin config Since we don't have the latest types right now we have to cast to any. Once the types are released we can remove it. Co-authored-by: Artem Sapegin --- src/scripts/make-webpack-config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/make-webpack-config.ts b/src/scripts/make-webpack-config.ts index d1992dfbc..dbeb9a70b 100644 --- a/src/scripts/make-webpack-config.ts +++ b/src/scripts/make-webpack-config.ts @@ -112,7 +112,7 @@ export default function( patterns: castArray(config.assetsDir).map(dir => ({ from: dir })), }; webpackConfig.plugins.push( - // since we don't have the type of copy-webpack-plugin@6.0 + // FIXME: Since we don't have the type of copy-webpack-plugin@6.0 // we cast the config as any to make it work. Once the new types are // released we must remove the cast. new CopyWebpackPlugin(copyPatterns as any)