UNPKG

schema-util-loader

Version:
26 lines (25 loc) 878 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var schema_util_1 = require("schema-util"); var formatError_1 = require("./formatError"); function default_1(source) { var _a = this, resourcePath = _a.resourcePath, callback = _a.callback; var isSync = typeof callback !== 'function'; if (isSync) { throw new Error('Synchronous compilation is not supported anymore.'); } // const options = getOptions(this); try { var schemaStr = JSON.stringify(schema_util_1.schema(source)) .replace(/\u2028/g, '\\u2028') .replace(/\u2029/g, '\\u2029'); ; return "module.exports = " + schemaStr; } catch (e) { e.message = "parse schema error " + e.message; var err = formatError_1.default(e, resourcePath); throw err; } } exports.default = default_1;