diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f5d43bb..9f3692f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -25,7 +25,10 @@ jobs: - name: install npm dependencies run: npm install - + + - name: build rxdb from source + run: bash scripts/build-rxdb.sh + - name: build code run: npm run build diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index eeb1a1e..0d59aca 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -38,7 +38,6 @@ jobs: with: path: | ~/.npm - ./node_modules key: ${{ runner.os }}-npm-core-x3-${{ hashFiles('**/package.json') }} restore-keys: | ${{ runner.os }}-npm-core-x3- @@ -46,6 +45,9 @@ jobs: - name: install npm dependencies run: npm install + - name: build rxdb from source + run: bash scripts/build-rxdb.sh + - name: build run: npm run build @@ -69,13 +71,14 @@ jobs: with: path: | ~/.npm - ./node_modules /tmp/.buildx-cache key: ${{ runner.os }}-npm-storage-dexie-x3-${{ hashFiles('**/package.json') }} restore-keys: | ${{ runner.os }}-npm-storage-dexie-x3- - run: npm install + - name: build rxdb from source + run: bash scripts/build-rxdb.sh - run: npm run test:integration:init - run: npm run test:integration:memory diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9044e0b..df9324a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,12 +27,13 @@ jobs: with: path: | ~/.npm - ./node_modules key: ${{ runner.os }}-npm-release-x2-${{ hashFiles('**/package.json') }} restore-keys: | ${{ runner.os }}-npm-release-x2- - run: npm install + - name: build rxdb from source + run: bash scripts/build-rxdb.sh - run: npm run build - name: Get version diff --git a/.github/workflows/update-rxdb.yml b/.github/workflows/update-rxdb.yml index 23b9ac0..d82977f 100644 --- a/.github/workflows/update-rxdb.yml +++ b/.github/workflows/update-rxdb.yml @@ -25,10 +25,10 @@ jobs: steps: - uses: actions/checkout@v6 - - name: Get current rxdb version from package.json + - name: Get current peer-deps rxdb version from package.json id: current run: | - CURRENT_VERSION=$(node -e "console.log(require('./package.json').devDependencies.rxdb)") + CURRENT_VERSION=$(node -e "console.log(require('./package.json').peerDependencies.rxdb)") echo "version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" - name: Get latest and next rxdb versions from npm @@ -39,6 +39,12 @@ jobs: echo "latest=$LATEST_VERSION" >> "$GITHUB_OUTPUT" echo "next=$NEXT_VERSION" >> "$GITHUB_OUTPUT" + - name: Get latest commit hash from rxdb master + id: hash + run: | + COMMIT_HASH=$(git ls-remote https://github.com/pubkey/rxdb.git refs/heads/master | cut -f1) + echo "commit=$COMMIT_HASH" >> "$GITHUB_OUTPUT" + - name: Determine target version id: target run: | @@ -66,23 +72,36 @@ jobs: fi echo "version=$TARGET" >> "$GITHUB_OUTPUT" + - name: Get current commit hash from package.json + id: current_hash + run: | + CURRENT_HASH=$(node -e " + const dep = require('./package.json').devDependencies.rxdb; + const match = dep.match(/\/archive\/([a-f0-9]+)\.tar\.gz$/); + console.log(match ? match[1] : ''); + ") + echo "commit=$CURRENT_HASH" >> "$GITHUB_OUTPUT" + - name: Update package.json - if: steps.target.outputs.changed == 'true' + if: steps.target.outputs.changed == 'true' || steps.hash.outputs.commit != steps.current_hash.outputs.commit run: | TARGET="${{ steps.target.outputs.version }}" + COMMIT="${{ steps.hash.outputs.commit }}" node -e " const fs = require('fs'); const pkg = JSON.parse(fs.readFileSync('./package.json', 'utf-8')); - pkg.devDependencies.rxdb = '$TARGET'; + pkg.peerDependencies.rxdb = '$TARGET'; + pkg.devDependencies.rxdb = 'https://github.com/pubkey/rxdb/archive/$COMMIT.tar.gz'; fs.writeFileSync('./package.json', JSON.stringify(pkg, null, 2) + '\n', 'utf-8'); " - name: Commit and push - if: steps.target.outputs.changed == 'true' + if: steps.target.outputs.changed == 'true' || steps.hash.outputs.commit != steps.current_hash.outputs.commit run: | TARGET="${{ steps.target.outputs.version }}" + COMMIT="${{ steps.hash.outputs.commit }}" git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" git config --local user.name "github-actions[bot]" git add package.json - git commit -m "chore: update rxdb to $TARGET" + git commit -m "chore: update rxdb to $TARGET (master: ${COMMIT:0:7})" git push diff --git a/package.json b/package.json index 9cf4edf..c8e7ad3 100644 --- a/package.json +++ b/package.json @@ -73,7 +73,7 @@ "test:integration:mongodb": "(cd test-integration && npm run transpile && npm run test:node:mongodb)" }, "peerDependencies": { - "rxdb": "*", + "rxdb": "17.1.0", "rxjs": "*" }, "dependencies": { @@ -131,7 +131,7 @@ "minify-all-js": "0.1.9", "mocha": "11.7.5", "rimraf": "6.1.3", - "rxdb": "17.1.0", + "rxdb": "https://github.com/pubkey/rxdb/archive/7a251701bbffefde18c360013c82148746dff5cb.tar.gz", "rxjs": "7.8.2", "ts-loader": "9.5.7", "ts-node": "10.9.2", diff --git a/scripts/build-rxdb.sh b/scripts/build-rxdb.sh new file mode 100644 index 0000000..9befbdb --- /dev/null +++ b/scripts/build-rxdb.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -e + +# When rxdb is installed from a GitHub tarball, dist/ is not included +# (it's gitignored in the rxdb repo). We install devDependencies, then build. +RXDB_DIR="node_modules/rxdb" + +if [ ! -d "$RXDB_DIR" ]; then + echo "Error: $RXDB_DIR does not exist" + exit 1 +fi + +cd "$RXDB_DIR" + +# Install all devDependencies of rxdb so the build can succeed +npm install + +# Deduplicate: remove nested packages that already exist at the root +# node_modules with the same version. This prevents TypeScript from +# generating non-portable paths like 'rxdb/node_modules/mingo/types' +# during declaration emit (TS2742). +cd .. +for nested in rxdb/node_modules/*/; do + pkg=$(basename "$nested") + if [ -d "$pkg" ]; then + nested_ver=$(node -p "try{require('./rxdb/node_modules/$pkg/package.json').version}catch(e){''}" 2>/dev/null) + root_ver=$(node -p "try{require('./$pkg/package.json').version}catch(e){''}" 2>/dev/null) + if [ -n "$nested_ver" ] && [ "$nested_ver" = "$root_ver" ]; then + rm -rf "$nested" + fi + fi +done +cd rxdb + +npm run build diff --git a/scripts/extract-rxdb-version.sh b/scripts/extract-rxdb-version.sh index 1026eaa..675bda9 100644 --- a/scripts/extract-rxdb-version.sh +++ b/scripts/extract-rxdb-version.sh @@ -1,10 +1,4 @@ #!/bin/bash set -e -RXDB_VERSION=$(cat ../package.json \ - | grep '"rxdb":' \ - | tail -1 \ - | awk -F: '{ print $2 }' \ - | sed 's/[",]//g' \ - | sed -e 's/^[[:space:]]*//' -) +RXDB_VERSION=$(node -e "console.log(require('../package.json').peerDependencies.rxdb)") diff --git a/scripts/test-integration-init.sh b/scripts/test-integration-init.sh index 8567457..1a1b87b 100644 --- a/scripts/test-integration-init.sh +++ b/scripts/test-integration-init.sh @@ -35,7 +35,7 @@ npm install npm install rxdb@$RXDB_VERSION npm install ./rxdb-server.tgz -(cd ./node_modules/rxdb-server/ && npm i) +(cd ./node_modules/rxdb-server/ && npm i --omit=dev) npm run build diff --git a/scripts/version.js b/scripts/version.js index e04116f..8e3156f 100644 --- a/scripts/version.js +++ b/scripts/version.js @@ -7,7 +7,7 @@ const fs = require('node:fs'); const packageJSON = require('../package.json'); -packageJSON.version = packageJSON.devDependencies.rxdb; +packageJSON.version = packageJSON.peerDependencies.rxdb; fs.writeFileSync('./package.json', JSON.stringify(packageJSON, null, 2), 'utf-8'); -console.log(packageJSON.devDependencies.rxdb); +console.log(packageJSON.peerDependencies.rxdb);