<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alexandru Bereghici on Medium]]></title>
        <description><![CDATA[Stories by Alexandru Bereghici on Medium]]></description>
        <link>https://medium.com/@alexandrubereghici?source=rss-8c39bf1ed014------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*TvNLKpQgs3SQnTsdrHk1VQ.png</url>
            <title>Stories by Alexandru Bereghici on Medium</title>
            <link>https://medium.com/@alexandrubereghici?source=rss-8c39bf1ed014------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 09:12:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@alexandrubereghici/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Keeping your development resources organized with Notion]]></title>
            <link>https://medium.com/@alexandrubereghici/keeping-your-development-resources-organized-with-notion-65483cc19fc1?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/65483cc19fc1</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[notion]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[resources]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Mon, 03 Oct 2022 15:40:02 GMT</pubDate>
            <atom:updated>2022-10-04T06:45:49.602Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*ioiH8_34KjStY0quhQttEg.jpeg" /></figure><p>As a developer, I have a lot of learning resources and I quickly realized that keeping stuff in my browser’s bookmark doesn’t work for me. I needed a tool to keep everything in one place. I started to use <a href="https://www.notion.so/">Notion</a> and it didn’t disappoint me. In this article, I want to share how I structured all my resources using this tool.</p><h3>Structure</h3><p>This is what my notion “homepage” looks like. I divided the articles and tutorials into different sections.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*eHGmA6gEH_Tn6mJr" /></figure><p>Each section is divided into subsections. This allows me to keep the resources related to one topic and it helps me find things faster.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*xD58BnTPRmeSulUU" /></figure><h3>Bookmarks</h3><p>Each subsection has a database where I store the bookmarks related to this specific topic. I’m using <a href="https://chrome.google.com/webstore/detail/save-to-notion/ldmmifpegigmeammaeckplhnjbbpccmm?hl=en">Save to Notion</a> chrome extension to bookmark my links. The benefits of keeping the bookmarks in Notion are that you can add tags or notes, and you can filter or sort them by different criteria.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*3erZ4sUgoGtWTCCl" /></figure><h3>Task List</h3><p>The importance of practice in programming cannot be ignored. “Practice makes a man perfect”, they said. Often, just reading a tutorial or a book is not enough, you have to get your hands dirty with that specific technology/ pattern/language / whatever you learned. In the task list, I define small side-projects or things I need to practice. This is a great way to assess the progress.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*pukweFeheu_5NHl3" /></figure><h3>Reading list</h3><p>The Reading list is my collection of books. I found that taking notes while reading a book helps me process the information better. Also, I like being able to go back and search my notes and quickly find the most essential information from books I’ve read.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*c-aLgtiWPAuYYoT4" /></figure><h3>Saved Tweets</h3><p>A majority of the most valuable information I consume online comes from tweets and threads. The goal is to keep everything in one place and hopefully, there is a bot named <a href="https://twitter.com/SaveToNotion">Save To Notion</a> that can save the tweets or threads directly in your notion by tagging the bot on a specific tweet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*1RGp1hjEwebKVmJh" /></figure><h3>RSS Feed</h3><p>I bookmarked many useful blogs, but it was annoying to open each link manually to see if there is new content. A common way to follow the new content is using RSS feeds. Unfortunately, Notion doesn’t provide this functionality. I solved this problem by creating a small application with Rust that allows you to manage the RSS sources in a separate notion page and daily reads the new content from your sources and saves them in a notion feed. The project and the setup instructions can be found here:<br><a href="https://github.com/abereghici/notion-feed.rs">https://github.com/abereghici/notion-feed.rs</a></p><p>This is how looks the RSS sources:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*IT14sOdCGCYFGVXW" /></figure><p>This is the RSS feed:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*u4Luc0AkIFuMdTxC" /></figure><h3>Conclusion</h3><p>Notion is a great and flexible tool that can increase your productivity. It comes with a lot of templates that can cover all your needs. If you find other useful use cases, share them with us in the comments.</p><p><em>Originally published at </em><a href="https://bereghici.dev/blog/keeping-your-development-resources-organized-with-notion"><em>https://bereghici.dev</em></a><em> on October 3, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=65483cc19fc1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Patch an NPM dependency with yarn]]></title>
            <link>https://itnext.io/patch-an-npm-dependency-with-yarn-ddde2e194576?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/ddde2e194576</guid>
            <category><![CDATA[dependencies]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[yarn]]></category>
            <category><![CDATA[patch]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Mon, 30 May 2022 12:06:20 GMT</pubDate>
            <atom:updated>2022-05-30T13:01:30.709Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*H113wSmxl4TEdbl0.jpg" /></figure><p>When you have a bug in a third-party dependency, usually you have a limited set of options to fix it.</p><p>You can modify directly the local code of the dependency and make a new build. This works if it’s a critical bug and you have to fix it as soon as possible. But, this is not the best option, because you’ll lose the fix on the next yarn or npm install. Also, you won&#39;t be able to share the fix with your team.</p><p>Another option is to fork the package, fix the bug, and create a pull request. At this point, you can update your project dependencies and use your fork until the maintainers of the package approve it and publish a new version.</p><pre>&quot;dependencies&quot;: {<br>  &quot;buggy-package&quot;: &quot;your_user/buggy-package#bugfix&quot;<br>}</pre><p>This looks like a good option, now your team members will get the fix when they will update the project dependencies. The downside is that you’ll have to maintain the fork and make sure it’s up to date.</p><p>Do we have a better option? Yes, we have. We can use the yarn patch command that was introduced in yarn v2.0.0. This allows you to instantly make and keep fixes to your dependencies without having to fork the packages.</p><p>Let’s take as an example the remix-run framework. During the development, I found an issue with the session storage. I opened a <a href="https://github.com/remix-run/remix/pull/3113">pull request</a> to fix it, then I patched the package directly in the project using the command:</p><pre>yarn patch @remix-run/node@npm:1.5.1 </pre><pre>➤ YN0000: Package @remix-run/node@npm:1.5.1 got extracted with success! <br>➤ YN0000: You can now edit the following folder: /private/var/folders/xm/qntd4h_97zn6w88tc95bsvxc0000gp/T/xfs-bfc9a229/user <br>➤ YN0000: Once you are done run yarn patch-commit -s /private/var/folders/xm/qntd4h_97zn6w88tc95bsvxc0000gp/T/xfs-bfc9a229/user and Yarn will store a patchfile based on your changes. ➤ YN0000: Done in 0s 68ms</pre><p>Once the package is extracted, we can open the created folder and make our changes there. One drawback is that you have to modify the production code, which might be minified and hard to debug. In my case was a simple change to the fileStorage module.</p><p>The next step is to commit the patch using the command displayed earlier in the console</p><pre>yarn patch-commit -s /private/var/folders/xm/qntd4h_97zn6w88tc95bsvxc0000gp/T/xfs-bfc9a229/user</pre><p>At this point, we should see the following change in package.json</p><pre>&quot;resolutions&quot; : { <br>   &quot;@remix-run/node@1.5.1&quot; : &quot;patch:@remix-      run/node@npm:1.5.1#.yarn/patches/@remix-run-node-npm-1.5.1-51061cf212.patch&quot; <br>}</pre><p>and in .yarn/patches you&#39;ll find the patch file.</p><p>The benefits of using this approach are that the patch can be reviewed by your team and it doesn’t require additional work to be applied compared to the fork. This should be used for critical fixes, if you need a new feature I would suggest forking it instead. Also, do not forget to open an issue and create a pull request in the actual package.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ddde2e194576" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/patch-an-npm-dependency-with-yarn-ddde2e194576">Patch an NPM dependency with yarn</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to test your GitHub Pull Requests with CodeSandbox CI]]></title>
            <link>https://itnext.io/how-to-test-your-github-pull-requests-with-codesandbox-ci-a7945f166fa?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/a7945f166fa</guid>
            <category><![CDATA[codesandbox]]></category>
            <category><![CDATA[github]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[open-source]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Thu, 11 Nov 2021 07:47:53 GMT</pubDate>
            <atom:updated>2022-01-11T09:04:21.929Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*iTiol81v7U8qzoq5.jpg" /></figure><p>If you’re an open-source project maintainer or you plan to build one, you should consider using CodeSandbox CI in your project configuration. CodeSandbox CI it’s an awesome GitHub application that auto-builds your open source project from pull requests. This can save a lot of time and effort to test and approve the changes.</p><h3>How does it work?</h3><p>Whenever someone opens a new pull request, CodeSandbox CI builds a new version of your project. Those builds get posted to the CodeSandbox registry, so you can test it in there or locally, and all without having to publish the build to npm⁠.</p><h3>How do I set this up?</h3><p>Let’s create a demo project to see CodeSandbox CI in action. For that, create a new project on GitHub and name it, for example, codesandbox-ci-test. Clone it locally and add a package.json file with the following content:</p><pre>{<br>  &quot;name&quot;: &quot;codesandbox-ci-test&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;main&quot;: &quot;dist/index.js&quot;,<br>  &quot;engines&quot;: {<br>    &quot;node&quot;: &quot;&gt;=12&quot;<br>  },<br>  &quot;scripts&quot;: {<br>    &quot;build&quot;: &quot;kcd-scripts build&quot;<br>  },<br>  &quot;peerDependencies&quot;: {<br>    &quot;react&quot;: &quot;^17.0.2&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;kcd-scripts&quot;: &quot;^11.2.2&quot;,<br>    &quot;react&quot;: &quot;^17.0.2&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;@babel/runtime&quot;: &quot;^7.16.0&quot;<br>  }<br>}</pre><p>This is a standard package.json file for a JavaScript project. We’ll be using kcd-scripts to build our project, and we&#39;ll be using react to create a small reusable component for this demo. @babel/runtime is required by kcd-scripts otherwise, it won&#39;t build the project.</p><p>In src/index.js create a simple Counter component:</p><pre>import * as React from &#39;react&#39;;<br><br>export default function Counter() {<br>  const [count, setCount] = React.useState(0);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;You clicked {count} times!!!&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Click me&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>Install the CodeSandbox Github application from <a href="https://github.com/apps/codesandbox">https://github.com/apps/codesandbox</a> in our new repository.</p><p>Create a file called ci.json in a folder called .codesandbox in the root of the repository and add:</p><pre>{<br>  &quot;buildCommand&quot;: &quot;build&quot;,<br>  &quot;node&quot;: &quot;12&quot;,<br>  &quot;sandboxes&quot;: [&quot;/cra-template&quot;]<br>}</pre><ul><li>buildCommand indicates which script in package.json should run to build the project.</li><li>node is the Node.js version to use for building the PR.</li><li>sandboxes is the list of sandboxes that we want to be generated. The default value is vanilla.</li></ul><p>We don’t want to use a default sandbox, because we’ll have to modify manually the sandbox code to import and display the Counter component. Instead, we’ll create a custom template, named cra-template.</p><p>Create a new folder named cra-template, inside of this folder create a package.json:</p><pre>{<br>  &quot;name&quot;: &quot;react-starter-example&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;React example starter project&quot;,<br>  &quot;main&quot;: &quot;src/index.js&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;react&quot;: &quot;17.0.2&quot;,<br>    &quot;react-dom&quot;: &quot;17.0.2&quot;,<br>    &quot;react-scripts&quot;: &quot;4.0.0&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;@babel/runtime&quot;: &quot;7.13.8&quot;,<br>    &quot;typescript&quot;: &quot;4.1.3&quot;<br>  },<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;react-scripts start&quot;,<br>    &quot;build&quot;: &quot;react-scripts build&quot;,<br>    &quot;test&quot;: &quot;react-scripts test --env=jsdom&quot;,<br>    &quot;eject&quot;: &quot;react-scripts eject&quot;<br>  },<br>  &quot;browserslist&quot;: [&quot;&gt;0.2%&quot;, &quot;not dead&quot;, &quot;not ie &lt;= 11&quot;, &quot;not op_mini all&quot;]<br>}</pre><p>Create a src folder and a index.js file with:</p><pre>import { StrictMode } from &#39;react&#39;;<br>import ReactDOM from &#39;react-dom&#39;;<br>import Counter from &#39;codesandbox-ci-test&#39;;<br><br>const rootElement = document.getElementById(&#39;root&#39;);<br>ReactDOM.render(<br>  &lt;StrictMode&gt;<br>    &lt;Counter /&gt;<br>  &lt;/StrictMode&gt;,<br>  rootElement<br>);</pre><p>Create a public folder with a index.html file with:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>  &lt;head&gt;<br>    &lt;meta charset=&quot;utf-8&quot; /&gt;<br>    &lt;meta<br>      name=&quot;viewport&quot;<br>      content=&quot;width=device-width, initial-scale=1, shrink-to-fit=no&quot;<br>    /&gt;<br>    &lt;meta name=&quot;theme-color&quot; content=&quot;#000000&quot; /&gt;<br>    &lt;link rel=&quot;manifest&quot; href=&quot;%PUBLIC_URL%/manifest.json&quot; /&gt;<br>    &lt;link rel=&quot;shortcut icon&quot; href=&quot;%PUBLIC_URL%/favicon.ico&quot; /&gt;<br>    &lt;title&gt;React App&lt;/title&gt;<br>  &lt;/head&gt;<br>  &lt;body&gt;<br>    &lt;noscript&gt; You need to enable JavaScript to run this app. &lt;/noscript&gt;<br>    &lt;div id=&quot;root&quot;&gt;&lt;/div&gt;<br>  &lt;/body&gt;<br>&lt;/html&gt;</pre><p>At this point, we can create a new pull request and see our configuration in action. The CodeSandbox CI app will build the project and will leave a comment on the pull request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sc70amV4kgG4uZNB4wRwmg.jpeg" /></figure><p>You can check out the following links to see the result:</p><ul><li>CodeSandbox CI dashboard for PRs: <a href="https://ci.codesandbox.io/status/abereghici/codesandbox-ci-test/pr/1/builds/186555">https://ci.codesandbox.io/status/abereghici/codesandbox-ci-test/pr/1/builds/186555</a></li><li>CodeSandbox app: <a href="https://codesandbox.io/s/react-zmd24">https://codesandbox.io/s/react-zmd24</a></li></ul><h3>Useful Links &amp; Documentation</h3><p>If you encountered any issues along the way, please check the Github repository <a href="https://github.com/abereghici/codesandbox-ci-test">https://github.com/abereghici/codesandbox-ci-test</a> with the code from this article.</p><p>If you’re interested in using CodeSandbox CI in a mono-repo project, you can check out the Design System project from Twilio <a href="https://github.com/twilio-labs/paste">https://github.com/twilio-labs/paste</a> to see their configuration.</p><p>For more information about CodeSandbox CI, check out the <a href="https://codesandbox.io/docs/ci">documentation</a>.</p><p><em>Originally published at </em><a href="https://bereghici.dev/blog/how-to-test-your-github-pull-requests-with-codesandbox-ci"><em>https://</em>bereghici.dev</a><em> on November 10, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a7945f166fa" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/how-to-test-your-github-pull-requests-with-codesandbox-ci-a7945f166fa">How to test your GitHub Pull Requests with CodeSandbox CI</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a scalable front-end with Rush monorepo and React — Part 5]]></title>
            <link>https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-5-355f5391fd27?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/355f5391fd27</guid>
            <category><![CDATA[vscode]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[rushjs]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[rushstack]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Fri, 03 Sep 2021 08:49:17 GMT</pubDate>
            <atom:updated>2022-01-11T09:03:36.046Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a scalable front-end with Rush monorepo and React — Part 5</h3><h3>VSCode</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/0*NOvt6xqlqb4bydPc.jpg" /></figure><p>This is the 5th part of the blog series “Build a scalable front-end with Rush monorepo and React”</p><ul><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-1-dd50ae38ad3e">Part 1</a>: Monorepo setup, import projects with preserving git history, <br>add Prettier</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-2-d7f1c19c1797">Part 2</a>: Create build tools package with Webpack and react-scripts</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-3-b90430f15af7">Part 3</a>: Add shared ESLint configuration and use it with lint-staged</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-4-d0939bfb8b8a">Part 4</a>: Setup a deployment workflow with Github Actions and Netlify.</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-5-355f5391fd27">Part 5</a>: Add VSCode configurations for a better development experience.</li></ul><h4>TL;DR</h4><p>If you’re interested in just see the code, you can find it here: <a href="https://github.com/abereghici/rush-monorepo-boilerplate">https://github.com/abereghici/rush-monorepo-boilerplate</a></p><p>If you want to see an example with Rush used in a real, large project, you can look at <a href="https://github.com/imodeljs/imodeljs">ITwin.js</a>, an open-source project developed by Bentley Systems.</p><p>In previous posts, we added prettier and eslint to format our code and enforce a consistent code style across our projects. We can save time by automatically formatting pasted code, or fix lint errors while writing code, without running the lint command to see all the errors.</p><p>VSCode provides two different types of settings:</p><ul><li>User Settings — applied to all VSCode instances</li><li>Workspace Settings — applied to the current project only.</li></ul><p>We’ll use Workspace Settings and few extensions to improve our development experience in VSCode.</p><h4>Install extensions</h4><p>Let’s add Prettier Formatter for VSCode. Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.</p><pre>ext install esbenp.prettier-vscode</pre><p>or you can open <a href="https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode">https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode</a> and install it manually.</p><p>In the same manner, let’s install the VSCode ESLint extension:</p><pre>ext install dbaeumer.vscode-eslint</pre><p>or install manually from <a href="https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint">https://marketplace.visualstudio.com/items?itemName=dbaeumer.vscode-eslint</a></p><h4>Add settings</h4><p>Create a new file .vscode/settings.json in the root of our monorepo and let&#39;s add the following settings:</p><pre>{<br>  &quot;editor.defaultFormatter&quot;: &quot;esbenp.prettier-vscode&quot;,<br>  &quot;editor.tabSize&quot;: 2,<br>  &quot;editor.insertSpaces&quot;: true,<br>  &quot;editor.formatOnSave&quot;: true,<br>  &quot;search.exclude&quot;: {<br>    &quot;**/node_modules&quot;: true,<br>    &quot;**/.nyc_output&quot;: true,<br>    &quot;**/.rush&quot;: true<br>  },<br>  &quot;files.exclude&quot;: {<br>    &quot;**/.nyc_output&quot;: true,<br>    &quot;**/.rush&quot;: true,<br>    &quot;**/*.build.log&quot;: true,<br>    &quot;**/*.build.error.log&quot;: true,<br>    &quot;**/generated-docs&quot;: true,<br>    &quot;**/package-deps.json&quot;: true,<br>    &quot;**/test-apps/**/build&quot;: true<br>  },<br>  &quot;files.trimTrailingWhitespace&quot;: true,<br>  &quot;eslint.validate&quot;: [<br>    &quot;javascript&quot;,<br>    &quot;javascriptreact&quot;,<br>    &quot;typescript&quot;,<br>    &quot;typescriptreact&quot;<br>  ],<br><br>  &quot;eslint.workingDirectories&quot;: [<br>    {<br>      &quot;mode&quot;: &quot;auto&quot;<br>    }<br>  ],<br>  &quot;eslint.nodePath&quot;: &quot;common/temp/node_modules&quot;,<br>  &quot;eslint.trace.server&quot;: &quot;verbose&quot;,<br>  &quot;eslint.options&quot;: {<br>    &quot;resolvePluginsRelativeTo&quot;: &quot;node_modules/@monorepo/eslint-config&quot;<br>  },<br>  &quot;eslint.format.enable&quot;: true,<br>  &quot;eslint.lintTask.enable&quot;: true,<br>  &quot;editor.codeActionsOnSave&quot;: {<br>    &quot;editor.action.fixAll&quot;: true,<br>    &quot;source.fixAll.eslint&quot;: true<br>  }<br>}</pre><p>In these settings we:</p><ul><li>set Prettier as default formater</li><li>exclude from search some irrelevant folders like node_modules and .nyc_output</li><li>exclude from VSCode file explorer irrelevant files</li><li>provide a nodePath for ESLint. We’re not using eslint directly (we&#39;re usinglint script from react-scripts) so we&#39;re helping the extension to find theeslint binary.</li><li>provide a path to eslint plugins. We&#39;re helping ESLint extension to pick up the right rules for each project.</li></ul><p>I hope you’ll find these settings useful.</p><p><em>Originally published at </em><a href="https://bereghici.dev/blog/build-a-scalable-front-end-with-rush-monorepo-and-react--vscode"><em>https://bereghici.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=355f5391fd27" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-5-355f5391fd27">Build a scalable front-end with Rush monorepo and React — Part 5</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a scalable front-end with Rush monorepo and React — Part 4]]></title>
            <link>https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-4-d0939bfb8b8a?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/d0939bfb8b8a</guid>
            <category><![CDATA[rushjs]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[netlify]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Fri, 03 Sep 2021 08:48:51 GMT</pubDate>
            <atom:updated>2022-01-11T09:02:56.841Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a scalable front-end with Rush monorepo and React — Part 4</h3><h3>Github Actions + Netlify</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/0*ABrgeZ2q2biwEQA4.jpg" /></figure><p>This is the 4th part of the blog series “Build a scalable front-end with Rush monorepo and React”</p><ul><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-1-dd50ae38ad3e">Part 1</a>: Monorepo setup, import projects with preserving git history, <br>add Prettier</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-2-d7f1c19c1797">Part 2</a>: Create build tools package with Webpack and react-scripts</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-3-b90430f15af7">Part 3</a>: Add shared ESLint configuration and use it with lint-staged</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-4-d0939bfb8b8a">Part 4</a>: Setup a deployment workflow with Github Actions and Netlify.</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-5-355f5391fd27">Part 5</a>: Add VSCode configurations for a better development experience.</li></ul><h4>TL;DR</h4><p>If you’re interested in just see the code, you can find it here: <a href="https://github.com/abereghici/rush-monorepo-boilerplate">https://github.com/abereghici/rush-monorepo-boilerplate</a></p><p>If you want to see an example with Rush used in a real, large project, you can look at <a href="https://github.com/imodeljs/imodeljs">ITwin.js</a>, an open-source project developed by Bentley Systems.</p><p><a href="https://www.netlify.com/">Netlify</a> allows you to configure the deployment of your project directly on their dashboard using a build command. This works well when you have a project in a single repository and you don’t need to deploy it very often. They give you a free plan which includes only 300 free build minutes. On the other hand, Github Actions is more flexible and they give you 2000 free build minutes. Also, you can run various tasks like “testing”, “linting”, “deployment”, etc.</p><h4>Create a Netlify site</h4><ul><li>Create an account if you don’t have one yet on Netlify and create a new site.</li><li>Go to the project settings and copy the API ID.</li><li>Open the Github repository and go to the settings of the repository.</li><li>Click on “Secrets” and add a new secret with the name NETLIFY_SITE_ID and paste the copied API ID from Netlify.</li><li>Go back to the Netlify dashboard and open user settings. <a href="https://app.netlify.com/user/applications#personal-access-tokens">https://app.netlify.com/user/applications#personal-access-tokens</a></li><li>Click on “Applications” and create a new access token.</li><li>Open Github “Secrets” and create a new secret with the name NETLIFY_AUTH_TOKEN and paste the new access token created on Netlify.</li></ul><h4>Create Github Actions workflow</h4><p>At this point, we have all credentials we need for deployment. Now, we can start writing our configurations.</p><p>We need to add two more commands in common/rush/command-line.json: lint and test. We&#39;ll trigger them on CI/CD before building the project.</p><p>In common/rush/command-line.json add the following:</p><pre>{<br>      &quot;name&quot;: &quot;test&quot;,<br>      &quot;commandKind&quot;: &quot;bulk&quot;,<br>      &quot;summary&quot;: &quot;Run tests on each package&quot;,<br>      &quot;description&quot;: &quot;Iterates through each package in the monorepo and runs the &#39;test&#39; script&quot;,<br>      &quot;enableParallelism&quot;: true,<br>      &quot;ignoreMissingScript&quot;: true,<br>      &quot;ignoreDependencyOrder&quot;: true,<br>      &quot;allowWarningsInSuccessfulBuild&quot;: true<br>    },<br>    {<br>      &quot;name&quot;: &quot;lint&quot;,<br>      &quot;commandKind&quot;: &quot;bulk&quot;,<br>      &quot;summary&quot;: &quot;Run linter on each package&quot;,<br>      &quot;description&quot;: &quot;Iterates through each package in the monorepo and runs the &#39;lint&#39; script&quot;,<br>      &quot;enableParallelism&quot;: true,<br>      &quot;ignoreMissingScript&quot;: true,<br>      &quot;ignoreDependencyOrder&quot;: true,<br>      &quot;allowWarningsInSuccessfulBuild&quot;: false<br>    }</pre><p>In the root of monorepo, create a .github/workflows folder and create a new file named main.yml.</p><pre>mkdir -p .github/workflows </pre><pre>touch .github/workflows/main.yml</pre><p>Now, let’s write the configurations for Github Actions.</p><pre><em># Name of workflow</em><br>name: Main workflow<br><br><em># When workflow is triggered</em><br>on:<br>  push:<br>    branches:<br>      - master<br>  pull_request:<br>    branches:<br>      - master<br><em># Jobs to carry out</em><br>jobs:<br>  lint:<br>    runs-on: ubuntu-latest<br>    strategy:<br>      matrix:<br>        node-version: [14.x]<br>    steps:<br>      <em># Get code from repo</em><br>      - name: Checkout code<br>        uses: actions/checkout@v1<br>      <em># Install NodeJS</em><br>      - name: Use Node.js ${{ matrix.node-version }}<br>        uses: actions/setup-node@v1<br>        with:<br>          node-version: ${{ matrix.node-version }}<br>      <em># Run rush install and build on our code</em><br>      - name: Install dependencies<br>        run: |<br>          node common/scripts/install-run-rush.js change -v<br>          node common/scripts/install-run-rush.js install<br>          node common/scripts/install-run-rush.js build<br>      <em># Run eslint to check all packages</em><br>      - name: Lint packages<br>        run: node common/scripts/install-run-rush.js lint<br>  test:<br>    runs-on: ubuntu-latest<br>    strategy:<br>      matrix:<br>        node-version: [14.x]<br>    env:<br>      CI: <strong>true</strong><br>    steps:<br>      <em># Get code from repo</em><br>      - name: Checkout code<br>        uses: actions/checkout@v1<br>      <em># Install NodeJS</em><br>      - name: Use Node.js ${{ matrix.node-version }}<br>        uses: actions/setup-node@v1<br>        with:<br>          node-version: ${{ matrix.node-version }}<br>      <em># Run rush install</em><br>      - name: Install dependencies<br>        run: |<br>          node common/scripts/install-run-rush.js change -v<br>          node common/scripts/install-run-rush.js install<br>          node common/scripts/install-run-rush.js build<br>      <em># Run unit tests for all packages</em><br>      - name: Run tests<br>        run: node common/scripts/install-run-rush.js test<br>  deploy:<br>    <em># Operating system to run job on</em><br>    runs-on: ubuntu-latest<br>    strategy:<br>      matrix:<br>        node-version: [14.x]<br>        app-name: [react-app]<br>        include:<br>          - app-name: react-app<br>            app: &#39;@monorepo/react-app&#39;<br>            app-dir: &#39;apps/react-app&#39;<br>            app-build: &#39;apps/react-app/build&#39;<br>            site-id: NETLIFY_SITE_ID<br>    needs: [lint, test]<br>    <em># Steps in job</em><br>    steps:<br>      <em># Get code from repo</em><br>      - name: Checkout code<br>        uses: actions/checkout@v1<br>      <em># Install NodeJS</em><br>      - name: Use Node.js ${{ matrix.node-version }}<br>        uses: actions/setup-node@v1<br>        with:<br>          node-version: ${{ matrix.node-version }}<br>      <em># Run rush install and build on our code</em><br>      - name: Install dependencies<br>        run: |<br>          node common/scripts/install-run-rush.js change -v<br>          node common/scripts/install-run-rush.js install<br>      - name: Build ${{ matrix.app-name }}<br>        working-directory: ${{ matrix.app-dir }}<br>        run: |<br>          node $GITHUB_WORKSPACE/common/scripts/install-run-rush.js build --verbose --to ${{ matrix.app }}<br>      - name: Deploy ${{ matrix.app-name }}<br>        uses: nwtgck/actions-netlify@v1.2<br>        with:<br>          publish-dir: ${{ matrix.app-build }}<br>          production-deploy: ${{ github.event_name != &#39;pull_request&#39; }}<br>          github-token: ${{ secrets.GITHUB_TOKEN }}<br>          enable-pull-request-comment: <strong>true</strong><br>          enable-commit-comment: <strong>true</strong><br>          overwrites-pull-request-comment: <strong>true</strong><br>        env:<br>          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}<br>          NETLIFY_SITE_ID: ${{ secrets[matrix.site-id] }}</pre><p>Let’s break down the configuration above.</p><p>We have 3 jobs: lint, test and deploy. lint and test jobs will run in parallel and deploy job will run after both lint and test jobs are successfully done. We&#39;re using a matrix to run jobs on different NodeJS versions (Currently we&#39;re using only 14.x but can be extended to other versions). Matrix is also used to run the same build steps for multiple projects. At the moment, we have only react-app project, but it can be easily extended.</p><p>We’re running this workflow when the master branch is modified. For pull requests, Netlify will provide preview URLs, but if we push something directly to master branch, it will trigger a production build and the code will be deployed to the main URL.</p><p>The main workflow we created is mostly suitable for development/staging environments. For production, you probably want to trigger the flow manually and create a git tag. You can create another site in Netlify, create a PRODUCTION_NETLIFY_SITE_ID secret in Github and use the following configuration:</p><pre>name: React App Production Deployment<br>on:<br>  workflow_dispatch:<br>    inputs:<br>      version:<br>        description: Bump Version<br>        default: v1.0.0<br>        required: <strong>true</strong><br>      git-ref:<br>        description: Git Ref (Optional)<br>        required: <strong>false</strong><br><em># Jobs to carry out</em><br>jobs:<br>  lint:<br>    runs-on: ubuntu-latest<br>    steps:<br>      <em># Get code from repo</em><br>      - name: Clone Repository (Latest)<br>        uses: actions/checkout@v2<br>        if: github.event.inputs.git-ref == &#39;&#39;<br>      - name: Clone Repository (Custom Ref)<br>        uses: actions/checkout@v2<br>        if: github.event.inputs.git-ref != &#39;&#39;<br>        with:<br>          ref: ${{ github.event.inputs.git-ref }}<br>      <em># Install NodeJS</em><br>      - name: Use Node.js 14.x<br>        uses: actions/setup-node@v1<br>        with:<br>          node-version: 14.x<br>      <em># Run rush install and build on our code</em><br>      - name: Install dependencies<br>        run: |<br>          node common/scripts/install-run-rush.js change -v<br>          node common/scripts/install-run-rush.js install<br>          node common/scripts/install-run-rush.js build<br>      <em># Run eslint to check all packages</em><br>      - name: Lint packages<br>        run: node common/scripts/install-run-rush.js lint<br>  test:<br>    runs-on: ubuntu-latest<br>    env:<br>      CI: <strong>true</strong><br>    steps:<br>      <em># Get code from repo</em><br>      - name: Clone Repository (Latest)<br>        uses: actions/checkout@v2<br>        if: github.event.inputs.git-ref == &#39;&#39;<br>      - name: Clone Repository (Custom Ref)<br>        uses: actions/checkout@v2<br>        if: github.event.inputs.git-ref != &#39;&#39;<br>        with:<br>          ref: ${{ github.event.inputs.git-ref }}<br>      <em># Install NodeJS</em><br>      - name: Use Node.js 14.x<br>        uses: actions/setup-node@v1<br>        with:<br>          node-version: 14.x<br>      <em># Run rush install</em><br>      - name: Install dependencies<br>        run: |<br>          node common/scripts/install-run-rush.js change -v<br>          node common/scripts/install-run-rush.js install<br>          node common/scripts/install-run-rush.js build<br>      <em># Run unit tests for all packages</em><br>      - name: Run tests<br>        run: node common/scripts/install-run-rush.js test<br>  deploy:<br>    <em># Operating system to run job on</em><br>    runs-on: ubuntu-latest<br>    needs: [lint, test]<br>    <em># Steps in job</em><br>    steps:<br>      <em># Get code from repo</em><br>      - name: Clone Repository (Latest)<br>        uses: actions/checkout@v2<br>        if: github.event.inputs.git-ref == &#39;&#39;<br>      - name: Clone Repository (Custom Ref)<br>        uses: actions/checkout@v2<br>        if: github.event.inputs.git-ref != &#39;&#39;<br>        with:<br>          ref: ${{ github.event.inputs.git-ref }}<br>      <em># Install NodeJS</em><br>      - name: Use Node.js 14.x<br>        uses: actions/setup-node@v1<br>        with:<br>          node-version: 14.x<br>      <em># Run rush install and build on our code</em><br>      - name: Install dependencies<br>        run: |<br>          node common/scripts/install-run-rush.js change -v<br>          node common/scripts/install-run-rush.js install<br>      <em># Build app</em><br>      - name: Build react app<br>        working-directory: apps/react-app<br>        run: |<br>          node  $GITHUB_WORKSPACE/common/scripts/install-run-rush.js build --verbose --to @monorepo/react-app<br>      - name: Deploy react app<br>        uses: nwtgck/actions-netlify@v1.2<br>        with:<br>          publish-dir: apps/react-app/build<br>          production-deploy: <strong>true</strong><br>          github-token: ${{ secrets.GITHUB_TOKEN }}<br>          enable-pull-request-comment: <strong>true</strong><br>          enable-commit-comment: <strong>true</strong><br>          overwrites-pull-request-comment: <strong>true</strong><br>        env:<br>          NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}<br>          NETLIFY_SITE_ID: ${{ secrets.PRODUCTION_NETLIFY_SITE_ID }}<br>      <em># Create release tag</em><br>      - name: Create tag<br>        run: |<br>          git tag ${{ github.event.inputs.version }}<br>          git push origin --tags</pre><p>Now we can trigger a production deployment manually for react-app project. We can provide the next version number as a version parameter and it will create a tag for us. If we want to revert to a previous version, you can also do it by providing a git-ref.</p><p>If you encountered any issues during the process, you can see the code related to this post <a href="https://github.com/abereghici/rush-monorepo-boilerplate">here</a>.</p><p>If you’re using VSCode, you might be interested to see some configurations that can enrich your development experience with this monorepo. See the <a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-5-355f5391fd27">next post</a>.</p><p><em>Originally published at </em><a href="https://bereghici.dev/blog/build-a-scalable-front-end-with-rush-monorepo-and-react--github-actions+netlify"><em>https://bereghici.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d0939bfb8b8a" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-4-d0939bfb8b8a">Build a scalable front-end with Rush monorepo and React — Part 4</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a scalable front-end with Rush monorepo and React — Part 3]]></title>
            <link>https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-3-b90430f15af7?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/b90430f15af7</guid>
            <category><![CDATA[eslint]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[rushjs]]></category>
            <category><![CDATA[rushstack]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Fri, 03 Sep 2021 08:48:04 GMT</pubDate>
            <atom:updated>2022-01-11T09:02:11.051Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a scalable front-end with Rush monorepo and React — Part 3</h3><h3>ESLint + Lint Staged</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/0*AeSFhH2_cO3nMUOP.jpg" /></figure><p>This is the 3rd part of the blog series “Build a scalable front-end with Rush monorepo and React”</p><ul><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-1-dd50ae38ad3e">Part 1</a>: Monorepo setup, import projects with preserving git history, <br>add Prettier</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-2-d7f1c19c1797">Part 2</a>: Create build tools package with Webpack and react-scripts</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-3-b90430f15af7">Part 3</a>: Add shared ESLint configuration and use it with lint-staged</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-4-d0939bfb8b8a">Part 4</a>: Setup a deployment workflow with Github Actions and Netlify.</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-5-355f5391fd27">Part 5</a>: Add VSCode configurations for a better development experience.</li></ul><h4>TL;DR</h4><p>If you’re interested in just see the code, you can find it here: <a href="https://github.com/abereghici/rush-monorepo-boilerplate">https://github.com/abereghici/rush-monorepo-boilerplate</a></p><p>If you want to see an example with Rush used in a real, large project, you can look at <a href="https://github.com/imodeljs/imodeljs">ITwin.js</a>, an open-source project developed by Bentley Systems.</p><p>ESLint is a dominant tool for linting TypeScript and JavaScript code. We’ll use it together with Lint Staged to achieve the goal “ <em>Enforced rules for code quality</em>” we defined in <a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-1-dd50ae38ad3e">Part 1</a>.</p><p>ESLint works with a set of rules you define. If you already have a configuration for ESLint that you like, you can add it to our next setup. We’ll be using AirBnB’s ESLint config, which is the most common rules list for JavaScript projects. As of mid-2021, it gets over 2.7 million downloads per week from NPM.</p><h4>Build eslint-config package</h4><p>Let’s start by creating a folder named eslint-config in packages and creating package.json file.</p><pre>mkdir packages/eslint-config </pre><pre>touch packages/eslint-config/package.json</pre><p>Paste the following content to packages/eslint-config/package.json:</p><pre>{<br>  &quot;name&quot;: &quot;@monorepo/eslint-config&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;description&quot;: &quot;Shared eslint rules&quot;,<br>  &quot;main&quot;: &quot;index.js&quot;,<br>  &quot;scripts&quot;: {<br>    &quot;build&quot;: &quot;&quot;<br>  },<br>  &quot;dependencies&quot;: {<br>    &quot;@babel/eslint-parser&quot;: &quot;~7.14.4&quot;,<br>    &quot;@babel/eslint-plugin&quot;: &quot;~7.13.16&quot;,<br>    &quot;@babel/preset-react&quot;: &quot;~7.13.13&quot;,<br>    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^4.26.1&quot;,<br>    &quot;@typescript-eslint/parser&quot;: &quot;^4.26.1&quot;,<br>    &quot;babel-eslint&quot;: &quot;~10.1.0&quot;,<br>    &quot;eslint-config-airbnb&quot;: &quot;^18.2.1&quot;,<br>    &quot;eslint-config-prettier&quot;: &quot;^7.1.0&quot;,<br>    &quot;eslint-config-react-app&quot;: &quot;~6.0.0&quot;,<br>    &quot;eslint-plugin-import&quot;: &quot;^2.23.4&quot;,<br>    &quot;eslint-plugin-flowtype&quot;: &quot;^5.2.1&quot;,<br>    &quot;eslint-plugin-jest&quot;: &quot;^24.1.5&quot;,<br>    &quot;eslint-plugin-jsx-a11y&quot;: &quot;^6.4.1&quot;,<br>    &quot;eslint-plugin-prettier&quot;: &quot;^3.3.1&quot;,<br>    &quot;eslint-plugin-react&quot;: &quot;^7.24.0&quot;,<br>    &quot;eslint-plugin-react-hooks&quot;: &quot;^4.2.0&quot;,<br>    &quot;eslint-plugin-testing-library&quot;: &quot;^3.9.2&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;read-pkg-up&quot;: &quot;7.0.1&quot;,<br>    &quot;semver&quot;: &quot;~7.3.5&quot;<br>  },<br>  &quot;peerDependencies&quot;: {<br>    &quot;eslint&quot;: &quot;^7.28.0&quot;,<br>    &quot;typescript&quot;: &quot;^4.3.5&quot;<br>  },<br>  &quot;peerDependenciesMeta&quot;: {<br>    &quot;typescript&quot;: {<br>      &quot;optional&quot;: true<br>    }<br>  }<br>}</pre><p>Here we added all dependencies we need for our ESLint config.</p><p>Now, let’s create a config.js file where we&#39;ll define ESLint configurations, non-related to rules.</p><pre>const fs = require(&#39;fs&#39;);<br>const path = require(&#39;path&#39;);<br><br>const tsConfig = fs.existsSync(&#39;tsconfig.json&#39;)<br>  ? path.resolve(&#39;tsconfig.json&#39;)<br>  : undefined;<br><br>module.exports = {<br>  parser: &#39;@babel/eslint-parser&#39;,<br>  parserOptions: {<br>    babelOptions: {<br>      presets: [&#39;@babel/preset-react&#39;],<br>    },<br>    requireConfigFile: false,<br>    ecmaVersion: 2021,<br>    sourceType: &#39;module&#39;,<br>    ecmaFeatures: {<br>      jsx: true,<br>    },<br>  },<br>  env: {<br>    es6: true,<br>    jest: true,<br>    browser: true,<br>  },<br>  globals: {<br>    globals: true,<br>    shallow: true,<br>    render: true,<br>    mount: true,<br>  },<br>  overrides: [<br>    {<br>      files: [&#39;**/*.ts?(x)&#39;],<br>      parser: &#39;@typescript-eslint/parser&#39;,<br>      parserOptions: {<br>        ecmaVersion: 2021,<br>        sourceType: &#39;module&#39;,<br>        project: tsConfig,<br>        ecmaFeatures: {<br>          jsx: true,<br>        },<br>        warnOnUnsupportedTypeScriptVersion: true,<br>      },<br>    },<br>  ],<br>};</pre><p>We’ll split ESLint rules into multiple files. In base.js file, we&#39;ll define the main rules that can be applied to all packages. In react.js will be the React-specific rules. We might have packages that don&#39;t use React, so we&#39;ll use only the base rules.</p><p>Create a base.js file and add:</p><pre>module.exports = {<br>  extends: [&#39;airbnb&#39;, &#39;prettier&#39;],<br>  plugins: [&#39;prettier&#39;],<br>  rules: {<br>    camelcase: &#39;error&#39;,<br>    semi: [&#39;error&#39;, &#39;always&#39;],<br>    quotes: [<br>      &#39;error&#39;,<br>      &#39;single&#39;,<br>      {<br>        allowTemplateLiterals: true,<br>        avoidEscape: true,<br>      },<br>    ],<br>  },<br>  overrides: [<br>    {<br>      files: [&#39;**/*.ts?(x)&#39;],<br>      extends: [<br>        &#39;prettier/@typescript-eslint&#39;,<br>        &#39;plugin:@typescript-eslint/recommended&#39;,<br>      ],<br>      rules: {},<br>    },<br>  ],<br>};</pre><p>Here we’re extending airbnb and prettier configurations. Here you can include other base rules you would like to use.</p><p>In react.js add the following:</p><pre>const readPkgUp = require(&#39;read-pkg-up&#39;);<br>const semver = require(&#39;semver&#39;);<br><br>let oldestSupportedReactVersion = &#39;17.0.1&#39;;<br><br><em>// Get react version from package.json and used it in lint configuration</em><br>try {<br>  const pkg = readPkgUp.sync({ normalize: true });<br>  const allDeps = Object.assign(<br>    { react: &#39;17.0.1&#39; },<br>    pkg.peerDependencies,<br>    pkg.devDependencies,<br>    pkg.dependencies<br>  );<br><br>  oldestSupportedReactVersion = semver<br>    .validRange(allDeps.react)<br>    .replace(/[&gt;=&lt;|]/g, &#39; &#39;)<br>    .split(&#39; &#39;)<br>    .filter(Boolean)<br>    .sort(semver.compare)[0];<br>} catch (error) {<br>  <em>// ignore error</em><br>}<br><br>module.exports = {<br>  extends: [<br>    &#39;react-app&#39;,<br>    &#39;react-app/jest&#39;,<br>    &#39;prettier/react&#39;,<br>    &#39;plugin:testing-library/recommended&#39;,<br>    &#39;plugin:testing-library/react&#39;,<br>  ],<br>  plugins: [&#39;react&#39;, &#39;react-hooks&#39;, &#39;testing-library&#39;, &#39;prettier&#39;],<br>  settings: {<br>    react: {<br>      version: oldestSupportedReactVersion,<br>    },<br>  },<br>  rules: {<br>    &#39;react/jsx-fragments&#39;: [&#39;error&#39;, &#39;element&#39;],<br>    &#39;react-hooks/rules-of-hooks&#39;: &#39;error&#39;,<br>  },<br>  overrides: [<br>    {<br>      files: [&#39;**/*.ts?(x)&#39;],<br>      rules: {<br>        &#39;react/jsx-filename-extension&#39;: [<br>          1,<br>          {<br>            extensions: [&#39;.js&#39;, &#39;.jsx&#39;, &#39;.ts&#39;, &#39;.tsx&#39;],<br>          },<br>        ],<br>      },<br>    },<br>  ],<br>};</pre><p>We have to provide a react version to react-app configuration. Instead of hardcoding it, we&#39;ll use read-pkg-up to get the version from package.json. semver is used to help us pick the right version.</p><p>The last step is to define the entry-point of our configurations. Create a index.js file and add:</p><pre>module.exports = {<br>  extends: [&#39;./config.js&#39;, &#39;./base.js&#39;],<br>};</pre><h4>Add lint command to react-scripts</h4><p>ESLint can be used in a variety of ways. You can install it on every package or create a lint script that runs the ESLint bin for you. I&#39;m feeling more comfortable with the second approach. We can control the ESLint version in one place which makes the upgrade process easier.</p><p>We’ll need few util functions for lint script, so create an index.js file inside of packages/react-scripts/scripts/utils and add the following:</p><pre>const fs = require(&#39;fs&#39;);<br>const path = require(&#39;path&#39;);<br>const which = require(&#39;which&#39;);<br>const readPkgUp = require(&#39;read-pkg-up&#39;);<br><br>const { path: pkgPath } = readPkgUp.sync({<br>  cwd: fs.realpathSync(process.cwd()),<br>});<br><br>const appDirectory = path.dirname(pkgPath);<br><br>const fromRoot = (...p) =&gt; path.join(appDirectory, ...p);<br><br>function resolveBin(<br>  modName,<br>  { executable = modName, cwd = process.cwd() } = {}<br>) {<br>  let pathFromWhich;<br>  try {<br>    pathFromWhich = fs.realpathSync(which.sync(executable));<br>    if (pathFromWhich &amp;&amp; pathFromWhich.includes(&#39;.CMD&#39;)) return pathFromWhich;<br>  } catch (_error) {<br>    <em>// ignore _error</em><br>  }<br>  try {<br>    const modPkgPath = require.resolve(`${modName}/package.json`);<br>    const modPkgDir = path.dirname(modPkgPath);<br>    const { bin } = require(modPkgPath);<br>    const binPath = typeof bin === &#39;string&#39; ? bin : bin[executable];<br>    const fullPathToBin = path.join(modPkgDir, binPath);<br>    if (fullPathToBin === pathFromWhich) {<br>      return executable;<br>    }<br>    return fullPathToBin.replace(cwd, &#39;.&#39;);<br>  } catch (error) {<br>    if (pathFromWhich) {<br>      return executable;<br>    }<br>    throw error;<br>  }<br>}<br><br>module.exports = {<br>  resolveBin,<br>  fromRoot,<br>  appDirectory,<br>};</pre><p>The most important function here is resolveBin that will try to resolve the binary for a given module.</p><p>Create lint.js file inside of packages/react-scripts/scripts and add the following:</p><pre>const spawn = require(&#39;react-dev-utils/crossSpawn&#39;);<br>const yargsParser = require(&#39;yargs-parser&#39;);<br>const { resolveBin, fromRoot, appDirectory } = require(&#39;./utils&#39;);<br><br>let args = process.argv.slice(2);<br>const parsedArgs = yargsParser(args);<br><br>const cache = args.includes(&#39;--no-cache&#39;)<br>  ? []<br>  : [<br>      &#39;--cache&#39;,<br>      &#39;--cache-location&#39;,<br>      fromRoot(&#39;node_modules/.cache/.eslintcache&#39;),<br>    ];<br><br>const files = parsedArgs._;<br><br>const relativeEslintNodeModules = &#39;node_modules/@monorepo/eslint-config&#39;;<br>const pluginsDirectory = `${appDirectory}/${relativeEslintNodeModules}`;<br><br>const resolvePluginsRelativeTo = [<br>  &#39;--resolve-plugins-relative-to&#39;,<br>  pluginsDirectory,<br>];<br><br>const result = spawn.sync(<br>  resolveBin(&#39;eslint&#39;),<br>  [<br>    ...cache,<br>    ...files,<br>    ...resolvePluginsRelativeTo,<br>    &#39;--no-error-on-unmatched-pattern&#39;,<br>  ],<br>  { stdio: &#39;inherit&#39; }<br>);<br><br>process.exit(result.status);</pre><p>In packages/react-scripts/bin/react-scripts.js register the lint command:</p><pre>. . .</pre><pre> const scriptIndex = args.findIndex(<br>  x =&gt; x === &#39;build&#39; || x === &#39;start&#39; || x === &#39;lint&#39; || x === &#39;test&#39;<br>);</pre><pre>. . .<br></pre><pre>if ([&#39;build&#39;, &#39;start&#39;, &#39;lint&#39;, &#39;test&#39;].includes(script)) {</pre><pre>. . .</pre><p>Now, add our new dependencies in packages/react-scripts/package.json:</p><pre>. . .</pre><pre>    &quot;which&quot;: &quot;~2.0.2&quot;,<br>    &quot;read-pkg-up&quot;: &quot;7.0.1&quot;,<br>    &quot;yargs-parser&quot;: &quot;~20.2.7&quot;,<br>    &quot;eslint&quot;: &quot;^7.28.0&quot;</pre><pre>. . .</pre><h4>Lint script in action</h4><p>Our lint script is ready, now let&#39;s run it in react-app project. Create a new file named .eslintrc.js and add the following:</p><pre>module.exports = {<br>  extends: [&#39;@monorepo/eslint-config&#39;, &#39;@monorepo/eslint-config/react&#39;],<br>};</pre><p>Inside package.json add eslint-config as dependency:</p><pre><br> &quot;@monorepo/eslint-config&quot;: &quot;1.0.0&quot;<br></pre><p>In scripts section add lint command:</p><pre>&quot;lint&quot;: &quot;react-scripts lint src&quot;</pre><p>Run rush update following by rushx lint. At this point, you should see a bunch of ESLint errors. As an exercise, you can try to fix them by enabling/disabling some rules in eslint-config or modify react-app project to make it pass the linting.</p><h4>Add lint-staged command to react-scripts</h4><p>We’ll follow the same approach as we did with lint script. Create lint-staged.js file inside of packages/react-scripts/scripts and add the following:</p><pre>const spawn = require(&#39;react-dev-utils/crossSpawn&#39;);<br>const { resolveBin } = require(&#39;./utils&#39;);<br><br>const args = process.argv.slice(2);<br><br>result = spawn.sync(resolveBin(&#39;lint-staged&#39;), [...args], {<br>  stdio: &#39;inherit&#39;,<br>});<br><br>process.exit(result.status);</pre><p>Add lint-staged as dependency in package.json:</p><pre>...<br> &quot;lint-staged&quot;: &quot;~11.0.0&quot;<br>...</pre><p>Open packages/react-scripts/bin/react-scripts.js and register lint-staged command.</p><p>Next step is to register a lint-staged rush command in common/config/command-line.json, as we did with prettier command in <a href="https://bereghici.dev/blog/build-a-scalable-front-end-with-rush-monorepo-and-react--repo-setup+import-projects+prettier">Part 1</a>.</p><pre>{<br>  &quot;name&quot;: &quot;lint-staged&quot;,<br>  &quot;commandKind&quot;: &quot;bulk&quot;,<br>  &quot;summary&quot;: &quot;Run lint-staged on each package&quot;,<br>  &quot;description&quot;: &quot;Iterates through each package in the monorepo and runs the &#39;lint-staged&#39; script&quot;,<br>  &quot;enableParallelism&quot;: false,<br>  &quot;ignoreMissingScript&quot;: true,<br>  &quot;ignoreDependencyOrder&quot;: true,<br>  &quot;allowWarningsInSuccessfulBuild&quot;: true<br>},</pre><p>Now, let’s run lint-staged command on git pre-commit hook. Open common/git-hooks/pre-commit and add the append to the end of the file:</p><pre>node common/scripts/install-run-rush.js lint-staged || exit $?</pre><h4>Lint staged in action</h4><p>Let’s define what tasks we want lint-staged to run for react-app project. Open package.json of react-app and add the configuration for lint-staged:</p><pre>&quot;lint-staged&quot;: {<br>    &quot;src/**/*.{ts,tsx}&quot;: [<br>      &quot;react-scripts lint --fix --&quot;,<br>      &quot;react-scripts test --findRelatedTests --watchAll=false --silent&quot;<br>    ],<br>  },</pre><p>Also in package.json add the new lint-staged script:</p><pre>&quot;lint-staged&quot;: &quot;react-scripts lint-staged&quot;</pre><p>Now, on each commit, lint-staged will lint our files and will run tests for related files.</p><p>Run rush install to register our command, then rush update and let&#39;s commit our changes to see everything in action.</p><p>If you encountered any issues during the process, you can see the code related to this post <a href="https://github.com/abereghici/rush-monorepo-boilerplate/tree/049506a98529d4931b2a2ecb629957e0d93e8a8d">here</a>.</p><p>Let’s go to the <a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-4-d0939bfb8b8a">next part</a> where we’ll see how to use Github Actions with Netlify to automate our deployment workflow.</p><p><em>Originally published at </em><a href="https://bereghici.dev/blog/build-a-scalable-front-end-with-rush-monorepo-and-react--eslint+lint-staged"><em>https://bereghici.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b90430f15af7" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-3-b90430f15af7">Build a scalable front-end with Rush monorepo and React — Part 3</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a scalable front-end with Rush monorepo and React — Part 2]]></title>
            <link>https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-2-d7f1c19c1797?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7f1c19c1797</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[rushjs]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[rushstack]]></category>
            <category><![CDATA[webpack]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Fri, 03 Sep 2021 08:47:30 GMT</pubDate>
            <atom:updated>2022-01-11T09:01:28.877Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a scalable front-end with Rush monorepo and React — Part 2</h3><h3>Webpack + Jest</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/0*3d4-KghKBezzZm2j.jpg" /></figure><p>This is the 2nd part of the blog series “Build a scalable front-end with Rush monorepo and React”</p><ul><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-1-dd50ae38ad3e">Part 1</a>: Monorepo setup, import projects with preserving git history, <br>add Prettier</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-2-d7f1c19c1797">Part 2</a>: Create build tools package with Webpack and react-scripts</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-3-b90430f15af7">Part 3</a>: Add shared ESLint configuration and use it with lint-staged</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-4-d0939bfb8b8a">Part 4</a>: Setup a deployment workflow with Github Actions and Netlify.</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-5-355f5391fd27">Part 5</a>: Add VSCode configurations for a better development experience.</li></ul><h3>TL;DR</h3><p>If you’re interested in just see the code, you can find it here: <a href="https://github.com/abereghici/rush-monorepo-boilerplate">https://github.com/abereghici/rush-monorepo-boilerplate</a></p><p>If you want to see an example with Rush used in a real, large project, you can look at <a href="https://github.com/imodeljs/imodeljs">ITwin.js</a>, an open-source project developed by Bentley Systems.</p><p><a href="https://create-react-app.dev/">create-react-app</a> is a great tool that allows you to develop react applications without having to manually configure build tools. When you develop small projects, it might be overkill to manage your own build tools and CRA is more than enough, but when you start to build large projects you might find CRA configuration lacking. CRA is an opinionated pre-configured tool, so there will always be some settings that you aren’t happy with and you cannot change them.</p><p>In this post, we’ll create our own build tools, based on <a href="https://create-react-app.dev/">create-react-app</a>. This will give us full control over the build process.</p><h4>Create react-scripts package</h4><p>Let’s create a new folder for react-scripts package.</p><pre>mkdir -p packages/react-scripts</pre><p>Create a package.json file inside the react-scripts folder and add the following configuration:</p><pre>{<br>  &quot;name&quot;: &quot;@monorepo/react-scripts&quot;,<br>  &quot;version&quot;: &quot;1.0.0&quot;,<br>  &quot;files&quot;: [&quot;bin&quot;, &quot;config&quot;, &quot;lib&quot;, &quot;scripts&quot;, &quot;utils&quot;],<br>  &quot;bin&quot;: {<br>    &quot;react-scripts&quot;: &quot;./bin/react-scripts.js&quot;<br>  },<br>  &quot;types&quot;: &quot;./lib/react-app.d.ts&quot;,<br>  &quot;dependencies&quot;: {<br>    &quot;@babel/core&quot;: &quot;7.12.3&quot;,<br>    &quot;@pmmmwh/react-refresh-webpack-plugin&quot;: &quot;0.4.3&quot;,<br>    &quot;@svgr/webpack&quot;: &quot;5.5.0&quot;,<br>    &quot;@testing-library/jest-dom&quot;: &quot;^5.14.1&quot;,<br>    &quot;@testing-library/react&quot;: &quot;^11.2.7&quot;,<br>    &quot;@testing-library/user-event&quot;: &quot;^12.8.3&quot;,<br>    &quot;@types/jest&quot;: &quot;^26.0.24&quot;,<br>    &quot;@types/node&quot;: &quot;^12.20.19&quot;,<br>    &quot;@types/react&quot;: &quot;^17.0.18&quot;,<br>    &quot;@types/react-dom&quot;: &quot;^17.0.9&quot;,<br>    &quot;@typescript-eslint/eslint-plugin&quot;: &quot;^4.5.0&quot;,<br>    &quot;@typescript-eslint/parser&quot;: &quot;^4.5.0&quot;,<br>    &quot;babel-eslint&quot;: &quot;^10.1.0&quot;,<br>    &quot;babel-jest&quot;: &quot;^26.6.0&quot;,<br>    &quot;babel-loader&quot;: &quot;8.1.0&quot;,<br>    &quot;babel-plugin-named-asset-import&quot;: &quot;^0.3.7&quot;,<br>    &quot;babel-preset-react-app&quot;: &quot;^10.0.0&quot;,<br>    &quot;bfj&quot;: &quot;^7.0.2&quot;,<br>    &quot;camelcase&quot;: &quot;^6.1.0&quot;,<br>    &quot;case-sensitive-paths-webpack-plugin&quot;: &quot;2.3.0&quot;,<br>    &quot;css-loader&quot;: &quot;4.3.0&quot;,<br>    &quot;dotenv&quot;: &quot;8.2.0&quot;,<br>    &quot;dotenv-expand&quot;: &quot;5.1.0&quot;,<br>    &quot;file-loader&quot;: &quot;6.1.1&quot;,<br>    &quot;fs-extra&quot;: &quot;^9.0.1&quot;,<br>    &quot;html-webpack-plugin&quot;: &quot;4.5.0&quot;,<br>    &quot;identity-obj-proxy&quot;: &quot;3.0.0&quot;,<br>    &quot;jest&quot;: &quot;26.6.0&quot;,<br>    &quot;jest-circus&quot;: &quot;26.6.0&quot;,<br>    &quot;jest-resolve&quot;: &quot;26.6.0&quot;,<br>    &quot;jest-watch-typeahead&quot;: &quot;0.6.1&quot;,<br>    &quot;mini-css-extract-plugin&quot;: &quot;0.11.3&quot;,<br>    &quot;optimize-css-assets-webpack-plugin&quot;: &quot;5.0.4&quot;,<br>    &quot;pnp-webpack-plugin&quot;: &quot;1.6.4&quot;,<br>    &quot;postcss-flexbugs-fixes&quot;: &quot;4.2.1&quot;,<br>    &quot;postcss-loader&quot;: &quot;3.0.0&quot;,<br>    &quot;postcss-normalize&quot;: &quot;8.0.1&quot;,<br>    &quot;postcss-preset-env&quot;: &quot;6.7.0&quot;,<br>    &quot;postcss-safe-parser&quot;: &quot;5.0.2&quot;,<br>    &quot;prompts&quot;: &quot;2.4.0&quot;,<br>    &quot;react-app-polyfill&quot;: &quot;^2.0.0&quot;,<br>    &quot;react-dev-utils&quot;: &quot;^11.0.3&quot;,<br>    &quot;react-refresh&quot;: &quot;^0.8.3&quot;,<br>    &quot;resolve&quot;: &quot;1.18.1&quot;,<br>    &quot;resolve-url-loader&quot;: &quot;^3.1.2&quot;,<br>    &quot;sass-loader&quot;: &quot;^10.0.5&quot;,<br>    &quot;semver&quot;: &quot;7.3.2&quot;,<br>    &quot;style-loader&quot;: &quot;1.3.0&quot;,<br>    &quot;terser-webpack-plugin&quot;: &quot;4.2.3&quot;,<br>    &quot;ts-pnp&quot;: &quot;1.2.0&quot;,<br>    &quot;url-loader&quot;: &quot;4.1.1&quot;,<br>    &quot;web-vitals&quot;: &quot;^1.1.2&quot;,<br>    &quot;webpack&quot;: &quot;4.44.2&quot;,<br>    &quot;webpack-dev-server&quot;: &quot;3.11.1&quot;,<br>    &quot;webpack-manifest-plugin&quot;: &quot;2.2.0&quot;,<br>    &quot;workbox-webpack-plugin&quot;: &quot;5.1.4&quot;<br>  },<br>  &quot;devDependencies&quot;: {<br>    &quot;react&quot;: &quot;^17.0.1&quot;,<br>    &quot;react-dom&quot;: &quot;^17.0.1&quot;<br>  }<br>}</pre><p>As you already noticed, we moved all build dependencies from react-app project to react-scripts package.</p><p>Move config and scripts folders from react-app to react-scripts and let&#39;s adjust the configurations.</p><p>Remove ESLint plugin and its dependencies from packages/react-scripts/config/webpack.config.js. We&#39;ll use it later as a separate action in our build process.</p><p>Open packages/react-scripts/config/paths.js and replace the file content with:</p><pre>const path = require(&#39;path&#39;);<br>const fs = require(&#39;fs&#39;);<br>const getPublicUrlOrPath = require(&#39;react-dev-utils/getPublicUrlOrPath&#39;);<br><br><em>// Make sure any symlinks in the project folder are resolved:</em><br><em>// https://github.com/facebook/create-react-app/issues/637</em><br>const appDirectory = fs.realpathSync(process.cwd());<br>const resolveApp = relativePath =&gt; path.resolve(appDirectory, relativePath);<br><br><em>// We use `PUBLIC_URL` environment variable or &quot;homepage&quot; field to infer</em><br><em>// &quot;public path&quot; at which the app is served.</em><br><em>// webpack needs to know it to put the right &lt;script&gt; hrefs into HTML even in</em><br><em>// single-page apps that may serve index.html for nested URLs like /todos/42.</em><br><em>// We can&#39;t use a relative path in HTML because we don&#39;t want to load something</em><br><em>// like /todos/42/static/js/bundle.7289d.js. We have to know the root.</em><br>const publicUrlOrPath = getPublicUrlOrPath(<br>  process.env.NODE_ENV === &#39;development&#39;,<br>  require(resolveApp(&#39;package.json&#39;)).homepage,<br>  process.env.PUBLIC_URL<br>);<br><br>const buildPath = process.env.BUILD_PATH || &#39;build&#39;;<br><br>const moduleFileExtensions = [<br>  &#39;web.mjs&#39;,<br>  &#39;mjs&#39;,<br>  &#39;web.js&#39;,<br>  &#39;js&#39;,<br>  &#39;web.ts&#39;,<br>  &#39;ts&#39;,<br>  &#39;web.tsx&#39;,<br>  &#39;tsx&#39;,<br>  &#39;json&#39;,<br>  &#39;web.jsx&#39;,<br>  &#39;jsx&#39;,<br>];<br><br><em>// Resolve file paths in the same order as webpack</em><br>const resolveModule = (resolveFn, filePath) =&gt; {<br>  const extension = moduleFileExtensions.find(extension =&gt;<br>    fs.existsSync(resolveFn(`${filePath}.${extension}`))<br>  );<br><br>  if (extension) {<br>    return resolveFn(`${filePath}.${extension}`);<br>  }<br><br>  return resolveFn(`${filePath}.js`);<br>};<br><br>const resolveOwn = relativePath =&gt; path.resolve(__dirname, &#39;..&#39;, relativePath);<br><br>module.exports = {<br>  dotenv: resolveApp(&#39;.env&#39;),<br>  appPath: resolveApp(&#39;.&#39;),<br>  appBuild: resolveApp(buildPath),<br>  appPublic: resolveApp(&#39;public&#39;),<br>  appHtml: resolveApp(&#39;public/index.html&#39;),<br>  appIndexJs: resolveModule(resolveApp, &#39;src/index&#39;),<br>  appPackageJson: resolveApp(&#39;package.json&#39;),<br>  appSrc: resolveApp(&#39;src&#39;),<br>  appTsConfig: resolveApp(&#39;tsconfig.json&#39;),<br>  appJsConfig: resolveApp(&#39;jsconfig.json&#39;),<br>  yarnLockFile: resolveApp(&#39;yarn.lock&#39;),<br>  testsSetup: resolveModule(resolveApp, &#39;src/setupTests&#39;),<br>  proxySetup: resolveApp(&#39;src/setupProxy.js&#39;),<br>  appNodeModules: resolveApp(&#39;node_modules&#39;),<br>  appWebpackCache: resolveApp(&#39;node_modules/.cache&#39;),<br>  appTsBuildInfoFile: resolveApp(&#39;node_modules/.cache/tsconfig.tsbuildinfo&#39;),<br>  swSrc: resolveModule(resolveApp, &#39;src/service-worker&#39;),<br>  publicUrlOrPath,<br>  <em>// These properties only exist before ejecting:</em><br>  ownPath: resolveOwn(&#39;.&#39;),<br>  ownNodeModules: resolveOwn(&#39;node_modules&#39;), <em>// This is empty on npm 3</em><br>  appTypeDeclarations: resolveApp(&#39;src/react-app-env.d.ts&#39;),<br>  ownTypeDeclarations: resolveOwn(&#39;lib/react-app.d.ts&#39;),<br>};<br><br>module.exports.moduleFileExtensions = moduleFileExtensions;</pre><p>The most important change in this file is the resolveApp function call. We shouldn&#39;t use relative paths anymore, because we are moving the configuration files to react-scripts package. We&#39;ll get the project files paths using a combination between path.resolve and process.cwd().</p><p>Create a bin folder and in react-scripts.js file add the following code:</p><pre>process.on(&#39;unhandledRejection&#39;, err =&gt; {<br>  throw err;<br>});<br><br>const spawn = require(&#39;react-dev-utils/crossSpawn&#39;);<br>const args = process.argv.slice(2);<br><br>const scriptIndex = args.findIndex(<br>  x =&gt; x === &#39;build&#39; || x === &#39;start&#39; || x === &#39;test&#39;<br>);<br>const script = scriptIndex === -1 ? args[0] : args[scriptIndex];<br>const nodeArgs = scriptIndex &gt; 0 ? args.slice(0, scriptIndex) : [];<br><br>if ([&#39;build&#39;, &#39;start&#39;, &#39;test&#39;].includes(script)) {<br>  const result = spawn.sync(<br>    process.execPath,<br>    nodeArgs<br>      .concat(require.resolve(&#39;../scripts/&#39; + script))<br>      .concat(args.slice(scriptIndex + 1)),<br>    { stdio: &#39;inherit&#39; }<br>  );<br>  if (result.signal) {<br>    if (result.signal === &#39;SIGKILL&#39;) {<br>      console.log(<br>        &#39;The build failed because the process exited too early. &#39; +<br>          &#39;This probably means the system ran out of memory or someone called &#39; +<br>          &#39;`kill -9` on the process.&#39;<br>      );<br>    } else if (result.signal === &#39;SIGTERM&#39;) {<br>      console.log(<br>        &#39;The build failed because the process exited too early. &#39; +<br>          &#39;Someone might have called `kill` or `killall`, or the system could &#39; +<br>          &#39;be shutting down.&#39;<br>      );<br>    }<br>    process.exit(1);<br>  }<br>  process.exit(result.status);<br>} else {<br>  console.log(&#39;Unknown script &quot;&#39; + script + &#39;&quot;.&#39;);<br>}</pre><p>This will be the entry point of our CLI. Every time when you’ll want to add a new command you have to adjust this file.</p><p>Create another folder named lib and in react-app.d.ts file add the following code:</p><pre><em>/// &lt;reference types=&quot;node&quot; /&gt;</em><br><em>/// &lt;reference types=&quot;react&quot; /&gt;</em><br><em>/// &lt;reference types=&quot;react-dom&quot; /&gt;</em><br><br>declare namespace NodeJS {<br>  interface ProcessEnv {<br>    readonly NODE_ENV: &#39;development&#39; | &#39;production&#39; | &#39;test&#39;;<br>    readonly PUBLIC_URL: string;<br>  }<br>}<br><br>declare module &#39;*.avif&#39; {<br>  const src: string;<br>  export default src;<br>}<br><br>declare module &#39;*.bmp&#39; {<br>  const src: string;<br>  export default src;<br>}<br><br>declare module &#39;*.gif&#39; {<br>  const src: string;<br>  export default src;<br>}<br><br>declare module &#39;*.jpg&#39; {<br>  const src: string;<br>  export default src;<br>}<br><br>declare module &#39;*.jpeg&#39; {<br>  const src: string;<br>  export default src;<br>}<br><br>declare module &#39;*.png&#39; {<br>  const src: string;<br>  export default src;<br>}<br><br>declare module &#39;*.webp&#39; {<br>  const src: string;<br>  export default src;<br>}<br><br>declare module &#39;*.svg&#39; {<br>  import * as React from &#39;react&#39;;<br><br>  export const ReactComponent: React.FunctionComponent&lt;<br>    React.SVGProps&lt;SVGSVGElement&gt; &amp; { title?: string }<br>  &gt;;<br><br>  const src: string;<br>  export default src;<br>}<br><br>declare module &#39;*.module.css&#39; {<br>  const classes: { readonly [key: string]: string };<br>  export default classes;<br>}<br><br>declare module &#39;*.module.scss&#39; {<br>  const classes: { readonly [key: string]: string };<br>  export default classes;<br>}<br><br>declare module &#39;*.module.sass&#39; {<br>  const classes: { readonly [key: string]: string };<br>  export default classes;<br>}</pre><p>Here we’ll store all type definitions for CSS, SASS, SCSS, and image files. We’ll reuse them in all react applications inside of the monorepo. You can address these type definitions by creating a file in your react project named react-app-env.d.ts with the following content:</p><pre><em>/// &lt;reference types=&quot;@monorepo/react-scripts&quot; /&gt;</em></pre><p>Now let’s register @monorepo/react-scripts package in rush configuration file. Open rush.json file and add an entry like this under the projects inventory:</p><pre>. . .<br> &quot;projects&quot;: [<br>    {<br>      &quot;packageName&quot;: &quot;@monorepo/react-scripts&quot;,<br>      &quot;projectFolder&quot;: &quot;packages/react-scripts&quot;,<br>      &quot;reviewCategory&quot;: &quot;tools&quot;<br>    }<br>  ]<br>. . .</pre><p>Now, let’s cleanup apps/react-app/package-json file by removing all dependencies related to build tools. We&#39;ll also remove the configurations for eslint, babel or jest, because we&#39;ll store them in a separate file. In our dependencies, we&#39;ll list@monorepo/react-scripts package.</p><p>Edit apps/react-app/package.json file and add the following configuration:</p><pre>{<br>  &quot;name&quot;: &quot;@monorepo/react-app&quot;,<br>  &quot;version&quot;: &quot;0.1.0&quot;,<br>  &quot;private&quot;: true,<br>  &quot;dependencies&quot;: {<br>    &quot;@testing-library/jest-dom&quot;: &quot;^5.14.1&quot;,<br>    &quot;@testing-library/react&quot;: &quot;^11.2.7&quot;,<br>    &quot;@testing-library/user-event&quot;: &quot;^12.8.3&quot;,<br>    &quot;@types/jest&quot;: &quot;^26.0.24&quot;,<br>    &quot;@types/react&quot;: &quot;^17.0.18&quot;,<br>    &quot;@types/react-dom&quot;: &quot;^17.0.9&quot;,<br>    &quot;react&quot;: &quot;^17.0.2&quot;,<br>    &quot;react-dom&quot;: &quot;^17.0.2&quot;,<br>    &quot;typescript&quot;: &quot;^4.3.5&quot;,<br>    &quot;web-vitals&quot;: &quot;^1.1.2&quot;,<br>    &quot;@monorepo/react-scripts&quot;: &quot;1.0.0&quot;<br>  },<br>  &quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;react-scripts start&quot;,<br>    &quot;build&quot;: &quot;react-scripts build&quot;,<br>    &quot;test&quot;: &quot;react-scripts test&quot;<br>  }<br>}</pre><p>Run rush update to install all dependencies and let&#39;s try to build our app with the react-script package we just created.</p><pre>cd apps/react-app </pre><pre>rushx build</pre><h4>Setup BrowserList</h4><p>By default, react-scripts expect to find a browserslist configuration in each project, otherwise, it fallbacks to the default browserslist configuration. If you want to use the same configuration for all your projects, you can modify packages/react-scripts/build.js to use browserslist from package.json from @monorepo/react-scripts.</p><p>Open package.json from @monorepo/react-scripts and add the following configuration:</p><pre>&quot;browserslist&quot;: {<br>    &quot;production&quot;: [<br>      &quot;&gt;0.2%&quot;,<br>      &quot;not dead&quot;,<br>      &quot;not op_mini all&quot;<br>    ],<br>    &quot;development&quot;: [<br>      &quot;last 1 chrome version&quot;,<br>      &quot;last 1 firefox version&quot;,<br>      &quot;last 1 safari version&quot;<br>    ]<br>  },</pre><p>Modify the checkBrowsers function call from packages/react-scripts/build.js and packages/react-scripts/start.js with:</p><pre>checkBrowsers(paths.ownPath, isInteractive)</pre><h4>Setup Jest</h4><p>Our current test script expects to find a jest configuration in each project. We&#39;ll modify it to use a shared configuration.</p><p>Create a utils folder in packages/react-scripts/scripts and in createJestConfig.js file add the following:</p><pre>const fs = require(&#39;fs&#39;);<br>const chalk = require(&#39;react-dev-utils/chalk&#39;);<br>const paths = require(&#39;../../config/paths&#39;);<br>const modules = require(&#39;../../config/modules&#39;);<br><br>module.exports = (resolve, rootDir, isEjecting) =&gt; {<br>  <em>// Use this instead of `paths.testsSetup` to avoid putting</em><br>  <em>// an absolute filename into configuration after ejecting.</em><br>  const setupTestsMatches = paths.testsSetup.match(/src[/\\]setupTests\.(.+)/);<br>  const setupTestsFileExtension =<br>    (setupTestsMatches &amp;&amp; setupTestsMatches[1]) || &#39;js&#39;;<br>  const setupTestsFile = fs.existsSync(paths.testsSetup)<br>    ? `&lt;rootDir&gt;/src/setupTests.${setupTestsFileExtension}`<br>    : undefined;<br><br>  const config = {<br>    roots: [&#39;&lt;rootDir&gt;/src&#39;],<br><br>    collectCoverageFrom: [&#39;src/**/*.{js,jsx,ts,tsx}&#39;, &#39;!src/**/*.d.ts&#39;],<br><br>    setupFiles: [<br>      isEjecting<br>        ? &#39;react-app-polyfill/jsdom&#39;<br>        : require.resolve(&#39;react-app-polyfill/jsdom&#39;),<br>    ],<br><br>    setupFilesAfterEnv: setupTestsFile ? [setupTestsFile] : [],<br>    testMatch: [<br>      &#39;&lt;rootDir&gt;/src/**/__tests__/**/*.{js,jsx,ts,tsx}&#39;,<br>      &#39;&lt;rootDir&gt;/src/**/*.{spec,test}.{js,jsx,ts,tsx}&#39;,<br>    ],<br>    testEnvironment: &#39;jsdom&#39;,<br>    testRunner: require.resolve(&#39;jest-circus/runner&#39;),<br>    transform: {<br>      &#39;^.+\\.(js|jsx|mjs|cjs|ts|tsx)$&#39;: resolve(<br>        &#39;config/jest/babelTransform.js&#39;<br>      ),<br>      &#39;^.+\\.css$&#39;: resolve(&#39;config/jest/cssTransform.js&#39;),<br>      &#39;^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)&#39;: resolve(<br>        &#39;config/jest/fileTransform.js&#39;<br>      ),<br>    },<br>    transformIgnorePatterns: [<br>      &#39;[/\\\\]node_modules[/\\\\].+\\.(js|jsx|mjs|cjs|ts|tsx)$&#39;,<br>      &#39;^.+\\.module\\.(css|sass|scss)$&#39;,<br>    ],<br>    modulePaths: modules.additionalModulePaths || [],<br>    moduleNameMapper: {<br>      &#39;^react-native$&#39;: &#39;react-native-web&#39;,<br>      &#39;^.+\\.module\\.(css|sass|scss)$&#39;: &#39;identity-obj-proxy&#39;,<br>      ...(modules.jestAliases || {}),<br>    },<br>    moduleFileExtensions: [...paths.moduleFileExtensions, &#39;node&#39;].filter(<br>      ext =&gt; !ext.includes(&#39;mjs&#39;)<br>    ),<br>    watchPlugins: [<br>      &#39;jest-watch-typeahead/filename&#39;,<br>      &#39;jest-watch-typeahead/testname&#39;,<br>    ],<br>    resetMocks: true,<br>  };<br>  if (rootDir) {<br>    config.rootDir = rootDir;<br>  }<br>  const overrides = Object.assign({}, require(paths.appPackageJson).jest);<br>  const supportedKeys = [<br>    &#39;clearMocks&#39;,<br>    &#39;collectCoverageFrom&#39;,<br>    &#39;coveragePathIgnorePatterns&#39;,<br>    &#39;coverageReporters&#39;,<br>    &#39;coverageThreshold&#39;,<br>    &#39;displayName&#39;,<br>    &#39;extraGlobals&#39;,<br>    &#39;globalSetup&#39;,<br>    &#39;globalTeardown&#39;,<br>    &#39;moduleNameMapper&#39;,<br>    &#39;resetMocks&#39;,<br>    &#39;resetModules&#39;,<br>    &#39;restoreMocks&#39;,<br>    &#39;snapshotSerializers&#39;,<br>    &#39;testMatch&#39;,<br>    &#39;transform&#39;,<br>    &#39;transformIgnorePatterns&#39;,<br>    &#39;watchPathIgnorePatterns&#39;,<br>  ];<br>  if (overrides) {<br>    supportedKeys.forEach(key =&gt; {<br>      if (Object.prototype.hasOwnProperty.call(overrides, key)) {<br>        if (Array.isArray(config[key]) || typeof config[key] !== &#39;object&#39;) {<br>          <em>// for arrays or primitive types, directly override the config key</em><br>          config[key] = overrides[key];<br>        } else {<br>          <em>// for object types, extend gracefully</em><br>          config[key] = Object.assign({}, config[key], overrides[key]);<br>        }<br><br>        delete overrides[key];<br>      }<br>    });<br>    const unsupportedKeys = Object.keys(overrides);<br>    if (unsupportedKeys.length) {<br>      const isOverridingSetupFile =<br>        unsupportedKeys.indexOf(&#39;setupFilesAfterEnv&#39;) &gt; -1;<br><br>      if (isOverridingSetupFile) {<br>        console.error(<br>          chalk.red(<br>            &#39;We detected &#39; +<br>              chalk.bold(&#39;setupFilesAfterEnv&#39;) +<br>              &#39; in your package.json.\n\n&#39; +<br>              &#39;Remove it from Jest configuration, and put the initialization code in &#39; +<br>              chalk.bold(&#39;src/setupTests.js&#39;) +<br>              &#39;.\nThis file will be loaded automatically.\n&#39;<br>          )<br>        );<br>      } else {<br>        console.error(<br>          chalk.red(<br>            &#39;\nOut of the box, Create React App only supports overriding &#39; +<br>              &#39;these Jest options:\n\n&#39; +<br>              supportedKeys<br>                .map(key =&gt; chalk.bold(&#39;  \u2022 &#39; + key))<br>                .join(&#39;\n&#39;) +<br>              &#39;.\n\n&#39; +<br>              &#39;These options in your package.json Jest configuration &#39; +<br>              &#39;are not currently supported by Create React App:\n\n&#39; +<br>              unsupportedKeys<br>                .map(key =&gt; chalk.bold(&#39;  \u2022 &#39; + key))<br>                .join(&#39;\n&#39;) +<br>              &#39;\n\nIf you wish to override other Jest options, you need to &#39; +<br>              &#39;eject from the default setup. You can do so by running &#39; +<br>              chalk.bold(&#39;npm run eject&#39;) +<br>              &#39; but remember that this is a one-way operation. &#39; +<br>              &#39;You may also file an issue with Create React App to discuss &#39; +<br>              &#39;supporting more options out of the box.\n&#39;<br>          )<br>        );<br>      }<br><br>      process.exit(1);<br>    }<br>  }<br>  return config;<br>};</pre><p>Now let’s use this configuration. Modify the test script in packages/react-scripts/scripts/test.js to look like this:</p><pre><em>// Do this as the first thing so that any code reading it knows the right env.</em><br>process.env.BABEL_ENV = &#39;test&#39;;<br>process.env.NODE_ENV = &#39;test&#39;;<br>process.env.PUBLIC_URL = &#39;&#39;;<br><br>process.on(&#39;unhandledRejection&#39;, err =&gt; {<br>  throw err;<br>});<br><br><em>// Ensure environment variables are read.</em><br>require(&#39;../config/env&#39;);<br><br>const jest = require(&#39;jest&#39;);<br>const execSync = require(&#39;child_process&#39;).execSync;<br>let argv = process.argv.slice(2);<br><br>function isInGitRepository() {<br>  try {<br>    execSync(&#39;git rev-parse --is-inside-work-tree&#39;, { stdio: &#39;ignore&#39; });<br>    return true;<br>  } catch (e) {<br>    return false;<br>  }<br>}<br><br>function isInMercurialRepository() {<br>  try {<br>    execSync(&#39;hg --cwd . root&#39;, { stdio: &#39;ignore&#39; });<br>    return true;<br>  } catch (e) {<br>    return false;<br>  }<br>}<br><br><em>// Watch unless on CI or explicitly running all tests</em><br>if (<br>  !process.env.CI &amp;&amp;<br>  argv.indexOf(&#39;--watchAll&#39;) === -1 &amp;&amp;<br>  argv.indexOf(&#39;--watchAll=false&#39;) === -1<br>) {<br>  <em>// https://github.com/facebook/create-react-app/issues/5210</em><br>  const hasSourceControl = isInGitRepository() || isInMercurialRepository();<br>  argv.push(hasSourceControl ? &#39;--watch&#39; : &#39;--watchAll&#39;);<br>}<br><br>const createJestConfig = require(&#39;./utils/createJestConfig&#39;);<br>const path = require(&#39;path&#39;);<br>const paths = require(&#39;../config/paths&#39;);<br>argv.push(<br>  &#39;--config&#39;,<br>  JSON.stringify(<br>    createJestConfig(<br>      relativePath =&gt; path.resolve(__dirname, &#39;..&#39;, relativePath),<br>      path.resolve(paths.appSrc, &#39;..&#39;),<br>      false<br>    )<br>  )<br>);<br><br><em>// This is a very dirty workaround for https://github.com/facebook/jest/issues/5913.</em><br><em>// We&#39;re trying to resolve the environment ourselves because Jest does it incorrectly.</em><br><em>// TODO: remove this as soon as it&#39;s fixed in Jest.</em><br>const resolve = require(&#39;resolve&#39;);<br>function resolveJestDefaultEnvironment(name) {<br>  const jestDir = path.dirname(<br>    resolve.sync(&#39;jest&#39;, {<br>      basedir: __dirname,<br>    })<br>  );<br>  const jestCLIDir = path.dirname(<br>    resolve.sync(&#39;jest-cli&#39;, {<br>      basedir: jestDir,<br>    })<br>  );<br>  const jestConfigDir = path.dirname(<br>    resolve.sync(&#39;jest-config&#39;, {<br>      basedir: jestCLIDir,<br>    })<br>  );<br>  return resolve.sync(name, {<br>    basedir: jestConfigDir,<br>  });<br>}<br>let cleanArgv = [];<br>let env = &#39;jsdom&#39;;<br>let next;<br>do {<br>  next = argv.shift();<br>  if (next === &#39;--env&#39;) {<br>    env = argv.shift();<br>  } else if (next.indexOf(&#39;--env=&#39;) === 0) {<br>    env = next.substring(&#39;--env=&#39;.length);<br>  } else {<br>    cleanArgv.push(next);<br>  }<br>} while (argv.length &gt; 0);<br>argv = cleanArgv;<br>let resolvedEnv;<br>try {<br>  resolvedEnv = resolveJestDefaultEnvironment(`jest-environment-${env}`);<br>} catch (e) {<br>  <em>// ignore</em><br>}<br>if (!resolvedEnv) {<br>  try {<br>    resolvedEnv = resolveJestDefaultEnvironment(env);<br>  } catch (e) {<br>    <em>// ignore</em><br>  }<br>}<br>const testEnvironment = resolvedEnv || env;<br>argv.push(&#39;--env&#39;, testEnvironment);<br><br>jest.run(argv);</pre><p>Now we can run rushx test inside of react-app project and test the shared configuration.</p><p>If you encountered any issues during the process, you can check all changes in <a href="https://github.com/abereghici/rush-monorepo-boilerplate/commit/de30f0a1bc1f3958e34bcccf7089d3439d153e2c">this commit</a>.</p><p>In the <a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-3-b90430f15af7">next part</a>, we’ll add a shared ESLint configuration and we’ll integrate it with <a href="https://github.com/okonet/lint-staged">lint-staged</a>.</p><p><em>Originally published at </em><a href="https://bereghici.dev/blog/build-a-scalable-front-end-with-rush-monorepo-and-react--webpack+jest"><em>https://bereghici.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7f1c19c1797" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-2-d7f1c19c1797">Build a scalable front-end with Rush monorepo and React — Part 2</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Build a scalable front-end with Rush monorepo and React — Part 1]]></title>
            <link>https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-1-dd50ae38ad3e?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/dd50ae38ad3e</guid>
            <category><![CDATA[rushjs]]></category>
            <category><![CDATA[monorepo]]></category>
            <category><![CDATA[rushstack]]></category>
            <category><![CDATA[prettier]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Fri, 03 Sep 2021 08:46:41 GMT</pubDate>
            <atom:updated>2022-01-11T09:00:23.454Z</atom:updated>
            <content:encoded><![CDATA[<h3>Build a scalable front-end with Rush monorepo and React — Part 1</h3><h3>Repo Setup + Import projects + Prettier</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1023/1*ciIztKJETR7pHahGedSX5A.jpeg" /></figure><p>This is the 1st part of the blog series “Build a scalable front-end with Rush monorepo and React”</p><ul><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-1-dd50ae38ad3e">Part 1</a>: Monorepo setup, import projects with preserving git history, <br>add Prettier</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-2-d7f1c19c1797">Part 2</a>: Create build tools package with Webpack and react-scripts</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-3-b90430f15af7">Part 3</a>: Add shared ESLint configuration and use it with lint-staged</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-4-d0939bfb8b8a">Part 4</a>: Setup a deployment workflow with Github Actions and Netlify.</li><li><a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-5-355f5391fd27">Part 5</a>: Add VSCode configurations for a better development experience.</li></ul><p>In a multi-repository project structure, it’s only a matter of time when you’ll need to reuse some code from one project to another. Adopting a monorepo architecture can help the team share and simply contribute code.</p><p>I won’t cover in this article the pros and cons of choosing this approach, because there are plenty of resources that debate this topic, instead, I’ll focus on the implementation of a scalable monorepo using Rush.js and React.</p><h3>Tools</h3><p>We’ll be using the following tools:</p><ul><li><a href="https://rushjs.io/">Rush</a></li><li><a href="https://reactjs.org/">React</a></li><li><a href="https://www.typescriptlang.org/">Typescript</a></li><li><a href="https://eslint.org/">ESLint</a></li><li><a href="https://webpack.js.org/">Webpack</a></li><li><a href="https://prettier.io/">Prettier</a></li><li><a href="https://github.com/okonet/lint-staged">Lint-staged</a></li><li><a href="https://github.com/features/actions">Github Actions</a></li><li><a href="https://www.netlify.com/">Netlify</a></li></ul><h3>Goals</h3><p>Before implementing the monorepo, let’s define the goals we want to achieve using these tools:</p><ul><li>Multiple applications</li><li>Code sharing between applications</li><li>Shared tools and configurations</li><li>Enforced rules for code quality</li><li>Automated workflow for development</li></ul><h3>TL;DR</h3><p>If you’re interested in just see the code, you can find it here: <a href="https://github.com/abereghici/rush-monorepo-boilerplate">https://github.com/abereghici/rush-monorepo-boilerplate</a></p><p>If you want to see an example with Rush used in a real, large project, you can look at <a href="https://github.com/imodeljs/imodeljs">ITwin.js</a>, an open-source project developed by Bentley Systems.</p><h3>Guide</h3><h4>Create a new repository</h4><p>I assume you already created an empty Github repository for this project. <br>Let’s clone it locally and let the magic begin!</p><h4>Initialize the rush monorepo</h4><p>Inside of your project folder, run the following commands:</p><pre>npm install -g @microsoft/rush</pre><pre>rush init</pre><p>After this command, you’ll see a bunch of files and folders created. You can check the config files reference <a href="https://rushjs.io/pages/advanced/config_files/">here</a>.</p><p>At this point, we can remove unnecessary files and create our first commit.</p><pre>rm -rf .travis.yml<br><br>git add .<br>git commit -m &quot;Initial commit&quot;<br>git push origin master</pre><p>Import existing projects without losing git history</p><p>You don&#39;t really want to perform a migration to monorepo if you lose all the history of your projects. If everything will point to the commit where you merged the projects, you won&#39;t be able to revert to the previous commits, or run git blame or git bisect.</p><p>We can copy all projects inside of the monorepo and keep the git history of each project with a single git command: git subtree.</p><p>Let&#39;s suppose we want to import the following project into our monorepo <a href="https://github.com/abereghici/react-app">https://github.com/abereghici/react-app</a>. We&#39;ll do it using the command git subtree add</p><pre>git subtree add --prefix apps/react-app \<br> https://github.com/abereghici/react-app master</pre><p>Let&#39;s decode the parameters of this command:</p><ul><li>apps/react-app is used to specify the path inside of the monorepo where the project will be imported.</li><li>https://github.com/abereghici/react-app is the remote repository URL of the project we want to import.</li><li>master is the branch from where the project will be imported.</li></ul><p>Now if you run git log you&#39;ll see the history of react-app project inside of our monorepo.</p><p>Open apps/react-app/package.json and change the name of the project with @monorepo/react-app.</p><p>The last step is to register @monorepo/react-app project in rush configuration file. Open rush.json file and add an entry like this under the projects inventory:</p><pre>&quot;projects&quot;: [<br>    {<br>      &quot;packageName&quot;: &quot;@monorepo/react-app&quot;,<br>      &quot;projectFolder&quot;: &quot;apps/react-app&quot;,<br>      &quot;reviewCategory&quot;: &quot;production&quot;<br>    }<br>  ]</pre><p>This tells Rush that it should manage this project. Next, run rush update to install the dependencies of react-app project. This command can be launched in any subfolder of the repo folder that contains rush.json file.</p><pre>rush update<br>git add .<br>git commit -m &quot;Imported react-app project&quot;<br>git push origin master</pre><h4>Adding Prettier</h4><p>We want to have consistent syntax and formatting across all code files in our monorepo. So we&#39;ll apply Prettier globally for the entire repository. We&#39;ll run it during git commit.</p><p>Let&#39;s create a configuration file in the root of the repo. Prettier allows many different names for this config file, but we&#39;ll use .prettierrc.js</p><p>&lt;repo root&gt;/.prettierrc.js</p><pre>module.exports = {<br>  arrowParens: &#39;avoid&#39;,<br>  bracketSpacing: true,<br>  htmlWhitespaceSensitivity: &#39;css&#39;,<br>  insertPragma: false,<br>  jsxBracketSameLine: false,<br>  jsxSingleQuote: false,<br>  printWidth: 80,<br>  proseWrap: &#39;preserve&#39;,<br>  quoteProps: &#39;as-needed&#39;,<br>  requirePragma: false,<br>  semi: true,<br>  singleQuote: true,<br>  tabWidth: 2,<br>  trailingComma: &#39;es5&#39;,<br>  useTabs: false,<br>};</pre><p>You also need to make a .prettierignore file to tell Prettier which files to skip. It is recommended for .prettierignore to extend the same patterns used in .gitignore.</p><pre>cp .gitignore .prettierignore</pre><p>Once the configuration is set up, next we need to invoke Prettier manually to reformat all the existing source files.</p><pre><em># See what files Prettier will format</em><br><em># check the output and modify .prettierignore rules if needed</em><br>npx prettier . --list-different<br><br><em># When you are ready, this will format all the source files</em><br>npx prettier . --write</pre><p>To speed up the prettier process on git commit hook, we&#39;ll use prettier-quick to calculate the subset of files that are staged for commit and format them.</p><p>Let&#39;s create a rush auto-installer, where we&#39;ll list all dependencies for formatting.</p><pre><em># This creates the common/autoinstallers/rush-prettier/package.json file:</em><br>rush init-autoinstaller --name rush-prettier</pre><p>Install the dependencies:</p><pre>cd common/autoinstallers/rush-prettier<br><br><em># Install the dependencies.</em><br><em># You can also manually edit the &quot;dependencies&quot; in the package.json file</em><br> pnpm install prettier<br> pnpm install pretty-quick<br><br><em># update the auto-installer</em><br>rush update-autoinstaller --name rush-prettier</pre><p>Next, we will create a rush prettier custom command that invokes the pretty-quick tool. Add this to the &quot;commands&quot; section of config/rush/command-line.json file:</p><pre>. . .<br>  &quot;commands&quot;: [<br>    {<br>      &quot;name&quot;: &quot;prettier&quot;,<br>      &quot;commandKind&quot;: &quot;global&quot;,<br>      &quot;summary&quot;: &quot;Used by the pre-commit Git hook. This command invokes Prettier to reformat staged changes.&quot;,<br>      &quot;safeForSimultaneousRushProcesses&quot;: true,<br><br>      &quot;autoinstallerName&quot;: &quot;rush-prettier&quot;,<br><br>      <em>// This will invoke common/autoinstallers/rush-prettier/node_modules/.bin/pretty-quick</em><br>      &quot;shellCommand&quot;: &quot;pretty-quick --staged&quot;<br>    }<br>    . . .</pre><p>After saving these changes, let’s test our custom command by running rush prettier.</p><p>The last step is to add a Git hook that invokes rush prettier automatically whenever git commit is performed. Let&#39;s create a file called pre-commit in the common/git-hooks folder:</p><p>common/git-hooks/pre-commit</p><pre><strong>#!/bin/sh</strong><br><em># Called by &quot;git commit&quot; with no arguments.  The hook should</em><br><em># exit with non-zero status after issuing an appropriate message if</em><br><em># it wants to stop the commit.</em><br><br><em># Invoke the &quot;rush prettier&quot; custom command to reformat files whenever they</em><br><em># are committed. The command is defined in common/config/rush/command-line.json</em><br><em># and uses the &quot;rush-prettier&quot; autoinstaller.</em><br>node common/scripts/install-run-rush.js prettier || exit $?</pre><p>Install the hook by running rush install.</p><p>We&#39;re done! Now on every commit, we&#39;ll be automatically prettified.</p><p>Let&#39;s go to the <a href="https://medium.com/@alexandrubereghici/build-a-scalable-front-end-with-rush-monorepo-and-react-part-2-d7f1c19c1797">next part</a> where we&#39;ll learn how to create build tools with Webpack and jest.</p><h4>See you there!</h4><p><em>Originally published at </em><a href="https://bereghici.dev/blog/build-a-scalable-front-end-with-rush-monorepo-and-react--repo-setup+import-projects+prettier"><em>https://bereghici.dev</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dd50ae38ad3e" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/build-a-scalable-front-end-with-rush-monorepo-and-react-part-1-dd50ae38ad3e">Build a scalable front-end with Rush monorepo and React — Part 1</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[This is about useful JS tips and tricks!]]></title>
            <link>https://itnext.io/this-is-about-useful-js-tips-and-tricks-4a7ef25c33ad?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a7ef25c33ad</guid>
            <category><![CDATA[clean-code]]></category>
            <category><![CDATA[tips-and-tricks]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[es6]]></category>
            <category><![CDATA[js]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Mon, 09 Sep 2019 13:08:31 GMT</pubDate>
            <atom:updated>2019-09-11T05:49:41.285Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/785/1*H-25KB7EbSHjv70HXrdl6w.png" /></figure><blockquote>This article aims to show some tips and tricks that can be used in your code to make the it cleaner or more readable.</blockquote><h4><strong>Required function parameters</strong></h4><p><strong>Default function parameters</strong> allow named parameters to be initialized with default values if no value or undefined is passed. We can take the advantages of this ES6 feature and make a function which throws an error and assign it as default value for required parameters.</p><p>Another way to deal with <strong>required function parameters </strong>is to create a global property named required . It can be assigned as default function parameter, so if no value has been specified in the function call, the getter handler will be triggered and the error will be thrown.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*J82PW0aPSO9oe5a5rgbrZQ.png" /></figure><h4>Effective Data Validation</h4><p>At some point we need to validate our data inside methods. My favorite approach is to use assert like functions. Assert functions are a short way of instructing the program to check the condition and if the condition is not True, it will throw error.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b6ffMPykGtU7fYmrb1eG0A.png" /></figure><h4><strong>Replacing texts in a string</strong></h4><p>The String prototype method named replace includes some interesting replacement patterns:</p><ul><li>$&amp; Inserts the matched substring.</li><li>$` Inserts the portion of the string that precedes the matched substring.</li><li>$&#39; Inserts the portion of the string that follows the matched substring.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rosy2kp2Yx3hXr5SG5fSaA.png" /></figure><h4><strong>Improve the code readability with async / await syntax</strong></h4><p>Async/await is a new and an elegant way to write asynchronous code in Javascript. Usually, I’m using it with fetch .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HWkKo4re9y5MqRP1lJ3U1g.png" /></figure><p>A more concise way to write this function can be:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Kk0aJID6O28KzA3He0bPRg.png" /></figure><h4><strong>Check the code performance with performance.now()</strong></h4><p>If you have a portion of code that needs to run really fast, it can be inspected with performance.now() function. Unlike regular timestamps created with Date.now() the method performance.now() generates high resolution timestamp (<a href="https://developer.mozilla.org/en-US/docs/Web/API/DOMHighResTimeStamp">DOMHighResTimeStamp</a>) .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zzFlH3gKkP4sExC9qWJXHQ.png" /></figure><h4><strong>Conditional logging without if / else</strong></h4><p>We can use <strong><em>console.assert(condition, msg)</em></strong> to log something when the condition is falsy. If the assertion is true, nothing happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jaXAO1bjKDhjUK_-7I8qpw.png" /></figure><h4><strong>Using setTimeout() with variable parameters</strong></h4><p>setTimeout allows us to run a function once after the interval of time. Instead of wrapping our method with an anonymous function, we can pass the function parameters directly: <br><em>( not quite sure if is more readable </em>😂 <em>but good to know … )</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agJLaU7sTTDJ_fO9hhyLLw.png" /></figure><h4>Filter falsy values</h4><p>If you need to filter falsy values like (0, undefined, null, false, etc.) out of an array, you can use this trick:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wSJDTB8dvPIpaizz9TTMjA.png" /></figure><h4>Multiple conditions in an if statement</h4><p>If you have to deal with checking a large number of conditions, you can use a clean looking alternative of if and || operator which scales nicely:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*08ShqiZ7YbxVutFORnJfRA.png" /></figure><p>Or even better, using includes method:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y2vj4xXisCPMnJw0m2Q3rg.png" /></figure><h4>RegExp named capture groups</h4><p>ES2018 introduced named capture groups into JavaScript regexes. Named captured groups provide less confusion with regular expressions, it improves the readability and quality of the code, because you can find easily a group using an identifier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KbcnpemUz2ffBrC-GjTj7g.png" /></figure><p>That’s it 🤪! What are your favorite JavaScript tricks?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a7ef25c33ad" width="1" height="1" alt=""><hr><p><a href="https://itnext.io/this-is-about-useful-js-tips-and-tricks-4a7ef25c33ad">This is about useful JS tips and tricks!</a> was originally published in <a href="https://itnext.io/">ITNEXT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[React Versions — The Newest Features of React 16.6 Explained for Everyday Use]]></title>
            <link>https://medium.com/@alexandrubereghici/react-versions-the-newest-features-of-react-16-6-explained-for-everyday-use-f55c21011d7c?source=rss-8c39bf1ed014------2</link>
            <guid isPermaLink="false">https://medium.com/p/f55c21011d7c</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[reactjs]]></category>
            <dc:creator><![CDATA[Alexandru Bereghici]]></dc:creator>
            <pubDate>Thu, 18 Jul 2019 09:14:46 GMT</pubDate>
            <atom:updated>2019-07-18T10:10:53.999Z</atom:updated>
            <content:encoded><![CDATA[<h3>React Versions — The Newest Features of React 16.6 Explained for Everyday Use</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*g_4bIdBvRQwKW37iYIm50Q.png" /></figure><h3>See the original post here: <a href="https://www.pentalog.com/blog/react-versions-explained/">https://www.pentalog.com/blog/react-versions-explained/</a></h3><p>We’re living in pretty eventful times for <strong>React</strong>. Late December 2018 saw the release of version 16.7 which included an important performance bugfix for <em>“React.lazy”</em>. But, no other API (application programming interface) changes were delivered.</p><p>For that reason, I’m doing a deep dive into React version 16.6, released in October 2018, just a few days before <a href="https://reactday.berlin/">React Day</a> in Berlin.</p><p>As a developer attending a conference, I expect to get practical and technical content as well as network with other developers dealing with the same challenges as me. Fortunately for me, <a href="https://reactday.berlin/"><strong>React Day Berlin</strong></a> jam packed immersive learning and networking experience for frontend engineers working with React into a one-day event. I managed to make new friends, share knowledge and learn new things about React that I could immediately put into practice.</p><p>As I stood there, sharing the room with some of the most fascinating developers’ minds in the world I let myself be inspired and made my decision there. I can now (officially) call myself a React aficionado, eager to tinker and test out any new features. So, once they were released, I did just that — and I’m going to lay it all out for you now. The good and the bad.</p><p>React 16.6 version is a minor release with major features focused on performance optimization. The main new features are:</p><ul><li><strong>React.memo()</strong></li><li><strong>React.lazy()</strong></li><li><strong>static contextType()</strong></li><li><strong>static getDerivedStateFromError()</strong></li></ul><h3>React.memo()</h3><p>Function components are convenient when you don’t need to manage state but the lack of lifecycle methods especially shouldComponentUpdate, means that your component is always going to re-render.</p><p>Similar to React.PureComponent, React.memo() is a higher order component that allows you to skip re-renders when props doesn’t change:</p><pre>const MyComponent = React.memo(function (props) { });</pre><h3>React.lazy()</h3><p>As your application grows in functionality, the bundle size also grows in size and sometimes, being lazy is a smart choice. React.lazy() feature allows you to load your components on demand, aka lazy loading.</p><pre>import { lazy } from &#39;react&#39;;<br>const MyLazyComponent = lazy(() =&gt; import(&#39;./MyLazyComponent&#39;));</pre><p>React.lazy() can be combined with Suspense, that will display a fallback component while the dynamic component is being loaded.</p><pre>import { lazy, Suspense } from &#39;react&#39;;<br>const MyLazyComponent = lazy(() =&gt; import(&#39;./MyLazyComponent&#39;));</pre><pre>function Application() {<br>  return (<br>    &lt;Suspense fallback={&lt;div&gt;Loading…&lt;/div&gt;}&gt;<br>      &lt;MyLazyComponent /&gt;<br>    &lt;/Suspense&gt;<br>  );<br>}</pre><h3>static contextType()</h3><p>React Context allows for parent components to pass data to their children, no matter how deep the component tree is. Usually, this is the use case for using Redux or Flux, but when you don’t need complex data management, React Context is a good choice.</p><p>Starting with React 16.6 is easier to consume the context value anywhere within class components:</p><pre>class MyComponent extends React.Component {<br>  static contextType = MyContext;<br>  render() {<br>    let value = this.context;<br>    /* render something based on the context value */<br>  }<br>}</pre><p>You can reference the context in any of the lifecycle methods including the render function.</p><blockquote><em>Keep in mind, this method only allows you to consume </em><strong><em>one</em></strong><em> context.</em></blockquote><h3>static getDerivedStateFromError()</h3><p>Error boundaries were introduced in React 16.3 and allow us to catch errors in our components and prevent the application from crashing.</p><p>React 16.6 introduced a new lifecycle method called getDerivedStateFromError. This method is invoked after an error has been thrown by a descendant component. It receives the error that was thrown as a parameter and should return a value to update the state providing a method to handle the error.</p><p>componentDidCatch should be used for side-effects like logging errors.</p><pre>class ErrorBoundary extends React.Component {<br>  state = { hasError: false };</pre><pre>  static getDerivedStateFromError(error) {<br>     // Update state so the next render will show the fallback UI.<br>    return { hasError: true };<br>  }</pre><pre>  componentDidCatch(error, info) {<br>    logComponentStackToMyService(info.componentStack);<br>  }</pre><pre>  render() {<br>    if (this.state.hasError) {<br>       // You can render any custom fallback UI<br>      return &lt;h1&gt;Something went wrong.&lt;/h1&gt;;<br>    }</pre><pre>    return this.props.children; <br>  }<br>}</pre><p>If you’d like an in-depth exploration of these features, <a href="https://www.youtube.com/watch?time_continue=389&amp;v=p8v9X2TNQKA">check out this video from React Day Berlin.</a></p><h3>React Hooks</h3><p>At React Day Berlin, the coding community celebrated the introduction of an awesome feature called Hooks! Although still in its testing phase, we discussed this functionality at length.</p><p>Currently, there are some problems with the way we write React components. Our components are simple and short in the beginning, but finished with huge components — complicated logic spread around the constructor, methods and within the lifecycle methods. Another problem is the lack of states in functional components. If we want to use React features like context, states &amp; lifecycle methods we need to convert a functional component into a class component.</p><p>Hooks are designed to fix these issues by adding the option to use state, context &amp; lifecycle methods in a functional component. This means we’ll no longer be forced to create class components and we can avoid the boilerplate code we have to write when using classes. Also, React Hooks are a good alternative to reuse some logic that comes with a much easier to understand syntax and logic flow.</p><h3>So, why do I love React so much?</h3><p>As a front-end developer, I love trying new things: frameworks, libraries — anything to make my job more efficient deserves my attention. I’ve created several projects using Angular and was quite happy with it, but Angular is a full-blown framework. It takes care of everything — HTTP, code structure, application architecture, so we are forced color inside their proverbial coding lines.</p><p>In contrast, React allows freedom. It comes with a different approach and philosophy to creating front-end. I prefer solutions where I can pick and choose the libraries that best fit the requirements of my app.</p><p>I love React because of its community. There is no shortage on tutorials for how to learn using it, write components, how to route, etc.</p><p>The React ecosystem is focused on developer experience and productivity. The community has created an impressive number of tools that help everyone write better code. Redux, React Router &amp; Immutable.js are just a few examples.</p><p>My list of reasons behind choosing React for front-end can go on, but these are the main behind my choice to use this library.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f55c21011d7c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>