Skip to content

Add feature --watch by including chokidar#71

Merged
jakubpawlowicz merged 3 commits intoclean-css:masterfrom
christiankozalla:master
Dec 8, 2021
Merged

Add feature --watch by including chokidar#71
jakubpawlowicz merged 3 commits intoclean-css:masterfrom
christiankozalla:master

Conversation

@christiankozalla
Copy link
Contributor

  1. Check if the watch flag has been passed
  2. Construct an array of expanded file paths in case it is a batched command
  3. Load chokidar, pass input paths to its watch method
  4. Pass minify(...) as a callback to chokidars onchange method

Check if the watch flag has been passed
Construct an array of expanded file paths in case it is a batched command
Load chokidar, pass input paths to its watch method
Pass minify(...) as a callback to chokidars onchange method
index.js Outdated
if (program.args.length > 0) {
minify(process, options, configurations, expandGlobs(program.args));
if (inputOptions.watch) {
var inputPaths = expandGlobs(program.args).map(function (path) { return path.expanded; });
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since we use expandGlobs(program.args) three times here, should we extract it into a variable?

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've extracted the call to expandGlobs() into a variable "expandedGlobs"

{
"name": "clean-css-cli",
"version": "5.4.2",
"lockfileVersion": 1,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you perhaps regenerate this file with older NPM to minimize number of changes? We may update to lockfile v2 later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright, I've set the lockfile back to version 1 by using npm v6 in order to install chokidar. Sorry about that, upgrading to v2 was just a side-effect I have not foreseen while I was on npm v7

@jakubpawlowicz
Copy link
Collaborator

Otherwise looks good!

@jakubpawlowicz
Copy link
Collaborator

👍 for changes - I'll pull the PR and give it a try locally before merging. If it's all good then we can release it.

@jakubpawlowicz
Copy link
Collaborator

All looks good, let's merge it.

@jakubpawlowicz
Copy link
Collaborator

Two comments for after merge:

  • I think we should rebuild all files on first run before 'chokidar' watches files, this is rather a well established approach
  • I think we should output to stdout sth like 'File ${path} has changed. Regenerating optimized file...'

@jakubpawlowicz jakubpawlowicz merged commit 019c031 into clean-css:master Dec 8, 2021
@jakubpawlowicz
Copy link
Collaborator

Ok, it's done. Please let me know @christiankozalla if you want to add those two simple changes or should I. Thanks!

@christiankozalla
Copy link
Contributor Author

Thank you for testing and merging!

I believe it's better if you could add these two changes, because right now I am not able to do the work, because I lying in bed sick. Nothing severe though

@jakubpawlowicz
Copy link
Collaborator

Gotcha, get well and many thanks for your contribution!

@jakubpawlowicz
Copy link
Collaborator

And it's released in clean-css 5.5.0. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants