From d281d727375ff346038ed0090572f57a7104f560 Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Wed, 2 Apr 2025 08:27:05 +0800 Subject: [PATCH] check lockfiles --- package.json | 2 +- src/locales/en.ts | 2 +- src/locales/zh.ts | 2 +- src/utils/add-gitignore.ts | 1 + src/utils/check-lockfile.ts | 15 ++++++++++----- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index f5387ca..5dc1cf9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-update-cli", - "version": "1.42.2", + "version": "1.43.0", "description": "Command tools for javaScript updater with `pushy` service for react native apps.", "main": "index.js", "bin": { diff --git a/src/locales/en.ts b/src/locales/en.ts index fa338a9..56ae6f6 100644 --- a/src/locales/en.ts +++ b/src/locales/en.ts @@ -6,7 +6,7 @@ export default { lockNotFound: 'No lock file detected, which may cause inconsistent dependencies and hot-updating issues.', multipleLocksFound: - 'Multiple lock files detected ({lockFiles}), which may cause inconsistent dependencies and hot-updating issues.', + 'Multiple lock files detected ({{lockFiles}}), which may cause inconsistent dependencies and hot-updating issues.', lockBestPractice: ` Best practices for lock files: 1. All members of the development team should use the same package manager to maintain a single lock file. diff --git a/src/locales/zh.ts b/src/locales/zh.ts index c227df2..57ac392 100644 --- a/src/locales/zh.ts +++ b/src/locales/zh.ts @@ -12,7 +12,7 @@ export default { 这样可以最大限度避免因依赖关系不一致而导致的热更异常,也降低供应链攻击等安全隐患。 `, multipleLocksFound: - '检测到多种不同格式的锁文件({lockFiles}),这可能导致依赖关系不一致而使热更异常。', + '检测到多种不同格式的锁文件({{lockFiles}}),这可能导致依赖关系不一致而使热更异常。', loginExpired: '登录信息已过期,请使用 `pushy login` 命令重新登录', fileSizeExceeded: '此文件大小 {{fileSize}} , 超出当前额度 {{maxSize}} 。您可以考虑升级付费业务以提升此额度。详情请访问: {{pricingPageUrl}}', diff --git a/src/utils/add-gitignore.ts b/src/utils/add-gitignore.ts index 978decf..41e5a82 100644 --- a/src/utils/add-gitignore.ts +++ b/src/utils/add-gitignore.ts @@ -23,6 +23,7 @@ export function addGitIgnore() { } if (shouldIgnore.length > 0) { + gitignoreLines.push('# react-native-update'); for (const line of shouldIgnore) { gitignoreLines.push(line); console.log(`Added ${line} to .gitignore`); diff --git a/src/utils/check-lockfile.ts b/src/utils/check-lockfile.ts index 92f7b9c..5dbe86b 100644 --- a/src/utils/check-lockfile.ts +++ b/src/utils/check-lockfile.ts @@ -1,5 +1,5 @@ import fs from 'node:fs'; -import { t } from '../../lib/utils/i18n'; +import { t } from './i18n'; const lockFiles = [ 'package-lock.json', @@ -16,9 +16,14 @@ export function checkLockFiles() { existingLockFiles.push(file); } } - if (existingLockFiles.length === 0) { - console.warn(t('lockFilesNotFound')); - } else if (existingLockFiles.length > 1) { - console.warn(t('multipleLockFilesFound')); + if (existingLockFiles.length === 1) { + return; } + console.warn(t('lockBestPractice')); + if (existingLockFiles.length === 0) { + throw new Error(t('lockNotFound')); + } + throw new Error( + t('multipleLocksFound', { lockFiles: existingLockFiles.join(', ') }), + ); }