UNPKG

@mnrendra/obtain-tsconfig-paths

Version:

Obtain a valid baseUrl and paths from the compilerOptions in the tsconfig.json file

3 lines (2 loc) 1.02 kB
"use strict";var i=require("@mnrendra/read-tsconfig");const s={NO_COMPILEROPTIONS:"Invalid `compilerOptions`: the value must be an object!",NO_BASEURL:"Invalid `compilerOptions.baseUrl`: the value must be a string!",NO_PATHS:"Invalid `compilerOptions.paths`: the value must be an object!"},o=t=>{const r={baseUrl:"./",paths:{}};if(t==null)return r;if(typeof t!="object"||Array.isArray(t))throw new Error(s.NO_COMPILEROPTIONS);const{baseUrl:e,paths:n}=t;if(e!=null&&typeof e!="string")throw new Error(s.NO_BASEURL);if(n!=null&&typeof n!="object"||Array.isArray(n))throw new Error(s.NO_PATHS);return r.baseUrl=e??"./",r.paths=n??{},r},a=async(t={})=>{const{baseUrl:r,paths:e}=t??{};if(r===void 0&&e===void 0){const{compilerOptions:n}=await i.readTSConfig();return o(n)}return o(t)},c=(t={})=>{const{baseUrl:r,paths:e}=t??{};if(r===void 0&&e===void 0){const{compilerOptions:n}=i.readTSConfigSync();return o(n)}return o(t)};exports.obtainTSConfigPaths=a,exports.obtainTSConfigPathsSync=c; //# sourceMappingURL=index.js.map