@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
1 lines • 4.5 kB
Source Map (JSON)
{"version":3,"sources":["../../src/lib/typescript/isolated-decl.ts"],"names":["isolatedDeclarations","id","code","transformOptions","sourceMap","ts","transpileDeclaration","errors","compilerOptions","declarationMap","outputText","diagnostics","sourceMapText","fileName","reportDiagnostics","split","at","startsWith","slice","join","length","formatDiagnostics","getCanonicalFileName","sys","useCaseSensitiveFileNames","toLowerCase","getCurrentDirectory","__name","getNewLine","newLine","JSON","parse","mappings","map"],"mappings":";;;;;;;;;AA0BA,eAAsBA,oBAAAA,CACpBC,EAAAA,EACAC,IAAAA,EACAC,gBAAAA,EACAC,SAAAA,EAAmB;AAEnB,EAAA,IAAI,CAACC,oBAAGC,oBAAAA,EAAsB;AAC5B,IAAA,OAAO;MACLJ,IAAAA,EAAM,EAAA;MACNK,MAAAA,EAAQ;AACN,QAAA;;AAEJ,KAAA;AACF,EAAA;AAEA,EAAA,MAAMC,eAAAA,GAAmC;IACvCC,cAAAA,EAAgBL,SAAAA;AAChB,IAAA,GAAGD,gBAAAA,EAAkBK;AACvB,GAAA;AACA,EAAA,IAAI,EAAEE,UAAAA,EAAYC,WAAAA,EAAaC,eAAa,GAAKP,mBAAAA,CAAGC,qBAClDJ,IAAAA,EACA;IACEW,QAAAA,EAAUZ,EAAAA;IACVa,iBAAAA,EAAmB,IAAA;IACnB,GAAGX,gBAAAA;AACHK,IAAAA;GACF,CAAA;AAGF,EAAA,IAAIA,gBAAgBC,cAAAA,EAAgB;AAClC,IAAA,IAAIC,UAAAA,CAAWK,MAAM,IAAA,CAAA,CAAMC,GAAG,EAAC,CAAA,EAAIC,UAAAA,CAAW,uBAAA,CAAA,EAA0B;AACtEP,MAAAA,UAAAA,GAAaA,UAAAA,CAAWK,MAAM,IAAA,CAAA,CAAMG,MAAM,CAAA,EAAG,EAAC,CAAA,CAAGC,IAAAA,CAAK,IAAA,CAAA;AACxD,IAAA;AACF,EAAA;AAEA,EAAA,MAAMZ,MAAAA,GAASI,aAAaS,MAAAA,GACxB;AACEf,IAAAA,mBAAAA,CAAGgB,kBAAkBV,WAAAA,EAAa;MAChCW,oBAAAA,kBAAsBT,wBAAAA,CAAAA,CAAAA,aACpBR,mBAAAA,CAAGkB,GAAAA,CAAIC,4BACHX,QAAAA,GACAA,QAAAA,CAASY,aAAW,EAHJZ,sBAAAA,CAAAA;AAItBa,MAAAA,mBAAAA,kBAAqBC,wBAAA,CAAA,MAAMtB,mBAAAA,CAAGkB,GAAAA,CAAIG,mBAAAA,EAAmB,EAAhC,qBAAA,CAAA;MACrBE,UAAAA,kBAAYD,wBAAA,CAAA,MAAMtB,mBAAAA,CAAGkB,GAAAA,CAAIM,OAAAA,EAAb,YAAA;KACd;MAEF,EAAA;AAEJ,EAAA,IAAIjB,aAAAA,EAAe;AACjBA,IAAAA,aAAAA,GAAgBkB,IAAAA,CAAKC,KAAAA,CAAMnB,aAAAA,CAAAA,CAAeoB,QAAAA;AAC5C,EAAA;AAEA,EAAA,OAAO;IACL9B,IAAAA,EAAMQ,UAAAA;AACNH,IAAAA,MAAAA;IACA0B,GAAAA,EAAKrB;AACP,GAAA;AACF;AAzDsBZ,wBAAAA,CAAAA,oBAAAA,EAAAA,sBAAAA,CAAAA","file":"chunk-GNXZRHKW.cjs","sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Storm Stack\n\n This code was released as part of the Storm Stack project. Storm Stack\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/storm-stack.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/storm-stack\n Documentation: https://docs.stormsoftware.com/projects/storm-stack\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport ts, { CompilerOptions, TranspileOptions } from \"typescript\";\n\nexport interface IsolatedDeclarationsResult {\n code: string;\n errors: Array<string>;\n map?: string;\n}\n\nexport async function isolatedDeclarations(\n id: string,\n code: string,\n transformOptions?: TranspileOptions,\n sourceMap?: boolean\n): Promise<IsolatedDeclarationsResult> {\n if (!ts.transpileDeclaration) {\n return {\n code: \"\",\n errors: [\n \"TypeScript version is too low, please upgrade to TypeScript 5.5.2+.\"\n ]\n };\n }\n\n const compilerOptions: CompilerOptions = {\n declarationMap: sourceMap,\n ...transformOptions?.compilerOptions\n };\n let { outputText, diagnostics, sourceMapText } = ts.transpileDeclaration(\n code,\n {\n fileName: id,\n reportDiagnostics: true,\n ...transformOptions,\n compilerOptions\n }\n );\n\n if (compilerOptions.declarationMap) {\n if (outputText.split(\"\\n\").at(-1)?.startsWith(\"//# sourceMappingURL=\")) {\n outputText = outputText.split(\"\\n\").slice(0, -1).join(\"\\n\");\n }\n }\n\n const errors = diagnostics?.length\n ? [\n ts.formatDiagnostics(diagnostics, {\n getCanonicalFileName: fileName =>\n ts.sys.useCaseSensitiveFileNames\n ? fileName\n : fileName.toLowerCase(),\n getCurrentDirectory: () => ts.sys.getCurrentDirectory(),\n getNewLine: () => ts.sys.newLine\n })\n ]\n : [];\n\n if (sourceMapText) {\n sourceMapText = JSON.parse(sourceMapText).mappings;\n }\n\n return {\n code: outputText,\n errors,\n map: sourceMapText\n };\n}\n"]}