phecda-server 7.0.0-alpha.3 → 7.0.0-alpha.4
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/assets/schema.json +55 -55
- package/package.json +2 -2
- package/register/index.mjs +41 -40
- package/register/loader.mjs +35 -10
package/assets/schema.json
CHANGED
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
{
|
|
2
|
-
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
-
"type": "object",
|
|
4
|
-
"properties": {
|
|
5
|
-
"resolve": {
|
|
6
|
-
"type": "array",
|
|
7
|
-
"items": {
|
|
8
|
-
"type": "object",
|
|
9
|
-
"properties": {
|
|
10
|
-
"source": {
|
|
11
|
-
"type": "string",
|
|
12
|
-
"description": "The middle name of the imported file."
|
|
13
|
-
},
|
|
14
|
-
"importer": {
|
|
15
|
-
"type": "string",
|
|
16
|
-
"description": "The middle name of the importer file."
|
|
17
|
-
},
|
|
18
|
-
"path": {
|
|
19
|
-
"type": "string",
|
|
20
|
-
|
|
21
|
-
"description": "Redirect path"
|
|
22
|
-
},
|
|
23
|
-
"filename": {
|
|
24
|
-
"type": "string",
|
|
25
|
-
"optional": true,
|
|
26
|
-
|
|
27
|
-
"description": "generate split chunk,only work in vite"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
"required": ["source", "path", "importer"]
|
|
31
|
-
},
|
|
32
|
-
"description": "Resolve and redirect modules path"
|
|
33
|
-
},
|
|
34
|
-
"moduleFile": {
|
|
35
|
-
"type": "array",
|
|
36
|
-
"items": {
|
|
37
|
-
"type": "string"
|
|
38
|
-
},
|
|
39
|
-
"description": "Including the module's file middle name, such as controller mapping to xx.controller.ts"
|
|
40
|
-
},
|
|
41
|
-
"virtualFile": {
|
|
42
|
-
"type": "object",
|
|
43
|
-
"additionalProperties": {
|
|
44
|
-
"type": "string"
|
|
45
|
-
},
|
|
46
|
-
"description": "Virtual module, just like in Vite."
|
|
47
|
-
},
|
|
48
|
-
"unimport": {
|
|
49
|
-
"type": "object",
|
|
50
|
-
"description": "Includes the arguments passed to unimport and 'dtsPath' that specifies the location for generating type files."
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
|
|
54
|
-
"required": ["resolve"]
|
|
55
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"type": "object",
|
|
4
|
+
"properties": {
|
|
5
|
+
"resolve": {
|
|
6
|
+
"type": "array",
|
|
7
|
+
"items": {
|
|
8
|
+
"type": "object",
|
|
9
|
+
"properties": {
|
|
10
|
+
"source": {
|
|
11
|
+
"type": "string",
|
|
12
|
+
"description": "The middle name of the imported file."
|
|
13
|
+
},
|
|
14
|
+
"importer": {
|
|
15
|
+
"type": "string",
|
|
16
|
+
"description": "The middle name of the importer file."
|
|
17
|
+
},
|
|
18
|
+
"path": {
|
|
19
|
+
"type": "string",
|
|
20
|
+
|
|
21
|
+
"description": "Redirect path"
|
|
22
|
+
},
|
|
23
|
+
"filename": {
|
|
24
|
+
"type": "string",
|
|
25
|
+
"optional": true,
|
|
26
|
+
|
|
27
|
+
"description": "generate split chunk,only work in vite"
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
"required": ["source", "path", "importer"]
|
|
31
|
+
},
|
|
32
|
+
"description": "Resolve and redirect modules path"
|
|
33
|
+
},
|
|
34
|
+
"moduleFile": {
|
|
35
|
+
"type": "array",
|
|
36
|
+
"items": {
|
|
37
|
+
"type": "string"
|
|
38
|
+
},
|
|
39
|
+
"description": "Including the module's file middle name, such as controller mapping to xx.controller.ts"
|
|
40
|
+
},
|
|
41
|
+
"virtualFile": {
|
|
42
|
+
"type": "object",
|
|
43
|
+
"additionalProperties": {
|
|
44
|
+
"type": "string"
|
|
45
|
+
},
|
|
46
|
+
"description": "Virtual module, just like in Vite."
|
|
47
|
+
},
|
|
48
|
+
"unimport": {
|
|
49
|
+
"type": "object",
|
|
50
|
+
"description": "Includes the arguments passed to unimport and 'dtsPath' that specifies the location for generating type files."
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
"required": ["resolve"]
|
|
55
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phecda-server",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.4",
|
|
4
4
|
"description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
|
|
5
5
|
"author": "fgsreally",
|
|
6
6
|
"license": "MIT",
|
|
@@ -147,7 +147,7 @@
|
|
|
147
147
|
"picocolors": "^1.0.0",
|
|
148
148
|
"reflect-metadata": "^0.1.13",
|
|
149
149
|
"ts-mixer": "^6.0.4",
|
|
150
|
-
"phecda-core": "4.0.
|
|
150
|
+
"phecda-core": "4.1.0-alpha.0"
|
|
151
151
|
},
|
|
152
152
|
"devDependencies": {
|
|
153
153
|
"@koa/router": "^12.0.1",
|
package/register/index.mjs
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
|
-
import { register } from 'node:module'
|
|
2
|
-
import { MessageChannel } from 'node:worker_threads'
|
|
3
|
-
import { log } from '../dist/index.mjs'
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
1
|
+
import { register } from 'node:module'
|
|
2
|
+
import { MessageChannel } from 'node:worker_threads'
|
|
3
|
+
import { log } from '../dist/index.mjs'
|
|
4
|
+
|
|
5
|
+
const { port1, port2 } = new MessageChannel()
|
|
6
|
+
|
|
7
|
+
register('./loader.mjs', {
|
|
8
|
+
parentURL: import.meta.url,
|
|
9
|
+
data: { port: port2 },
|
|
10
|
+
transferList: [port2],
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
let isRunning = true
|
|
14
|
+
|
|
15
|
+
port1.on('message', async (data) => {
|
|
16
|
+
const { type, files } = JSON.parse(data)
|
|
17
|
+
|
|
18
|
+
if (!isRunning || !globalThis.__PS_HMR__ || type === 'relaunch')
|
|
19
|
+
return process.exit(2)// file change -> relaunch
|
|
20
|
+
|
|
21
|
+
if (type === 'change') {
|
|
22
|
+
log('reload module...')
|
|
23
|
+
|
|
24
|
+
for (const cb of globalThis.__PS_HMR__) await cb(files)
|
|
25
|
+
|
|
26
|
+
log('reload done')
|
|
27
|
+
}
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
process.on('uncaughtException', (err) => {
|
|
31
|
+
log('Uncaught Exception:', 'error')
|
|
32
|
+
isRunning = false
|
|
33
|
+
console.error(err)
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
process.on('unhandledRejection', (err) => {
|
|
37
|
+
log('Unhandled Promise Rejection:', 'error')
|
|
38
|
+
isRunning = false
|
|
39
|
+
|
|
40
|
+
console.error(err)
|
|
41
|
+
})
|
package/register/loader.mjs
CHANGED
|
@@ -2,26 +2,42 @@ import { fileURLToPath, pathToFileURL } from 'url'
|
|
|
2
2
|
import { writeFile } from 'fs/promises'
|
|
3
3
|
import {
|
|
4
4
|
basename,
|
|
5
|
+
dirname,
|
|
5
6
|
extname,
|
|
6
7
|
isAbsolute,
|
|
7
8
|
relative,
|
|
8
9
|
resolve as resolvePath,
|
|
9
10
|
} from 'path'
|
|
10
11
|
import { createRequire } from 'module'
|
|
12
|
+
import { existsSync } from 'fs'
|
|
11
13
|
import ts from 'typescript'
|
|
12
14
|
import chokidar from 'chokidar'
|
|
13
15
|
import { log } from '../dist/index.mjs'
|
|
14
16
|
import { compile, genUnImportRet, handleClassTypes, slash } from './utils.mjs'
|
|
15
17
|
|
|
16
18
|
let port
|
|
19
|
+
let tsconfig = {
|
|
20
|
+
module: ts.ModuleKind.ESNext,
|
|
21
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
22
|
+
}
|
|
17
23
|
|
|
18
24
|
const isLowVersion = parseFloat(process.version.slice(1)) < 18.19
|
|
19
25
|
// this part is important or not?
|
|
20
26
|
const EXTENSIONS = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Mts]
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
|
|
28
|
+
const tsconfigPath = resolvePath(process.cwd(), 'tsconfig.json')
|
|
29
|
+
const tsRet = ts.readConfigFile(tsconfigPath, ts.sys.readFile)
|
|
30
|
+
|
|
31
|
+
if (!tsRet.error) {
|
|
32
|
+
const { error, options } = ts.parseJsonConfigFileContent(
|
|
33
|
+
tsRet.config,
|
|
34
|
+
ts.sys,
|
|
35
|
+
dirname(tsconfigPath),
|
|
36
|
+
)
|
|
37
|
+
if (!error)
|
|
38
|
+
tsconfig = options
|
|
24
39
|
}
|
|
40
|
+
|
|
25
41
|
const moduleResolutionCache = ts.createModuleResolutionCache(
|
|
26
42
|
ts.sys.getCurrentDirectory(),
|
|
27
43
|
x => x,
|
|
@@ -56,6 +72,8 @@ export async function initialize(data) {
|
|
|
56
72
|
config = require(configPath)
|
|
57
73
|
if (!config.virtualFile)
|
|
58
74
|
config.virtualFile = {}
|
|
75
|
+
if (!config.paths)
|
|
76
|
+
config.paths = {}
|
|
59
77
|
|
|
60
78
|
if (!process.env.PS_HMR_BAN) {
|
|
61
79
|
chokidar.watch(configPath, { persistent: true }).on('change', () => {
|
|
@@ -127,13 +145,20 @@ export const resolve = async (specifier, context, nextResolve) => {
|
|
|
127
145
|
}
|
|
128
146
|
// entrypoint
|
|
129
147
|
if (!context.parentURL) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
:
|
|
135
|
-
|
|
136
|
-
|
|
148
|
+
if (/^file:\/\/\//.test(specifier) && existsSync(fileURLToPath(specifier))) {
|
|
149
|
+
entryUrl = specifier
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
format: EXTENSIONS.some(ext => specifier.endsWith(ext))
|
|
153
|
+
? 'ts'
|
|
154
|
+
: undefined,
|
|
155
|
+
url: specifier,
|
|
156
|
+
shortCircuit: true,
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
// won't resolve virtual file as entry in vite
|
|
161
|
+
return nextResolve(specifier)
|
|
137
162
|
}
|
|
138
163
|
}
|
|
139
164
|
// url import
|