@docusaurus/utils-validation 2.0.0-beta.15 → 2.0.0-beta.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/JoiFrontMatter.d.ts +8 -0
- package/lib/JoiFrontMatter.d.ts.map +1 -1
- package/lib/JoiFrontMatter.js +8 -5
- package/lib/JoiFrontMatter.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +16 -5
- package/lib/index.js.map +1 -1
- package/lib/validationSchemas.d.ts.map +1 -1
- package/lib/validationSchemas.js +4 -2
- package/lib/validationSchemas.js.map +1 -1
- package/lib/validationUtils.d.ts +0 -2
- package/lib/validationUtils.d.ts.map +1 -1
- package/lib/validationUtils.js +6 -38
- package/lib/validationUtils.js.map +1 -1
- package/package.json +5 -9
- package/src/JoiFrontMatter.ts +8 -5
- package/src/index.ts +16 -2
- package/src/validationSchemas.ts +6 -2
- package/src/validationUtils.ts +5 -39
package/lib/JoiFrontMatter.d.ts
CHANGED
|
@@ -5,5 +5,13 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import Joi from './Joi';
|
|
8
|
+
/**
|
|
9
|
+
* Enhance the default Joi.string() type so that it can convert number to
|
|
10
|
+
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
11
|
+
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
12
|
+
* to dates automatically.
|
|
13
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
14
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
15
|
+
*/
|
|
8
16
|
export declare const JoiFrontMatter: typeof Joi;
|
|
9
17
|
//# sourceMappingURL=JoiFrontMatter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JoiFrontMatter.d.ts","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"JoiFrontMatter.d.ts","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAaxB;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,GAAsC,CAAC"}
|
package/lib/JoiFrontMatter.js
CHANGED
|
@@ -9,11 +9,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.JoiFrontMatter = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const Joi_1 = (0, tslib_1.__importDefault)(require("./Joi"));
|
|
12
|
-
// Enhance the default Joi.string() type so that it can convert number to strings
|
|
13
|
-
// If user use front matter "tag: 2021", we shouldn't need to ask the user to write "tag: '2021'"
|
|
14
|
-
// Also yaml tries to convert patterns like "2019-01-01" to dates automatically
|
|
15
|
-
// see https://github.com/facebook/docusaurus/issues/4642
|
|
16
|
-
// see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
17
12
|
const JoiFrontMatterString = {
|
|
18
13
|
type: 'string',
|
|
19
14
|
base: Joi_1.default.string(),
|
|
@@ -25,5 +20,13 @@ const JoiFrontMatterString = {
|
|
|
25
20
|
return { value };
|
|
26
21
|
},
|
|
27
22
|
};
|
|
23
|
+
/**
|
|
24
|
+
* Enhance the default Joi.string() type so that it can convert number to
|
|
25
|
+
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
26
|
+
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
27
|
+
* to dates automatically.
|
|
28
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
29
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
30
|
+
*/
|
|
28
31
|
exports.JoiFrontMatter = Joi_1.default.extend(JoiFrontMatterString);
|
|
29
32
|
//# sourceMappingURL=JoiFrontMatter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JoiFrontMatter.js","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6DAAwB;AAExB,
|
|
1
|
+
{"version":3,"file":"JoiFrontMatter.js","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6DAAwB;AAExB,MAAM,oBAAoB,GAAkB;IAC1C,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,aAAG,CAAC,MAAM,EAAE;IAClB,2EAA2E;IAC3E,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;QACjB,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,YAAY,IAAI,EAAE;YACtD,OAAO,EAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAC,CAAC;SAClC;QACD,OAAO,EAAC,KAAK,EAAC,CAAC;IACjB,CAAC;CACF,CAAC;AACF;;;;;;;GAOG;AACU,QAAA,cAAc,GAAe,aAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC"}
|
package/lib/index.d.ts
CHANGED
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { default as Joi } from './Joi';
|
|
8
8
|
export { JoiFrontMatter } from './JoiFrontMatter';
|
|
9
|
-
export
|
|
10
|
-
export
|
|
9
|
+
export { printWarning, normalizePluginOptions, normalizeThemeConfig, validateFrontMatter, } from './validationUtils';
|
|
10
|
+
export { PluginIdSchema, RemarkPluginsSchema, RehypePluginsSchema, AdmonitionsSchema, URISchema, PathnameSchema, FrontMatterTagsSchema, FrontMatterTOCHeadingLevels, } from './validationSchemas';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAC,OAAO,IAAI,GAAG,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAC,OAAO,IAAI,GAAG,EAAC,MAAM,OAAO,CAAC;AACrC,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAEhD,OAAO,EACL,YAAY,EACZ,sBAAsB,EACtB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,cAAc,EACd,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -6,13 +6,24 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.JoiFrontMatter = exports.Joi = void 0;
|
|
10
|
-
const tslib_1 = require("tslib");
|
|
9
|
+
exports.FrontMatterTOCHeadingLevels = exports.FrontMatterTagsSchema = exports.PathnameSchema = exports.URISchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = exports.JoiFrontMatter = exports.Joi = void 0;
|
|
11
10
|
// /!\ don't remove this export, as we recommend plugin authors to use it
|
|
12
11
|
var Joi_1 = require("./Joi");
|
|
13
|
-
Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return
|
|
12
|
+
Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return __importDefault(Joi_1).default; } });
|
|
14
13
|
var JoiFrontMatter_1 = require("./JoiFrontMatter");
|
|
15
14
|
Object.defineProperty(exports, "JoiFrontMatter", { enumerable: true, get: function () { return JoiFrontMatter_1.JoiFrontMatter; } });
|
|
16
|
-
|
|
17
|
-
(
|
|
15
|
+
var validationUtils_1 = require("./validationUtils");
|
|
16
|
+
Object.defineProperty(exports, "printWarning", { enumerable: true, get: function () { return validationUtils_1.printWarning; } });
|
|
17
|
+
Object.defineProperty(exports, "normalizePluginOptions", { enumerable: true, get: function () { return validationUtils_1.normalizePluginOptions; } });
|
|
18
|
+
Object.defineProperty(exports, "normalizeThemeConfig", { enumerable: true, get: function () { return validationUtils_1.normalizeThemeConfig; } });
|
|
19
|
+
Object.defineProperty(exports, "validateFrontMatter", { enumerable: true, get: function () { return validationUtils_1.validateFrontMatter; } });
|
|
20
|
+
var validationSchemas_1 = require("./validationSchemas");
|
|
21
|
+
Object.defineProperty(exports, "PluginIdSchema", { enumerable: true, get: function () { return validationSchemas_1.PluginIdSchema; } });
|
|
22
|
+
Object.defineProperty(exports, "RemarkPluginsSchema", { enumerable: true, get: function () { return validationSchemas_1.RemarkPluginsSchema; } });
|
|
23
|
+
Object.defineProperty(exports, "RehypePluginsSchema", { enumerable: true, get: function () { return validationSchemas_1.RehypePluginsSchema; } });
|
|
24
|
+
Object.defineProperty(exports, "AdmonitionsSchema", { enumerable: true, get: function () { return validationSchemas_1.AdmonitionsSchema; } });
|
|
25
|
+
Object.defineProperty(exports, "URISchema", { enumerable: true, get: function () { return validationSchemas_1.URISchema; } });
|
|
26
|
+
Object.defineProperty(exports, "PathnameSchema", { enumerable: true, get: function () { return validationSchemas_1.PathnameSchema; } });
|
|
27
|
+
Object.defineProperty(exports, "FrontMatterTagsSchema", { enumerable: true, get: function () { return validationSchemas_1.FrontMatterTagsSchema; } });
|
|
28
|
+
Object.defineProperty(exports, "FrontMatterTOCHeadingLevels", { enumerable: true, get: function () { return validationSchemas_1.FrontMatterTOCHeadingLevels; } });
|
|
18
29
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yEAAyE;AACzE,6BAAqC;AAA7B,2GAAA,OAAO,OAAO;AACtB,mDAAgD;AAAxC,gHAAA,cAAc,OAAA;AAEtB,qDAK2B;AAJzB,+GAAA,YAAY,OAAA;AACZ,yHAAA,sBAAsB,OAAA;AACtB,uHAAA,oBAAoB,OAAA;AACpB,sHAAA,mBAAmB,OAAA;AAErB,yDAS6B;AAR3B,mHAAA,cAAc,OAAA;AACd,wHAAA,mBAAmB,OAAA;AACnB,wHAAA,mBAAmB,OAAA;AACnB,sHAAA,iBAAiB,OAAA;AACjB,8GAAA,SAAS,OAAA;AACT,mHAAA,cAAc,OAAA;AACd,0HAAA,qBAAqB,OAAA;AACrB,gIAAA,2BAA2B,OAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationSchemas.d.ts","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAKxB,eAAO,MAAM,cAAc,
|
|
1
|
+
{"version":3,"file":"validationSchemas.d.ts","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAKxB,eAAO,MAAM,cAAc,kBAKE,CAAC;AAU9B,eAAO,MAAM,mBAAmB,iBAAwB,CAAC;AACzD,eAAO,MAAM,mBAAmB,iBAAwB,CAAC;AAEzD,eAAO,MAAM,iBAAiB,uBAA2B,CAAC;AAI1D,eAAO,MAAM,SAAS,wBAgBpB,CAAC;AAEH,eAAO,MAAM,cAAc,kBASxB,CAAC;AAeJ,eAAO,MAAM,qBAAqB,iBAK9B,CAAC;AAEL,eAAO,MAAM,2BAA2B;;;CASvC,CAAC"}
|
package/lib/validationSchemas.js
CHANGED
|
@@ -12,7 +12,8 @@ const Joi_1 = (0, tslib_1.__importDefault)(require("./Joi"));
|
|
|
12
12
|
const utils_1 = require("@docusaurus/utils");
|
|
13
13
|
const JoiFrontMatter_1 = require("./JoiFrontMatter");
|
|
14
14
|
exports.PluginIdSchema = Joi_1.default.string()
|
|
15
|
-
.regex(/^[a-zA-
|
|
15
|
+
.regex(/^[a-zA-Z0-9_-]+$/)
|
|
16
|
+
.message('Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.')
|
|
16
17
|
.default(utils_1.DEFAULT_PLUGIN_ID);
|
|
17
18
|
const MarkdownPluginsSchema = Joi_1.default.array()
|
|
18
19
|
.items(Joi_1.default.array().ordered(Joi_1.default.function().required(), Joi_1.default.object().required()), Joi_1.default.function(), Joi_1.default.object())
|
|
@@ -23,7 +24,8 @@ exports.AdmonitionsSchema = Joi_1.default.object().default({});
|
|
|
23
24
|
// TODO how can we make this emit a custom error message :'(
|
|
24
25
|
// Joi is such a pain, good luck to annoying trying to improve this
|
|
25
26
|
exports.URISchema = Joi_1.default.alternatives(Joi_1.default.string().uri({ allowRelative: true }),
|
|
26
|
-
// This custom validation logic is required notably because Joi does not
|
|
27
|
+
// This custom validation logic is required notably because Joi does not
|
|
28
|
+
// accept paths like /a/b/c ...
|
|
27
29
|
Joi_1.default.custom((val, helpers) => {
|
|
28
30
|
try {
|
|
29
31
|
// eslint-disable-next-line no-new
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationSchemas.js","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,6DAAwB;AACxB,6CAAqE;AAErE,qDAAgD;AAEnC,QAAA,cAAc,GAAG,aAAG,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E,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;KACjD,CAAC;IACF,qBAAqB,EAAE,+BAAc,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7D,CAAC"}
|
package/lib/validationUtils.d.ts
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import type Joi from './Joi';
|
|
8
|
-
export declare const isValidationDisabledEscapeHatch: boolean;
|
|
9
|
-
export declare const logValidationBugReportHint: () => void;
|
|
10
8
|
export declare function printWarning(warning?: Joi.ValidationError): void;
|
|
11
9
|
export declare function normalizePluginOptions<T extends {
|
|
12
10
|
id?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAI7B,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,eAAe,GAAG,IAAI,CAOhE;AAED,wBAAgB,sBAAsB,CAAC,CAAC,SAAS;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5D,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAClB,CAAC,CAiBH;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,GACtB,CAAC,CAgBH;AAED,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAC1B,CAAC,CAuBH"}
|
package/lib/validationUtils.js
CHANGED
|
@@ -6,27 +6,10 @@
|
|
|
6
6
|
* LICENSE file in the root directory of this source tree.
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning =
|
|
9
|
+
exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
11
|
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
12
|
const validationSchemas_1 = require("./validationSchemas");
|
|
13
|
-
// TODO temporary escape hatch for alpha-60: to be removed soon
|
|
14
|
-
// Our validation schemas might be buggy at first
|
|
15
|
-
// will permit users to bypass validation until we fix all validation errors
|
|
16
|
-
// see for example: https://github.com/facebook/docusaurus/pull/3120
|
|
17
|
-
// Undocumented on purpose, as we don't want users to keep using it over time
|
|
18
|
-
// Maybe we'll make this escape hatch official some day, with a better api?
|
|
19
|
-
exports.isValidationDisabledEscapeHatch = process.env.DISABLE_DOCUSAURUS_VALIDATION === 'true';
|
|
20
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
21
|
-
logger_1.default.error `You should avoid using code=${'DISABLE_DOCUSAURUS_VALIDATION'} escape hatch, this will be removed.`;
|
|
22
|
-
}
|
|
23
|
-
const logValidationBugReportHint = () => {
|
|
24
|
-
logger_1.default.error('A validation error occurred.');
|
|
25
|
-
logger_1.default.info(`The validation system was added recently to Docusaurus as an attempt to avoid user configuration errors.
|
|
26
|
-
We may have made some mistakes.
|
|
27
|
-
If you think your configuration is valid and should keep working, please open a bug report.`);
|
|
28
|
-
};
|
|
29
|
-
exports.logValidationBugReportHint = logValidationBugReportHint;
|
|
30
13
|
function printWarning(warning) {
|
|
31
14
|
if (warning) {
|
|
32
15
|
const warningMessages = warning.details
|
|
@@ -47,16 +30,9 @@ function normalizePluginOptions(schema, options) {
|
|
|
47
30
|
});
|
|
48
31
|
printWarning(warning);
|
|
49
32
|
if (error) {
|
|
50
|
-
|
|
51
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
52
|
-
logger_1.default.error(error);
|
|
53
|
-
return options;
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
33
|
+
throw error;
|
|
58
34
|
}
|
|
59
|
-
return value; // TODO remove !
|
|
35
|
+
return value; // TODO remove this ! in TS 4.6, see https://twitter.com/sebastienlorber/status/1481950042277793793
|
|
60
36
|
}
|
|
61
37
|
exports.normalizePluginOptions = normalizePluginOptions;
|
|
62
38
|
function normalizeThemeConfig(schema, themeConfig) {
|
|
@@ -69,16 +45,9 @@ function normalizeThemeConfig(schema, themeConfig) {
|
|
|
69
45
|
});
|
|
70
46
|
printWarning(warning);
|
|
71
47
|
if (error) {
|
|
72
|
-
|
|
73
|
-
if (exports.isValidationDisabledEscapeHatch) {
|
|
74
|
-
logger_1.default.error(error);
|
|
75
|
-
return themeConfig;
|
|
76
|
-
}
|
|
77
|
-
else {
|
|
78
|
-
throw error;
|
|
79
|
-
}
|
|
48
|
+
throw error;
|
|
80
49
|
}
|
|
81
|
-
return value; // TODO remove !
|
|
50
|
+
return value; // TODO remove this ! in TS 4.6
|
|
82
51
|
}
|
|
83
52
|
exports.normalizeThemeConfig = normalizeThemeConfig;
|
|
84
53
|
function validateFrontMatter(frontMatter, schema) {
|
|
@@ -92,7 +61,6 @@ function validateFrontMatter(frontMatter, schema) {
|
|
|
92
61
|
const frontMatterString = JSON.stringify(frontMatter, null, 2);
|
|
93
62
|
const errorDetails = error.details;
|
|
94
63
|
const invalidFields = errorDetails.map(({ path }) => path).join(', ');
|
|
95
|
-
(0, exports.logValidationBugReportHint)();
|
|
96
64
|
logger_1.default.error `The following front matter:
|
|
97
65
|
${logger_1.default.yellow(frontMatterString)}
|
|
98
66
|
contains invalid values for field(s): ${logger_1.default.yellow(invalidFields)}.
|
|
@@ -100,7 +68,7 @@ ${errorDetails.map(({ message }) => message)}
|
|
|
100
68
|
`;
|
|
101
69
|
throw error;
|
|
102
70
|
}
|
|
103
|
-
return value; // TODO remove !
|
|
71
|
+
return value; // TODO remove this ! in TS 4.6
|
|
104
72
|
}
|
|
105
73
|
exports.validateFrontMatter = validateFrontMatter;
|
|
106
74
|
//# sourceMappingURL=validationUtils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,6EAAwC;AACxC,2DAAmD;AAEnD
|
|
1
|
+
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,6EAAwC;AACxC,2DAAmD;AAEnD,SAAgB,YAAY,CAAC,OAA6B;IACxD,IAAI,OAAO,EAAE;QACX,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO;aACpC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,CAAC;aAC3B,IAAI,CAAC,IAAI,CAAC,CAAC;QACd,gBAAM,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;KAC9B;AACH,CAAC;AAPD,oCAOC;AAED,SAAgB,sBAAsB,CACpC,MAA2B,EAC3B,OAAmB;IAEnB,sEAAsE;IACtE,yCAAyC;IACzC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC;QAChC,EAAE,EAAE,kCAAc;KACnB,CAAC,CAAC;IACH,MAAM,EAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAC,GAAG,WAAW,CAAC,QAA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QAEpE,gBAAM,CAAC,KAAK,CAAA;EACd,gBAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC;wCACM,gBAAM,CAAC,MAAM,CAAC,aAAa,CAAC;EAClE,YAAY,CAAC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,CAAC;CACzC,CAAC;QACE,MAAM,KAAK,CAAC;KACb;IAED,OAAO,KAAM,CAAC,CAAC,+BAA+B;AAChD,CAAC;AA1BD,kDA0BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils-validation",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.16",
|
|
4
4
|
"description": "Node validation utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,17 +18,13 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/logger": "2.0.0-beta.
|
|
22
|
-
"@docusaurus/utils": "2.0.0-beta.
|
|
23
|
-
"joi": "^17.
|
|
21
|
+
"@docusaurus/logger": "2.0.0-beta.16",
|
|
22
|
+
"@docusaurus/utils": "2.0.0-beta.16",
|
|
23
|
+
"joi": "^17.6.0",
|
|
24
24
|
"tslib": "^2.3.1"
|
|
25
25
|
},
|
|
26
|
-
"peerDependencies": {
|
|
27
|
-
"react": "*",
|
|
28
|
-
"react-dom": "*"
|
|
29
|
-
},
|
|
30
26
|
"engines": {
|
|
31
27
|
"node": ">=14"
|
|
32
28
|
},
|
|
33
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "eb43c4d4f95a4fb97dc9bb9dc615413e0dc2e1e7"
|
|
34
30
|
}
|
package/src/JoiFrontMatter.ts
CHANGED
|
@@ -7,11 +7,6 @@
|
|
|
7
7
|
|
|
8
8
|
import Joi from './Joi';
|
|
9
9
|
|
|
10
|
-
// Enhance the default Joi.string() type so that it can convert number to strings
|
|
11
|
-
// If user use front matter "tag: 2021", we shouldn't need to ask the user to write "tag: '2021'"
|
|
12
|
-
// Also yaml tries to convert patterns like "2019-01-01" to dates automatically
|
|
13
|
-
// see https://github.com/facebook/docusaurus/issues/4642
|
|
14
|
-
// see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
15
10
|
const JoiFrontMatterString: Joi.Extension = {
|
|
16
11
|
type: 'string',
|
|
17
12
|
base: Joi.string(),
|
|
@@ -23,4 +18,12 @@ const JoiFrontMatterString: Joi.Extension = {
|
|
|
23
18
|
return {value};
|
|
24
19
|
},
|
|
25
20
|
};
|
|
21
|
+
/**
|
|
22
|
+
* Enhance the default Joi.string() type so that it can convert number to
|
|
23
|
+
* strings. If user use front matter "tag: 2021", we shouldn't need to ask her
|
|
24
|
+
* to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
|
|
25
|
+
* to dates automatically.
|
|
26
|
+
* @see https://github.com/facebook/docusaurus/issues/4642
|
|
27
|
+
* @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
|
|
28
|
+
*/
|
|
26
29
|
export const JoiFrontMatter: typeof Joi = Joi.extend(JoiFrontMatterString);
|
package/src/index.ts
CHANGED
|
@@ -9,5 +9,19 @@
|
|
|
9
9
|
export {default as Joi} from './Joi';
|
|
10
10
|
export {JoiFrontMatter} from './JoiFrontMatter';
|
|
11
11
|
|
|
12
|
-
export
|
|
13
|
-
|
|
12
|
+
export {
|
|
13
|
+
printWarning,
|
|
14
|
+
normalizePluginOptions,
|
|
15
|
+
normalizeThemeConfig,
|
|
16
|
+
validateFrontMatter,
|
|
17
|
+
} from './validationUtils';
|
|
18
|
+
export {
|
|
19
|
+
PluginIdSchema,
|
|
20
|
+
RemarkPluginsSchema,
|
|
21
|
+
RehypePluginsSchema,
|
|
22
|
+
AdmonitionsSchema,
|
|
23
|
+
URISchema,
|
|
24
|
+
PathnameSchema,
|
|
25
|
+
FrontMatterTagsSchema,
|
|
26
|
+
FrontMatterTOCHeadingLevels,
|
|
27
|
+
} from './validationSchemas';
|
package/src/validationSchemas.ts
CHANGED
|
@@ -11,7 +11,10 @@ import type {Tag} from '@docusaurus/utils';
|
|
|
11
11
|
import {JoiFrontMatter} from './JoiFrontMatter';
|
|
12
12
|
|
|
13
13
|
export const PluginIdSchema = Joi.string()
|
|
14
|
-
.regex(/^[a-zA-
|
|
14
|
+
.regex(/^[a-zA-Z0-9_-]+$/)
|
|
15
|
+
.message(
|
|
16
|
+
'Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.',
|
|
17
|
+
)
|
|
15
18
|
.default(DEFAULT_PLUGIN_ID);
|
|
16
19
|
|
|
17
20
|
const MarkdownPluginsSchema = Joi.array()
|
|
@@ -31,7 +34,8 @@ export const AdmonitionsSchema = Joi.object().default({});
|
|
|
31
34
|
// Joi is such a pain, good luck to annoying trying to improve this
|
|
32
35
|
export const URISchema = Joi.alternatives(
|
|
33
36
|
Joi.string().uri({allowRelative: true}),
|
|
34
|
-
// This custom validation logic is required notably because Joi does not
|
|
37
|
+
// This custom validation logic is required notably because Joi does not
|
|
38
|
+
// accept paths like /a/b/c ...
|
|
35
39
|
Joi.custom((val, helpers) => {
|
|
36
40
|
try {
|
|
37
41
|
// eslint-disable-next-line no-new
|
package/src/validationUtils.ts
CHANGED
|
@@ -9,26 +9,6 @@ import type Joi from './Joi';
|
|
|
9
9
|
import logger from '@docusaurus/logger';
|
|
10
10
|
import {PluginIdSchema} from './validationSchemas';
|
|
11
11
|
|
|
12
|
-
// TODO temporary escape hatch for alpha-60: to be removed soon
|
|
13
|
-
// Our validation schemas might be buggy at first
|
|
14
|
-
// will permit users to bypass validation until we fix all validation errors
|
|
15
|
-
// see for example: https://github.com/facebook/docusaurus/pull/3120
|
|
16
|
-
// Undocumented on purpose, as we don't want users to keep using it over time
|
|
17
|
-
// Maybe we'll make this escape hatch official some day, with a better api?
|
|
18
|
-
export const isValidationDisabledEscapeHatch =
|
|
19
|
-
process.env.DISABLE_DOCUSAURUS_VALIDATION === 'true';
|
|
20
|
-
|
|
21
|
-
if (isValidationDisabledEscapeHatch) {
|
|
22
|
-
logger.error`You should avoid using code=${'DISABLE_DOCUSAURUS_VALIDATION'} escape hatch, this will be removed.`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export const logValidationBugReportHint = (): void => {
|
|
26
|
-
logger.error('A validation error occurred.');
|
|
27
|
-
logger.info(`The validation system was added recently to Docusaurus as an attempt to avoid user configuration errors.
|
|
28
|
-
We may have made some mistakes.
|
|
29
|
-
If you think your configuration is valid and should keep working, please open a bug report.`);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
12
|
export function printWarning(warning?: Joi.ValidationError): void {
|
|
33
13
|
if (warning) {
|
|
34
14
|
const warningMessages = warning.details
|
|
@@ -54,16 +34,10 @@ export function normalizePluginOptions<T extends {id?: string}>(
|
|
|
54
34
|
printWarning(warning);
|
|
55
35
|
|
|
56
36
|
if (error) {
|
|
57
|
-
|
|
58
|
-
if (isValidationDisabledEscapeHatch) {
|
|
59
|
-
logger.error(error);
|
|
60
|
-
return options as T;
|
|
61
|
-
} else {
|
|
62
|
-
throw error;
|
|
63
|
-
}
|
|
37
|
+
throw error;
|
|
64
38
|
}
|
|
65
39
|
|
|
66
|
-
return value!; // TODO remove !
|
|
40
|
+
return value!; // TODO remove this ! in TS 4.6, see https://twitter.com/sebastienlorber/status/1481950042277793793
|
|
67
41
|
}
|
|
68
42
|
|
|
69
43
|
export function normalizeThemeConfig<T>(
|
|
@@ -82,15 +56,9 @@ export function normalizeThemeConfig<T>(
|
|
|
82
56
|
printWarning(warning);
|
|
83
57
|
|
|
84
58
|
if (error) {
|
|
85
|
-
|
|
86
|
-
if (isValidationDisabledEscapeHatch) {
|
|
87
|
-
logger.error(error);
|
|
88
|
-
return themeConfig as T;
|
|
89
|
-
} else {
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
59
|
+
throw error;
|
|
92
60
|
}
|
|
93
|
-
return value!; // TODO remove !
|
|
61
|
+
return value!; // TODO remove this ! in TS 4.6
|
|
94
62
|
}
|
|
95
63
|
|
|
96
64
|
export function validateFrontMatter<T>(
|
|
@@ -110,8 +78,6 @@ export function validateFrontMatter<T>(
|
|
|
110
78
|
const errorDetails = error.details;
|
|
111
79
|
const invalidFields = errorDetails.map(({path}) => path).join(', ');
|
|
112
80
|
|
|
113
|
-
logValidationBugReportHint();
|
|
114
|
-
|
|
115
81
|
logger.error`The following front matter:
|
|
116
82
|
${logger.yellow(frontMatterString)}
|
|
117
83
|
contains invalid values for field(s): ${logger.yellow(invalidFields)}.
|
|
@@ -120,5 +86,5 @@ ${errorDetails.map(({message}) => message)}
|
|
|
120
86
|
throw error;
|
|
121
87
|
}
|
|
122
88
|
|
|
123
|
-
return value!; // TODO remove !
|
|
89
|
+
return value!; // TODO remove this ! in TS 4.6
|
|
124
90
|
}
|