diff --git a/src/info.ts b/src/info.ts index 1960570bd..eac3777fe 100644 --- a/src/info.ts +++ b/src/info.ts @@ -1,18 +1 @@ -import _packageJson from '../package.json'; - -interface MyPackageJson { - name: string; - displayName: string; - version: string; - description: string; - author: string; - repository: { - type: string; - url: string; - }; - license: string; - bugs: string; - homepage: string; -} - -export const packageJson: MyPackageJson = _packageJson; +export { name, displayName, version, description, license, bugs, homepage } from '../package.json'; diff --git a/src/plugin/extension-updater.ts b/src/plugin/extension-updater.ts index a65c291ce..d00c10d9c 100644 --- a/src/plugin/extension-updater.ts +++ b/src/plugin/extension-updater.ts @@ -6,7 +6,7 @@ import { Messaging } from 'services/messaging'; import { Notification } from 'services/notification'; import { Http } from 'services/http'; import type { GithubRelease } from 'interface'; -import { packageJson } from 'info'; +import { version, displayName } from 'info'; @Service() export class ExtensionUpdater { @@ -33,7 +33,7 @@ export class ExtensionUpdater { const response = await this.http.json( 'https://api.github.com/repos/EhTagTranslation/EhSyringe/releases/latest', ); - const current = `v${packageJson.version}`; + const current = `v${version}`; const latest = response.tag_name; if (typeof latest != 'string' || !latest.startsWith('v')) { const e = new Error('响应格式错误'); @@ -45,7 +45,7 @@ export class ExtensionUpdater { if (latest === current) return false; this.notification.send({ - title: packageJson.displayName, + title: displayName, message: `发现新的版本 ${latest},点击跳转到下载页面。`, action: () => openInTab(response.html_url), }); diff --git a/src/plugin/popup/index.ts b/src/plugin/popup/index.ts index 221037e12..01b0f5404 100644 --- a/src/plugin/popup/index.ts +++ b/src/plugin/popup/index.ts @@ -7,7 +7,7 @@ import { Messaging } from 'services/messaging'; import { DateTime } from 'services/date-time'; import { openInTab } from 'providers/utils'; import type { DownloadStatus } from 'plugin/database-updater'; -import { packageJson } from 'info'; +import { homepage, version } from 'info'; import type { MessageListener } from 'providers/common/messaging'; import './index.less'; @@ -348,7 +348,7 @@ export class Popup { return html`
- v${packageJson.version} + v${version}
diff --git a/src/providers/web-ext/storage.ts b/src/providers/web-ext/storage.ts index 3915ca621..2e72f6099 100644 --- a/src/providers/web-ext/storage.ts +++ b/src/providers/web-ext/storage.ts @@ -1,6 +1,6 @@ import type { Storage, Listener, ListenerId, SyncStorage } from '../common/storage'; import type { JsonValue } from 'type-fest'; -import { packageJson } from 'info'; +import { name } from 'info'; const listeners = new Map(); @@ -42,7 +42,7 @@ export const storage: Storage = { }, }; -const mark = `${packageJson.name}.`; +const mark = `${name}.`; const syncKey = (k: string): string => mark + k; export const syncStorage: SyncStorage = { diff --git a/src/providers/web-ext/utils.ts b/src/providers/web-ext/utils.ts index 4deb8c2cd..a0210daa2 100644 --- a/src/providers/web-ext/utils.ts +++ b/src/providers/web-ext/utils.ts @@ -1,6 +1,6 @@ import type { NotificationInfo } from '../common/notification'; import type { Badge } from 'providers/common/badge'; -import { packageJson } from 'info'; +import { displayName } from 'info'; export function openInTab(url: string): void { void browser.tabs.create({ @@ -38,7 +38,7 @@ export function setBadge(info: Badge): void { if (typeof chrome.action.setBadgeText == 'function') { void chrome.action.setBadgeText({ text: info.text }); } else if (typeof chrome.action.setTitle == 'function') { - const extname = packageJson.displayName; + const extname = displayName; const title = info.text ? `${extname} (${info.text})` : extname; void chrome.action.setTitle({ title }); } diff --git a/src/services/sync-storage.ts b/src/services/sync-storage.ts index cbe09c1a3..0a0fcae8c 100644 --- a/src/services/sync-storage.ts +++ b/src/services/sync-storage.ts @@ -3,7 +3,7 @@ import { syncStorage } from 'providers/storage'; import { Logger } from './logger'; import type { JsonValue } from 'type-fest'; import { type ConfigData, Storage } from './storage'; -import { packageJson } from 'info'; +import { version } from 'info'; export interface SyncStorageItems { version: string; @@ -19,9 +19,9 @@ export class SyncStorage { readonly async: Storage, ) { const oldVer = this.get('version'); - if (packageJson.version !== oldVer) { + if (version !== oldVer) { this.migrate(); - this.set('version', packageJson.version); + this.set('version', version); } } @@ -52,7 +52,7 @@ export class SyncStorage { } readonly defaults: Readonly = { - version: packageJson.version, + version: version, databaseMap: undefined, databaseSha: undefined, config: this.async.defaults.config, diff --git a/src/user-script/popup-host.ts b/src/user-script/popup-host.ts index 8999cbf83..dd4ea9c23 100644 --- a/src/user-script/popup-host.ts +++ b/src/user-script/popup-host.ts @@ -1,7 +1,7 @@ import { Container } from 'services'; import { isHathNetwork } from 'utils/hosts'; import { Popup } from 'plugin/popup'; -import { packageJson } from 'info'; +import { displayName } from 'info'; import { setBadge } from 'providers/utils'; import './popup-host.less'; @@ -113,7 +113,7 @@ export function createPopup(): void { } const button = document.body.appendChild(document.createElement('div')); button.id = 'eh-syringe-popup-button'; - button.title = packageJson.displayName; + button.title = displayName; const badge = button.appendChild(document.createElement('div')); badge.id = 'eh-syringe-popup-badge'; setBadge({ text: '' }); diff --git a/webpack.config.js b/webpack.config.js index eab8c5a2f..1151e4701 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -17,7 +17,7 @@ const WebExtensionPlugin = _WebExtensionPlugin.default; const __dirname = path.resolve(fileURLToPath(import.meta.url), '../'); -/** @type { import('./src/info').packageJson & import('type-fest').PackageJson } */ +/** @type { import('./src/info') & import('type-fest').PackageJson } */ const pkgJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, './package.json'))); const manifestJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, './manifest.json')));