While there are write operations in this, other write operations may need to examine the composer.json to determine their own configuration.
348535
function () {
      var isNewProject = (this.composerOrig == undefined);
      if (!isNewProject) {
        // Use original composer file if project already generated.
        this.composer = this.composerOrig;
      }

      this.composer.name = 'organization/' + options.projectName;
      this.composer.description = options.projectDescription;
      // Allow distros to modify the composer.json.
      if (typeof options.drupalDistro.modifyComposer == 'function') {
        var done = this.async();
        options.drupalDistro.modifyComposer(options, this.composer, isNewProject, done, function(err, result, done) {
          if (!err && result) {
            this.composer = result;
          }
          else {
            this.log.warning("Could not retrieve Octane's composer.json: "  + err);
            return done(err);
          }
          done();
        }.bind(this));
      }
    }
974876
public function removeComposerScript($script_key) {
    $composer_json = $this->getComposerJson();
    if (!empty($composer_json['scripts'])) {
      foreach ($composer_json['scripts'] as $key => $script) {
        if ($script_key == $key) {
          unset($composer_json['scripts'][$key]);
          $this->writeComposerJson($composer_json);

          return TRUE;
        }
      }
    }
    return FALSE;
  }
658050
protected function setComposerNamespace()
    {
        if (file_exists($this->addon->path('composer.json'))) {
            $this->replaceIn(
                $this->addon->path('composer.json'), $this->currentNamespace.'\\\\', str_replace('\\', '\\\\', $this->newNamespace).'\\\\'
            );
        }
    }
348832
public function configure(Composer $composer, IOInterface $io)
    {
        $this->composer = $composer;
        $this->jsonFile = null;
        $this->io = $io;
        
        $publicDirectorySet = $this->isPublicDirectorySet();
        $wordPressInstallDirectorySet = $this->isWordPressInstallDirectorySet();
        $reposConfigured = $this->areReposConfigured();
        $sortingConfigured = $this->isSortingConfigured();
        
        if ($publicDirectorySet && $wordPressInstallDirectorySet && $reposConfigured && $sortingConfigured) {
            return;
        }
        
        if (! $publicDirectorySet) {
            $this->setPublicDirectory();
        }
        
        if (! $wordPressInstallDirectorySet) {
            $this->setWordPressInstallDirectory();
        }
        
        if (! $reposConfigured) {
            $this->configureRepos();
        }
        
        if (! $sortingConfigured) {
            $this->configureSorting();
        }
        
        $this->sortProperties();
        $this->saveJson();
    }
1289133
private function setup()
    {
        if ($this->started) {
            return;
        }

        if ($this->app['extend.writeable']) {
            // Do required JSON update/set up
            try {
                $this->updateJson();
            } catch (ParseException $e) {
                $this->app['logger.flash']->danger(Trans::__('Error reading extensions/composer.json file: %ERROR%', ['%ERROR%' => $e->getMessage()]));
                $this->started = false;

                return;
            }
        }

        $this->started = true;
    }
1251639
public function build()
    {
        $packages = [];

        if (file_exists($installed = $this->vendorPath.'/composer/installed.json')) {
            $packages = json_decode(file_get_contents($installed), true);
        }

        $this->write($this->map($packages));
    }
691386
public function update_8006006() {
    $composer_json = $this->updater->getComposerJson();
    unset($composer_json['require-dev']['drush/drush']);
    $this->updater->writeComposerJson($composer_json);
  }
275242
protected function updateComposerJson(array $requires, array $devRequires, int $type): void
    {
        $this->io->writeError('Updating composer.json');

        if ($type === self::ADD) {
            $jsonManipulator = new JsonManipulator(\file_get_contents($this->jsonFile->getPath()));
            $sortPackages    = $this->composer->getConfig()->get('sort-packages') ?? false;

            foreach ($requires as $name => $version) {
                $jsonManipulator->addLink('require', $name, $version, $sortPackages);
            }

            foreach ($devRequires as $name => $version) {
                $jsonManipulator->addLink('require-dev', $name, $version, $sortPackages);
            }

            \file_put_contents($this->jsonFile->getPath(), $jsonManipulator->getContents());
        } elseif ($type === self::REMOVE) {
            $jsonFileContent = $this->jsonFile->read();

            foreach ($requires as $packageName => $version) {
                unset($jsonFileContent['require'][$packageName]);
            }

            foreach ($devRequires as $packageName => $version) {
                unset($jsonFileContent['require-dev'][$packageName]);
            }

            $this->jsonFile->write($jsonFileContent);
        }
    }
1077775
async function composeConfig() {
    const { LUIS_APP_ID, LUIS_AUTHORING_KEY, LUIS_VERSION_ID, LUIS_REGION } = process.env;

    const {
        appId: args_appId,
        authoringKey: args_authoringKey,
        versionId: args_versionId,
        region: args_region
    } = args;

    let luisrcJson = {};
    let config;
    try {
        await fs.access(path.join(process.cwd(), '.luisrc'), fs.R_OK);
        luisrcJson = JSON.parse(await txtfile.read(path.join(process.cwd(), '.luisrc')));
    } catch (e) {
        // Do nothing
    } finally {
        config = {
            appId: (args_appId || luisrcJson.appId || LUIS_APP_ID),
            authoringKey: (args_authoringKey || luisrcJson.authoringKey || LUIS_AUTHORING_KEY),
            versionId: (args_versionId || luisrcJson.versionId || LUIS_VERSION_ID),
            region: (args_region || luisrcJson.region || LUIS_REGION)
        };
    }
    return config;
}
1156090
private function mayInstall()
    {
        $destinationDir = $this->file->get(self::SETTING_DESTINATION_DIR) . DIRECTORY_SEPARATOR;

        return !(file_exists($destinationDir . 'composer.json'));
    }
861220
private static function getInstalledComposerJson()
    {
        $finder = new Finder();
        $finder->files()
            ->name('composer.json')
            ->notPath('vendor/composer')
            ->depth(2)
            ->followLinks()
        ;
        try {
            $finder->in(['vendor']);
        } catch (\InvalidArgumentException $e) {
            // Composer has not had its autoloader dumped
        }

        return $finder;
    }
491788
private boolean isValid(TransactionWrite write, AdvancedCache<byte[], byte[]> readCache) {
      if (write.skipRead()) {
         if (isTrace) {
            log.tracef("Operation %s wasn't read.", write);
         }
         return true;
      }
      CacheEntry<byte[], byte[]> entry = readCache.getCacheEntry(write.key);
      if (write.wasNonExisting()) {
         if (isTrace) {
            log.tracef("Key didn't exist for operation %s. Entry is %s", write, entry);
         }
         return entry == null || entry.getValue() == null;
      }
      if (isTrace) {
         log.tracef("Checking version for operation %s. Entry is %s", write, entry);
      }
      return entry != null && write.versionRead == MetadataUtils.extractVersion(entry);
   }
521260
function(targetOptions, sourceOptions, keys, mergeWriteConcern) {
  // Mix in any allowed options
  for (var i = 0; i < keys.length; i++) {
    if (!targetOptions[keys[i]] && sourceOptions[keys[i]] !== undefined) {
      targetOptions[keys[i]] = sourceOptions[keys[i]];
    }
  }

  // No merging of write concern
  if (!mergeWriteConcern) return targetOptions;

  // Found no write Concern options
  var found = false;
  for (i = 0; i < writeConcernKeys.length; i++) {
    if (targetOptions[writeConcernKeys[i]]) {
      found = true;
      break;
    }
  }

  if (!found) {
    for (i = 0; i < writeConcernKeys.length; i++) {
      if (sourceOptions[writeConcernKeys[i]]) {
        targetOptions[writeConcernKeys[i]] = sourceOptions[writeConcernKeys[i]];
      }
    }
  }

  return targetOptions;
}
19882
function writeConfig(json) {
  if (!skyuxConfigOriginal) {
    skyuxConfigOriginal = JSON.parse(fs.readFileSync(skyuxConfigPath));
  }

  fs.writeFileSync(skyuxConfigPath, JSON.stringify(json), 'utf8');
}
990736
public function write() {
		Log::instance()->write( 'Writing config.', 1 );

		$create_dir = Utils\create_snapshot_directory();

		if ( ! $create_dir ) {
			Log::instance()->write( 'Cannot create necessary snapshot directory.', 0, 'error' );

			return false;
		}

		file_put_contents( Utils\get_snapshot_directory() . 'config.json', json_encode( $this->config, JSON_PRETTY_PRINT ) );
	}
1025476
public function updateFromComposerInfo()
    {
        $this->launchPreInstallActions();
        $operations = $this->operationExecutor->buildOperationList();
        $this->operationExecutor->execute($operations);
    }
599445
private function configureEnv() {
		if ($this->selfEdit) {
			chdir(__DIR__."/../../..");
			\putenv('COMPOSER=composer-mouf.json');
		} else {
			chdir(__DIR__."/../../../../../..");
		}
		
		$composerHome = getenv('COMPOSER_HOME');
		if (!$composerHome) {
			$composerTmpDir = sys_get_temp_dir().'/.mouf_composer/';
			if (function_exists('posix_getpwuid')) {
				$processUser = posix_getpwuid(posix_geteuid());
				$composerTmpDir .= $processUser['name'].'/';
			}
			\putenv('COMPOSER_HOME='.$composerTmpDir);
		}
		
	}