<?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 Morty Green on Medium]]></title>
        <description><![CDATA[Stories by Morty Green on Medium]]></description>
        <link>https://medium.com/@zeleny.maros?source=rss-5e316ff6ad2c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*oao_TutxYuEhKMWQ9uWK1A.jpeg</url>
            <title>Stories by Morty Green on Medium</title>
            <link>https://medium.com/@zeleny.maros?source=rss-5e316ff6ad2c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 23:59:47 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@zeleny.maros/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[Involving lerna into monorepo project]]></title>
            <link>https://medium.com/@zeleny.maros/involving-lerna-into-monorepo-project-f91f72040645?source=rss-5e316ff6ad2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/f91f72040645</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[lerna]]></category>
            <category><![CDATA[husky]]></category>
            <category><![CDATA[monorepo]]></category>
            <dc:creator><![CDATA[Morty Green]]></dc:creator>
            <pubDate>Wed, 18 Mar 2020 10:54:53 GMT</pubDate>
            <atom:updated>2020-03-19T15:56:47.026Z</atom:updated>
            <content:encoded><![CDATA[<h3>Adding lerna into monorepo project</h3><h3>Problem</h3><p>In our company we are building project based on microservice architecture. The classic problem that you encountered during development, you would like to avoid some issues before you push changes into remote git repository. These issues are mostly lint and tests errors. If you change something in one service and you want to push your changes into remote branch, all linters and tests scripts for all services will start running. This problem is caused by installation of husky in every service. Husky documentation says: “use lerna”.</p><p>The second problem we encountered, we started to set up lerna too late. After one year of development, lerna came in. Set it up it at the beginning.</p><p>All code (we are using it in our project but some sensitive information are hidden) and text below is based on my experience of incorporating lerna into our project.</p><h3>Setting up lerna</h3><ol><li>Run script <strong>lerna init. </strong>It creates new lerna repo with:</li></ol><p>a) lerna.json</p><ul><li>npm is by default but you can use yarn client instead.</li><li>contains all packages <strong>(I will call them services)</strong> that should be managed by lerna.</li><li>you can choose between locked/ independent mode.</li></ul><pre>{<br>&quot;<strong>npmClient</strong>&quot;: &quot;npm&quot;,<br>&quot;<strong>packages</strong>&quot;: [&quot;frontend-service&quot;,&quot;identity-service&quot;,&quot;neo4j-  service&quot;,&quot;project-service&quot;,&quot;reference-model-service&quot;],<br>&quot;<strong>version</strong>&quot;: &quot;independent&quot;<br>}</pre><p>b) packages folder</p><p>You can put all your services into this folder or you can choose which one you want to be managed by lerna as in my example. We don’t or can’t manage some services by lerna from different reasons (for example: they are not node.js services). If you have all services in packages folder and you want to exclude some of them, check the doc.</p><p>c) root package.json (<strong>hoisting dependencies</strong>)</p><p>Lerna hold hoisted devDependencies there(check chapter common devDependencies in lerna doc). Use<strong> lerna</strong> <strong>link convert</strong> command to “extract” common node modules into the root package.json.</p><p>We hoisted for example eslint npm packages, which we use across all services. We also installed husky package here(as is recommended in husky doc). You can put there also packages that are not used by all services but most of them.</p><p>Occasionally you may encounter some problems with hoisted dependencies:</p><p><strong>The first problem:</strong></p><p>We have react-scripts in our frontend service as prod dependency and we had in root package.json @hapi/lab module (testing library for hapi server for our backend services). React scripts started yelling that it use another version of eslint as @hapi/lab. So, We moved @hapi/lab into every backend service’s package.json instead of holding it in root package.json.</p><p><strong>The second problem:</strong></p><p>Our integrations tests are running in isolation so they don’t have access to the hoisted devDependencies. We moved all tests libraries into package.json of every service. We found this solution much easier then rewriting logic of launching integration tests.</p><p>Putting shared npm packages into root package.json may not always be a good solution.</p><p>Our root package.json:</p><pre>{<br>  &quot;name&quot;: &quot;root&quot;,<br>  &quot;private&quot;: true,</pre><pre>&quot;devDependencies&quot;: {<br>   <br>   &quot;btoa&quot;: &quot;1.2.1&quot;,<br>   &quot;eslint&quot;: &quot;6.8.0&quot;,<br>   &quot;eslint-config-airbnb-base&quot;: &quot;14.0.0&quot;,<br>   &quot;eslint-config-prettier&quot;: &quot;6.10.0&quot;,<br>   &quot;eslint-plugin-import&quot;: &quot;2.2.0”,<br>   &quot;eslint-plugin-jsx-a11y&quot;: &quot;6.2.3”,<br>   &quot;eslint-plugin-prettier&quot;: &quot;3.1.2”,<br>   &quot;eslint-plugin-react&quot;: &quot;7.19.0&quot;,<br>   &quot;husky&quot;: &quot;4.2.3&quot;,<br>   &quot;kafka-node&quot;: &quot;3.0.1&quot;,<br>   &quot;lerna&quot;: &quot;3.20.2&quot;,<br>   &quot;lint-staged&quot;: &quot;9.5.0&quot;,<br>   &quot;lodash&quot;: &quot;4.17.15&quot;,<br>   &quot;nodemon&quot;: &quot;2.0.2&quot;,<br>   &quot;nyc&quot;: &quot;14.1.1&quot;,<br>   &quot;prettier&quot;: &quot;1.19.1&quot;,<br>   &quot;typescript&quot;: &quot;3.8.3”<br>},<br>&quot;husky&quot;: {<br> &quot;hooks&quot;: {<br>  &quot;pre-commit&quot;: &quot;lerna run lint-staged — concurrency 1 — since dev&quot;,<br>  &quot;pre-push&quot;: &quot;lerna run prepush — stream — concurrency 1 — since dev&quot;<br>  }<br>},<br>&quot;dependencies&quot;: {<br>  &quot;frontend&quot;: &quot;file:frontend&quot;,<br>  &quot;identity-service”: &quot;file:identity-service&quot;,<br>  &quot;project-service&quot;: &quot;file:project-service&quot;,<br>  &quot;reference-model-service&quot;: &quot;file:reference-model-service&quot;,<br>  &quot;neo4j-service&quot;: &quot;file:neo4j-service&quot;<br>  }<br>}</pre><h3>Husky with Lerna</h3><p>We use husky hooks <strong>pre-commit</strong> and <strong>pre-push </strong>with flags <strong>concurrency - 1 </strong>and<strong> since - dev. </strong>I will explain these flags now:</p><p><strong>concurrency 1</strong></p><p>We have in our project integration tests that runs against postgresql test database launched through docker-compose as docker image. All services launch same db (except neo4j-service, which uses neo4j graph db).</p><p>Here is the scenario:</p><ol><li>launch local db (It runs as shell script via npm script)</li><li>run integration tests</li><li>stop local db</li></ol><ul><li>this needs to be repeated <strong>sequentially not parallel</strong> for all services otherwise tests fail because they work with the same db image.</li></ul><p><strong>since [ref]</strong></p><ul><li>run husky hooks only against service/s that has been changed since the specific ref. In my case it’s branch dev because all our features branches are created from it. It compares actual committed changes, you want to push against actual dev branch. It runs scripts only on services that have been changed. I recommend still keep up date your feature branch with dev branch or other one before pushing.</li></ul><p>When you run<strong> lerna bootstrap</strong> command it should install all dependencies defined in root package.json for every service. Don’t expect that you will see these dependencies in node_modules in every service. This is one of the lerna’s power:</p><blockquote>reduce the time and space requirements for numerous copies of packages in development and build environments by “hoisting” dependencies up to topmost lerna-project-level node_modules.</blockquote><p>You still need to install rest of dependencies with <strong>npm i</strong> for every service independently (dependencies for production and also devDependencies specific for given service if you have any).</p><p>If you get into troubles:</p><ul><li>use <strong>lerna clean</strong> command to uninstall node_modules from all services (check for sure if all node_modules were removed if not remove them manually) and reinstall them.</li><li>delete <strong>package-lock.json</strong> and <strong>node_modules </strong>in root.</li><li>do not forget installing lerna globally to access CLI.</li></ul><p>Lerna has also another commands. One of the most important that was not mentioned here is <strong>lerna publish </strong>but in our case we don’t need it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f91f72040645" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Migrate webpack v3 to v4 in create-react-app ejected version.]]></title>
            <link>https://medium.com/@zeleny.maros/migrate-webpack-v3-to-v4-in-create-react-app-ejected-version-5760bfa6b5f2?source=rss-5e316ff6ad2c------2</link>
            <guid isPermaLink="false">https://medium.com/p/5760bfa6b5f2</guid>
            <category><![CDATA[migration]]></category>
            <category><![CDATA[create-react-app]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[webpack]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Morty Green]]></dc:creator>
            <pubDate>Sun, 26 Aug 2018 13:53:30 GMT</pubDate>
            <atom:updated>2018-08-26T20:16:44.586Z</atom:updated>
            <content:encoded><![CDATA[<p>Helloooou,<br>I decided to write my first article about the migration of webpack 3 to webpack 4 in ejected create-react-app. As I know so far they still didn’t update react-scripts, which brings new webpack version. (I think it will be in react-script 2)<br>Maybe you are wondering why I ejected my project. The reason was adding css-modules. Yes, Im using css modules with sass preprocessor.<strong> Never ever !</strong></p><p>I hate this style config and in next my project I will come back to<strong> CSS in JS </strong>coding style (styled-components). If you use something else let me know in comments !.</p><p>Before I decided to upgrade webpack I thought it will be pain in ass but absolutely not ! You need to pass through few errors and upgrade some npm modules and make some code refactor.</p><p>The whole config folder, you get when app is ejected is not easy to understand. Last time I configure webpack it was a version 1 or 2. So really long time ago. So I started to “refresh my webpack knowledge” through couldcourses on frontend master by mr. @Sean Larkin. (I really recommend his courses). That’s helps me understand webpack better and also make migration much easier.</p><p>So let’s get into it!</p><p>My app config:</p><p><strong>frontend</strong> — react.js</p><p><strong>API</strong> — graphql apollo (I love that!)</p><p><strong>backend</strong> — node.js with express.js, postgresql</p><p>Here is my scenario for upgrade-ing webpack:</p><ol><li>add HtmlWebpackPlugin before InterpolateHtmlPlugin in webpack.config.dev.js</li></ol><p><strong>2. if you get eslint error something like eslint is not defined</strong></p><p>— upgrade eslint-loader to the newest version -&gt; <strong>npm i eslint-loader</strong></p><p><strong>3. error — Module build failed (from ./node_modules/file-loader/dist/cjs.js):TypeError: Cannot read property ‘context’ of undefined</strong></p><ul><li>upgrade npm module<strong> file-loader </strong>to the newest version</li></ul><p><strong>4. TypeError: missingDeps.some is not a function</strong></p><p>— upgrade react-dev-utils to the latest version. If this will not work uscoulde next version <strong>npm i react-dev-utils@next.</strong></p><p>5.<strong>ReferenceError: require is not definedModule../node_modules/graphql/jsutils/instanceOf.mjs</strong></p><p>— this was already fixed in one PR in create-react-app. This error is thrown because graphql is using mjs files.</p><p>Add this code into webpack.config.dev.js file into webpack loaders part.</p><pre>module: {<br> {<br>  test: /\.mjs$/,<br>  include: /node_modules/,<br>  type: &quot;javascript/auto&quot;,<br> }<br>}</pre><p>Also add into the same file mjs in extensions before .js.</p><pre>resolve: {<br>.....<br>  extensions: [&quot;.web.js&quot;, <strong>&quot;.mjs&quot;</strong>, &quot;.js&quot;, &quot;.json&quot;, &quot;.web.jsx&quot;, &quot;.jsx&quot;],<br>  alias: {<br>    &quot;react-native&quot;: &quot;react-native-web&quot;<br>  },<br>  plugins: [<br>    new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson])<br>  ]<br>},</pre><p>6. only for graphql-apollo users.</p><p><strong>Error: Cannot use e “__Schema” from another module or real</strong>could<strong>m. Ensure that there is only one instance of “graphql” in the node_modules directory. If different versions of “graphql” are the dependencies of other relied on modules, use “resolutions” to ensure only one version is installed.</strong></p><p>Its much longer error but I cutted it off. Webpack 4 introduced new feature called “mode” (Look into the spec <a href="https://webpack.js.org/concepts/mode/#src/components/Sidebar/Sidebar.jsx">https://webpack.js.org/concepts/mode/#src/components/Sidebar/Sidebar.jsx</a>).</p><p>Just define mode: “development” in webpack.config.dev.js in root config. And the same for production.</p><p>7. what else ?</p><ul><li>check your package.json and update all webpack loaders/plugins.</li><li>refactor loaders in dev and prod webpack files according to the spec.</li><li>remove <strong>ExtractTextPlugin </strong>and replace it with <strong>MiniCssExtractPlugin</strong></li></ul><p>check usage :(<a href="https://github.com/webpack-contrib/extract-text-webpack-plugin">https://github.com/webpack-contrib/extract-text-webpack-plugin</a>)</p><ul><li>refactor <strong>UglifyJsPlugin. </strong>My refactor according react-create-app:</li></ul><pre>optimization: { <br> minimizer: [ <br>  new UglifyJsPlugin({ <br>    compress: {<br>     warnings: false, comparisons: false }, <br>     mangle: { safari10: true }, <br>     output: { comments: false, ascii_only: true }, <br>     sourceMap: shouldUseSourceMap }) <br> ]<br>}</pre><p><strong>So that’s it!!!</strong></p><p>I didn’t find any official migration guide. So according to some articles and my experience I wrote this guide. So If missed something leave me comment below.</p><p>I hope it helps someone:).</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5760bfa6b5f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>