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

Use Rollup for tests and examples #348

Merged
merged 16 commits into from
Sep 8, 2022
Merged

Conversation

gabalafou
Copy link
Contributor

@gabalafou gabalafou commented Aug 13, 2022

Closes #332.

Test plan

For each package, for example @lumino/algorithm:

cd packages/algorithm
yarn build:test
yarn test:firefox
yarn test:firefox-headless
yarn test:chrome
yarn test:chrome-headless

One way to check that each package (not examples, not tests) builds exactly the same as before is to build the packages from the main branch, then build them with this PR and compare the two. You can leverage git to do it:

git checkout -b build-from-main main
git clean -xfd
echo node_modules/ > .gitignore
yarn && yarn build && yarn build:examples && yarn build:test
git add .
git commit --no-verify -m"build"
git merge rollup
git checkout -b build-from-rollup rollup
git clean -xfd
echo node_modules/ > .gitignore
yarn && yarn build && yarn build:examples && yarn build:test
git add .
git commit --no-verify -m"build"
git diff build-from-main --stat

You'll see that the bundles for the examples and the tests have changed. That's to be expected because they were previously built with Webpack. But you shouldn't see any differences for the main packages, which were built with Rollup before this PR (and are still built with Rollup after this PR).

@welcome
Copy link

welcome bot commented Aug 13, 2022

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@gabalafou gabalafou changed the title Replace webpack with rollup for packages/algorithm/tests Use Rollup for tests and examples Aug 13, 2022
@gabalafou
Copy link
Contributor Author

gabalafou commented Aug 13, 2022

I'm opening this draft pull request with one package in order to catch any problems before extending to all of the other packages.

I will soon also convert a single example from the examples folder to use rollup instead of webpack.

Copy link
Contributor Author

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done self-reviewing

@@ -26,9 +26,9 @@
"api": "api-extractor run --local --verbose",
"build": "npm run build:src && rollup -c",
"build:src": "tsc --build",
"build:test": "tsc --build tests && cd tests && webpack",
"build:test": "npm run clean:test && tsc --build tests && cd tests && rollup -c",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should clean be part of the build step? If you don't run clean and delete the tests/tsconfig.tsbuildinfo file then the build step will do nothing.

"clean": "rimraf ./lib && rimraf *.tsbuildinfo && rimraf ./types && rimraf ./dist",
"clean:test": "rimraf tests/build",
"clean:test": "rimraf tests/lib && rimraf tests/tsconfig.tsbuildinfo",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Must delete the .tsbuildinfo file or else the build command will do nothing.

packages/algorithm/package.json Show resolved Hide resolved
packages/algorithm/tests/rollup.config.js Outdated Show resolved Hide resolved
packages/algorithm/package.json Show resolved Hide resolved
Copy link
Contributor Author

@gabalafou gabalafou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done self-reviewing second commit (example-accordionpanel)

@@ -1188,6 +1188,14 @@
estree-walker "^1.0.1"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All yarn.lock changes should be related to the changes in the package.json files in this PR.

@@ -26,9 +26,9 @@
"api": "api-extractor run --local --verbose",
"build": "npm run build:src && rollup -c",
"build:src": "tsc --build",
"build:test": "tsc --build tests && cd tests && webpack",
"build:test": "npm run clean:test && tsc --build tests && cd tests && rollup -c",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure if I should add clean:test here, but without it the build:test script/command is not idempotent because it creates a tsconfig.tsbuildinfo file, which I found prevents a second run of the build:test command from picking up intervening changes in the test code.

@gabalafou
Copy link
Contributor Author

Thanks @blink1073 for reviewing the test-related Rollup changes. I feel confident now extending my changes in @lumino/algorithm tests to the other packages' tests in the monorepo.

@blink1073 blink1073 added the maintenance Dependencies, build, technical debt, etc. label Aug 15, 2022
Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot @gabalafou

I added some suggestions before you move forward.

packages/algorithm/package.json Outdated Show resolved Hide resolved
examples/example-accordionpanel/rollup.config.js Outdated Show resolved Hide resolved
@@ -7400,6 +7509,13 @@ rollup@^2.77.2:
optionalDependencies:
fsevents "~2.3.2"

rollup@^2.77.3:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging, we should check that this entry disappears as it should merge with the previous one. But it is not a blocker.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. Still hasn't disappeared.

Copy link
Contributor Author

@gabalafou gabalafou Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I added Rollup to the package.json file for each example, it set: "rollup": "^2.77.3".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind running yarn why rollup to find why we have two versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is my console log for yarn why rollup:

