From a74b7542ba77d50e440d4dc9640e1ab8ff2f9f9e Mon Sep 17 00:00:00 2001 From: Simon <10131203+gaomeng1900@users.noreply.github.com> Date: Thu, 12 Mar 2026 00:37:43 +0800 Subject: [PATCH] feat: extension use the same version as packages --- package-lock.json | 2 +- package.json | 1 - packages/extension/package.json | 2 +- .../extension/src/entrypoints/main-world.ts | 4 +- .../sidepanel/components/ConfigPanel.tsx | 5 +-- packages/extension/src/types/globals.d.ts | 3 +- packages/extension/wxt.config.js | 3 +- scripts/ext-version.js | 41 ------------------- scripts/sync-version.js | 27 ++++++------ 9 files changed, 20 insertions(+), 68 deletions(-) delete mode 100644 scripts/ext-version.js diff --git a/package-lock.json b/package-lock.json index 0dcf59f..c35caa3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11106,7 +11106,7 @@ }, "packages/extension": { "name": "@page-agent/ext", - "version": "0.1.17", + "version": "1.5.5", "hasInstallScript": true, "dependencies": { "@page-agent/core": "1.5.5", diff --git a/package.json b/package.json index c06018f..b3dffbc 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,6 @@ "build:website": "npm run build:website --workspace=@page-agent/website", "build:ext": "npm run build:libs && npm run zip -w @page-agent/ext", "version": "node scripts/sync-version.js", - "version:ext": "node scripts/ext-version.js", "lint": "eslint .", "cleanup": "rm -rf packages/*/dist", "prepare": "husky" diff --git a/packages/extension/package.json b/packages/extension/package.json index 828d792..5a5a139 100644 --- a/packages/extension/package.json +++ b/packages/extension/package.json @@ -1,7 +1,7 @@ { "name": "@page-agent/ext", "private": true, - "version": "0.1.17", + "version": "1.5.5", "type": "module", "scripts": { "dev": "wxt", diff --git a/packages/extension/src/entrypoints/main-world.ts b/packages/extension/src/entrypoints/main-world.ts index c17f035..8433faa 100644 --- a/packages/extension/src/entrypoints/main-world.ts +++ b/packages/extension/src/entrypoints/main-world.ts @@ -110,9 +110,9 @@ export default defineUnlistedScript(() => { ) } - ;(window as any).PAGE_AGENT_EXT_VERSION = __EXT_VERSION__ + ;(window as any).PAGE_AGENT_EXT_VERSION = __VERSION__ ;(window as any).PAGE_AGENT_EXT = { - version: __EXT_VERSION__, + version: __VERSION__, execute, stop, } diff --git a/packages/extension/src/entrypoints/sidepanel/components/ConfigPanel.tsx b/packages/extension/src/entrypoints/sidepanel/components/ConfigPanel.tsx index 6ae7ef3..6abc1de 100644 --- a/packages/extension/src/entrypoints/sidepanel/components/ConfigPanel.tsx +++ b/packages/extension/src/entrypoints/sidepanel/components/ConfigPanel.tsx @@ -321,10 +321,7 @@ export function ConfigPanel({ config, onSave, onClose }: ConfigPanelProps) {
- Extension v{__EXT_VERSION__} - - - PageAgent v{__CORE_VERSION__} + Version v{__VERSION__}
diff --git a/packages/extension/src/types/globals.d.ts b/packages/extension/src/types/globals.d.ts index c8effde..4160217 100644 --- a/packages/extension/src/types/globals.d.ts +++ b/packages/extension/src/types/globals.d.ts @@ -1,2 +1 @@ -declare const __EXT_VERSION__: string -declare const __CORE_VERSION__: string +declare const __VERSION__: string diff --git a/packages/extension/wxt.config.js b/packages/extension/wxt.config.js index 23f0303..ca259e7 100644 --- a/packages/extension/wxt.config.js +++ b/packages/extension/wxt.config.js @@ -19,8 +19,7 @@ export default defineConfig({ vite: () => ({ plugins: [tailwindcss()], define: { - __EXT_VERSION__: JSON.stringify(pkg.version), - __CORE_VERSION__: JSON.stringify(pkg.dependencies['@page-agent/core']), + __VERSION__: JSON.stringify(pkg.version), }, optimizeDeps: { force: true, diff --git a/scripts/ext-version.js b/scripts/ext-version.js deleted file mode 100644 index 13360fa..0000000 --- a/scripts/ext-version.js +++ /dev/null @@ -1,41 +0,0 @@ -#!/usr/bin/env node -/** - * Bump extension version and show git tag commands - * - * Usage: - * node scripts/ext-version.js 0.1.16 - */ -import chalk from 'chalk' -import { readFileSync, writeFileSync } from 'fs' -import { dirname, join } from 'path' -import { exit } from 'process' -import { fileURLToPath } from 'url' - -const __dirname = dirname(fileURLToPath(import.meta.url)) -const pkgPath = join(__dirname, '..', 'packages', 'extension', 'package.json') - -const newVersion = process.argv[2] -if (!newVersion) { - console.log(chalk.yellow('āš ļø Usage: npm run ext:version \n')) - exit(1) -} - -const pkg = JSON.parse(readFileSync(pkgPath, 'utf-8')) -const oldVersion = pkg.version - -pkg.version = newVersion -writeFileSync(pkgPath, JSON.stringify(pkg, null, ' ') + '\n') - -console.log( - chalk.green.bold('\nāœ“') + - ` ${chalk.bold('@page-agent/ext')}: ${chalk.dim(oldVersion)} → ${chalk.yellow(newVersion)}\n` -) - -const tagName = `EXT_v${newVersion}` -console.log(chalk.cyan.bold('šŸ“‹ Next steps:\n')) -console.log(chalk.blueBright(`npm i`)) -console.log( - chalk.blueBright(`git add . && git commit -m "chore(ext): bump version to ${newVersion}"`) -) -console.log(chalk.blueBright(`git tag -a ${tagName} -m "${tagName}"`)) -console.log(chalk.blueBright(`git push && git push origin ${tagName}\n`)) diff --git a/scripts/sync-version.js b/scripts/sync-version.js index 736e60f..7cf550b 100644 --- a/scripts/sync-version.js +++ b/scripts/sync-version.js @@ -4,7 +4,7 @@ * * Usage: * node scripts/sync-version.js # Sync current version from root - * node scripts/sync-version.js 0.1.0 # Set and sync new version + * node scripts/sync-version.js 0.1.0 # Set root version, then sync all packages */ import chalk from 'chalk' import { existsSync, readFileSync, readdirSync, writeFileSync } from 'fs' @@ -15,19 +15,18 @@ import { fileURLToPath } from 'url' const __dirname = dirname(fileURLToPath(import.meta.url)) const rootDir = join(__dirname, '..') -// Parse arguments const versionArg = process.argv[2] -if (!versionArg) { - console.log(chalk.yellow('āš ļø No version specified.\n')) - exit(1) -} - // Read root package.json const rootPkgPath = join(rootDir, 'package.json') const rootPkg = JSON.parse(readFileSync(rootPkgPath, 'utf-8')) const oldVersion = rootPkg.version -const newVersion = versionArg +const newVersion = versionArg ?? rootPkg.version + +if (!newVersion) { + console.log(chalk.yellow('āš ļø No version found in root package.json.\n')) + exit(1) +} console.log(chalk.cyan.bold('\nšŸ“¦ Syncing version\n')) @@ -35,7 +34,10 @@ console.log(chalk.cyan.bold('\nšŸ“¦ Syncing version\n')) if (versionArg) { rootPkg.version = newVersion writeFileSync(rootPkgPath, JSON.stringify(rootPkg, null, ' ') + '\n') - console.log(chalk.green('āœ“') + ` ${chalk.bold('root')} → ${chalk.yellow(newVersion)}`) + console.log( + chalk.green('āœ“') + + ` ${chalk.bold('root')}: ${chalk.dim(oldVersion)} → ${chalk.yellow(newVersion)}` + ) } else { console.log(chalk.dim(' root:') + ` ${chalk.yellow(newVersion)} ${chalk.dim('(source)')}`) } @@ -78,11 +80,8 @@ for (const pkg of packages) { const pkgJson = JSON.parse(readFileSync(pkgPath, 'utf-8')) let pkgChanged = false - // Skip extension package version (it has its own versioning) - const isExtension = pkg === 'extension' - - // Update package version (skip extension) - if (!isExtension && pkgJson.version !== newVersion) { + // Update package version + if (pkgJson.version !== newVersion) { pkgJson.version = newVersion pkgChanged = true }