Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

refactor(extension): single source of truth for version

daniel31x137b7c9f3e0b63
diff --git a/apps/extension/README.md b/apps/extension/README.md
index 8e62db0e..104f08a5 100644
--- a/apps/extension/README.md
+++ b/apps/extension/README.md
@@ -86,7 +86,8 @@ plus the few keys that differ per target, and a vite plugin writes the result to
Chrome and Firefox build in `dist/`, and `safari` for `dist-safari/`, selected by
the `EXT_TARGET` environment variable that `yarn build:safari` sets.
-Version bumps and permission changes go in that one file. Anything Safari cannot
+Version bumps and permission changes go in that one file, Safari included: see
+[Versioning](#versioning) below. Anything Safari cannot
do (the bookmarks permission, the service worker, the omnibox keyword) is a flag
on the target rather than a second copy of the manifest.
@@ -106,3 +107,21 @@ The Xcode project references `dist-safari/` directly rather than holding its own
of the extension, so `yarn build:safari` has to run first or you will archive a
stale build. There is no conversion step: running `safari-web-extension-converter`
against `safari/` would replace the committed project and its signing configuration.
+
+## Versioning
+
+The version lives in `manifest.config.ts` and nowhere else. Every build writes it
+to `version.xcconfig`, which the Xcode project reads as the base configuration on
+both targets, so one edit covers Chrome, Firefox and Safari.
+
+`version.xcconfig` is generated and committed. Do not edit it by hand. It is
+committed rather than ignored so a fresh clone opens in Xcode without a dangling
+file reference, which would silently resolve `MARKETING_VERSION` to empty and
+produce an archive App Store Connect rejects. Any build regenerates it, so
+`git diff --exit-code apps/extension/version.xcconfig` after a build is a
+reasonable CI check that the two have not drifted.
+
+`CURRENT_PROJECT_VERSION` also lives there. It is the build number rather than the
+version, and only has to be unique per App Store Connect upload, so CI passes
+`CURRENT_PROJECT_VERSION=$GITHUB_RUN_NUMBER` on the `xcodebuild` command line,
+which takes precedence over the xcconfig.
diff --git a/apps/extension/manifest.config.ts b/apps/extension/manifest.config.ts
index be8790a3..69b7ed80 100644
--- a/apps/extension/manifest.config.ts
+++ b/apps/extension/manifest.config.ts
@@ -3,7 +3,9 @@
*
* Every browser gets the same manifest apart from the handful of keys collected
* in `targets` below. The vite plugin in vite.config.ts writes the result into
- * the build output, so there is no manifest.json checked into the repo.
+ * the build output, so there is no manifest.json checked into the repo. The same
+ * plugin writes `version` out to version.xcconfig for the Safari Xcode project,
+ * which cannot read this file itself.
*/
/**
@@ -49,7 +51,12 @@ const targets: Record<ManifestTarget, TargetOptions> = {
},
};
-const version = "1.5.4";
+/**
+ * The version for every target, including Safari: the vite plugin mirrors this
+ * into `version.xcconfig`, which the Xcode project reads as its base
+ * configuration. Bump it here and nowhere else.
+ */
+export const version = "1.5.4";
const icons = {
"16": "16.png",
diff --git a/apps/extension/safari/Linkwarden/Linkwarden.xcodeproj/project.pbxproj b/apps/extension/safari/Linkwarden/Linkwarden.xcodeproj/project.pbxproj
index 59831cca..1cee4b70 100644
--- a/apps/extension/safari/Linkwarden/Linkwarden.xcodeproj/project.pbxproj
+++ b/apps/extension/safari/Linkwarden/Linkwarden.xcodeproj/project.pbxproj
@@ -79,6 +79,7 @@
65E051FE2F9AFEE300628D48 /* manifest.json */ = {isa = PBXFileReference; lastKnownFileType = text.json; name = manifest.json; path = "../../../dist-safari/manifest.json"; sourceTree = "<group>"; };
65E051FF2F9AFEE300628D48 /* assets */ = {isa = PBXFileReference; lastKnownFileType = folder; name = assets; path = "../../../dist-safari/assets"; sourceTree = "<group>"; };
65E052002F9AFEE300628D48 /* src */ = {isa = PBXFileReference; lastKnownFileType = folder; name = src; path = "../../../dist-safari/src"; sourceTree = "<group>"; };
+ 65E0520C2F9AFEE300628D48 /* version.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = version.xcconfig; path = "../../version.xcconfig"; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -102,6 +103,7 @@
65E051C02F9AFEE100628D48 = {
isa = PBXGroup;
children = (
+ 65E0520C2F9AFEE300628D48 /* version.xcconfig */,
65E051CB2F9AFEE100628D48 /* Linkwarden */,
65E051E82F9AFEE300628D48 /* Linkwarden Extension */,
65E051CA2F9AFEE100628D48 /* Products */,
@@ -335,6 +337,7 @@
/* Begin XCBuildConfiguration section */
65E051EC2F9AFEE300628D48 /* Debug */ = {
isa = XCBuildConfiguration;
+ baseConfigurationReference = 65E0520C2F9AFEE300628D48 /* version.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
@@ -398,6 +401,7 @@
};
65E051ED2F9AFEE300628D48 /* Release */ = {
isa = XCBuildConfiguration;
+ baseConfigurationReference = 65E0520C2F9AFEE300628D48 /* version.xcconfig */;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES;
@@ -455,7 +459,6 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = FZ44882Y36;
ENABLE_APP_SANDBOX = YES;
ENABLE_HARDENED_RUNTIME = YES;
@@ -470,7 +473,6 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
- MARKETING_VERSION = 1.5.4;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
@@ -490,7 +492,6 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_STYLE = Automatic;
- CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = FZ44882Y36;
ENABLE_APP_SANDBOX = YES;
ENABLE_HARDENED_RUNTIME = YES;
@@ -506,7 +507,6 @@
"@executable_path/../../../../Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 13.0;
- MARKETING_VERSION = 1.5.4;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
@@ -530,7 +530,6 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
- CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = FZ44882Y36;
ENABLE_APP_SANDBOX = YES;
ENABLE_HARDENED_RUNTIME = YES;
@@ -547,7 +546,6 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
- MARKETING_VERSION = 1.5.4;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
@@ -574,7 +572,6 @@
ASSETCATALOG_COMPILER_INCLUDE_ALL_APPICON_ASSETS = NO;
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
- CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = FZ44882Y36;
ENABLE_APP_SANDBOX = YES;
ENABLE_HARDENED_RUNTIME = YES;
@@ -592,7 +589,6 @@
"$(inherited)",
"@executable_path/../Frameworks",
);
- MARKETING_VERSION = 1.5.4;
OTHER_LDFLAGS = (
"-framework",
SafariServices,
diff --git a/apps/extension/version.xcconfig b/apps/extension/version.xcconfig
new file mode 100644
index 00000000..ea3f89b7
--- /dev/null
+++ b/apps/extension/version.xcconfig
@@ -0,0 +1,4 @@
+// Generated from manifest.config.ts by vite.config.ts. Do not edit.
+// Bump the version in manifest.config.ts and rebuild.
+MARKETING_VERSION = 1.5.4
+CURRENT_PROJECT_VERSION = 1
diff --git a/apps/extension/vite.config.ts b/apps/extension/vite.config.ts
index 2efcffb5..242c92b4 100644
--- a/apps/extension/vite.config.ts
+++ b/apps/extension/vite.config.ts
@@ -2,7 +2,7 @@ import fs from 'fs';
import path from 'path';
import react from '@vitejs/plugin-react';
import { defineConfig, type Plugin } from 'vite';
-import { buildManifest, resolveTarget } from './manifest.config';
+import { buildManifest, resolveTarget, version } from './manifest.config';
// `build:safari` sets EXT_TARGET; every other build, including the watching dev
// builds, gets the Chrome and Firefox manifest.
@@ -10,6 +10,28 @@ const target = resolveTarget();
const isWatch = process.argv.includes('--watch') || process.argv.includes('-w');
+// Xcode resolves build settings before any script it could run, so the Safari
+// project cannot read manifest.config.ts. It reads this instead, as the base
+// configuration on both targets. Committed so a fresh clone opens without a
+// dangling reference, which would leave MARKETING_VERSION empty and produce an
+// archive App Store Connect rejects.
+//
+// CURRENT_PROJECT_VERSION is the build number rather than the version, and only
+// has to be unique per upload. CI overrides it on the xcodebuild command line,
+// which beats an xcconfig.
+function writeVersionXcconfig() {
+ fs.writeFileSync(
+ path.resolve(__dirname, 'version.xcconfig'),
+ [
+ '// Generated from manifest.config.ts by vite.config.ts. Do not edit.',
+ '// Bump the version in manifest.config.ts and rebuild.',
+ `MARKETING_VERSION = ${version}`,
+ 'CURRENT_PROJECT_VERSION = 1',
+ '',
+ ].join('\n')
+ );
+}
+
// Writing the manifest here rather than copying a file afterwards keeps it in
// place for `vite build --watch`, which never returns to run a follow-up step.
function manifest(): Plugin {
@@ -26,6 +48,9 @@ function manifest(): Plugin {
path.join(outDir, 'manifest.json'),
JSON.stringify(buildManifest(target), null, 2) + '\n'
);
+ // Every target, not just safari, so the two cannot drift apart just
+ // because `build:safari` happened not to run.
+ writeVersionXcconfig();
},
};
}