-
-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathutils.ts
More file actions
43 lines (39 loc) · 1.29 KB
/
utils.ts
File metadata and controls
43 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
const memoize = require(
normalizeWebpackPath('webpack/lib/util/memoize'),
) as typeof import('webpack/lib/util/memoize');
const getValidate = memoize(() => require('schema-utils').validate);
/**
* @template {object | object[]} T
* @param {(function(T): boolean) | undefined} check check
* @param {() => JsonObject} getSchema get schema fn
* @param {ValidationErrorConfiguration} options options
* @returns {function(T=): void} validate
*/
const createSchemaValidation = (
check: ((value: any) => boolean) | undefined,
getSchema: () => any,
options: any,
) => {
getSchema = memoize(getSchema);
//@ts-ignore
return (value) => {
if (check && !check(/** @type {T} */ value)) {
getValidate()(
getSchema(),
/** @type {object | object[]} */
value,
options,
);
require('util').deprecate(
/* istanbul ignore next - deprecation warning */
function noop() {
/* intentionally empty for deprecation */
},
'webpack bug: Pre-compiled schema reports error while real schema is happy. This has performance drawbacks.',
'DEP_WEBPACK_PRE_COMPILED_SCHEMA_INVALID',
)();
}
};
};
export { createSchemaValidation };