@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
1 lines • 4.04 kB
Source Map (JSON)
{"version":3,"sources":["../../src/lib/esbuild/transpiler-plugin.ts"],"names":["transpilerPlugin","context","options","handleLoad","args","path","resolvedPath","vfs","resolvePath","contents","readFile","result","compiler","transpile","defu","skipTransformUnimport","babel","plugins","ModuleResolverPlugin","pluginData","name","setup","build","onLoad","filter"],"mappings":";;;;;;;;;;AA8BO,SAASA,gBAAAA,CACdC,OAAAA,EACAC,OAAAA,GAA2B,EAAC,EAAC;AAE7B,EAAA,MAAMC,UAAAA,mDAAmBC,IAAAA,KAAAA;AACvB,IAAA,IAAIA,KAAKC,IAAAA,EAAM;AACb,MAAA,MAAMC,YAAAA,GAAeL,OAAAA,CAAQM,GAAAA,CAAIC,WAAAA,CAAYJ,KAAKC,IAAI,CAAA;AACtD,MAAA,IAAIC,YAAAA,EAAc;AAChB,QAAA,MAAMG,QAAAA,GAAW,MAAMR,OAAAA,CAAQM,GAAAA,CAAIG,SAASJ,YAAAA,CAAAA;AAC5C,QAAA,IAAI,CAACG,QAAAA,EAAU;AACb,UAAA;AACF,QAAA;AAEA,QAAA,MAAME,MAAAA,GAAS,MAAMV,OAAAA,CAAQW,QAAAA,CAASC,UACpCZ,OAAAA,EACAK,YAAAA,EACAG,QAAAA,EACAK,qBAAAA,CAAKZ,OAAAA,EAAS;UACZa,qBAAAA,EAAuB,IAAA;UACvBC,KAAAA,EAAO;YACLC,OAAAA,EAAS;AACPC,cAAAA,sCAAAA,CAAqBjB,OAAAA,CAAAA;AAClBA,cAAAA,GAAAA,OAAAA,CAAQC,QAAQc,KAAAA,CAAMC;;AAE7B;AACF,SAAA,CAAA,CAAA;AAGF,QAAA,OAAO;UACLR,QAAAA,EAAUE,MAAAA;AACVQ,UAAAA,UAAAA,EAAYf,IAAAA,CAAKe;AACnB,SAAA;AACF,MAAA;AACF,IAAA;AAGA,IAAA;EACF,CAAA,EAjCmB,YAAA,CAAA;AAmCnB,EAAA,OAAO;IACLC,IAAAA,EAAM,wBAAA;AACNC,IAAAA,KAAAA,CAAMC,KAAAA,EAAK;AACTA,MAAAA,KAAAA,CAAMC,MAAAA,CAAO;QAAEC,MAAAA,EAAQ;AAAK,OAAA,EAAGrB,UAAAA,CAAAA;AAC/BmB,MAAAA,KAAAA,CAAMC,MAAAA,CAAO;QAAEC,MAAAA,EAAQ;AAAU,OAAA,EAAGrB,UAAAA,CAAAA;AACtC,IAAA;AACF,GAAA;AACF;AA9CgBH,wBAAAA,CAAAA,gBAAAA,EAAAA,kBAAAA,CAAAA","file":"chunk-WMPMHBXV.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 { CompilerOptions } from \"../../types/compiler\";\nimport type { Context } from \"../../types/context\";\nimport { ModuleResolverPlugin } from \"../babel/plugins/module-resolver\";\n\n/**\n * Create a transpiler plugin for esbuild that transpiles TypeScript files.\n *\n * @param context - The base context containing TypeScript configuration and options.\n * @returns An esbuild plugin that transpiles TypeScript files.\n */\nexport function transpilerPlugin(\n context: Context,\n options: CompilerOptions = {}\n): Plugin {\n const handleLoad = async args => {\n if (args.path) {\n const resolvedPath = context.vfs.resolvePath(args.path);\n if (resolvedPath) {\n const contents = await context.vfs.readFile(resolvedPath);\n if (!contents) {\n return;\n }\n\n const result = await context.compiler.transpile(\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 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:transpiler\",\n setup(build) {\n build.onLoad({ filter: /.*/ }, handleLoad);\n build.onLoad({ filter: /^storm:/ }, handleLoad);\n }\n };\n}\n"]}