<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Erik "Noaa" Engervall</title>
    <description>The latest articles on DEV Community by Erik "Noaa" Engervall (@erikengervall).</description>
    <link>https://dev.to/erikengervall</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F320798%2F3e12f319-56fc-49e8-835c-6f7295cc52f2.jpeg</url>
      <title>DEV Community: Erik "Noaa" Engervall</title>
      <link>https://dev.to/erikengervall</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/erikengervall"/>
    <language>en</language>
    <item>
      <title>Entering open-source software</title>
      <dc:creator>Erik "Noaa" Engervall</dc:creator>
      <pubDate>Thu, 20 Feb 2020 08:25:38 +0000</pubDate>
      <link>https://dev.to/erikengervall/entering-open-source-software-3edp</link>
      <guid>https://dev.to/erikengervall/entering-open-source-software-3edp</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flive.staticflickr.com%2F65535%2F49560128901_cffa232f26_b.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flive.staticflickr.com%2F65535%2F49560128901_cffa232f26_b.jpg" alt="open source software"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Credit: Getty
&lt;/h6&gt;

&lt;p&gt;I've built free web-apps fulfilling various practical purposes (mostly silly) for quite some time, but it wasn't until fairly recently (~1 yr) that I started getting into open-source software (OSS). It has opened my mind to a whole new world and has had an enormous impact on my general understanding of JavaScript and its ecosystem. This extension of knowledge was partly thanks to contributing to open-source projects but even more so by simply reading a lot more source code written by other developers. The realization that all source code is written by mere mortals, and that it doesn’t bite, caused the threshold for deep diving into libraries whenever issues arose to be significantly lowered.&lt;/p&gt;

&lt;h1&gt;
  
  
  Learnings
&lt;/h1&gt;

&lt;p&gt;My OSS journey hasn’t been without bumps in the road. But where there’s bumps, there’s learnings.&lt;/p&gt;

&lt;h2&gt;
  
  
  Git &amp;amp; npm: The Confusing Parts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  npm tags
&lt;/h3&gt;

&lt;p&gt;Git and npm has a lot of overlapping terminology which can be confusing at first. When starting out with developing my own projects I had a lot of assumptions as to how the two platforms interacted. For example, a misconception I had early on was that npm would interpret my libraries' versions and make contextual decisions, such as "marking" a release published as &lt;code&gt;0.0.1-alpha.0&lt;/code&gt; as an &lt;em&gt;alpha-release&lt;/em&gt; rather than a &lt;em&gt;latest-release&lt;/em&gt;. However, even though &lt;code&gt;0.0.1-alpha.0&lt;/code&gt; is completely &lt;a href="https://semver.org/#spec-item-9" rel="noopener noreferrer"&gt;valid&lt;/a&gt; semver, npm requires that one explicitly &lt;a href="https://docs.npmjs.com/cli/publish#description" rel="noopener noreferrer"&gt;tag&lt;/a&gt; releases: &lt;code&gt;npm publish --tag alpha&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;A npm tag can be pretty much anything &lt;a href="https://docs.npmjs.com/cli/dist-tag#caveats" rel="noopener noreferrer"&gt;&lt;em&gt;except&lt;/em&gt;&lt;/a&gt; for something resembling semver. For example,&lt;code&gt;npm publish --tag ihavenoideawhatimdoing&lt;/code&gt; is completely valid:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flive.staticflickr.com%2F65535%2F49490741663_b9ca622363_o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flive.staticflickr.com%2F65535%2F49490741663_b9ca622363_o.png" alt="npm tags"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  git tags
&lt;/h3&gt;

&lt;p&gt;We just learned what a tag is in npm's world. What about Git?&lt;/p&gt;

&lt;p&gt;A &lt;a href="https://git-scm.com/book/en/v2/Git-Basics-Tagging" rel="noopener noreferrer"&gt;tag in Git&lt;/a&gt; is essentially a snapshot of a repository at a particular time in its history. Dealing with Git tags is fairly straightforward. The weirdest part is that the tag's name can be literally anything and doesn't have to conform to semver. Developers commonly use tags to help mark releases and thus, for sanity's sake, use their library's version as a Git tag (prefixed by &lt;code&gt;v&lt;/code&gt; of course 🤷🏼‍♂️):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create tag&lt;/span&gt;
git tag v0.0.1

&lt;span class="c"&gt;# Push to repo (will turn up as a commit)&lt;/span&gt;
git push &lt;span class="nt"&gt;--tags&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  TypeScript
&lt;/h2&gt;

&lt;p&gt;Building your library in TypeScript?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia1.tenor.com%2Fimages%2Fef005366f35f143e799a2bf05739c352%2Ftenor.gif%3Fitemid%3D13356160" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia1.tenor.com%2Fimages%2Fef005366f35f143e799a2bf05739c352%2Ftenor.gif%3Fitemid%3D13356160" alt="typescript is supereasy"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Expose your type declarations
&lt;/h3&gt;

&lt;p&gt;There's a &lt;a href="https://www.typescriptlang.org/docs/handbook/compiler-options.html" rel="noopener noreferrer"&gt;ton&lt;/a&gt; of options for compiling TypeScript projects. However, there's one in particular that'll make whoever depends on your library super happy 🐼:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"declaration"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This'll generate declaration files (&lt;code&gt;file.d.ts&lt;/code&gt;) next to each JavaScript file outputted from the compilation that'll be exposed to your users when they import your library.&lt;/p&gt;

