-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Make CSS assets async #1390
Make CSS assets async #1390
Conversation
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.
What about creating: Resolver.resolveSync inside the Resolver, that would remove all deasync calls instantly (except for get package in Asset.js, but that's just for backwards compatibility)?
The changes in sass resolver is a good edit though, as it's async anyway it doesn't need resolveSync.
@DeMoorJasper oh yeah, I was thinking the same. What do you think of making three classes :
I'm trying to find a good pattern where we could reuse maximum code and only have to implement What do you think of implementing a interface Thenable<T> {
then<U>(
do: (v: T) => (Thenable<U> | U),
catch: (err: Error) => (Thenable<U> | U)
): Thenable<U>
}
interface SyncThenable<T> extends Thenable<T> {
get(): T
then<U>(
do: (v: T) => (SyncThenable<U> | U),
catch: (err: Error) => (SyncThenable<U> | U)
): SyncThenable<U>
static from(value: T): SyncThenable<T>
} And in each resolver:
class SyncResolver extends Resolver {
stat(file) {
return Thenable.from(fs.statSync(file))
}
readFile(file) {
return Thenable.from(fs.readFileSync(file))
}
resolve(input, parent) {
// Returns the sync result of the Thenable
return super.resolve(input, parent).get()
}
}
class AsyncResolver extends Resolver {
stat(file) {
return fsUtils.stat(file)
}
readFile(file) {
return fsUtils.readFile(file)
}
} |
I think the resolver should contain them both as a function, so that in the bundler we don't have to create a second instance if we would ever need a synchronous version. |
hmm this was originally added for Stylus, which requires the resolution be synchronous. Even if we switched to |
Hope you don't mind me committing to this branch but I found a way to make the less filemanager async and pushed it to this branch @fathyb So apparently all that's left now is Stylus |
Codecov Report
@@ Coverage Diff @@
## master #1390 +/- ##
==========================================
+ Coverage 85.01% 88.51% +3.49%
==========================================
Files 79 80 +1
Lines 4391 4639 +248
==========================================
+ Hits 3733 4106 +373
+ Misses 658 533 -125
Continue to review full report at Codecov.
|
Awesome @DeMoorJasper, I don't mind at all, thanks! For Stylus I think I found a way to make it async using a double-traversal :
|
Just pushed an async |
I previously commit with `--no-verify`
I tried it out and it ran to completion for me. |
I can also confirm that the build finishes on previously problematic project. |
src/assets/StylusAsset.js
Outdated
cache: true, | ||
filename: asset.name | ||
}; | ||
let parser = new Parser(code, 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.
unfortunately I think this will result in the code being parsed twice for each file: once here, and once when actually processing the code later. Do you think there is a way they could share the same AST?
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 tested by putting some logs in Stylus' code and (ironically) cache: true
broke the Parser cache (the cache is disabled if it isn't 'memory'
).
I fixed it and now it'll parse in getDependencies
and use the cached AST in generate
.
Remove `deasync` from CSS assets. Fixes #1331 and bring some performance improvements. #### Status - [x] Sass - [x] Less - [x] Stylus
Remove `deasync` from CSS assets. Fixes #1331 and bring some performance improvements. #### Status - [x] Sass - [x] Less - [x] Stylus
Remove
deasync
from CSS assets.Fixes #1331 and bring some performance improvements.
Status