title: Typescript project setup with shared package
body: <p>I have a few premises before starting:</p>
  
  <ol>
  <li>I want a shared package which will be included in three other packages,</li>
  <li>typescript,</li>
  <li>just one node modules,</li>
  <li>multiplatform usage (Windows / Linux),</li>
  <li>use dependencies from the shared package,</li>
  <li>(live reload will be nice),</li>
  <li>not to lose the ability to later publish shared package (the other three packages are web servers, but now is under heavy development),</li>
  <li>common scripts <code>build:web</code> <code>build:api</code> <code>build:admin</code> from global package.</li>
  </ol>
  
  <p>My dreamed folder structure is:</p>
  
  <pre><code>/
  /node_modules/***
  
  /packages/shared/package.json // Shared dependencies like typeorm, lodash etc..
  /packages/shared/src/index.ts
  /packages/shared/src/models/User.ts
  
  /packages/web/package.json
  /packages/web/tsconfig.json
  /packages/web/src/index.ts // first express server (using shared code)
  
  /packages/api/package.json
  /packages/api/tsconfig.json
  /packages/api/src/index.ts
  ...
  
  /package.json
  /tsconfig.common.json
  </code></pre>
  
  <p>There are a lot of solutions across the internet - Lerna, typescript project reference, npm / yarn link... but I am not able to find a suitable solution...</p>
  
  <p>For example, this <a href="https://github.com/Quramy/lerna-yarn-workspaces-example" rel="nofollow noreferrer">https://github.com/Quramy/lerna-yarn-workspaces-example</a> is cool, but I was not able to setup to run something like this:</p>
  
  <pre><code>// package.json
  
  {
    "scripts": {
       "debug:web": "concurrently \"(cd packages/shared &amp;&amp; tsc -w)\" \"(cd packages/web &amp;&amp; tsc -w)\" \"(cd packages/web &amp;&amp; nodemon --inspect dist/index.js --watch .. /)\""
  
  ...
  </code></pre>
  
  <p>I want to continuously build the shared package (generate dist/index.js and .ts files) and in nodemon restart server after something changed in ../ (packages folder).</p>
  
  <p>After a few hours I gave up to chance to have code reloading and try that via "easiest-way" I could find - no package in <code>shared</code> but include code directly via:</p>
  
  <pre><code>// shared/index.ts
  export const createConnection = () =&gt; ....
  
  // web/index.ts
  import { createConnection } from 'shared'
  </code></pre>
  
  <p>it looks like it does not work either:</p>
  
  <pre><code>// tsconfig.json
  
  {
    "extends": "../../tsconfig.settings.json",
    "compilerOptions": {
      "rootDir": "../",
      "outDir": "dist",
      "baseUrl": "./",
      "paths": {
        "shared":  [ "../shared/src/" ]
      }
    }
  }
  </code></pre>
  
  <p>the problem is now:</p>
  
  <pre><code>File /shared/src/index.ts is not listed within the file list of the project in tsconfig.json. Projects must list all files or use an 'include' pattern.
  </code></pre>
  
  <p>Next step is (obviously):</p>
  
  <pre><code>{
    "extends": "../../tsconfig.settings.json",
    "include": [
      "./src/**/*.ts",
      "../shared/src/**/*.ts"
    ],
    "compilerOptions": {
      "rootDir": "../",
      "outDir": "dist",
      "baseUrl": "./",
      "paths": {
        "shared":  [ "../shared/src/" ]
      }
    }
  }
  </code></pre>
  
  <p>This works! No errors, but no files in "dist" also... LOL</p>
  
  <p>I am pretty sure, there is some nice solution, example or it won't work either, but I was not able to find it or build it.</p>