In the context of 4D development, managing components typically involves a substantial amount of work. However, introducing the Component Manager feature in the 4D environment represents a significant advancement in component management.
No longer confined to placing components in a designated Components folder, this feature relies on two key elements: dependencies.json and environment4d.json. Since 4D 20 R5, these files offer developers better visibility into application dependencies and the flexibility to customize component paths.
A COMPONENT manager interface in development
Before diving into the heart of the matter, please be informed that you can currently view 4D components and components from your project’s Components folder in the brand new Project Dependencies screen that you can access from the Design menu.
Not only does this screen allows you to view your project dependencies, but it will also soon allow you to add new ones and manage them.
Structured Management with dependencies.json
Component management is orchestrated through dependencies.json, a manifest file listing the components your application uses. This manifest file ensures a clear structure for dependency management by simplifying the loading of these crucial elements.
The benefit is that all your projects are maintained in a flat structure (such as via GitHub Desktop), eliminating the need for aliases or creating duplicate copies, especially when dealing with interdependent components.
dependencies.json example:
{ "dependencies": { "MyComponent" : {} } }
In this example, MyComponent, which is the component we want to load, is located next to the package folder.
Customization with environment4d.json
If the default path (next to the package folder) doesn’t suit you, defining component paths in a personal working environment file is still possible. The environment4d.json enables environment customization. By specifying absolute or relative paths to components, this manifest offers appreciable adaptability to meet the specific needs of each project.
The direct benefit is that each developer can have their environment file in a parent folder of the database, allowing them to decide not to commit it, for instance, and to accommodate their disk organization.
environment4d.json example:
{ "dependencies": { "myComponent1" : "../MyComponent1", "myComponent2" : "./MyComponent2", "myComponent3" : "file:///Users/jean/MyComponent3" } }
Practical Management for Developers
If environment4d.json is absent for a given dependency or if this file lacks information on a dependency listed in dependencies.json, 4D utilizes the name mentioned in dependencies.json to retrieve the dependency next to the package folder.
Get statE of all your components in a single place
In the project dependencies screen, you will also be able to view the components declared in dependencies.json and environment4d.json and get information for each dependency, such as the name, source, and access to the dependency on disk, as well as the state of the dependency: whether there is a conflict with another dependency, whether the dependency has been successfully loaded, and why if not.
The Component Manager feature represents a notable advancement in the 4D ecosystem. By leveraging dependencies.json and environment4d.json, this new approach offers developers enhanced control over component management. Take a look at the documentation for more details, and stay tuned for upcoming updates on the component manager!