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
Standardise lazy requires #4729
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.
Great job!
types/import-lazy/index.d.ts
Outdated
@@ -0,0 +1,5 @@ | |||
declare module 'import-lazy' { |
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.
Can this be moved to types/global.d.ts
?
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.
Nice, looks good!
|
#2454
In this pull request, I've standardised how we lazy/dynamic-require:
Previously we were using lots of different workarounds to get the require-time down. I'm now only using import-lazy.
This lays the foundation for being able to bundle code, closing #2454 and #3935.
This pull request doesn't improve the require-time much, because we'd already optimised all that we could without bundling (using the various workarounds). Require-time does seem more consistent, though, normally coming in at the
120
mark.This pull request does, however, improve the time taken to run stylelint when the auto syntax is used because all the syntaxes are now lazy-required.
Testing locally with
On
master
:This branch:
Using the auto syntax is almost comparable to using the
syntax
option in this branch, whereas it's significantly slower inmaster
.This improvement is reflected in the test suite which now runs in 72s (down from 92s).
The import-lazy library has two patterns:
I'm using the former for formatters and rules, and the latter for syntaxes. This will allow us to bundle syntaxes separately in the future.
As a consequence, it exposed a shortcoming in how we were excluding files from TypeScript. Previously all the rule files were ignored because they were excluded and dynamically required using
require("rules" + rulename)
, which TypeScript couldn't resolve. As we are now using a lazy-require pattern it can resolve, we have to explicitly mark each rule file with a// @ts-nocheck
. This is arguably cleaner as we were previously relying on a quirk of the TypeScript's module resolution. Theinclude
andexclude
TypeScript config options are cleaner too now.