-
Notifications
You must be signed in to change notification settings - Fork 902
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
294 correctly use and bundle yoastseo package in premium #21006
base: trunk
Are you sure you want to change the base?
294 correctly use and bundle yoastseo package in premium #21006
Conversation
…nt Babel from transpiling ES6 modules to CommonJS. This way, webpack can analyze more accurately the dependency tree and shake off unused dependencies.
packages/yoastseo/babel.config.js
Outdated
presets: [ | ||
[ | ||
"@babel/preset-env", { | ||
modules: 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.
Setting modules
to false
is to make sure that the code is not bundled in CommonJS. For treeshaking to work, the module needs to be bundled in ES2015 syntax (from this source and this source). The default value is set to auto
.
Tree shaking doesn't work with CommonJS modules and only works with ES modules
However, Babel's docs mentions that we should only set it to false
when we intend to ship native ES Modules to browsers. So I am not entirely sure about this. cc @mhkuu @mykola
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.
Additionally, I found out that apparently yarn test
is failing with SyntaxError: Cannot use import statement outside a module
message when I set modules
to false
.
This is because the following:
- Before running test, we're running
yarn build
, where we build ECMAScript modules whenmodules
is set tofalse
inbabel.config.js
- We use the build modules for testing
- When running
yarn test
, jest is using CommonJS modules by default. Hence the failing tests
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.
Fixed by adjusting the config to still transform the modules to CommonJS when it's for testing. From this article. Props to @mhkuu for finding it! 🙌🏽
AbstractResearcher, | ||
transliterate, | ||
replaceDiacritics, | ||
createRegexFromArray, | ||
imageInText, | ||
stripSpaces, | ||
baseStemmer, | ||
getWords, | ||
flattenSortLength, | ||
indices, | ||
buildFormRule, | ||
createRulesFromArrays, | ||
createSingleRuleFromArray, | ||
matchRegularParticiples, | ||
directPrecedenceException, | ||
precedenceException, | ||
nonDirectPrecedenceException, | ||
findMatchingEndingInArray, | ||
regexHelpers, | ||
exceptionListHelpers, | ||
stemHelpers, | ||
areWordsInSentence, | ||
values, | ||
getClauses, | ||
getClausesSplitOnStopWords, | ||
stripHTMLTags, | ||
stripBlockTagsAtStartEnd, | ||
countMetaDescriptionLength, | ||
sanitizeString, | ||
removePunctuation, | ||
getLanguage, | ||
getSentences, | ||
getFieldsToMark, | ||
unifyAllSpaces, | ||
normalizeHTML, | ||
collectMarkingsInSentence, | ||
normalizeSingle, | ||
parseSynonyms, | ||
mergeListItems, | ||
findWordFormsInString, | ||
markWordsInSentences, | ||
helpers, | ||
researches, | ||
languageHelpers, |
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 expose these helpers from languageProcessing/helpers
as processingHelpers
. This way this index.js
file is cleaner
@@ -55,7 +55,7 @@ module.exports = [ | |||
{ | |||
entry: languages.reduce( ( memo, language ) => { | |||
const name = ( language === "_default" ) ? "default" : language; | |||
memo[ name ] = "./node_modules/yoastseo/src/languageProcessing/languages/" + language + "/Researcher"; | |||
memo[ name ] = "./node_modules/yoastseo/build/languageProcessing/languages/" + language + "/Researcher"; |
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.
When we create bundled entries for language specific Researcher in Free, I change it so that we use the build code from yoastseo
. Actually now I am not so sure anymore 😅 . I vaguely remember that we want to use the build code, but is it also when it's used in Free? 🤔
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.
This means that when building the plugin, we should also build the package.
…nto 294-correctly-use-and-bundle-yoastseo-package-in-premium
… accessed from the Class itself and not from the object instance of the class.
…lass, which means that it cannot be accessed from an object instance of that class.
} ], | ||
_isPassive: true, | ||
_sentenceText: "Cats are adored.", | ||
} ); |
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.
Testing parse
method of the class here is irrelevant since now this method cannot be accessed from an instance of this class. The parse
method is made static
…nto 294-correctly-use-and-bundle-yoastseo-package-in-premium
…nto 294-correctly-use-and-bundle-yoastseo-package-in-premium
A merge conflict has been detected for the proposed code changes in this PR. Please resolve the conflict by either rebasing the PR or merging in changes from the base branch. |
Context
Summary
This PR can be summarized in the following changelog entry:
ProminentWord
,AssessmentResult
,Mark
, andPaper
to useclass
notation.languageProcessing
. Now they are grouped together asprocessingHelpers
.yoastseo
package in the plugin.Relevant technical choices:
Test instructions
Test instructions for the acceptance test before the PR gets merged
This PR can be acceptance tested by following these steps:
Relevant test scenarios
Test instructions for QA when the code is in the RC
QA can test this PR by following these steps:
Impact check
This PR affects the following parts of the plugin, which may require extra testing:
UI changes
Other environments
[shopify-seo]
, added test instructions for Shopify and attached theShopify
label to this PR.Documentation
Quality assurance
Innovation
innovation
label.Fixes #