@tsonic/nodejs 10.0.37 → 10.0.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -27
- package/package.json +1 -1
- package/tsonic.bindings.json +6 -0
package/README.md
CHANGED
|
@@ -15,18 +15,22 @@ Use `@tsonic/nodejs` when you want Node-like modules (`fs`, `path`, `events`, `c
|
|
|
15
15
|
|
|
16
16
|
```bash
|
|
17
17
|
mkdir my-app && cd my-app
|
|
18
|
-
npx --yes tsonic@latest init
|
|
18
|
+
npx --yes tsonic@latest init --surface nodejs
|
|
19
19
|
npx --yes tsonic@latest add npm @tsonic/nodejs
|
|
20
|
+
```
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
import {
|
|
22
|
+
```ts
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
import { readFileSync } from "node:fs";
|
|
24
25
|
|
|
25
26
|
export function main(): void {
|
|
26
|
-
|
|
27
|
+
const fullPath = join("src", "App.ts");
|
|
28
|
+
console.log(fullPath);
|
|
29
|
+
console.log(readFileSync(fullPath, "utf-8"));
|
|
27
30
|
}
|
|
28
|
-
|
|
31
|
+
```
|
|
29
32
|
|
|
33
|
+
```bash
|
|
30
34
|
npm run dev
|
|
31
35
|
```
|
|
32
36
|
|
|
@@ -36,6 +40,12 @@ npm run dev
|
|
|
36
40
|
npx --yes tsonic@latest add npm @tsonic/nodejs
|
|
37
41
|
```
|
|
38
42
|
|
|
43
|
+
If the workspace is not already Node surface, set:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
npx --yes tsonic@latest init --surface nodejs
|
|
47
|
+
```
|
|
48
|
+
|
|
39
49
|
## Versioning
|
|
40
50
|
|
|
41
51
|
This repo is versioned by runtime major:
|
|
@@ -51,32 +61,29 @@ When publishing, run: `npm publish versions/10 --access public`
|
|
|
51
61
|
|
|
52
62
|
## Usage
|
|
53
63
|
|
|
54
|
-
### File System
|
|
64
|
+
### File System (`node:fs`)
|
|
55
65
|
|
|
56
66
|
```typescript
|
|
57
|
-
import {
|
|
58
|
-
|
|
59
|
-
// Read file
|
|
60
|
-
const content = fs.readFileSync("./package.json", "utf-8");
|
|
67
|
+
import { readFileSync, writeFileSync } from "node:fs";
|
|
61
68
|
|
|
62
|
-
|
|
63
|
-
|
|
69
|
+
const content = readFileSync("./package.json", "utf-8");
|
|
70
|
+
writeFileSync("./output.txt", "Hello from Tsonic!");
|
|
64
71
|
```
|
|
65
72
|
|
|
66
|
-
### Path Operations
|
|
73
|
+
### Path Operations (`node:path`)
|
|
67
74
|
|
|
68
75
|
```typescript
|
|
69
|
-
import {
|
|
76
|
+
import { join, extname, dirname } from "node:path";
|
|
70
77
|
|
|
71
|
-
const fullPath =
|
|
72
|
-
const ext =
|
|
73
|
-
const dir =
|
|
78
|
+
const fullPath = join("config", "settings.json");
|
|
79
|
+
const ext = extname(fullPath); // ".json"
|
|
80
|
+
const dir = dirname(fullPath);
|
|
74
81
|
```
|
|
75
82
|
|
|
76
83
|
### Events
|
|
77
84
|
|
|
78
85
|
```typescript
|
|
79
|
-
import { EventEmitter
|
|
86
|
+
import { EventEmitter } from "@tsonic/nodejs/index.js";
|
|
80
87
|
|
|
81
88
|
class MyEmitter extends EventEmitter {}
|
|
82
89
|
const emitter = new MyEmitter();
|
|
@@ -86,16 +93,16 @@ emitter.on("data", (chunk) => console.log(chunk));
|
|
|
86
93
|
### Crypto
|
|
87
94
|
|
|
88
95
|
```ts
|
|
89
|
-
import {
|
|
96
|
+
import { randomUUID } from "node:crypto";
|
|
90
97
|
|
|
91
|
-
const
|
|
92
|
-
void
|
|
98
|
+
const id = randomUUID();
|
|
99
|
+
void id;
|
|
93
100
|
```
|
|
94
101
|
|
|
95
102
|
### Process
|
|
96
103
|
|
|
97
104
|
```ts
|
|
98
|
-
import
|
|
105
|
+
import * as process from "node:process";
|
|
99
106
|
|
|
100
107
|
const cwd = process.cwd();
|
|
101
108
|
void cwd;
|
|
@@ -109,12 +116,16 @@ import { http } from "@tsonic/nodejs/nodejs.Http.js";
|
|
|
109
116
|
|
|
110
117
|
## Imports (important)
|
|
111
118
|
|
|
112
|
-
|
|
119
|
+
For `--surface nodejs` projects, prefer Node-style imports:
|
|
120
|
+
|
|
121
|
+
- `node:fs`, `node:path`, `node:crypto`, `node:process`, ...
|
|
122
|
+
- bare aliases (`fs`, `path`, `crypto`, ...) are also supported
|
|
123
|
+
|
|
124
|
+
Direct ESM imports from `@tsonic/nodejs/index.js` are still supported.
|
|
113
125
|
|
|
114
|
-
|
|
115
|
-
- submodules like `@tsonic/nodejs/nodejs.Http.js` for separately emitted namespaces
|
|
126
|
+
`node:http` is currently not mapped by the surface alias set; use:
|
|
116
127
|
|
|
117
|
-
|
|
128
|
+
- `@tsonic/nodejs/nodejs.Http.js`
|
|
118
129
|
|
|
119
130
|
## Relationship to `@tsonic/js`
|
|
120
131
|
|
package/package.json
CHANGED
package/tsonic.bindings.json
CHANGED