File tree Expand file tree Collapse file tree 3 files changed +97
-25
lines changed Expand file tree Collapse file tree 3 files changed +97
-25
lines changed Original file line number Diff line number Diff line change @@ -49,32 +49,51 @@ Donations help me allocate more time for my open source work.
4949
5050## Install
5151
52+ > ❗ ** ` tslog ` is a native ES module.**
53+
5254``` bash
5355npm install tslog
5456```
5557
56- ** Enable TypeScript source map support: **
58+ In order to run a native ES module in Node.js, you have to do two things:
5759
58- This feature enables ` tslog ` to reference a correct line number in your TypeScript source code.
60+ 1 ) Set ` "type": "module ` in ` package.json ` .
61+ 2 ) Start with ` --experimental-specifier-resolution=node `
5962
60- ``` json5
61- // tsconfig. json
63+ Example ` package.json `
64+ ``` json
6265{
63- // ...
64- compilerOptions: {
65- // ...
66- sourceMap: true ,
67- // we recommend using a current ES version
68- target: " es2020" ,
66+ "name" : " bot" ,
67+ "version" : " 1.0.0" ,
68+ "main" : " dist/app.js" ,
69+ "type" : " module" , // <-- here
70+ "scripts" : {
71+ "build" : " tsc -p ." ,
72+ "start" : " node --enable-source-maps --experimental-specifier-resolution=node index.js" // <-- and here
73+ },
74+ "dependencies" : {
75+ "tslog" : " ^4"
76+ },
77+ "devDependencies" : {
78+ "typescript" : " ^4.8.4"
6979 },
80+ "engines" : {
81+ "node" : " >=16"
82+ }
7083}
7184```
7285
73- And run with:
86+ With this ` package.json ` you can simply build and run it:
87+ ``` bash
88+ npm run build
89+ npm start
90+ ```
91+
92+ ** Otherwise:**
7493
7594Node.js with JavaScript:
7695``` bash
77- node --enable-source-maps
96+ node --enable-source-maps --experimental-specifier-resolution=node
7897```
7998
8099Node.js with TypeScript and ` ts-node ` (with ESM support):
@@ -103,6 +122,23 @@ Browser:
103122</html >
104123```
105124
125+ ** Enable TypeScript source map support:**
126+
127+ This feature enables ` tslog ` to reference a correct line number in your TypeScript source code.
128+
129+ ``` json5
130+ // tsconfig.json
131+ {
132+ // ...
133+ compilerOptions: {
134+ // ...
135+ " inlineSourceMap" : true , // <!-- here
136+ // we recommend using a current ES version
137+ target: " es2020" ,
138+ },
139+ }
140+ ```
141+
106142## Simple example
107143
108144``` typescript
Original file line number Diff line number Diff line change @@ -49,32 +49,51 @@ Donations help me allocate more time for my open source work.
4949
5050## Install
5151
52+ > ❗ ** ` tslog ` is a native ES module.**
53+
5254``` bash
5355npm install tslog
5456```
5557
56- ** Enable TypeScript source map support: **
58+ In order to run a native ES module in Node.js, you have to do two things:
5759
58- This feature enables ` tslog ` to reference a correct line number in your TypeScript source code.
60+ 1 ) Set ` "type": "module ` in ` package.json ` .
61+ 2 ) Start with ` --experimental-specifier-resolution=node `
5962
60- ``` json5
61- // tsconfig. json
63+ Example ` package.json `
64+ ``` json
6265{
63- // ...
64- compilerOptions: {
65- // ...
66- sourceMap: true ,
67- // we recommend using a current ES version
68- target: " es2020" ,
66+ "name" : " bot" ,
67+ "version" : " 1.0.0" ,
68+ "main" : " dist/app.js" ,
69+ "type" : " module" , // <-- here
70+ "scripts" : {
71+ "build" : " tsc -p ." ,
72+ "start" : " node --enable-source-maps --experimental-specifier-resolution=node index.js" // <-- and here
73+ },
74+ "dependencies" : {
75+ "tslog" : " ^4"
76+ },
77+ "devDependencies" : {
78+ "typescript" : " ^4.8.4"
6979 },
80+ "engines" : {
81+ "node" : " >=16"
82+ }
7083}
7184```
7285
73- And run with:
86+ With this ` package.json ` you can simply build and run it:
87+ ``` bash
88+ npm run build
89+ npm start
90+ ```
91+
92+ ** Otherwise:**
7493
7594Node.js with JavaScript:
7695``` bash
77- node --enable-source-maps
96+ node --enable-source-maps --experimental-specifier-resolution=node
7897```
7998
8099Node.js with TypeScript and ` ts-node ` (with ESM support):
@@ -103,6 +122,23 @@ Browser:
103122</html >
104123```
105124
125+ ** Enable TypeScript source map support:**
126+
127+ This feature enables ` tslog ` to reference a correct line number in your TypeScript source code.
128+
129+ ``` json5
130+ // tsconfig.json
131+ {
132+ // ...
133+ compilerOptions: {
134+ // ...
135+ " inlineSourceMap" : true , // <!-- here
136+ // we recommend using a current ES version
137+ target: " es2020" ,
138+ },
139+ }
140+ ```
141+
106142## Simple example
107143
108144``` typescript
Original file line number Diff line number Diff line change 99 "moduleResolution" : " Node" ,
1010 "emitDecoratorMetadata" : true ,
1111 "experimentalDecorators" : true ,
12- "sourceMap " : true ,
12+ "inlineSourceMap " : true ,
1313 "strict" : true ,
1414 "skipLibCheck" : true ,
1515 "suppressImplicitAnyIndexErrors" : true ,
You can’t perform that action at this time.
0 commit comments