-
Notifications
You must be signed in to change notification settings - Fork 33
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
@W-17471447 Add a ssr processor and update ssr rule #185
@W-17471447 Add a ssr processor and update ssr rule #185
Conversation
That's gonna mess with things like eslint-plugin-header and anything else that relies on a top-of-file directive. |
…t js file with .ssrjs extension
26bd4db
to
b1ab9be
Compare
Yeah I noticed that, thats why this I pushed it to draft, I have updated the processor to add a new file with extension .ssrjs for every js file of ssr component which can be used in seperate config to target ssr js files with |
Co-authored-by: Ravi Jayaramappa <[email protected]>
Co-authored-by: Ravi Jayaramappa <[email protected]>
Co-authored-by: Ravi Jayaramappa <[email protected]>
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.
Creating a virtual file that's a clone of an existing file feels weird. It'll tell users that there's an error in a file that doesn't even exist. And you'll end up processing each file twice, just to conditionally apply a subset of rules that you might not even be using.
It feels more intuitive to me to have this configured at the rule level. Users can just treat it like a regular eslint rule, and not have to learn any new quirks. The potential downside is doing the XML check for each file for every rule, but hopefully caching the result will make that a non-issue. Parsing ASTs and file reads are both expensive operations, so I don't actually know which would be more performant. Would be worthwhile to compare implementations.
To make this configurable at the rules level, add this function to the utils:
function shouldLintSsrRules(context) {
const userConfig = context.settings && context.settings.lwc && context.settings.lwc.autoDetectSsrCapabilities;
if (typeof userConfig === 'boolean') {
return userConfig
}
return hasSSRCapabilities(path.dirname(context.filename))
}
(Note that this suggestion uses shared settings, rather than per-rule options, but it doesn't matter which you use. You could even use both!)
And then just add this short snippet to every SSR rule:
if (!shouldLintSsrRules(context)) {
return {};
}
bundle && bundle.capabilities | ||
? bundle.capabilities.some((capabilityObj) => | ||
Array.isArray(capabilityObj.capability) | ||
? capabilityObj.capability.some((cap) => SSR_CAPABILITIES.includes(cap)) | ||
: SSR_CAPABILITIES.includes(capabilityObj.capability), | ||
) | ||
: false; |
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.
bundle && bundle.capabilities | |
? bundle.capabilities.some((capabilityObj) => | |
Array.isArray(capabilityObj.capability) | |
? capabilityObj.capability.some((cap) => SSR_CAPABILITIES.includes(cap)) | |
: SSR_CAPABILITIES.includes(capabilityObj.capability), | |
) | |
: false; | |
bundle?.capabilities?.some((capabilityObj) => | |
Array.isArray(capabilityObj.capability) | |
? capabilityObj.capability.some((cap) => SSR_CAPABILITIES.includes(cap)) | |
: SSR_CAPABILITIES.includes(capabilityObj.capability), | |
) ?? false; |
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.
Actually, looks like the eslint enforced on this package is on an old version of ECMAScript, so this won't pass. We should update that at some point... 😅
Not really from the perspective of user, the eslint output still showcases ssr violations reported under original ssr file (not the virtual one)
Aren't we going to deal with something similar even with rule level approach, you will be processing each file for every rule. Also considering this is a public plugin, processor approach makes it easier for 3rd party users to apply any new ssr specific file without dealing with ssr capability checks at rule level
I think its a tradeoff between adding the header check to every ssr rule vs adding a separate config for Also most probably this is a interim solution. @ravijayaramappa can comment more on this but I believe there are plans to seperate ssr components under a different path (maybe having |
@wjhsf I agree with Ayush's comment's above. The two drawbacks of including the detection logic in the rule implementation itself is:
|
@wjhsf @ravijayaramappa lets keep this pr on hold for now. I am trying to test current changes with 2.1.0-beta.1 version in core but have been running into issues while applying processor(its having trouble dealing with virtual files as ts parser needs the file to be listed in tsconfig) in core 1st party configs. I will spend some more time testing it .Will share an update here. |
I meant the step parsing the ASTs, rather than reading the files. By using the processor to create
Does the in-memory content have to conditionally detect SSR capabilities? How is that detection done? If it doesn't look weird in the console for the end user, and if we're constrained by not always having the file system available, then I'm fine with this approach. |
The Invokers of the compiler, e.g Aura compiler reads the content of the meta.xml file and passes down the signal via a compiler flag. |
ssr
processor here processes the component js files and checks whether the component is SSR capable or not.To check for if a cmp is ssrable or not, the processor looks for particular capabilites define in thejs-meta.xml
file of component