Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
],
"commit": false,
"ignore": [],
"fixed": [],
"fixed": [
[
"@clerk/electron-passkeys",
"@clerk/electron-passkeys-darwin-arm64",
"@clerk/electron-passkeys-darwin-x64",
"@clerk/electron-passkeys-win32-arm64-msvc",
"@clerk/electron-passkeys-win32-x64-msvc"
]
],
Comment on lines +11 to +19

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all five packages must publish at the same version number. The four platform packages are optionalDependencies of the wrapper at an exact version, and napi-rs's native loader matches the .node binary by the package version it was built with

"linked": [],
"access": "public",
"baseBranch": "origin/main",
Expand Down
5 changes: 5 additions & 0 deletions .changeset/electron-passkeys-native-binaries.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@clerk/electron-passkeys': patch
---

Introduce native passkey (WebAuthn) support for Clerk's Electron SDK, with prebuilt binaries for macOS (arm64 and x64) and Windows (arm64 and x64). Installing the package automatically pulls in the matching platform binary, so passkeys work without a local build toolchain.
113 changes: 113 additions & 0 deletions .github/workflows/electron-passkeys.yml

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this workflow builds the native Rust addon for @clerk/electron-passkeys, then assembles the per-platform npm packages and uploads them as a single artifact. It's called by release.yml when a version bump to @clerk/electron-passkeys is detected

Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
name: Electron Passkeys Native Build

on:
workflow_call:
workflow_dispatch:
pull_request:
paths:
- 'packages/electron-passkeys/**'
- '.github/workflows/electron-passkeys.yml'

permissions:
contents: read
actions: read

concurrency:
group: electron-passkeys-${{ github.head_ref || github.ref }}
cancel-in-progress: true

permissions:
contents: read
Comment on lines +11 to +20

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Duplicate permissions key causes YAML syntax error.

The workflow defines permissions twice (lines 11-12 and 19-20), which violates YAML syntax and will cause the workflow to fail parsing.

🐛 Proposed fix

Remove the duplicate permissions block:

 permissions:
   contents: read
   actions: read

 concurrency:
   group: electron-passkeys-${{ github.head_ref || github.ref }}
   cancel-in-progress: true

-permissions:
-  contents: read
-
 jobs:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
permissions:
contents: read
actions: read
concurrency:
group: electron-passkeys-${{ github.head_ref || github.ref }}
cancel-in-progress: true
permissions:
contents: read
permissions:
contents: read
actions: read
concurrency:
group: electron-passkeys-${{ github.head_ref || github.ref }}
cancel-in-progress: true
jobs:
🧰 Tools
🪛 actionlint (1.7.12)

[error] 19-19: key "permissions" is duplicated in "workflow" section. previously defined at line:11,col:1

(syntax-check)

🪛 YAMLlint (1.37.1)

[error] 19-19: duplication of key "permissions" in mapping

(key-duplicates)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/electron-passkeys.yml around lines 11 - 20, The workflow
file has a duplicate permissions key defined in the YAML structure, which causes
a parsing error. Remove the second permissions block that only contains
contents: read and keep only the first permissions block that includes both
contents: read and actions: read. This will resolve the YAML syntax error and
allow the workflow to parse correctly.

Source: Linters/SAST tools


jobs:
build:
name: Build ${{ matrix.settings.target }}
runs-on: ${{ matrix.settings.host }}
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
settings:
- host: macos-14
target: aarch64-apple-darwin
- host: macos-14
target: x86_64-apple-darwin
- host: windows-latest
target: x86_64-pc-windows-msvc
- host: windows-latest
target: aarch64-pc-windows-msvc
defaults:
run:
working-directory: packages/electron-passkeys
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 24

- uses: pnpm/action-setup@v4

- uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.settings.target }}

- uses: Swatinem/rust-cache@v2
with:
workspaces: packages/electron-passkeys

- name: Install dependencies
run: pnpm install --filter @clerk/electron-passkeys... --frozen-lockfile --ignore-scripts
working-directory: .

- name: Build native module
run: pnpm build:native --target ${{ matrix.settings.target }}

- name: Smoke test (host-native targets only)
if: matrix.settings.target == 'aarch64-apple-darwin' || matrix.settings.target == 'x86_64-pc-windows-msvc'
run: node -e "const m = require('./index.js'); console.log('isAvailable:', m.isAvailable(), 'capabilities:', JSON.stringify(m.capabilities())); if (!m.isAvailable()) throw new Error('the loader did not find the freshly built native binary');"

