@docusaurus/utils-validation 0.0.0-4291 → 0.0.0-4304
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/validationUtils.d.ts.map +1 -1
- package/lib/validationUtils.js +14 -12
- package/lib/validationUtils.js.map +1 -1
- package/package.json +4 -4
- package/src/validationUtils.ts +14 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAUxB,eAAO,MAAM,+BAA+B,SACU,CAAC;
|
|
1
|
+
{"version":3,"file":"validationUtils.d.ts","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,GAAG,MAAM,OAAO,CAAC;AAUxB,eAAO,MAAM,+BAA+B,SACU,CAAC;AAMvD,eAAO,MAAM,0BAA0B,QAAO,IAK7C,CAAC;AAEF,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,CAuBH;AAED,wBAAgB,oBAAoB,CAAC,CAAC,EACpC,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC,CAAC,CAAC,EAC3B,WAAW,EAAE,OAAO,CAAC,CAAC,CAAC,GACtB,CAAC,CAsBH;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,CAyBH"}
|
package/lib/validationUtils.js
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.validateFrontMatter = exports.normalizeThemeConfig = exports.normalizePluginOptions = exports.printWarning = exports.logValidationBugReportHint = exports.isValidationDisabledEscapeHatch = void 0;
|
|
10
10
|
const tslib_1 = require("tslib");
|
|
11
|
-
const
|
|
11
|
+
const logger_1 = (0, tslib_1.__importDefault)(require("@docusaurus/logger"));
|
|
12
12
|
const validationSchemas_1 = require("./validationSchemas");
|
|
13
13
|
// TODO temporary escape hatch for alpha-60: to be removed soon
|
|
14
14
|
// Our validation schemas might be buggy at first
|
|
@@ -18,12 +18,13 @@ const validationSchemas_1 = require("./validationSchemas");
|
|
|
18
18
|
// Maybe we'll make this escape hatch official some day, with a better api?
|
|
19
19
|
exports.isValidationDisabledEscapeHatch = process.env.DISABLE_DOCUSAURUS_VALIDATION === 'true';
|
|
20
20
|
if (exports.isValidationDisabledEscapeHatch) {
|
|
21
|
-
|
|
21
|
+
logger_1.default.error `You should avoid using code=${'DISABLE_DOCUSAURUS_VALIDATION'} escape hatch, this will be removed.`;
|
|
22
22
|
}
|
|
23
23
|
const logValidationBugReportHint = () => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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.`);
|
|
27
28
|
};
|
|
28
29
|
exports.logValidationBugReportHint = logValidationBugReportHint;
|
|
29
30
|
function printWarning(warning) {
|
|
@@ -31,7 +32,7 @@ function printWarning(warning) {
|
|
|
31
32
|
const warningMessages = warning.details
|
|
32
33
|
.map(({ message }) => message)
|
|
33
34
|
.join('\n');
|
|
34
|
-
|
|
35
|
+
logger_1.default.warn(warningMessages);
|
|
35
36
|
}
|
|
36
37
|
}
|
|
37
38
|
exports.printWarning = printWarning;
|
|
@@ -48,7 +49,7 @@ function normalizePluginOptions(schema, options) {
|
|
|
48
49
|
if (error) {
|
|
49
50
|
(0, exports.logValidationBugReportHint)();
|
|
50
51
|
if (exports.isValidationDisabledEscapeHatch) {
|
|
51
|
-
|
|
52
|
+
logger_1.default.error(error);
|
|
52
53
|
return options;
|
|
53
54
|
}
|
|
54
55
|
else {
|
|
@@ -70,7 +71,7 @@ function normalizeThemeConfig(schema, themeConfig) {
|
|
|
70
71
|
if (error) {
|
|
71
72
|
(0, exports.logValidationBugReportHint)();
|
|
72
73
|
if (exports.isValidationDisabledEscapeHatch) {
|
|
73
|
-
|
|
74
|
+
logger_1.default.error(error);
|
|
74
75
|
return themeConfig;
|
|
75
76
|
}
|
|
76
77
|
else {
|
|
@@ -91,11 +92,12 @@ function validateFrontMatter(frontMatter, schema) {
|
|
|
91
92
|
const frontMatterString = JSON.stringify(frontMatter, null, 2);
|
|
92
93
|
const errorDetails = error.details;
|
|
93
94
|
const invalidFields = errorDetails.map(({ path }) => path).join(', ');
|
|
94
|
-
const errorMessages = errorDetails
|
|
95
|
-
.map(({ message }) => ` - ${message}`)
|
|
96
|
-
.join('\n');
|
|
97
95
|
(0, exports.logValidationBugReportHint)();
|
|
98
|
-
|
|
96
|
+
logger_1.default.error `The following frontmatter:
|
|
97
|
+
${logger_1.default.yellow(frontMatterString)}
|
|
98
|
+
contains invalid values for field(s): ${logger_1.default.yellow(invalidFields)}.
|
|
99
|
+
${errorDetails.map(({ message }) => message)}
|
|
100
|
+
`;
|
|
99
101
|
throw error;
|
|
100
102
|
}
|
|
101
103
|
return value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAGH
|
|
1
|
+
{"version":3,"file":"validationUtils.js","sourceRoot":"","sources":["../src/validationUtils.ts"],"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AC,EAAC,IAAI,EAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEpE,IAAA,kCAA0B,GAAE,CAAC;QAE7B,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,KAAK,CAAC;AACf,CAAC;AA5BD,kDA4BC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/utils-validation",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4304",
|
|
4
4
|
"description": "Node validation utility functions for Docusaurus packages.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
},
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@docusaurus/
|
|
22
|
-
"
|
|
21
|
+
"@docusaurus/logger": "0.0.0-4304",
|
|
22
|
+
"@docusaurus/utils": "0.0.0-4304",
|
|
23
23
|
"joi": "^17.4.2",
|
|
24
24
|
"tslib": "^2.3.1"
|
|
25
25
|
},
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"engines": {
|
|
31
31
|
"node": ">=14"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "741cabdc2fdced32592aa340740e35a5b30de55e"
|
|
34
34
|
}
|
package/src/validationUtils.ts
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import Joi from './Joi';
|
|
9
|
-
import
|
|
9
|
+
import logger from '@docusaurus/logger';
|
|
10
10
|
import {PluginIdSchema} from './validationSchemas';
|
|
11
11
|
|
|
12
12
|
// TODO temporary escape hatch for alpha-60: to be removed soon
|
|
@@ -19,21 +19,14 @@ export const isValidationDisabledEscapeHatch =
|
|
|
19
19
|
process.env.DISABLE_DOCUSAURUS_VALIDATION === 'true';
|
|
20
20
|
|
|
21
21
|
if (isValidationDisabledEscapeHatch) {
|
|
22
|
-
|
|
23
|
-
chalk.red(
|
|
24
|
-
'You should avoid using DISABLE_DOCUSAURUS_VALIDATION escape hatch, this will be removed.',
|
|
25
|
-
),
|
|
26
|
-
);
|
|
22
|
+
logger.error`You should avoid using code=${'DISABLE_DOCUSAURUS_VALIDATION'} escape hatch, this will be removed.`;
|
|
27
23
|
}
|
|
28
24
|
|
|
29
25
|
export const logValidationBugReportHint = (): void => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
'\nIf you think your configuration is valid and should keep working, please open a bug report.',
|
|
35
|
-
)}\n`,
|
|
36
|
-
);
|
|
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.`);
|
|
37
30
|
};
|
|
38
31
|
|
|
39
32
|
export function printWarning(warning?: Joi.ValidationError): void {
|
|
@@ -41,7 +34,7 @@ export function printWarning(warning?: Joi.ValidationError): void {
|
|
|
41
34
|
const warningMessages = warning.details
|
|
42
35
|
.map(({message}) => message)
|
|
43
36
|
.join('\n');
|
|
44
|
-
|
|
37
|
+
logger.warn(warningMessages);
|
|
45
38
|
}
|
|
46
39
|
}
|
|
47
40
|
|
|
@@ -63,7 +56,7 @@ export function normalizePluginOptions<T extends {id?: string}>(
|
|
|
63
56
|
if (error) {
|
|
64
57
|
logValidationBugReportHint();
|
|
65
58
|
if (isValidationDisabledEscapeHatch) {
|
|
66
|
-
|
|
59
|
+
logger.error(error);
|
|
67
60
|
return options as T;
|
|
68
61
|
} else {
|
|
69
62
|
throw error;
|
|
@@ -91,7 +84,7 @@ export function normalizeThemeConfig<T>(
|
|
|
91
84
|
if (error) {
|
|
92
85
|
logValidationBugReportHint();
|
|
93
86
|
if (isValidationDisabledEscapeHatch) {
|
|
94
|
-
|
|
87
|
+
logger.error(error);
|
|
95
88
|
return themeConfig as T;
|
|
96
89
|
} else {
|
|
97
90
|
throw error;
|
|
@@ -116,19 +109,14 @@ export function validateFrontMatter<T>(
|
|
|
116
109
|
const frontMatterString = JSON.stringify(frontMatter, null, 2);
|
|
117
110
|
const errorDetails = error.details;
|
|
118
111
|
const invalidFields = errorDetails.map(({path}) => path).join(', ');
|
|
119
|
-
const errorMessages = errorDetails
|
|
120
|
-
.map(({message}) => ` - ${message}`)
|
|
121
|
-
.join('\n');
|
|
122
112
|
|
|
123
113
|
logValidationBugReportHint();
|
|
124
114
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
),
|
|
131
|
-
);
|
|
115
|
+
logger.error`The following frontmatter:
|
|
116
|
+
${logger.yellow(frontMatterString)}
|
|
117
|
+
contains invalid values for field(s): ${logger.yellow(invalidFields)}.
|
|
118
|
+
${errorDetails.map(({message}) => message)}
|
|
119
|
+
`;
|
|
132
120
|
throw error;
|
|
133
121
|
}
|
|
134
122
|
|