-
Notifications
You must be signed in to change notification settings - Fork 145
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
[App Extensibility ⚙️] Fix Babel configuration ignore node_modules
folder (@W-17373534@)
#2228
[App Extensibility ⚙️] Fix Babel configuration ignore node_modules
folder (@W-17373534@)
#2228
Conversation
function (filepath) { | ||
// Ignore node_modules, but include @salesforce/extension-* and pwa-kit-extension-sdk | ||
if (/node_modules/.test(filepath)) { | ||
// Only ignore non-extension @salesforce packages | ||
if ( | ||
/node_modules\/(?!@salesforce\/pwa-kit-extension-sdk|@salesforce\/extension-)/.test( | ||
filepath | ||
) | ||
) { | ||
return true | ||
} | ||
return false | ||
} | ||
return 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.
I asked AI to invert the logic to get rid of the nested conditions. Here is the output i got:
function (filepath) {
// Return false if it's an allowed extension package
if (/node_modules\/@salesforce\/(pwa-kit-extension-sdk|extension-)/.test(filepath)) {
return false;
}
// Return true if it's in node_modules (excluding allowed packages handled above)
if (/node_modules/.test(filepath)) {
return true;
}
// Return false for all other files
return false;
}
// By default babel doesn't process files in "node_modules" folder, so here we will ensure they are included. | ||
exclude: /node_modules\/(?!(@?[^/]+\/)?extension-)[^/]+\/.*$/i, |
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.
normally I wouldn't advocate to document the "what", only the "why"s.
But I feel like when it comes to regexes, we should add a quick explanation of what this regex aims to do. Because it's hard to tell unless you copy and paste the regex to a tool like https://regexr.com/
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.e. This regex exclude everything in node_modules, but node_modules/extensions-*/ folders
} | ||
}, | ||
ignore: [ | ||
function (filepath) { |
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.
TIL you can pass a function into babel config ignore :-o. Any doc link about this?
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.
It's basically creating an inline Babel plugin. See https://babeljs.io/docs/plugins#plugin-development
// Only ignore non-extension @salesforce packages | ||
if ( | ||
/node_modules\/(?!@salesforce\/pwa-kit-extension-sdk|@salesforce\/extension-)/.test( | ||
filepath |
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.
Unblocking comment, let's look a bit further in the future when partners start to create their own extensions. Do they have to follow the pattern of @salesforce/extension-* or just extension-* or their brand name like this @company/extension?
If it is more than @salesforce/extension-* we may want to allow other pattern here too to avoid bug later down the road.
@@ -340,6 +340,8 @@ const ruleForBabelLoader = (babelPlugins) => { | |||
id: 'babel-loader', | |||
test: /(\.js(x?)|\.ts(x?))$/, | |||
// NOTE: Because our extensions are just folders containing source code, we need to ensure that the babel-loader processes them. | |||
// By default babel doesn't process files in "node_modules" folder, so here we will ensure they are included. | |||
exclude: /node_modules\/(?!(@?[^/]+\/)?extension-)[^/]+\/.*$/i, |
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.
Dumb question, we have exclude
here and ignore
in the babel config? How are they working with each other? I recall they can't be used on a same directory like node_modules
because exclude is exclusive to the folder and will override ignore
.
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.
These are different configurations that don't work with each other. One is the Webpack configuration for babel-loader, and the other is the Babel configuration for babel-node, where we cannot use the exclude option. They are used in separate stages.
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.
Tested locally. Verified there were no Babel warnings in the terminal. LGTM
Description
Problem
We identified an issue where Babel is transpiling all files in
node_modules
due to using the wrong Babel configuration, leading to two warnings when we start the template-typescript-minimal project.Solution
The PR fixes the Babel configuration to avoid transpiling all files in
node_modules
, solving the two warnings we saw when starting the dev server.The Babel warnings no longer appear when starting the dev server.
Screenshare.-.2025-01-28.6_27_27.PM.mp4
Types of Changes
Changes
How to Test-Drive This PR
packages/extension-chakra-storefront/config/sample.json
into theextension-chakra-storefront
inside the generated projectpackage.json
file.Verify
Checklists
General
Accessibility Compliance
You must check off all items in one of the follow two lists:
or...
Localization