Skip to content

Commit 8bf1e9e

Browse files
BridgeJS: Improve Xcode editing experience by removing symlinks
Xcode does not handle symlinks well, especially when showing errors in the editor. This commit removes the symlinks in the BridgeJS plugin package and use SwiftPM's native target structure. We still use symlinks for the actual BridgeJSTool executable target in the main package as a build-time optimization, but it should not affect the Xcode editing experience on the main package.
1 parent 82048d5 commit 8bf1e9e

25 files changed

+200
-97
lines changed

Package.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ let package = Package(
151151
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
152152
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
153153
],
154-
path: "Plugins/BridgeJS/Sources/BridgeJSTool",
155154
exclude: ["TS2Skeleton/JavaScript"]
156155
),
157156
.testTarget(

Plugins/BridgeJS/Package.swift

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22

33
import PackageDescription
44

5-
let coreDependencies: [Target.Dependency] = [
6-
.product(name: "SwiftParser", package: "swift-syntax"),
7-
.product(name: "SwiftSyntax", package: "swift-syntax"),
8-
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
9-
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
10-
]
11-
125
let package = Package(
136
name: "BridgeJS",
147
platforms: [.macOS(.v13)],
@@ -19,11 +12,42 @@ let package = Package(
1912
.target(name: "BridgeJSBuildPlugin"),
2013
.executableTarget(
2114
name: "BridgeJSTool",
22-
dependencies: coreDependencies
15+
dependencies: [
16+
"BridgeJSCore",
17+
"TS2Skeleton",
18+
]
19+
),
20+
.target(
21+
name: "TS2Skeleton",
22+
dependencies: [
23+
"BridgeJSCore",
24+
"BridgeJSSkeleton",
25+
]
26+
),
27+
.target(
28+
name: "BridgeJSCore",
29+
dependencies: [
30+
"BridgeJSSkeleton",
31+
.product(name: "SwiftParser", package: "swift-syntax"),
32+
.product(name: "SwiftSyntax", package: "swift-syntax"),
33+
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
34+
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
35+
]
2336
),
37+
.target(name: "BridgeJSSkeleton"),
38+
39+
.target(
40+
name: "BridgeJSLink",
41+
dependencies: ["BridgeJSSkeleton"]
42+
),
43+
2444
.testTarget(
2545
name: "BridgeJSToolTests",
26-
dependencies: coreDependencies,
46+
dependencies: [
47+
"BridgeJSCore",
48+
"BridgeJSLink",
49+
"TS2Skeleton",
50+
],
2751
exclude: ["__Snapshots__", "Inputs"]
2852
),
2953
]
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
struct BridgeJSCoreError: Swift.Error, CustomStringConvertible {
2-
let description: String
1+
public struct BridgeJSCoreError: Swift.Error, CustomStringConvertible {
2+
public let description: String
33

4-
init(_ message: String) {
4+
public init(_ message: String) {
55
self.description = message
66
}
77
}

Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import SwiftBasicFormat
22
import SwiftSyntax
33
import SwiftSyntaxBuilder
4+
#if canImport(BridgeJSSkeleton)
5+
import BridgeJSSkeleton
6+
#endif
47

58
/// Exports Swift functions and classes to JavaScript
69
///
@@ -11,14 +14,14 @@ import SwiftSyntaxBuilder
1114
///
1215
/// The generated skeletons will be used by ``BridgeJSLink`` to generate
1316
/// JavaScript glue code and TypeScript definitions.
14-
class ExportSwift {
17+
public class ExportSwift {
1518
let progress: ProgressReporting
1619

1720
private var exportedFunctions: [ExportedFunction] = []
1821
private var exportedClasses: [ExportedClass] = []
1922
private var typeDeclResolver: TypeDeclResolver = TypeDeclResolver()
2023

21-
init(progress: ProgressReporting) {
24+
public init(progress: ProgressReporting) {
2225
self.progress = progress
2326
}
2427

@@ -27,7 +30,7 @@ class ExportSwift {
2730
/// - Parameters:
2831
/// - sourceFile: The parsed Swift source file to process
2932
/// - inputFilePath: The file path for error reporting
30-
func addSourceFile(_ sourceFile: SourceFileSyntax, _ inputFilePath: String) throws {
33+
public func addSourceFile(_ sourceFile: SourceFileSyntax, _ inputFilePath: String) throws {
3134
progress.print("Processing \(inputFilePath)")
3235
typeDeclResolver.addSourceFile(sourceFile)
3336

@@ -44,7 +47,7 @@ class ExportSwift {
4447
///
4548
/// - Returns: A tuple containing the generated Swift code and a skeleton
4649
/// describing the exported APIs
47-
func finalize() throws -> (outputSwift: String, outputSkeleton: ExportedSkeleton)? {
50+
public func finalize() throws -> (outputSwift: String, outputSkeleton: ExportedSkeleton)? {
4851
guard let outputSwift = renderSwiftGlue() else {
4952
return nil
5053
}

Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import SwiftBasicFormat
22
import SwiftSyntax
33
import SwiftSyntaxBuilder
4+
#if canImport(BridgeJSSkeleton)
5+
import BridgeJSSkeleton
6+
#endif
47

58
/// Imports TypeScript declarations and generates Swift bridge code
69
///
@@ -10,25 +13,25 @@ import SwiftSyntaxBuilder
1013
///
1114
/// The generated skeletons will be used by ``BridgeJSLink`` to generate
1215
/// JavaScript glue code and TypeScript definitions.
13-
struct ImportTS {
14-
let progress: ProgressReporting
15-
private(set) var skeleton: ImportedModuleSkeleton
16+
public struct ImportTS {
17+
public let progress: ProgressReporting
18+
public private(set) var skeleton: ImportedModuleSkeleton
1619
private var moduleName: String {
1720
skeleton.moduleName
1821
}
1922

20-
init(progress: ProgressReporting, moduleName: String) {
23+
public init(progress: ProgressReporting, moduleName: String) {
2124
self.progress = progress
2225
self.skeleton = ImportedModuleSkeleton(moduleName: moduleName, children: [])
2326
}
2427

2528
/// Adds a skeleton to the importer's state
26-
mutating func addSkeleton(_ skeleton: ImportedFileSkeleton) {
29+
public mutating func addSkeleton(_ skeleton: ImportedFileSkeleton) {
2730
self.skeleton.children.append(skeleton)
2831
}
2932

3033
/// Finalizes the import process and generates Swift code
31-
func finalize() throws -> String? {
34+
public func finalize() throws -> String? {
3235
var decls: [DeclSyntax] = []
3336
for skeleton in self.skeleton.children {
3437
for function in skeleton.functions {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
struct ProgressReporting {
1+
public struct ProgressReporting {
22
let print: (String) -> Void
33

4-
init(verbose: Bool) {
4+
public init(verbose: Bool) {
55
self.init(print: verbose ? { Swift.print($0) } : { _ in })
66
}
77

88
private init(print: @escaping (String) -> Void) {
99
self.print = print
1010
}
1111

12-
static var silent: ProgressReporting {
12+
public static var silent: ProgressReporting {
1313
return ProgressReporting(print: { _ in })
1414
}
1515

16-
func print(_ message: String) {
16+
public func print(_ message: String) {
1717
self.print(message)
1818
}
1919
}

Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import class Foundation.JSONDecoder
22
import struct Foundation.Data
3+
#if canImport(BridgeJSSkeleton)
4+
import BridgeJSSkeleton
5+
#endif
36

47
struct BridgeJSLink {
58
/// The exported skeletons
@@ -295,8 +298,7 @@ struct BridgeJSLink {
295298
}
296299

297300
for method in klass.methods {
298-
let methodSignature =
299-
"\(method.name)\(renderTSSignature(parameters: method.parameters, returnType: method.returnType));"
301+
let methodSignature = "\(method.name)\(renderTSSignature(parameters: method.parameters, returnType: method.returnType));"
300302
dtsLines.append("\(methodSignature)".indent(count: identBaseSize * (parts.count + 2)))
301303
}
302304

@@ -321,8 +323,7 @@ struct BridgeJSLink {
321323
}
322324

323325
for function in functions {
324-
let signature =
325-
"function \(function.name)\(renderTSSignature(parameters: function.parameters, returnType: function.returnType));"
326+
let signature = "function \(function.name)\(renderTSSignature(parameters: function.parameters, returnType: function.returnType));"
326327
dtsLines.append("\(signature)".indent(count: identBaseSize * (parts.count + 1)))
327328
}
328329

0 commit comments

Comments
 (0)