@docusaurus/utils-validation 2.0.0-beta.15d451942 → 2.0.0-beta.18

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/Joi.d.ts CHANGED
@@ -5,3 +5,4 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export { default } from 'joi';
8
+ //# sourceMappingURL=Joi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Joi.d.ts","sourceRoot":"","sources":["../src/Joi.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAC,OAAO,EAAC,MAAM,KAAK,CAAC"}
package/lib/Joi.js CHANGED
@@ -9,3 +9,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.default = void 0;
10
10
  var joi_1 = require("joi");
11
11
  Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(joi_1).default; } });
12
+ //# sourceMappingURL=Joi.js.map
package/lib/Joi.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Joi.js","sourceRoot":"","sources":["../src/Joi.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2BAA4B;AAApB,+GAAA,OAAO,OAAA"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
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
+ *
14
+ * @see https://github.com/facebook/docusaurus/issues/4642
15
+ * @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
16
+ */
17
+ export declare const JoiFrontMatter: typeof Joi;
18
+ //# sourceMappingURL=JoiFrontMatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JoiFrontMatter.d.ts","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAcxB;;;;;;;;GAQG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,GAAsC,CAAC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.JoiFrontMatter = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const Joi_1 = tslib_1.__importDefault(require("./Joi"));
12
+ const JoiFrontMatterString = {
13
+ type: 'string',
14
+ base: Joi_1.default.string(),
15
+ // Fix Yaml that tries to auto-convert many things to string out of the box
16
+ prepare: (value) => {
17
+ if (typeof value === 'number' || value instanceof Date) {
18
+ return { value: value.toString() };
19
+ }
20
+ return { value };
21
+ },
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
+ *
29
+ * @see https://github.com/facebook/docusaurus/issues/4642
30
+ * @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
31
+ */
32
+ exports.JoiFrontMatter = Joi_1.default.extend(JoiFrontMatterString);
33
+ //# sourceMappingURL=JoiFrontMatter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JoiFrontMatter.js","sourceRoot":"","sources":["../src/JoiFrontMatter.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAwB;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;AAEF;;;;;;;;GAQG;AACU,QAAA,cAAc,GAAe,aAAG,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC"}
package/lib/index.d.ts CHANGED
@@ -5,5 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
  export { default as Joi } from './Joi';
8
- export * from './validationUtils';
9
- export * from './validationSchemas';
8
+ export { JoiFrontMatter } from './JoiFrontMatter';
9
+ export { printWarning, normalizePluginOptions, normalizeThemeConfig, validateFrontMatter, } from './validationUtils';
10
+ export { PluginIdSchema, RemarkPluginsSchema, RehypePluginsSchema, AdmonitionsSchema, URISchema, PathnameSchema, FrontMatterTagsSchema, FrontMatterTOCHeadingLevels, } from './validationSchemas';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,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,10 +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.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 tslib_1.__importDefault(Joi_1).default; } });
14
- tslib_1.__exportStar(require("./validationUtils"), exports);
15
- tslib_1.__exportStar(require("./validationSchemas"), exports);
12
+ Object.defineProperty(exports, "Joi", { enumerable: true, get: function () { return __importDefault(Joi_1).default; } });
13
+ var JoiFrontMatter_1 = require("./JoiFrontMatter");
14
+ Object.defineProperty(exports, "JoiFrontMatter", { enumerable: true, get: function () { return JoiFrontMatter_1.JoiFrontMatter; } });
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; } });
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"}
@@ -11,3 +11,9 @@ export declare const RehypePluginsSchema: Joi.ArraySchema;
11
11
  export declare const AdmonitionsSchema: Joi.ObjectSchema<any>;
12
12
  export declare const URISchema: Joi.AlternativesSchema;
13
13
  export declare const PathnameSchema: Joi.StringSchema;
14
+ export declare const FrontMatterTagsSchema: Joi.ArraySchema;
15
+ export declare const FrontMatterTOCHeadingLevels: {
16
+ toc_min_heading_level: Joi.NumberSchema;
17
+ toc_max_heading_level: Joi.NumberSchema;
18
+ };
19
+ //# sourceMappingURL=validationSchemas.d.ts.map
@@ -0,0 +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,kBAKE,CAAC;AAe9B,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"}
@@ -1,46 +1,78 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PathnameSchema = exports.URISchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = void 0;
4
- const tslib_1 = require("tslib");
5
2
  /**
6
3
  * Copyright (c) Facebook, Inc. and its affiliates.
7
4
  *
8
5
  * This source code is licensed under the MIT license found in the
9
6
  * LICENSE file in the root directory of this source tree.
10
7
  */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.FrontMatterTOCHeadingLevels = exports.FrontMatterTagsSchema = exports.PathnameSchema = exports.URISchema = exports.AdmonitionsSchema = exports.RehypePluginsSchema = exports.RemarkPluginsSchema = exports.PluginIdSchema = void 0;
