GithubHelp home page GithubHelp logo

Comments (8)

MatthD avatar MatthD commented on September 26, 2024 1

Thanks for this explication !
In fact in devv we have all the app with their composent installed at the sale time.
For prod because we want the smalest build possible and have micro services build (but still use à monorepo) we are copying one app and the with a script and the help of bit show and version specific of out workspace we are keeping only what we need.
Will try to provide you a veru simple repo with the script

from bit.

davidfirst avatar davidfirst commented on September 26, 2024

Can you elaborate more on the use-case why all these dependencies are in workspace.jsonc although they're not in use?
In general, I'm not aware of such an option to ignore part of workspace.jsonc and install only the ones that are used by the components.
What you might want to do is the opposite - remove all dependencies from workspace.jsonc so then bit install searches for the dependencies from the components only. (you'll need --add-missing-deps if those deps are newly introduced)

from bit.

MatthD avatar MatthD commented on September 26, 2024

The idea is that we are trying to build the best dev experience about workspace management for our team.
ATM bit show app. and bit status help a lot to identify what dependencies are needed or missing.
We don't want to manage manually by app/component the deps (and forgot to remove then etc..), because BIT can do it for us via git show (identified what is needed and missing) so that we have them globally inside workspace.jsonc .

The solution you do propose could be cool but how could we indicate that we want a specific version of dependencies ? We couldn't just get the latest one available ;) (and aliases etc)

We thought about something that bit can install only app/component we would want to limit the dependencies install for build production for eg.

from bit.

davidfirst avatar davidfirst commented on September 26, 2024

So if I understand correctly, you have like a pool of dependencies with specific versions that you want bit install to use.
This way, when a component needs one of these dependencies, it'll find the version in that pool instead of using the latest.
Specifying them in workspace.jsonc doesn't work for you because then all of them get installed and you want to install only the dependencies you use.

@GiladShoham @zkochan , maybe you guys have an idea.

from bit.

GiladShoham avatar GiladShoham commented on September 26, 2024

You can do something like create a temp workspace and bring only the app component into it (bit import it). Then it will only install its dependencies.
Or you can even make a temp folder (non even bit workspace) and just npm install the app component itself.

from bit.

MatthD avatar MatthD commented on September 26, 2024

Thanks for the suggestions !

  1. About the create a temp workspace and bring only the app component into it (bit import it) Yes but how to do that because we don't have package.json/lock per component for deps, they are only managed by our workspace.jsonc. And we need specific versions of dependencies, some with aliases ... So don't know how to not have the workspace.jsonc
  2. Not really possible with npm install because we don't want to manage our component manually via npm (we removed package.lock and deps inside package.json to benefit of bit dependencies detection !)

For the moment what I am trying on is:

  1. bit install the full deps
  2. Call a script that will get deps from bit show ${app} and generate the list of dependencies necessary (with sub-deps nedeed by all local packages)
  3. The script will filter dev dependencies and not use dependencies
  4. Export the list inside the property dependencies of workspace.jsonc
  5. Remove node-modulesand lock file,
  6. Reinstall

I think that this way I am cleaning the useless element for production build and have the minimum required.
Inside the script I am using chlid_process of node to call bit cli , I would have prefer to use the API of @teambit, do you guys can indicate if there is a way to call this command bit show/bit install.... programatically?

from bit.

GiladShoham avatar GiladShoham commented on September 26, 2024
  1. when you create a new workspace and import the app component into it, the app component itself contains all the dependencies it needs. so you don't need to have any dependencies in the workspace.jsonc. they will be just installed correctly during the bit import process. if you do want to change some versions by force, you can run the bit show on the real workspace, then copy some dependencies to the policy in the workspace.jsonc of the temp one and modify the versions. (or even set overrides in the temp workspace)
  2. I was talking about running npm install on a temp empty folder, so in that case any way you don't need bit dependency detection. it's only a temp folder of your app for running/deploying it.

Your method that you are trying to do now, will not work.
even if you remove the dependencies from the policy in the worksapce.jsonc, when you do bit install, bit will recognize all dependencies used by the components in the workspace, and will install them.

from bit.

MatthD avatar MatthD commented on September 26, 2024

So here is a script I did for our project

  • it removed not needed deps based on bit show + dev deps
  • It update workspace.jsonc to keep only needed packages for a specific app
  • It list the sub deps of related packages, that means I need to first do a bit install , then run the script, then bit install

In the end by running you should get only needed deps for an app and re-running bit install you will get only the needed deps and sub-deps (of packages)

npx tsx scripts/clean-prod-deps.ts -p front

                "pino-pretty": "npm:[email protected]",
                "commander": "^12.0.0",
                "chalk": "^5.3.0",
                "redis": "^2.8.0",
                "redislatest": "npm:redis@latest",
                "twilio": "^4.11.2",
                "uuid": "^9.0.1",
                "wrtc": "npm:@avahq/[email protected]"

It's usefull because in the end it prevent you to have one package.json per apps/packages but manage them globally and in a prod container only get the needed deps per app , that means you can have a monorepo workspace with micro service

from bit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.