Skip to content

Commit

Permalink
Merge pull request #75 from easyops-cn/steve/fix-joi
Browse files Browse the repository at this point in the history
feat: fix error of mixing of joi schemas
  • Loading branch information
weareoutman authored Apr 20, 2021
2 parents d7c9a46 + a4ed874 commit ed0c371
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 92 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,8 @@ DEBUG=search-local:* yarn build
In case some specific errors occurred:

- `Error: Cannot mix different versions of joi schemas`:
- Try using @easyops-cn/docusaurus-search-local >= v0.14.0 with Docusaurus >= v2.0.0-alpha.68
- Try using @easyops-cn/docusaurus-search-local >= v0.16.0 with Docusaurus >= v2.0.0-alpha.73
- Try using @easyops-cn/docusaurus-search-local between v0.14.0 and v0.15.1 with Docusaurus between v2.0.0-alpha.68 and v2.0.0-alpha.72
- Or try using @easyops-cn/docusaurus-search-local <= v0.13.1 with Docusaurus <= v2.0.0-alpha.66
- `Error: Command failed with signal "SIGSEGV"`:
- This is probably caused by a [known issue](https://github.com/yanyiwu/nodejieba/issues/187) introduced by `nodejieba@2.5.2`, if you enabled language of zh.
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
},
"license": "MIT",
"dependencies": {
"@docusaurus/utils": "^2.0.0-alpha.69",
"@docusaurus/utils": "^2.0.0-alpha.73",
"@docusaurus/utils-validation": "^2.0.0-alpha.73",
"@easyops-cn/autocomplete.js": "^0.38.1",
"cheerio": "^1.0.0-rc.3",
"clsx": "^1.1.1",
"debug": "^4.2.0",
"fs-extra": "^9.0.1",
"joi": "^17.3.0",
"klaw-sync": "^6.0.0",
"lunr": "^2.3.9",
"lunr-languages": "^1.4.0",
Expand All @@ -43,7 +43,7 @@
"@babel/preset-env": "^7.12.1",
"@babel/preset-react": "^7.12.1",
"@babel/preset-typescript": "^7.12.1",
"@docusaurus/module-type-aliases": "^2.0.0-alpha.69",
"@docusaurus/module-type-aliases": "^2.0.0-alpha.73",
"@tsconfig/docusaurus": "^1.0.2",
"@types/debug": "^4.1.5",
"@types/enzyme": "^3.10.7",
Expand Down
4 changes: 4 additions & 0 deletions src/client/theme/SearchBar/SearchBar.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ html[data-theme="dark"] .noResultsIcon {
text-decoration: underline;
}

.searchBarContainer {
margin-left: 16px;
}

.searchBarContainer .searchBarLoadingRing {
display: none;
position: absolute;
Expand Down
84 changes: 42 additions & 42 deletions src/server/utils/validateOptions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import Joi from "joi";
import { Joi } from "@docusaurus/utils-validation";
import { PluginOptions } from "../../shared/interfaces";
import { validateOptions } from "./validateOptions";

describe("validateOptions", () => {
const defaultTranslations = {
"search_placeholder": "Search",
"see_all_results": "See all results",
"no_results": "No results.",
"search_results_for": "Search results for \"{{ keyword }}\"",
"search_the_documentation": "Search the documentation",
"count_documents_found": "{{ count }} document found",
"count_documents_found_plural": "{{ count }} documents found",
"no_documents_were_found": "No documents were found"
search_placeholder: "Search",
see_all_results: "See all results",
no_results: "No results.",
search_results_for: 'Search results for "{{ keyword }}"',
search_the_documentation: "Search the documentation",
count_documents_found: "{{ count }} document found",
count_documents_found_plural: "{{ count }} documents found",
no_documents_were_found: "No documents were found",
};

function validate(
Expand Down Expand Up @@ -139,15 +139,15 @@ describe("validateOptions", () => {
[
{
translations: {
"search_placeholder": "搜索",
"see_all_results": "查看全部结果",
"no_results": "没有找到任何文档。",
"search_results_for": "搜索 “{{ keyword }}”",
"search_the_documentation": "搜索文档",
search_placeholder: "搜索",
see_all_results: "查看全部结果",
no_results: "没有找到任何文档。",
search_results_for: "搜索 “{{ keyword }}”",
search_the_documentation: "搜索文档",
// `*_plural` can be omitted if it is the same as singular.
"count_documents_found": "共找到 {{ count }} 篇文档",
"no_documents_were_found": "没有找到任何文档"
}
count_documents_found: "共找到 {{ count }} 篇文档",
no_documents_were_found: "没有找到任何文档",
},
},
{
blogRouteBasePath: ["blog"],
Expand All @@ -164,30 +164,30 @@ describe("validateOptions", () => {
searchResultLimits: 8,
searchResultContextMaxLength: 50,
translations: {
"search_placeholder": "搜索",
"see_all_results": "查看全部结果",
"no_results": "没有找到任何文档。",
"search_results_for": "搜索 “{{ keyword }}”",
"search_the_documentation": "搜索文档",
"count_documents_found": "共找到 {{ count }} 篇文档",
"count_documents_found_plural": "共找到 {{ count }} 篇文档",
"no_documents_were_found": "没有找到任何文档"
search_placeholder: "搜索",
see_all_results: "查看全部结果",
no_results: "没有找到任何文档。",
search_results_for: "搜索 “{{ keyword }}”",
search_the_documentation: "搜索文档",
count_documents_found: "共找到 {{ count }} 篇文档",
count_documents_found_plural: "共找到 {{ count }} 篇文档",
no_documents_were_found: "没有找到任何文档",
},
},
],
[
{
translations: {
"search_placeholder": "搜索",
"see_all_results": "查看全部结果",
"no_results": "没有找到任何文档。",
"search_results_for": "搜索 “{{ keyword }}”",
"search_the_documentation": "搜索文档",
"count_documents_found": "共找到一篇文档",
search_placeholder: "搜索",
see_all_results: "查看全部结果",
no_results: "没有找到任何文档。",
search_results_for: "搜索 “{{ keyword }}”",
search_the_documentation: "搜索文档",
count_documents_found: "共找到一篇文档",
// Explicitly override `*_plural`.
"count_documents_found_plural": "共找到 {{ count }} 篇文档",
"no_documents_were_found": "没有找到任何文档"
}
count_documents_found_plural: "共找到 {{ count }} 篇文档",
no_documents_were_found: "没有找到任何文档",
},
},
{
blogRouteBasePath: ["blog"],
Expand All @@ -204,14 +204,14 @@ describe("validateOptions", () => {
searchResultLimits: 8,
searchResultContextMaxLength: 50,
translations: {
"search_placeholder": "搜索",
"see_all_results": "查看全部结果",
"no_results": "没有找到任何文档。",
"search_results_for": "搜索 “{{ keyword }}”",
"search_the_documentation": "搜索文档",
"count_documents_found": "共找到一篇文档",
"count_documents_found_plural": "共找到 {{ count }} 篇文档",
"no_documents_were_found": "没有找到任何文档"
search_placeholder: "搜索",
see_all_results: "查看全部结果",
no_results: "没有找到任何文档。",
search_results_for: "搜索 “{{ keyword }}”",
search_the_documentation: "搜索文档",
count_documents_found: "共找到一篇文档",
count_documents_found_plural: "共找到 {{ count }} 篇文档",
no_documents_were_found: "没有找到任何文档",
},
},
],
Expand Down
14 changes: 10 additions & 4 deletions src/server/utils/validateOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Joi from "joi";
import { Joi } from "@docusaurus/utils-validation";
import { PluginOptions } from "../../shared/interfaces";

type ValidateFn = (
Expand Down Expand Up @@ -29,12 +29,18 @@ const schema = Joi.object<PluginOptions>({
search_placeholder: Joi.string().default("Search"),
see_all_results: Joi.string().default("See all results"),
no_results: Joi.string().default("No results."),
search_results_for: Joi.string().default("Search results for \"{{ keyword }}\""),
search_results_for: Joi.string().default(
'Search results for "{{ keyword }}"'
),
search_the_documentation: Joi.string().default("Search the documentation"),
count_documents_found_plural: Joi.string().default((parent) => parent.count_documents_found ?? "{{ count }} documents found"),
count_documents_found_plural: Joi.string().default(
(parent) => parent.count_documents_found ?? "{{ count }} documents found"
),
count_documents_found: Joi.string().default("{{ count }} document found"),
no_documents_were_found: Joi.string().default("No documents were found"),
}).default().unknown(false),
})
.default()
.unknown(false),
});

export function validateOptions({
Expand Down
106 changes: 64 additions & 42 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -960,34 +960,46 @@
exec-sh "^0.3.2"
minimist "^1.2.0"

"@docusaurus/module-type-aliases@^2.0.0-alpha.69":
version "2.0.0-alpha.69"
resolved "https://registry.yarnpkg.com/@docusaurus/module-type-aliases/-/module-type-aliases-2.0.0-alpha.69.tgz#eb46ee531cab6e1ac8e9c148c4cffc8151f36751"
integrity sha512-4aYZ0KrydLe2t5Ae4LWF2QHhEu4mDJOwwpEf3kEsmZU+OBrWoMlN3W4QGPIt9rJmxrRk5pniz3o+XATSFXZNNQ==
"@docusaurus/module-type-aliases@^2.0.0-alpha.73":
version "2.0.0-alpha.73"
resolved "https://registry.yarnpkg.com/@docusaurus/module-type-aliases/-/module-type-aliases-2.0.0-alpha.73.tgz#8411a9d37562969974506059ffbd646056f44328"
integrity sha512-JHhRRxcn9Gwn1sFqaZtx0Yna8SeDBZypjtjuu1nulXXwaWr1L8fc1RHp1PXy+DNXQ3XkTMEqCX6HFniG271ipg==

"@docusaurus/types@2.0.0-alpha.69":
version "2.0.0-alpha.69"
resolved "https://registry.yarnpkg.com/@docusaurus/types/-/types-2.0.0-alpha.69.tgz#05d1a28f325600185b3cb4088326c865fb4b54a9"
integrity sha512-8TgHmUMH5q+5D93nyugk/dtUeGPblRE++gxxrwjNYnJucRUNDKRC8kJhEozODGcSfXddTeMalPvbRKSz9Pxj2g==
"@docusaurus/types@2.0.0-alpha.73":
version "2.0.0-alpha.73"
resolved "https://registry.yarnpkg.com/@docusaurus/types/-/types-2.0.0-alpha.73.tgz#d19947ab0b86586191025069cefbe84cfd77cfbd"
integrity sha512-+q7q178LS2mMTGD/U5KgloLGKtG8yzpqj+NOp2QprjFVqTfkwTFcMhN33PTZTUcDunMDuUt+LOo9hi9Vz9+r5Q==
dependencies:
"@types/webpack" "^4.41.0"
commander "^4.0.1"
commander "^5.1.0"
joi "^17.4.0"
querystring "0.2.0"
webpack-merge "^4.2.2"

"@docusaurus/utils@^2.0.0-alpha.69":
version "2.0.0-alpha.69"
resolved "https://registry.yarnpkg.com/@docusaurus/utils/-/utils-2.0.0-alpha.69.tgz#9532cd489742beede570575ab70265dacecb3f24"
integrity sha512-RpxqcjPT0L+MxLyS/4QOHp/2hlKPcPoDyvfqtTJiS9DPtUzkH573a5/yMbfzz8IbPeYWRCPL2qxWtmN7XCZ/sQ==
"@docusaurus/utils-validation@^2.0.0-alpha.73":
version "2.0.0-alpha.73"
resolved "https://registry.yarnpkg.com/@docusaurus/utils-validation/-/utils-validation-2.0.0-alpha.73.tgz#d18708a681361ecd08f1628538358146a893c521"
integrity sha512-A36kKC+tCy/MGXdaK7emH2CHyHKru/+Td9zCm6fvNdNbu+dDNvEddTZ3ecjB0zNdDZM25Er4+KIo9GV3vnJ8Rg==
dependencies:
"@docusaurus/types" "2.0.0-alpha.69"
chalk "^3.0.0"
escape-string-regexp "^2.0.0"
fs-extra "^9.0.1"
"@docusaurus/utils" "2.0.0-alpha.73"
chalk "^4.1.0"
joi "^17.4.0"
tslib "^2.1.0"

"@docusaurus/utils@2.0.0-alpha.73", "@docusaurus/utils@^2.0.0-alpha.73":
version "2.0.0-alpha.73"
resolved "https://registry.yarnpkg.com/@docusaurus/utils/-/utils-2.0.0-alpha.73.tgz#eeca700e888e41961c9d06febed2256064e859e4"
integrity sha512-kUHnE1b/3yNWNAn0V8owLgCrxqyxfolkCbkPFfnRT+4m+agyn3riEcr+ZVObs7K9nxCla8oklX5RKSJGzyqWww==
dependencies:
"@docusaurus/types" "2.0.0-alpha.73"
"@types/github-slugger" "^1.3.0"
chalk "^4.1.0"
escape-string-regexp "^4.0.0"
fs-extra "^9.1.0"
gray-matter "^4.0.2"
lodash.camelcase "^4.3.0"
lodash.kebabcase "^4.1.1"
lodash "^4.17.20"
resolve-pathname "^3.0.0"
tslib "^2.1.0"

"@easyops-cn/autocomplete.js@^0.38.1":
version "0.38.1"
Expand Down Expand Up @@ -1351,6 +1363,11 @@
dependencies:
"@types/node" "*"

"@types/github-slugger@^1.3.0":
version "1.3.0"
resolved "https://registry.yarnpkg.com/@types/github-slugger/-/github-slugger-1.3.0.tgz#16ab393b30d8ae2a111ac748a015ac05a1fc5524"
integrity sha512-J/rMZa7RqiH/rT29TEVZO4nBoDP9XJOjnbbIofg7GQKs4JIduEO3WLpte+6WeUz/TcrXKlY+bM7FYrp8yFB+3g==

"@types/graceful-fs@^4.1.2":
version "4.1.3"
resolved "https://registry.yarnpkg.com/@types/graceful-fs/-/graceful-fs-4.1.3.tgz#039af35fe26bec35003e8d86d2ee9c586354348f"
Expand Down Expand Up @@ -2303,10 +2320,10 @@ commander@^2.19.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

commander@^4.0.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==
commander@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae"
integrity sha512-P0CysNDQ7rtVw4QIQtm+MRxV66vKFSvlsQvGYXZWR3qFU0jlMKHZZZgw8e+8DSah4UDKMqnknRDQz+xuQXQ/Zg==

commander@^6.0.0:
version "6.1.0"
Expand Down Expand Up @@ -3098,6 +3115,11 @@ escape-string-regexp@^2.0.0:
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==

escape-string-regexp@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-4.0.0.tgz#14ba83a5d373e3d311e5afca29cf5bfad965bf34"
integrity sha512-TtpcNJ3XAzx3Gq8sWRzJaVajRs0uVxA2YAkdb1jm2YkPz4G6egUFAyA3n5vtEIZefPk5Wa4UXbKuS5fKkJWdgA==

escodegen@^1.14.1:
version "1.14.3"
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.14.3.tgz#4e7b81fba61581dc97582ed78cab7f0e8d63f503"
Expand Down Expand Up @@ -3511,15 +3533,15 @@ fs-access@^1.0.1:
dependencies:
null-check "^1.0.0"

fs-extra@^9.0.1:
version "9.0.1"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.0.1.tgz#910da0062437ba4c39fedd863f1675ccfefcb9fc"
integrity sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ==
fs-extra@^9.0.1, fs-extra@^9.1.0:
version "9.1.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-9.1.0.tgz#5954460c764a8da2094ba3554bf839e6b9a7c86d"
integrity sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==
dependencies:
at-least-node "^1.0.0"
graceful-fs "^4.2.0"
jsonfile "^6.0.1"
universalify "^1.0.0"
universalify "^2.0.0"

fs-minipass@^1.2.5:
version "1.2.7"
Expand Down Expand Up @@ -4715,10 +4737,10 @@ jest@^26.5.3:
import-local "^3.0.2"
jest-cli "^26.5.3"

joi@^17.3.0:
version "17.3.0"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.3.0.tgz#f1be4a6ce29bc1716665819ac361dfa139fff5d2"
integrity sha512-Qh5gdU6niuYbUIUV5ejbsMiiFmBdw8Kcp8Buj2JntszCkCfxJ9Cz76OtHxOZMPXrt5810iDIXs+n1nNVoquHgg==
joi@^17.4.0:
version "17.4.0"
resolved "https://registry.yarnpkg.com/joi/-/joi-17.4.0.tgz#b5c2277c8519e016316e49ababd41a1908d9ef20"
integrity sha512-F4WiW2xaV6wc1jxete70Rw4V/VuMd6IN+a5ilZsxG4uYtUXWu2kq9W5P2dz30e7Gmw8RCbY/u/uk+dMPma9tAg==
dependencies:
"@hapi/hoek" "^9.0.0"
"@hapi/topo" "^5.0.0"
Expand Down Expand Up @@ -5001,11 +5023,6 @@ lodash._reinterpolate@^3.0.0:
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
integrity sha1-DM8tiRZq8Ds2Y8eWU4t1rG4RTZ0=

lodash.camelcase@^4.3.0:
version "4.3.0"
resolved "https://registry.yarnpkg.com/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz#b28aa6288a2b9fc651035c7711f65ab6190331a6"
integrity sha1-soqmKIorn8ZRA1x3EfZathkDMaY=

lodash.escape@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/lodash.escape/-/lodash.escape-4.0.1.tgz#c9044690c21e04294beaa517712fded1fa88de98"
Expand All @@ -5026,11 +5043,6 @@ lodash.ismatch@^4.4.0:
resolved "https://registry.yarnpkg.com/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz#756cb5150ca3ba6f11085a78849645f188f85f37"
integrity sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc=

lodash.kebabcase@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.kebabcase/-/lodash.kebabcase-4.1.1.tgz#8489b1cb0d29ff88195cceca448ff6d6cc295c36"
integrity sha1-hImxyw0p/4gZXM7KRI/21swpXDY=

lodash.sortby@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438"
Expand Down Expand Up @@ -7244,6 +7256,11 @@ tslib@^1.8.1, tslib@^1.9.0:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.14.1.tgz#cf2d38bdc34a134bcaf1091c41f6619e2f672d00"
integrity sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==

tslib@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.2.0.tgz#fb2c475977e35e241311ede2693cee1ec6698f5c"
integrity sha512-gS9GVHRU+RGn5KQM2rllAlR3dU6m7AcpJKdtH8gFvQiC4Otgk98XnmMU+nZenHt/+VhnBPWwgrJsyrdcw6i23w==

tsutils@^3.17.1:
version "3.17.1"
resolved "https://registry.yarnpkg.com/tsutils/-/tsutils-3.17.1.tgz#ed719917f11ca0dee586272b2ac49e015a2dd759"
Expand Down Expand Up @@ -7362,6 +7379,11 @@ universalify@^1.0.0:
resolved "https://registry.yarnpkg.com/universalify/-/universalify-1.0.0.tgz#b61a1da173e8435b2fe3c67d29b9adf8594bd16d"
integrity sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug==

universalify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/universalify/-/universalify-2.0.0.tgz#75a4984efedc4b08975c5aeb73f530d02df25717"
integrity sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==

unset-value@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"
Expand Down

0 comments on commit ed0c371

Please sign in to comment.