yarn why rollup                                                                                                                                                                                                                                                                              rollup
yarn why v1.22.19
[1/4] 🤔  Why do we have the module "rollup"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "rollup@2.77.2"
info Has been hoisted to "rollup"
info Reasons this module exists
   - "workspace-aggregator-511ef2db-8ac6-4e9e-8474-e5094676397f" depends on it
   - Hoisted from "_project_#@lumino#algorithm#rollup"
   - Hoisted from "_project_#@lumino#application#rollup"
   - Hoisted from "_project_#@lumino#collections#rollup"
   - Hoisted from "_project_#@lumino#commands#rollup"
   - Hoisted from "_project_#@lumino#coreutils#rollup"
   - Hoisted from "_project_#@lumino#datagrid#rollup"
   - Hoisted from "_project_#@lumino#disposable#rollup"
   - Hoisted from "_project_#@lumino#domutils#rollup"
   - Hoisted from "_project_#@lumino#dragdrop#rollup"
   - Hoisted from "_project_#@lumino#keyboard#rollup"
   - Hoisted from "_project_#@lumino#messaging#rollup"
   - Hoisted from "_project_#@lumino#polling#rollup"
   - Hoisted from "_project_#@lumino#properties#rollup"
   - Hoisted from "_project_#@lumino#signaling#rollup"
   - Hoisted from "_project_#@lumino#virtualdom#rollup"
   - Hoisted from "_project_#@lumino#widgets#rollup"
info Disk size without dependencies: "6.43MB"
info Disk size with unique dependencies: "6.43MB"
info Disk size with transitive dependencies: "6.43MB"
info Number of shared dependencies: 0
=> Found "@lumino/example-accordionpanel#rollup@2.77.3"
info This module exists because "_project_#@lumino#example-accordionpanel" depends on it.
info Disk size without dependencies: "6.43MB"
info Disk size with unique dependencies: "6.43MB"
info Disk size with transitive dependencies: "6.43MB"
info Number of shared dependencies: 0
=> Found "@lumino/example-datagrid#rollup@2.77.3"
info This module exists because "_project_#@lumino#example-datagrid" depends on it.
info Disk size without dependencies: "6.43MB"
info Disk size with unique dependencies: "6.43MB"
info Disk size with transitive dependencies: "6.43MB"
info Number of shared dependencies: 0
=> Found "@lumino/example-dockpanel#rollup@2.77.3"
info This module exists because "_project_#@lumino#example-dockpanel" depends on it.
info Disk size without dependencies: "6.43MB"
info Disk size with unique dependencies: "6.43MB"
info Disk size with transitive dependencies: "6.43MB"
info Number of shared dependencies: 0
✨  Done in 0.85s.

gabalafou and others added 2 commits August 16, 2022 04:18
Co-authored-by: Frédéric Collonval <fcollonval@users.noreply.github.com>
@gabalafou
Copy link
Contributor Author

gabalafou commented Aug 19, 2022

@fcollonval, could you take a look at my last commit add2f47, is it something like what you had imagined?

One question I have: should I move all of the rollup dependencies (the plugins) out of the various package.jsons and into the root package.json?

import nodeResolve from '@rollup/plugin-node-resolve';
import styles from 'rollup-plugin-styles';

const globals = id =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copied this line from rollup.src.config because it fixed a warning or error message that I saw from the rollup command.

rollup.src.config.js Show resolved Hide resolved
packages/algorithm/rollup.config.js Show resolved Hide resolved
packages/algorithm/rollup.config.js Show resolved Hide resolved
@fcollonval
Copy link
Member

should I move all of the rollup dependencies (the plugins) out of the various package.jsons and into the root package.json?

@gabalafou it is better to let them in each package where they are used.

import nodeResolve from '@rollup/plugin-node-resolve';
import styles from 'rollup-plugin-styles';

export const globals = id =>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's something I find a bit counter-intuitive about these base config files. For example, I tripped up here because I thought I could replace this line with an import like so:

import { globals } from './rollup.src.config';

But that caused the build script in the examples to fail. That's because importing from that other Rollup config brought along its dependencies, which are not included in the package.json for each of the example packages. In other words, for example, rollup-plugin-postcss is not included as a dependency for any of the example-* packages, but is a dependency in the other packages.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is expected - a solution would be to define a base config that only uses common dep. But here this is probably not worth the trouble just for the globals definition.

@gabalafou gabalafou marked this pull request as ready for review September 5, 2022 21:50
Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gabalafou

We only have to figure out why there are still two versions of rollup in the yarn.lock. And we should be good to go.

@@ -7400,6 +7509,13 @@ rollup@^2.77.2:
optionalDependencies:
fsevents "~2.3.2"

rollup@^2.77.3:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind running yarn why rollup to find why we have two versions?

import nodeResolve from '@rollup/plugin-node-resolve';
import styles from 'rollup-plugin-styles';

export const globals = id =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is expected - a solution would be to define a base config that only uses common dep. But here this is probably not worth the trouble just for the globals definition.

@fcollonval fcollonval added this to the Lumino 2 milestone Sep 6, 2022
@fcollonval
Copy link
Member

Kicking the CI

Copy link
Member

@fcollonval fcollonval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks a lot @gabalafou

@fcollonval fcollonval merged commit 45a6e9e into jupyterlab:main Sep 8, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
maintenance Dependencies, build, technical debt, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove webpack from Lumino examples and code base
3 participants