Skip to content

Conversation

@davidfirst
Copy link
Member

Problem

When importing a component that uses a custom env (e.g., Vue env) with custom file extension detectors (e.g., .vue files), the first install after import fails to detect dependencies imported in those custom files. A second bit install is required to detect and install the missing packages.

Reproduction:

cd /tmp && mkdir test && cd test && bit init
bit import learnbit-vue.graphql/user-app
bit status
# Shows: missing packages or links from node_modules to the source
#        user-app.vue -> @learnbit-vue/graphql.composables.user

The issue occurs because:

  1. During the first install, the env package isn't yet in node_modules
  2. Components are loaded and dependencies detected without the env's detectors available
  3. After install, the env is available but cached component data with incomplete dependency info is used
  4. Missing dependencies are never detected or installed

This is a follow-up fix to #10044 which enabled loading components with seeders during dependency detection, but didn't handle the case where the env itself needs to be installed first.

Solution

Track failed envs before install (scopes/workspace/install/install.main.runtime.ts:372-374):

  • Capture which envs fail to load before the first install runs
  • This information is used later to determine if a post-install re-check is needed

Re-check for missing deps after install (scopes/workspace/install/install.main.runtime.ts:491-519):
When addMissingDeps is enabled and there were envs that failed to load before install:

  • Clear cache to get fresh component data
  • Re-detect missing packages with env detectors now available
  • If found, add them to root policy and run another install

Enable during import (scopes/component/component-writer/component-writer.main.runtime.ts:114-118):

  • Set addMissingDeps: true when calling install during import
  • This triggers the post-install re-check logic

Test Plan

Tested with learnbit-vue.graphql/user-app which uses .vue files:

  • bit import learnbit-vue.graphql/user-app now correctly installs missing Vue composable dependency on first import
  • bit import -x followed by bit install --add-missing-deps works correctly
  • bit status shows no issues after import

The fix ensures that custom file extension dependencies are detected and installed on the first import, eliminating the need for a second install.

## Problem

When importing a component that uses a custom env (e.g., Vue env) with custom file extension detectors (e.g., .vue files), the first install after import fails to detect dependencies imported in those custom files. A second `bit install` is required to detect and install the missing packages.

This happens because:
1. During the first install, the env package isn't yet in node_modules
2. Components are loaded and dependencies detected without the env's detectors
3. After install, the env is available but cached component data with incomplete dependency info is used
4. Missing dependencies are never detected or installed

## Solution

1. **Capture envs that fail to load before install**: Track which envs aren't available before the first install runs.

2. **Re-check for missing deps after install**: When `addMissingDeps` is enabled and there were envs that failed to load before install:
   - Clear cache to get fresh component data
   - Re-detect missing packages with env detectors now available
   - If found, add them to root policy and run another install

3. **Enable addMissingDeps during import**: Set `addMissingDeps: true` when `installPackagesGracefully` is called during component import to trigger the post-install re-check.

## Test Plan

Tested with `learnbit-vue.graphql/user-app` which uses `.vue` files:
- `bit import learnbit-vue.graphql/user-app` now correctly installs missing Vue composable dependency on first import
- `bit import -x` followed by `bit install --add-missing-deps` works correctly
- `bit status` shows no issues after import
// an env detector that wasn't available during the first dependency detection pass.
if (options?.addMissingDeps && envsFailedToLoadBeforeInstall.length > 0) {
await this.workspace.clearCache();
const missingPackages = await this._getAllMissingPackages();
Copy link
Member

Choose a reason for hiding this comment

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

so it will install all missing dependencies, not only those that were not detected due to the lack of env in node_modules. Is that fine? Maybe we should just pick the missing deps of the imported components?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure. Honestly, I'm not even sure that this fix is in the right direction. It might be better to forget about this PR and fix the original issue regardless of this.

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.

3 participants