From d351243ab765ca06fc7445686e0d0fe11279b40e Mon Sep 17 00:00:00 2001 From: sunnylqm Date: Tue, 1 Apr 2025 23:24:02 +0800 Subject: [PATCH] check lockfile --- src/bundle.ts | 5 +++++ src/index.ts | 2 -- src/utils/add-gitignore.ts | 6 +++--- src/utils/check-lockfile.ts | 24 ++++++++++++++++++++++++ src/utils/lock-checker.ts | 7 ------- 5 files changed, 32 insertions(+), 12 deletions(-) create mode 100644 src/utils/check-lockfile.ts delete mode 100644 src/utils/lock-checker.ts diff --git a/src/bundle.ts b/src/bundle.ts index cf61a0c..b1f194f 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -13,6 +13,8 @@ const properties = require('properties'); import { depVersions } from './utils/dep-versions'; import { t } from './utils/i18n'; import { tempDir } from './utils/constants'; +import { checkLockFiles } from './utils/check-lockfile'; +import { addGitIgnore } from './utils/add-gitignore'; let bsdiff; let hdiff; @@ -913,6 +915,9 @@ export const commands = { platform, }); + checkLockFiles(); + addGitIgnore(); + const bundleParams = await checkPlugins(); const sourcemapPlugin = bundleParams.sourcemap; const isSentry = bundleParams.sentry; diff --git a/src/index.ts b/src/index.ts index bf4eaae..fc6b985 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,7 +5,6 @@ import updateNotifier from 'update-notifier'; import { printVersionCommand } from './utils'; import pkg from '../package.json'; import { t } from './utils/i18n'; -import { addGitIgnore } from './utils/add-gitignore'; updateNotifier({ pkg }).notify({ isGlobal: true, @@ -33,7 +32,6 @@ const commands = { }; async function run() { - addGitIgnore(); await printVersionCommand(); if (process.argv.indexOf('-v') >= 0 || process.argv[2] === 'version') { process.exit(); diff --git a/src/utils/add-gitignore.ts b/src/utils/add-gitignore.ts index 7ca522d..978decf 100644 --- a/src/utils/add-gitignore.ts +++ b/src/utils/add-gitignore.ts @@ -1,11 +1,11 @@ import fs from 'node:fs'; -import path from 'node:path'; +// import path from 'node:path'; import { credentialFile, tempDir } from './constants'; export function addGitIgnore() { const shouldIgnore = [credentialFile, tempDir]; - const gitignorePath = path.join(process.cwd(), '.gitignore'); + const gitignorePath = '.gitignore'; if (!fs.existsSync(gitignorePath)) { return; @@ -16,7 +16,7 @@ export function addGitIgnore() { const gitignoreLines = gitignoreContent.split('\n'); for (const line of gitignoreLines) { - const index = shouldIgnore.indexOf(line); + const index = shouldIgnore.indexOf(line.trim()); if (index !== -1) { shouldIgnore.splice(index, 1); } diff --git a/src/utils/check-lockfile.ts b/src/utils/check-lockfile.ts new file mode 100644 index 0000000..92f7b9c --- /dev/null +++ b/src/utils/check-lockfile.ts @@ -0,0 +1,24 @@ +import fs from 'node:fs'; +import { t } from '../../lib/utils/i18n'; + +const lockFiles = [ + 'package-lock.json', + 'yarn.lock', + 'pnpm-lock.yaml', + 'bun.lockb', + 'bun.lock', +]; + +const existingLockFiles: string[] = []; +export function checkLockFiles() { + for (const file of lockFiles) { + if (fs.existsSync(file)) { + existingLockFiles.push(file); + } + } + if (existingLockFiles.length === 0) { + console.warn(t('lockFilesNotFound')); + } else if (existingLockFiles.length > 1) { + console.warn(t('multipleLockFilesFound')); + } +} diff --git a/src/utils/lock-checker.ts b/src/utils/lock-checker.ts deleted file mode 100644 index 593c702..0000000 --- a/src/utils/lock-checker.ts +++ /dev/null @@ -1,7 +0,0 @@ -const lockFiles = [ - 'package-lock.json', - 'yarn.lock', - 'pnpm-lock.yaml', - 'bun.lockb', - 'bun.lock', -];