UNPKG

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