Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,33 @@ end
expect(content).toContain(SCAFFOLDER_MARKER);
});

it('emits resources before publicHeadersPath, the order SwiftPM requires', () => {
fs.mkdirSync(path.join(depRoot, 'ios'));
fs.writeFileSync(path.join(depRoot, 'ios', 'Foo.h'), '');
fs.writeFileSync(
path.join(depRoot, 'react-native-foo.podspec'),
`
Pod::Spec.new do |s|
s.name = "react-native-foo"
s.version = "1.0"
s.source_files = "ios/**/*.{h,m,mm}"
s.resources = ["ios/Foo.bundle"]
s.dependency "React-Core"
end
`,
);
scaffoldPackageSwiftForDep(makeDep(), makeCtx());
const content = fs.readFileSync(
path.join(depRoot, 'Package.swift'),
'utf8',
);
const resourcesAt = content.indexOf('resources: [.copy("ios/Foo.bundle")]');
const publicHeadersAt = content.indexOf('publicHeadersPath: "ios"');
expect(resourcesAt).toBeGreaterThan(-1);
expect(publicHeadersAt).toBeGreaterThan(-1);
expect(resourcesAt).toBeLessThan(publicHeadersAt);
});

it('skips (does not write) a mixed-language dep — Swift + ObjC(++) cannot share one SPM target', () => {
// react-native-screens shape: a single source glob mixing .swift and .mm.
const podspecPath = path.join(depRoot, 'react-native-foo.podspec');
Expand Down Expand Up @@ -1542,7 +1569,7 @@ describe('SCAFFOLDER_VERSION', () => {
});

it('is at the version the current emitter output requires', () => {
expect(SCAFFOLDER_VERSION).toBe(20);
expect(SCAFFOLDER_VERSION).toBe(21);
});

it('emitter writes the current version to the file', () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/react-native/scripts/spm/scaffold-package-swift.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,9 @@ const {log, warn} = makeLogger('scaffold-package-swift');
// under NDEBUG). Bumped so existing scaffolds regenerate with the defines.
// v20: the platform floor is the app's iOS deployment target in string form
// (the `.v15` enum cannot express a dependency minimum like 16.4).
const SCAFFOLDER_VERSION = 20;
// v21: `resources:` is emitted before `publicHeadersPath:`, the argument order
// `.target(...)` requires (the reverse order fails to resolve).
const SCAFFOLDER_VERSION = 21;
const SCAFFOLDER_VERSION_LINE_RE = /^\/\/ AUTO-SCAFFOLDED-VERSION: (\d+)$/m;

const AUTOGEN_MARKER =
Expand Down Expand Up @@ -778,7 +780,7 @@ let package = Package(
${packageDepsBlock} targets: [
.target(
name: "${spec.swiftName}",${targetDepsLine}
path: ".",${sourcesLine}${publicHeadersLine}${resourcesLine}
path: ".",${sourcesLine}${resourcesLine}${publicHeadersLine}
cSettings: ${cSettings},
cxxSettings: ${cxxSettings},
linkerSettings: [${linkerEntries.join(', ')}]
Expand Down
Loading