diff --git a/package.json b/package.json index e1efe411..32ba3488 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,8 @@ "find-cache-dir": "^2.0.0", "loader-utils": "^1.0.2", "mkdirp": "^0.5.1", - "pify": "^4.0.1" + "pify": "^4.0.1", + "schema-utils": "^2.6.4" }, "peerDependencies": { "@babel/core": "^7.0.0", @@ -45,7 +46,7 @@ }, "scripts": { "clean": "rimraf lib/", - "build": "babel src/ --out-dir lib/", + "build": "babel src/ --out-dir lib/ --copy-files", "format": "prettier --write --trailing-comma all 'src/**/*.js' 'test/**/*.test.js' 'test/helpers/*.js' && prettier --write --trailing-comma es5 'scripts/*.js'", "lint": "eslint src test", "precommit": "lint-staged", diff --git a/src/index.js b/src/index.js index fd0c2cca..2209bc65 100644 --- a/src/index.js +++ b/src/index.js @@ -23,9 +23,11 @@ const { version } = require("../package.json"); const cache = require("./cache"); const transform = require("./transform"); const injectCaller = require("./injectCaller"); +const schema = require("./schema"); const { isAbsolute } = require("path"); const loaderUtils = require("loader-utils"); +const validateOptions = require("schema-utils"); function subscribe(subscriber, metadata, context) { if (context[subscriber]) { @@ -54,6 +56,10 @@ async function loader(source, inputSourceMap, overrides) { let loaderOptions = loaderUtils.getOptions(this) || {}; + validateOptions(schema, loaderOptions, { + name: "Babel loader", + }); + if (loaderOptions.customize != null) { if (typeof loaderOptions.customize !== "string") { throw new Error( diff --git a/src/schema.json b/src/schema.json new file mode 100644 index 00000000..9c52785a --- /dev/null +++ b/src/schema.json @@ -0,0 +1,28 @@ +{ + "type": "object", + "properties": { + "cacheDirectory": { + "oneOf": [ + { + "type": "boolean" + }, + { + "type": "string" + } + ], + "default": false + }, + "cacheIdentifier": { + "type": "string" + }, + "cacheCompression": { + "type": "boolean", + "default": true + }, + "customize": { + "type": "string", + "default": null + } + }, + "additionalProperties": true +} diff --git a/yarn.lock b/yarn.lock index 99801e93..db992f8b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5713,6 +5713,14 @@ schema-utils@^1.0.0: ajv-errors "^1.0.0" ajv-keywords "^3.1.0" +schema-utils@^2.6.4: + version "2.6.4" + resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.6.4.tgz#a27efbf6e4e78689d91872ee3ccfa57d7bdd0f53" + integrity sha512-VNjcaUxVnEeun6B2fiiUDjXXBtD4ZSH7pdbfIu1pOFwgptDPLMo/z9jr4sUfsjFVPqDCEin/F7IYlq7/E6yDbQ== + dependencies: + ajv "^6.10.2" + ajv-keywords "^3.4.1" + semver-compare@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/semver-compare/-/semver-compare-1.0.0.tgz#0dee216a1c941ab37e9efb1788f6afc5ff5537fc"