UNPKG

@storm-stack/core

Version:

A build toolkit and runtime used by Storm Software in TypeScript applications

1 lines 4.16 kB
{"version":3,"sources":["../../src/lib/esbuild/deepkit-plugin.ts"],"names":["loader","DeepkitLoader","deepkitPlugin","context","name","setup","build","onLoad","filter","args","contents","readFile","path","pluginData","isReflected","RESOLVE_NAMESPACE","transform","error","log","LogLevelLabel","ERROR","Error","message","String"],"mappings":";;;;;;;AAyBA,IAAMA,MAAAA,GAAS,KAAoBC,MAAAA,GAAa;AAEzC,IAAMC,aAAAA,6CAAiBC,OAAAA,KAAAA;AAC5B,EAAA,OAAO;IACLC,IAAAA,EAAM,qBAAA;AACNC,IAAAA,KAAAA,CAAMC,KAAAA,EAAK;AACTA,MAAAA,KAAAA,CAAMC,MAAAA,CACJ;QAAEC,MAAAA,EAAQ;AAAS,OAAA,EACnB,OAAOC,IAAAA,KAAAA;AACL,QAAA,IAAIC,QAAAA;AAEJ,QAAA,IAAI;AACFA,UAAAA,QAAAA,GAAW,MAAMC,iBAAAA,CAASF,IAAAA,CAAKG,IAAI,CAAA;AAEnC,UAAA,IAAIH,IAAAA,CAAKI,YAAYC,WAAAA,EAAa;AAChC,YAAA,OAAO;AACLJ,cAAAA,QAAAA;;cAEAG,UAAAA,EAAY;gBACV,GAAIJ,IAAAA,CAAKI,cAAc,EAAC;AACxB,gBAAA,CAACE,mCAAAA,GAAoB;kBACnBD,WAAAA,EAAa;AACf;AACF;AACF,aAAA;AACF,UAAA;AAEAJ,UAAAA,QAAAA,GAAWV,MAAAA,CAAOgB,SAAAA,CAAUN,QAAAA,EAAUD,IAAAA,CAAKG,IAAI,CAAA;AACjD,QAAA,CAAA,CAAA,OAASK,KAAAA,EAAO;AACdd,UAAAA,OAAAA,CAAQe,GAAAA,CACNC,mBAAAA,CAAcC,KAAAA,EACd,CAAA,mCAAA,EAAsCX,KAAKG,IAAI,CAAA,GAAA,EAAMK,KAAAA,YAAiBI,KAAAA,GAAQJ,KAAAA,CAAMK,OAAAA,GAAUC,MAAAA,CAAON,KAAAA,CAAAA,CAAAA,CAAQ,CAAA;AAE/G,UAAA,OAAO,IAAA;AACT,QAAA;AAEA,QAAA,OAAO;AACLP,UAAAA,QAAAA;;UAEAG,UAAAA,EAAY;YACV,GAAIJ,IAAAA,CAAKI,cAAc,EAAC;AACxB,YAAA,CAACE,mCAAAA,GAAoB;cACnBD,WAAAA,EAAa;AACf;AACF;AACF,SAAA;MACF,CAAA,CAAA;AAEJ,IAAA;AACF,GAAA;AACF,CAAA,EAhD6B,eAAA","file":"chunk-ZJ4TUCL7.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 * as DeepkitCompiler from \"@deepkit/type-compiler\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { readFile } from \"@stryke/fs/read-file\";\nimport type { OnLoadArgs, OnLoadResult, Plugin } from \"esbuild\";\nimport { Context } from \"../../types/context\";\nimport { RESOLVE_NAMESPACE } from \"./constants\";\n\nconst loader = new DeepkitCompiler.DeepkitLoader();\n\nexport const deepkitPlugin = (context: Context): Plugin => {\n return {\n name: \"storm-stack:deepkit\",\n setup(build) {\n build.onLoad(\n { filter: /.tsx?$/ },\n async (args: OnLoadArgs): Promise<OnLoadResult | null | undefined> => {\n let contents: string;\n\n try {\n contents = await readFile(args.path);\n // If already reflected do nothing\n if (args.pluginData?.isReflected) {\n return {\n contents,\n // loader: \"ts\",\n pluginData: {\n ...(args.pluginData || {}),\n [RESOLVE_NAMESPACE]: {\n isReflected: true\n }\n }\n };\n }\n\n contents = loader.transform(contents, args.path);\n } catch (error) {\n context.log(\n LogLevelLabel.ERROR,\n `Deepkit reflection error for file \"${args.path}\": ${error instanceof Error ? error.message : String(error)}`\n );\n return null;\n }\n\n return {\n contents,\n // loader: \"ts\",\n pluginData: {\n ...(args.pluginData || {}),\n [RESOLVE_NAMESPACE]: {\n isReflected: true\n }\n }\n };\n }\n );\n }\n };\n};\n"]}