&lt;h3&gt;
  
  
  Fighting your IDE 👨🏼‍💻🥊
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;The relevance of this particular tip may vary depending on your &lt;a href="https://en.wikipedia.org/wiki/Integrated_development_environment" rel="noopener noreferrer"&gt;IDE&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;There's a wide variety of IDE's out there, from those that give absolutely zero support whatsoever to those that borderline autocompletes your thoughts. My current IDE of choice, &lt;a href="https://code.visualstudio.com/" rel="noopener noreferrer"&gt;VS Code&lt;/a&gt;, is somewhere in the middle of this range. It is equipped with a bunch of debugging tools and a solid selection of extensions, improving developer experience via customizability. In a perfect world a developer wouldn't have to run e.g. ESLint's CLI but would solely rely on an extension that'd guarantee the same experience.&lt;/p&gt;

&lt;p&gt;When developing TypeScript your IDE relies on your &lt;code&gt;tsconfig.json&lt;/code&gt; to validate your code and highlight type errors. This behavior, as intended as it may be, causes some level of cumbersomeness when publishing your library to e.g. npm.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, &lt;em&gt;hopefully&lt;/em&gt;, your project is blessed with at least &lt;em&gt;one&lt;/em&gt; unit test. Ideally, tests shouldn't turn up in the distribution code, i.e. the &lt;em&gt;dist&lt;/em&gt;, just as development dependencies shouldn't turn up in production. However, using &lt;code&gt;exclude&lt;/code&gt; in your tsconfig makes VS Code a sad 🐼 and you'll see the errors such as:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Cannot find name 'describe'. Do you need to install type definitions for a test runner? Try &lt;code&gt;npm i @types/jest&lt;/code&gt; or &lt;code&gt;npm i @types/mocha&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flive.staticflickr.com%2F65535%2F49435983712_b5ebae248c_o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flive.staticflickr.com%2F65535%2F49435983712_b5ebae248c_o.png" alt="Sad VS Code"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;I haven't found any better workaround than to include all TypeScript files in my &lt;code&gt;tsconfig.json&lt;/code&gt; and create a separate &lt;code&gt;tsconfig.publish.json&lt;/code&gt; that'll be used when publishing to npm. This setup makes VS code happier...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flive.staticflickr.com%2F65535%2F49435761671_90121b77a0_o_d.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Flive.staticflickr.com%2F65535%2F49435761671_90121b77a0_o_d.png" alt="Happy VS Code"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;...but forces developers to remember yet another detail before publishing: compile the dist using &lt;code&gt;yarn tsc --project tsconfig.publish.json&lt;/code&gt; instead of simply &lt;code&gt;yarn tsc&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pipeline - automate automate automate
&lt;/h2&gt;

&lt;p&gt;A colleague of mine who's an OSS wizard once recommended me to automate as much as I possibly could for my projects. Not being a huge fan of pipelines and such, I kindly nodded and postponed the advice as long as possible.&lt;/p&gt;

&lt;p&gt;However, my patience finally got the best of me. I learned the hard way that a bunch of manual steps easily led to mistakes and ultimately frustration. Lucky for me, &lt;a href="https://github.com/actions" rel="noopener noreferrer"&gt;GitHub Actions&lt;/a&gt; had just been released and it matched my level of interest in DevOps. With it, I could fairly painlessly create &lt;a href="https://github.com/erikengervall/dockest/blob/master/.github/workflows/nodejs.yml" rel="noopener noreferrer"&gt;workflows&lt;/a&gt; that would automate everything I needed in order to publish libraries. &lt;/p&gt;

&lt;p&gt;What kind of steps does this entail? Well, here's roughly the flow of my pipeline:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Linting&lt;/strong&gt;: Running e.g. ESLint is a great way to discover problems without having to run any code.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tests&lt;/strong&gt;: Just like the responsible developers that we are, there's plenty of tests validating that our code can do stuff, even better if it does what it's supposed to. Extra points for integration tests ⨑&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Since we only wish to publish to npm on version bumps, the following steps only execute on &lt;a href="https://developer.github.com/v3/git/refs/" rel="noopener noreferrer"&gt;git refs&lt;/a&gt; starting with &lt;code&gt;refs/tags/&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Publish library&lt;/strong&gt;: Install dependencies, build the dist and publish to npm. This step also attaches necessary npm tags, for example &lt;code&gt;v0.0.1-alpha.0&lt;/code&gt; results in &lt;code&gt;npm publish --tag alpha&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build and deploy website&lt;/strong&gt;: Creating a website for your library's documentation is pretty sweet once the README starts occupying a few viewports. I recommend &lt;a href="https://docusaurus.io/" rel="noopener noreferrer"&gt;Docusaurus&lt;/a&gt; since it's easy to use and deploy.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;This article was intended to outline some of the challenges I've encountered during my adventures on GitHub, I hope it inspires more than it frightens 🙌🏼&lt;/p&gt;

&lt;p&gt;If there's interest I'd be happy to share more on this topic!&lt;/p&gt;

</description>
      <category>npm</category>
      <category>git</category>
      <category>opensource</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