- uses: actions/upload-artifact@v4
with:
name: bindings-${{ matrix.settings.target }}
path: packages/electron-passkeys/electron-passkeys.*.node
if-no-files-found: error

package:
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
name: Assemble platform packages
needs: build
runs-on: blacksmith-8vcpu-ubuntu-2204
timeout-minutes: 10
defaults:
run:
working-directory: packages/electron-passkeys
steps:
- uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: 24

- uses: pnpm/action-setup@v4

- name: Install dependencies
run: pnpm install --filter @clerk/electron-passkeys... --frozen-lockfile --ignore-scripts
working-directory: .

- uses: actions/download-artifact@v4
with:
path: packages/electron-passkeys/artifacts

- name: Move binaries into per-platform npm packages
run: pnpm artifacts

- name: Verify every platform package contains its binary
run: node scripts/check-electron-passkeys-binaries.mjs packages/electron-passkeys/npm
working-directory: .

- name: Upload assembled platform binaries
uses: actions/upload-artifact@v4
with:
name: electron-passkeys-npm
path: packages/electron-passkeys/npm/**/*.node
if-no-files-found: error
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Fixed
51 changes: 50 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,47 @@ concurrency:
cancel-in-progress: true

jobs:
detect-native:
name: Detect electron-passkeys publish
if: ${{ github.event_name == 'push' && github.repository == 'clerk/javascript' }}
runs-on: ${{ vars.RUNNER_NORMAL || 'ubuntu-latest' }}
timeout-minutes: 5
permissions:
contents: read
outputs:
should-build: ${{ steps.detect.outputs.should-build }}
steps:
- name: Checkout repo
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
persist-credentials: false
fetch-depth: 1
fetch-tags: false
filter: 'blob:none'
show-progress: false

- name: Determine whether electron-passkeys is about to publish
id: detect
run: node scripts/detect-electron-passkeys-publish.mjs >> "$GITHUB_OUTPUT"

build-native:
name: Build electron-passkeys native binaries
needs: detect-native
if: ${{ needs.detect-native.outputs.should-build == 'true' }}
permissions:
contents: read
uses: ./.github/workflows/electron-passkeys.yml
Comment on lines +46 to +52

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

Workflow call will fail due to syntax error in electron-passkeys.yml.

The reusable workflow .github/workflows/electron-passkeys.yml contains a duplicate permissions key (already flagged in that file), which will cause this workflow call to fail during YAML parsing.

This will be resolved once the duplicate permissions block is removed from electron-passkeys.yml.

🧰 Tools
🪛 actionlint (1.7.12)

[error] 52-52: error while parsing reusable workflow "./.github/workflows/electron-passkeys.yml": yaml: unmarshal errors: line 19: mapping key "permissions" already defined at line 11

(workflow-call)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In @.github/workflows/release.yml around lines 46 - 52, Navigate to the
`.github/workflows/electron-passkeys.yml` reusable workflow file and locate the
duplicate `permissions` key that is causing the YAML parsing error. Remove one
of the duplicate `permissions` blocks so that only a single `permissions`
definition remains in the file. This will resolve the syntax error and allow the
workflow call in the build-native job to execute successfully.

Source: Linters/SAST tools


release:
name: Release
if: ${{ github.event_name == 'push' && github.repository == 'clerk/javascript' }}
needs: [detect-native, build-native]
if: >-
always()
&& github.event_name == 'push'
&& github.repository == 'clerk/javascript'
&& needs.detect-native.result == 'success'
&& needs.build-native.result != 'failure'
&& needs.build-native.result != 'cancelled'
runs-on: ${{ vars.RUNNER_NORMAL || 'ubuntu-latest' }}
timeout-minutes: ${{ vars.TIMEOUT_MINUTES_NORMAL && fromJSON(vars.TIMEOUT_MINUTES_NORMAL) || 10 }}

Expand Down Expand Up @@ -67,6 +105,17 @@ jobs:
- name: Build release
run: pnpm turbo build $TURBO_ARGS --force

- name: Download electron-passkeys native binaries
if: ${{ needs.detect-native.outputs.should-build == 'true' }}
uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093 # v4
with:
name: electron-passkeys-npm
path: packages/electron-passkeys/npm
Comment on lines +108 to +113

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binaries land here before changesets/action runs so npm publish picks themup


- name: Verify electron-passkeys binaries are present
if: ${{ needs.detect-native.outputs.should-build == 'true' }}
run: node scripts/check-electron-passkeys-binaries.mjs packages/electron-passkeys/npm

- name: Create Release PR
id: changesets
uses: changesets/action@63a615b9cd06ba9a3e6d13796c7fbcb080a60a0b # v1
Expand Down
12 changes: 10 additions & 2 deletions scripts/canary.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import { $, echo } from 'zx';

import { constants, getChangesetIgnoredPackages, getPackageNames, pinWorkspaceDeps } from './common.mjs';
import {
constants,
getChangesetIgnoredPackages,
getPackageNames,
isElectronPasskeysPackage,
pinWorkspaceDeps,
} from './common.mjs';

const ignoredPackages = await getChangesetIgnoredPackages();
const packageNames = (await getPackageNames()).filter(name => !ignoredPackages.has(name));
const packageNames = (await getPackageNames()).filter(
name => !ignoredPackages.has(name) && !isElectronPasskeysPackage(name),
);
const packageEntries = packageNames.map(name => `'${name}': patch`).join('\n');

const snapshot = `---
Expand Down
46 changes: 46 additions & 0 deletions scripts/check-electron-passkeys-binaries.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env node

import { readdir } from 'node:fs/promises';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

export const DEFAULT_NPM_DIR = 'packages/electron-passkeys/npm';

export async function findMissingBinaries(npmDir) {
const entries = await readdir(npmDir, { withFileTypes: true });
const platformDirs = entries.filter(entry => entry.isDirectory()).sort((a, b) => a.name.localeCompare(b.name));
const missing = [];

for (const platformDir of platformDirs) {
const dir = resolve(npmDir, platformDir.name);
const files = await readdir(dir, { withFileTypes: true });
const count = files.filter(file => file.isFile() && file.name.endsWith('.node')).length;

if (count !== 1) {
missing.push({ dir, count });
}
}

return missing;
}

async function main() {
const npmDir = process.argv[2] || DEFAULT_NPM_DIR;
const missing = await findMissingBinaries(npmDir);

if (missing.length > 0) {
for (const { dir, count } of missing) {
console.error(
`::error::${dir} has ${count} .node binaries (expected exactly 1); publishing it would ship an empty package`,
);
}

process.exit(1);
}

console.log('All electron-passkeys platform packages contain exactly one .node binary.');
}

if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
await main();
Comment on lines +27 to +45

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Handle CLI read errors explicitly and fix inaccurate failure text.

If findMissingBinaries() throws (e.g., missing/unreadable directory), the script currently fails with an unhandled rejection instead of a GitHub annotation. Also, Line 34 always says “empty package,” which is incorrect when count > 1.

Suggested patch
 async function main() {
-  const npmDir = process.argv[2] || DEFAULT_NPM_DIR;
-  const missing = await findMissingBinaries(npmDir);
+  const npmDir = process.argv[2] || DEFAULT_NPM_DIR;
+  let missing;
+  try {
+    missing = await findMissingBinaries(npmDir);
+  } catch (error) {
+    const message = error instanceof Error ? error.message : String(error);
+    console.error(`::error::Failed to scan ${npmDir}: ${message}`);
+    process.exit(1);
+  }

   if (missing.length > 0) {
     for (const { dir, count } of missing) {
       console.error(
-        `::error::${dir} has ${count} .node binaries (expected exactly 1); publishing it would ship an empty package`,
+        count === 0
+          ? `::error::${dir} has 0 .node binaries (expected exactly 1); publishing it would ship an empty package`
+          : `::error::${dir} has ${count} .node binaries (expected exactly 1); publishing it would ship an invalid package`,
       );
     }

     process.exit(1);
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/check-electron-passkeys-binaries.mjs` around lines 27 - 45, The main
function lacks error handling for the findMissingBinaries call, which means any
thrown errors will result in unhandled rejections instead of GitHub annotations.
Wrap the await findMissingBinaries(npmDir) call in a try-catch block and use
console.error with the ::error:: format to report caught exceptions.
Additionally, the error message template is inaccurate as it always says "empty
package" regardless of the count value; update the message logic to correctly
indicate that the issue is having an incorrect number of binaries (not exactly
1), adjusting the text appropriately when count is greater than 1 versus when
count is 0.

}
52 changes: 52 additions & 0 deletions scripts/check-electron-passkeys-binaries.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
import { tmpdir } from 'node:os';
import { join } from 'node:path';

