Skip to content

Commit cbd9236

Browse files
chrfalchclaude
andcommitted
feat(spm): rn-tester + helloworld SPM consumption & test library
SPM-mode consumption for the example apps: rn-tester and helloworld each get a Package.swift + *-SPM xcodeproj that consume React via SwiftPM product deps (zero header search paths). Adds react-native-test-library (apple + common) and its rn-tester example, plus the react-native.config.js spmModules wiring. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 6157eb5 commit cbd9236

31 files changed

Lines changed: 1875 additions & 0 deletions
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Generated SPM artifacts (written by setup-ios-spm.js's earlier in-place
2+
# layout). The current autolinker emits these under the consumer app's
3+
# build/generated/autolinking/ tree instead, so any copy that lands here is
4+
# stale and should not be committed.
5+
Package.swift
6+
Package.resolved
7+
include/
8+
9+
# SwiftPM caches
10+
.build/
11+
.swiftpm/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTBridgeModule.h>
9+
10+
@interface TestLibraryApple : NSObject <RCTBridgeModule>
11+
@end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "TestLibraryApple.h"
9+
10+
// Synth library products are emitted as .library(type: .dynamic, ...), so SPM
11+
// wraps each autolinked dep as a Foo.framework under PackageFrameworks/. That
12+
// gives angle-bracket imports the standard <Module/Header.h> resolution path,
13+
// matching how most React Native libraries already organize their headers.
14+
#import <ReactNativeTestLibraryCommon/TestLibraryCommon.h>
15+
16+
@implementation TestLibraryApple
17+
18+
RCT_EXPORT_MODULE()
19+
20+
RCT_EXPORT_METHOD(echo
21+
: (NSString *)message resolve
22+
: (RCTPromiseResolveBlock)resolve reject
23+
: (RCTPromiseRejectBlock)reject)
24+
{
25+
NSString *prefix = [TestLibraryCommon defaultPrefix];
26+
resolve([NSString stringWithFormat:@"%@apple: %@", prefix, message]);
27+
}
28+
29+
@end
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Copyright (c) Meta Platforms, Inc. and affiliates.
2+
#
3+
# This source code is licensed under the MIT license found in the
4+
# LICENSE file in the root directory of this source tree.
5+
6+
require "json"
7+
8+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
9+
10+
Pod::Spec.new do |s|
11+
s.name = "TestLibraryApple"
12+
s.version = package["version"]
13+
s.summary = package["description"]
14+
s.homepage = "https://github.com/facebook/react-native"
15+
s.license = "MIT"
16+
s.platforms = min_supported_versions
17+
s.author = "Meta Platforms, Inc. and its affiliates"
18+
s.source = { :git => "https://github.com/facebook/react-native.git", :tag => "#{s.version}" }
19+
s.source_files = "*.{h,m,mm,swift}"
20+
s.requires_arc = true
21+
22+
install_modules_dependencies(s)
23+
end
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* Smoke test that the SPM autolinker excludes `__tests__/` directories from
8+
* the `sources:` allowlist. If this file ever ends up in a target's sources,
9+
* the build fails immediately with an unresolved header — making the
10+
* regression loud.
11+
*/
12+
13+
#include <this/header/intentionally/does/not/exist.h>
14+
15+
static_assert(false, "TestLibraryAppleTests.cpp must not be compiled by the SPM autolinker");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import type {Greeting} from 'react-native-test-library-common';
2+
3+
export function greet(g: Greeting): Promise<string>;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
import type {Greeting} from 'react-native-test-library-common';
14+
15+
import {formatGreeting} from 'react-native-test-library-common';
16+
import {NativeModules, Platform} from 'react-native';
17+
18+
export function greet(g: Greeting): Promise<string> {
19+
const TestLibraryApple = NativeModules.TestLibraryApple;
20+
if (TestLibraryApple == null) {
21+
return Promise.reject(
22+
new Error(
23+
`react-native-test-library-apple: native module unavailable on ${Platform.OS}. This package is iOS-only; install a platform-specific sibling (e.g. react-native-test-library-android) for cross-platform coverage.`,
24+
),
25+
);
26+
}
27+
return TestLibraryApple.echo(formatGreeting(g));
28+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "react-native-test-library-apple",
3+
"version": "0.87.0-main",
4+
"description": "Apple platform implementation for the React Native autolinking fixture. Depends on react-native-test-library-common; used to validate iOS/macOS autolinking discovery and transitive native dependency resolution.",
5+
"private": true,
6+
"main": "index.js",
7+
"types": "index.d.ts",
8+
"license": "MIT",
9+
"files": [
10+
"index.js",
11+
"index.d.ts",
12+
"react-native.config.js",
13+
"TestLibraryApple.podspec",
14+
"TestLibraryApple.h",
15+
"TestLibraryApple.mm"
16+
],
17+
"keywords": [
18+
"react-native",
19+
"fixture",
20+
"autolinking",
21+
"ios",
22+
"macos"
23+
],
24+
"dependencies": {
25+
"react-native-test-library-common": "0.87.0-main"
26+
},
27+
"peerDependencies": {
28+
"react": "*",
29+
"react-native": "1000.0.0"
30+
}
31+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @format
8+
* @noflow
9+
*/
10+
11+
'use strict';
12+
13+
module.exports = {
14+
dependency: {
15+
platforms: {
16+
ios: {},
17+
},
18+
},
19+
spm: {
20+
dependencies: ['react-native-test-library-common'],
21+
},
22+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <React/RCTBridgeModule.h>
9+
10+
@interface TestLibraryCommon : NSObject <RCTBridgeModule>
11+
12+
/** Shared prefix used by other test-library packages that depend on common. */
13+
+ (NSString *)defaultPrefix;
14+
15+
@end

0 commit comments

Comments
 (0)