Compare commits

...
3 Commits
9 changed files with 177 additions and 83 deletions
+36 -22
View File
@@ -1154,7 +1154,7 @@ export GEM_PATH=$shortened_path
###### 1. Bump the version in package.json & CHANGELOG.md for `MARKETING_VERSION`, then `grep CURRENT_PROJECT_VERSION ios/App/App.xcodeproj/project.pbxproj` and add 1 for the numbered version here:
```bash
cd ios/App && xcrun agvtool new-version 79 && perl -p -i -e "s/MARKETING_VERSION = .*;/MARKETING_VERSION = 1.4.13;/g" App.xcodeproj/project.pbxproj && cd -
cd ios/App && xcrun agvtool new-version 80 && perl -p -i -e "s/MARKETING_VERSION = .*;/MARKETING_VERSION = 1.4.14;/g" App.xcodeproj/project.pbxproj && cd -
# Unfortunately this edits Info.plist directly.
#xcrun agvtool new-marketing-version 0.4.5
```
@@ -1333,12 +1333,13 @@ npm run build:android:test:run # test env build, install, launch
npm run build:android # Development build (builds and opens Android Studio)
npm run build:android:dev # Development build (builds and opens Android Studio)
npm run build:android:test # Test build (builds for testing environment)
npm run build:android:prod # Production build (builds for production environment).
npm run build:android:prod # Production web bundle in a debug APK (not for upload; use build:android:release)
# Auto-run builds
npm run build:android:test:run # Test build with auto-run (builds then runs on emulator)
npm run build:android:prod:run # Production build with auto-run (builds then runs on emulator)
# Auto-run targets the one connected device; with none or several it prompts, or exits 9 without a terminal
# Auto-run installs the APK just built (debug, or release with --release) via native-run:
# a hardware device, else a running emulator, else it boots an AVD. Set ANDROID_SERIAL to choose.
# Firebase off (`:nostore` sets FIREBASE_ENABLED=false, which passes -PfirebaseEnabled=false)
npm run build:android:test:nostore:run # Same as test:run, without Firebase
@@ -1347,13 +1348,11 @@ npm run build:android:prod:nostore # Same as prod, without Firebase
# Debug and release builds
npm run build:android:debug # Debug build (builds debug APK)
npm run build:android:debug:run # Debug build with auto-run (builds then runs on emulator)
npm run build:android:release # Release build (builds release APK)
npm run build:android:release:run # Release build with auto-run (builds then runs on device)
npm run build:android:release # Play Store release: production mode, signed APK + AAB (fails if unsigned)
npm run build:android:release:run # Production release APK, installed and launched on a device
# Additional operations
npm run build:android:studio # Build and open in Android Studio
npm run build:android:apk # Build and generate APK file
npm run build:android:aab # Build and generate AAB (Android App Bundle)
npm run build:android:clean # Clean build artifacts only
npm run build:android:sync # Sync Capacitor only
npm run build:android:assets # Generate assets only
@@ -1446,16 +1445,25 @@ The recommended way to build for Android is using the automated build script:
##### 1. Bump the version in package.json, then update these versions & run:
```bash
perl -p -i -e 's/versionCode .*/versionCode 79/g' android/app/build.gradle
perl -p -i -e 's/versionName .*/versionName "1.4.13"/g' android/app/build.gradle
perl -p -i -e 's/versionCode .*/versionCode 80/g' android/app/build.gradle
perl -p -i -e 's/versionName .*/versionName "1.4.14"/g' android/app/build.gradle
```
##### 1.1 Bump daily-notifications-plugin
If there is an update in the daily-notifications-plugin then run this:
```
npm run deps:update-daily-notification-plugin
```
##### 2. Build
Here's prod. Also available: test, dev
Here's 'release'. Also available: prod, test, dev -- but only 'release' builds an aab for the Play Store
```bash
npm run build:android:prod
# if you use pkgx: pkgx +openjdk.org /bin/zsh
npm run build:android:release
```
##### 2.1. (Optional) Open the project in Android Studio
@@ -1464,15 +1472,20 @@ npm run build:android:prod
npx cap open android
```
##### 3. Use Android Studio to build and run on emulator or device
##### 2.2 (Optional) Android Build from the console
#### Android Build from the console
This is if you didn't build with ":release" but rather with ":prod".
`cd android`
* Note that this currently fails: `./gradlew build`
To create a signed `aab` release:
To create a signed `aab` release, run `npm run build:android:release` from the
project root: it builds the production web bundle, syncs it, and runs
`assembleRelease` and `bundleRelease`. It first runs
`scripts/check-installed-deps.js`, which stops the build when `node_modules`
does not match `package-lock.json` (fix with `npm ci`); it never updates
dependencies itself. The steps below are the manual equivalent.
- Setup by adding the app/gradle.properties.secrets file (see properties at top
of app/build.gradle) and the app/time-safari-upload-key-pkcs12.jks file
@@ -1498,13 +1511,15 @@ To create an unsigned debugging bundle (not usable in Play Store):
uploading, confirm it has production server defaults:
`./scripts/check-prod-bundle.sh android/app/build/outputs/bundle/release/app-release.aab`
* `build-android.sh` runs `./gradlew clean`, which deletes any earlier `aab`, so
run `bundleRelease` after the build script finishes.
when building by hand, run `bundleRelease` after the build script finishes.
##### 3 Release to Play Store
At play.google.com/console:
- Go to Production or the Closed Testing and either Create Track or Manage Track.
- Click "Create new release".
- Upload the `aab` file from: app/build/outputs/bundle/release/app-release.aab
- Upload the `aab` file from: android/app/build/outputs/bundle/release/app-release.aab
- Hit "Next".
- Save, go to "Publishing Overview" as prompted, and click "Send changes for review".
@@ -2157,10 +2172,9 @@ command chaining, following DRY principles.
--test Build for testing environment
--prod, --production Build for production environment
--debug Build debug APK
--release Build release APK
--release Build signed release APK (production unless --dev/--test)
--studio Open Android Studio after build
--apk Build APK file
--aab Build AAB (Android App Bundle)
--aab Also build a signed release AAB (implies --release)
--clean Clean build artifacts only
--sync Sync Capacitor only
--assets Generate assets only
@@ -2170,8 +2184,8 @@ command chaining, following DRY principles.
# Examples
./scripts/build-android.sh --dev --studio # Development build + open studio
./scripts/build-android.sh --prod --apk # Production APK build
./scripts/build-android.sh --test --aab # Testing AAB build
./scripts/build-android.sh --prod # Production web build, debug APK
./scripts/build-android.sh --prod --aab # Play Store release APK + AAB
./scripts/build-android.sh --clean # Clean only
./scripts/build-android.sh --sync # Sync only
```
@@ -2185,7 +2199,7 @@ command chaining, following DRY principles.
**Build Types**:
- **Debug**: Build debug APK (default)
- **Release**: Build release APK
- **Release**: Build signed release APK (production mode unless --dev or --test is given)
**Exit Codes**:
+5
View File
@@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.4.14] - 2026.11.11
### Fixed
- Crash on starting the camera (and other permissions requests)
## [1.4.13] - 2026.11.10
### Fixed
- Tapping the New Activity notification opens New Activity, including when that tap is what launches the app. Receiving the notification does not open it.
+2 -2
View File
@@ -378,10 +378,10 @@ Prerequisites: git, Node.js 20 (see `.nvmrc`), Java 21, and the Android SDK with
```bash
npm ci
npm run build:android:prod -- --apk
npm run build:android:prod
```
`npm ci` installs the exact dependency versions locked for 1.4.6. `build:android:prod -- --apk` builds the web app with production server settings, syncs it into the Android project, and runs `./gradlew assembleDebug`. The result is signed with your local Android debug key, so it installs on any device without a release keystore.
`npm ci` installs the exact dependency versions locked for 1.4.6. `build:android:prod` builds the web app with production server settings, syncs it into the Android project, and runs `./gradlew assembleDebug`. The result is signed with your local Android debug key, so it installs on any device without a release keystore.
4. Find the APK at `android/app/build/outputs/apk/debug/app-debug.apk` and install it, either with `adb install android/app/build/outputs/apk/debug/app-debug.apk` (USB debugging enabled on the phone) or by copying the file to the phone and opening it (allow "Install unknown apps" for the file manager).
+2 -2
View File
@@ -39,8 +39,8 @@ android {
applicationId "app.timesafari.app"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 79
versionName "1.4.13"
versionCode 80
versionName "1.4.14"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
+8 -8
View File
@@ -568,7 +568,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = App/AppDebug.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 79;
CURRENT_PROJECT_VERSION = 80;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_APP_SANDBOX = NO;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -581,7 +581,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.13;
MARKETING_VERSION = 1.4.14;
OTHER_SWIFT_FLAGS = "$(inherited) \"-D\" \"COCOAPODS\" \"-DDEBUG\"";
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari;
PRODUCT_NAME = "$(TARGET_NAME)";
@@ -600,7 +600,7 @@
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_ENTITLEMENTS = App/App.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 79;
CURRENT_PROJECT_VERSION = 80;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_APP_SANDBOX = NO;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
@@ -613,7 +613,7 @@
"$(inherited)",
"@executable_path/Frameworks",
);
MARKETING_VERSION = 1.4.13;
MARKETING_VERSION = 1.4.14;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "";
@@ -631,7 +631,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = TimeSafariShareExtension/TimeSafariShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 79;
CURRENT_PROJECT_VERSION = 80;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
FIREBASE_ENABLED = YES;
@@ -647,7 +647,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.4.13;
MARKETING_VERSION = 1.4.14;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari.TimeSafariShareExtension;
@@ -671,7 +671,7 @@
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = TimeSafariShareExtension/TimeSafariShareExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 79;
CURRENT_PROJECT_VERSION = 80;
DEVELOPMENT_TEAM = GM3FS5JQPH;
ENABLE_USER_SCRIPT_SANDBOXING = NO;
FIREBASE_ENABLED = YES;
@@ -687,7 +687,7 @@
"@executable_path/../../Frameworks",
);
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
MARKETING_VERSION = 1.4.13;
MARKETING_VERSION = 1.4.14;
MTL_FAST_MATH = YES;
PRODUCT_BUNDLE_IDENTIFIER = app.timesafari.TimeSafariShareExtension;
PRODUCT_NAME = "$(TARGET_NAME)";
+4 -4
View File
@@ -1,12 +1,12 @@
{
"name": "giftopia",
"version": "1.4.14-beta",
"version": "1.4.15-beta",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "giftopia",
"version": "1.4.14-beta",
"version": "1.4.15-beta",
"dependencies": {
"@capacitor-community/electron": "^5.0.1",
"@capacitor-community/sqlite": "^7.0.3",
@@ -11512,8 +11512,8 @@
}
},
"node_modules/@timesafari/daily-notification-plugin": {
"version": "5.0.0",
"resolved": "git+https://gitea.anomalistdesign.com/trent_larson/daily-notification-plugin.git#cde2d5ab96c6413929aa5a2b13c59f2d8032165d",
"version": "5.0.1",
"resolved": "git+https://gitea.anomalistdesign.com/trent_larson/daily-notification-plugin.git#5953daa423eb0e2e136e816aa469f2eba7deee82",
"license": "MIT",
"workspaces": [
"packages/*"
+3 -5
View File
@@ -1,6 +1,6 @@
{
"name": "giftopia",
"version": "1.4.14-beta",
"version": "1.4.15-beta",
"description": "Giftopia App",
"author": {
"name": "Gift Economies Team"
@@ -17,8 +17,6 @@
"auto-run:prod": "./scripts/auto-run.sh --prod",
"auto-run:test": "./scripts/auto-run.sh --test",
"build:android": "./scripts/build-android.sh",
"build:android:aab": "./scripts/build-android.sh --aab",
"build:android:apk": "./scripts/build-android.sh --apk",
"build:android:assets": "./scripts/build-android.sh --assets",
"build:android:clean": "./scripts/build-android.sh --clean",
"build:android:debug": "./scripts/build-android.sh --debug",
@@ -32,8 +30,8 @@
"build:android:prod:nostore": "FIREBASE_ENABLED=false npm run build:android:prod",
"build:android:prod:nostore:run": "FIREBASE_ENABLED=false npm run build:android:prod:run",
"build:android:prod:run": "./scripts/build-android.sh --prod --auto-run",
"build:android:release": "./scripts/build-android.sh --release",
"build:android:release:run": "./scripts/build-android.sh --release --auto-run",
"build:android:release": "./scripts/build-android.sh --prod --release --aab",
"build:android:release:run": "./scripts/build-android.sh --prod --release --auto-run",
"build:android:studio": "./scripts/build-android.sh --studio",
"build:android:sync": "./scripts/build-android.sh --sync",
"build:android:test": "./scripts/build-android.sh --test",
+52 -40
View File
@@ -14,10 +14,10 @@
# --test Build for testing environment
# --prod, --production Build for production environment
# --debug Build debug APK
# --release Build release APK
# --release Build signed release APK (production mode unless
# --dev or --test is given; fails if unsigned)
# --studio Open Android Studio after build
# --apk Build APK file
# --aab Build AAB (Android App Bundle)
# --aab Also build a signed release AAB (implies --release)
# --clean Clean build artifacts only
# --sync Sync Capacitor only
# --assets Generate assets only
@@ -29,8 +29,8 @@
#
# Examples:
# ./scripts/build-android.sh --dev --studio # Development build + open studio
# ./scripts/build-android.sh --prod --apk # Production APK build
# ./scripts/build-android.sh --test --aab # Testing AAB build
# ./scripts/build-android.sh --prod # Production web build, debug APK
# ./scripts/build-android.sh --prod --aab # Play Store release APK + AAB
# ./scripts/build-android.sh --clean # Clean only
# ./scripts/build-android.sh --sync # Sync only
#
@@ -44,6 +44,8 @@
# 7 - Asset generation failed
# 8 - Android Studio launch failed
# 9 - Android asset validation failed
# 10 - Production bundle check failed
# 11 - node_modules does not match package-lock.json (release builds)
# Exit on any error
set -e
@@ -329,9 +331,9 @@ validate_android_assets() {
# Default values
BUILD_MODE="development"
BUILD_MODE_SET=false
BUILD_TYPE="debug"
OPEN_STUDIO=false
BUILD_APK=false
BUILD_AAB=false
CLEAN_ONLY=false
SYNC_ONLY=false
@@ -352,12 +354,15 @@ parse_android_args() {
case $arg in
--dev|--development)
BUILD_MODE="development"
BUILD_MODE_SET=true
;;
--test)
BUILD_MODE="test"
BUILD_MODE_SET=true
;;
--prod|--production)
BUILD_MODE="production"
BUILD_MODE_SET=true
;;
--debug)
BUILD_TYPE="debug"
@@ -368,11 +373,9 @@ parse_android_args() {
--studio)
OPEN_STUDIO=true
;;
--apk)
BUILD_APK=true
;;
--aab)
BUILD_AAB=true
BUILD_TYPE="release"
;;
--clean)
CLEAN_ONLY=true
@@ -428,15 +431,14 @@ print_android_usage() {
echo " --test Build for testing environment"
echo " --prod, --production Build for production environment"
echo " --debug Build debug APK (default)"
echo " --release Build release APK"
echo " --release Build signed release APK (production unless --dev/--test)"
echo " --studio Open Android Studio after build"
echo " --apk Build APK file"
echo " --aab Build AAB (Android App Bundle)"
echo " --aab Also build a signed release AAB (implies --release)"
echo " --clean Clean build artifacts only"
echo " --sync Sync Capacitor only"
echo " --assets Generate assets only"
echo " --deploy Deploy APK to connected device"
echo " --auto-run Auto-run app after build"
echo " --auto-run Install and launch the APK just built (debug or release)"
echo " --uninstall Uninstall app from connected device"
echo " --api-ip <ip> Custom IP address for claim API (defaults to 10.0.2.2)"
echo ""
@@ -449,8 +451,8 @@ print_android_usage() {
echo ""
echo "Examples:"
echo " $0 --dev --studio # Development build + open studio"
echo " $0 --prod --apk # Production APK build"
echo " $0 --test --aab # Testing AAB build"
echo " $0 --prod # Production web build, debug APK"
echo " $0 --prod --aab # Play Store release APK + AAB"
echo " $0 --test --auto-run # Test build + auto-run"
echo " $0 --clean # Clean only"
echo " $0 --sync # Sync only"
@@ -464,6 +466,13 @@ print_android_usage() {
# Parse command line arguments
parse_android_args "$@"
# A release build without an explicit mode would otherwise bundle the
# development web build (emulator API servers at 10.0.2.2).
if [ "$BUILD_TYPE" = "release" ] && [ "$BUILD_MODE_SET" = false ]; then
BUILD_MODE="production"
log_info "Release build without a mode; using production"
fi
# Firebase is on unless FIREBASE_ENABLED is false, 0, or no. Gradle also
# defaults firebaseEnabled=true; this only forwards an explicit opt-out.
gradle_firebase_arg=""
@@ -600,6 +609,12 @@ if [ "$UNINSTALL" = true ]; then
exit 0
fi
# Step 2.5: A release packages whatever is in node_modules; make sure that is
# what package-lock.json records (e.g. the daily-notification-plugin commit).
if [ "$BUILD_TYPE" = "release" ]; then
safe_execute "Checking node_modules against package-lock.json" "node scripts/check-installed-deps.js" || exit 11
fi
# Step 3: Clean dist directory
log_info "Cleaning dist directory..."
clean_build_artifacts "dist"
@@ -650,17 +665,16 @@ if [ "$BUILD_TYPE" = "debug" ]; then
safe_execute "Assembling debug build" "cd android && ./gradlew assembleDebug ${gradle_firebase_arg} && cd .." || exit 5
elif [ "$BUILD_TYPE" = "release" ]; then
safe_execute "Assembling release build" "cd android && ./gradlew assembleRelease ${gradle_firebase_arg} && cd .." || exit 5
fi
# Step 10: Build APK/AAB if requested
if [ "$BUILD_APK" = true ]; then
if [ "$BUILD_TYPE" = "debug" ]; then
safe_execute "Building debug APK" "cd android && ./gradlew assembleDebug ${gradle_firebase_arg} && cd .." || exit 5
else
safe_execute "Building release APK" "cd android && ./gradlew assembleRelease ${gradle_firebase_arg} && cd .." || exit 5
# Gradle signs release only when a keystore is configured (env vars or
# android/app/gradle.properties.secrets); otherwise it quietly writes
# app-release-unsigned.apk, which neither installs nor uploads.
if [ ! -f "android/app/build/outputs/apk/release/app-release.apk" ]; then
log_error "Release build is unsigned: configure the keystore (see top of android/app/build.gradle)"
exit 5
fi
fi
# Step 10: Build AAB if requested (step 9 already built the APK)
if [ "$BUILD_AAB" = true ]; then
safe_execute "Building AAB" "cd android && ./gradlew bundleRelease ${gradle_firebase_arg} && cd .." || exit 5
if [ "$BUILD_MODE" = "production" ]; then
@@ -669,24 +683,24 @@ if [ "$BUILD_AAB" = true ]; then
fi
# Step 11: Auto-run app if requested
# cap run runs sync by default, which would overwrite capacitor.plugins.json again;
# we already synced and ran restore-local-plugins.js above, so skip sync here.
# Install and launch the APK built above with native-run (the tool cap run uses
# for its deploy step). Not `npx cap run android`: that always rebuilds with
# assembleDebug, which installs a debug build even after --release and drops
# -PfirebaseEnabled=false. With no target, native-run picks a hardware device,
# else a running emulator, else boots an AVD. ANDROID_SERIAL picks a target.
if [ "$AUTO_RUN" = true ]; then
log_step "Auto-running Android app..."
# With exactly one connected device, target it directly. Otherwise cap run
# shows an interactive picker, which without a terminal exits 0 having
# launched nothing, so fail instead of reporting a false success.
run_devices=$(adb devices | awk 'NR > 1 && $2 == "device" { print $1 }')
run_apk="android/app/build/outputs/apk/${BUILD_TYPE}/app-${BUILD_TYPE}.apk"
run_target=""
if [ "$(printf '%s\n' "$run_devices" | grep -c .)" = "1" ]; then
run_target="--target $run_devices"
elif [ ! -t 0 ]; then
log_error "Auto-run needs exactly one connected device when not run from a terminal (found: ${run_devices:-none})"
exit 9
if [ -n "$ANDROID_SERIAL" ]; then
run_target="--target $ANDROID_SERIAL"
fi
safe_execute "Launching app" "npx cap run android --no-sync $run_target" || {
if [ "$BUILD_TYPE" = "release" ]; then
log_info "Installing a release-signed APK over a debug-signed install fails; uninstall first if needed"
fi
safe_execute "Installing and launching $run_apk" "npx native-run android --app $run_apk $run_target" || {
log_error "Failed to launch Android app"
log_info "You can manually run with: npx cap run android --no-sync"
log_info "You can retry with: npx native-run android --app $run_apk"
exit 9
}
log_success "Android app launched successfully!"
@@ -701,11 +715,9 @@ fi
log_success "Android build completed successfully!"
log_info "Build mode: $BUILD_MODE"
log_info "Build type: $BUILD_TYPE"
if [ "$BUILD_APK" = true ]; then
log_info "APK build: completed"
fi
log_info "APK: android/app/build/outputs/apk/${BUILD_TYPE}/app-${BUILD_TYPE}.apk"
if [ "$BUILD_AAB" = true ]; then
log_info "AAB build: completed"
log_info "AAB: android/app/build/outputs/bundle/release/app-release.aab"
fi
if [ "$AUTO_RUN" = true ]; then
log_info "Auto-run: completed"
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env node
/**
* Fail when node_modules does not match package-lock.json.
*
* Compares the committed lockfile with npm's record of what is installed
* (node_modules/.package-lock.json). A release build packages whatever is in
* node_modules, so a lockfile pulled without `npm ci` (for example a newer
* daily-notification-plugin commit) would otherwise ship the stale install.
*
* Git dependencies are compared by resolved commit, registry packages by
* version. Optional packages missing from node_modules are skipped, since npm
* leaves out optional packages for other platforms.
*
* Usage: node scripts/check-installed-deps.js
* Fix a failure with: npm ci
*/
const fs = require('fs');
const path = require('path');
const root = path.join(__dirname, '..');
const lockPath = path.join(root, 'package-lock.json');
const installedPath = path.join(root, 'node_modules', '.package-lock.json');
if (!fs.existsSync(installedPath)) {
console.error('❌ node_modules/.package-lock.json not found. Run "npm ci".');
process.exit(1);
}
const locked = JSON.parse(fs.readFileSync(lockPath, 'utf8')).packages || {};
const installed = JSON.parse(fs.readFileSync(installedPath, 'utf8')).packages || {};
const problems = [];
for (const [pkgPath, want] of Object.entries(locked)) {
if (pkgPath === '' || !pkgPath.startsWith('node_modules/') || want.link) {
continue;
}
const have = installed[pkgPath];
const name = pkgPath.replace(/^.*node_modules\//, '');
if (!have) {
if (!want.optional && !want.devOptional && !want.peer) {
problems.push(`${name}: locked ${want.version}, not installed`);
}
continue;
}
if (want.resolved && want.resolved.startsWith('git+')) {
if (have.resolved !== want.resolved) {
const commit = (r) => (r || 'unknown').split('#').pop();
problems.push(`${name}: locked commit ${commit(want.resolved)}, installed ${commit(have.resolved)}`);
}
} else if (have.version !== want.version) {
problems.push(`${name}: locked ${want.version}, installed ${have.version}`);
}
}
if (problems.length > 0) {
console.error('❌ node_modules does not match package-lock.json:');
for (const p of problems) {
console.error(` ${p}`);
}
console.error(' Run "npm ci" (or commit the lockfile you meant to build with).');
process.exit(1);
}
console.log('✅ node_modules matches package-lock.json');