-
-
Notifications
You must be signed in to change notification settings - Fork 15
Fix node-sass watcher #71
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
Conversation
Currently node-sass watcher is used to compile sass files when some changes occurs. The problem is when file A is imported in file B. If some change occurs in file A, file A will be successfully compiled by `node-sass` but file B will not be updated. So when `livesync command` is executed, changes are not reflected in the app's UI. This PR removes `--watch` option from `node-sass` compiler and introduces chokidar watcher. Also fixes this #70
src/lib/converter.js
Outdated
options = options || {}; | ||
var sassPath = getSassPath(); | ||
var data = { | ||
sassPath: sassPath, |
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.
you can use short syntax for all properties:
var data = {
sassPath,
projectDir,
...
}
src/lib/converter.js
Outdated
cwd: appDir, | ||
awaitWriteFinish: { | ||
pollInterval: 100, | ||
stabilityThreshold: 500 |
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.
isn't it way too long, maybe 300 ?
src/lib/converter.js
Outdated
logger.info('Found peer node-sass'); | ||
} catch (err) { } | ||
} else { | ||
throw Error('node-sass installation local to project was not found. Install by executing `npm install node-sass`.'); |
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.
throw new Error
src/lib/converter.js
Outdated
var currentSassProcess = spawn(process.execPath, nodeArgs, { env: env }); | ||
|
||
var isResolved = false; | ||
var watchResolveTimeout; |
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.
this variable is not used
src/lib/converter.js
Outdated
if (code === 0) { | ||
resolve(); | ||
} else { | ||
reject(Error('SASS compiler failed with exit code ' + code)); |
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.
new Error
src/lib/converter.js
Outdated
}); | ||
|
||
// SASS does not recompile on watch, so directly resolve. | ||
if (options.watch && !isResolved) { |
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 don't think you need the check for options.watch
here
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 fact the whole if and the call to resolve
is not needed here.
src/lib/converter.js
Outdated
|
||
watcher = choki.watch(['**/*.scss', '**/*.sass'], watcherOptions) | ||
.on('all', (event, filePath) => { | ||
spawnNodeSass(data); |
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 case you apply several changes and save them one-by-one, you'll receive multiple events and several processes will be spawned. This is a problem, so I suggest chaining the calls to spawnNodeSass
:
var watchPromisesChain = Promise.resolve();
watcher = choki.watch(['**/*.scss', '**/*.sass'], watcherOptions)
.on('all', (event, filePath) => {
watchPromiseChain = watchPromiseChain.then( () => spawnNodeSass(data) );
});
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.
Great work!
src/lib/converter.js
Outdated
if (fs.existsSync(sassPath)) { | ||
try { | ||
logger.info('Found peer node-sass'); | ||
} catch (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.
When will the logger.info
fail ?
Currently node-sass watcher is used to compile sass files when some changes occurs. The problem is when file A is imported in file B. If some change occurs in file A, file A will be successfully compiled by
node-sass
but file B will not be updated. So whenlivesync command
is executed, changes are not reflected in the app's UI.This PR removes
--watch
option fromnode-sass
compiler and introduces chokidar watcher.Also fixes this #70