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,CAAC,CAAA;IACjE,IAAI,aAAa,IAAI,IAAI,EAAE;QACzB,IAAA,yBAAU,EAAC,eAAe,EAAE,aAAa,CAAC,CAAA;KAC3C;IAED,oEAAoE;IACpE,MAAM,uBAAuB,GAAG,kBAAkB,CAAC,eAAe,EAAE;QAClE,MAAM,EAAE,IAAI;QACZ,sBAAsB;QACtB,uBAAuB;KACxB,CAAC,CAAA;IACF,IAAI,uBAAuB,IAAI,IAAI,EAAE;QACnC,OAAO,uBAAuB,CAAA;KAC/B;SAAM,IAAI,aAAa,IAAI,IAAI,EAAE;QAChC,OAAO,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC,CAAA;KAChD;IACD,OAAO,IAAI,CAAA;AACb,CAAC","sourcesContent":["import { debug, log, deepAssign } from \"builder-util\"\nimport { FileTransformer } from \"builder-util/out/fs\"\nimport { readFile } from \"fs/promises\"\nimport * as path from \"path\"\nimport { Configuration } from \"./configuration\"\nimport { Packager } from \"./packager\"\n\n/** @internal */\nexport const NODE_MODULES_PATTERN = `${path.sep}node_modules${path.sep}`\n\n/** @internal */\nexport function isElectronCompileUsed(info: Packager): boolean {\n if (info.config.electronCompile != null) {\n return info.config.electronCompile\n }\n\n // if in devDependencies - it means that babel is used for precompilation or for some reason user decided to not use electron-compile for production\n return hasDep(\"electron-compile\", info)\n}\n\n/** @internal */\nexport function hasDep(name: string, info: Packager) {\n const deps = info.metadata.dependencies\n return deps != null && name in deps\n}\n\n/** @internal */\nexport function createTransformer(srcDir: string, configuration: Configuration, extraMetadata: any, extraTransformer: FileTransformer | null): FileTransformer {\n const mainPackageJson = path.join(srcDir, \"package.json\")\n const isRemovePackageScripts = configuration.removePackageScripts !== false\n const isRemovePackageKeywords = configuration.removePackageKeywords !== false\n const packageJson = path.sep + \"package.json\"\n return file => {\n if (file === mainPackageJson) {\n return modifyMainPackageJson(file, extraMetadata, isRemovePackageScripts, isRemovePackageKeywords)\n }\n\n if (file.endsWith(packageJson) && file.includes(NODE_MODULES_PATTERN)) {\n return readFile(file, \"utf-8\")\n .then(it =>\n cleanupPackageJson(JSON.parse(it), {\n isMain: false,\n isRemovePackageScripts,\n isRemovePackageKeywords,\n })\n )\n .catch((e: any) => log.warn(e))\n } else if (extraTransformer != null) {\n return extraTransformer(file)\n } else {\n return null\n }\n }\n}\n\n/** @internal */\nexport interface CompilerHost {\n compile(file: string): any\n\n saveConfiguration(): Promise<any>\n}\n\n/** @internal */\nexport function createElectronCompilerHost(projectDir: string, cacheDir: string): Promise<CompilerHost> {\n const electronCompilePath = path.join(projectDir, \"node_modules\", \"electron-compile\", \"lib\")\n return require(path.join(electronCompilePath, \"config-parser\")).createCompilerHostFromProjectRoot(projectDir, cacheDir)\n}\n\nconst ignoredPackageMetadataProperties = new Set([\"dist\", \"gitHead\", \"build\", \"jspm\", \"ava\", \"xo\", \"nyc\", \"eslintConfig\", \"contributors\", \"bundleDependencies\", \"tags\"])\n\ninterface CleanupPackageFileOptions {\n readonly isRemovePackageScripts: boolean\n readonly isRemovePackageKeywords: boolean\n readonly isMain: boolean\n}\n\nfunction cleanupPackageJson(data: any, options: CleanupPackageFileOptions): any {\n const deps = data.dependencies\n // https://github.com/electron-userland/electron-builder/issues/507#issuecomment-312772099\n const isRemoveBabel = deps != null && typeof deps === \"object\" && !Object.getOwnPropertyNames(deps).some(it => it.startsWith(\"babel\"))\n try {\n let changed = false\n for (const prop of Object.getOwnPropertyNames(data)) {\n // removing devDependencies from package.json breaks levelup in electron, so, remove it only from main package.json\n if (\n prop[0] === \"_\" ||\n ignoredPackageMetadataProperties.has(prop) ||\n (options.isRemovePackageScripts && prop === \"scripts\") ||\n (options.isRemovePackageKeywords && prop === \"keywords\") ||\n (options.isMain && prop === \"devDependencies\") ||\n (!options.isMain && prop === \"bugs\") ||\n (isRemoveBabel && prop === \"babel\")\n ) {\n delete data[prop]\n changed = true\n }\n }\n\n if (changed) {\n return JSON.stringify(data, null, 2)\n }\n } catch (e: any) {\n debug(e)\n }\n\n return null\n}\n\nasync function modifyMainPackageJson(file: string, extraMetadata: any, isRemovePackageScripts: boolean, isRemovePackageKeywords: boolean) {\n const mainPackageData = JSON.parse(await readFile(file, \"utf-8\"))\n if (extraMetadata != null) {\n deepAssign(mainPackageData, extraMetadata)\n }\n\n // https://github.com/electron-userland/electron-builder/issues/1212\n const serializedDataIfChanged = cleanupPackageJson(mainPackageData, {\n isMain: true,\n isRemovePackageScripts,\n isRemovePackageKeywords,\n })\n if (serializedDataIfChanged != null) {\n return serializedDataIfChanged\n } else if (extraMetadata != null) {\n return JSON.stringify(mainPackageData, null, 2)\n }\n return null\n}\n"]}