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,YAAY,EAAE,UAAU,EAAE,EAAE,4FAA4F,CAAC,CAAA;SACrI;QACD,OAAO,YAAY,CAAA;KACpB;IAED,KAAK,MAAM,GAAG,IAAI,qBAAqB,EAAE;QACvC,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;QAC/C,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,cAAc,CAAC,CAAA;QAC3D,MAAM,IAAI,GAAG,MAAM,eAAU,CAAC,WAAW,CAAC,CAAA;QAC1C,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,EAAE;YACjC,OAAO,YAAY,CAAA;SACpB;KACF;IACD,OAAO,UAAU,CAAA;AACnB,CAAC;AAvBD,gEAuBC","sourcesContent":["import { DebugLogger, deepAssign, InvalidConfigurationError, log, safeStringifyJson } from \"builder-util\"\nimport { statOrNull } from \"builder-util/out/fs\"\nimport { readJson } from \"fs-extra\"\nimport { Lazy } from \"lazy-val\"\nimport * as path from \"path\"\nimport { getConfig as _getConfig, loadParentConfig, orNullIfFileNotExist, ReadConfigRequest } from \"read-config-file\"\nimport { Configuration } from \"../configuration\"\nimport { FileSet } from \"../options/PlatformSpecificBuildOptions\"\nimport { reactCra } from \"../presets/rectCra\"\nimport { PACKAGE_VERSION } from \"../version\"\n// eslint-disable-next-line @typescript-eslint/no-var-requires\nconst validateSchema = require(\"@develar/schema-utils\")\n\n// https://github.com/electron-userland/electron-builder/issues/1847\nfunction mergePublish(config: Configuration, configFromOptions: Configuration) {\n // if config from disk doesn't have publish (or object), no need to handle, it will be simply merged by deepAssign\n const publish = Array.isArray(config.publish) ? configFromOptions.publish : null\n if (publish != null) {\n delete (configFromOptions as any).publish\n }\n\n deepAssign(config, configFromOptions)\n\n if (publish == null) {\n return\n }\n\n const listOnDisk = config.publish as Array<any>\n if (listOnDisk.length === 0) {\n config.publish = publish\n } else {\n // apply to first\n Object.assign(listOnDisk[0], publish)\n }\n}\n\nexport async function getConfig(\n projectDir: string,\n configPath: string | null,\n configFromOptions: Configuration | null | undefined,\n packageMetadata: Lazy<{ [key: string]: any } | null> = new Lazy(() => orNullIfFileNotExist(readJson(path.join(projectDir, \"package.json\"))))\n): Promise<Configuration> {\n const configRequest: ReadConfigRequest = { packageKey: \"build\", configFilename: \"electron-builder\", projectDir, packageMetadata }\n const configAndEffectiveFile = await _getConfig<Configuration>(configRequest, configPath)\n const config = configAndEffectiveFile == null ? {} : configAndEffectiveFile.result\n if (configFromOptions != null) {\n mergePublish(config, configFromOptions)\n }\n\n if (configAndEffectiveFile != null) {\n log.info({ file: configAndEffectiveFile.configFile == null ? 'package.json (\"build\" field)' : configAndEffectiveFile.configFile }, \"loaded configuration\")\n }\n\n if (config.extends == null && config.extends !== null) {\n const metadata = (await packageMetadata.value) || {}\n const devDependencies = metadata.devDependencies\n const dependencies = metadata.dependencies\n if ((dependencies != null && \"react-scripts\" in dependencies) || (devDependencies != null && \"react-scripts\" in devDependencies)) {\n config.extends = \"react-cra\"\n } else if (devDependencies != null && \"electron-webpack\" in devDependencies) {\n let file = \"electron-webpack/out/electron-builder.js\"\n try {\n file = require.resolve(file)\n } catch (ignore) {\n file = require.resolve(\"electron-webpack/electron-builder.yml\")\n }\n config.extends = `file:${file}`\n }\n }\n\n const parentConfigs = await loadParentConfigsRecursively(config.extends, async configExtend => {\n if (configExtend === \"react-cra\") {\n const result = await reactCra(projectDir)\n log.info({ preset: configExtend }, \"loaded parent configuration\")\n return result\n } else {\n const { configFile, result } = await loadParentConfig<Configuration>(configRequest, configExtend)\n log.info({ file: configFile }, \"loaded parent configuration\")\n return result\n }\n })\n\n return doMergeConfigs([...parentConfigs, config])\n}\n\nfunction asArray(value: string[] | string | undefined | null): string[] {\n return Array.isArray(value) ? value : typeof value === \"string\" ? [value] : []\n}\n\nasync function loadParentConfigsRecursively(configExtends: Configuration[\"extends\"], loader: (configExtend: string) => Promise<Configuration>): Promise<Configuration[]> {\n const configs = []\n\n for (const configExtend of asArray(configExtends)) {\n const result = await loader(configExtend)\n const parentConfigs = await loadParentConfigsRecursively(result.extends, loader)\n configs.push(...parentConfigs, result)\n }\n\n return configs\n}\n\n// normalize for easy merge\nfunction normalizeFiles(configuration: Configuration, name: \"files\" | \"extraFiles\" | \"extraResources\") {\n let value = configuration[name]\n if (value == null) {\n return\n }\n\n if (!Array.isArray(value)) {\n value = [value]\n }\n\n itemLoop: for (let i = 0; i < value.length; i++) {\n let item = value[i]\n if (typeof item === \"string\") {\n // merge with previous if possible\n if (i !== 0) {\n let prevItemIndex = i - 1\n let prevItem: FileSet\n do {\n prevItem = value[prevItemIndex--] as FileSet\n } while (prevItem == null)\n\n if (prevItem.from == null && prevItem.to == null) {\n if (prevItem.filter == null) {\n prevItem.filter = [item]\n } else {\n ;(prevItem.filter as Array<string>).push(item)\n }\n value[i] = null as any\n continue itemLoop\n }\n }\n\n item = {\n filter: [item],\n }\n value[i] = item\n } else if (Array.isArray(item)) {\n throw new Error(`${name} configuration is invalid, nested array not expected for index ${i}: ${item}`)\n }\n\n // make sure that merge logic is not complex - unify different presentations\n if (item.from === \".\") {\n item.from = undefined\n }\n\n if (item.to === \".\") {\n item.to = undefined\n }\n\n if (item.filter != null && typeof item.filter === \"string\") {\n item.filter = [item.filter]\n }\n }\n\n configuration[name] = value.filter(it => it != null)\n}\n\nfunction isSimilarFileSet(value: FileSet, other: FileSet): boolean {\n return value.from === other.from && value.to === other.to\n}\n\ntype Filter = FileSet[\"filter\"]\n\nfunction mergeFilters(value: Filter, other: Filter): string[] {\n return asArray(value).concat(asArray(other))\n}\n\nfunction mergeFileSets(lists: FileSet[][]): FileSet[] {\n const result = []\n\n for (const list of lists) {\n for (const item of list) {\n const existingItem = result.find(i => isSimilarFileSet(i, item))\n if (existingItem) {\n existingItem.filter = mergeFilters(item.filter, existingItem.filter)\n } else {\n result.push(item)\n }\n }\n }\n\n return result\n}\n\n/**\n * `doMergeConfigs` takes configs in the order you would pass them to\n * Object.assign as sources.\n */\nexport function doMergeConfigs(configs: Configuration[]): Configuration {\n for (const config of configs) {\n normalizeFiles(config, \"files\")\n normalizeFiles(config, \"extraFiles\")\n normalizeFiles(config, \"extraResources\")\n }\n\n const result = deepAssign(getDefaultConfig(), ...configs)\n\n // `deepAssign` prioritises latter configs, while `mergeFilesSets` prioritises\n // former configs, so we have to reverse the order, because latter configs\n // must have higher priority.\n configs = configs.slice().reverse()\n\n result.files = mergeFileSets(configs.map(config => (config.files ?? []) as FileSet[]))\n return result\n}\n\nfunction getDefaultConfig(): Configuration {\n return {\n directories: {\n output: \"dist\",\n buildResources: \"build\",\n },\n }\n}\n\nconst schemeDataPromise = new Lazy(() => readJson(path.join(__dirname, \"..\", \"..\", \"scheme.json\")))\n\nexport async function validateConfig(config: Configuration, debugLogger: DebugLogger) {\n const extraMetadata = config.extraMetadata\n if (extraMetadata != null) {\n if (extraMetadata.build != null) {\n throw new InvalidConfigurationError(`--em.build is deprecated, please specify as -c\"`)\n }\n if (extraMetadata.directories != null) {\n throw new InvalidConfigurationError(`--em.directories is deprecated, please specify as -c.directories\"`)\n }\n }\n\n const oldConfig: any = config\n if (oldConfig.npmSkipBuildFromSource === false) {\n throw new InvalidConfigurationError(`npmSkipBuildFromSource is deprecated, please use buildDependenciesFromSource\"`)\n }\n if (oldConfig.appImage != null && oldConfig.appImage.systemIntegration != null) {\n throw new InvalidConfigurationError(`appImage.systemIntegration is deprecated, https://github.com/TheAssassin/AppImageLauncher is used for desktop integration\"`)\n }\n\n // noinspection JSUnusedGlobalSymbols\n validateSchema(await schemeDataPromise.value, config, {\n name: `electron-builder ${PACKAGE_VERSION}`,\n postFormatter: (formattedError: string, error: any): string => {\n if (debugLogger.isEnabled) {\n debugLogger.add(\"invalidConfig\", safeStringifyJson(error))\n }\n\n const site = \"https://www.electron.build\"\n let url = `${site}/configuration/configuration`\n const targets = new Set([\"mac\", \"dmg\", \"pkg\", \"mas\", \"win\", \"nsis\", \"appx\", \"linux\", \"appimage\", \"snap\"])\n const dataPath: string = error.dataPath == null ? null : error.dataPath\n const targetPath = dataPath.startsWith(\".\") ? dataPath.substr(1).toLowerCase() : null\n if (targetPath != null && targets.has(targetPath)) {\n url = `${site}/configuration/${targetPath}`\n }\n\n return `${formattedError}\\n How to fix:\n 1. Open ${url}\n 2. Search the option name on the page (or type in into Search to find across the docs).\n * Not found? The option was deprecated or not exists (check spelling).\n * Found? Check that the option in the appropriate place. e.g. \"title\" only in the \"dmg\", not in the root.\n`\n },\n })\n}\n\nconst DEFAULT_APP_DIR_NAMES = [\"app\", \"www\"]\n\nexport async function computeDefaultAppDirectory(projectDir: string, userAppDir: string | null | undefined): Promise<string> {\n if (userAppDir != null) {\n const absolutePath = path.resolve(projectDir, userAppDir)\n const stat = await statOrNull(absolutePath)\n if (stat == null) {\n throw new InvalidConfigurationError(`Application directory ${userAppDir} doesn't exist`)\n } else if (!stat.isDirectory()) {\n throw new InvalidConfigurationError(`Application directory ${userAppDir} is not a directory`)\n } else if (projectDir === absolutePath) {\n log.warn({ appDirectory: userAppDir }, `Specified application directory equals to project dir — superfluous or wrong configuration`)\n }\n return absolutePath\n }\n\n for (const dir of DEFAULT_APP_DIR_NAMES) {\n const absolutePath = path.join(projectDir, dir)\n const packageJson = path.join(absolutePath, \"package.json\")\n const stat = await statOrNull(packageJson)\n if (stat != null && stat.isFile()) {\n return absolutePath\n }\n }\n return projectDir\n}\n"]}
\No newline at end of file