@storm-stack/core
Version:
A build toolkit and runtime used by Storm Software in TypeScript applications
1 lines • 5.51 kB
Source Map (JSON)
{"version":3,"sources":["../../src/lib/esbuild/bundle.ts"],"names":["bundle","context","bundleOptions","options","defu","plugins","resolverPlugin","external","noExternal","skipNodeModulesBundle","compiler","skipAllTransforms","transpilerPlugin","compilerPlugin","filter","Boolean","resolveESBuildOptions","outdir","outputPath","entryPoints","resolveEsbuildEntryOptions","entry","Array","isArray","isString","Object","values","esbuild","error","log","LogLevelLabel","ERROR","message"],"mappings":";;;;;;;;;;;;;;;;AAwDA,eAAsBA,MAAAA,CACpBC,OAAAA,EACAC,aAAAA,GAA+B,EAAC,EAAC;AAEjC,EAAA,MAAMC,UAAUC,qBAAAA,CACd;IACEC,OAAAA,EAAS;AACPC,MAAAA,gCAAAA,CAAeL,OAAAA,EAAS;AACtBM,QAAAA,QAAAA,EAAUL,aAAAA,CAAcK,QAAAA;AACxBC,QAAAA,UAAAA,EAAYN,aAAAA,CAAcM,UAAAA;AAC1BC,QAAAA,qBAAAA,EAAuBP,aAAAA,CAAcO;OACvC,CAAA;MACAP,aAAAA,CAAcQ,QAAAA,EAAUC,iBAAAA,KAAsB,IAAA,GAC1CC,kCAAAA,CAAiBX,OAAAA,EAASC,aAAAA,CAAcQ,QAAQ,CAAA,GAChDG,gCAAAA,CAAeZ,OAAAA,EAASC,aAAAA,CAAcQ,QAAQ;AAClDI,KAAAA,CAAAA,MAAAA,CAAOC,OAAAA;AACX,GAAA,EACAC,wCACEf,OAAAA,EACA;AACEgB,IAAAA,MAAAA,EAAQf,aAAAA,CAAcgB,UAAAA;AACtBC,IAAAA,WAAAA,EAAaC,4CAAAA,CACXnB,OAAAA,EACAC,aAAAA,CAAcmB,KAAAA,GACVC,MAAMC,OAAAA,CAAQrB,aAAAA,CAAcmB,KAAK,CAAA,GAC/BnB,aAAAA,CAAcmB,KAAAA,GACdG,iBAAAA,CAAStB,aAAAA,CAAcmB,KAAK,CAAA,GAC1B;MAACnB,aAAAA,CAAcmB;AACfI,KAAAA,GAAAA,MAAAA,CAAOC,MAAAA,CAAOxB,aAAAA,CAAcmB,KAAK,CAAA,GACrC,EAAE,CAAA;IAERrB,MAAAA,EAAQ;AACV,GAAA,EACAE,aAAAA,CAAAA,CAAAA;AAIJ,EAAA,IAAI;AACF,IAAA,OAAO,MAAMyB,cAAQxB,OAAAA,CAAAA;AACvB,EAAA,CAAA,CAAA,OAASyB,KAAAA,EAAO;AACd3B,IAAAA,OAAAA,CAAQ4B,GAAAA,CACNC,oBAAcC,KAAAA,EACdH,KAAAA,EAAOI,UACH,CAAA,kCAAA,EAAqCJ,KAAAA,EAAOI,OAAAA,CAAAA,CAAAA,GAC5C,kCAAA,CAAA;AAGN,IAAA,MAAMJ,KAAAA;AACR,EAAA;AACF;AAjDsB5B,wBAAAA,CAAAA,MAAAA,EAAAA,QAAAA,CAAAA","file":"chunk-X2JNQCAO.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 { Entry } from \"@storm-software/build-tools/types\";\nimport { LogLevelLabel } from \"@storm-software/config-tools/types\";\nimport { isString } from \"@stryke/type-checks/is-string\";\nimport defu from \"defu\";\nimport {\n build as esbuild,\n BuildOptions as ExternalESBuildOptions\n} from \"esbuild\";\nimport type { ResolvedOptions } from \"../../types/build\";\nimport { CompilerOptions } from \"../../types/compiler\";\nimport { ESBuildOverrideOptions } from \"../../types/config\";\nimport type { Context } from \"../../types/context\";\nimport { compilerPlugin } from \"./compiler-plugin\";\nimport { resolveEsbuildEntryOptions, resolveESBuildOptions } from \"./options\";\nimport { resolverPlugin } from \"./resolver-plugin\";\nimport { transpilerPlugin } from \"./transpiler-plugin\";\n\n/**\n * Options for the bundling process using esbuild. This type extends the ResolvedOptions type to include additional properties specific to the bundling process.\n */\nexport type BundleOptions = Pick<\n ResolvedOptions,\n \"external\" | \"noExternal\" | \"skipNodeModulesBundle\"\n> & {\n entry?: Entry;\n outputPath?: string;\n alias?: Record<string, string>;\n override?: Partial<ESBuildOverrideOptions>;\n compiler?: CompilerOptions;\n};\n\n/**\n * Bundles the specified entry points using esbuild.\n *\n * @param context - Base context for the bundling process.\n * @param bundleOptions - Additional options for the bundling process.\n * @returns The result of the bundling process.\n */\nexport async function bundle(\n context: Context,\n bundleOptions: BundleOptions = {}\n) {\n const options = defu(\n {\n plugins: [\n resolverPlugin(context, {\n external: bundleOptions.external,\n noExternal: bundleOptions.noExternal,\n skipNodeModulesBundle: bundleOptions.skipNodeModulesBundle\n }),\n bundleOptions.compiler?.skipAllTransforms === true\n ? transpilerPlugin(context, bundleOptions.compiler)\n : compilerPlugin(context, bundleOptions.compiler)\n ].filter(Boolean)\n },\n resolveESBuildOptions(\n context,\n {\n outdir: bundleOptions.outputPath,\n entryPoints: resolveEsbuildEntryOptions(\n context,\n bundleOptions.entry\n ? Array.isArray(bundleOptions.entry)\n ? bundleOptions.entry\n : isString(bundleOptions.entry)\n ? [bundleOptions.entry]\n : Object.values(bundleOptions.entry)\n : []\n ),\n bundle: true\n },\n bundleOptions\n )\n ) as ExternalESBuildOptions;\n\n try {\n return await esbuild(options);\n } catch (error) {\n context.log(\n LogLevelLabel.ERROR,\n error?.message\n ? `An error occurred while bundling: ${error?.message}`\n : \"An error occurred while bundling\"\n );\n\n throw error;\n }\n}\n"]}