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
feat: add 'watch' mode #138
Conversation
3f3bbb2
to
b85f4a4
Compare
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.
Над тестами бы подумать, конечно. Но в целом ок
lib/micromatch/index.js
Outdated
const lastArg = args[args.length - 1]; | ||
|
||
if (args.length > 1 && isPlainObject(lastArg)) { | ||
Object.assign({}, lastArg, options); |
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.
и с полученным в итоге объектом ты ничего не делаешь
package.json
Outdated
"cp-file": "5.0.0", | ||
"glob": "7.1.2", | ||
"glob-stream": "6.1.0", | ||
"graceful-fs": "4.1.11", | ||
"lodash.isplainobject": "^4.0.6", |
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.
нафиг оно нужно, подключай весь lodash
и не парься. Это же не клиентский код
lib/streams/watch-stream.js
Outdated
const micromatchOptions = { dot: options.dot }; | ||
const cwd = this._cwd = options.cwd; | ||
|
||
const chokidar = proxyquire('chokidar', { |
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.
оставь коммент зачем мы его так странно подключаем
lib/streams/watch-stream.js
Outdated
/** | ||
* Must be implemented in a child class of stream.Readable | ||
*/ | ||
// eslint-disable-next-line class-methods-use-this |
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.
это же отключает правило про пустую строчку сразу после объявления метода? А зачем там пустая строка? Почему нельзя написать:
_read() {}
_read() {
}
lib/streams/watch-stream.js
Outdated
const cwd = this._cwd = options.cwd; | ||
|
||
const chokidar = proxyquire('chokidar', { | ||
anymatch: proxyquire('anymatch', { micromatch: micromatch.bindOptions(micromatchOptions) }) |
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.
разнеси по строчкам, ну сложно же читается
README.md
Outdated
|
||
Tartifacts will work in an observe mode which means that all files and directories will be added to a destination directory or archive as soon as they appear on a file system. | ||
|
||
Note: in order to stop tartifacts `SIGTERM` signal should be sent |
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.
здесь нужно написать, что процесс будет завершен корректно (с закрытием всех файловых дескрипторов), но на это нужно время
lib/streams/watch-stream.js
Outdated
watcher.on(WatcherEvents.add, path => this._push(path)); | ||
options.nodir || watcher.on(WatcherEvents.addDir, path => this._push(path)); | ||
|
||
process.on(SIGINT, () => { |
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.
SIGTERM тоже нужно обрабатывать. И, да, при таком переопределении теряется стандартная логика про exitCode
81f3283
to
e644d34
Compare
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.
Спасибо! В целом решение с Watch-стримом нравится.
Написал вопросы по конкретным кейсам.
|
||
// 'chokidar' does not provide the ability to pass 'dot' option to 'micromatch' directly, | ||
// so we use 'proxyquire' to monkey patch 'micromatch' in order to call all its methods with this option | ||
const chokidar = proxyquire('chokidar', { |
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.
Давай вынесем это в отдельный модуль (файл), чтобы в стриме просто его рекваерить.
Тогда на эту логику можно будет написать тест: вызывается micromatch
с необходимыми опциями.
* @param {object} options | ||
* @returns {function} | ||
*/ | ||
exports.bindOptions = (options) => { |
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.
Добавь, пожалуйста, тесты на этот модуль и напиши пару слов зачем он нужен.
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.
А я в месте использования написал, что там за магия происходит
lib/streams/watch-stream.js
Outdated
watcher.on(WATCHER_EVENTS.add, path => this._push(path)); | ||
options.nodir || watcher.on(WATCHER_EVENTS.addDir, path => this._push(path)); | ||
|
||
SIGNALS.forEach((signal) => process.on(signal, () => this._close(watcher))); |
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.
Как это будет работать в CLI?
Нажал я такой cltr + c
, что должно произойти?) Что я увижу как пользователь?
lib/streams/watch-stream.js
Outdated
}); | ||
|
||
const watcher = chokidar.watch(patterns, { cwd, followSymlinks: options.follow }); | ||
watcher.on(WATCHER_EVENTS.add, path => this._push(path)); |
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.
Я правильно понимаю, что тут и файлы и симлинки?
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.
Что с событиями удаления (unlink
и unlinkDir
)?
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.
Если сработает change
, что в итоге попадёт в архив? Первая версия этого файла? Файл вообще не попадёт?
Вот кейс который меня интересует. В ENB «таргеты» по смыслу являются кэшами.
Т.е. во время сборки не только добавляются новые файлы, но и старые могут быть изменены, а так же не изменены (если mtime подходит). Но эти файлы всё равно должны попасть в архив.
Как это будет работать с текущим решением?
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.
Ну и jsdoc ты зря повыгашивал, наверное
lib/artifact/artifact.js
Outdated
|
||
module.exports = class Artifact { | ||
static create(destDir, streams) { | ||
return new Artifact(destDir, streams); |
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.
...args
lib/artifact/artifact.js
Outdated
|
||
write() { | ||
return makeDir(this._destDir, { fs }) | ||
.then(() => { |
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.
async await?
lib/artifact/index.js
Outdated
const TarStream = streams.TarStream; | ||
const CopyStream = streams.CopyStream; | ||
const TransformStream = streams.TransformStream; | ||
const WatchStream = streams.WatchStream; |
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.
desctructuring
lib/artifact/index.js
Outdated
}; | ||
const writeStreamOptions = {emptyFiles: options.emptyFiles, emptyDirs: options.emptyDirs}; | ||
const gzipOptions = {gzip: options.gzip, gzipOptions: options.gzipOptions}; | ||
|
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.
лишняя пустая строка. А тут линтер не настроен?
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.
он настроен, но не ругается
lib/artifact/artifact.js
Outdated
write() { | ||
return makeDir(this._destDir, { fs }) | ||
.then(() => { | ||
return new Promise((resolve, reject) => { |
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.
этот промис нужно создавать до makeDir
Тестов новых пока не писал После рефакторинга все старые тесты проходят (я сами тесты не выгашивал, а просто подправил род новую архитектуру) |
c88f7fb
to
3f828c0
Compare
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.
Пару замечаний по документации.
Тестов конечно не хватает :)
Давай после влития pr выпустим препатч и проверим с помощью dobby
, что в проектах всё продолжает работать как и раньше.
README.md
Outdated
|
||
Tartifacts will work in an observe mode which means that all files and directories will be added to a destination directory or archive as soon as they appear on a file system. | ||
|
||
Note: in order to stop tartifacts `SIGTERM` or `SIGINT` signal should be sent; these signals stop observing of a file system, but do not abort the process, so all file descriptors will be closed correctly and all tasks will be finished after a while |
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.
Поправь документацию, сейчас нужно вызывать метод, а не отправить сигналы.
|
||
process.on('SIGTERM', () => tartifacts.closeArtifacts()); | ||
|
||
tartifacts.writeArtifacts({ |
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.
Надо в API документации добавить про класс Tartifacts
и его методы.
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.
добавил
18b7b72
to
1a9355e
Compare
проверил
постараюсь на новую функциональность дописать в свободное время |
cc @j0tunn @blond