Skip to content

Add swift-node native addon support - #22

Merged
biw merged 3 commits into
mainfrom
biw/add-swift-node-support
Aug 10, 2026
Merged

Add swift-node native addon support#22
biw merged 3 commits into
mainfrom
biw/add-swift-node-support

Conversation

@biw

@biw biw commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Summary

Adds swift-node 0.1.0 loader support so its target-qualified native addons and runtime sidecars are emitted with valid runtime paths.

What This PR Does

  • Recognizes swift-node 0.1.0's generated resolveAddonPath() loader
  • Resolves macOS flat binaries plus Linux and Windows target subdirectories, including Linux musl targets
  • Preserves Swift runtime .so and .dll sidecar filenames beside the hashed addon

What This Improves

  • Bundles swift-node packages, including macos-native-clone-file

What This Does Not Do

  • Does not execute a native Swift binary during the test suite

Important Context

  • No configuration, migration, or release artifact changes

Code To Review Closely

src/index.ts:328

Verify that sidecars are emitted only for a resolved swift-node addon and retain the filenames required by the dynamic linker.

const sidecarPaths =
  process.platform === "darwin"
    ? []
    : fs
        .readdirSync(path.dirname(binaryPath))
        .filter((filename) =>
          process.platform === "win32"
            ? filename.toLowerCase().endsWith(".dll")
            : /\.so(?:\..+)?$/i.test(filename),
        )
        .map((filename) => path.join(path.dirname(binaryPath), filename));

return { nodeFilePath: binaryPath, sidecarPaths };

Gotchas, Risks, And Edge Cases

  • Target selection uses the build host's platform, architecture, and Linux libc detection, matching swift-node 0.1.0
  • Conflicting runtime-sidecar filenames with different contents fail the build

Tests And Regression Coverage

Validation Run

  • pnpm test: 200 passing tests
  • pnpm lint: formatting, lint, and type checks passed
  • pnpm build: ESM and CommonJS package builds passed

Coverage Assessment

Sufficient for generated-loader bundling because the tests cover the 0.1.0 resolver, emitted hashed addon, and Linux/Windows sidecar assets.

Regressions These Tests Should Catch

  • Unresolved resolveAddonPath() calls from swift-node 0.1.0
  • Missing native assets for the macOS or target-subdirectory layouts
  • Missing Swift runtime sidecars on Linux and Windows

Gaps And Recommended Follow-Up Tests

  • Native runtime execution remains covered by the consuming package rather than this plugin's fake-addon fixture

Follow-Up Work

  • Not applicable

@biw
biw merged commit a75dcda into main Aug 10, 2026
2 checks passed
@biw
biw deleted the biw/add-swift-node-support branch August 10, 2026 21:55
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.

1 participant