Files
react-native/scripts/update-template-package.js
T
Luna Wei f322dc7a84 Typing scripts used for test-e2e-local (#42610)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42610

Changelog: [Internal] Adding more typing to internal scripts used by test-e2e-local

Reviewed By: NickGerleman

Differential Revision: D52988733

fbshipit-source-id: 6e187b7c9560b30def014e8932ab82ed07cf8488
2024-01-24 15:39:06 -08:00

57 lines
1.4 KiB
JavaScript
Executable File

/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
const {applyPackageVersions} = require('./npm-utils');
const fs = require('fs');
const path = require('path');
/**
* Updates the react-native template package.json with
* dependencies in `dependencyMap`.
*
* `dependencyMap` is a dict of package name to its version
* ex. {"react-native": "0.23.0", "other-dep": "nightly"}
*/
function updateTemplatePackage(dependencyMap /*: {[string]: string} */) {
const jsonPath = path.join(
__dirname,
'../packages/react-native/template/package.json',
);
// $FlowIgnore[unsupported-syntax]
const templatePackageJson = require(jsonPath);
const updatedPackageJson = applyPackageVersions(
templatePackageJson,
dependencyMap,
);
fs.writeFileSync(
jsonPath,
JSON.stringify(updatedPackageJson, null, 2) + '\n',
'utf-8',
);
}
if (require.main === module) {
const dependencyMapStr = process.argv[2];
if (!dependencyMapStr) {
console.error(
'Please provide a json string of package name and their version. Ex. \'{"packageName":"0.23.0"}\'',
);
process.exit(1);
}
updateTemplatePackage(JSON.parse(dependencyMapStr));
}
module.exports = updateTemplatePackage;