| | |
| | | "use strict"; |
| | | |
| | | const { JSON_MODULE_TYPE } = require("../ModuleTypeConstants"); |
| | | const createSchemaValidation = require("../util/create-schema-validation"); |
| | | const JsonGenerator = require("./JsonGenerator"); |
| | | const JsonParser = require("./JsonParser"); |
| | | |
| | | /** @typedef {import("../Compiler")} Compiler */ |
| | | |
| | | const validate = createSchemaValidation( |
| | | require("../../schemas/plugins/json/JsonModulesPluginParser.check"), |
| | | () => require("../../schemas/plugins/json/JsonModulesPluginParser.json"), |
| | | { |
| | | name: "Json Modules Plugin", |
| | | baseDataPath: "parser" |
| | | } |
| | | ); |
| | | |
| | | const validateGenerator = createSchemaValidation( |
| | | require("../../schemas/plugins/json/JsonModulesPluginGenerator.check"), |
| | | () => require("../../schemas/plugins/json/JsonModulesPluginGenerator.json"), |
| | | { |
| | | name: "Json Modules Plugin", |
| | | baseDataPath: "generator" |
| | | } |
| | | ); |
| | | |
| | | const PLUGIN_NAME = "JsonModulesPlugin"; |
| | | |
| | |
| | | */ |
| | | class JsonModulesPlugin { |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | |
| | | normalModuleFactory.hooks.createParser |
| | | .for(JSON_MODULE_TYPE) |
| | | .tap(PLUGIN_NAME, (parserOptions) => { |
| | | validate(parserOptions); |
| | | compiler.validate( |
| | | () => |
| | | require("../../schemas/plugins/json/JsonModulesPluginParser.json"), |
| | | parserOptions, |
| | | { |
| | | name: "Json Modules Plugin", |
| | | baseDataPath: "parser" |
| | | }, |
| | | (options) => |
| | | require("../../schemas/plugins/json/JsonModulesPluginParser.check")( |
| | | options |
| | | ) |
| | | ); |
| | | |
| | | return new JsonParser(parserOptions); |
| | | }); |
| | | normalModuleFactory.hooks.createGenerator |
| | | .for(JSON_MODULE_TYPE) |
| | | .tap(PLUGIN_NAME, (generatorOptions) => { |
| | | validateGenerator(generatorOptions); |
| | | compiler.validate( |
| | | () => |
| | | require("../../schemas/plugins/json/JsonModulesPluginGenerator.json"), |
| | | generatorOptions, |
| | | { |
| | | name: "Json Modules Plugin", |
| | | baseDataPath: "generator" |
| | | }, |
| | | (options) => |
| | | require("../../schemas/plugins/json/JsonModulesPluginGenerator.check")( |
| | | options |
| | | ) |
| | | ); |
| | | |
| | | return new JsonGenerator(generatorOptions); |
| | | }); |
| | | } |