Skip to content

Commit 50a8de6

Browse files
committed
Node. Unify approach to default export handling
1 parent 079519a commit 50a8de6

File tree

8 files changed

+57
-14
lines changed

8 files changed

+57
-14
lines changed

kotlin-node/karakum/src/jsMain/kotlin/node/karakum/Main.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,14 +290,12 @@ suspend fun main() {
290290
"**/module/exports.kt",
291291
"**/module/module.val.kt",
292292
"**/path/namespace.kt",
293-
"**/path/path.kt",
294293
"**/path/PlatformPathDelimiter.kt",
295294
"**/path/PlatformPathSep.kt",
296295
"**/path/posix/**",
297296
"**/path/win32/**",
298297
"**/perfHooks/global/**",
299298
"**/process/global/namespace.kt",
300-
"**/process/global/process.kt",
301299
"**/querystring/decode.kt",
302300
"**/querystring/encode.kt",
303301
"**/readline/createInterface.kt",
@@ -340,6 +338,7 @@ suspend fun main() {
340338
"node:node:" to "node:",
341339
"node:assert(#assert)?" to "node:assert/strict",
342340
"node:globals" to "",
341+
"node:process#global" to "node:process",
343342
"events#EventEmitter" to "events",
344343
"module#Module" to "module",
345344
)
@@ -429,6 +428,7 @@ suspend fun main() {
429428

430429
"^process/global/nodejs/Process.kt" to "node/process/Process.interface.kt",
431430
"^process/global/nodejs/(.+)\\.kt" to "node/process/$1.kt",
431+
"^process/global/(.+)\\.kt" to "node/process/$1.kt",
432432
"^process" to "node/process",
433433

434434
"^querystring" to "node/querystring",

kotlin-node/karakum/src/jsMain/kotlin/node/karakum/annotations/annotateDefaultExports.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@ fun annotateDefaultExports(node: Node, context: AnnotationContext) = nullable {
2727
ensure(isIdentifier(name))
2828
ensure(name.text == "cluster")
2929

30+
"@JsName(\"default\")"
31+
} ?: nullable {
32+
ensure(sourceFileName.endsWith("path.d.ts"))
33+
34+
ensure(isVariableDeclaration(node))
35+
36+
val name = node.name
37+
ensure(isIdentifier(name))
38+
ensure(name.text == "path")
39+
40+
"@JsName(\"default\")"
41+
} ?: nullable {
42+
ensure(sourceFileName.endsWith("process.d.ts"))
43+
44+
ensure(isVariableDeclaration(node))
45+
46+
val name = node.name
47+
ensure(isIdentifier(name))
48+
ensure(name.text == "process")
49+
3050
"@JsName(\"default\")"
3151
}
3252
}

kotlin-node/karakum/src/jsMain/kotlin/node/karakum/plugins/convertModuleQualifiedName.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ private val modules = setOf(
1414
"tls",
1515
"fs",
1616
"http",
17+
"path",
1718
)
1819

1920
val convertModuleQualifiedName = createPlugin { node, _, render ->

kotlin-node/karakum/src/jsMain/kotlin/node/karakum/plugins/convertNodeJsQualifiedName.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ val convertNodeJsQualifiedName = createPlugin { node, _, render ->
1919
"AsyncIterator" -> "js.iterable.AsyncIterator"
2020
"ArrayBufferView" -> "js.buffer.ArrayBufferView"
2121
"TypedArray" -> "js.typedarrays.TypedArray"
22+
2223
"EventEmitter" -> "node.events.EventEmitter"
24+
2325
"Module" -> "node.module.Module"
2426
"Require" -> "node.module.Require"
27+
28+
"Process" -> "node.process.Process"
2529
"Signals" -> "node.process.Signals"
2630
"ProcessEnv" -> "node.process.ProcessEnv"
2731
"Platform" -> "node.process.Platform"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Generated by Karakum - do not modify it manually!
2+
3+
@file:JsModule("node:path")
4+
5+
package node.path
6+
7+
@JsName("default")
8+
external val path: PlatformPath
9+
10+
/**
11+
* The `node:path` module provides utilities for working with file and directory
12+
* paths. It can be accessed using:
13+
*
14+
* ```js
15+
* import path from 'node:path';
16+
* ```
17+
* @see [source](https://github.com/nodejs/node/blob/v24.x/lib/path.js)
18+
*/
19+
20+
// import path = require("path");
21+
// export = path;
22+
23+
// import path = require("path/posix");
24+
// export = path;
25+
26+
// import path = require("path/win32");
27+
// export = path;

kotlin-node/src/webMain/generated/node/process/process.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,8 @@
44

55
package node.process
66

7+
@JsName("default")
8+
external var process: Process
9+
710
// import process = require("process");
811
// export = process;

kotlin-node/src/webMain/kotlin/node/path/path.export.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

kotlin-node/src/webMain/kotlin/node/process/process.export.kt

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)