rokucommunity / ropm

A package manager for the Roku platform.
MIT License
31 stars 5 forks source link

how to deal with transitive dependencies? #55

Closed ZeeD closed 1 year ago

ZeeD commented 1 year ago

I'm trying to write a (bs) library, that itself relies on some libraries that I found - like, for example (rodash)[https://github.com/TKSS-Software/rodash], and (roku-log)[https://github.com/georgejecook/roku-log].

I started using ropm, and it was easy to "consume" the other libraries. For how I understood, it creates a subfolder for each dependency in /source/roku_modules and/or /component/roku_modules, so they are "part of the project".

Now I have doubts trying to create a package to publish myself (unfortunately it will be private, but still)

flowchart
    A --> rodash
    A --> lib
    lib --> rodash

what happens in A? does it have two "copies" of rodash?

TwitchBronBron commented 1 year ago

You should explicitly exclude the roku_modules folders when publishing your package to npm. ropm will handle installing the dependencies in the proper locations, rewriting import paths ,etc. However, even if you forgot to omit them, ropm will refuse to copy any files from roku_modules in the npm packages over into the consuming project. We briefly talk about this in the readme.

https://github.com/rokucommunity/ropm#changing-where-the-modules-files-are-copied-from-as-a-package-author

All folders named roku_modules that are found in a ropm module will be ignored. This is due to the fact that modules should not be publishing their own copies of their ropm modules. ropm will handle this for them. So as a package author, be sure to exclude all folders named roku_modules during your publishing process.

ropm will read the dependencies section of your project and all transitive dependencies, and narrow the versions of the library. See this readme section.

ZeeD commented 1 year ago

just to be sure: in the final .tgz there should be the compiled files, correct? (I expect to find .brs and maybe .d.bs with the definitions) so I need to use bsc to compile my project (I saw other projects use npx bsc --create-package false --staging-folder-path staging to basically create a folder with .brs files). But then I cannot blacklist the roku modules (as they are needed at this stage)

maybe I'm dense, but I don't get what is the "command" to create / publish a package. If it is npm (as in npm pack/npm publish) how does it know that he should ignore the roku_modules? it doesn't seams to me that ropm is able to do it, and bsc creates .zip files (that are meant to be "deployed" on roku devices, not on a npm registry)

TwitchBronBron commented 1 year ago

Here's the steps to publish a ropm package with bsc and the npm cli.

  1. Set "retainStagingFolder": true and "stagingFolderPath": "dist" in your bsconfig.json. (dist is just my favorite output directory name, but you can call it whatever you want).
  2. Run bsc, so now the the dist folder will contain all of the transpiled files.
  3. In your library project's package.json, set the "files" array to something like this:
    {
        "name": "quick-list"
        //when npm creates the package, only include these files
        "files": [
            "dist/**/*",
            //exclude all roku_modules files when creating npm package. 
            "!**/roku_modules/**/*"
        ],
        "ropm": {
            //tell ropm that the files for this module reside in the "./dist" folder
            "packageRootDir": "dist"
        }
    }
  4. follow the standard npm docs for how to publish an npm package. See this section in the readme for instructions.
TwitchBronBron commented 1 year ago

FYI, I just updated my example above. I had the ignore pattern in the wrong spot.

ZeeD commented 1 year ago

Thanks! I think I got now. To better understand what was happening I created a (very dumb) example on https://github.com/ZeeD/_bs_lib_monorepo where I tried to follow your advices