package.lib.config.partial.js.map Maven / Gradle / Ivy
The newest version!
{"version":3,"names":["_path","data","require","_plugin","_util","_item","_configChain","_environment","_options","_index","_resolveTargets","_excluded","_objectWithoutPropertiesLoose","source","excluded","target","sourceKeys","Object","keys","key","i","length","indexOf","resolveRootMode","rootDir","rootMode","upwardRootDir","findConfigUpwards","assign","Error","ROOT_CONFIG_FILENAMES","join","code","dirname","loadPrivatePartialConfig","inputOpts","Array","isArray","args","validate","envName","getEnv","cwd","root","caller","cloneInputAst","absoluteCwd","path","resolve","absoluteRootDir","filename","undefined","showConfigPath","resolveShowConfigPath","context","showConfig","configChain","buildRootChain","merged","assumptions","options","forEach","opts","mergeOptions","targets","resolveTargets","babelrc","configFile","browserslistConfigFile","passPerPreset","plugins","map","descriptor","createItemFromDescriptor","presets","fileHandling","ignore","config","files","loadPartialConfig","showIgnoredFiles","_opts","result","item","value","Plugin","PartialConfig","filepath","constructor","babelignore","freeze","hasFilesystemConfig","prototype"],"sources":["../../src/config/partial.ts"],"sourcesContent":["import path from \"path\";\nimport type { Handler } from \"gensync\";\nimport Plugin from \"./plugin.ts\";\nimport { mergeOptions } from \"./util.ts\";\nimport { createItemFromDescriptor } from \"./item.ts\";\nimport { buildRootChain } from \"./config-chain.ts\";\nimport type { ConfigContext, FileHandling } from \"./config-chain.ts\";\nimport { getEnv } from \"./helpers/environment.ts\";\nimport { validate } from \"./validation/options.ts\";\n\nimport type {\n ValidatedOptions,\n NormalizedOptions,\n RootMode,\n} from \"./validation/options.ts\";\n\nimport {\n findConfigUpwards,\n resolveShowConfigPath,\n ROOT_CONFIG_FILENAMES,\n} from \"./files/index.ts\";\nimport type { ConfigFile, IgnoreFile } from \"./files/index.ts\";\nimport { resolveTargets } from \"./resolve-targets.ts\";\n\nfunction resolveRootMode(rootDir: string, rootMode: RootMode): string {\n switch (rootMode) {\n case \"root\":\n return rootDir;\n\n case \"upward-optional\": {\n const upwardRootDir = findConfigUpwards(rootDir);\n return upwardRootDir === null ? rootDir : upwardRootDir;\n }\n\n case \"upward\": {\n const upwardRootDir = findConfigUpwards(rootDir);\n if (upwardRootDir !== null) return upwardRootDir;\n\n throw Object.assign(\n new Error(\n `Babel was run with rootMode:\"upward\" but a root could not ` +\n `be found when searching upward from \"${rootDir}\".\\n` +\n `One of the following config files must be in the directory tree: ` +\n `\"${ROOT_CONFIG_FILENAMES.join(\", \")}\".`,\n ) as any,\n {\n code: \"BABEL_ROOT_NOT_FOUND\",\n dirname: rootDir,\n },\n );\n }\n default:\n throw new Error(`Assertion failure - unknown rootMode value.`);\n }\n}\n\ntype PrivPartialConfig = {\n options: NormalizedOptions;\n context: ConfigContext;\n fileHandling: FileHandling;\n ignore: IgnoreFile | void;\n babelrc: ConfigFile | void;\n config: ConfigFile | void;\n files: Set;\n};\n\nexport default function* loadPrivatePartialConfig(\n inputOpts: unknown,\n): Handler {\n if (\n inputOpts != null &&\n (typeof inputOpts !== \"object\" || Array.isArray(inputOpts))\n ) {\n throw new Error(\"Babel options must be an object, null, or undefined\");\n }\n\n const args = inputOpts ? validate(\"arguments\", inputOpts) : {};\n\n const {\n envName = getEnv(),\n cwd = \".\",\n root: rootDir = \".\",\n rootMode = \"root\",\n caller,\n cloneInputAst = true,\n } = args;\n const absoluteCwd = path.resolve(cwd);\n const absoluteRootDir = resolveRootMode(\n path.resolve(absoluteCwd, rootDir),\n rootMode,\n );\n\n const filename =\n typeof args.filename === \"string\"\n ? path.resolve(cwd, args.filename)\n : undefined;\n\n const showConfigPath = yield* resolveShowConfigPath(absoluteCwd);\n\n const context: ConfigContext = {\n filename,\n cwd: absoluteCwd,\n root: absoluteRootDir,\n envName,\n caller,\n showConfig: showConfigPath === filename,\n };\n\n const configChain = yield* buildRootChain(args, context);\n if (!configChain) return null;\n\n const merged: ValidatedOptions = {\n assumptions: {},\n };\n configChain.options.forEach(opts => {\n mergeOptions(merged as any, opts);\n });\n\n const options: NormalizedOptions = {\n ...merged,\n targets: resolveTargets(merged, absoluteRootDir),\n\n // Tack the passes onto the object itself so that, if this object is\n // passed back to Babel a second time, it will be in the right structure\n // to not change behavior.\n cloneInputAst,\n babelrc: false,\n configFile: false,\n browserslistConfigFile: false,\n passPerPreset: false,\n envName: context.envName,\n cwd: context.cwd,\n root: context.root,\n rootMode: \"root\",\n filename:\n typeof context.filename === \"string\" ? context.filename : undefined,\n\n plugins: configChain.plugins.map(descriptor =>\n createItemFromDescriptor(descriptor),\n ),\n presets: configChain.presets.map(descriptor =>\n createItemFromDescriptor(descriptor),\n ),\n };\n\n return {\n options,\n context,\n fileHandling: configChain.fileHandling,\n ignore: configChain.ignore,\n babelrc: configChain.babelrc,\n config: configChain.config,\n files: configChain.files,\n };\n}\n\ntype LoadPartialConfigOpts = {\n showIgnoredFiles?: boolean;\n};\n\nexport function* loadPartialConfig(\n opts?: LoadPartialConfigOpts,\n): Handler {\n let showIgnoredFiles = false;\n // We only extract showIgnoredFiles if opts is an object, so that\n // loadPrivatePartialConfig can throw the appropriate error if it's not.\n if (typeof opts === \"object\" && opts !== null && !Array.isArray(opts)) {\n ({ showIgnoredFiles, ...opts } = opts);\n }\n\n const result: PrivPartialConfig | undefined | null =\n yield* loadPrivatePartialConfig(opts);\n if (!result) return null;\n\n const { options, babelrc, ignore, config, fileHandling, files } = result;\n\n if (fileHandling === \"ignored\" && !showIgnoredFiles) {\n return null;\n }\n\n (options.plugins || []).forEach(item => {\n // @ts-expect-error todo(flow->ts): better type annotation for `item.value`\n if (item.value instanceof Plugin) {\n throw new Error(\n \"Passing cached plugin instances is not supported in \" +\n \"babel.loadPartialConfig()\",\n );\n }\n });\n\n return new PartialConfig(\n options,\n babelrc ? babelrc.filepath : undefined,\n ignore ? ignore.filepath : undefined,\n config ? config.filepath : undefined,\n fileHandling,\n files,\n );\n}\n\nexport type { PartialConfig };\n\nclass PartialConfig {\n /**\n * These properties are public, so any changes to them should be considered\n * a breaking change to Babel's API.\n */\n options: NormalizedOptions;\n babelrc: string | void;\n babelignore: string | void;\n config: string | void;\n fileHandling: FileHandling;\n files: Set;\n\n constructor(\n options: NormalizedOptions,\n babelrc: string | void,\n ignore: string | void,\n config: string | void,\n fileHandling: FileHandling,\n files: Set,\n ) {\n this.options = options;\n this.babelignore = ignore;\n this.babelrc = babelrc;\n this.config = config;\n this.fileHandling = fileHandling;\n this.files = files;\n\n // Freeze since this is a public API and it should be extremely obvious that\n // reassigning properties on here does nothing.\n Object.freeze(this);\n }\n\n /**\n * Returns true if there is a config file in the filesystem for this config.\n */\n hasFilesystemConfig(): boolean {\n return this.babelrc !== undefined || this.config !== undefined;\n }\n}\nObject.freeze(PartialConfig.prototype);\n"],"mappings":";;;;;;;AAAA,SAAAA,MAAA;EAAA,MAAAC,IAAA,GAAAC,OAAA;EAAAF,KAAA,YAAAA,CAAA;IAAA,OAAAC,IAAA;EAAA;EAAA,OAAAA,IAAA;AAAA;AAEA,IAAAE,OAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAEA,IAAAK,YAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAQA,IAAAO,MAAA,GAAAP,OAAA;AAMA,IAAAQ,eAAA,GAAAR,OAAA;AAAsD,MAAAS,SAAA;AAAA,SAAAC,8BAAAC,MAAA,EAAAC,QAAA,QAAAD,MAAA,yBAAAE,MAAA,WAAAC,UAAA,GAAAC,MAAA,CAAAC,IAAA,CAAAL,MAAA,OAAAM,GAAA,EAAAC,CAAA,OAAAA,CAAA,MAAAA,CAAA,GAAAJ,UAAA,CAAAK,MAAA,EAAAD,CAAA,MAAAD,GAAA,GAAAH,UAAA,CAAAI,CAAA,OAAAN,QAAA,CAAAQ,OAAA,CAAAH,GAAA,kBAAAJ,MAAA,CAAAI,GAAA,IAAAN,MAAA,CAAAM,GAAA,YAAAJ,MAAA;AAEtD,SAASQ,eAAeA,CAACC,OAAe,EAAEC,QAAkB,EAAU;EACpE,QAAQA,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