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

chore: improve build responsiveness #2992

Merged
merged 6 commits into from Mar 23, 2021
Merged

chore: improve build responsiveness #2992

merged 6 commits into from Mar 23, 2021

Conversation

vladitasev
Copy link
Contributor

@vladitasev vladitasev commented Mar 23, 2021

This change fixes 2 bugs of the yarn start command:

  • Newly created .css files are not usable unless yarn start is killed and re-run. The reason is a known postcss bug in --watch mode: newly created files are not detected, only existing files are re-compiled (--watch mode doesn't pick up new files  postcss/postcss-cli#161).
  • Newly added entries to messagebundle.properties are not automatically available in i18n-defaults.js and if you try to use them - the bundle breaks. This is due to the fact that there is no watch mode for i18n.

Changes:

  • Use chokidar for watching the themes/ directory and for each newly added file run postcss to build this file only, and then run again postcss -w to start watching it.
  • Create a watch task for i18n too: it only needs to watch the messagebundle.properties file and regenerate the defaults file (not the .jsons).

After the change it's possible to create a new component with all needed files and resources without restarting yarn start.

}
}

const process = processes.find(p => p.cmd.includes("postcss") && p.cmd.endsWith(`-w --packageName=${packageName}`));
Copy link
Contributor

Choose a reason for hiding this comment

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

better make this p.cmd.includes which has the same effect but is less error prone in case someone adds more parameters to the postcss command

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 put endsWithbecause @ui5/webcomponents will also match @ui5/webcomponents-fiori.

if (process) {
await fkill(process.pid);

exec(`npx nps build.styles.components`, (err, stdout, stderr) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

isn't the watch below sufficient because a new start will see the newly added files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It turns out no, that's why probably we have first build.styles.components and only then watch.styles.components. The -w flag does not execute the initial action.

console.log(stdout);
});

exec(`npx nps watch.styles.components`, (err, stdout, stderr) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

not sure if starting npx from yarn won't have additional problems. could we reuse the nps api with require?

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 didn't find any. That was my initial intention too. I could only find nps-utils.

@@ -62,12 +64,14 @@ const getScripts = (options) => {
es5: 'rollup --config config/rollup.config.js -w --environment ES5_BUILD,DEV,DEPLOY_PUBLIC_PATH:/resources/'
},
styles: {
default: 'concurrently "nps watch.styles.themes" "nps watch.styles.components"',
default: 'concurrently "nps watch.styles.themes" "nps watch.styles.components" "nps watch.styles.monitor"',
Copy link
Contributor

Choose a reason for hiding this comment

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

watch and monitor are the same thing, something like restart-on-add is more descriptive

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 are a couple of general problems:

  • I still can't have it work on windows: the ps-list module ships a binary that simulates ps on windows, but it does not provide the full command, only the name of the executable "something.exe" without any parameters. Running ps on the git bash is the same.
  • Sometimes the ps-list fails with a promise rejection on Mac, therefore the retry. The retry works, but once I had an error trying to kill the current postcss process.

@vladitasev vladitasev changed the title Restart postcss chore: improve build responsiveness Mar 23, 2021
@vladitasev vladitasev merged commit 8048c9f into master Mar 23, 2021
@vladitasev vladitasev deleted the restart-postcss branch March 23, 2021 15:20
ilhan007 pushed a commit that referenced this pull request Mar 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants