phecda-server 5.0.0-beta.20 → 5.0.0-beta.21
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/dist/{chunk-WNTTAFLC.js → chunk-562XCEUU.js} +9 -11
- package/dist/{chunk-PXI5J4LR.mjs → chunk-AL36AJMH.mjs} +8 -10
- package/dist/{core-d11fe855.d.ts → core-895ed04d.d.ts} +54 -74
- package/dist/index.d.ts +38 -15
- package/dist/index.js +22 -24
- package/dist/index.mjs +1 -3
- package/dist/rpc/kafka/index.d.ts +2 -2
- package/dist/rpc/kafka/index.js +4 -4
- package/dist/rpc/kafka/index.mjs +1 -1
- package/dist/rpc/rabbitmq/index.d.ts +2 -2
- package/dist/rpc/rabbitmq/index.js +4 -4
- package/dist/rpc/rabbitmq/index.mjs +1 -1
- package/dist/rpc/redis/index.d.ts +2 -2
- package/dist/rpc/redis/index.js +4 -4
- package/dist/rpc/redis/index.mjs +1 -1
- package/dist/server/express/index.d.ts +1 -1
- package/dist/server/express/index.js +12 -10
- package/dist/server/express/index.mjs +3 -1
- package/dist/server/fastify/index.d.ts +1 -1
- package/dist/server/fastify/index.js +17 -12
- package/dist/server/fastify/index.mjs +7 -2
- package/dist/server/h3/index.d.ts +1 -1
- package/dist/server/h3/index.js +12 -10
- package/dist/server/h3/index.mjs +3 -1
- package/dist/server/koa/index.d.ts +1 -1
- package/dist/server/koa/index.js +12 -10
- package/dist/server/koa/index.mjs +3 -1
- package/dist/test.d.ts +1 -1
- package/package.json +2 -1
- package/register/loader.mjs +3 -5
- package/register/utils.mjs +46 -5
package/register/loader.mjs
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from 'url'
|
|
2
|
-
import { existsSync } from 'fs'
|
|
3
2
|
import { writeFile } from 'fs/promises'
|
|
4
3
|
import { extname, isAbsolute, relative } from 'path'
|
|
5
4
|
import ts from 'typescript'
|
|
6
5
|
import chokidar from 'chokidar'
|
|
7
6
|
import { PS_FILE_RE, log } from '../dist/index.mjs'
|
|
8
|
-
import { compile, genUnImportRet } from './utils.mjs'
|
|
7
|
+
import { compile, genUnImportRet, handleClassTypes } from './utils.mjs'
|
|
9
8
|
let port
|
|
10
9
|
const isLowVersion = parseFloat(process.version.slice(1)) < 18.18
|
|
11
10
|
// this part is important or not?
|
|
@@ -35,15 +34,14 @@ export async function initialize(data) {
|
|
|
35
34
|
if (data)
|
|
36
35
|
port = data.port
|
|
37
36
|
|
|
38
|
-
if (process.env.
|
|
37
|
+
if (process.env.PS_UNIMPORT_BAN)
|
|
39
38
|
return
|
|
40
39
|
|
|
41
40
|
unimportRet = await genUnImportRet()
|
|
42
41
|
|
|
43
42
|
if (unimportRet) {
|
|
44
43
|
log('auto import...')
|
|
45
|
-
|
|
46
|
-
writeFile(dtsPath, await unimportRet.generateTypeDeclarations())
|
|
44
|
+
writeFile(dtsPath, handleClassTypes(await unimportRet.generateTypeDeclarations()))
|
|
47
45
|
}
|
|
48
46
|
}
|
|
49
47
|
|
package/register/utils.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isAbsolute } from 'path'
|
|
1
2
|
import { transform } from '@swc-node/core'
|
|
2
3
|
const injectInlineSourceMap = ({ code, map }) => {
|
|
3
4
|
if (map) {
|
|
@@ -18,7 +19,6 @@ export async function compile(sourcecode, filename) {
|
|
|
18
19
|
emitDecoratorMetadata: true,
|
|
19
20
|
experimentalDecorators: true,
|
|
20
21
|
esModuleInterop: false,
|
|
21
|
-
|
|
22
22
|
})
|
|
23
23
|
|
|
24
24
|
return injectInlineSourceMap({ code, map })
|
|
@@ -26,16 +26,57 @@ export async function compile(sourcecode, filename) {
|
|
|
26
26
|
|
|
27
27
|
export async function genUnImportRet() {
|
|
28
28
|
try {
|
|
29
|
-
const
|
|
29
|
+
const psExports = Object.keys(await import('../dist/index.mjs'))
|
|
30
30
|
const { createUnimport } = await import('unimport')
|
|
31
31
|
|
|
32
|
+
const workspaceExports = await findWorkspaceExports()
|
|
32
33
|
return createUnimport({
|
|
33
|
-
imports:
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
imports: psExports
|
|
35
|
+
.map((k) => {
|
|
36
|
+
return { name: k, from: 'phecda-server' }
|
|
37
|
+
})
|
|
38
|
+
.concat(workspaceExports),
|
|
36
39
|
})
|
|
37
40
|
}
|
|
38
41
|
catch (e) {
|
|
39
42
|
return false
|
|
40
43
|
}
|
|
41
44
|
}
|
|
45
|
+
|
|
46
|
+
function slash(str) {
|
|
47
|
+
return str.replace(/\\/g, '/')
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function findWorkspaceExports() {
|
|
51
|
+
try {
|
|
52
|
+
const { default: fg } = await import('fast-glob')
|
|
53
|
+
const { scanExports } = await import('unimport')
|
|
54
|
+
const result = await fg(
|
|
55
|
+
'**/*.@(controller|service|module|extension|ext|guard|interceptor|plugin|filter|pipe|edge).ts',
|
|
56
|
+
{
|
|
57
|
+
ignore: ['node_modules'],
|
|
58
|
+
absolute: true,
|
|
59
|
+
cwd: process.cwd(),
|
|
60
|
+
onlyFiles: true,
|
|
61
|
+
followSymbolicLinks: true,
|
|
62
|
+
},
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
const files = Array.from(new Set(result.flat())).map(slash)
|
|
66
|
+
|
|
67
|
+
return (await Promise.all(files.map(i => scanExports(i, false))))
|
|
68
|
+
.flat()
|
|
69
|
+
}
|
|
70
|
+
catch (e) {
|
|
71
|
+
return []
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function handleClassTypes(input) {
|
|
76
|
+
return input.replace(/const\s+(\w+)\s*:\s*typeof\s+import\(['"](.+)['"]\)\['(\w+)'\]/g, (_, n, p, e) => {
|
|
77
|
+
if (isAbsolute(p))
|
|
78
|
+
return `${_}\n type ${n} = InstanceType<typeof import('${p}')['${e}']>`
|
|
79
|
+
|
|
80
|
+
return _
|
|
81
|
+
})
|
|
82
|
+
}
|