-
Notifications
You must be signed in to change notification settings - Fork 644
Initial frontend monorepo structure #1362
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
Initial frontend monorepo structure #1362
Conversation
Created #1363 to improve on Yarn version management. |
"private": true, | ||
"main": "src/index.ts", | ||
"scripts": { | ||
"test": "yarn --cwd ../.. run test packages/console-shared" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this PR is fantastic work @vojtechszocs ! ⭐️
My only feedback at this point is just merely a question...any chance the jest projects
array (ProjectConfig) would be easier for you on this piece? It seems that Jest now internally supports monorepos as well.
https://jestjs.io/docs/en/configuration#projects-array-string-projectconfig
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, Patrick 😃
This PR retains the existing test
script (and others) in the monorepo root package.json
without any changes. Those scripts represent a single execution of some tool (e.g. Jest) to operate on the whole code base.
So instead of e.g. yarn workspaces run test
(analogy to lerna run test
), which delegates the responsibility to each package and results in multiple Jest executions, the monorepo root's test
script simply runs Jest on all the code.
In specific packages, like console-shared
above, we "override" the root test
script by scoping Jest execution to that package. This is to support developer experience on the package level, where you cd frontend/packages/console-shared
and do yarn test
etc.
Now regarding your question, I like the idea of using Jest projects
feature 👍 if we can support above mentioned root & per-package developer experience. Enumerating individual packages as Jest "projects" isn't good as it imposes assumptions about concrete packages, so we could go with:
{
"projects": ["<rootDir>/packages/*"]
}
but I think we'd still end up cwd
-ing to monorepo root since the Jest configuration is still global:
yarn --cwd ../.. run test --projects packages/console-shared
which isn't too different from the current approach. However, I can be wrong here so let me know what you think.
The long-term idea, inspired by fabric8-ui monorepo, is to extract Jest, ESLint and other tool specific configuration & scripts into a separate package (say console-scripts
) and let each package to run those scripts while reusing the same common configuration.
So in the long-term, the root test
script would become yarn workspaces run test
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, thanks for the explanation @vojtechszocs - this syntax was a little odd to me, but now I understand. Agree that long-term yarn workspaces run test
is much easier to follow and it seems this is intended ;-)
https://yarnpkg.com/lang/en/docs/cli/workspaces/#toc-yarn-workspaces-run
I'm going to update this PR to retain the |
3f9803a
to
acbe9b0
Compare
/retest |
/cc @christianvogt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @vojtechszocs. This is a great first step. I'd like to get @christianvogt's input as well.
/approve
@@ -0,0 +1 @@ | |||
yarn-path ".yarn/releases/yarn-1.15.2.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd expect yarn.lock changes to add integrity checks, but maybe those slipped into master by mistake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that existing yarn.lock
entries are not automatically updated to the latest format upon yarn install
, regardless of using --update-checksums
parameter (tested with Yarn 1.15.2).
However, when you add or modify a dependency, that dependency (as well as any related ones) will have their corresponding yarn.lock
entries updated to the latest format.
Only a few entries in the current yarn.lock
already have an integrity
field. This indicates that those dependencies were added or modified using a newer version of Yarn and passed code review (people oftentimes skip over yarn.lock
changes).
clean-frontend.sh
Outdated
@@ -1,4 +1,4 @@ | |||
#!/usr/bin/env bash | |||
|
|||
rm -rf frontend/node_modules | |||
find frontend -name 'node_modules' -type d -delete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will fail for non-empty directories, my mistake. I'll fix it shortly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in the latest PR update.
frontend/package.json
Outdated
@@ -51,7 +52,9 @@ | |||
], | |||
"collectCoverageFrom": [ | |||
"public/*.{js,jsx,ts,tsx}", | |||
"public/{components,module,ui}/**/*.{js,jsx,ts,tsx}" | |||
"public/{components,module,ui}/**/*.{js,jsx,ts,tsx}", | |||
"packages/**/*.{js,jsx,ts,tsx}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably only include files within the src
directory of the packages:
"packages/*/src/**/*.{js,jsx,ts,tsx}",
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed & fixed in the latest PR update.
acbe9b0
to
afe6d70
Compare
afe6d70
to
7977ef6
Compare
/retest |
/skip |
/test e2e-aws-console |
Thanks @vojtechszocs for starting this. I know you wanted to move the code immediately into the sub-packages but I think it's better to do this in smaller steps. /approve |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: christianvogt, spadgett, vojtechszocs The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@vojtechszocs: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
/retest |
Thanks @spadgett for fast-forwarding
Agreed. 👍 I've actually tried to symlink |
Frontend monorepo
This PR does two things:
public
directory intactCloses https://jira.coreos.com/browse/CONSOLE-1241
Closes #1363
Note: any file paths mentioned below are meant in context of the
frontend
directory.Yarn version management
.yarnrc
is used to delegate execution to the local binary at.yarn/releases/yarn-<version>.js
via theyarn-path
option. This option is supported by Yarn >= 1.0 so there's no need to bump the global version installed on the system.This causes the local Yarn binary to be used by both developers and automated systems such as CI/CD. Switching to a newer version of Yarn becomes super easy - put the new binary in
.yarn/releases
and update.yarnrc
accordingly.Developers can override this behavior by setting
yarn-path
tofalse
if necessary.Monorepo support
The monorepo is powered by Yarn workspaces, a feature introduced in Yarn v0.28 (Jul 2017) and enabled by default since Yarn v1.0.0 (Sep 2017).
This PR avoids using Lerna since Yarn workspaces already covers all of our monorepo requirements:
package.json
standardnode_modules
file structure ⭐⭐ Hoisting of dependencies (moving them "up" into root
node_modules
directory) is an optimization to eliminate redundancy and improve performance. Yarn hoists by default but also supports thenohoist
option to circumvent potential issues. See also Lerna docs on hoisting.Packages
The
packages
directory is a flat list of all the frontend packages. Theconsole
prefix implies a core package owned by the Console team. This PR introduces two core packages:@console/app
represents the Console web application itself.src/index.ts
module simply imports the React application code frompublic
directory['./polyfills.js', '@console/app']
@console/shared
represents the code shared between all packages.src/index.ts
module exports an empty object (placeholder for future updates)test
script to scope Jest execution (test co-location preference)Dependencies
Existing core
dependencies
anddevDependencies
are kept in the monorepo rootpackage.json
. In general, having all external dependencies declared in one place makes it easier to maintain a coherent technology stack across all the packages and reduce potential of conflicts or duplicities.Non-core packages can still declare specific dependencies, e.g.
react-cosmos
or@patternfly/react-console
for a potentialkubevirt-components
package.Other changes
0.0.0-fixed
)packages/.eslintrc
is a symlink topublic/.eslintrc
In future, we'll also need to ensure that ESLint
import/no-extraneous-dependencies
is applied to all the packages./cc @spadgett @jhadvig @christianvogt @priley86 @mareklibra @rawagner @jelkosz