onnxruntime/js/react_native/scripts/prepack.ts
Yulong Wang cdf3e9dba9
[js] update prepack script to use exact version (#17484)
### Description
update prepack script to use exact version.

the prepack script for onnxruntime-node, onnxruntime-web and
onnxruntime-react-native is used to update their referencing version of
dependency "onnxruntime-common".

Previously "~" (tilde symbol) is used. This may cause NPM choose an
older version (if the old version matches the version requirement and
was previously installed already so hit the cache). see also
https://semver.npmjs.com/. [This
build](https://dev.azure.com/onnxruntime/onnxruntime/_build/results?buildId=1134671&view=results)
is caused by this issue.
2023-09-13 00:07:16 -07:00

28 lines
1.2 KiB
TypeScript

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import * as fs from 'fs-extra';
import * as path from 'path';
import * as process from 'process';
function updatePackageJson() {
const commonPackageJsonPath = path.join(__dirname, '..', '..', 'common', 'package.json');
const selfPackageJsonPath = path.join(__dirname, '..', 'package.json');
console.log(`=== start to update package.json: ${selfPackageJsonPath}`);
const packageCommon = fs.readJSONSync(commonPackageJsonPath);
const packageSelf = fs.readJSONSync(selfPackageJsonPath);
if (process.env.npm_config_ort_js_pack_mode === 'e2e' || process.env.ORT_JS_PACK_MODE === 'e2e') {
// for E2E testing mode, we remove "onnxruntime-common" as a dependency.
// we do this because yarn cannot resolve it with an unpublished version.
delete packageSelf.dependencies['onnxruntime-common'];
} else {
const version = packageCommon.version;
packageSelf.dependencies['onnxruntime-common'] = `${version}`;
}
fs.writeJSONSync(selfPackageJsonPath, packageSelf, {spaces: 2});
console.log('=== finished updating package.json.');
}
// update version of dependency "onnxruntime-common" before packing
updatePackageJson();