-
Notifications
You must be signed in to change notification settings - Fork 3
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
Add --update and --watch options #4
Conversation
63ffa55
to
cad21c4
Compare
@LordotU Why did you choose |
package.json
Outdated
@@ -61,5 +63,8 @@ | |||
"CLI", | |||
"backtick" | |||
] | |||
}, | |||
"peerDependencies": { |
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 is better to create separate PR for another changes
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
update-and-show-snapshots.js
Outdated
async function updateAndShowSnaphots (print, error, cwd, filter) { | ||
print(chalk.blue('\nUpdating snapshots... \n')) | ||
|
||
let { stdout, stderr } = await execCommand('"./node_modules/.bin/jest" -u', { |
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.
npx jest --no-install
is a better way since we can’t trust to find jest
in ./node_modules/.bin/
.
For instance, we print-snapshots
can be run from ./test
dir. In this case ./node_modules/.bin/jest
will not be found.
update-and-show-snapshots.js
Outdated
cwd | ||
}) | ||
|
||
print(chalk.grey(stdout)) |
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.
Here you will lose Jest color output. We need to keep origin colors, because jest -u
can fall and colors will help us to find the reasons.
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.
In Node.js we have std: inherit
option to bind executed script to existed stdout
/stderr
. In this case you will not loose colors.
Hi! Chokidar is very hyped, yes, but I think it is the most maintainable package with pretty API, anymatch pattern support and short graph of deps. Also we have, for example:
and some others, that were updated a year ago |
f066efe
to
b71cd24
Compare
What about webpack’s watchpack? |
When I searched, this package was not even on the second page, cause my query was |
bin.js
Outdated
|
||
if (arg === '--watch') { | ||
(await watchAndShowSnaphots(print, error, cwd, filter)) | ||
.on('error', err => error(err.stack || err)) |
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.
Let’s refactor this code to something more readable. We even pass error
function there, we do not need to print errors here.
Yeap. I prefer smaller dependency |
update-and-show-snapshots.js
Outdated
|
||
print(chalk.green('Snapshots updated! \n')) | ||
spawned.on('exit', async () => { | ||
print(chalk.green('\nSnapshots updated! \n')) |
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 think we do not need this note
https://npm.anvaka.com/#/view/2d/watchpack vs https://npm.anvaka.com/#/view/2d/chokidar Chokidar is the winner? ) |
Yeap, let’s use chokidar |
update-and-show-snapshots.js
Outdated
let showSnapshots = require('./show-snapshots') | ||
|
||
async function updateAndShowSnaphots (print, cwd, filter) { | ||
print(chalk.blue('\nUpdating snapshots... \n')) |
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.
Let’s remove this note as well
watch-and-show-snapshots.js
Outdated
if (fs.existsSync(`${ cwd }/.gitignore`)) { | ||
ignored = [...new Set([ | ||
...ignored, | ||
...parseGitignore(fs.readFileSync(`${ cwd }/.gitignore`)).map( |
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 can believe that cwd
will be the root of the project (since the user can run tool from test/
dir)
The only way to find the project root is to find package.json
.
bin.js
Outdated
@@ -16,16 +20,22 @@ function print (...lines) { | |||
|
|||
async function run () { | |||
let arg = process.argv[2] || '' | |||
let filter = process.argv[3] || '' |
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.
The filter can be passed before --update
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.
Are shure about give ability to set filter before args?
For example, all CLIs that working with paths accept it as last argument
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.
Yeap. User may call npx print-snapshots server
, found problem, press arrow up to load latest command in terminal and add --watch
in the end.
By the way, did we forget about changing --help
?
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, i will fix it and update help output. Thank you!
update-and-show-snapshots.js
Outdated
cwd, stdio: 'inherit' | ||
}) | ||
|
||
spawned.on('exit', async () => { |
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.
Why do we need async
here? exit
callback can’t return a Promise
watch-and-show-snapshots.js
Outdated
let chokidar = require('chokidar') | ||
let parseGitignore = require('parse-gitignore') | ||
|
||
let updateAndShowSnaphots = require('./update-and-show-snapshots') | ||
|
||
let rootPath = path.dirname(require.main.filename) |
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.
require.main.filename
will point to /path/to/the/project/node_modules/.bin/print-snapshots
.
I think we need pkg-up
to find package.json
and be sure about the root of the project.
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, I need to sleep a little :-)
@ai Thanks for the tips. I was glad to help! |
Do you have a Twitter account? |
Released at 0.2 |
The same as Github - https://twitter.com/LordotU. |
No description provided.