Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve export command to support implicit exports and better upstream management #1956

Closed
itaymendel opened this issue Aug 26, 2019 · 10 comments

Comments

@itaymendel
Copy link
Contributor

itaymendel commented Aug 26, 2019

Some of the flag and property names are TBD and might be changed as we progress with the development of the feature.

Context

bit export is lacking the support of managing and syncing a single component between many collections. This means that it is very hard to:

  1. Export the same components to several collections ("forking").
  2. Sync component changes in several collections (managing upstreams).
  3. No way to run an implicit bit export command that will export each component to the correct collection (need to manually define to which collection which component will be exported to).
  4. No way to include component's dependencies with a 'fork'.

To resolve it there are several features and improvements to implement.

Support defaultCollection in workspace configuration

To allow implicit exports for staged components that have never been exported, Bit needs to support a defaultCollection property for a workspace. It is not mandatory but will improve user experience.

{
  "bit": {
    "defaultCollection": "<string>"
  }
}

Add a list of upstream collections to component

A component should contain an ordered list of objects representing the remote upstreams. Each item on the list should have:

  1. url - the location of the remote collection. if upstream was resolved in hub_domain use it as a url.
  2. name.
  3. date.

Workspace should contain the current upstream that the component is synced to.

To allow implicit exports for components that were already exported, the workspace should distinct a specific collection as the current collection to sync the component with.

  1. If I exported a component to any non-default collection, the component should still remain staged, unless I specifically asked Bit to change the current-collection (more on that later).
  2. If I change current after export and set it to the location I have exported the component to, the component is still staged. But when I try to export again, Bit will figure out that the component was already exported, and unstage it.

Show current in bit show

bit show is the main API for providing data on a component. It should support showing the workspace data about current collection.

Update export command synopsis.

$ $ bit export [--eject] [--include-dependencies] [--set-current-upstream] [--force] [<scope> [<component id patterns>...]]
Options
--eject

After export, removes the exported components and install them as node modules using npm/yarn.

--set-current

Ensure the component's remote scope is set according to the target location.

--force

Ignore prompt about moving components to another scope.

<scope>

The "remote" scope that is the destination of the export operation.

<component id patterns>

Component name, ID or a glob-pattern. Bit to parses it to get the component IDs to export.

--include-dependencies

Include the component's dependencies as part of the export to the remote scope.

Examples
$ bit export

Works just like bit export <scope>, where <scope> is current component's scope.
If no scope is defined for a component, triggers a message to add a scope (upstream) to the component.

Implicit export only applied for staged components.

$ bit export current

Without additional configuration, exports each component to their current scope (upstream).
If no scope is defined for a component, triggers a message to add a scope (upstream) to the component.
If a workspace has default-scope defined and a component does not have a scope, sets the default-scope as an upstream for the component, and export.

Implicit export only applied for staged components.

$ bit export current foo/bar

Exports component foo/bar to its current scope. If a component has no scope defined, and a workspace has default-scope defined and a component does not have a scope, sets the default-scope as an upstream for the component, and export.

$ bit export moon foo/bar

Add the scope moon to foo/bar as an upstream (scope) and exports component to it.
If the component does not have any upstream defined, sets moon as the current scope.
If the component has other upstreams defined, the command does not change the current scope.

$ bit export moon *

Add the scope moon to all components as an upstream (scope) and exports component to it.
If the component does not have any upstream defined, sets moon as the current scope.
If the component has other upstreams defined, the command does not change the current scope.

If there's a mix of components that some of them might move to another scope, trigger a message asking user to approve (or use --force).

$ bit export sun foo/bar --set-current-upstream

Exports foo/bar to sun and set the workspace to use sun as the current (default) scope for the components.

Possible future options
--code-mod

Update the exported component's import and require statements (if found) to the scope they are being exported to.

--eject-dependencies

Eject component dependencies and installs them as node modules. Does not mean Bit ejects itself. Only relevant for directly imported components that are dependencies.

davidfirst added a commit that referenced this issue Aug 28, 2019
…ke sure to throw when a bare-scope name is "current", implement "--include-dependencies" flag to behave like a fork
@davidfirst
Copy link
Member

davidfirst commented Aug 30, 2019

All improvements are implemented on #1954, except the "Possible future options".
A few changes from the description above.

  1. The flag --set-current-upstream has changed to --set-current-scope.
  2. The workspace config defaultCollection has changed to defaultScope.
  3. The scopes list is shown by running bit show with (an existing) --detailed flag. I figured that for most cases this won't be relevant.
  4. Added a new flag --all to include also non-staged components. Without this flag, when running bit export <remote> or bit export <remote> *, it affects only staged components.

davidfirst added a commit that referenced this issue Sep 2, 2019
* task #1956, replace "--last-scope" with a reserved word "current", make sure to throw when a bare-scope name is "current".

* implement "--include-dependencies" flag to behave like a fork. Meaning, when exporting with this flag, it'll export the component and all its dependencies to the remote scope, not only cached them. So then it'll be possible to completely work with the new remote without the old one.

* exporting to a different remote, does not change the component from staging to exported, unless "--set-current-scope" is used

* save "listScopes" data into the Model Component.

* implement "all" flag for exporting non-staged components.

* implement "force" flag for exporting multiple components while changing the remote-scope for some.

* show the scopes-list in show command
davidfirst added a commit that referenced this issue Sep 2, 2019
…ort" to replace the import/require statements in the source to the newly exported scope
davidfirst added a commit that referenced this issue Sep 18, 2019
* implements a part of #1956, introduce a new flag --codemod for "bit export" to replace the import/require statements in the source to the newly exported scope

* re-import components when using codemod to have the updated code on the workspace

* do not show a warning about components missing from .bitmap when "include-dependencies" flag was used

* remove components with the old scope from the package.json file and from node_modules dir
@Tallyb
Copy link
Contributor

Tallyb commented Sep 19, 2019

can we rename --code-mod to --redirect? code-mod can do any change.

@davidfirst
Copy link
Member

@Tallyb , not sure about --redirect, it doesn't tell me about the code change.
Maybe --codemod-scope-change?

@GiladShoham
Copy link
Member

maybe --codemode-scope-name?

@Tallyb
Copy link
Contributor

Tallyb commented Sep 19, 2019

--rename-scope?

@davidfirst
Copy link
Member

@Tallyb , not sure that --rename-scope is clear enough about changing the source code, which is something that Bit has never done before.
I believe that users will interpret rename-scope to an internal Bit change of the component and not their code.

@GiladShoham
Copy link
Member

@Tallyb I agree with @davidfirst . rename scope is a bit confusing because it's not say anything about code changes.

@Tallyb
Copy link
Contributor

Tallyb commented Sep 22, 2019

--codemod -> --rewire-imports / --refactor-imports : changes the import statement for components that are exported to a new collection to depend on the component in the new scope.

@GiladShoham
Copy link
Member

I'm renaming it to --rewire-scope

@itaymendel
Copy link
Contributor Author

resolved as part of b15

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants