UNPKG

1.67 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const validOptions = [
4 "configFile",
5 "extensions",
6 "baseUrl",
7 "silent",
8 "logLevel",
9 "logInfoToStdOut",
10 "context"
11];
12/**
13 * Takes raw options from the webpack config,
14 * validates them and adds defaults for missing options
15 */
16function getOptions(rawOptions) {
17 validateOptions(rawOptions);
18 const options = makeOptions(rawOptions);
19 return options;
20}
21exports.getOptions = getOptions;
22/**
23 * Validate the supplied loader options.
24 * At present this validates the option names only; in future we may look at validating the values too
25 * @param rawOptions
26 */
27function validateOptions(rawOptions) {
28 const loaderOptionKeys = Object.keys(rawOptions);
29 for (let i = 0; i < loaderOptionKeys.length; i++) {
30 const option = loaderOptionKeys[i];
31 const isUnexpectedOption = validOptions.indexOf(option) === -1;
32 if (isUnexpectedOption) {
33 throw new Error(`tsconfig-paths-webpack-plugin was supplied with an unexpected loader option: ${option}
34Please take a look at the options you are supplying; the following are valid options:
35${validOptions.join(" / ")}
36`);
37 }
38 }
39}
40function makeOptions(rawOptions) {
41 const options = Object.assign({}, {
42 configFile: "tsconfig.json",
43 extensions: [".ts", ".tsx"],
44 baseUrl: undefined,
45 silent: false,
46 logLevel: "WARN",
47 logInfoToStdOut: false,
48 context: undefined,
49 colors: true
50 }, rawOptions);
51 const options2 = Object.assign({}, options, { logLevel: options.logLevel.toUpperCase() });
52 return options2;
53}