@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
1 lines • 4.78 kB
Source Map (JSON)
{"version":3,"sources":["../../src/lib/esbuild/compiler-plugin.ts"],"names":["compilerPlugin","context","options","cache","Map","handleLoad","args","path","resolvedPath","vfs","resolvePath","type","has","contents","get","pluginData","readFile","result","compiler","compile","defu","skipTransformUnimport","babel","plugins","ModuleResolverPlugin","set","name","setup","build","onLoad","filter"],"mappings":";;;;;;;;;;AA+BO,SAASA,cAAAA,CACdC,OAAAA,EACAC,OAAAA,GAA2B,EAAC,EAAC;AAE7B,EAAA,MAAMC,KAAAA,uBAAYC,GAAAA,EAAAA;AAElB,EAAA,MAAMC,UAAAA,mDAAmBC,IAAAA,KAAAA;AACvB,IAAA,IAAIA,KAAKC,IAAAA,EAAM;AACb,MAAA,MAAMC,YAAAA,GAAeP,OAAAA,CAAQQ,GAAAA,CAAIC,WAAAA,CAAYJ,KAAKC,IAAAA,EAAM;QACtDI,IAAAA,EAAM;OACR,CAAA;AAEA,MAAA,IAAIH,YAAAA,EAAc;AAChB,QAAA,IAAIL,KAAAA,CAAMS,GAAAA,CAAIJ,YAAAA,CAAAA,EAAe;AAC3B,UAAA,OAAO;YACLK,QAAAA,EAAUV,KAAAA,CAAMW,IAAIN,YAAAA,CAAAA;AACpBO,YAAAA,UAAAA,EAAYT,IAAAA,CAAKS;AACnB,WAAA;AACF,QAAA;AAEA,QAAA,MAAMF,QAAAA,GAAW,MAAMZ,OAAAA,CAAQQ,GAAAA,CAAIO,SAASR,YAAAA,CAAAA;AAC5C,QAAA,IAAI,CAACK,QAAAA,EAAU;AACb,UAAA;AACF,QAAA;AAEA,QAAA,MAAMI,MAAAA,GAAS,MAAMhB,OAAAA,CAAQiB,QAAAA,CAASC,QACpClB,OAAAA,EACAO,YAAAA,EACAK,QAAAA,EACAO,qBAAAA,CAAKlB,OAAAA,EAAS;UACZmB,qBAAAA,EAAuB,IAAA;UACvBC,KAAAA,EAAO;YACLC,OAAAA,EAAS;AACPC,cAAAA,sCAAAA,CAAqBvB,OAAAA,CAAAA;AAClBA,cAAAA,GAAAA,OAAAA,CAAQC,QAAQoB,KAAAA,CAAMC;;AAE7B;AACF,SAAA,CAAA,CAAA;AAGFpB,QAAAA,KAAAA,CAAMsB,GAAAA,CAAInB,IAAAA,CAAKC,IAAAA,EAAMU,MAAAA,CAAAA;AAErB,QAAA,OAAO;UACLJ,QAAAA,EAAUI,MAAAA;AACVF,UAAAA,UAAAA,EAAYT,IAAAA,CAAKS;AACnB,SAAA;AACF,MAAA;AACF,IAAA;AAGA,IAAA;EACF,CAAA,EA7CmB,YAAA,CAAA;AA+CnB,EAAA,OAAO;IACLW,IAAAA,EAAM,sBAAA;AACNC,IAAAA,KAAAA,CAAMC,KAAAA,EAAK;AACTA,MAAAA,KAAAA,CAAMC,MAAAA,CAAO;QAAEC,MAAAA,EAAQ;AAAK,OAAA,EAAGzB,UAAAA,CAAAA;AAC/BuB,MAAAA,KAAAA,CAAMC,MAAAA,CAAO;QAAEC,MAAAA,EAAQ;AAAU,OAAA,EAAGzB,UAAAA,CAAAA;AACtC,IAAA;AACF,GAAA;AACF;AA5DgBL,wBAAAA,CAAAA,cAAAA,EAAAA,gBAAAA,CAAAA","file":"chunk-UY2GAVJJ.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 defu from \"defu\";\nimport type { Plugin } from \"esbuild\";\nimport type { CompilerOptions } from \"../../types/compiler\";\nimport { Context } from \"../../types/context\";\nimport { ModuleResolverPlugin } from \"../babel/plugins/module-resolver\";\n\n/**\n * Create a compiler plugin for esbuild that compiles TypeScript files.\n *\n * @param context - The base context containing TypeScript configuration and options.\n * @param options - Optional compiler options to customize the TypeScript compilation.\n * @returns An esbuild plugin that compiles TypeScript files.\n */\nexport function compilerPlugin(\n context: Context,\n options: CompilerOptions = {}\n): Plugin {\n const cache = new Map<string, string>();\n\n const handleLoad = async args => {\n if (args.path) {\n const resolvedPath = context.vfs.resolvePath(args.path, {\n type: \"file\"\n });\n\n if (resolvedPath) {\n if (cache.has(resolvedPath)) {\n return {\n contents: cache.get(resolvedPath),\n pluginData: args.pluginData\n };\n }\n\n const contents = await context.vfs.readFile(resolvedPath);\n if (!contents) {\n return;\n }\n\n const result = await context.compiler.compile(\n context,\n resolvedPath,\n contents,\n defu(options, {\n skipTransformUnimport: true,\n babel: {\n plugins: [\n ModuleResolverPlugin(context),\n ...context.options.babel.plugins\n ]\n }\n })\n );\n\n cache.set(args.path, result);\n\n return {\n contents: result,\n pluginData: args.pluginData\n };\n }\n }\n\n // eslint-disable-next-line no-useless-return\n return;\n };\n\n return {\n name: \"storm-stack:compiler\",\n setup(build) {\n build.onLoad({ filter: /.*/ }, handleLoad);\n build.onLoad({ filter: /^storm:/ }, handleLoad);\n }\n };\n}\n"]}