node-swift icon indicating copy to clipboard operation
node-swift copied to clipboard

Multiple modules / dynamic libs in the same package

Open fpirsch opened this issue 1 year ago • 2 comments

I need to build several distinct NodeModules in the same project. I have this directory structure

root
  ├ Sources
  │  ├ Module1
  │  │   └ Module1.swift
  │  └ Module2
  │      └ Module2.swift
  ├ package.json
  └ Package.swift

And in Package.swift I declared my 2 .dynamic products and the 2 associated targets. When I run node-swift build I get this error : Error: Found more than 1 dynamic library in the Swift Package. Consider specifying which product should be built via the swift.product field in package.json.

I ended up patching cli.js to accept another command line argument specifying which product to build.

Is there some other way to achieve this ?

fpirsch avatar Oct 27 '24 13:10 fpirsch

It would be possible to extend the CLI to support multiple products, but I think there are two simpler options:

  1. Expose both of your Swift API interfaces from a single module
  2. If you really want multiple NodeModules, you can alternatively use a monorepo structure and create two child packages

Is there a reason either of these approaches doesn't work for you? Curious to know your use case.

kabiroberai avatar Apr 06 '25 20:04 kabiroberai

1 is undesirable because separation of concerns: both products are too different 2 a monorepo is a bit overkill here and adds useless complexity

The use case is a node.js program with screen capture (product 1), image processing, and output in a native window (product 2)

fpirsch avatar Apr 14 '25 11:04 fpirsch