<?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 Mark Skelton on Medium]]></title>
        <description><![CDATA[Stories by Mark Skelton on Medium]]></description>
        <link>https://medium.com/@mskelton?source=rss-4ee41ced3916------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*smqrz852ItpNCrjxZx1Hrg.jpeg</url>
            <title>Stories by Mark Skelton on Medium</title>
            <link>https://medium.com/@mskelton?source=rss-4ee41ced3916------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 18:11:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mskelton/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[My Journey to Become a Staff Software Engineer]]></title>
            <link>https://mskelton.medium.com/my-journey-to-become-a-staff-software-engineer-23b359b0b124?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/23b359b0b124</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[careers]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Tue, 01 Feb 2022 14:23:35 GMT</pubDate>
            <atom:updated>2022-02-01T14:23:35.856Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This article was originally posted </em><a href="https://mskelton.dev/blog/my-journey-to-become-a-staff-software-engineer"><em>on my blog</em></a><em>. Check it out as well as my other articles!</em></p><p>This week, I begin my new position at <a href="https://www.widen.com/">Widen</a> as a staff software engineer with a focus on JavaScript engineering and developer experience. As I reflected on my career journey and what I learned to make it to this point, I wanted to share my journey and learnings to help other developers advance their careers and become better software engineers. In this article, I’ll outline the 9 most important lessons I learned in the last 5 years I’ve spent as a software engineer.</p><h3>TLDR</h3><ol><li>Try Things Out</li><li>Teach What You Learn</li><li>Read Documentation</li><li>Get Good at Google</li><li>Relentlessly Improve Efficiency</li><li>Chase Your Passion</li><li>Stay Humble</li><li>Embrace your team’s norms</li><li>Challenge the Status Quo</li></ol><h3>Try Things Out</h3><p>One of the best ways to learn something is just trying it out to see what you learn. So much of what I have learned is a result of experimenting with new languages and frameworks; trying new ways of architecting applications; and taking inspiration from other developers and applying it to your own projects. The key here is “trying”. You can learn so much if you give things a try, even if you decide you didn’t like it and you throw it away. I’ve started so many projects and never completed them because completing them wasn’t the point, rather I was having fun trying new approaches to problems that I’ve solved many times to see if I can find a better way.</p><h3>Read Documentation</h3><p>It often shocks me how often I see engineers asking questions or failing to understand concepts when there are so many amazing sources of documentation that clearly explain these things. You can learn so much by reading documentation, even if you aren’t looking for a specific answer to a question. In fact, this is where some of the best learnings come as you discover better ways of doing something that you may not have known were possible!</p><p>Now, I know what you are thinking, reading documentation sounds boring. That can certainly be the case, so set yourself small and attainable goals so you don’t burn out from reading too much documentation. For the past year, I’ve set a goal to read one page of documentation (or 5 minutes worth) every workday. Five minutes is such a small commitment, but you’d be surprised how much documentation you can read in a year when you do it every day!</p><h3>Get Good at Google</h3><p>This might sound silly, especially when many companies (including mine) don’t allow using Google during coding interviews, but learning how to research problems is a very important skill to becoming a more effective engineer. I frequently see junior-level developers who when faced with a problem they can’t figure out, will quickly go to a more experienced engineer to ask why their code isn’t working.</p><p>While I always encourage reaching out to more experienced developers for help, overusing those resources can do two things. First, it limits the learning potential as getting a quick answer is quickly forgotten while taking the time to research a problem is often better retained. Second, if you overload senior engineers with questions, they will eventually get frustrated that you aren’t taking the time yourself to research the issue. Senior engineers want to see junior engineers grow, and learning how to research and discover solutions is one of the foremost ways you can do this.</p><p>To be clear, I’m not suggesting that you don’t ask any questions to senior engineers, rather I’m suggesting to spend more time learning and researching on your own before you ask questions. There will always be those tough questions that you just can’t figure out, and that’s a great time to get some help from a more experienced engineer. Eventually, when you become the senior engineer, people will be asking you questions and you may no longer have a more senior engineer to lean on, so practice these skills now!</p><h3>Teach What You Learn</h3><p>As you learn and grow as a software engineer, one of the best ways to reinforce and deepen your knowledge is by teaching others what you have learned. This is not anything new that other people haven’t already figured out, but it certainly is true. When I am preparing to teach a concept, even if it is a simple Slack message to my teammates, it introduces an opportunity for me to ensure my knowledge of the subject is complete and accurate. The last thing I want to do is make and spread false claims or information, so as a result teaching becomes an opportunity to ensure my knowledge is accurate, which often brings with it new information I may not have known before.</p><p>Keep in mind, teaching doesn’t need to be a lecture in front of your whole engineering department at work. In fact, it doesn’t even have to be a speech, it can be a simple Slack message with a new tip you learned or a mention of a more efficient process on a Zoom call. These methods of teaching require far less preparation while still resulting in deepening your knowledge and helping your coworkers to also improve their skills.</p><h3>Relentlessly Improve Efficiency</h3><p>As you advance to higher levels of software engineering, you will solve more complex problems that require more time and mental energy. As you do, you will be limited by two factors: how quickly you can develop solutions to these problems and how quickly you can implement these solutions. Improving the efficiency of developing solutions generally comes with time and experience making it more difficult to artificially speed up, but the opposite is true of improving the efficiency of implementing solutions.</p><p>While certainly not the only factor in efficiency, how you type and your typing speed are important factors to efficiency. While software engineers do not simply type for 8 hours straight every day, we do type a lot, so improving your typing skills will have a positive impact on your overall efficiency. Not only that, but if you improve not only your typing speed but also your typing method you will find yourself wasting less mental energy thinking about typing, and instead you can use that energy to think about the problem you are trying to solve.</p><p>There are so many other ways to improve efficiency, but rather than making this section huge, here are some of my top tips.</p><ul><li>Learn keyboard shortcuts to reduce time wasted moving between your mouse and keyboard.</li><li>Prefer CLIs over GUIs. While GUIs are nicer to look at and use, CLIs are often more efficient. For example, with some configuration, I can manage my Git repositories far quicker via the command line than I can via VS Code’s built-in Git client.</li><li>Automate as much as you can. Setup a GitHub action to automatically update dependencies every other week, create lint rules to enforce coding standards, or create recurring reminders of common tasks. Anything you can do to reduce what you have to remember and do will improve your efficiency.</li><li>For macOS users, replace Spotlight with <a href="https://www.raycast.com/">Raycast</a> or <a href="https://www.alfredapp.com/">Alfred</a> which both provide more functionality and offer means of customizing with extensions or workflows to automate common tasks.</li></ul><h3>Chase Your Passion</h3><p>The world of software engineering is vast and varied. You can dive into low-level programming with Rust and C, data science with Python and R, web application development with JavaScript and TypeScript, and so many more areas. Due to the wide breadth of the space, it is not feasible to truly excel in every area and so it is important to specialize in a subset of the overall field based on what you are passionate about. For me, that is web JavaScript engineering and developer experience, but what is it for you?</p><p>As you grow, explore different areas to find where your passion lies so you can hone your skills and find more enjoyment in what you do every day. Don’t just pick the most loved language on the StackOverflow annual survey or the language that pays the most, find what you love doing, and do that. If possible, use time outside of work to build side projects either to explore new technologies or deepen your knowledge of existing technologies you use.</p><h3>Stay Humble</h3><p>The more experience you get as a software engineer, the easier it will become to be prideful of your knowledge, position, experience, salary, you name it. Fight this and stay humble. Pride will not only cause you to lose respect from your coworkers, which is vitally important as a senior engineer and a leader, but it will also stunt your continued growth and learning. If you think you have it all figured out and know everything you need to know, you will stop learning and stagnate at your current level of knowledge. However, if you remain humble, and remember that not only do you have much to learn but also that every one of your coworkers, regardless of seniority, can teach you something, you will unlock the door to continued growth and learning.</p><h3>Embrace Your Team’s Norms</h3><p>Since starting at Widen 3 years ago, I have moved around to different teams quite a bit. During some of the earlier transitions, I had a tendency to come to the team making all sorts of suggestions based on “what I did on my other team” or “what I did at my last job”. While suggestions like this are not necessarily bad, they make it significantly more difficult to build respect with your team as they see your suggestions as a challenge to how they work, what they have built, etc. This can cause others on the team to quickly become defensive rather than being open to your ideas.</p><p>What I’ve found to be much more effective is to embrace the norms of a team when joining them. This allows you to more easily see why they do what they do including the benefits of their process and approaches. As you embrace your team’s norms, you will gain their respect far quicker which in turn will give you the ability to suggest improvements that will likely be taken much better by your team. Not only that, but often you will find that some of the things that were so important when you first joined might not be as important as you think after spending a little time on your new team.</p><h3>Challenge the Status Quo</h3><p>The final lesson I’ll share in this article is to challenge the status quo. Being a highly effective software engineer involves challenging processes and decisions rather than blindly following the direction set by others. While this may sound contrary to my last point and very rebellious, when done properly, it can have a great positive impact. The key is knowing what to challenge. For example, at my work, UX decisions are something I often challenge. Asking why a design was created the way it was, suggesting simpler alternatives, or explaining technical reasons why a design should be reviewed. Be careful though, as your goal should not be to challenge for the sake of challenge, rather your goal should be to make the best possible software for your customers. If you are careful in how you challenge the status quo, you will likely find that others on your team appreciate your challenges and feedback.</p><p>Thanks for reading! I hope you have found this article helpful and if you have any comments, feel free to share them with me on Twitter or GitHub!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=23b359b0b124" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating and Using Yarn Constraints]]></title>
            <link>https://medium.com/swlh/creating-and-using-yarn-constraints-2464ba46482a?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/2464ba46482a</guid>
            <category><![CDATA[yarn]]></category>
            <category><![CDATA[yarn-workspace]]></category>
            <category><![CDATA[constraints]]></category>
            <category><![CDATA[yarn-package-manager]]></category>
            <category><![CDATA[monorepo]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Sun, 06 Dec 2020 22:24:40 GMT</pubDate>
            <atom:updated>2022-02-18T13:24:03.459Z</atom:updated>
            <content:encoded><![CDATA[<h3>Using Yarn Constraints</h3><h4>How to create and use Yarn constraints for managing your monorepos</h4><figure><img alt="Yarn package manager logo" src="https://cdn-images-1.medium.com/max/1024/1*m6zlwvyKm9BPeFQCKvGQEQ.png" /></figure><p><em>This article was originally posted </em><a href="https://mskelton.dev/blog/using-yarn-constraints"><em>on my blog</em></a><em>. Check it out as well as my other articles!</em></p><p>Yarn 2 (aka berry) introduced a new feature referred to as “constraints” which allow developers to enforce rules for dependencies or manifest fields for some or all workspaces in a project. While constraints are still experimental and community examples of using them are a bit sparse, they are a very powerful tool to help you more easily manage your project.</p><h3>What Are Yarn Constraints?</h3><p>As previously mentioned, <a href="https://yarnpkg.com/features/constraints">Yarn constraints</a> allow you to enforce rules for your dependencies or manifest fields in your project. While they could be used for a project with a single workspace, their value comes in when used on projects with multiple workspaces such as a component library. Constraints are written in Prolog which, although it has a learning curve, allows writing powerful rules in just a few short lines.</p><h3>Let’s See An Example</h3><p>Alright, let’s get down to business and look at an example of a constraint. For the rest of this article, let’s assume that we are working on an open-source component library containing 10 packages. This would thus have 11 total “workspaces” as each package is a workspace plus the root workspace which contains the workspaces key in the package.json file.</p><p>Since our example project is open source, we want to make sure all of our packages have a license field in their manifest files (package.json). This would look something like this.</p><pre>// constraints.pro<br>gen_enforced_field(WorkspaceCwd, &#39;license&#39;, &#39;ISC&#39;).</pre><p><em>All the examples in this article can be viewed on the </em><a href="https://github.com/mskelton/yarn-constraints-example"><em>accompanying GitHub repo</em></a><em> I created for this article.</em></p><p>This will instruct Yarn that we want to enforce a constraint on all of our workspaces (including the root) where each workspace should contain a license field with the value of ISC. We can check to see if our constraints are met by running the yarn constraints command.</p><pre>$ yarn constraints<br>➤ YN0037: package-a must have a field license set to &quot;ISC&quot;, but doesn&#39;t<br>➤ YN0038: package-b must have a field license set to &quot;ISC&quot;, but is set to &quot;MIT&quot; instead<br>➤ YN0000: Failed with errors in 0s 29ms</pre><p>As you can see from the output, Yarn warned us that package-a does not have a license field in it’s manifest and package-b has an incorrect value for the license field. To fix these issues, we can add the --fix argument to the command which will instruct Yarn to fix the issues for us if possible.</p><pre>$ yarn constraints --fix<br>➤ YN0000: Done in 0s 43ms</pre><p>The errors are now gone, and if we look at the changed files in Git, we will see that the manifest file for package-a and package-b have been updated.</p><p>Now that we’ve seen what Yarn constraints look like and how to check/fix them, let’s look at a number of real world use cases where you might want to use constraints to enforce rules for your workspaces.</p><h3>Use Case: Enforce Homepage URL</h3><p>Continuing with our hypothetical component library, we probably want to include a homepage field in the manifest of each workspace so that users can use the npm docs command to open the readme for each of our packages. This constraint isn’t quite as simple as the last since the homepage of each workspace will be different.</p><p>When writing more complex constraints like this, I like to start with a basic constraint and then add the complexity bit by bit. So, I’ll start with something similar to our license constraint.</p><pre>gen_enforced_field(WorkspaceCwd, &#39;homepage&#39;, &#39;something&#39;).</pre><p>Okay, good start. Now I have a constraint that will add a homepage field to each workspace. There are two problems that I’ll need to address:</p><ol><li>This constraint will also be enforced for the root workspace which we don’t want.</li><li>The homepage URL isn’t correct.</li></ol><p>Let’s start with the first issue. We need to instruct Yarn not to enforce the constraint for the root workspace. There are a number of ways you could do this, but the approach I like to take looks something like this.</p><pre>gen_enforced_field(WorkspaceCwd, &#39;homepage&#39;, &#39;something&#39;) :-<br>  workspace_field(WorkspaceCwd, &#39;version&#39;, _).</pre><h4>Aside about syntax</h4><p>Before I explain the code block above, I should pause for a moment to explain some of the syntax in the previous code block and the mental model you should use when reading and writing Yarn constraints.</p><p>In Prolog, we use “rules” to create conditional statements that will either be true or false. Rules contain a “head” section, and a “body” section where the head will be true if the body is true. For example, the following rule would be read as “X is a mortal if X is human” with mortal(X) as the “head” and human(X) as the “body”.</p><pre>mortal(X) :- human(X).</pre><p>When writing Yarn constraints, we create rules which when true instruct Yarn to enforce the constraint for the given workspace. This does not necessarily mean that the constraint is met, simply that Yarn should enforce it when we run yarn constraints. This point is important to remember.</p><blockquote><em>The rules we create don’t indicate whether constraint has been </em><strong><em>met</em></strong><em>, rather it indicates that the constraint should be </em><strong><em>enforced</em></strong><em>.</em></blockquote><p>The last thing to note about Prolog syntax is that rules without a body are always true. Prolog calls these rules “facts” and our previous example of enforcing the license field is an example of a fact. Facts are just syntactic sugar meaning that the following two lines give the same result.</p><pre>gen_enforced_field(WorkspaceCwd, &#39;license&#39;, &#39;ISC&#39;) :- true.<br>gen_enforced_field(WorkspaceCwd, &#39;license&#39;, &#39;ISC&#39;).</pre><h4>Enough syntax, back to work</h4><p>Okay, back to our homepage constraint example. We left off with the following block of code, but I didn’t explain why I added the workspace_field portion to the body of the rule.</p><pre>gen_enforced_field(WorkspaceCwd, &#39;homepage&#39;, &#39;something&#39;) :-<br>  workspace_field(WorkspaceCwd, &#39;version&#39;, _).</pre><p>This change resolved the first of the two issues where the constraint was being enforced for the root workspace. By using the workspace_field rule provided by Yarn, our rule will now return true for all workspaces whose manifest has a version property set to any value (underscores in Prolog indicate any value). Since our root workspace does not have a version property in its manifest, the constraint will not be enforced.</p><p>Next, we need to set the correct homepage URL and to do that, we can change our constraint to the following.</p><pre>gen_enforced_field(WorkspaceCwd, &#39;homepage&#39;, Homepage) :-<br>  workspace_field(WorkspaceCwd, &#39;version&#39;, _),<br>  atom_concat(&#39;https://github.com/mskelton/yarn-constraints-example/tree/main/&#39;, WorkspaceCwd, Homepage).</pre><p>To get the correct homepage URL for each workspace, we use Prolog’s built-in atom_concat predicate to concatenate the GitHub URL and the workspace directory into a variable called Homepage. We then can use this variable as the third argument to gen_enforced_field so Yarn will enforce the correct homepage URL in each workspace. If we check our constraints, we will likely see something like this.</p><pre>$ yarn constraints<br>➤ YN0037: package-a must have a field homepage set to &quot;<a href="https://github.com/mskelton/yarn-constraints-example/tree/main/packages/package-b">https://github.com/mskelton/yarn-constraints-example/tree/main/packages/package-a</a>&quot;, but doesn&#39;t<br>➤ YN0037: package-b must have a field homepage set to &quot;<a href="https://github.com/mskelton/yarn-constraints-example/tree/main/packages/package-b">https://github.com/mskelton/yarn-constraints-example/tree/main/packages/package-b</a>&quot;, but doesn&#39;t<br>➤ YN0000: Failed with errors in 0s 22ms</pre><p><em>This constraint is also auto-fixable when you run </em><em>yarn constraints --fix.</em></p><h3>Use Case: Ensuring a Dependency Is a Peer Dependency</h3><p>So, we’ve been using the example of a component library to demonstrate constraints, so let’s extend the example to say that we are building a React component library. When building React component packages, the react dependency should be a peer dependency, not a regular dependency. This is a perfect opportunity to add a constraint to enforce this rule in all of our packages. This constraint would look like this.</p><pre>gen_enforced_dependency(WorkspaceCwd, &#39;react&#39;, null, dependencies) :-<br>  workspace_field(WorkspaceCwd, &#39;version&#39;, _).</pre><p>As you can see, instead of creating a gen_enforced_field rule, we are creating a gen_enforced_dependency rule. Similar to our previous rules, we only want to run this for published packages, so we ignore the root workspace using our version check trick. For the workspaces where we enforce this constraint, Yarn will ensure the react is not present in the dependencies block of the manifest. If it is, we will get the following error.</p><pre>$ yarn constraints<br>➤ YN0025: package-a has an extraneous dependency on react (in dependencies)<br>➤ YN0000: Failed with errors in 0s 20ms</pre><p>As we can see in the message, our newly created constraint prevents us from using react as a regular dependency.</p><h3>Wrapping It Up</h3><p>That was a lot for a single article! I hope this article has helped you to understand what constraints are, when you might want to use them, and how to build them. There is definitely a learning curve to constraints, but my best advice is to just try it out for a while and see what you come up with! Whether you pull inspiration from the constraints I wrote here or come up with your own ideas of what constraints to create, I encourage you to give constraints a try on one of your projects.</p><p><em>Goodbye and God bless!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2464ba46482a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/creating-and-using-yarn-constraints-2464ba46482a">Creating and Using Yarn Constraints</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automating npm Package Releases]]></title>
            <link>https://mskelton.medium.com/automating-npm-package-releases-7593596d06dc?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/7593596d06dc</guid>
            <category><![CDATA[semantic-release]]></category>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[github-actions]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Mon, 25 May 2020 21:19:34 GMT</pubDate>
            <atom:updated>2022-02-18T13:25:05.847Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to setup semantic-release with GitHub Actions</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dW-X2A55qtzVLXe2" /><figcaption>Photo by <a href="https://unsplash.com/@pinjasaur?utm_source=medium&amp;utm_medium=referral">Paul Esch-Laurent</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article was originally posted <a href="https://mskelton.dev/blog/automating-npm-package-releases">on my blog</a>. Check it out as well as my other articles!</p><p>semantic-release is a tool which fully automates the process of releasing your code to the world. It determines the next version based on the commit messages (e.g. fix, feat) giving you full control over the next version but still automating the release process. This short article shows how to setup semantic-release for an npm package using GitHub Actions.</p><p>First, create a GitHub Action which calls npx semantic-release (or yarn semantic-release if you use Yarn). This should be run after any other pre-release steps such as npm run build and npm test.</p><pre>name: Release<br>on: [push]<br>jobs:<br>  release:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v2<br>      - run: npm ci<br>      - run: npx semantic-release<br>        env:<br>          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}<br>          NPM_TOKEN: ${{ secrets.NPM_TOKEN }}</pre><p>Next, update your package changelog to indicate that change notes can be viewed on the releases tab.</p><pre># Changelog</pre><pre>The changelog is automatically updated using [semantic-release](<a href="https://github.com/semantic-release/semantic-release">https://github.com/semantic-release/semantic-release</a>). You can see it on the [releases page](../../releases).</pre><p>Finally, update the version in your package.json to something that indicates your package is versioned using semantic release.</p><pre>&quot;version&quot;: &quot;0.0.0-semantically-released&quot;</pre><p>That’s it! Your package is now being automatically released via semantic-release!</p><p><em>For more details, checkout the </em><a href="https://github.com/semantic-release/semantic-release/blob/master/docs/recipes/github-actions.md#using-semantic-release-with-github-actions"><em>semantic-release docs</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7593596d06dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Auto Formatting Code Using Prettier and GitHub Actions]]></title>
            <link>https://mskelton.medium.com/auto-formatting-code-using-prettier-and-github-actions-ed458f58b7df?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/ed458f58b7df</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[code-style]]></category>
            <category><![CDATA[prettier]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Sat, 11 Apr 2020 15:43:55 GMT</pubDate>
            <atom:updated>2022-02-18T13:25:20.025Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="Prettier and GitHub Actions logos" src="https://cdn-images-1.medium.com/max/1024/1*C3iyFIPbMBajNUzBWhF20w.png" /></figure><p>This article was originally posted <a href="https://mskelton.dev/blog/auto-formatting-code-using-prettier-and-github-actions">on my blog</a>. Check it out as well as my other articles!</p><p>Prettier is a very popular code formatter which uses very opinionated but sensible styles to format your code and prevent the ongoing debates about code styles. When implementing Prettier into a project, the typical approach is to setup a pre-commit hook using a tool such as <a href="https://github.com/okonet/lint-staged">lint-staged</a> which will run Prettier on your staged files prior to committing. While this works well in most cases, there are a number of challenges with this approach.</p><ol><li>Non-staged files are not formatted. When changes are made to Prettier configuration or Prettier is updated, untouched files will not be formatted unless you manually run Prettier.</li><li>Pre-commit steps can be skipped. Running git commit --no-verify will commit code without running pre-commit hooks which can result in files not being formatted.</li><li>Pre-commit steps are slow. Running tasks like Prettier during pre-commit adds additional time when committing files due to Prettier having to format each file that is staged.</li></ol><h3>Finding a Better Way</h3><figure><img alt="Stone path through a valley looking towards beautiful mountains." src="https://cdn-images-1.medium.com/max/1024/0*ks0v3Fydw7kgUpXE" /><figcaption>Photo by <a href="https://unsplash.com/@lili_popper?utm_source=medium&amp;utm_medium=referral">Lili Popper</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Recently, a few of my coworkers implemented a tool called <a href="https://github.com/diffplug/spotless">Spotless</a> into a number of projects to automatically format Java code in our CI pipeline. I was quite intrigued by the concept of automatically formatting code in CI that I pondered if a similar process could be done using Prettier and GitHub Actions for JavaScript projects. <em>Spoiler alert, it works!</em></p><p>After a few Google searches, I came across <a href="https://github.com/creyD/prettier_action">GitHub Prettier Action</a> which formats your code using Prettier and commits any changes files when finished. While this looked like it would be the solution, it doesn’t use the version of Prettier specified in your dependencies meaning that local formatting changes applied by your editor or by running Prettier manually could get changed by the CI build if the versions differed. While this could be resolved by always keeping the version of Prettier in your npm dependencies and the GitHub action in sync, this adds extra work that needs to be done when updating dependencies.</p><p>So, while the Prettier Action is not the best solution, there is another solution that is just as easy to implement! This solution utilizes the <a href="https://github.com/stefanzweifel/git-auto-commit-action">git-auto-commit-action</a> alongside whatever formatting script you have in your repository. For example, my repository has the following script to format using Prettier.</p><pre>&quot;format&quot;: &quot;prettier --write .&quot;</pre><p>To setup the GitHub action, all we need to do is install our dependencies (e.g. npm ci), run our format script (e.g. npm run format), and then commit any changes if necessary.</p><pre>name: Format<br>on:<br>  pull_request:<br>    branches: [main]<br>jobs:<br>  format:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@v2<br>        with:<br>          ref: ${{ github.head_ref }}<br>      - uses: actions/setup-node@v2<br>        with:<br>          node-version: &quot;14.x&quot;<br>      - run: npm ci<br>      - run: npm run format<br>      - name: Commit changes<br>        uses: stefanzweifel/git-auto-commit-action@v4<br>        with:<br>          commit_message: Apply formatting changes<br>          branch: ${{ github.head_ref }}</pre><h3>Conclusion</h3><p>By utilizing GitHub Actions for automatically formatting with Prettier, we were able to eliminate all three issues described at the beginning of this article. While the example I showed only performed formatting with Prettier, you could also run ESLint, stylelint, or any other formatting tool you use as part of the GitHub action!</p><p>If you are interested in the source code for this post, check out the example repository I put together using the link below. God bless and happy coding!</p><p><a href="https://github.com/mskelton/prettier-formatting-example">mskelton/prettier-formatting-example</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ed458f58b7df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Conquering Derived State]]></title>
            <link>https://levelup.gitconnected.com/conquering-derived-state-57087036b230?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/57087036b230</guid>
            <category><![CDATA[derived-state]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[state-management]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Fri, 03 Apr 2020 13:17:07 GMT</pubDate>
            <atom:updated>2022-02-18T13:25:49.847Z</atom:updated>
            <content:encoded><![CDATA[<h4>How to recognize and replace derived state in your React components</h4><figure><img alt="The hilt of a decorated sword sticking out of the ground." src="https://cdn-images-1.medium.com/max/1024/0*ZGNagmTNsfoKpQET" /><figcaption>Photo by <a href="https://unsplash.com/@mavrick?utm_source=medium&amp;utm_medium=referral">Ricardo Cruz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article was originally posted <a href="https://mskelton.dev/blog/conquering-derived-state">on my blog</a>. Check it out as well as my other articles!</p><p>A couple weeks ago, my fellow front-end developers at Widen had a conversation regarding one of our shared React components which we were struggling to implement in one of our applications. While most React components are fully controlled (via props) or fully uncontrolled (internal state), this component used what is known as “derived state” which is internal state that is controlled to some degree by props. Although derived state might seem like a good solution, it often causes many more problems than it attempts to solve.</p><p>My goal in this article is not to convince you that derived state should be avoided. React has an excellent <a href="https://reactjs.org/blog/2018/06/07/you-probably-dont-need-derived-state.html">blog post on derived state</a> which does a great job of explaining why derived state is an anti-pattern. The focus of this article will be about how to recognize derived state in your components and several alternatives to derived state.</p><h3>Recognizing Derived State</h3><figure><img alt="Magnifying glass held slightly above a laptop keyboard." src="https://cdn-images-1.medium.com/max/1024/0*n4qYLnca_ckHysdj" /><figcaption>Photo by <a href="https://unsplash.com/@olloweb?utm_source=medium&amp;utm_medium=referral">Agence Olloweb</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Before I go any further, let me provide a few examples of derived state to help you start recognizing derived state patterns. I’ll begin with class based components as they are easier to recognize than function based components.</p><pre>class PartiallyControlledInput extends React.Component {<br>  state = {<br>    value: this.props.value,<br>  };</pre><pre>  componentWillReceiveProps(nextProps) {<br>    if (nextProps.value !== this.props.value) {<br>      this.setState({ value: nextProps.value });<br>    }<br>  }</pre><pre>  render() {<br>    return (<br>      &lt;input<br>        onChange={(e) =&gt; this.setState({ value: e.target.value })}<br>        value={this.state.value}<br>      /&gt;<br>    );<br>  }<br>}</pre><p>In this example, we have a component which is a partially controlled input field. The component manages its state internally but it also allows the parent component to update the state by changing the value prop. The key part of this example is componentWillReceiveProps which is the red flag indicating the component derives its state from props.</p><p>Because componentWillReceiveProps is being deprecated, React has a newer lifecycle method named getDerivedStateFromProps. This method almost needs no example as its name speaks for itself, but a quick example won’t hurt.</p><pre>class PartiallyControlledInput extends React.Component {<br>  state = {<br>    value: this.props.value,<br>    prevFormId: this.props.formId,<br>  };</pre><pre>  static getDerivedStateFromProps(props, state) {<br>    if (props.formId !== state.prevFormId) {<br>      return {<br>        prevFormId: props.formId,<br>        value: props.value,<br>      };<br>    }</pre><pre>    return null;<br>  }</pre><pre>  render() {<br>    return (<br>      &lt;input<br>        onChange={(e) =&gt; this.setState({ value: e.target.value })}<br>        value={this.state.value}<br>      /&gt;<br>    );<br>  }<br>}</pre><p>As you can see, getDerivedStateFromProps gets even more complex as we are required to store a prop value in state so when that prop changes we can reset state based on props.</p><p>As we move on to function based components, derived state is a bit tougher to spot as you have to look for more than just componentWillReceiveProps or getDerivedStateFromProps.</p><pre>function PartiallyControlledInput(props) {<br>  const [value, setValue] = useState(props.value);</pre><pre>  useEffect(() =&gt; {<br>    setValue(props.value)<br>  }, [props.value])</pre><pre>  return (<br>    &lt;input<br>      onChange={(e) =&gt; setValue(e.target.value)}<br>      value={value}<br>    /&gt;<br>  );<br>}</pre><p>As you can see, the previous example is a more subtle use of derived state. When props.value changes, an effect will run which will set the value of the input with the new prop value. This is essentially the same as the first example we showed above and suffers from the exact same problems. Just because it is written with hooks doesn’t mean it is magically better than its class based equivalent!</p><h3>Alternatives to Derived State</h3><figure><img alt="Post with four signs pointed in different directions." src="https://cdn-images-1.medium.com/max/1024/0*hWj0pElVxnhsMKev" /><figcaption>Photo by <a href="https://unsplash.com/@soymeraki?utm_source=medium&amp;utm_medium=referral">Javier Allegue Barros</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Now that we’ve seen a few examples of derived state, let’s look at some alternative solutions.</p><h4>Fully uncontrolled component with a key</h4><p>The first option would be to make the component fully uncontrolled and use React’s special key prop which will create a new instance of the component rather than updating the existing one. This includes re-initializing component state with the initial values provided.</p><pre>function FullyUncontrolledInput({ initialValue }) {<br>  const [value, setValue] = useState(initialValue);</pre><pre>  return (<br>    &lt;input<br>      onChange={(e) =&gt; setValue(e.target.value)}<br>      value={value}<br>    /&gt;<br>  );<br>}</pre><p>To use the component, we simply need to provide an initialValue prop as well as a key prop. To re-initialize the internal state of the input, we simply need to change the key. In the following code block, we use a variable named formId which we can change when the form needs to be reset.</p><pre>function Form() {<br>  return (<br>    &lt;FullyUncontrolledInput key={formId} initialValue=&quot;Initial&quot; /&gt;<br>  )<br>}</pre><h4>Fully controlled component</h4><p>The next option is to make the input fully controlled and let the parent component manage its state. This option will require us to add an onChange prop to the input component so the parent can listen to changes and update state accordingly.</p><pre>function FullyControlledInput({ value, onChange }) {<br>  return (<br>    &lt;input<br>      onChange={(e) =&gt; onChange(e.target.value)}<br>      value={value}<br>    /&gt;<br>  );<br>}</pre><p>With our fully controlled input component, we now can add a simple useState hook to our form component which will manage the state of our input.</p><pre>function Form() {<br>  const [value, setValue] = useState(&quot;Initial&quot;);</pre><pre>  return (<br>    &lt;FullyControlledInput onChange={setValue} value={value} /&gt;<br>  );<br>}</pre><h4>Custom hooks!</h4><p>While the previous examples sound like easy solutions, many real-world components are much more complex than those simple examples. In these situations, creating a custom hook might just be what you need to achieve a high level of customization without large boilerplate.</p><p>For example, consider a date picker component which accepts props for the currently selected day and month as well as event handlers when the user changes the day or month. Rather than making our form component manage all the state and event handlers, we can wrap that logic in a custom useDatePicker hook!</p><pre>function useDatePicker(initialValues = { day: 1, month: &quot;Jan&quot; }) {<br>  const [month, setMonth] = useState(initialValues.month);<br>  const [day, setDay] = useState(initialValues.day);</pre><pre>  return {<br>    datePickerProps: {<br>      day,<br>      month,<br>      onDayChange: setDay,<br>      onMonthChange: setMonth,<br>    },<br>    day,<br>    month,<br>    setDay,<br>    setMonth,<br>  };<br>}</pre><p>Now, we can very easily call the useDatePicker hook inside our form component and pass datePickerProps to the date picker component which will add all the necessary props for managing the state of the component.</p><pre>function Form() {<br>  const { datePickerProps, day, month } = useDatePicker();</pre><pre>  useEffect(() =&gt; {<br>    // Do something when day or month changes<br>  }, [day, month]);</pre><pre>  return &lt;DatePicker {...datePickerProps} theme=&quot;dark&quot; /&gt;;<br>}</pre><p>Because the hook isn’t directly tied to the component, we can achieve a high level of customization. For example, if we want to trigger some side effect when the day changes, we can simply add a useEffect hook with a dependency on the day variable. Or, if we needed to customize the onDayChange logic, we could override the prop returned in datePickerProps with a custom onDayChange prop. We could even create a reset button in the form component which when clicked uses the setDay and setMonth functions to reset the date picker to the current day. The possibilities are endless, so use your imagination and come up with something great!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57087036b230" width="1" height="1" alt=""><hr><p><a href="https://levelup.gitconnected.com/conquering-derived-state-57087036b230">Conquering Derived State</a> was originally published in <a href="https://levelup.gitconnected.com/">Level Up Coding</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Dangers of Shallow Rendering]]></title>
            <link>https://mskelton.medium.com/the-dangers-of-shallow-rendering-343e48fe5f28?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/343e48fe5f28</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Sun, 22 Mar 2020 03:51:31 GMT</pubDate>
            <atom:updated>2022-02-18T13:26:20.926Z</atom:updated>
            <content:encoded><![CDATA[<h4>Three reasons why you should avoid shallow rendering when writing JavaScript component tests</h4><figure><img alt="Sign reading “danger no entry”." src="https://cdn-images-1.medium.com/max/1024/0*KWVQ9grLjrX1mqDc" /><figcaption>Photo by <a href="https://unsplash.com/@bailey_i?utm_source=medium&amp;utm_medium=referral">Issy Bailey</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article was originally posted <a href="https://mskelton.medium.com/the-dangers-of-shallow-rendering-343e48fe5f28">on my blog</a>. Check it out as well as my other articles!</p><p>In my article titled “<a href="https://medium.com/swlh/a-tale-of-two-ideas-cea3e43121e">A Tale of Two Ideas</a>” I discussed my method for discerning between opposing ideas and used the topic of shallow rendering as an example of a topic which has very distinct and differing opinions. Although I did not tell my opinion in the article as I didn’t want to taint the purpose of the article, I did promise to publish an article with my opinions at a later point. And now, that time has come!</p><h3>TLDR</h3><p>Rather than making you scroll all the way to the end to see my list of reasons, they are listed succinctly in the following list. If you don’t like what you see, you won’t be forced to read any more. 🙂</p><ol><li>Shallow rendering creates additional failure points.</li><li>Shallow rendering decreases confidence.</li><li>Shallow rendering complicates refactoring.</li></ol><p><em>If you’re interested in the original article, check it out using the link below!</em></p><p><a href="https://medium.com/swlh/a-tale-of-two-ideas-cea3e43121e">A Tale of Two Ideas</a></p><h3>Shallow Rendering Creates Additional Failure Points</h3><figure><img alt="A blue and white plate shattered on a concrete floor." src="https://cdn-images-1.medium.com/max/1024/0*eym78taXPTzGHwhQ" /><figcaption>Photo by <a href="https://unsplash.com/@chuttersnap?utm_source=medium&amp;utm_medium=referral">chuttersnap</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>What is the purpose of shallow rendering in the first place? According to the <a href="https://enzymejs.github.io/enzyme/docs/api/shallow.html">Enzyme docs</a>,</p><blockquote>Shallow rendering is useful to constrain yourself to testing a component as a unit, and to ensure that your tests aren’t indirectly asserting on behavior of child components.</blockquote><p>To a developer with a component driven design mindset, this sounds great since you can build your components and tests together and have confidence that your components work as expected. However, the fundamental flaw with this idea is that components which work in isolation might be integrated together incorrectly resulting in unexpected user behavior. To fix this, you are required to write additional integration tests to verify that you have integrated your components correctly. This not only increases the number of tests you must maintain, but it also overcomplicates what can be very simple testing.</p><p>A simple way to reduce additional failure points when testing is to move your tests up the component tree and test larger pieces of your application. For example, if you have a component with two child components and each of those three components has a separate set of tests, reduce it to a single set of tests using the highest level component. In addition to testing the components, this will verify that your components are properly integrated removing that additional point of failure.</p><h3>Shallow Rendering Decreases Confidence</h3><figure><img alt="A very long bridge over a valley between two mountains." src="https://cdn-images-1.medium.com/max/1024/0*UipaQMVWTwFRyydB" /><figcaption>Photo by <a href="https://unsplash.com/@mostly_brave?utm_source=medium&amp;utm_medium=referral">Jonathan Klok</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>When developing web applications, the end result is some form of user value. Whether that is a visual or functional improvement, every change that is made should either directly provide user value or remove barriers to creating user value (e.g. refactoring to enable faster iteration). Tests fit in the second category as they provide confidence that new features or changes provide the expected user value and do not cause regressions in existing user value.</p><p>So, if the goal of testing is to increase confidence that your code provides the user value it is supposed to, you should write tests that provide the highest level of confidence possible. This is where shallow rendering really breaks down. Shallow rendering might give high confidence that a single component is working correctly, but it gives little to no confidence that it results in the correct user behavior.</p><p>It is also important to mention that increased confidence doesn’t necessarily result in less time spent writing tests. Before you panic, that’s okay! The most likely outcome of increased confidence is better testing coverage. Since you won’t spend as much time fixing false positives/negatives, you will have more time to test known edge cases and perform exploratory testing to find other edge cases.</p><h3>Shallow Rendering Complicates Refactoring</h3><figure><img alt="Orange colored neon sign with the word “change”." src="https://cdn-images-1.medium.com/max/1024/0*IIENL5xGO5_mK0Zr" /><figcaption>Photo by <a href="https://unsplash.com/@rossf?utm_source=medium&amp;utm_medium=referral">Ross Findon</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Refactoring is a necessary part of software development and often occurs many times during the lifetime of an application. When refactoring code, you should be able to lean heavily on your test suite to verify that your changes did not cause regressions in your applications. However, shallow rendering complicates this due to its tight coupling of components and tests. To understand this better, let me give an example.</p><p>Consider a React component named UserDetails which displays user information (i.e. name, email, phone number) in a list. The phone number is passed to a separate component named FormattedPhone. During initial development of the component, I added a test that verifies the UserDetails component renders a FormattedPhone component with the correct props. Later, I decide to remove the FormattedPhone component and format the phone in the UserDetails component. Since I used shallow rendering, my test breaks since it was expecting to find a FormattedPhone component. Not only do the tests now require changes, but they don’t give me confidence that the changes to the components maintained the expected user behavior.</p><h3>A Better Way</h3><p>If you are convinced that shallow rendering is not a good testing practice, the next big question is what to do instead? While there are many ways to answer this question, my current thoughts are best described with the following recommendations:</p><ol><li>Replace shallow rendering with full DOM rendering. If you use Enzyme, this means replacing shallow with mount.</li><li>Think less about props/state and more about user behavior. Rather than directly interacting with your components props, instead try rendering additional DOM elements which you can interact with which in turn affect your component. This is more similar to a real application where user interaction affects your component.</li><li>Never under any circumstance use APIs which allow you to directly affect component state (e.g. Enzyme’s setState method). This does not accurately reflect user behavior. Directly modifying props is also not ideal, but it is less problematic than directly modifying state.</li><li>Try out <a href="https://testing-library.com/docs/react-testing-library/intro">React Testing Library</a> which does not support shallow rendering and has an API which prevents many common testing patterns which test implementation detail. Although not required to write good tests, I have found it very helpful in increasing the quality of my tests and the confidence they provide.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=343e48fe5f28" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Customizing npmjs.com styles]]></title>
            <link>https://mskelton.medium.com/customizing-npmjs-com-styles-d3f4cf227188?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/d3f4cf227188</guid>
            <category><![CDATA[npm]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Sun, 01 Dec 2019 22:05:48 GMT</pubDate>
            <atom:updated>2022-02-18T13:27:49.423Z</atom:updated>
            <content:encoded><![CDATA[<h3>Customizing npmjs.com Styles</h3><h4>A few simple improvements to the npmjs.com package view styles</h4><p>This article was originally posted <a href="https://mskelton.dev/blog/customizing-npm-styles">on my blog</a>. Check it out as well as my other articles!</p><p>Like most front-end developers, I use npm quite often for finding new packages or checking out documentation for packages I use. I’ve also started to publish some npm packages of my own recently giving back to the open-source community.</p><p>As I have used npm more in the past few months, a couple of the styles used on the package view page were just bugging me as they gave the page an unfinished and poorly styled look. So, with the help of the <a href="https://chrome.google.com/webstore/detail/stylus/clngdbkpkpeebahjckkjfobafhncgmne?hl=en">Chrome Stylus extension</a> I was able to add a couple quick styles to get the page looking nice. The before and after of the page are shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dmZaVlc_XG8jnRph271TGA.png" /><figcaption>npm package view before and after adding the custom styles.</figcaption></figure><p>Here is the code I used for this simple style adjustment.</p><pre>blockquote &gt; p {<br> margin: 5px 0 !important;<br>}</pre><pre>table {<br>  border-bottom: none !important;<br>  margin-bottom: 16px;<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d3f4cf227188" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Automated npm publishing using GitHub Actions]]></title>
            <link>https://mskelton.medium.com/automated-npm-publishing-using-github-actions-594ef1aaabe2?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/594ef1aaabe2</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[npm]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Sun, 17 Nov 2019 01:58:47 GMT</pubDate>
            <atom:updated>2022-02-18T13:28:30.118Z</atom:updated>
            <content:encoded><![CDATA[<h3>Automated npm Publishing Using GitHub Actions</h3><p>This article was originally posted <a href="https://mskelton.dev/blog/automated-npm-publishing-using-github-actions">on my blog</a>. Check it out as well as my other articles!</p><p>GitHub Actions are a great way to setup CI/CD tasks directly in your GitHub repos for running tests, deploying code, publishing packages, and so much more. I’ve recently done some work to setup actions in my open source repositories for easily publishing npm packages without forcing me to run a bunch of commands from my local development machine. In this article, I’ll go through some basic jobs that you can run using GitHub Actions to simplify the process of publishing npm packages.</p><h3>Basic Publish Action</h3><p>To get our feet wet with publishing npm packages using GitHub Actions, let’s start by creating a simple action that will publish to npm when we push a new version tag.</p><pre>name: Publish<br>on:<br>  push:<br>    tags:<br>      - v*.*.*<br>jobs:<br>  publish:<br>    runs-on: ubuntu-latest<br>    steps:<br>      - uses: actions/checkout@master<br>      - uses: actions/setup-node@v1<br>        with:<br>          node-version: 12<br>          registry-url: <a href="https://registry.npmjs.org/">https://registry.npmjs.org/</a><br>      - run: yarn<br>      - run: yarn publish<br>        env:<br>          NODE_AUTH_TOKEN: ${{ secrets.npm_token }}</pre><p>This action is pretty basic and easy to understand. For the trigger, we use the tag pattern of v*.*.* to match semantic version tags (i.e. v1.0.0). When the action is triggered, we install dependencies by running yarn and then publish the package to npm using yarn publish . This could be modified to use npm install and npm publish if you prefer npm over Yarn.</p><p>An important part of this action is the NODE_AUTH_TOKEN environment variable which is required for authenticating with npm to publish the package. The example above uses GitHub secrets for storing the token which can be generated in your npm profile.</p><h3>Publishing A Release</h3><p>To publish a release with our new action, we can run yarn publish or npm publish to increment the package version in package.json and create a new git tag which we will use to trigger our action. After running the publish command, we can run git push &amp;&amp; git push --tags to push our tag to GitHub and fire off our action!</p><p><em>Hint: adding a </em>postversion<em> script to package.json will save us from having to run the git push command every time we run our publish command. That script would look like this </em>&quot;postversion&quot;: &quot;git push &amp;&amp; git push --tags&quot; <em>and should be places in the </em>scripts<em> section of your package.json</em></p><h3>Creating GitHub Releases</h3><p>Now that we have the basic publish action created, we can improve it so it will automatically create a GitHub release with change notes pulled automatically from a CHANGELOG.md file. To make this easy, we will be using a custom GitHub action by <a href="https://github.com/Roang-zero1">Roang-zero1</a> that will automate this entire process for us. To set this up, add the following job to your action.</p><pre>create-release:<br>  runs-on: ubuntu-latest<br>  steps:<br>    - uses: actions/checkout@master<br>    - uses: Roang-zero1/github-create-release-action@master<br>      env:<br>        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}</pre><p>As you can see, the only thing we need to do is use the github-create-release-action and set the GITHUB_TOKEN environment variable so the custom action can authenticate with GitHub to create the release and upload the change notes. The value of this is the GITHUB_TOKEN secret that is <a href="https://help.github.com/en/actions/automating-your-workflow-with-github-actions/authenticating-with-the-github_token">automatically available inside all GitHub actions</a>.</p><h3>Running Tests</h3><p>While the above examples work great for simple packages where you just need to publish and create a release, most packages will probably have a suite of tests that you will want to run before publishing and releasing. To update our action, we are going to need to make a few changes.</p><p>First, we will need to change the action trigger from on tags to on push. This way we can use the same action to run our tests on branches and pull requests. The trigger should now look like this.</p><pre>on: [push]</pre><p>Next, we will add a test job to the action that uses a matrix strategy to test our package against multiple node versions. You could also add OS versions to the matrix but for our example we’ll keep it simple.</p><pre>test:<br>  runs-on: ubuntu-latest<br>  strategy:<br>    matrix:<br>      node-version: [10.x, 12.x]<br>  steps:<br>    - uses: actions/checkout@v1<br>    - uses: actions/setup-node@v1<br>      with:<br>        node-version: ${{ matrix.node-version }}<br>    - run: yarn<br>    - run: yarn test</pre><p>The last step is to update our other two jobs to depend on the test job and only run on tags. By depending on the test job we can ensure that we don’t publish a package until the tests have run and passed. Additionally, since we changed our trigger from tags to any push, we need to add a conditional to ensure that the publish and release steps will only run for tags while the test can still run for any push. We will need to add the following two lines to both the publish and release jobs.</p><pre>needs: test<br>if: startsWith(github.ref, &#39;refs/tags/&#39;)</pre><h3>Putting It All together</h3><p>Putting all three of these pieces together, our final action would look like this. In some cases, you may not need all three of the jobs so you can easily mix and match to suit you needs.</p><pre>name: Test, Publish, &amp; Release<br>on: [push]<br>jobs:<br>  test:<br>    runs-on: ubuntu-latest<br>    strategy:<br>      matrix:<br>        node-version: [10.x, 12.x]<br>    steps:<br>      - uses: actions/checkout@v1<br>      - uses: actions/setup-node@v1<br>        with:<br>          node-version: ${{ matrix.node-version }}<br>      - run: yarn<br>      - run: yarn test<br>  publish:<br>    needs: test<br>    runs-on: ubuntu-latest<br>    if: startsWith(github.ref, &#39;refs/tags/&#39;)<br>    steps:<br>      - uses: actions/checkout@master<br>      - uses: actions/setup-node@v1<br>        with:<br>          node-version: 12<br>          registry-url: <a href="https://registry.npmjs.org/">https://registry.npmjs.org/</a><br>      - run: yarn<br>      - run: yarn publish<br>        env:<br>          NODE_AUTH_TOKEN: ${{ secrets.npm_token }}<br>  create-release:<br>    needs: test<br>    runs-on: ubuntu-latest<br>    if: startsWith(github.ref, &#39;refs/tags/&#39;)<br>    steps:<br>      - uses: actions/checkout@master<br>      - uses: Roang-zero1/github-create-release-action@master<br>        env:<br>          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}</pre><h3>Bonus: GitHub Actions Badge</h3><p>Once you get your actions working, you may wish to add a status badge to your readme to show if the build is passing or failing. GitHub Actions have builtin support for this which you can read more about on their <a href="https://help.github.com/en/actions/automating-your-workflow-with-github-actions/configuring-a-workflow#adding-a-workflow-status-badge-to-your-repository">official documentation</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=594ef1aaabe2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Tale of Two Ideas]]></title>
            <link>https://medium.com/swlh/a-tale-of-two-ideas-cea3e43121e?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/cea3e43121e</guid>
            <category><![CDATA[react]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[ideas]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Sun, 03 Nov 2019 00:57:10 GMT</pubDate>
            <atom:updated>2022-02-18T13:28:44.337Z</atom:updated>
            <content:encoded><![CDATA[<h4>What to do when encountering ideas from differing perspectives</h4><figure><img alt="A sticky note with a light bulb drawn on it pinned to a bulletin board." src="https://cdn-images-1.medium.com/max/1024/0*nuOeB7qxSv8Yl7qj" /><figcaption>Photo by <a href="https://unsplash.com/@freegraphictoday?utm_source=medium&amp;utm_medium=referral">AbsolutVision</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>This article was originally posted <a href="https://mskelton.dev/blog/a-tale-of-two-ideas">on my blog</a>. Check it out as well as my other articles!</p><p>Every day, we encounter ideas and viewpoints that affect our lives in one way or another. Sometimes we agree with the ideas we hear, other times we disagree, and many times we aren’t immediately sure if we agree or disagree with the ideas we encounter. The challenge we face is discerning which ideas are true and which are false.</p><p>While ideas come from a variety of sources, by far the easiest example of opposing ideas is politics (d<em>on’t worry, this is not a political opinion article</em>). Each election cycle, candidates give speeches and participate in debates to make their ideas known in an effort to gain supporters who will vote for them in the upcoming election. However, the decision rests with the voters who must decide which candidate’s ideas most closely align with their own beliefs.</p><h3>Forks in the Road</h3><figure><img alt="A fork in a trail through the woods." src="https://cdn-images-1.medium.com/max/1024/0*ZhoCTx5v1KUs65Gk" /><figcaption>Photo by <a href="https://unsplash.com/@leliejens?utm_source=medium&amp;utm_medium=referral">Jens Lelie</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><em>The remainder of this post discusses an example of opposing ideas from my career in the software development industry. As such, many readers will not find it very useful due to its technical nature. If you are interested in a more general example, please let me know in the comments. Thanks!</em></p><p>Over the last few months, I’ve been interested in the topic of testing React components and I came across the concept of shallow rendering. In a nutshell, shallow rendering allows you to test React components without rendering their child components. React’s documentation says the following about shallow rendering (<em>plus some other stuff not relevant to this article</em>).</p><blockquote>Shallow rendering lets you render a component “one level deep”, … This does not require a DOM.</blockquote><p>While some believe that shallow rendering is a good technique for testing React components, others disagree thus creating two opposing viewpoints of which technique is best. While I do not intend on giving my own thoughts on the subject, I would like to share my thoughts about the two ideas as a way of demonstrating how to discern between differing viewpoints.</p><h3>Zooming Out</h3><figure><img alt="A left hand holding a camera lens." src="https://cdn-images-1.medium.com/max/1024/0*JYTXhO03ByAM5see" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Once you have identified a set of opposing viewpoints, it is helpful to “zoom out” from the specifics and look at what high-level differences exist between the ideas. When we stay “zoomed in” we can miss important details and make poor judgement calls due to insufficient information. Often, the high-level differences result in a cascade of logic that eventually leads to the details that appear to be radically different from each other even though they stem from similar but slightly different high-level viewpoints.</p><p>For my shallow rendering investigation, I compared an article by <a href="https://twitter.com/kentcdodds">Kent C. Dodds</a> called “<a href="https://kentcdodds.com/blog/why-i-never-use-shallow-rendering">Why I Never Use Shallow Rendering</a>” with an article by <a href="https://twitter.com/TimCDoherty">Tim Doherty</a> called “<a href="https://medium.com/@tim.c.doherty/in-defense-of-shallow-rendering-5f627f7c155d">In Defense of Shallow Rendering</a>”. While you may find other differences, I found two high-level differences between the articles (<em>again, I’m saving my opinions for a different article</em>). The two differences I identified were:</p><ul><li>Overall testing methodology (testing pyramid vs testing trophy)</li><li>Definition of “implementation details”</li></ul><h4>Testing Methodology</h4><p>One of the biggest differences between the two opinions on shallow rendering, as discussed in the aforementioned articles, is the overall testing methodology. Kent developed the “testing trophy” methodology where integration tests are favored over unit tests whereas Tim subscribes to the more traditional “testing pyramid” where unit tests are favored over integration tests. This difference in how testing should be approached is a big reason why they differ on the idea of shallow rendering.</p><h4>Implementation Details</h4><p>Another difference I noticed was the definition of “implementation details”. While both Tim and Kent discuss implementation details, they use it to mean very different things. For example, Tim mentions in his post that “the DOM is an implementation detail” and goes on to say that child components are implementation details when testing a parent component. Kent looks at implementation details from the user’s perspective in which case the DOM would not be an implementation detail but instead a necessary part of the code. These difference perspectives on implementation details further explain why the two authors have very different thoughts on shallow rendering.</p><h3>Making the Judgement Call</h3><figure><img alt="A signpost with arrows pointing in different directions." src="https://cdn-images-1.medium.com/max/1024/0*K3JpFxRgcoEJlI_y" /><figcaption>Photo by <a href="https://unsplash.com/@soymeraki?utm_source=medium&amp;utm_medium=referral">Javier Allegue Barros</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>So, the question you are probably asking yourself is “which approach is right?” However, this is not always the best question to ask. While it is often the case where one idea is right and another idea is wrong, there are instances where both ideas are right depending on the context or use. Remember that the goal is not always to find which idea is right and parade that idea through the streets in a triumphal procession; sometimes simply understanding each idea thoroughly will help you achieve the results you desire.</p><p>In most cases, there comes a time to make the judgement call and decide which idea you believe to be true. When you do, be prepared for others to disagree with your conclusion and be willing to accept their feedback. Hearing feedback from others or searching for more information yourself may result in your opinion changing on a subject, and that’s okay! Making incorrect judgements, while undesirable, should be viewed as a learning opportunity rather than a failure.</p><p>Making a decision on a subject can be scary at times especially if the decision could have an impact on those around you such as your family, friends, or employer. We have all likely heard of people who made simple decisions that resulted in a massive problem down the road and while this does happen, don’t let that stop you from making your decision and moving on. I’ve made many decisions in my career that I later found were less than ideal or just flat out wrong! The key in situations like this is simple: learn from the poor decision, change your future decisions, and move on with your life 🙂</p><p><em>If you are interested in the follow up article I wrote to this about my personal opinions on shallow rendering, check it out using the link below!</em></p><p><a href="https://medium.com/@mskelton/the-dangers-of-shallow-rendering-343e48fe5f28">The Dangers of Shallow Rendering</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cea3e43121e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/a-tale-of-two-ideas-cea3e43121e">A Tale of Two Ideas</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Experience Changing my GitHub Username]]></title>
            <link>https://mskelton.medium.com/my-experience-changing-my-github-username-8414e1baa113?source=rss-4ee41ced3916------2</link>
            <guid isPermaLink="false">https://medium.com/p/8414e1baa113</guid>
            <category><![CDATA[username]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Mark Skelton]]></dc:creator>
            <pubDate>Sat, 19 Oct 2019 12:04:36 GMT</pubDate>
            <atom:updated>2022-02-18T13:29:10.785Z</atom:updated>
            <content:encoded><![CDATA[<p>This article was originally posted <a href="https://mskelton.dev/blog/my-experience-changing-my-github-username">on my blog</a>. Check it out as well as my other articles!</p><p>I created my GitHub account about 3 years ago while working at my first software development job. At the time, Python was one of my primary languages for personal projects and was the inspiration for my first StackOverflow and GitHub username: markypython.</p><p>Since that time however, my usage of Python has decreased dramatically as I moved into JavaScript and Node.js development. I also had begun to use the username mskelton for most of my other accounts and the inconsistency annoyed me. However, some initial research into changing my GitHub username got me pretty frightened and I seriously questioned if it was worth it. Nevertheless, the desire to change my username remained and I eventually decided to do it.</p><h3>Determining the Impact</h3><figure><img alt="A room packed full of stacks of books." src="https://cdn-images-1.medium.com/max/1024/0*uzJlqJrXpYuY4Ez3" /><figcaption>Photo by <a href="https://unsplash.com/@cristina_gottardi?utm_source=medium&amp;utm_medium=referral">Cristina Gottardi</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The first important step in changing my username was determining what the impact of changing it would be. While <a href="https://docs.github.com/en/github/setting-up-and-managing-your-github-user-account/changing-your-github-username">GitHub’s documentation</a> provided some helpful information, I also found two articles by others who have changed their GitHub username that provided good information about what could break when you changing your username. I have linked those articles below.</p><ul><li><a href="https://www.freecodecamp.org/news/a-quick-guide-to-changing-your-github-username/">A quick guide to changing your GitHub username</a></li><li><a href="https://www.nikhita.dev/changing-my-github-username">Changing my GitHub username</a></li></ul><p>I was quite fortunate because I don’t use GitHub pages, Netlify, or any other service that uses a username.github.io url, so a number of the steps in those articles did not apply to me. In the end, the changes I was</p><ul><li>Repository links in package.json and readme files.</li><li>Changelogs or contribution links in repositories I’ve contributed to.</li><li>VSCode and JetBrains extension links</li><li>Travis CI</li><li>Git config files</li></ul><h3>Taking the Plunge</h3><figure><img alt="A person jumping into water from a high height." src="https://cdn-images-1.medium.com/max/1024/0*MXAmJb3bfou4PR_c" /><figcaption>Photo by <a href="https://unsplash.com/@blakesox?utm_source=medium&amp;utm_medium=referral">Blake Wheeler</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Once I was reasonably confident of the impact, I decided to take the plunge and rename my account. I had already secured my new username and had created a separate GitHub account for it while I prepared for the rename. Once I was ready to go, I deleted the temporary account and then renamed my main account to the new username. GitHub did its thing and within a minute it had successfully changed my username. Hooray 🎉</p><p>After renaming your username, the first step you should take is squatting your old username. I’ll explain more about this in the next section, but you’ll want to make sure that you do this immediately after renaming your account.</p><p>Once my account was renamed, I started updating my repos in order of most used to least used. I maintain a JetBrains plugin and two VS Code plugins, so I started with those so I could get a new patch release out with my updating username. I use Travis CI for these plugins, and I found that you need to login to your Travis account and click the sync account button in your account settings for Travis to update to use your new username. Codecov was similar to Travis CI, but I found that I needed to logout and then log back in for the username change to be applied.</p><p>When making updates to your repos, take advantage of GitHub’s search feature which allows you to search all of GitHub for a piece of text. This was very helpful in determining where my username was being used especially for repos I’ve contributed to. I even found a repo I didn’t know existed which was based on one of my repos!</p><p>Updating my Git config files was fairly painless by running grep to find which of my projects needed updating.</p><pre>grep markypython */.git/config</pre><p>After getting that list, I just did some VS Code multi-cursor editing to generate a list of sed commands that looked like this. <em>This worked on macOS, but if you use another Unix-based OS, your mileage may vary.</em></p><pre>sed -i &#39;&#39; -e &#39;s/markypython/mskelton/&#39; dotfiles/.git/config</pre><h3>Squatting Your Old Username</h3><p>When you rename your account, GitHub will setup redirects from your old username to your new username, but if someone takes over your new username and creates a repo with the same name, those redirects will no longer go to your repository. To prevent this, create a new account with your old username and clearly identify that you renamed your main account.</p><figure><img alt="GitHub account for the old username contains a repo with a description of “I RENAMED MY ACCOUNT”." src="https://cdn-images-1.medium.com/max/528/1*nfGEru6CemDyQ2a4pP8X8A.png" /><figcaption>Old username clearly indicating that the account was renamed.</figcaption></figure><p>An important note about squatting your old username is that GitHub prohibits name squatting and holding names for future use in their <a href="https://help.github.com/en/articles/github-username-policy">username policy</a>. Because of this policy, I would recommend squatting your old username for a month or two and then deleting your old account so it is available for other users in the future.</p><h3>Wrapping It Up</h3><figure><img alt="A present wrapped with brown paper and a pink bow on top." src="https://cdn-images-1.medium.com/max/1024/0*gVhD3scNBwRtSs5H" /><figcaption>Photo by <a href="https://unsplash.com/@plushdesignstudio?utm_source=medium&amp;utm_medium=referral">Plush Design Studio</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Aside from the decision to start the processing of renaming my account at 9:30 PM on a Friday night, I am very happy that I decided to rename my account as it was not nearly as bad as I thought it would be. The changes required are mostly busy-work and don’t require a huge amount of effort. I wish the best to anyone else who embarks on the same journey of renaming their GitHub account and I hope this article was helpful in explaining some of that process!</p><p>You can view my GitHub repository with my <strong>new</strong> username at <a href="https://github.com/mskelton">github.com/mskelton</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8414e1baa113" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>