import { afterEach, describe, expect, test } from 'vitest';

import { findMissingBinaries } from './check-electron-passkeys-binaries.mjs';

const roots = [];

async function createRoot() {
const root = await mkdtemp(join(tmpdir(), 'electron-passkeys-binaries-'));
roots.push(root);
return root;
}

async function createPlatformDir(root, name, nodeFiles) {
const dir = join(root, name);
await mkdir(dir, { recursive: true });

await Promise.all(nodeFiles.map(file => writeFile(join(dir, file), '')));

return dir;
}

afterEach(async () => {
await Promise.all(roots.splice(0).map(root => rm(root, { force: true, recursive: true })));
});

describe('findMissingBinaries', () => {
test('returns [] when every platform dir has exactly one .node', async () => {
const root = await createRoot();
await createPlatformDir(root, 'darwin-arm64', ['passkeys.node']);
await createPlatformDir(root, 'linux-x64', ['passkeys.node']);

await expect(findMissingBinaries(root)).resolves.toEqual([]);
});

test('flags a dir with no .node files', async () => {
const root = await createRoot();
await createPlatformDir(root, 'darwin-arm64', ['README.md']);

await expect(findMissingBinaries(root)).resolves.toEqual([{ dir: join(root, 'darwin-arm64'), count: 0 }]);
});

test('flags a dir with more than one .node file', async () => {
const root = await createRoot();
await createPlatformDir(root, 'darwin-arm64', ['passkeys.node', 'other.node']);

await expect(findMissingBinaries(root)).resolves.toEqual([{ dir: join(root, 'darwin-arm64'), count: 2 }]);
});
});
4 changes: 4 additions & 0 deletions scripts/common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export async function getPackageNames() {
return packageNames.sort();
}

export function isElectronPasskeysPackage(name) {
return name === '@clerk/electron-passkeys' || name.startsWith('@clerk/electron-passkeys-');
}

/**
* Converts `workspace:^` to `workspace:*` for all @clerk/* dependencies.
* This ensures that snapshot/canary releases use exact versions instead of
Expand Down
39 changes: 39 additions & 0 deletions scripts/detect-electron-passkeys-publish.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env node

import { execFile } from 'node:child_process';
import { readFile } from 'node:fs/promises';
import { resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import { promisify } from 'node:util';

const execFileAsync = promisify(execFile);

const WRAPPER_PACKAGE = '@clerk/electron-passkeys';
const WRAPPER_MANIFEST = 'packages/electron-passkeys/package.json';

async function readInTreeVersion() {
const manifest = JSON.parse(await readFile(WRAPPER_MANIFEST, 'utf8'));
return manifest.version;
}

async function readLatestPublishedVersion() {
try {
const { stdout } = await execFileAsync('npm', ['view', WRAPPER_PACKAGE, 'version']);
return stdout.trim();
} catch {
return '';
}
}

async function main() {
const inTreeVersion = await readInTreeVersion();
const latestPublishedVersion = await readLatestPublishedVersion();
// npm versions are immutable, so a differing in-tree version means a publish is pending and needs binaries.
const shouldBuild = inTreeVersion !== latestPublishedVersion;

console.log(`should-build=${shouldBuild}`);
}

if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
await main();
}
12 changes: 10 additions & 2 deletions scripts/snapshot.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

import { $, argv, echo } from 'zx';

import { constants, getChangesetIgnoredPackages, getPackageNames, pinWorkspaceDeps } from './common.mjs';
import {
constants,
getChangesetIgnoredPackages,
getPackageNames,
isElectronPasskeysPackage,
pinWorkspaceDeps,
} from './common.mjs';

const ignoredPackages = await getChangesetIgnoredPackages();
const packageNames = (await getPackageNames()).filter(name => !ignoredPackages.has(name));
const packageNames = (await getPackageNames()).filter(
name => !ignoredPackages.has(name) && !isElectronPasskeysPackage(name),
);
const packageEntries = packageNames.map(name => `'${name}': patch`).join('\n');

const snapshot = `---
Expand Down
Loading