Skip to content

BridgeJS: Improve Xcode editing experience by removing symlinks #407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 15, 2025
Merged
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
1 change: 0 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ let package = Package(
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
],
path: "Plugins/BridgeJS/Sources/BridgeJSTool",
exclude: ["TS2Skeleton/JavaScript"]
),
.testTarget(
Expand Down
42 changes: 33 additions & 9 deletions Plugins/BridgeJS/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@

import PackageDescription

let coreDependencies: [Target.Dependency] = [
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
]

let package = Package(
name: "BridgeJS",
platforms: [.macOS(.v13)],
Expand All @@ -19,11 +12,42 @@ let package = Package(
.target(name: "BridgeJSBuildPlugin"),
.executableTarget(
name: "BridgeJSTool",
dependencies: coreDependencies
dependencies: [
"BridgeJSCore",
"TS2Skeleton",
]
),
.target(
name: "TS2Skeleton",
dependencies: [
"BridgeJSCore",
"BridgeJSSkeleton",
]
),
.target(
name: "BridgeJSCore",
dependencies: [
"BridgeJSSkeleton",
.product(name: "SwiftParser", package: "swift-syntax"),
.product(name: "SwiftSyntax", package: "swift-syntax"),
.product(name: "SwiftBasicFormat", package: "swift-syntax"),
.product(name: "SwiftSyntaxBuilder", package: "swift-syntax"),
]
),
.target(name: "BridgeJSSkeleton"),

.target(
name: "BridgeJSLink",
dependencies: ["BridgeJSSkeleton"]
),

.testTarget(
name: "BridgeJSToolTests",
dependencies: coreDependencies,
dependencies: [
"BridgeJSCore",
"BridgeJSLink",
"TS2Skeleton",
],
exclude: ["__Snapshots__", "Inputs"]
),
]
Expand Down
6 changes: 3 additions & 3 deletions Plugins/BridgeJS/Sources/BridgeJSCore/BridgeJSCoreError.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
struct BridgeJSCoreError: Swift.Error, CustomStringConvertible {
let description: String
public struct BridgeJSCoreError: Swift.Error, CustomStringConvertible {
public let description: String

init(_ message: String) {
public init(_ message: String) {
self.description = message
}
}
11 changes: 7 additions & 4 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ExportSwift.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import SwiftBasicFormat
import SwiftSyntax
import SwiftSyntaxBuilder
#if canImport(BridgeJSSkeleton)
import BridgeJSSkeleton
#endif

/// Exports Swift functions and classes to JavaScript
///
Expand All @@ -11,14 +14,14 @@ import SwiftSyntaxBuilder
///
/// The generated skeletons will be used by ``BridgeJSLink`` to generate
/// JavaScript glue code and TypeScript definitions.
class ExportSwift {
public class ExportSwift {
let progress: ProgressReporting

private var exportedFunctions: [ExportedFunction] = []
private var exportedClasses: [ExportedClass] = []
private var typeDeclResolver: TypeDeclResolver = TypeDeclResolver()

init(progress: ProgressReporting) {
public init(progress: ProgressReporting) {
self.progress = progress
}

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

Expand All @@ -44,7 +47,7 @@ class ExportSwift {
///
/// - Returns: A tuple containing the generated Swift code and a skeleton
/// describing the exported APIs
func finalize() throws -> (outputSwift: String, outputSkeleton: ExportedSkeleton)? {
public func finalize() throws -> (outputSwift: String, outputSkeleton: ExportedSkeleton)? {
guard let outputSwift = renderSwiftGlue() else {
return nil
}
Expand Down
15 changes: 9 additions & 6 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ImportTS.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import SwiftBasicFormat
import SwiftSyntax
import SwiftSyntaxBuilder
#if canImport(BridgeJSSkeleton)
import BridgeJSSkeleton
#endif

/// Imports TypeScript declarations and generates Swift bridge code
///
Expand All @@ -10,25 +13,25 @@ import SwiftSyntaxBuilder
///
/// The generated skeletons will be used by ``BridgeJSLink`` to generate
/// JavaScript glue code and TypeScript definitions.
struct ImportTS {
let progress: ProgressReporting
private(set) var skeleton: ImportedModuleSkeleton
public struct ImportTS {
public let progress: ProgressReporting
public private(set) var skeleton: ImportedModuleSkeleton
private var moduleName: String {
skeleton.moduleName
}

init(progress: ProgressReporting, moduleName: String) {
public init(progress: ProgressReporting, moduleName: String) {
self.progress = progress
self.skeleton = ImportedModuleSkeleton(moduleName: moduleName, children: [])
}

/// Adds a skeleton to the importer's state
mutating func addSkeleton(_ skeleton: ImportedFileSkeleton) {
public mutating func addSkeleton(_ skeleton: ImportedFileSkeleton) {
self.skeleton.children.append(skeleton)
}

/// Finalizes the import process and generates Swift code
func finalize() throws -> String? {
public func finalize() throws -> String? {
var decls: [DeclSyntax] = []
for skeleton in self.skeleton.children {
for function in skeleton.functions {
Expand Down
8 changes: 4 additions & 4 deletions Plugins/BridgeJS/Sources/BridgeJSCore/ProgressReporting.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
struct ProgressReporting {
public struct ProgressReporting {
let print: (String) -> Void

init(verbose: Bool) {
public init(verbose: Bool) {
self.init(print: verbose ? { Swift.print($0) } : { _ in })
}

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

static var silent: ProgressReporting {
public static var silent: ProgressReporting {
return ProgressReporting(print: { _ in })
}

func print(_ message: String) {
public func print(_ message: String) {
self.print(message)
}
}
3 changes: 3 additions & 0 deletions Plugins/BridgeJS/Sources/BridgeJSLink/BridgeJSLink.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import class Foundation.JSONDecoder
import struct Foundation.Data
#if canImport(BridgeJSSkeleton)
import BridgeJSSkeleton
#endif

struct BridgeJSLink {
/// The exported skeletons
Expand Down
Loading