Skip to content

fix: [SDK-4782] export package metadata for Capacitor discovery - #35

Merged
fadi-george merged 4 commits into
mainfrom
fadi/sdk-4782
Jun 17, 2026
Merged

fix: [SDK-4782] export package metadata for Capacitor discovery#35
fadi-george merged 4 commits into
mainfrom
fadi/sdk-4782

Conversation

@fadi-george

Copy link
Copy Markdown
Contributor

Description

One Line Summary

Export package metadata so Capacitor can discover the plugin in pnpm/Nx monorepos.

Details

Motivation

Issue #34 reported that @onesignal/capacitor-plugin was skipped by cap sync when installed in a pnpm project. The reporter later provided an Nx monorepo reproduction where the Capacitor app lives under apps/shop, dependencies are declared at the workspace root, and Capacitor detects @capawesome/capacitor-app-update but not @onesignal/capacitor-plugin.

In that layout, Capacitor resolves plugin package metadata from the app workspace. Packages without an exports map allow require.resolve('<package>/package.json'), but our package export map did not expose ./package.json, so the metadata lookup failed and Capacitor skipped the plugin.

Scope

This PR adds ./package.json to the package export map. It does not change the runtime JS entrypoint, native Android/iOS sources, or public SDK APIs.

Reproduction And Validation

Added examples/demo-nx, a minimal Nx-style pnpm workspace matching the reporter's structure:

  • Workspace root dependencies include @capawesome/capacitor-app-update and @onesignal/capacitor-plugin.
  • The Capacitor app lives in apps/shop with no app-local package.json.
  • The fixture can sync against a locally packed SDK tarball to verify the fix.

Before the package metadata export fix, cap sync found only Capawesome. After packing this branch and installing the local tarball in examples/demo-nx, cap sync finds both plugins for Android and iOS.

Testing

Unit testing

No unit tests were added because this is package metadata used by Capacitor CLI discovery rather than runtime SDK behavior.

Manual testing

  • vp pack
  • vp check package.json vite.config.ts
  • vp test run
  • Packed the SDK with vp pm pack, installed it into examples/demo-nx via file:../../onesignal-capacitor-plugin.tgz, and ran COREPACK_ENABLE_STRICT=0 npx pnpm@10.33.0 run sync.
  • Confirmed generated native files include both @capawesome/capacitor-app-update and @onesignal/capacitor-plugin:
    • apps/shop/android/capacitor.settings.gradle
    • apps/shop/android/app/capacitor.build.gradle
    • apps/shop/ios/App/CapApp-SPM/Package.swift

Affected code checklist

  • Notifications
    • Display
    • Open
    • Push Processing
    • Confirm Deliveries
  • Outcomes
  • Sessions
  • In-App Messaging
  • REST API requests
  • Public API changes

Checklist

Overview

  • I have filled out all REQUIRED sections above
  • PR does one thing
  • Any Public API changes are explained in the PR details and conform to existing APIs

Testing

  • I have included test coverage for these changes, or explained why they are not needed
  • All automated tests pass, or I explained why that is not possible
  • I have personally tested this on my device, or explained why that is not possible

Final pass

  • Code is as readable as possible.
  • I have reviewed this PR myself, ensuring it meets each checklist item

Made with Cursor

@fadi-george
fadi-george requested a review from a team June 17, 2026 21:42
@sherwinski

Copy link
Copy Markdown

@claude review once

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM — adding ./package.json to the exports map is the standard fix for letting Capacitor's CLI discover plugin metadata when an exports field is present.

Extended reasoning...

Overview

The substantive SDK change is a single addition to package.json's exports map: "./package.json": "./package.json". Everything else (~80 files) is a non-shipping Nx/pnpm reproduction fixture under examples/demo-nx/ used to validate the fix against the reporter's environment.

Security risks

None. This only exposes the already-public package.json manifest through the package's exports map. No code, auth, crypto, or permission surface is touched. The fixture lives under examples/ and is not published (the files field in package.json restricts what ships).

Level of scrutiny

Low. This is a well-known Node.js convention — once a package declares an exports map, deep-path require.resolve calls (used by Capacitor CLI for plugin discovery) must be explicitly allowed. The pattern is documented in Node's resolution algorithm and is the standard remedy for tools that resolve sibling package.json paths.

Other factors

The reported nit is documentation-only on the example fixture's README (it describes pre-fix expectations while the committed generated files are post-fix). It does not affect SDK consumers and is fine to land as-is or address in a follow-up. PR description thoroughly explains motivation (issue #34), validation steps, and confirms both Android (capacitor.settings.gradle) and iOS (Package.swift) generated files now reference OneSignal.

Comment thread examples/demo-nx/README.md Outdated
@fadi-george
fadi-george merged commit f6a4b50 into main Jun 17, 2026
5 checks passed
@fadi-george
fadi-george deleted the fadi/sdk-4782 branch June 17, 2026 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants