Merged
Conversation
🦋 Changeset detectedLatest commit: a6ffa4d The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Collaborator
sgb-io
reviewed
Dec 8, 2022
|
|
||
| type PackageTypeDefinitions = { [Type in PackageType]: PackageTypeDefinition }; | ||
|
|
||
| const packageTypeDefinitions: PackageTypeDefinitions = { |
Contributor
There was a problem hiding this comment.
Ideal content to go in the markdown docs as a table
added 2 commits
December 16, 2022 15:15
Contributor
|
Approved, but wondering if we should PR into feature/v4 and fixing the conflicts (if any) now- having said that I don't mind merging to main and then pulling main into v4 again, not a huge effort |
AlbertoBrusa
approved these changes
Dec 20, 2022
Merged
sgb-io
approved these changes
Dec 20, 2022
Contributor
sgb-io
left a comment
There was a problem hiding this comment.
LGTM, just 1 comment about some possible debug artefacts
| @@ -157,10 +162,14 @@ async function addPackage({ | |||
|
|
|||
| try { | |||
Contributor
There was a problem hiding this comment.
Are these console.log statements intentional?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
modular.type: sourceand--dangerouslyIgnoreCircularDependenciesThis PR introduces the
sourcetype (i.e., a package that can be imported but never gets built or started)Why we are considering
sourcepackagesThe
sourcetype is useful for all those packages that just get imported fromapp,esm-vieworpackageworkspaces and never get built (ie common utils or views only used internally). When thepackagetype is used for these kind of workspaces, a confusing situation arises, in which these packages should never be built standalone (they can even fail, since they're often intended to be built as part ofapps oresm-views and might need build-time plugins) but still get built by selective build operators (for example,--changedwill try to incrementally build all changed Modular workspaces). There are two ways of avoiding this: disallowing direct imports from source via eslint rules or introducing thesourcetype. The first solution is not really practical, since many pre-existing projects are already set-up to import other packages from source (and you probably shouldn't be forced to build all your common utils everytime), so thesourcetype could be an useful solution to the problem.When to convert to
sourcepackagesIf your workspace:
package*app,esm-vieworpackagetype in your monorepo**distdirectoryyour workspace is a good candidate to be converted to the
sourcetype* You can also convert a
viewtosource, but you will lose the possibility ofmodular starting it.** If it's imported by only one workspace and it's not published as per 4), you might consider incorporating it into the importing package?
sourcepackages and circular dependenciesNormally
modular buildthrows when there are circular dependencies in the workspace dependencies graph, since it can't calculate the correct build order. Sincesourcetypes don't build, however, it's possible for Modular to work with circular dependencies, if the circularity depends onsourcepackages (i.e., if, removing source packages from the graph, the cycle[s] disappear). We require the flag--dangerouslyIgnoreCircularDependenciesto be set in that case.Why we are considering allowing circular dependencies
Circular dependencies should not be used; they mess up the require order, they can confuse developer tools and they are always fixable by creating additional dependencies which contain the common parts.
When Modular analyses dependencies to build them in order, the algorithm can't decide what to build first when it encounters a circular dependency (e.g.: if A depends on B but B depends on A, how do you know which
distfiles are needed first?), and it throws. Even if A importsB/a-moduleand B depends onA/some-module(so the circularity can technically "work", because the code that importsa-moduleisn't the same code that is imported byB, and vice-versa), it's impossible to determine that that is the case by just statically analysing the code. Additionally, the resulting code is a nightmare to maintain (if you refactor files in A so thatimportandimport-ed are in the same file, the build chain comes crashing down). If possible, projects should not use circular dependencies, and Modular might to want warn in the future when it detects them.This PR shows that the Modular order algorithm can allow circular dependencies if we introduce a new
modular.typecalledsource, which signals that the package doesn't need to (and cannot) be built. If we have a circular dependency involving a source package (i.e. ifBissourcein the previous example), we can still calculate a valid build order by removingsources from the order graph, since they don't get built and nothing can depend on their build result anyway. This is not to encourage circular deps, but to allow huge projects that unfortunately already have them to be onboarded without extensive refactoring.Examples
Cycle disappearing when
sourcetypes are removed from the dependency graph (cycle betweenpackageandsource)(assuming that
packageb is depending onsourcec andsourcec isdepending on
packageb andpackaged):Without
--dangerouslyIgnoreCircularDependenciesthe build failsWith
--dangerouslyIgnoreCircularDependenciesthe build warns but succeedsCycle not disappearing when
sourcetypes are removed from the dependency graph (cycle betweenpackages)(assuming that
packageb is depending onpackagec andpackagec isdepending on
packageb andpackaged):Even with
--dangerouslyIgnoreCircularDependenciesthe build fails:TODO
sourcetype--dangerouslyIgnoreCircularDependenciessourcetype--dangerouslyIgnoreCircularDependencies