'use strict';
import { readFile } from 'node:fs/promises';
import { stringEncodingNames } from '../../../base-repo/app-constants/internal-system-constants.js';
import { packagesPath, files } from '../../../base-repo/app-constants/project-paths.js';
import { npmPackages } from '../../../base-repo/constants/packages.js';
import { aliasSymbols } from '../../../base-repo/app-constants/aliases.js';
import { environmentVariables, ciLogMessages } from '../constants/ci-constants.js';
import { nxProjects } from '../constants/paths.js';
import { pnpmFlags, npmCommands } from '../constants/npm-commands.js';
import { execSyncCommand } from '../tools/exec.js';
import { pnpmAdd } from '../tools/npm-command-funcs.js';
import { createEarlyInfraError } from '../tools/create-early-infra-error.js';
import { getBooleanEnvSetting } from '../../../fd-toolbox/infra/env-functions.js';
import { logDryRun } from '../jobs/sync-saas-kit-version-to-main.js';
import { cliLogSeparator, cliLogSuccess, cliLogSubtitle, cliLogInfo, cliLogError } from '../../../fd-toolbox/logging/cli-logger.js';

var __defProp=Object['defineProperty'],__name=(_0x37abc6,_0x1b204c)=>__defProp(_0x37abc6,'name',{'value':_0x1b204c,'configurable':!![]});async function updateWorkspaceDependencies(_0x26e765){const _0x293c85=_0x26e765['expectedVersion'],_0x44a4e7=_0x26e765['actualVersion'];if(!_0x293c85)throw createEarlyInfraError('No\x20version\x20provided\x20to\x20sync.');let _0x415776=_0x293c85;const _0x2ff367=getBooleanEnvSetting(environmentVariables['ciPublishAndTestPackageDryRun']);if(_0x2ff367){const _0x3e4427='[DRY\x20RUN]\x20Version\x20to\x20apply\x20swapped\x20from\x20\x27'+_0x293c85+'\x27\x20to\x20actual\x20NPM\x20version\x20\x27'+_0x44a4e7+'\x27\x20to\x20allow\x20full\x20flow\x20execution.';logDryRun(_0x3e4427),cliLogSeparator(),_0x415776=_0x44a4e7;}const _0x3416cc=''+npmPackages['saasKit']+aliasSymbols['atSign']+_0x415776;execSyncCommand(pnpmAdd(_0x3416cc,pnpmFlags['filter']+'\x20'+nxProjects['test'])),cliLogSeparator(),await logJsonContent(packagesPath['testPackageJsonPath']),cliLogSuccess('\x27'+nxProjects['test']+'\x20'+files['packageJson']+ciLogMessages['updatedSuffix']),cliLogSeparator(),execSyncCommand(pnpmAdd(_0x3416cc,pnpmFlags['filter']+'\x20'+nxProjects['ranksters'])),cliLogSeparator();const _0x2142b1=''+packagesPath['packagesRanksters']+files['packageJson'];await logJsonContent(_0x2142b1),cliLogSuccess('\x27'+nxProjects['ranksters']+'\x20'+files['packageJson']+ciLogMessages['updatedSuffix']),cliLogSeparator(),cliLogSubtitle('Re-installing\x20all\x20dependencies\x20to\x20finalize\x20lock\x20file\x20changes...'),execSyncCommand(npmCommands['pnpmInstallFrozen']);}__name(updateWorkspaceDependencies,'updateWorkspaceDependencies');async function logJsonContent(_0x32a8a0){try{const _0x336817=await readFile(_0x32a8a0,stringEncodingNames['utfDash8']);cliLogInfo('Content\x20of\x20'+_0x32a8a0),cliLogInfo(_0x336817);}catch{cliLogError('Failed\x20to\x20read\x20'+_0x32a8a0+'\x20for\x20verification.');}}__name(logJsonContent,'logJsonContent');

export { updateWorkspaceDependencies };
