Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

get-tsconfig

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

get-tsconfig - npm Package Compare versions

Comparing version 4.0.7 to 4.1.0

4

dist/index.d.ts

@@ -1262,2 +1262,4 @@ declare global {

declare function parseTsconfig(tsconfigPath: string): TsConfigJsonResolved;
/**

@@ -1269,2 +1271,2 @@ * Reference:

export { TsConfigJson, TsConfigJsonResolved, TsConfigResult, createPathsMatcher, getTsconfig };
export { TsConfigJson, TsConfigJsonResolved, TsConfigResult, createPathsMatcher, getTsconfig, parseTsconfig };

@@ -1,3 +0,3 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var H=require("path"),G=require("fs");function W(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var l=W(H),O=W(G);function L(r){const t=/^\\\\\?\\/.test(r),n=/[^\u0000-\u0080]+/.test(r);return t||n?r:r.replace(/\\/g,"/")}function U(r,t){for(;;){const n=l.default.join(r,t);if(O.default.existsSync(n))return L(n);const e=l.default.dirname(r);if(e===r)return;r=e}}function K(r,t){t===void 0&&(t=!1);var n=r.length,e=0,i="",f=0,a=16,d=0,s=0,v=0,p=0,u=0;function y(o,b){for(var C=0,k=0;C<o||!b;){var h=r.charCodeAt(e);if(h>=48&&h<=57)k=k*16+h-48;else if(h>=65&&h<=70)k=k*16+h-65+10;else if(h>=97&&h<=102)k=k*16+h-97+10;else break;e++,C++}return C<o&&(k=-1),k}function V(o){e=o,i="",f=0,a=16,u=0}function B(){var o=e;if(r.charCodeAt(e)===48)e++;else for(e++;e<r.length&&T(r.charCodeAt(e));)e++;if(e<r.length&&r.charCodeAt(e)===46)if(e++,e<r.length&&T(r.charCodeAt(e)))for(e++;e<r.length&&T(r.charCodeAt(e));)e++;else return u=3,r.substring(o,e);var b=e;if(e<r.length&&(r.charCodeAt(e)===69||r.charCodeAt(e)===101))if(e++,(e<r.length&&r.charCodeAt(e)===43||r.charCodeAt(e)===45)&&e++,e<r.length&&T(r.charCodeAt(e))){for(e++;e<r.length&&T(r.charCodeAt(e));)e++;b=e}else u=3;return r.substring(o,b)}function S(){for(var o="",b=e;;){if(e>=n){o+=r.substring(b,e),u=2;break}var C=r.charCodeAt(e);if(C===34){o+=r.substring(b,e),e++;break}if(C===92){if(o+=r.substring(b,e),e++,e>=n){u=2;break}var k=r.charCodeAt(e++);switch(k){case 34:o+='"';break;case 92:o+="\\";break;case 47:o+="/";break;case 98:o+="\b";break;case 102:o+="\f";break;case 110:o+=`
`;break;case 114:o+="\r";break;case 116:o+=" ";break;case 117:var h=y(4,!0);h>=0?o+=String.fromCharCode(h):u=4;break;default:u=5}b=e;continue}if(C>=0&&C<=31)if(P(C)){o+=r.substring(b,e),u=2;break}else u=6;e++}return o}function A(){if(i="",u=0,f=e,s=d,p=v,e>=n)return f=n,a=17;var o=r.charCodeAt(e);if($(o)){do e++,i+=String.fromCharCode(o),o=r.charCodeAt(e);while($(o));return a=15}if(P(o))return e++,i+=String.fromCharCode(o),o===13&&r.charCodeAt(e)===10&&(e++,i+=`
`),d++,v=e,a=14;switch(o){case 123:return e++,a=1;case 125:return e++,a=2;case 91:return e++,a=3;case 93:return e++,a=4;case 58:return e++,a=6;case 44:return e++,a=5;case 34:return e++,i=S(),a=10;case 47:var b=e-1;if(r.charCodeAt(e+1)===47){for(e+=2;e<n&&!P(r.charCodeAt(e));)e++;return i=r.substring(b,e),a=12}if(r.charCodeAt(e+1)===42){e+=2;for(var C=n-1,k=!1;e<C;){var h=r.charCodeAt(e);if(h===42&&r.charCodeAt(e+1)===47){e+=2,k=!0;break}e++,P(h)&&(h===13&&r.charCodeAt(e)===10&&e++,d++,v=e)}return k||(e++,u=1),i=r.substring(b,e),a=13}return i+=String.fromCharCode(o),e++,a=16;case 45:if(i+=String.fromCharCode(o),e++,e===n||!T(r.charCodeAt(e)))return a=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return i+=B(),a=11;default:for(;e<n&&m(o);)e++,o=r.charCodeAt(e);if(f!==e){switch(i=r.substring(f,e),i){case"true":return a=8;case"false":return a=9;case"null":return a=7}return a=16}return i+=String.fromCharCode(o),e++,a=16}}function m(o){if($(o)||P(o))return!1;switch(o){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function c(){var o;do o=A();while(o>=12&&o<=15);return o}return{setPosition:V,getPosition:function(){return e},scan:t?c:A,getToken:function(){return a},getTokenValue:function(){return i},getTokenOffset:function(){return f},getTokenLength:function(){return e-f},getTokenStartLine:function(){return s},getTokenStartCharacter:function(){return f-p},getTokenError:function(){return u}}}function $(r){return r===32||r===9||r===11||r===12||r===160||r===5760||r>=8192&&r<=8203||r===8239||r===8287||r===12288||r===65279}function P(r){return r===10||r===13||r===8232||r===8233}function T(r){return r>=48&&r<=57}var N;(function(r){r.DEFAULT={allowTrailingComma:!1}})(N||(N={}));function Q(r,t,n){t===void 0&&(t=[]),n===void 0&&(n=N.DEFAULT);var e=null,i=[],f=[];function a(s){Array.isArray(i)?i.push(s):e!==null&&(i[e]=s)}var d={onObjectBegin:function(){var s={};a(s),f.push(i),i=s,e=null},onObjectProperty:function(s){e=s},onObjectEnd:function(){i=f.pop()},onArrayBegin:function(){var s=[];a(s),f.push(i),i=s,e=null},onArrayEnd:function(){i=f.pop()},onLiteralValue:a,onError:function(s,v,p){t.push({error:s,offset:v,length:p})}};return X(r,d,n),i[0]}function X(r,t,n){n===void 0&&(n=N.DEFAULT);var e=K(r,!1);function i(g){return g?function(){return g(e.getTokenOffset(),e.getTokenLength(),e.getTokenStartLine(),e.getTokenStartCharacter())}:function(){return!0}}function f(g){return g?function(w){return g(w,e.getTokenOffset(),e.getTokenLength(),e.getTokenStartLine(),e.getTokenStartCharacter())}:function(){return!0}}var a=i(t.onObjectBegin),d=f(t.onObjectProperty),s=i(t.onObjectEnd),v=i(t.onArrayBegin),p=i(t.onArrayEnd),u=f(t.onLiteralValue),y=f(t.onSeparator),V=i(t.onComment),B=f(t.onError),S=n&&n.disallowComments,A=n&&n.allowTrailingComma;function m(){for(;;){var g=e.scan();switch(e.getTokenError()){case 4:c(14);break;case 5:c(15);break;case 3:c(13);break;case 1:S||c(11);break;case 2:c(12);break;case 6:c(16);break}switch(g){case 12:case 13:S?c(10):V();break;case 16:c(1);break;case 15:case 14:break;default:return g}}}function c(g,w,E){if(w===void 0&&(w=[]),E===void 0&&(E=[]),B(g),w.length+E.length>0)for(var _=e.getToken();_!==17;){if(w.indexOf(_)!==-1){m();break}else if(E.indexOf(_)!==-1)break;_=m()}}function o(g){var w=e.getTokenValue();return g?u(w):d(w),m(),!0}function b(){switch(e.getToken()){case 11:var g=e.getTokenValue(),w=Number(g);isNaN(w)&&(c(2),w=0),u(w);break;case 7:u(null);break;case 8:u(!0);break;case 9:u(!1);break;default:return!1}return m(),!0}function C(){return e.getToken()!==10?(c(3,[],[2,5]),!1):(o(!1),e.getToken()===6?(y(":"),m(),F()||c(4,[],[2,5])):c(5,[],[2,5]),!0)}function k(){a(),m();for(var g=!1;e.getToken()!==2&&e.getToken()!==17;){if(e.getToken()===5){if(g||c(4,[],[]),y(","),m(),e.getToken()===2&&A)break}else g&&c(6,[],[]);C()||c(4,[],[2,5]),g=!0}return s(),e.getToken()!==2?c(7,[2],[]):m(),!0}function h(){v(),m();for(var g=!1;e.getToken()!==4&&e.getToken()!==17;){if(e.getToken()===5){if(g||c(4,[],[]),y(","),m(),e.getToken()===4&&A)break}else g&&c(6,[],[]);F()||c(4,[],[4,5]),g=!0}return p(),e.getToken()!==4?c(8,[4],[]):m(),!0}function F(){switch(e.getToken()){case 3:return h();case 1:return k();case 10:return o(!0);default:return b()}}return m(),e.getToken()===17?n.allowEmptyContent?!0:(c(4,[],[]),!1):F()?(e.getToken()!==17&&c(9,[],[]),!0):(c(4,[],[]),!1)}var Y=Q;const M=r=>L(/^[./]/.test(r)?r:`./${r}`),D=r=>O.default.existsSync(r),Z=r=>{try{return JSON.parse(r)}catch{}};function x(r,t){let n=r;if(n===".."&&(n+="/tsconfig.json"),n.startsWith(".")){let e=l.default.resolve(t,n);if(D(e)&&O.default.statSync(e).isFile()||!e.endsWith(".json")&&(e+=".json",D(e)))return e}else{let e=U(t,l.default.join("node_modules",n));if(e){if(O.default.statSync(e).isDirectory()){const i=l.default.join(e,"package.json");if(D(i)){const f=Z(O.default.readFileSync(i,"utf8"));f&&"tsconfig"in f?e=l.default.join(e,f.tsconfig):e=l.default.join(e,"tsconfig.json")}else e=l.default.join(e,"tsconfig.json");if(D(e))return e}else if(e.endsWith(".json"))return e}if(!n.endsWith(".json")&&(n+=".json",e=U(t,l.default.join("node_modules",n)),e))return e}throw new Error(`File '${r}' not found.`)}var ee=Object.defineProperty,re=Object.defineProperties,ne=Object.getOwnPropertyDescriptors,J=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,ae=Object.prototype.propertyIsEnumerable,q=(r,t,n)=>t in r?ee(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n,j=(r,t)=>{for(var n in t||(t={}))te.call(t,n)&&q(r,n,t[n]);if(J)for(var n of J(t))ae.call(t,n)&&q(r,n,t[n]);return r},oe=(r,t)=>re(r,ne(t));function I(r){var t,n;const e=O.default.realpathSync(r),i=l.default.dirname(e),f=O.default.readFileSync(r,"utf8").trim();let a={};if(f&&(a=Y(f),!a||typeof a!="object"))throw new SyntaxError(`Failed to parse JSON: ${r}`);if(a.extends){const d=x(a.extends,i),s=I(d);if(delete s.references,(t=s.compilerOptions)!=null&&t.baseUrl){const{compilerOptions:p}=s;p.baseUrl=l.default.relative(i,l.default.join(l.default.dirname(d),p.baseUrl))||"./"}s.files&&(s.files=s.files.map(p=>l.default.relative(i,l.default.join(l.default.dirname(d),p)))),s.include&&(s.include=s.include.map(p=>l.default.relative(i,l.default.join(l.default.dirname(d),p)))),delete a.extends;const v=oe(j(j({},s),a),{compilerOptions:j(j({},s.compilerOptions),a.compilerOptions)});s.watchOptions&&(v.watchOptions=j(j({},s.watchOptions),a.watchOptions)),a=v}if((n=a.compilerOptions)!=null&&n.baseUrl){const{compilerOptions:d}=a;d.baseUrl=M(d.baseUrl)}if(a.files&&(a.files=a.files.map(M)),a.include&&(a.include=a.include.map(L)),a.watchOptions){const{watchOptions:d}=a;d.excludeDirectories&&(d.excludeDirectories=d.excludeDirectories.map(s=>L(l.default.resolve(i,s))))}return a}function ie(r=process.cwd(),t="tsconfig.json"){const n=U(r,t);if(!n)return null;const e=I(n);return{path:n,config:e}}const R=/^\.{1,2}(\/.*)?$/,se=/\*/g,z=(r,t)=>{const n=r.match(se);if(n&&n.length>1)throw new Error(t)};function fe(r){if(r.includes("*")){const[t,n]=r.split("*");return{prefix:t,suffix:n}}return r}const ue=({prefix:r,suffix:t},n)=>n.startsWith(r)&&n.endsWith(t);function ce(r,t,n){return Object.entries(r).map(([e,i])=>(z(e,`Pattern '${e}' can have at most one '*' character.`),{pattern:fe(e),substitutions:i.map(f=>{if(z(f,`Substitution '${f}' in pattern '${e}' can have at most one '*' character.`),!t&&!R.test(f))throw new Error("Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?");return l.default.join(n,f)})}))}function le(r){if(!r.config.compilerOptions)return null;const{baseUrl:t,paths:n}=r.config.compilerOptions;if(!t&&!n)return null;const e=l.default.resolve(l.default.dirname(r.path),t||"."),i=n?ce(n,t,e):[];return function(a){if(R.test(a))return[];const d=[];for(const u of i){if(u.pattern===a)return u.substitutions;typeof u.pattern!="string"&&d.push(u)}let s,v=-1;for(const u of d)ue(u.pattern,a)&&u.pattern.prefix.length>v&&(v=u.pattern.prefix.length,s=u);if(!s)return t?[l.default.join(e,a)]:[];const p=a.slice(s.pattern.prefix.length,a.length-s.pattern.suffix.length);return s.substitutions.map(u=>u.replace("*",p))}}exports.createPathsMatcher=le,exports.getTsconfig=ie;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var R=require("path"),G=require("fs");function q(r){return r&&typeof r=="object"&&"default"in r?r:{default:r}}var d=q(R),O=q(G);function T(r){const t=/^\\\\\?\\/.test(r),n=/[^\u0000-\u0080]+/.test(r);return t||n?r:r.replace(/\\/g,"/")}function F(r,t){for(;;){const n=d.default.join(r,t);if(O.default.existsSync(n))return T(n);const e=d.default.dirname(r);if(e===r)return;r=e}}function K(r,t){t===void 0&&(t=!1);var n=r.length,e=0,s="",a=0,o=16,u=0,c=0,p=0,C=0,f=0;function A(i,b){for(var v=0,k=0;v<i||!b;){var h=r.charCodeAt(e);if(h>=48&&h<=57)k=k*16+h-48;else if(h>=65&&h<=70)k=k*16+h-65+10;else if(h>=97&&h<=102)k=k*16+h-97+10;else break;e++,v++}return v<i&&(k=-1),k}function V(i){e=i,s="",a=0,o=16,f=0}function $(){var i=e;if(r.charCodeAt(e)===48)e++;else for(e++;e<r.length&&y(r.charCodeAt(e));)e++;if(e<r.length&&r.charCodeAt(e)===46)if(e++,e<r.length&&y(r.charCodeAt(e)))for(e++;e<r.length&&y(r.charCodeAt(e));)e++;else return f=3,r.substring(i,e);var b=e;if(e<r.length&&(r.charCodeAt(e)===69||r.charCodeAt(e)===101))if(e++,(e<r.length&&r.charCodeAt(e)===43||r.charCodeAt(e)===45)&&e++,e<r.length&&y(r.charCodeAt(e))){for(e++;e<r.length&&y(r.charCodeAt(e));)e++;b=e}else f=3;return r.substring(i,b)}function E(){for(var i="",b=e;;){if(e>=n){i+=r.substring(b,e),f=2;break}var v=r.charCodeAt(e);if(v===34){i+=r.substring(b,e),e++;break}if(v===92){if(i+=r.substring(b,e),e++,e>=n){f=2;break}var k=r.charCodeAt(e++);switch(k){case 34:i+='"';break;case 92:i+="\\";break;case 47:i+="/";break;case 98:i+="\b";break;case 102:i+="\f";break;case 110:i+=`
`;break;case 114:i+="\r";break;case 116:i+=" ";break;case 117:var h=A(4,!0);h>=0?i+=String.fromCharCode(h):f=4;break;default:f=5}b=e;continue}if(v>=0&&v<=31)if(S(v)){i+=r.substring(b,e),f=2;break}else f=6;e++}return i}function P(){if(s="",f=0,a=e,c=u,C=p,e>=n)return a=n,o=17;var i=r.charCodeAt(e);if(U(i)){do e++,s+=String.fromCharCode(i),i=r.charCodeAt(e);while(U(i));return o=15}if(S(i))return e++,s+=String.fromCharCode(i),i===13&&r.charCodeAt(e)===10&&(e++,s+=`
`),u++,p=e,o=14;switch(i){case 123:return e++,o=1;case 125:return e++,o=2;case 91:return e++,o=3;case 93:return e++,o=4;case 58:return e++,o=6;case 44:return e++,o=5;case 34:return e++,s=E(),o=10;case 47:var b=e-1;if(r.charCodeAt(e+1)===47){for(e+=2;e<n&&!S(r.charCodeAt(e));)e++;return s=r.substring(b,e),o=12}if(r.charCodeAt(e+1)===42){e+=2;for(var v=n-1,k=!1;e<v;){var h=r.charCodeAt(e);if(h===42&&r.charCodeAt(e+1)===47){e+=2,k=!0;break}e++,S(h)&&(h===13&&r.charCodeAt(e)===10&&e++,u++,p=e)}return k||(e++,f=1),s=r.substring(b,e),o=13}return s+=String.fromCharCode(i),e++,o=16;case 45:if(s+=String.fromCharCode(i),e++,e===n||!y(r.charCodeAt(e)))return o=16;case 48:case 49:case 50:case 51:case 52:case 53:case 54:case 55:case 56:case 57:return s+=$(),o=11;default:for(;e<n&&m(i);)e++,i=r.charCodeAt(e);if(a!==e){switch(s=r.substring(a,e),s){case"true":return o=8;case"false":return o=9;case"null":return o=7}return o=16}return s+=String.fromCharCode(i),e++,o=16}}function m(i){if(U(i)||S(i))return!1;switch(i){case 125:case 93:case 123:case 91:case 34:case 58:case 44:case 47:return!1}return!0}function l(){var i;do i=P();while(i>=12&&i<=15);return i}return{setPosition:V,getPosition:function(){return e},scan:t?l:P,getToken:function(){return o},getTokenValue:function(){return s},getTokenOffset:function(){return a},getTokenLength:function(){return e-a},getTokenStartLine:function(){return c},getTokenStartCharacter:function(){return a-C},getTokenError:function(){return f}}}function U(r){return r===32||r===9||r===11||r===12||r===160||r===5760||r>=8192&&r<=8203||r===8239||r===8287||r===12288||r===65279}function S(r){return r===10||r===13||r===8232||r===8233}function y(r){return r>=48&&r<=57}var D;(function(r){r.DEFAULT={allowTrailingComma:!1}})(D||(D={}));function Q(r,t,n){t===void 0&&(t=[]),n===void 0&&(n=D.DEFAULT);var e=null,s=[],a=[];function o(c){Array.isArray(s)?s.push(c):e!==null&&(s[e]=c)}var u={onObjectBegin:function(){var c={};o(c),a.push(s),s=c,e=null},onObjectProperty:function(c){e=c},onObjectEnd:function(){s=a.pop()},onArrayBegin:function(){var c=[];o(c),a.push(s),s=c,e=null},onArrayEnd:function(){s=a.pop()},onLiteralValue:o,onError:function(c,p,C){t.push({error:c,offset:p,length:C})}};return X(r,u,n),s[0]}function X(r,t,n){n===void 0&&(n=D.DEFAULT);var e=K(r,!1);function s(g){return g?function(){return g(e.getTokenOffset(),e.getTokenLength(),e.getTokenStartLine(),e.getTokenStartCharacter())}:function(){return!0}}function a(g){return g?function(w){return g(w,e.getTokenOffset(),e.getTokenLength(),e.getTokenStartLine(),e.getTokenStartCharacter())}:function(){return!0}}var o=s(t.onObjectBegin),u=a(t.onObjectProperty),c=s(t.onObjectEnd),p=s(t.onArrayBegin),C=s(t.onArrayEnd),f=a(t.onLiteralValue),A=a(t.onSeparator),V=s(t.onComment),$=a(t.onError),E=n&&n.disallowComments,P=n&&n.allowTrailingComma;function m(){for(;;){var g=e.scan();switch(e.getTokenError()){case 4:l(14);break;case 5:l(15);break;case 3:l(13);break;case 1:E||l(11);break;case 2:l(12);break;case 6:l(16);break}switch(g){case 12:case 13:E?l(10):V();break;case 16:l(1);break;case 15:case 14:break;default:return g}}}function l(g,w,_){if(w===void 0&&(w=[]),_===void 0&&(_=[]),$(g),w.length+_.length>0)for(var L=e.getToken();L!==17;){if(w.indexOf(L)!==-1){m();break}else if(_.indexOf(L)!==-1)break;L=m()}}function i(g){var w=e.getTokenValue();return g?f(w):u(w),m(),!0}function b(){switch(e.getToken()){case 11:var g=e.getTokenValue(),w=Number(g);isNaN(w)&&(l(2),w=0),f(w);break;case 7:f(null);break;case 8:f(!0);break;case 9:f(!1);break;default:return!1}return m(),!0}function v(){return e.getToken()!==10?(l(3,[],[2,5]),!1):(i(!1),e.getToken()===6?(A(":"),m(),B()||l(4,[],[2,5])):l(5,[],[2,5]),!0)}function k(){o(),m();for(var g=!1;e.getToken()!==2&&e.getToken()!==17;){if(e.getToken()===5){if(g||l(4,[],[]),A(","),m(),e.getToken()===2&&P)break}else g&&l(6,[],[]);v()||l(4,[],[2,5]),g=!0}return c(),e.getToken()!==2?l(7,[2],[]):m(),!0}function h(){p(),m();for(var g=!1;e.getToken()!==4&&e.getToken()!==17;){if(e.getToken()===5){if(g||l(4,[],[]),A(","),m(),e.getToken()===4&&P)break}else g&&l(6,[],[]);B()||l(4,[],[4,5]),g=!0}return C(),e.getToken()!==4?l(8,[4],[]):m(),!0}function B(){switch(e.getToken()){case 3:return h();case 1:return k();case 10:return i(!0);default:return b()}}return m(),e.getToken()===17?n.allowEmptyContent?!0:(l(4,[],[]),!1):B()?(e.getToken()!==17&&l(9,[],[]),!0):(l(4,[],[]),!1)}var Y=Q;const W=/^\.{1,2}(\/.*)?$/,M=r=>T(W.test(r)?r:`./${r}`),N=r=>O.default.existsSync(r),Z=r=>{try{return JSON.parse(r)}catch{}};function x(r,t){let n=r;if(n===".."&&(n+="/tsconfig.json"),n.startsWith(".")){let e=d.default.resolve(t,n);if(N(e)&&O.default.statSync(e).isFile()||!e.endsWith(".json")&&(e+=".json",N(e)))return e}else{let e=F(t,d.default.join("node_modules",n));if(e){if(O.default.statSync(e).isDirectory()){const s=d.default.join(e,"package.json");if(N(s)){const a=Z(O.default.readFileSync(s,"utf8"));a&&"tsconfig"in a?e=d.default.join(e,a.tsconfig):e=d.default.join(e,"tsconfig.json")}else e=d.default.join(e,"tsconfig.json");if(N(e))return e}else if(e.endsWith(".json"))return e}if(!n.endsWith(".json")&&(n+=".json",e=F(t,d.default.join("node_modules",n)),e))return e}throw new Error(`File '${r}' not found.`)}var ee=Object.defineProperty,re=Object.defineProperties,ne=Object.getOwnPropertyDescriptors,I=Object.getOwnPropertySymbols,te=Object.prototype.hasOwnProperty,ae=Object.prototype.propertyIsEnumerable,z=(r,t,n)=>t in r?ee(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n,j=(r,t)=>{for(var n in t||(t={}))te.call(t,n)&&z(r,n,t[n]);if(I)for(var n of I(t))ae.call(t,n)&&z(r,n,t[n]);return r},oe=(r,t)=>re(r,ne(t));function J(r){var t;let n;try{n=O.default.realpathSync(r)}catch{throw new Error(`Cannot resolve tsconfig at path: ${r}`)}const e=d.default.dirname(n),s=O.default.readFileSync(n,"utf8").trim();let a={};if(s&&(a=Y(s),!a||typeof a!="object"))throw new SyntaxError(`Failed to parse tsconfig at: ${r}`);if(a.extends){const o=x(a.extends,e),u=J(o);if(delete u.references,(t=u.compilerOptions)!=null&&t.baseUrl){const{compilerOptions:p}=u;p.baseUrl=d.default.relative(e,d.default.join(d.default.dirname(o),p.baseUrl))||"./"}u.files&&(u.files=u.files.map(p=>d.default.relative(e,d.default.join(d.default.dirname(o),p)))),u.include&&(u.include=u.include.map(p=>d.default.relative(e,d.default.join(d.default.dirname(o),p)))),delete a.extends;const c=oe(j(j({},u),a),{compilerOptions:j(j({},u.compilerOptions),a.compilerOptions)});u.watchOptions&&(c.watchOptions=j(j({},u.watchOptions),a.watchOptions)),a=c}if(a.compilerOptions){const{compilerOptions:o}=a;o.baseUrl&&(o.baseUrl=M(o.baseUrl)),o.outDir&&(Array.isArray(a.exclude)||(a.exclude=[]),a.exclude.push(o.outDir),o.outDir=M(o.outDir))}if(a.files&&(a.files=a.files.map(M)),a.include&&(a.include=a.include.map(T)),a.watchOptions){const{watchOptions:o}=a;o.excludeDirectories&&(o.excludeDirectories=o.excludeDirectories.map(u=>T(d.default.resolve(e,u))))}return a}function ie(r=process.cwd(),t="tsconfig.json"){const n=F(r,t);if(!n)return null;const e=J(n);return{path:n,config:e}}const se=/\*/g,H=(r,t)=>{const n=r.match(se);if(n&&n.length>1)throw new Error(t)};function fe(r){if(r.includes("*")){const[t,n]=r.split("*");return{prefix:t,suffix:n}}return r}const ue=({prefix:r,suffix:t},n)=>n.startsWith(r)&&n.endsWith(t);function ce(r,t,n){return Object.entries(r).map(([e,s])=>(H(e,`Pattern '${e}' can have at most one '*' character.`),{pattern:fe(e),substitutions:s.map(a=>{if(H(a,`Substitution '${a}' in pattern '${e}' can have at most one '*' character.`),!t&&!W.test(a))throw new Error("Non-relative paths are not allowed when 'baseUrl' is not set. Did you forget a leading './'?");return d.default.join(n,a)})}))}function le(r){if(!r.config.compilerOptions)return null;const{baseUrl:t,paths:n}=r.config.compilerOptions;if(!t&&!n)return null;const e=d.default.resolve(d.default.dirname(r.path),t||"."),s=n?ce(n,t,e):[];return function(o){if(W.test(o))return[];const u=[];for(const f of s){if(f.pattern===o)return f.substitutions.map(T);typeof f.pattern!="string"&&u.push(f)}let c,p=-1;for(const f of u)ue(f.pattern,o)&&f.pattern.prefix.length>p&&(p=f.pattern.prefix.length,c=f);if(!c)return t?[T(d.default.join(e,o))]:[];const C=o.slice(c.pattern.prefix.length,o.length-c.pattern.suffix.length);return c.substitutions.map(f=>T(f.replace("*",C)))}}exports.createPathsMatcher=le,exports.getTsconfig=ie,exports.parseTsconfig=J;
{
"name": "get-tsconfig",
"version": "4.0.7",
"version": "4.1.0",
"description": "Find and parse the tsconfig.json file from a directory path",

@@ -30,2 +30,8 @@ "keywords": [

},
"imports": {
"#get-tsconfig": {
"development": "./src/index.ts",
"default": "./dist/index.mjs"
}
},
"scripts": {

@@ -35,3 +41,4 @@ "lint": "eslint .",

"pretest": "npm run build",
"test": "tsx tests"
"test": "tsx tests",
"dev": "tsx watch --conditions=development tests"
},

@@ -47,3 +54,3 @@ "devDependencies": {

"slash": "^4.0.0",
"tsx": "^3.4.2",
"tsx": "^3.6.0",
"type-fest": "^2.13.1",

@@ -50,0 +57,0 @@ "typescript": "^4.7.3"

@@ -7,3 +7,3 @@ # get-tsconfig [![Latest version](https://badgen.net/npm/v/get-tsconfig)](https://npm.im/get-tsconfig)

- Zero dependency (not even TypeScript)
- Tested against TypeScript for accuracy
- Tested against TypeScript for correctness
- Supports comments & dangling commas in `tsconfig.json`

@@ -24,23 +24,5 @@ - Resolves [`extends`](https://www.typescriptlang.org/tsconfig/#extends)

## 👨‍🏫 Usage
```ts
import { getTsconfig } from 'get-tsconfig'
// Finds tsconfig.json in the current directory
console.log(getTsconfig())
// Find tsconfig.json from a TypeScript file path
console.log(getTsconfig('./path/to/index.ts'))
// Find tsconfig.json from a directory file path
console.log(getTsconfig('./path/to/directory'))
// Explicitly pass in tsconfig.json path
console.log(getTsconfig('./path/to/tsconfig.json'))
```
## ⚙️ API
### getTsconfig(searchPath?: string, configName?: string)
### getTsconfig(searchPath?, configName?)
Searches for a `tsconfig.json` file and parses it. Returns `null` if a config file cannot be found, or an object containing the path and parsed TSConfig object if found.

@@ -78,13 +60,45 @@

### createPathsMatcher(tsconfig: TsconfigResult)
#### Example
Given a tsconfig with [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) defined, it returns a matcher function.
```ts
import { getTsconfig } from 'get-tsconfig'
// Searches for tsconfig.json starting in the current directory
console.log(getTsconfig())
// Find tsconfig.json from a TypeScript file path
console.log(getTsconfig('./path/to/index.ts'))
// Find tsconfig.json from a directory file path
console.log(getTsconfig('./path/to/directory'))
// Explicitly pass in tsconfig.json path
console.log(getTsconfig('./path/to/tsconfig.json'))
```
---
### parseTsconfig(tsconfigPath)
The `tsconfig.json` parser used internally by `getTsconfig`. Returns the parsed tsconfig as `TsConfigJsonResolved`.
#### tsconfigPath
Type: `string`
Required path to the tsconfig file.
#### Example
```ts
import { getTsconfig, createPathsMatcher } from 'get-tsconfig'
import { parseTsconfig } from 'get-tsconfig'
const tsconfig = getTsconfig()
const pathsMatcher = createPathsMatcher(tsconfig)
// Must pass in a path to an existing tsconfig.json file
console.log(parseTsconfig('./path/to/tsconfig.custom.json'))
```
---
### createPathsMatcher(tsconfig: TsconfigResult)
Given a tsconfig with [`compilerOptions.paths`](https://www.typescriptlang.org/tsconfig#paths) defined, it returns a matcher function.
The matcher function accepts an [import specifier (the path to resolve)](https://nodejs.org/api/esm.html#terminology), checks it against `compilerOptions.paths`, and returns an array of possible paths to check:

@@ -97,2 +111,19 @@ ```ts

#### Example
```ts
import { getTsconfig, createPathsMatcher } from 'get-tsconfig'
const tsconfig = getTsconfig()
const pathsMatcher = createPathsMatcher(tsconfig)
function exampleResolver(request: string) {
if (pathsMatcher) {
const tryPaths = pathsMatcher(request)
// Check if paths in `tryPaths` exist
}
}
```
## FAQ

@@ -99,0 +130,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc