From c666b4bd86d117cbafadb6d048ad4cf3a985a45f Mon Sep 17 00:00:00 2001 From: Eugene Terehov Date: Wed, 16 Nov 2022 15:35:32 +0200 Subject: [PATCH] Update README --- README.md | 60 ++++++++++++++++++++++++++++++++++++++++---------- docs/README.md | 60 ++++++++++++++++++++++++++++++++++++++++---------- tsconfig.json | 2 +- 3 files changed, 97 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 712d633..afb01fa 100644 --- a/README.md +++ b/README.md @@ -49,32 +49,51 @@ Donations help me allocate more time for my open source work. ## Install +> ❗ **`tslog` is a native ES module.** + ```bash npm install tslog ``` -**Enable TypeScript source map support:** +In order to run a native ES module in Node.js, you have to do two things: -This feature enables `tslog` to reference a correct line number in your TypeScript source code. +1) Set `"type": "module` in `package.json`. +2) Start with `--experimental-specifier-resolution=node` -```json5 -// tsconfig.json +Example `package.json` +```json { - // ... - compilerOptions: { - // ... - sourceMap: true, - // we recommend using a current ES version - target: "es2020", + "name": "bot", + "version": "1.0.0", + "main": "dist/app.js", + "type": "module", // <-- here + "scripts": { + "build": "tsc -p .", + "start": "node --enable-source-maps --experimental-specifier-resolution=node index.js" // <-- and here + }, + "dependencies": { + "tslog": "^4" + }, + "devDependencies": { + "typescript": "^4.8.4" }, + "engines": { + "node": ">=16" + } } ``` -And run with: +With this `package.json` you can simply build and run it: +```bash +npm run build +npm start +``` + +**Otherwise:** Node.js with JavaScript: ```bash -node --enable-source-maps +node --enable-source-maps --experimental-specifier-resolution=node ``` Node.js with TypeScript and `ts-node` (with ESM support): @@ -103,6 +122,23 @@ Browser: ``` +**Enable TypeScript source map support:** + +This feature enables `tslog` to reference a correct line number in your TypeScript source code. + +```json5 +// tsconfig.json +{ + // ... + compilerOptions: { + // ... + "inlineSourceMap": true, //