INNER CODE UNIT · JavaScript
syncOhPackageVersion
reactnativecn/react-native-update · scripts/build-harmony-har.js:194
function syncOhPackageVersion() {
const packageJsonPath = path.join(projectRoot, 'package.json');
const ohPackagePath = path.join(harmonyModuleDir, 'oh-package.json5');
const version = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')).version;
if (typeof version !== 'string' || !version) {
fail('package.json has no version to write into oh-package.json5');
}
const content = fs.readFileSync(ohPackagePath, 'utf8');
// JSON5 allows the key bare or quoted (check-release-version.js matches
// the same shapes).
const versionLine =
/^(\s*(?:"version"|'version'|version)\s*:\s*)(['"])([^'"]*)\2(\s*,?)/m;
const match = content.match(versionLine);
if (!match) {
fail(
`Cannot find a version field in ${relativeToProject(ohPackagePath)}`
);
}