printer.js.map 7.9 KB

1
  1. {"version":3,"names":["_gensync","data","require","ChainFormatter","exports","Programmatic","Config","Formatter","title","type","callerName","filepath","loc","index","envName","optionsAndDescriptors","opt","content","Object","assign","options","overrides","env","pluginDescriptors","plugins","length","map","d","descriptorToConfig","presetDescriptors","presets","JSON","stringify","undefined","_d$file","name","file","request","value","toString","slice","ConfigPrinter","constructor","_stack","configure","enabled","push","format","config","output","configs","gensync","all","s","join"],"sources":["../../src/config/printer.ts"],"sourcesContent":["import gensync from \"gensync\";\n\nimport type { Handler } from \"gensync\";\n\nimport type {\n OptionsAndDescriptors,\n UnloadedDescriptor,\n} from \"./config-descriptors.ts\";\n\n// todo: Use flow enums when @babel/transform-flow-types supports it\nexport const ChainFormatter = {\n Programmatic: 0,\n Config: 1,\n};\n\ntype PrintableConfig = {\n content: OptionsAndDescriptors;\n type: (typeof ChainFormatter)[keyof typeof ChainFormatter];\n callerName: string | undefined | null;\n filepath: string | undefined | null;\n index: number | undefined | null;\n envName: string | undefined | null;\n};\n\nconst Formatter = {\n title(\n type: (typeof ChainFormatter)[keyof typeof ChainFormatter],\n callerName?: string | null,\n filepath?: string | null,\n ): string {\n let title = \"\";\n if (type === ChainFormatter.Programmatic) {\n title = \"programmatic options\";\n if (callerName) {\n title += \" from \" + callerName;\n }\n } else {\n title = \"config \" + filepath;\n }\n return title;\n },\n loc(index?: number | null, envName?: string | null): string {\n let loc = \"\";\n if (index != null) {\n loc += `.overrides[${index}]`;\n }\n if (envName != null) {\n loc += `.env[\"${envName}\"]`;\n }\n return loc;\n },\n\n *optionsAndDescriptors(opt: OptionsAndDescriptors) {\n const content = { ...opt.options };\n // overrides and env will be printed as separated config items\n delete content.overrides;\n delete content.env;\n // resolve to descriptors\n const pluginDescriptors = [...(yield* opt.plugins())];\n if (pluginDescriptors.length) {\n content.plugins = pluginDescriptors.map(d => descriptorToConfig(d));\n }\n const presetDescriptors = [...(yield* opt.presets())];\n if (presetDescriptors.length) {\n content.presets = [...presetDescriptors].map(d => descriptorToConfig(d));\n }\n return JSON.stringify(content, undefined, 2);\n },\n};\n\nfunction descriptorToConfig<API>(\n d: UnloadedDescriptor<API>,\n): object | string | [string, unknown] | [string, unknown, string] {\n let name: object | string = d.file?.request;\n if (name == null) {\n if (typeof d.value === \"object\") {\n name = d.value;\n } else if (typeof d.value === \"function\") {\n // If the unloaded descriptor is a function, i.e. `plugins: [ require(\"my-plugin\") ]`,\n // we print the first 50 characters of the function source code and hopefully we can see\n // `name: 'my-plugin'` in the source\n name = `[Function: ${d.value.toString().slice(0, 50)} ... ]`;\n }\n }\n if (name == null) {\n name = \"[Unknown]\";\n }\n if (d.options === undefined) {\n return name;\n } else if (d.name == null) {\n return [name, d.options];\n } else {\n return [name, d.options, d.name];\n }\n}\n\nexport class ConfigPrinter {\n _stack: Array<PrintableConfig> = [];\n configure(\n enabled: boolean,\n type: (typeof ChainFormatter)[keyof typeof ChainFormatter],\n {\n callerName,\n filepath,\n }: {\n callerName?: string;\n filepath?: string;\n },\n ) {\n if (!enabled) return () => {};\n return (\n content: OptionsAndDescriptors,\n index?: number | null,\n envName?: string | null,\n ) => {\n this._stack.push({\n type,\n callerName,\n filepath,\n content,\n index,\n envName,\n });\n };\n }\n static *format(config: PrintableConfig): Handler<string> {\n let title = Formatter.title(\n config.type,\n config.callerName,\n config.filepath,\n );\n const loc = Formatter.loc(config.index, config.envName);\n if (loc) title += ` ${loc}`;\n const content = yield* Formatter.optionsAndDescriptors(config.content);\n return `${title}\\n${content}`;\n }\n\n *output(): Handler<string> {\n if (this._stack.length === 0) return \"\";\n const configs = yield* gensync.all(\n this._stack.map(s => ConfigPrinter.format(s)),\n );\n return configs.join(\"\\n\\n\");\n }\n}\n"],"mappings":";;;;;;AAAA,SAAAA,SAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,QAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAUO,MAAME,cAAc,GAAAC,OAAA,C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