10
+ const tslib_1 = require("tslib");
11
11
  const Joi_1 = tslib_1.__importDefault(require("./Joi"));
12
12
  const utils_1 = require("@docusaurus/utils");
13
+ const JoiFrontMatter_1 = require("./JoiFrontMatter");
13
14
  exports.PluginIdSchema = Joi_1.default.string()
14
- .regex(/^[a-zA-Z_-]+$/)
15
- // duplicate core constant, otherwise cyclic dependency is created :(
16
- .default('default');
15
+ .regex(/^[\w-]+$/)
16
+ .message('Illegal plugin ID value "{#value}": it should only contain alphanumerics, underscores, and dashes.')
17
+ .default(utils_1.DEFAULT_PLUGIN_ID);
17
18
  const MarkdownPluginsSchema = Joi_1.default.array()
18
- .items(Joi_1.default.array().ordered(Joi_1.default.function().required(), Joi_1.default.object().required()), Joi_1.default.function(), Joi_1.default.object())
19
+ .items(Joi_1.default.array().ordered(Joi_1.default.function().required(), Joi_1.default.any().required()), Joi_1.default.function(), Joi_1.default.object())
20
+ .messages({
21
+ 'array.includes': `{#label} does not look like a valid MDX plugin config. A plugin config entry should be one of:
22
+ - A tuple, like \`[require("rehype-katex"), \\{ strict: false \\}]\`, or
23
+ - A simple module, like \`require("remark-math")\``,
24
+ })
19
25
  .default([]);
20
26
  exports.RemarkPluginsSchema = MarkdownPluginsSchema;
21
27
  exports.RehypePluginsSchema = MarkdownPluginsSchema;
22
28
  exports.AdmonitionsSchema = Joi_1.default.object().default({});
23
- exports.URISchema = Joi_1.default.alternatives(Joi_1.default.string().uri({ allowRelative: true }), Joi_1.default.custom((val, helpers) => {
29
+ // TODO how can we make this emit a custom error message :'(
30
+ // Joi is such a pain, good luck to annoying trying to improve this
31
+ exports.URISchema = Joi_1.default.alternatives(Joi_1.default.string().uri({ allowRelative: true }),
32
+ // This custom validation logic is required notably because Joi does not
33
+ // accept paths like /a/b/c ...
34
+ Joi_1.default.custom((val, helpers) => {
24
35
  try {
25
- const url = new URL(val);
26
- if (url) {
27
- return val;
28
- }
29
- else {
30
- return helpers.error('any.invalid');
31
- }
36
+ // eslint-disable-next-line no-new
37
+ new URL(val);
38
+ return val;
32
39
  }
33
40
  catch {
34
41
  return helpers.error('any.invalid');
35
42
  }
36
- }));
43
+ })).messages({
44
+ 'alternatives.match': "{{#label}} does not look like a valid url (value='{{.value}}')",
45
+ });
37
46
  exports.PathnameSchema = Joi_1.default.string()
