Skip to content

PackageToJS: Fix skeleton file discovery path for build plugin output#591

Merged
krodak merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:krodak/packagetojslocationfix
Feb 5, 2026
Merged

PackageToJS: Fix skeleton file discovery path for build plugin output#591
krodak merged 1 commit intoswiftwasm:mainfrom
PassiveLogic:krodak/packagetojslocationfix

Conversation

@krodak
Copy link
Member

@krodak krodak commented Feb 5, 2026

Overview

Fixes skeleton file discovery in SkeletonCollector for projects using the BridgeJS build plugin workflow.

Since commit 91d2f06, BridgeJSTool writes skeleton files to destination/BridgeJS/JavaScript/BridgeJS.json, but PackageToJS was searching in destination/BridgeJS/BridgeJS.json (missing the JavaScript/ subdirectory).

Issue

Projects using the BridgeJS build plugin for automatic code generation fail to produce bridge-js.js because PackageToJS cannot find the skeleton files:

# Build plugin outputs to:
.build/plugins/outputs/[pkg]/[target]/destination/BridgeJS/JavaScript/BridgeJS.json

# PackageToJS searched in:
.build/plugins/outputs/[pkg]/[target]/destination/BridgeJS/BridgeJS.json

This results in HAS_BRIDGE=false and stub implementations in instantiate.js.

Example

A project using the build plugin workflow:

// Package.swift
.executableTarget(
    name: "MyApp",
    dependencies: ["JavaScriptKit"],
    swiftSettings: [
        .enableExperimentalFeature("Extern")
    ],
    plugins: [
        .plugin(name: "BridgeJS", package: "JavaScriptKit")  // Using build plugin
    ]
)
// Sources/MyApp/Greeter.swift
@JS(namespace: "MyApp")
public enum Greeter {
    @JS
    public static func hello(name: String) -> String {
        return "Hello, \(name)!"
    }
}

When building with swift package js, the skeleton is generated but not discovered, resulting in missing exports in bridge-js.js.

Root Cause

When the unified generate subcommand was introduced in 91d2f06, the output path was changed to include JavaScript/ subdirectory, but only one of the two search paths in SkeletonCollector was updated:

  • ✅ Path 1 (source directory): target.directoryURL/Generated/JavaScript - works for command plugin / pre-generated files
  • ❌ Path 2 (build output): destination/BridgeJS - missing /JavaScript

Fix

Add /JavaScript to the second search path to match the actual output location.

Testing

Tested with a project using the BridgeJS build plugin workflow. After the fix, bridge-js.js is correctly generated with exported functions at the specified namespace.

The SkeletonCollector was looking for BridgeJS.json at the wrong path
for build-time generated files. Since commit 91d2f06, BridgeJSTool
writes skeleton files to `destination/BridgeJS/JavaScript/BridgeJS.json`,
but PackageToJS was searching in `destination/BridgeJS/BridgeJS.json`
(missing the JavaScript/ subdirectory).

This caused projects using dynamic BridgeJS generation via the build
plugin to fail - PackageToJS couldn't find the skeleton files, resulting
in HAS_BRIDGE=false and stub implementations in instantiate.js.
@krodak krodak self-assigned this Feb 5, 2026
Copy link
Member

@kateinoigakukun kateinoigakukun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, thanks 🙏

@krodak krodak merged commit 9a312e2 into swiftwasm:main Feb 5, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants