├── .editorconfig ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .nvmrc ├── LICENSE.md ├── README.md ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── app │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── app.ts │ │ └── sayHelloLocal.ts │ └── tsconfig.json └── es-module │ ├── package-lock.json │ ├── package.json │ ├── src │ └── index.ts │ └── tsconfig.json └── tsconfig.settings.json /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | charset = utf-8 5 | end_of_line = lf 6 | indent_size = 2 7 | indent_style = space 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | trim_trailing_whitespace = false -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-18.04 8 | 9 | steps: 10 | - uses: actions/checkout@master 11 | - uses: actions/setup-node@v1 12 | with: 13 | node-version: 12 14 | - run: npm ci 15 | - run: npm run build 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | lib/ 2 | node_modules/ 3 | .DS_Store 4 | .vscode 5 | *.log 6 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 12 -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright © `2020` `kevinpollet ` 4 | 5 | Permission is hereby granted, free of charge, to any person 6 | obtaining a copy of this software and associated documentation 7 | files (the “Software”), to deal in the Software without 8 | restriction, including without limitation the rights to use, 9 | copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the 11 | Software is furnished to do so, subject to the following 12 | conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 | OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Running TypeScript ES Modules with Node.js 2 | 3 | [![Build Status](https://github.com/kevinpollet/typescript-es-modules-node-example/workflows/Build/badge.svg)](https://github.com/kevinpollet/typescript-es-modules-node-example/actions) 4 | [![License](https://img.shields.io/badge/license-MIT-blue.svg)](./LICENSE.md) 5 | 6 | Based on the [Announcing a new experimental modules](https://medium.com/@nodejs/announcing-a-new-experimental-modules-1be8d2d6c2ff) post from the Node team, this repository is an example of a TypeScript app running with the new `experimental modules` feature shipped with Node.js 12. As explained in the linked post, it's now possible to use `import` and `export` syntax in `.js` files, so ES Modules transpiled from TypeScript can be used out of the box 😎 7 | 8 | ## Project tree 9 | 10 | ``` 11 | . 12 | ├── lerna.json 13 | ├── package-lock.json 14 | ├── package.json 15 | ├── packages 16 | │   ├── app //--> TypeScript app transpiled as an ES Module, using es-module dependency 17 | │   │   ├── package-lock.json 18 | │   │   ├── package.json 19 | │   │   └── tsconfig.json 20 | │   └── es-module //--> ES Module written in TypeScript 21 | │   ├── package-lock.json 22 | │   ├── package.json 23 | │   └── tsconfig.json 24 | └── tsconfig.settings.json 25 | ``` 26 | 27 | ## Config 28 | 29 | ### Node.js 30 | 31 | - `type: module`: New package.json field to treat all `.js` files in project as ES Modules, see [app](./packages/app/package.json) and [es-module](./packages/es-module/package.json) files. 32 | - `--experimental-modules`: Flag to enable new experimental modules feature. 33 | - `--es-module-specifier-resolution=node`: By default, file extensions are mandatory in import. This flag enable CommonJS-style automatic extension resolution behavior. This flag is required because [TypeScript does not add imported file extension in transpiled code](https://github.com/microsoft/TypeScript/issues/16577). 34 | 35 | ### TypeScript 36 | 37 | - `module: "esnext"`: Set the module code generation to `esnext`, see inherited [tsconfig.settings.json](./tsconfig.settings.json) 38 | 39 | ## Run app 40 | 41 | 1. Install [Node.js 12](https://nodejs.org/en/blog/release/v12.0.0/) or type `nvm use` if you use [nvm](https://github.com/creationix/nvm) 42 | 2. Install project dependencies with: `npm install` 43 | 3. Start app with: `npm run start` 44 | 4. Browse http://localhost:3000 45 | 46 | You should see the following JSON response: 47 | 48 | ```json 49 | { 50 | "messages": ["Hello from ES Module dependency", "Hello from local ES Module"] 51 | } 52 | ``` 53 | 54 | ## License 55 | 56 | [MIT](./License.md) © kevinpollet 57 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "packages": ["packages/*"], 3 | "version": "independent" 4 | } 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "typescript-es-modules-node-example", 3 | "version": "0.0.0", 4 | "author": "kevinpollet ", 5 | "private": true, 6 | "license": "MIT", 7 | "homepage": "https://github.com/kevinpollet/typescript-es-modules-node-example#readme", 8 | "bugs": "https://github.com/kevinpollet/typescript-es-modules-node-example/issues", 9 | "repository": "github:kevinpollet/typescript-es-modules-node-example", 10 | "scripts": { 11 | "clean": "lerna run clean && lerna clean --yes", 12 | "bootstrap": "lerna bootstrap", 13 | "build": "lerna run build", 14 | "format": "prettier --write 'packages/**/*.{json,md,ts}' '*.{json,md,ts}' '!lib'", 15 | "start": "node --experimental-modules --es-module-specifier-resolution=node packages/app/lib/app.js", 16 | "prebuild": "npm run bootstrap", 17 | "prestart": "npm run build" 18 | }, 19 | "devDependencies": { 20 | "@kevinpollet/tsconfig": "^0.1.0", 21 | "husky": "^4.2.5", 22 | "lerna": "^3.20.2", 23 | "lint-staged": "^10.2.2", 24 | "prettier": "^2.0.5" 25 | }, 26 | "husky": { 27 | "hooks": { 28 | "pre-commit": "lint-staged" 29 | } 30 | }, 31 | "lint-staged": { 32 | "*.{json,ts,md}": [ 33 | "prettier --write", 34 | "git add" 35 | ] 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/app/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "0.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@types/node": { 8 | "version": "12.12.30", 9 | "resolved": "https://registry.npmjs.org/@types/node/-/node-12.12.30.tgz", 10 | "integrity": "sha512-sz9MF/zk6qVr3pAnM0BSQvYIBK44tS75QC5N+VbWSE4DjCV/pJ+UzCW/F+vVnl7TkOPcuwQureKNtSSwjBTaMg==" 11 | }, 12 | "abstract-logging": { 13 | "version": "2.0.0", 14 | "resolved": "https://registry.npmjs.org/abstract-logging/-/abstract-logging-2.0.0.tgz", 15 | "integrity": "sha512-/oA9z7JszpIioo6J6dB79LVUgJ3eD3cxkAmdCkvWWS+Y9tPtALs1rLqOekLUXUbYqM2fB9TTK0ibAyZJJOP/CA==" 16 | }, 17 | "ajv": { 18 | "version": "6.12.2", 19 | "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.2.tgz", 20 | "integrity": "sha512-k+V+hzjm5q/Mr8ef/1Y9goCmlsK4I6Sm74teeyGvFk1XrOsbsKLjEdrvny42CZ+a8sXbk8KWpY/bDwS+FLL2UQ==", 21 | "requires": { 22 | "fast-deep-equal": "^3.1.1", 23 | "fast-json-stable-stringify": "^2.0.0", 24 | "json-schema-traverse": "^0.4.1", 25 | "uri-js": "^4.2.2" 26 | } 27 | }, 28 | "archy": { 29 | "version": "1.0.0", 30 | "resolved": "https://registry.npmjs.org/archy/-/archy-1.0.0.tgz", 31 | "integrity": "sha1-+cjBN1fMHde8N5rHeyxipcKGjEA=" 32 | }, 33 | "atomic-sleep": { 34 | "version": "1.0.0", 35 | "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", 36 | "integrity": "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ==" 37 | }, 38 | "avvio": { 39 | "version": "6.4.1", 40 | "resolved": "https://registry.npmjs.org/avvio/-/avvio-6.4.1.tgz", 41 | "integrity": "sha512-jeZaUK+F7MuWSNT3VHfltskPJZKqVeTWQqBA4SDaDoLaQ0lb5TOgLeQT1BEuhTIUNISCDCGY3zjYyVmQQ48gKA==", 42 | "requires": { 43 | "archy": "^1.0.0", 44 | "debug": "^4.0.0", 45 | "fastq": "^1.6.0" 46 | } 47 | }, 48 | "balanced-match": { 49 | "version": "1.0.0", 50 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 51 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", 52 | "dev": true 53 | }, 54 | "brace-expansion": { 55 | "version": "1.1.11", 56 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", 57 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", 58 | "dev": true, 59 | "requires": { 60 | "balanced-match": "^1.0.0", 61 | "concat-map": "0.0.1" 62 | } 63 | }, 64 | "concat-map": { 65 | "version": "0.0.1", 66 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 67 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", 68 | "dev": true 69 | }, 70 | "cookie": { 71 | "version": "0.4.1", 72 | "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.4.1.tgz", 73 | "integrity": "sha512-ZwrFkGJxUR3EIoXtO+yVE69Eb7KlixbaeAWfBQB9vVsNn/o+Yw69gBWSSDK825hQNdN+wF8zELf3dFNl/kxkUA==" 74 | }, 75 | "debug": { 76 | "version": "4.1.1", 77 | "resolved": "https://registry.npmjs.org/debug/-/debug-4.1.1.tgz", 78 | "integrity": "sha512-pYAIzeRo8J6KPEaJ0VWOh5Pzkbw/RetuzehGM7QRRX5he4fPHx2rdKMB256ehJCkX+XRQm16eZLqLNS8RSZXZw==", 79 | "requires": { 80 | "ms": "^2.1.1" 81 | } 82 | }, 83 | "deepmerge": { 84 | "version": "4.2.2", 85 | "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", 86 | "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==" 87 | }, 88 | "fast-decode-uri-component": { 89 | "version": "1.0.1", 90 | "resolved": "https://registry.npmjs.org/fast-decode-uri-component/-/fast-decode-uri-component-1.0.1.tgz", 91 | "integrity": "sha512-WKgKWg5eUxvRZGwW8FvfbaH7AXSh2cL+3j5fMGzUMCxWBJ3dV3a7Wz8y2f/uQ0e3B6WmodD3oS54jTQ9HVTIIg==" 92 | }, 93 | "fast-deep-equal": { 94 | "version": "3.1.1", 95 | "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.1.tgz", 96 | "integrity": "sha512-8UEa58QDLauDNfpbrX55Q9jrGHThw2ZMdOky5Gl1CDtVeJDPVrG4Jxx1N8jw2gkWaff5UUuX1KJd+9zGe2B+ZA==" 97 | }, 98 | "fast-json-stable-stringify": { 99 | "version": "2.1.0", 100 | "resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz", 101 | "integrity": "sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==" 102 | }, 103 | "fast-json-stringify": { 104 | "version": "1.20.1", 105 | "resolved": "https://registry.npmjs.org/fast-json-stringify/-/fast-json-stringify-1.20.1.tgz", 106 | "integrity": "sha512-PEPWrRZvKqI11fY2uDhLLuoapIda9wVQ2mzAj8rkBfVD7jWvOSIICL0Om1knoReIWKF5y/5bbR/GzcZANaaJfQ==", 107 | "requires": { 108 | "ajv": "^6.11.0", 109 | "deepmerge": "^4.2.2", 110 | "string-similarity": "^4.0.1" 111 | } 112 | }, 113 | "fast-redact": { 114 | "version": "2.0.0", 115 | "resolved": "https://registry.npmjs.org/fast-redact/-/fast-redact-2.0.0.tgz", 116 | "integrity": "sha512-zxpkULI9W9MNTK2sJ3BpPQrTEXFNESd2X6O1tXMFpK/XM0G5c5Rll2EVYZH2TqI3xRGK/VaJ+eEOt7pnENJpeA==" 117 | }, 118 | "fast-safe-stringify": { 119 | "version": "2.0.7", 120 | "resolved": "https://registry.npmjs.org/fast-safe-stringify/-/fast-safe-stringify-2.0.7.tgz", 121 | "integrity": "sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA==" 122 | }, 123 | "fastify": { 124 | "version": "2.14.1", 125 | "resolved": "https://registry.npmjs.org/fastify/-/fastify-2.14.1.tgz", 126 | "integrity": "sha512-nSL8AgIdFCpZmFwjqB5Zzv+3/1KpwwVtB/h88Q4Og8njYbkddKGpuQlQ2tHUULXPTJrLZ7wop6olzx6HEbHdpw==", 127 | "requires": { 128 | "abstract-logging": "^2.0.0", 129 | "ajv": "^6.12.0", 130 | "avvio": "^6.3.1", 131 | "fast-json-stringify": "^1.18.0", 132 | "find-my-way": "^2.2.2", 133 | "flatstr": "^1.0.12", 134 | "light-my-request": "^3.7.3", 135 | "middie": "^4.1.0", 136 | "pino": "^5.17.0", 137 | "proxy-addr": "^2.0.6", 138 | "readable-stream": "^3.6.0", 139 | "rfdc": "^1.1.2", 140 | "secure-json-parse": "^2.1.0", 141 | "tiny-lru": "^7.0.2" 142 | } 143 | }, 144 | "fastq": { 145 | "version": "1.7.0", 146 | "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.7.0.tgz", 147 | "integrity": "sha512-YOadQRnHd5q6PogvAR/x62BGituF2ufiEA6s8aavQANw5YKHERI4AREboX6KotzP8oX2klxYF2wcV/7bn1clfQ==", 148 | "requires": { 149 | "reusify": "^1.0.4" 150 | } 151 | }, 152 | "find-my-way": { 153 | "version": "2.2.2", 154 | "resolved": "https://registry.npmjs.org/find-my-way/-/find-my-way-2.2.2.tgz", 155 | "integrity": "sha512-zk3eOsS1tABNQjII0vCbhkqgsX/COpRUxl0b5rlA41V2Ft7jWDr30LhYq4BZXLAlzw5yskg24XQG/U1wCT30vQ==", 156 | "requires": { 157 | "fast-decode-uri-component": "^1.0.0", 158 | "safe-regex2": "^2.0.0", 159 | "semver-store": "^0.3.0" 160 | } 161 | }, 162 | "flatstr": { 163 | "version": "1.0.12", 164 | "resolved": "https://registry.npmjs.org/flatstr/-/flatstr-1.0.12.tgz", 165 | "integrity": "sha512-4zPxDyhCyiN2wIAtSLI6gc82/EjqZc1onI4Mz/l0pWrAlsSfYH/2ZIcU+e3oA2wDwbzIWNKwa23F8rh6+DRWkw==" 166 | }, 167 | "forwarded": { 168 | "version": "0.1.2", 169 | "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.1.2.tgz", 170 | "integrity": "sha1-mMI9qxF1ZXuMBXPozszZGw/xjIQ=" 171 | }, 172 | "fs.realpath": { 173 | "version": "1.0.0", 174 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 175 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", 176 | "dev": true 177 | }, 178 | "glob": { 179 | "version": "7.1.6", 180 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", 181 | "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", 182 | "dev": true, 183 | "requires": { 184 | "fs.realpath": "^1.0.0", 185 | "inflight": "^1.0.4", 186 | "inherits": "2", 187 | "minimatch": "^3.0.4", 188 | "once": "^1.3.0", 189 | "path-is-absolute": "^1.0.0" 190 | } 191 | }, 192 | "inflight": { 193 | "version": "1.0.6", 194 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 195 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 196 | "dev": true, 197 | "requires": { 198 | "once": "^1.3.0", 199 | "wrappy": "1" 200 | } 201 | }, 202 | "inherits": { 203 | "version": "2.0.3", 204 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 205 | "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" 206 | }, 207 | "ipaddr.js": { 208 | "version": "1.9.1", 209 | "resolved": "https://registry.npmjs.org/ipaddr.js/-/ipaddr.js-1.9.1.tgz", 210 | "integrity": "sha512-0KI/607xoxSToH7GjN1FfSbLoU0+btTicjsQSWQlh/hZykN8KpmMf7uYwPW3R+akZ6R/w18ZlXSHBYXiYUPO3g==" 211 | }, 212 | "json-schema-traverse": { 213 | "version": "0.4.1", 214 | "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz", 215 | "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==" 216 | }, 217 | "light-my-request": { 218 | "version": "3.8.0", 219 | "resolved": "https://registry.npmjs.org/light-my-request/-/light-my-request-3.8.0.tgz", 220 | "integrity": "sha512-cIOWmNsgoStysmkzcv2EwvLwMb2hEm6oqKMerG/b5ey9F0we2Qony8cAZgBktmGPYUvPyKsDCzMcYU6fXbpWew==", 221 | "requires": { 222 | "ajv": "^6.10.2", 223 | "cookie": "^0.4.0", 224 | "readable-stream": "^3.4.0", 225 | "set-cookie-parser": "^2.4.1" 226 | } 227 | }, 228 | "middie": { 229 | "version": "4.1.0", 230 | "resolved": "https://registry.npmjs.org/middie/-/middie-4.1.0.tgz", 231 | "integrity": "sha512-eylPpZA+K3xO9kpDjagoPkEUkNcWV3EAo5OEz0MqsekUpT7KbnQkk8HNZkh4phx2vvOAmNNZuLRWF9lDDHPpVQ==", 232 | "requires": { 233 | "path-to-regexp": "^4.0.0", 234 | "reusify": "^1.0.2" 235 | } 236 | }, 237 | "minimatch": { 238 | "version": "3.0.4", 239 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 240 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 241 | "dev": true, 242 | "requires": { 243 | "brace-expansion": "^1.1.7" 244 | } 245 | }, 246 | "ms": { 247 | "version": "2.1.2", 248 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 249 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" 250 | }, 251 | "once": { 252 | "version": "1.4.0", 253 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 254 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 255 | "dev": true, 256 | "requires": { 257 | "wrappy": "1" 258 | } 259 | }, 260 | "path-is-absolute": { 261 | "version": "1.0.1", 262 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 263 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", 264 | "dev": true 265 | }, 266 | "path-to-regexp": { 267 | "version": "4.0.5", 268 | "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-4.0.5.tgz", 269 | "integrity": "sha512-l+fTaGG2N9ZRpCEUj5fG1VKdDLaiqwCIvPngpnxzREhcdobhZC4ou4w984HBu72DqAJ5CfcdV6tjqNOunfpdsQ==" 270 | }, 271 | "pino": { 272 | "version": "5.17.0", 273 | "resolved": "https://registry.npmjs.org/pino/-/pino-5.17.0.tgz", 274 | "integrity": "sha512-LqrqmRcJz8etUjyV0ddqB6OTUutCgQULPFg2b4dtijRHUsucaAdBgSUW58vY6RFSX+NT8963F+q0tM6lNwGShA==", 275 | "requires": { 276 | "fast-redact": "^2.0.0", 277 | "fast-safe-stringify": "^2.0.7", 278 | "flatstr": "^1.0.12", 279 | "pino-std-serializers": "^2.4.2", 280 | "quick-format-unescaped": "^3.0.3", 281 | "sonic-boom": "^0.7.5" 282 | } 283 | }, 284 | "pino-std-serializers": { 285 | "version": "2.4.2", 286 | "resolved": "https://registry.npmjs.org/pino-std-serializers/-/pino-std-serializers-2.4.2.tgz", 287 | "integrity": "sha512-WaL504dO8eGs+vrK+j4BuQQq6GLKeCCcHaMB2ItygzVURcL1CycwNEUHTD/lHFHs/NL5qAz2UKrjYWXKSf4aMQ==" 288 | }, 289 | "proxy-addr": { 290 | "version": "2.0.6", 291 | "resolved": "https://registry.npmjs.org/proxy-addr/-/proxy-addr-2.0.6.tgz", 292 | "integrity": "sha512-dh/frvCBVmSsDYzw6n926jv974gddhkFPfiN8hPOi30Wax25QZyZEGveluCgliBnqmuM+UJmBErbAUFIoDbjOw==", 293 | "requires": { 294 | "forwarded": "~0.1.2", 295 | "ipaddr.js": "1.9.1" 296 | } 297 | }, 298 | "punycode": { 299 | "version": "2.1.1", 300 | "resolved": "https://registry.npmjs.org/punycode/-/punycode-2.1.1.tgz", 301 | "integrity": "sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A==" 302 | }, 303 | "quick-format-unescaped": { 304 | "version": "3.0.3", 305 | "resolved": "https://registry.npmjs.org/quick-format-unescaped/-/quick-format-unescaped-3.0.3.tgz", 306 | "integrity": "sha512-dy1yjycmn9blucmJLXOfZDx1ikZJUi6E8bBZLnhPG5gBrVhHXx2xVyqqgKBubVNEXmx51dBACMHpoMQK/N/AXQ==" 307 | }, 308 | "readable-stream": { 309 | "version": "3.6.0", 310 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz", 311 | "integrity": "sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==", 312 | "requires": { 313 | "inherits": "^2.0.3", 314 | "string_decoder": "^1.1.1", 315 | "util-deprecate": "^1.0.1" 316 | } 317 | }, 318 | "ret": { 319 | "version": "0.2.2", 320 | "resolved": "https://registry.npmjs.org/ret/-/ret-0.2.2.tgz", 321 | "integrity": "sha512-M0b3YWQs7R3Z917WRQy1HHA7Ba7D8hvZg6UE5mLykJxQVE2ju0IXbGlaHPPlkY+WN7wFP+wUMXmBFA0aV6vYGQ==" 322 | }, 323 | "reusify": { 324 | "version": "1.0.4", 325 | "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz", 326 | "integrity": "sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==" 327 | }, 328 | "rfdc": { 329 | "version": "1.1.4", 330 | "resolved": "https://registry.npmjs.org/rfdc/-/rfdc-1.1.4.tgz", 331 | "integrity": "sha512-5C9HXdzK8EAqN7JDif30jqsBzavB7wLpaubisuQIGHWf2gUXSpzy6ArX/+Da8RjFpagWsCn+pIgxTMAmKw9Zug==" 332 | }, 333 | "rimraf": { 334 | "version": "3.0.2", 335 | "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", 336 | "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", 337 | "dev": true, 338 | "requires": { 339 | "glob": "^7.1.3" 340 | } 341 | }, 342 | "safe-buffer": { 343 | "version": "5.2.0", 344 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", 345 | "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" 346 | }, 347 | "safe-regex2": { 348 | "version": "2.0.0", 349 | "resolved": "https://registry.npmjs.org/safe-regex2/-/safe-regex2-2.0.0.tgz", 350 | "integrity": "sha512-PaUSFsUaNNuKwkBijoAPHAK6/eM6VirvyPWlZ7BAQy4D+hCvh4B6lIG+nPdhbFfIbP+gTGBcrdsOaUs0F+ZBOQ==", 351 | "requires": { 352 | "ret": "~0.2.0" 353 | } 354 | }, 355 | "secure-json-parse": { 356 | "version": "2.1.0", 357 | "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.1.0.tgz", 358 | "integrity": "sha512-GckO+MS/wT4UogDyoI/H/S1L0MCcKS1XX/vp48wfmU7Nw4woBmb8mIpu4zPBQjKlRT88/bt9xdoV4111jPpNJA==" 359 | }, 360 | "semver-store": { 361 | "version": "0.3.0", 362 | "resolved": "https://registry.npmjs.org/semver-store/-/semver-store-0.3.0.tgz", 363 | "integrity": "sha512-TcZvGMMy9vodEFSse30lWinkj+JgOBvPn8wRItpQRSayhc+4ssDs335uklkfvQQJgL/WvmHLVj4Ycv2s7QCQMg==" 364 | }, 365 | "set-cookie-parser": { 366 | "version": "2.4.5", 367 | "resolved": "https://registry.npmjs.org/set-cookie-parser/-/set-cookie-parser-2.4.5.tgz", 368 | "integrity": "sha512-LkSDwseogN5l6TerqGzFzL9mUDTxSq3hX2b5AaynjC1nSCNWiDypEgHatfc0v6KcnfgV3/6F6h4ABh6igjzlQQ==" 369 | }, 370 | "sonic-boom": { 371 | "version": "0.7.7", 372 | "resolved": "https://registry.npmjs.org/sonic-boom/-/sonic-boom-0.7.7.tgz", 373 | "integrity": "sha512-Ei5YOo5J64GKClHIL/5evJPgASXFVpfVYbJV9PILZQytTK6/LCwHvsZJW2Ig4p9FMC2OrBrMnXKgRN/OEoAWfg==", 374 | "requires": { 375 | "atomic-sleep": "^1.0.0", 376 | "flatstr": "^1.0.12" 377 | } 378 | }, 379 | "string-similarity": { 380 | "version": "4.0.1", 381 | "resolved": "https://registry.npmjs.org/string-similarity/-/string-similarity-4.0.1.tgz", 382 | "integrity": "sha512-v36MJzloekKVvKAsYi6O/qpn2mIuvwEFIT9Gx3yg4spkNjXYsk7yxc37g4ZTyMVIBvt/9PZGxnqEtme8XHK+Mw==" 383 | }, 384 | "string_decoder": { 385 | "version": "1.3.0", 386 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", 387 | "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", 388 | "requires": { 389 | "safe-buffer": "~5.2.0" 390 | } 391 | }, 392 | "tiny-lru": { 393 | "version": "7.0.2", 394 | "resolved": "https://registry.npmjs.org/tiny-lru/-/tiny-lru-7.0.2.tgz", 395 | "integrity": "sha512-cmc9OOwmnAJtyFBYaznKR3abypEhWecarFrvS5db6qwSgoaDUWV0JX+mdh6B9wN60Wux3+gE1vjzxkoqxFBjqw==" 396 | }, 397 | "typescript": { 398 | "version": "3.8.3", 399 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", 400 | "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", 401 | "dev": true 402 | }, 403 | "uri-js": { 404 | "version": "4.2.2", 405 | "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.2.2.tgz", 406 | "integrity": "sha512-KY9Frmirql91X2Qgjry0Wd4Y+YTdrdZheS8TFwvkbLWf/G5KNJDCh6pKL5OZctEW4+0Baa5idK2ZQuELRwPznQ==", 407 | "requires": { 408 | "punycode": "^2.1.0" 409 | } 410 | }, 411 | "util-deprecate": { 412 | "version": "1.0.2", 413 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 414 | "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" 415 | }, 416 | "wrappy": { 417 | "version": "1.0.2", 418 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 419 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", 420 | "dev": true 421 | } 422 | } 423 | } 424 | -------------------------------------------------------------------------------- /packages/app/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "app", 3 | "version": "0.0.0", 4 | "private": true, 5 | "author": "kevinpollet ", 6 | "license": "MIT", 7 | "homepage": "https://github.com/kevinpollet/typescript-es-modules-node-example/tree/master/packages/server#readme", 8 | "repository": { 9 | "type": "git", 10 | "url": "git+https://github.com/kevinpollet/typescript-node12-modules-example.git" 11 | }, 12 | "bugs": { 13 | "url": "https://github.com/kevinpollet/typescript-node12-modules-example/issues" 14 | }, 15 | "main": "lib/app.js", 16 | "type": "module", 17 | "files": [ 18 | "lib" 19 | ], 20 | "scripts": { 21 | "clean": "rimraf lib", 22 | "build": "tsc", 23 | "start": "node --experimental-modules --es-module-specifier-resolution=node lib/server.js", 24 | "prebuild": "npm run clean" 25 | }, 26 | "devDependencies": { 27 | "rimraf": "^3.0.2", 28 | "typescript": "^3.8.3" 29 | }, 30 | "dependencies": { 31 | "@types/node": "^12.12.30", 32 | "es-module": "0.0.0", 33 | "fastify": "^2.14.1" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/app/src/app.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2019 kevinpollet ` 3 | * 4 | * Use of this source code is governed by an MIT-style license that can be 5 | * found in the LICENSE.md file. 6 | */ 7 | 8 | import { sayHello } from "es-module"; 9 | import fastify from "fastify"; 10 | import { sayHelloLocal } from "./sayHelloLocal"; 11 | 12 | fastify({ logger: true }) 13 | .get("*", async (_, reply) => 14 | reply.send({ messages: [sayHello(), sayHelloLocal()] }) 15 | ) 16 | .listen(3000); 17 | -------------------------------------------------------------------------------- /packages/app/src/sayHelloLocal.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2019 kevinpollet ` 3 | * 4 | * Use of this source code is governed by an MIT-style license that can be 5 | * found in the LICENSE.md file. 6 | */ 7 | 8 | export const sayHelloLocal = () => "Hello from local ES Module"; 9 | -------------------------------------------------------------------------------- /packages/app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.settings.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "outDir": "lib", 6 | "rootDir": "src" 7 | }, 8 | "include": ["src"] 9 | } 10 | -------------------------------------------------------------------------------- /packages/es-module/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "es-module", 3 | "version": "0.0.0", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "balanced-match": { 8 | "version": "1.0.0", 9 | "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", 10 | "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=", 11 | "dev": true 12 | }, 13 | "brace-expansion": { 14 | "version": "1.1.11", 15 | "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", 16 | "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", 17 | "dev": true, 18 | "requires": { 19 | "balanced-match": "^1.0.0", 20 | "concat-map": "0.0.1" 21 | } 22 | }, 23 | "concat-map": { 24 | "version": "0.0.1", 25 | "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 26 | "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=", 27 | "dev": true 28 | }, 29 | "fs.realpath": { 30 | "version": "1.0.0", 31 | "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", 32 | "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=", 33 | "dev": true 34 | }, 35 | "glob": { 36 | "version": "7.1.6", 37 | "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", 38 | "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", 39 | "dev": true, 40 | "requires": { 41 | "fs.realpath": "^1.0.0", 42 | "inflight": "^1.0.4", 43 | "inherits": "2", 44 | "minimatch": "^3.0.4", 45 | "once": "^1.3.0", 46 | "path-is-absolute": "^1.0.0" 47 | } 48 | }, 49 | "inflight": { 50 | "version": "1.0.6", 51 | "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", 52 | "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", 53 | "dev": true, 54 | "requires": { 55 | "once": "^1.3.0", 56 | "wrappy": "1" 57 | } 58 | }, 59 | "inherits": { 60 | "version": "2.0.4", 61 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 62 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", 63 | "dev": true 64 | }, 65 | "minimatch": { 66 | "version": "3.0.4", 67 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", 68 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", 69 | "dev": true, 70 | "requires": { 71 | "brace-expansion": "^1.1.7" 72 | } 73 | }, 74 | "once": { 75 | "version": "1.4.0", 76 | "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", 77 | "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", 78 | "dev": true, 79 | "requires": { 80 | "wrappy": "1" 81 | } 82 | }, 83 | "path-is-absolute": { 84 | "version": "1.0.1", 85 | "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", 86 | "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", 87 | "dev": true 88 | }, 89 | "rimraf": { 90 | "version": "3.0.2", 91 | "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", 92 | "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", 93 | "dev": true, 94 | "requires": { 95 | "glob": "^7.1.3" 96 | } 97 | }, 98 | "typescript": { 99 | "version": "3.8.3", 100 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.8.3.tgz", 101 | "integrity": "sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==", 102 | "dev": true 103 | }, 104 | "wrappy": { 105 | "version": "1.0.2", 106 | "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", 107 | "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=", 108 | "dev": true 109 | } 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /packages/es-module/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "es-module", 3 | "version": "0.0.0", 4 | "private": true, 5 | "description": "ES Module transpiled with TypeScript", 6 | "author": "kevinpollet ", 7 | "license": "MIT", 8 | "homepage": "https://github.com/kevinpollet/typescript-es-modules-node-example/tree/master/packages/es-module#readme", 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/kevinpollet/typescript-node12-modules-example.git" 12 | }, 13 | "bugs": { 14 | "url": "https://github.com/kevinpollet/typescript-node12-modules-example/issues" 15 | }, 16 | "main": "lib/index.js", 17 | "type": "module", 18 | "files": [ 19 | "lib" 20 | ], 21 | "scripts": { 22 | "clean": "rimraf lib", 23 | "build": "tsc", 24 | "prebuild": "npm run clean" 25 | }, 26 | "devDependencies": { 27 | "rimraf": "^3.0.2", 28 | "typescript": "^3.8.3" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/es-module/src/index.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2019 kevinpollet ` 3 | * 4 | * Use of this source code is governed by an MIT-style license that can be 5 | * found in the LICENSE.md file. 6 | */ 7 | 8 | export const sayHello = () => "Hello from ES Module dependency"; 9 | -------------------------------------------------------------------------------- /packages/es-module/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.settings.json", 3 | "compilerOptions": { 4 | "declaration": true, 5 | "outDir": "lib", 6 | "rootDir": "src" 7 | }, 8 | "include": ["src"] 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@kevinpollet/tsconfig", 3 | "compilerOptions": { 4 | "lib": ["es2019"], 5 | "module": "esnext", 6 | "target": "es2019" 7 | } 8 | } 9 | --------------------------------------------------------------------------------