mirror of
https://gitcode.com/github-mirrors/react-native-update-cli.git
synced 2025-10-30 22:33:11 +08:00
26
src/utils/dep-versions.ts
Normal file
26
src/utils/dep-versions.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
const currentPackage = require(`${process.cwd()}/package.json`);
|
||||
|
||||
const depKeys = Object.keys(currentPackage.dependencies);
|
||||
const devDepKeys = Object.keys(currentPackage.devDependencies);
|
||||
const dedupedDeps = [...new Set([...depKeys, ...devDepKeys])];
|
||||
|
||||
const _depVersions: Record<string, string> = {};
|
||||
|
||||
for (const dep of dedupedDeps) {
|
||||
try {
|
||||
const packageJsonPath = require.resolve(`${dep}/package.json`, {
|
||||
paths: [process.cwd()],
|
||||
});
|
||||
const version = require(packageJsonPath).version;
|
||||
_depVersions[dep] = version;
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
export const depVersions = Object.keys(_depVersions)
|
||||
.sort() // Sort the keys alphabetically
|
||||
.reduce((obj, key) => {
|
||||
obj[key] = _depVersions[key]; // Rebuild the object with sorted keys
|
||||
return obj;
|
||||
}, {} as Record<string, string>);
|
||||
|
||||
// console.log({ depVersions });
|
||||
@@ -10,6 +10,7 @@ import { checkPlugins } from './check-plugin';
|
||||
|
||||
import { read } from 'read';
|
||||
import { tempDir } from './constants';
|
||||
import { depVersions } from './dep-versions';
|
||||
|
||||
export async function question(query: string, password?: boolean) {
|
||||
if (NO_INTERACTIVE) {
|
||||
@@ -38,26 +39,6 @@ export function translateOptions(options: Record<string, string>) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
export function getRNVersion() {
|
||||
const version = JSON.parse(
|
||||
fs
|
||||
.readFileSync(
|
||||
require.resolve('react-native/package.json', {
|
||||
paths: [process.cwd()],
|
||||
}),
|
||||
)
|
||||
.toString(),
|
||||
).version;
|
||||
|
||||
const [, major, minor] = /^(\d+)\.(\d+)\./.exec(version) || [];
|
||||
|
||||
return {
|
||||
version,
|
||||
major: Number(major),
|
||||
minor: Number(minor),
|
||||
};
|
||||
}
|
||||
|
||||
export async function getApkInfo(fn: string) {
|
||||
const appInfoParser = new AppInfoParser(fn);
|
||||
const bundleFile = await appInfoParser.parser.getEntry(
|
||||
@@ -198,21 +179,11 @@ export async function printVersionCommand() {
|
||||
`react-native-update-cli: ${pkg.version}${latestPushyCliVersion}`,
|
||||
);
|
||||
let pushyVersion = '';
|
||||
try {
|
||||
const PACKAGE_JSON_PATH = require.resolve(
|
||||
'react-native-update/package.json',
|
||||
{
|
||||
paths: [process.cwd()],
|
||||
},
|
||||
);
|
||||
pushyVersion = require(PACKAGE_JSON_PATH).version;
|
||||
latestPushyVersion = latestPushyVersion
|
||||
? ` (最新:${chalk.green(latestPushyVersion)})`
|
||||
: '';
|
||||
console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
|
||||
} catch (e) {
|
||||
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
|
||||
}
|
||||
pushyVersion = depVersions['react-native-update'];
|
||||
latestPushyVersion = latestPushyVersion
|
||||
? ` (最新:${chalk.green(latestPushyVersion)})`
|
||||
: '';
|
||||
console.log(`react-native-update: ${pushyVersion}${latestPushyVersion}`);
|
||||
if (pushyVersion) {
|
||||
if (semverSatisfies(pushyVersion, '<8.5.2')) {
|
||||
console.warn(
|
||||
@@ -229,6 +200,8 @@ export async function printVersionCommand() {
|
||||
'当前版本已不再支持,请升级到 v10 的最新小版本(代码无需改动,可直接热更): npm i react-native-update@10',
|
||||
);
|
||||
}
|
||||
} else {
|
||||
console.log('react-native-update: 无法获取版本号,请在项目目录中运行命令');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
24
src/utils/lock-checker.ts
Normal file
24
src/utils/lock-checker.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
const lockFiles = [
|
||||
'package-lock.json',
|
||||
'yarn.lock',
|
||||
'pnpm-lock.yaml',
|
||||
'bun.lockb',
|
||||
'bun.lock',
|
||||
];
|
||||
|
||||
const lockNotFound = `
|
||||
没有检测到任何 lock 文件,这可能导致依赖关系不一致而使热更异常。
|
||||
`;
|
||||
|
||||
const multipleLocksFound = `
|
||||
检测到多个锁文件(),这可能导致依赖关系不一致而使热更异常。
|
||||
`;
|
||||
|
||||
|
||||
const lockBestPractice = `
|
||||
关于 lock 文件的最佳实践:
|
||||
1. 开发团队中的所有成员应该使用相同的包管理器,维护同一份 lock 文件。
|
||||
2. 将 lock 文件添加到版本控制中(但不要同时提交多种不同格式的 lock 文件)。
|
||||
3. 代码审核时应关注 lock 文件的变化。
|
||||
这样可以最大限度避免因依赖关系不一致而导致的热更异常,也降低供应链攻击等安全隐患。
|
||||
`;
|
||||
Reference in New Issue
Block a user