Skip to content

Commit

Permalink
improve the extension version
Browse files Browse the repository at this point in the history
  • Loading branch information
YunFeng0817 committed Aug 28, 2024
1 parent d1e64d8 commit 23ed59f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/web-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
"devDependencies": {
"@rrweb/types": "^2.0.0-alpha.17",
"@types/react-dom": "^18.0.6",
"@types/semver": "^7.5.8",
"@types/webextension-polyfill": "^0.9.1",
"@vitejs/plugin-react": "^4.2.1",
"semver": "^7.6.3",
"type-fest": "^2.19.0",
"vite": "^5.3.1",
"vite-plugin-web-extension": "^4.1.3",
Expand Down
31 changes: 28 additions & 3 deletions packages/web-extension/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import zip from 'vite-plugin-zip-pack';
import * as path from 'path';
import type { PackageJson } from 'type-fest';
import react from '@vitejs/plugin-react';
import semver from 'semver';

const emptyOutDir = !process.argv.includes('--watch');

Expand Down Expand Up @@ -39,6 +40,29 @@ function useSpecialFormat(
};
}

/**
* Get the extension version based on the rrweb version.
*/
function getExtensionVersion(rrwebVersion: string): string {
const parsedVersion = semver.parse(rrwebVersion.replace('^', ''));

if (!parsedVersion) {
throw new Error('Invalid version format');
}

if (parsedVersion.prerelease.length > 0) {
// If it's a pre-release version like alpha or beta, strip the pre-release identifier
return `${parsedVersion.major}.${parsedVersion.minor}.${
parsedVersion.patch
}.${parsedVersion.prerelease[1] || 0}`;
} else if (rrwebVersion === '2.0.0') {
// This version has already been released as the first version. We need to add a patch version to it to avoid publishing conflicts.
return '2.0.0.100';
} else {
return rrwebVersion;
}
}

export default defineConfig({
root: 'src',
// Configure our outputs - nothing special, this is normal vite config
Expand Down Expand Up @@ -73,10 +97,11 @@ export default defineConfig({
const BrowserName =
process.env.TARGET_BROWSER === 'chrome' ? 'chrome' : 'firefox';
const commonManifest = originalManifest.common;
const rrwebVersion = packageJson.dependencies!.rrweb!.replace('^', '');
const manifest = {
version: '2.0.0',
version: getExtensionVersion(rrwebVersion),
author: packageJson.author,
version_name: packageJson.dependencies?.rrweb?.replace('^', ''),
version_name: rrwebVersion,
...commonManifest,
};
Object.assign(
Expand All @@ -92,7 +117,7 @@ export default defineConfig({
watchIgnored: ['*.md', '*.log'],
},
additionalInputs: ['pages/index.html', 'content/inject.ts'],
}),
}) as PluginOption,
// https://github.com/aklinker1/vite-plugin-web-extension/issues/50#issuecomment-1317922947
// transfer inject.ts to iife format to avoid error
useSpecialFormat(
Expand Down
7 changes: 6 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2820,7 +2820,7 @@
"@types/prop-types" "*"
csstype "^3.0.2"

"@types/semver@^7.3.12", "@types/semver@^7.5.0":
"@types/semver@^7.3.12", "@types/semver@^7.5.0", "@types/semver@^7.5.8":
version "7.5.8"
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.8.tgz#8268a8c57a3e4abd25c165ecd36237db7948a55e"
integrity sha512-I8EUhyrgfLrcTkzV3TSsGyl1tSuPrEDzr0yd5m90UgNxQkyDXULk3b6MlQqTCpZpNtWe1K0hzclnZkTcLBe2UQ==
Expand Down Expand Up @@ -8985,6 +8985,11 @@ semver@^6.3.0, semver@^6.3.1:
resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4"
integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA==

semver@^7.6.3:
version "7.6.3"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.6.3.tgz#980f7b5550bc175fb4dc09403085627f9eb33143"
integrity sha512-oVekP1cKtI+CTDvHWYFUcMtsK/00wmAEfyqKfNdARm8u1wNVhSgaX7A8d4UuIlUI5e84iEwOhs7ZPYRmzU9U6A==

semver@~7.5.4:
version "7.5.4"
resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e"
Expand Down

0 comments on commit 23ed59f

Please sign in to comment.