diff --git a/.changeset/fix-config-plugin-swift-path.md b/.changeset/fix-config-plugin-swift-path.md new file mode 100644 index 00000000000..17bc304301d --- /dev/null +++ b/.changeset/fix-config-plugin-swift-path.md @@ -0,0 +1,5 @@ +--- +"@clerk/expo": patch +--- + +fix(expo): use `require.resolve` in config plugin to find `ClerkViewFactory.swift`, resolving failures in pnpm workspaces nested 2+ levels deep diff --git a/packages/expo/app.plugin.js b/packages/expo/app.plugin.js index f8dca293ce2..9f264e5a7b3 100644 --- a/packages/expo/app.plugin.js +++ b/packages/expo/app.plugin.js @@ -258,41 +258,14 @@ const withClerkIOS = config => { const projectName = config.modRequest.projectName; const iosProjectPath = path.join(platformProjectRoot, projectName); - // Find the ClerkViewFactory.swift source file - // Check multiple possible locations in order of preference + // Find the ClerkViewFactory.swift source file using Node's module resolution, + // which handles arbitrary nesting depths in pnpm/yarn/npm workspaces. let sourceFile; - const possiblePaths = [ - // Standard node_modules (npm, yarn) - path.join(config.modRequest.projectRoot, 'node_modules', '@clerk', 'expo', 'ios', 'ClerkViewFactory.swift'), - // pnpm hoisted node_modules - path.join( - config.modRequest.projectRoot, - '..', - 'node_modules', - '@clerk', - 'expo', - 'ios', - 'ClerkViewFactory.swift', - ), - // Monorepo workspace (pnpm workspace) - path.join( - config.modRequest.projectRoot, - '..', - 'javascript', - 'packages', - 'expo', - 'ios', - 'ClerkViewFactory.swift', - ), - // Alternative monorepo structure - path.join(config.modRequest.projectRoot, '..', 'packages', 'expo', 'ios', 'ClerkViewFactory.swift'), - ]; - - for (const possiblePath of possiblePaths) { - if (fs.existsSync(possiblePath)) { - sourceFile = possiblePath; - break; - } + try { + const packageRoot = path.dirname(require.resolve('@clerk/expo/package.json')); + sourceFile = path.join(packageRoot, 'ios', 'ClerkViewFactory.swift'); + } catch { + sourceFile = null; } if (sourceFile && fs.existsSync(sourceFile)) {