diff --git a/.github/workflows/ci-supabase-js.yml b/.github/workflows/ci-supabase-js.yml index e35fe394e..309a59f32 100644 --- a/.github/workflows/ci-supabase-js.yml +++ b/.github/workflows/ci-supabase-js.yml @@ -20,10 +20,8 @@ env: jobs: build-package: - name: Build supabase-js package + name: Build all packages runs-on: ubuntu-latest - outputs: - tgz-name: ${{ steps.pack.outputs.filename }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -41,22 +39,20 @@ jobs: - uses: nrwl/nx-set-shas@v4 - - name: Build - run: npx nx build supabase-js + - name: Build all packages + run: npx nx run-many --target=build --all - - name: Pack npm module - id: pack - run: | - cd packages/core/supabase-js - PKG=$(npm pack) - echo "filename=$PKG" >> "$GITHUB_OUTPUT" - cd ../../.. - - - name: Upload .tgz package + - name: Upload built packages uses: actions/upload-artifact@v4 with: - name: supabase-tgz - path: packages/core/supabase-js/${{ steps.pack.outputs.filename }} + name: packages-dist + path: | + packages/core/auth-js/dist + packages/core/functions-js/dist + packages/core/postgrest-js/dist + packages/core/realtime-js/dist + packages/core/storage-js/dist + packages/core/supabase-js/dist - name: Upload UMD build uses: actions/upload-artifact@v4 @@ -147,11 +143,26 @@ jobs: with: node-version: ${{ env.NODE_VERSION }} cache: 'npm' - - name: Download artifact + + - name: Download built packages uses: actions/download-artifact@v4 with: - name: supabase-tgz - path: ./packages/core/supabase-js/supabase-pkg + name: packages-dist + path: packages/core + + - name: Install dependencies + run: npm ci --legacy-peer-deps + + - name: Start Verdaccio + run: | + npx verdaccio --config .verdaccio/config.yml & + sleep 3 + + - name: Configure npm auth for Verdaccio + run: npm config set //localhost:4873/:_authToken "secretVerdaccioToken" + + - name: Publish packages to Verdaccio + run: node scripts/populate-verdaccio.mjs - name: Start Supabase and apply migrations run: | @@ -169,29 +180,35 @@ jobs: echo "Verifying storage bucket exists" supabase db query "select id, name from storage.buckets where id = 'test-bucket';" - - name: Install dependencies and build + - name: Verify packages in Verdaccio run: | - npm ci --legacy-peer-deps - npx nx build supabase-js + echo "Verifying @supabase/supabase-js is available in Verdaccio..." + npm view @supabase/supabase-js version --registry http://localhost:4873 + npm view @supabase/supabase-js --registry http://localhost:4873 | head -20 - - name: Run Deno Tests + - name: Run Deno Tests (1.x) if: ${{ matrix.deno == '1.x' }} env: STORAGE_JS_ENTRY: main + DENO_NPM_REGISTRY: http://localhost:4873 run: | cd packages/core/supabase-js/test/deno - cp ../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz . + echo "registry=http://localhost:4873/" > .npmrc npm install npm test || npm test + rm -f .npmrc cd ../../.. - - name: Run Deno Tests + - name: Run Deno Tests (2.x) if: ${{ matrix.deno == '2.x' }} + env: + DENO_NPM_REGISTRY: http://localhost:4873 run: | cd packages/core/supabase-js/test/deno - cp ../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz . + echo "registry=http://localhost:4873/" > .npmrc npm install npm test || npm test + rm -f .npmrc cd ../../.. - name: Run integration and browser tests on Deno 2.x only @@ -286,17 +303,31 @@ jobs: node-version: ${{ env.NODE_VERSION }} cache: 'npm' - - name: Download artifact - uses: actions/download-artifact@v4 - with: - name: supabase-tgz - path: ./packages/core/supabase-js/supabase-pkg - - name: Setup Supabase CLI uses: supabase/setup-cli@v1 with: version: latest + - name: Download built packages + uses: actions/download-artifact@v4 + with: + name: packages-dist + path: packages/core + + - name: Install dependencies + run: npm ci --legacy-peer-deps + + - name: Start Verdaccio + run: | + npx verdaccio --config .verdaccio/config.yml & + sleep 3 + + - name: Configure npm auth for Verdaccio + run: npm config set //localhost:4873/:_authToken "secretVerdaccioToken" + + - name: Publish packages to Verdaccio + run: node scripts/populate-verdaccio.mjs + - name: Start Supabase and apply migrations run: | cd packages/core/supabase-js @@ -316,13 +347,23 @@ jobs: - name: Install Playwright browsers and dependencies run: npx playwright install --with-deps - - name: Run integration tests + - name: Verify packages in Verdaccio + run: | + echo "Verifying @supabase/supabase-js is available in Verdaccio..." + npm view @supabase/supabase-js version --registry http://localhost:4873 + npm view @supabase/supabase-js --registry http://localhost:4873 | head -20 + + - name: Run integration tests in isolation run: | - cd packages/core/supabase-js/test/integration/next - cp ../../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz . + TEST_DIR="/tmp/test-next-${{ github.run_id }}" + mkdir -p "$TEST_DIR" + cp -r packages/core/supabase-js/test/integration/next/* "$TEST_DIR/" + cd "$TEST_DIR" + echo "registry=http://localhost:4873/" > .npmrc npm install --legacy-peer-deps npx playwright install npm run test + rm -f .npmrc - name: Stop Supabase if: always() @@ -352,11 +393,25 @@ jobs: with: version: latest - - name: Download artifact + - name: Download built packages uses: actions/download-artifact@v4 with: - name: supabase-tgz - path: ./packages/core/supabase-js/supabase-pkg + name: packages-dist + path: packages/core + + - name: Install dependencies + run: npm ci --legacy-peer-deps + + - name: Start Verdaccio + run: | + npx verdaccio --config .verdaccio/config.yml & + sleep 3 + + - name: Configure npm auth for Verdaccio + run: npm config set //localhost:4873/:_authToken "secretVerdaccioToken" + + - name: Publish packages to Verdaccio + run: node scripts/populate-verdaccio.mjs - name: Start Supabase and apply migrations run: | @@ -374,12 +429,22 @@ jobs: echo "Verifying storage bucket exists" supabase db query "select id, name from storage.buckets where id = 'test-bucket';" - - name: Install dependencies and run tests + - name: Verify packages in Verdaccio run: | - cd packages/core/supabase-js/test/integration/expo - cp ../../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz . + echo "Verifying @supabase/supabase-js is available in Verdaccio..." + npm view @supabase/supabase-js version --registry http://localhost:4873 + npm view @supabase/supabase-js --registry http://localhost:4873 | head -20 + + - name: Install test dependencies and run tests in isolation + run: | + TEST_DIR="/tmp/test-expo-${{ github.run_id }}" + mkdir -p "$TEST_DIR" + cp -r packages/core/supabase-js/test/integration/expo/* "$TEST_DIR/" + cd "$TEST_DIR" + echo "registry=http://localhost:4873/" > .npmrc npm install - npm test || npm test + npm test + rm -f .npmrc - name: Stop Supabase if: always() @@ -403,16 +468,36 @@ jobs: with: bun-version: latest + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'npm' + - name: Setup Supabase CLI uses: supabase/setup-cli@v1 with: version: latest - - name: Download artifact + - name: Download built packages uses: actions/download-artifact@v4 with: - name: supabase-tgz - path: ./packages/core/supabase-js/supabase-pkg + name: packages-dist + path: packages/core + + - name: Install dependencies + run: npm ci --legacy-peer-deps + + - name: Start Verdaccio + run: | + npx verdaccio --config .verdaccio/config.yml & + sleep 3 + + - name: Configure npm auth for Verdaccio + run: npm config set //localhost:4873/:_authToken "secretVerdaccioToken" + + - name: Publish packages to Verdaccio + run: node scripts/populate-verdaccio.mjs - name: Start Supabase and apply migrations run: | @@ -430,12 +515,22 @@ jobs: echo "Verifying storage bucket exists" supabase db query "select id, name from storage.buckets where id = 'test-bucket';" - - name: Install dependencies and run tests + - name: Verify packages in Verdaccio + run: | + echo "Verifying @supabase/supabase-js is available in Verdaccio..." + npm view @supabase/supabase-js version --registry http://localhost:4873 + npm view @supabase/supabase-js --registry http://localhost:4873 | head -20 + + - name: Install dependencies and run tests in isolation run: | - cd packages/core/supabase-js/test/integration/bun - cp ../../../supabase-pkg/supabase-supabase-js-0.0.0-automated.tgz . + TEST_DIR="/tmp/test-bun-${{ github.run_id }}" + mkdir -p "$TEST_DIR" + cp -r packages/core/supabase-js/test/integration/bun/* "$TEST_DIR/" + cd "$TEST_DIR" + echo "registry=http://localhost:4873/" > .npmrc bun install bun test + rm -f .npmrc - name: Stop Supabase if: always() diff --git a/packages/core/supabase-js/test/deno/package.json b/packages/core/supabase-js/test/deno/package.json index 0ed684bed..102cb44dd 100644 --- a/packages/core/supabase-js/test/deno/package.json +++ b/packages/core/supabase-js/test/deno/package.json @@ -7,6 +7,6 @@ "setup-deps": "node setup-deps.js" }, "dependencies": { - "@supabase/supabase-js": "file:supabase-supabase-js-0.0.0-automated.tgz" + "@supabase/supabase-js": "*" } } diff --git a/packages/core/supabase-js/test/integration/bun/package.json b/packages/core/supabase-js/test/integration/bun/package.json index 03a2714a4..4789c82fd 100644 --- a/packages/core/supabase-js/test/integration/bun/package.json +++ b/packages/core/supabase-js/test/integration/bun/package.json @@ -6,7 +6,7 @@ "test:watch": "bun test --watch integration.test.ts" }, "dependencies": { - "@supabase/supabase-js": "file:supabase-supabase-js-0.0.0-automated.tgz" + "@supabase/supabase-js": "*" }, "devDependencies": { "bun-types": "latest" diff --git a/packages/core/supabase-js/test/integration/expo/package.json b/packages/core/supabase-js/test/integration/expo/package.json index 43da41494..ce8da7291 100644 --- a/packages/core/supabase-js/test/integration/expo/package.json +++ b/packages/core/supabase-js/test/integration/expo/package.json @@ -16,7 +16,7 @@ "@react-navigation/bottom-tabs": "^7.3.10", "@react-navigation/elements": "^2.3.8", "@react-navigation/native": "^7.1.6", - "@supabase/supabase-js": "file:supabase-supabase-js-0.0.0-automated.tgz", + "@supabase/supabase-js": "*", "expo": "~53.0.9", "expo-blur": "~14.1.4", "expo-constants": "~17.1.6", diff --git a/packages/core/supabase-js/test/integration/next/package.json b/packages/core/supabase-js/test/integration/next/package.json index c041c5f60..02f46f779 100644 --- a/packages/core/supabase-js/test/integration/next/package.json +++ b/packages/core/supabase-js/test/integration/next/package.json @@ -17,7 +17,7 @@ "@radix-ui/react-label": "^2.1.6", "@radix-ui/react-slot": "^1.2.2", "@supabase/ssr": "latest", - "@supabase/supabase-js": "file:supabase-supabase-js-0.0.0-automated.tgz", + "@supabase/supabase-js": "*", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "lucide-react": "^0.511.0", diff --git a/project.json b/project.json new file mode 100644 index 000000000..6937e63a8 --- /dev/null +++ b/project.json @@ -0,0 +1,23 @@ +{ + "name": "supabase-js-workspace", + "$schema": "node_modules/nx/schemas/project-schema.json", + "projectType": "library", + "targets": { + "local-registry": { + "executor": "@nx/js:verdaccio", + "options": { + "port": 4873, + "config": ".verdaccio/config.yml", + "storage": "tmp/local-registry/storage", + "clear": false + } + }, + "populate-local-registry": { + "executor": "nx:run-commands", + "options": { + "command": "node scripts/populate-verdaccio.mjs" + }, + "dependsOn": ["local-registry"] + } + } +} diff --git a/scripts/populate-verdaccio.mjs b/scripts/populate-verdaccio.mjs new file mode 100644 index 000000000..3a620cda3 --- /dev/null +++ b/scripts/populate-verdaccio.mjs @@ -0,0 +1,116 @@ +#!/usr/bin/env node +/** + * Publishes pre-built packages to local Verdaccio registry for integration testing. + * + * This script: + * 1. Waits for Verdaccio to be ready + * 2. Publishes each pre-built package to the local registry + * 3. Fails fast on any error + * + * Note: Packages must be built before running this script. + */ + +import { exec } from 'node:child_process'; +import { promisify } from 'node:util'; + +const execAsync = promisify(exec); + +const VERDACCIO_PORT = process.env.VERDACCIO_PORT || '4873'; +const REGISTRY_URL = `http://localhost:${VERDACCIO_PORT}`; +const MAX_WAIT_TIME = 60000; // 60 seconds +const POLL_INTERVAL = 500; // 500ms + +// Packages to publish in dependency order +const PACKAGES = [ + 'auth-js', + 'postgrest-js', + 'realtime-js', + 'storage-js', + 'functions-js', + 'supabase-js', +]; + +/** + * Waits for Verdaccio to be ready by polling the health endpoint + */ +async function waitForVerdaccio() { + const startTime = Date.now(); + + while (Date.now() - startTime < MAX_WAIT_TIME) { + try { + const response = await fetch(REGISTRY_URL); + if (response.ok) { + console.log(`āœ“ Verdaccio is ready at ${REGISTRY_URL}`); + return; + } + } catch (error) { + // Verdaccio not ready yet, continue polling + } + + await new Promise(resolve => setTimeout(resolve, POLL_INTERVAL)); + } + + throw new Error(`Verdaccio failed to start within ${MAX_WAIT_TIME}ms at ${REGISTRY_URL}`); +} + +/** + * Publishes a single package to Verdaccio + */ +async function publishPackage(packageName) { + const packagePath = `packages/core/${packageName}`; + + console.log(` Publishing @supabase/${packageName}...`); + + try { + const { stdout } = await execAsync( + `npm publish --registry ${REGISTRY_URL} --access public`, + { + cwd: packagePath, + maxBuffer: 10 * 1024 * 1024, + env: { + ...process.env, + npm_config_registry: REGISTRY_URL, + }, + } + ); + + console.log(` āœ“ @supabase/${packageName} published`); + } catch (error) { + console.error(` āœ— Failed to publish @supabase/${packageName}:`, error.message); + if (error.stdout) console.log(error.stdout); + if (error.stderr) console.error(error.stderr); + throw error; + } +} + +/** + * Publishes all packages to Verdaccio + */ +async function publishPackages() { + console.log(`\nšŸ“¤ Publishing packages to ${REGISTRY_URL}...`); + + for (const pkg of PACKAGES) { + await publishPackage(pkg); + } + + console.log('\nāœ“ All packages published successfully'); +} + +/** + * Main execution + */ +async function main() { + try { + console.log('šŸš€ Publishing packages to Verdaccio...\n'); + + await waitForVerdaccio(); + await publishPackages(); + + console.log('\nāœ… All packages published to Verdaccio successfully'); + } catch (error) { + console.error('\nāŒ Failed to publish to Verdaccio:', error.message); + process.exit(1); + } +} + +main();