-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Allow circular dependencies for source packages * Remove non-buildable workspaces from build anyway * Better package types utilities * Typos + fix test * Better start check and error message * Remove default export * Simplify Modular type checks * Split selectWorkspaces * Introduce --dangerouslyIgnoreCircularDependencies * Add circular dependencies docs * Add fixtures and tests * Add source type to add command + docs * update snapshots * Create short-laws-stare.md * Fix typo
- Loading branch information
1 parent
2241c2b
commit 5322a71
Showing
39 changed files
with
673 additions
and
111 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"modular-scripts": minor | ||
--- | ||
|
||
modular `source` type + `--dangerouslyIgnoreCircularDependencies` build option |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# https://editorconfig.org | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_size = 2 | ||
indent_style = space | ||
insert_final_newline = true | ||
max_line_length = 80 | ||
trim_trailing_whitespace = true | ||
|
||
[*.{md,mdx}] | ||
max_line_length = 0 | ||
trim_trailing_whitespace = false | ||
|
||
[COMMIT_EDITMSG] | ||
max_line_length = 0 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
packages/**/public | ||
/dist |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
/dist | ||
|
||
.vscode |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/dist | ||
/packages/**/public |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
disable-self-update-check true |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is the `README.md` for the whole monorepo. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Allows for adding setup configuration to Jest | ||
export {}; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// jest-dom adds custom jest matchers for asserting on DOM nodes. | ||
// allows you to do things like: | ||
// expect(element).toHaveTextContent(/react/i) | ||
// learn more: https://github.com/testing-library/jest-dom | ||
import '@testing-library/jest-dom/extend-expect'; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ | ||
"name": "ghost-building", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"author": "Cristiano Belloni <cristiano.belloni@jpmorgan.com>", | ||
"license": "MIT", | ||
"private": true, | ||
"workspaces": [ | ||
"packages/**" | ||
], | ||
"modular": { | ||
"type": "root" | ||
}, | ||
"scripts": { | ||
"start": "modular start", | ||
"build": "modular build", | ||
"test": "modular test", | ||
"lint": "eslint . --ext .js,.ts,.tsx", | ||
"prettier": "prettier --write ." | ||
}, | ||
"eslintConfig": { | ||
"extends": "modular-app" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
}, | ||
"prettier": { | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"printWidth": 80, | ||
"proseWrap": "always" | ||
}, | ||
"dependencies": { | ||
"@testing-library/dom": "^8.19.0", | ||
"@testing-library/jest-dom": "^5.16.5", | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/user-event": "^7.2.1", | ||
"@types/jest": "^29.2.3", | ||
"@types/node": "^18.11.9", | ||
"@types/react": "^18.0.25", | ||
"@types/react-dom": "^18.0.9", | ||
"eslint-config-modular-app": "^3.0.2", | ||
"modular-scripts": "^3.5.0", | ||
"modular-template-app": "^1.1.0", | ||
"modular-template-package": "^1.1.0", | ||
"prettier": "^2.7.1", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"typescript": ">=4.2.1 <4.5.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "a", | ||
"private": false, | ||
"modular": { | ||
"type": "package" | ||
}, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"e": "1.0.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function add(a: number, b: number): number { | ||
return a + b; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "b", | ||
"private": false, | ||
"modular": { | ||
"type": "package" | ||
}, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"c": "1.0.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function add(a: number, b: number): number { | ||
return a + b; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "c", | ||
"private": false, | ||
"modular": { | ||
"type": "source" | ||
}, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"b": "1.0.0", | ||
"d": "1.0.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function add(a: number, b: number): number { | ||
return a + b; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "d", | ||
"private": false, | ||
"modular": { | ||
"type": "source" | ||
}, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function add(a: number, b: number): number { | ||
return a + b; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"name": "e", | ||
"private": false, | ||
"modular": { | ||
"type": "package" | ||
}, | ||
"main": "./src/index.ts", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"a": "1.0.0" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function add(a: number, b: number): number { | ||
return a + b; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"extends": "modular-scripts/tsconfig.json", | ||
"include": ["modular", "packages/**/src"] | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
title: Circular Dependencies | ||
parent: Concepts | ||
--- | ||
|
||
# Circular dependencies and Modular | ||
|
||
`modular build` always tries to calculate the build order based on the workspace | ||
dependency graph. If it encounters a cyclic dependency during this calculation, | ||
it will bail out, since the build order can't be determined (if A depends on the | ||
build result of B and B depends on the build result of A, which one should be | ||
get built first?) | ||
|
||
Circular dependencies should never be introduced in your Modular monorepository; | ||
apart from interfering with the calculation of build order, they can | ||
[lead to unexpected results in require order](https://nodejs.org/api/modules.html#cycles), | ||
they can confuse developer tools and they are always fixable | ||
[by creating additional dependencies which contain the common parts](https://nx.dev/recipes/other/resolve-circular-dependencies). | ||
Even you manage to avoid all of those issues, circular dependencies can make | ||
refactoring fragile: if a part of A depends on a part of B and an unrelated part | ||
of B depends on an unrelated part of A, refactoring code in A can make the | ||
require order in B fail and vice versa. | ||
|
||
## `--dangerouslyIgnoreCircularDependencies` escape hatch | ||
|
||
If your circular dependencies involve packages that never get built (namely, | ||
`modular.type: source` packages), Modular can still calculate the correct build | ||
order by removing them from the dependency graph. By default, `modular build` | ||
will still refuse to build any build graph that contains a circular dependency, | ||
but this behaviour can be overridden by specifying the | ||
`--dangerouslyIgnoreCircularDependencies` flag. Please note that `modular build` | ||
will still fail if the cycle involves two or more buildable (i.e. non-`source`) | ||
packages. This doesn't solve all the other issues linked to | ||
`--dangerouslyIgnoreCircularDependencies`, so please don't use this flag in | ||
production and always split you dependencies to avoid cycles. | ||
|
||
## Examples | ||
|
||
### Cycle disappearing when `source` types are removed from the dependency graph (cycle between `package` and `source`) | ||
|
||
(assuming that `package` b is depending on `source` c and `source` c is | ||
depending on `package` b and `package` d): | ||
|
||
#### Without `--dangerouslyIgnoreCircularDependencies` the build fails | ||
|
||
```bash | ||
> modular-dev build b --descendants | ||
[modular] Building packages at: b | ||
[modular] Cycle detected, b -> c -> b | ||
``` | ||
|
||
#### With `--dangerouslyIgnoreCircularDependencies` the build warns but succeeds | ||
|
||
```bash | ||
> modular-dev build b --descendants --dangerouslyIgnoreCircularDependencies | ||
[modular] Building packages at: b | ||
[modular] You chose to dangerously ignore cycles in the dependency graph. Builds will still fail if a cycle is found involving two or more buildable packages. Please note that the use of this flag is not recommended. It's always possible to break a cyclic dependency by creating an additional dependency that contains the common code. | ||
[modular] $ b: generating .d.ts files | ||
[modular] $ b: building b... | ||
[modular] $ b: built b in /Users/N761472/dev/rig/ghost-building/dist/b | ||
[modular] $ d: generating .d.ts files | ||
[modular] $ d: building d... | ||
[modular] $ d: built d in /Users/N761472/dev/rig/ghost-building/dist/d | ||
``` | ||
### Cycle not disappearing when `source` types are removed from the dependency graph (cycle between `package`s) | ||
(assuming that `package` b is depending on `package` c and `package` c is | ||
depending on `package` b and `package` d): | ||
#### Even with `--dangerouslyIgnoreCircularDependencies` the build fails: | ||
```bash | ||
> modular-dev build b --descendants --dangerouslyIgnoreCircularDependencies | ||
[modular] Building packages at: b | ||
[modular] You chose to dangerously ignore cycles in the dependency graph. Builds will still fail if a cycle is found involving two or more buildable packages. Please note that the use of this flag is not recommended. It's always possible to break a cyclic dependency by creating an additional dependency that contains the common code. | ||
[modular] Cycle detected, b -> c -> b | ||
``` |
This file contains 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
Oops, something went wrong.