38
47
  .custom((val) => {
39
- if (!utils_1.isValidPathname(val)) {
48
+ if (!(0, utils_1.isValidPathname)(val)) {
40
49
  throw new Error();
41
50
  }
42
- else {
43
- return val;
44
- }
51
+ return val;
45
52
  })
46
- .message('{{#label}} is not a valid pathname. Pathname should start with / and not contain any domain or query string');
53
+ .message('{{#label}} is not a valid pathname. Pathname should start with slash and not contain any domain or query string.');
54
+ const FrontMatterTagSchema = JoiFrontMatter_1.JoiFrontMatter.alternatives()
55
+ .try(JoiFrontMatter_1.JoiFrontMatter.string().required(), JoiFrontMatter_1.JoiFrontMatter.object({
56
+ label: JoiFrontMatter_1.JoiFrontMatter.string().required(),
57
+ permalink: JoiFrontMatter_1.JoiFrontMatter.string().required(),
58
+ }).required())
59
+ .messages({
60
+ 'alternatives.match': '{{#label}} does not look like a valid tag',
61
+ 'alternatives.types': '{{#label}} does not look like a valid tag',
62
+ });
63
+ exports.FrontMatterTagsSchema = JoiFrontMatter_1.JoiFrontMatter.array()
64
+ .items(FrontMatterTagSchema)
65
+ .messages({
66
+ 'array.base': '{{#label}} does not look like a valid FrontMatter Yaml array.',
67
+ });
68
+ exports.FrontMatterTOCHeadingLevels = {
69
+ toc_min_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().when('toc_max_heading_level', {
70
+ is: JoiFrontMatter_1.JoiFrontMatter.exist(),
71
+ then: JoiFrontMatter_1.JoiFrontMatter.number()
72
+ .min(2)
73
+ .max(JoiFrontMatter_1.JoiFrontMatter.ref('toc_max_heading_level')),
74
+ otherwise: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
75
+ }),
76
+ toc_max_heading_level: JoiFrontMatter_1.JoiFrontMatter.number().min(2).max(6),
77
+ };
78
+ //# sourceMappingURL=validationSchemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationSchemas.js","sourceRoot":"","sources":["../src/validationSchemas.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,wDAAw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+BAAc,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;CAC7D,CAAC"}
@@ -4,12 +4,26 @@
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
- import Joi from './Joi';
8
- export declare const isValidationDisabledEscapeHatch: boolean;
9
- export declare const logValidationBugReportHint: () => void;
7
+ import type Joi from './Joi';
8
+ /** Print warnings returned from Joi validation. */
9
+ export declare function printWarning(warning?: Joi.ValidationError): void;
10
+ /**
11
+ * The callback that should be used to validate plugin options. Handles plugin
12
+ * IDs on a generic level: no matter what the schema declares, this callback
13
+ * would require a string ID or default to "default".
14
+ */
10
15
  export declare function normalizePluginOptions<T extends {
11
16
  id?: string;
12
- }>(schema: Joi.ObjectSchema<T>, options: Partial<T>): T;
17
+ }>(schema: Joi.ObjectSchema<T>, options?: Partial<T>): T;
18
+ /**
19
+ * The callback that should be used to validate theme config. No matter what the
20
+ * schema declares, this callback would allow unknown attributes.
21
+ */
13
22
  export declare function normalizeThemeConfig<T>(schema: Joi.ObjectSchema<T>, themeConfig: Partial<T>): T;
14
- export declare const JoiFrontMatter: typeof Joi;
15
- export declare function validateFrontMatter<T>(frontMatter: Record<string, unknown>, schema: Joi.ObjectSchema<T>): T;
23
+ /**
24
+ * Validate front matter with better error message
25
+ */
26
+ export declare function validateFrontMatter<T>(frontMatter: {
27
+ [key: string]: unknown;
28
+ }, schema: Joi.ObjectSchema<T>): T;
29
+ //# sourceMappingURL=validationUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,GAAG,MAAM,OAAO,CAAC;AAK7B,mDAAmD;AACnD,wBAAgB,YAAY,CAAC,OAAO,CAAC,EAAE,GAAG,CAAC,eAAe,GAAG,IAAI,CAOhE;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS;IAAC,EAAE,CAAC,EAAE,MAAM,CAAA;CAAC,EAC5D,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAE3B,OAAO,GAAE,OAAO,CAAC,CAAC,CAAM,GACvB,CAAC,CAiBH;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,GACtB,CAAC,CAgBH;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EACnC,WAAW,EAAE;IAAC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CAAC,EACrC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,GAC1B,CAAC,CAuBH"}
@@ -1,115 +1,90 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateFrontMatter = exports.JoiFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.logValidationBugReportHint = exports.isValidationDisabledEscapeHatch = void 0;
4
- const tslib_1 = require("tslib");
5
2
  /**
6
3
  * Copyright (c) Facebook, Inc. and its affiliates.
7
4
  *
8
5
  * This source code is licensed under the MIT license found in the
9
6
  * LICENSE file in the root directory of this source tree.
10
7
  */
11
- const Joi_1 = tslib_1.__importDefault(require("./Joi"));
12
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = void 0;
10
+ const tslib_1 = require("tslib");
11
+ const logger_1 = tslib_1.__importDefault(require("@docusaurus/logger"));
12
+ const js_yaml_1 = tslib_1.__importDefault(require("js-yaml"));
13
13
  const validationSchemas_1 = require("./validationSchemas");
14
- // TODO temporary escape hatch for alpha-60: to be removed soon
15
- // Our validation schemas might be buggy at first
16
- // will permit users to bypass validation until we fix all validation errors
17
- // see for example: https://github.com/facebook/docusaurus/pull/3120
18
- // Undocumented on purpose, as we don't want users to keep using it over time
19
- // Maybe we'll make this escape hatch official some day, with a better api?
20
- exports.isValidationDisabledEscapeHatch = process.env.DISABLE_DOCUSAURUS_VALIDATION === 'true';
21
- if (exports.isValidationDisabledEscapeHatch) {
22
- console.error(chalk_1.default.red('You should avoid using DISABLE_DOCUSAURUS_VALIDATION escape hatch, this will be removed'));
14
+ /** Print warnings returned from Joi validation. */
15
+ function printWarning(warning) {
16
+ if (warning) {
17
+ const warningMessages = warning.details
18
+ .map(({ message }) => message)
19
+ .join('\n');
20
+ logger_1.default.warn(warningMessages);
21
+ }
23
22
  }
24
- const logValidationBugReportHint = () => {
25
- console.log(`\n${chalk_1.default.red('A validation error occured.')}${chalk_1.default.cyanBright('\nThe validation system was added recently to Docusaurus as an attempt to avoid user configuration errors.' +
26
- '\nWe may have made some mistakes.' +
27
- '\nIf you think your configuration is valid and should keep working, please open a bug report.')}\n`);
28
- };
29
- exports.logValidationBugReportHint = logValidationBugReportHint;
30
- function normalizePluginOptions(schema, options) {
23
+ exports.printWarning = printWarning;
24
+ /**
25
+ * The callback that should be used to validate plugin options. Handles plugin
26
+ * IDs on a generic level: no matter what the schema declares, this callback
27
+ * would require a string ID or default to "default".
28
+ */
29
+ function normalizePluginOptions(schema,
30
+ // This allows us to automatically normalize undefined to { id: "default" }
31
+ options = {}) {
31
32
  // All plugins can be provided an "id" option (multi-instance support)
32
33
  // we add schema validation automatically
33
34
  const finalSchema = schema.append({
34
35
  id: validationSchemas_1.PluginIdSchema,
35
36
  });
36
- const { error, value } = finalSchema.validate(options, {
37
+ const { error, warning, value } = finalSchema.validate(options, {
37
38
  convert: false,
38
39
  });
40
+ printWarning(warning);
39
41
  if (error) {
40
- exports.logValidationBugReportHint();
41
- if (exports.isValidationDisabledEscapeHatch) {
42
- console.error(error);
43
- return options;
44
- }
45
- else {
46
- throw error;
47
- }
42
+ throw error;
48
43
  }
49
44
  return value;
50
45
  }
51
46
  exports.normalizePluginOptions = normalizePluginOptions;
47
+ /**
48
+ * The callback that should be used to validate theme config. No matter what the
49
+ * schema declares, this callback would allow unknown attributes.
50
+ */
52
51
  function normalizeThemeConfig(schema, themeConfig) {
53
- // A theme should only validate his "slice" of the full themeConfig,
52
+ // A theme should only validate its "slice" of the full themeConfig,
54
53
  // not the whole object, so we allow unknown attributes
55
54
  // otherwise one theme would fail validating the data of another theme
56
55
  const finalSchema = schema.unknown();
57
- const { error, value } = finalSchema.validate(themeConfig, {
56
+ const { error, warning, value } = finalSchema.validate(themeConfig, {
58
57
  convert: false,
59
58
  });
59
+ printWarning(warning);
60
60
  if (error) {
61
- exports.logValidationBugReportHint();
62
- if (exports.isValidationDisabledEscapeHatch) {
63
- console.error(error);
64
- return themeConfig;
65
- }
66
- else {
67
- throw error;
68
- }
61
+ throw error;
69
62
  }
70
63
  return value;
71
64
  }
72
65
  exports.normalizeThemeConfig = normalizeThemeConfig;
73
- // Enhance the default Joi.string() type so that it can convert number to strings
74
- // If user use frontmatter "tag: 2021", we shouldn't need to ask the user to write "tag: '2021'"
75
- // Also yaml tries to convert patterns like "2019-01-01" to dates automatically
76
- // see https://github.com/facebook/docusaurus/issues/4642
77
- // see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
78
- const JoiFrontMatterString = {
79
- type: 'string',
80
- base: Joi_1.default.string(),
81
- // Fix Yaml that tries to auto-convert many things to string out of the box
82
- prepare: (value) => {
83
- if (typeof value === 'number' || value instanceof Date) {
84
- return { value: value.toString() };
85
- }
86
- return { value };
87
- },
88
- };
89
- exports.JoiFrontMatter = Joi_1.default.extend(JoiFrontMatterString);
66
+ /**
67
+ * Validate front matter with better error message
68
+ */
90
69
  function validateFrontMatter(frontMatter, schema) {
91
70
  const { value, error, warning } = schema.validate(frontMatter, {
92
71
  convert: true,
93
72
  allowUnknown: true,
94
73
  abortEarly: false,
95
74
  });
75
+ printWarning(warning);
96
76
  if (error) {
97
- const frontMatterString = JSON.stringify(frontMatter, null, 2);
98
77
  const errorDetails = error.details;
99
78
  const invalidFields = errorDetails.map(({ path }) => path).join(', ');
100
- const errorMessages = errorDetails
101
- .map(({ message }) => ` - ${message}`)
102
- .join('\n');
103
- exports.logValidationBugReportHint();
104
- console.error(chalk_1.default.red(`The following FrontMatter:\n${chalk_1.default.yellow(frontMatterString)}\ncontains invalid values for field(s): ${invalidFields}.\n${errorMessages}\n`));
79
+ logger_1.default.error `The following front matter:
80
+ ---
81
+ ${js_yaml_1.default.dump(frontMatter)}---
82
+ contains invalid values for field(s): code=${invalidFields}.
83
+ ${errorDetails.map(({ message }) => message)}
84
+ `;
105
85
  throw error;
106
86
  }
107
- if (warning) {
108
- const warningMessages = warning.details
109
- .map(({ message }) => message)
110
- .join('\n');
111
- console.log(chalk_1.default.yellow(warningMessages));
112
- }
113
87
  return value;
114
88
  }
115
89
  exports.validateFrontMatter = validateFrontMatter;
90
+ //# sourceMappingURL=validationUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH,wEAAwC;AACxC,8DAA2B;AAC3B,2DAAmD;AAEnD,mDAAmD;AACnD,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;;;;GAIG;AACH,SAAgB,sBAAsB,CACpC,MAA2B;AAC3B,2EAA2E;AAC3E,UAAsB,EAAE;IAExB,sEAAsE;IACtE,yCAAyC;IACzC,MAAM,WAA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C,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpE,gBAAM,CAAC,KAAK,CAAA;;EAEd,iBAAI,CAAC,IAAI,CAAC,WAAW,CAAC;6CACqB,aAAa;EACxD,YAAY,CAAC,GAAG,CAAC,CAAC,EAAC,OAAO,EAAC,EAAE,EAAE,CAAC,OAAO,CAAC;CACzC,CAAC;QACE,MAAM,KAAK,CAAC;KACb;IAED,OAAO,KAAK,CAAC;AACf,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.15d451942",
3
+ "version": "2.0.0-beta.18",
4
4
  "description": "Node validation utility functions for Docusaurus packages.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,13 +18,14 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/utils": "2.0.0-beta.15d451942",
22
- "chalk": "^4.1.1",
23
- "joi": "^17.4.0",
24
- "tslib": "^2.1.0"
21
+ "@docusaurus/logger": "2.0.0-beta.18",
22
+ "@docusaurus/utils": "2.0.0-beta.18",
23
+ "joi": "^17.6.0",
24
+ "js-yaml": "^4.1.0",
25
+ "tslib": "^2.3.1"
25
26
  },
26
27
  "engines": {
27
- "node": ">=12.13.0"
28
+ "node": ">=14"
28
29
  },
29
- "gitHead": "dfceae8bd3e8b42ba8fc14f1449d861046c26143"
30
+ "gitHead": "1a945d06993d53376e61bed2c942799fe07dc336"
30
31
  }
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import Joi from './Joi';
9
+
10
+ const JoiFrontMatterString: Joi.Extension = {
11
+ type: 'string',
12
+ base: Joi.string(),
13
+ // Fix Yaml that tries to auto-convert many things to string out of the box
14
+ prepare: (value) => {
15
+ if (typeof value === 'number' || value instanceof Date) {
16
+ return {value: value.toString()};
17
+ }
18
+ return {value};
19
+ },
20
+ };
21
+
22
+ /**
23
+ * Enhance the default `Joi.string()` type so that it can convert number to
24
+ * strings. If user use front matter "tag: 2021", we shouldn't need to ask her
25
+ * to write "tag: '2021'". Also yaml tries to convert patterns like "2019-01-01"
26
+ * to dates automatically.
27
+ *
28
+ * @see https://github.com/facebook/docusaurus/issues/4642
29
+ * @see https://github.com/sideway/joi/issues/1442#issuecomment-823997884
30
+ */
31
+ export const JoiFrontMatter: typeof Joi = Joi.extend(JoiFrontMatterString);
package/src/index.ts CHANGED
@@ -7,6 +7,21 @@
7
7
 
8
8
  // /!\ don't remove this export, as we recommend plugin authors to use it
9
9
  export {default as Joi} from './Joi';
10
+ export {JoiFrontMatter} from './JoiFrontMatter';
10
11
 
11
- export * from './validationUtils';
12
- export * from './validationSchemas';
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';