mirror of
https://github.com/danog/dart-sass.git
synced 2025-01-22 22:02:00 +01:00
Check fs.existsSync() before running fs.statSync() (#812)
This produces non-negligible speed improvements for Node users with lots of imports.
This commit is contained in:
parent
d9ebb5eff0
commit
35880d171f
@ -1,3 +1,7 @@
|
||||
## 1.22.12
|
||||
|
||||
* Improve the performance of Node.js compilation involving many `@import`s.
|
||||
|
||||
## 1.22.11
|
||||
|
||||
* Don't try to load unquoted plain-CSS indented-syntax imports.
|
||||
|
@ -156,23 +156,39 @@ String _cleanErrorMessage(_SystemError error) {
|
||||
}
|
||||
|
||||
bool fileExists(String path) {
|
||||
try {
|
||||
return _fs.statSync(path).isFile();
|
||||
} catch (error) {
|
||||
var systemError = error as _SystemError;
|
||||
if (systemError.code == 'ENOENT') return false;
|
||||
rethrow;
|
||||
}
|
||||
return _systemErrorToFileSystemException(() {
|
||||
// `existsSync()` is faster than `statSync()`, but it doesn't clarify
|
||||
// whether the entity in question is a file or a directory. Since false
|
||||
// negatives are much more common than false positives, it works out in our
|
||||
// favor to check this first.
|
||||
if (!_fs.existsSync(path)) return false;
|
||||
|
||||
try {
|
||||
return _fs.statSync(path).isFile();
|
||||
} catch (error) {
|
||||
var systemError = error as _SystemError;
|
||||
if (systemError.code == 'ENOENT') return false;
|
||||
rethrow;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool dirExists(String path) {
|
||||
try {
|
||||
return _fs.statSync(path).isDirectory();
|
||||
} catch (error) {
|
||||
var systemError = error as _SystemError;
|
||||
if (systemError.code == 'ENOENT') return false;
|
||||
rethrow;
|
||||
}
|
||||
return _systemErrorToFileSystemException(() {
|
||||
// `existsSync()` is faster than `statSync()`, but it doesn't clarify
|
||||
// whether the entity in question is a file or a directory. Since false
|
||||
// negatives are much more common than false positives, it works out in our
|
||||
// favor to check this first.
|
||||
if (!_fs.existsSync(path)) return false;
|
||||
|
||||
try {
|
||||
return _fs.statSync(path).isDirectory();
|
||||
} catch (error) {
|
||||
var systemError = error as _SystemError;
|
||||
if (systemError.code == 'ENOENT') return false;
|
||||
rethrow;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
void ensureDir(String path) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
name: sass
|
||||
version: 1.22.11
|
||||
version: 1.22.12-dev
|
||||
description: A Sass implementation in Dart.
|
||||
author: Sass Team
|
||||
homepage: https://github.com/sass/dart-sass
|
||||
|
Loading…
x
Reference in New Issue
Block a user