Skip to content
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

Draft
wants to merge 30 commits into
base: trunk
Choose a base branch
from

Conversation

FAMarfuaty
Copy link
Contributor

@FAMarfuaty FAMarfuaty commented Dec 22, 2023

Context

Summary

This PR can be summarized in the following changelog entry:

  • [yoastseo] Refactors classes ProminentWord, AssessmentResult, Mark, and Paper to use class notation.
  • [yoastseo] Cleans up the helper modules that are exposed in languageProcessing. Now they are grouped together as processingHelpers.
  • Uses the build code from 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

  • Changes should be tested with the browser console open
  • Changes should be tested on different posts/pages/taxonomies/custom post types/custom taxonomies
  • Changes should be tested on different editors (Block/Classic/Elementor/other)
  • Changes should be tested on different browsers
  • Changes should be tested on multisite

Test instructions for QA when the code is in the RC

  • QA should use the same steps as above.

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

  • This PR changes the UI in the plugin. I have added the 'UI change' label to this PR.

Other environments

  • This PR also affects Shopify. I have added a changelog entry starting with [shopify-seo], added test instructions for Shopify and attached the Shopify label to this PR.

Documentation

  • I have written documentation for this change.

Quality assurance

  • I have tested this code to the best of my abilities.
  • During testing, I had activated all plugins that Yoast SEO provides integrations for.
  • I have added unit tests to verify the code works as intended.
  • If any part of the code is behind a feature flag, my test instructions also cover cases where the feature flag is switched off.
  • I have written this PR in accordance with my team's definition of done.
  • I have checked that the base branch is correctly set.

Innovation

  • No innovation project is applicable for this PR.
  • This PR falls under an innovation project. I have attached the innovation label.
  • I have added my hours to the WBSO document.

Fixes #

presets: [
[
"@babel/preset-env", {
modules: false,
Copy link
Contributor Author

@FAMarfuaty FAMarfuaty Jan 3, 2024

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

Copy link
Contributor Author

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 when modules is set to false in babel.config.js
  • We use the build modules for testing
  • When running yarn test, jest is using CommonJS modules by default. Hence the failing tests

Copy link
Contributor Author

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! 🙌🏽

Comment on lines 28 to 107
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,
Copy link
Contributor Author

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";
Copy link
Contributor Author

@FAMarfuaty FAMarfuaty Jan 3, 2024

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? 🤔

Copy link
Contributor Author

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.

} ],
_isPassive: true,
_sentenceText: "Cats are adored.",
} );
Copy link
Contributor Author

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

Base automatically changed from releasing-yoastseo to trunk April 2, 2024 13:23
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant