phecda-server 7.1.3 → 8.0.0
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 +5 -0
- package/dist/{chunk-MKRHYZCL.mjs → chunk-FI5756JX.mjs} +2 -2
- package/dist/{chunk-JTSD2LIG.js → chunk-OLNN4U3O.js} +13 -11
- package/dist/{chunk-TQSHE4PZ.mjs → chunk-PFPOEZHH.mjs} +13 -11
- package/dist/{chunk-DPPDWBYO.js → chunk-UYZSUBX4.js} +2 -2
- package/dist/{chunk-P3CS65OP.mjs → chunk-VAHCYYCB.mjs} +32 -17
- package/dist/{chunk-OV3UJLGP.js → chunk-YJ3QHGTC.js} +32 -17
- package/dist/{core-B5yKYkMJ.d.mts → core-BTSHIAyB.d.ts} +2 -1
- package/dist/{core-BRuvL6hY.d.ts → core-D1YYphEn.d.mts} +2 -1
- package/dist/helper.d.mts +1 -1
- package/dist/helper.d.ts +1 -1
- package/dist/helper.js +2 -2
- package/dist/helper.mjs +1 -1
- package/dist/http/elysia/index.d.mts +3 -3
- package/dist/http/elysia/index.d.ts +3 -3
- package/dist/http/elysia/index.js +30 -30
- package/dist/http/elysia/index.mjs +15 -15
- package/dist/http/express/index.d.mts +3 -3
- package/dist/http/express/index.d.ts +3 -3
- package/dist/http/express/index.js +27 -27
- package/dist/http/express/index.mjs +14 -14
- package/dist/http/fastify/index.d.mts +3 -3
- package/dist/http/fastify/index.d.ts +3 -3
- package/dist/http/fastify/index.js +29 -29
- package/dist/http/fastify/index.mjs +15 -15
- package/dist/http/h3/index.d.mts +3 -3
- package/dist/http/h3/index.d.ts +3 -3
- package/dist/http/h3/index.js +28 -28
- package/dist/http/h3/index.mjs +14 -14
- package/dist/http/hono/index.d.mts +3 -3
- package/dist/http/hono/index.d.ts +3 -3
- package/dist/http/hono/index.js +26 -26
- package/dist/http/hono/index.mjs +14 -14
- package/dist/http/hyper-express/index.d.mts +3 -3
- package/dist/http/hyper-express/index.d.ts +3 -3
- package/dist/http/hyper-express/index.js +26 -26
- package/dist/http/hyper-express/index.mjs +14 -14
- package/dist/http/koa/index.d.mts +3 -3
- package/dist/http/koa/index.d.ts +3 -3
- package/dist/http/koa/index.js +27 -27
- package/dist/http/koa/index.mjs +14 -14
- package/dist/index.d.mts +20 -13
- package/dist/index.d.ts +20 -13
- package/dist/index.js +112 -71
- package/dist/index.mjs +69 -28
- package/dist/{meta-C_eDyXnK.d.ts → meta-DNF6Fl27.d.mts} +11 -9
- package/dist/{meta-C_eDyXnK.d.mts → meta-DNF6Fl27.d.ts} +11 -9
- package/dist/rpc/bullmq/index.d.mts +3 -3
- package/dist/rpc/bullmq/index.d.ts +3 -3
- package/dist/rpc/bullmq/index.js +16 -16
- package/dist/rpc/bullmq/index.mjs +11 -11
- package/dist/rpc/electron/index.d.mts +3 -3
- package/dist/rpc/electron/index.d.ts +3 -3
- package/dist/rpc/electron/index.js +11 -11
- package/dist/rpc/electron/index.mjs +7 -7
- package/dist/rpc/kafka/index.d.mts +3 -3
- package/dist/rpc/kafka/index.d.ts +3 -3
- package/dist/rpc/kafka/index.js +14 -14
- package/dist/rpc/kafka/index.mjs +9 -9
- package/dist/rpc/nats/index.d.mts +3 -3
- package/dist/rpc/nats/index.d.ts +3 -3
- package/dist/rpc/nats/index.js +14 -14
- package/dist/rpc/nats/index.mjs +9 -9
- package/dist/rpc/rabbitmq/index.d.mts +3 -3
- package/dist/rpc/rabbitmq/index.d.ts +3 -3
- package/dist/rpc/rabbitmq/index.js +14 -14
- package/dist/rpc/rabbitmq/index.mjs +9 -9
- package/dist/rpc/redis/index.d.mts +3 -3
- package/dist/rpc/redis/index.d.ts +3 -3
- package/dist/rpc/redis/index.js +14 -14
- package/dist/rpc/redis/index.mjs +9 -9
- package/dist/rpc/ws/index.d.mts +3 -3
- package/dist/rpc/ws/index.d.ts +3 -3
- package/dist/rpc/ws/index.js +10 -10
- package/dist/rpc/ws/index.mjs +6 -6
- package/dist/test.d.mts +2 -2
- package/dist/test.d.ts +2 -2
- package/dist/test.js +5 -5
- package/dist/test.mjs +4 -4
- package/dist/{types-7-m2wEkP.d.mts → types-BOZ8yE2L.d.mts} +1 -1
- package/dist/{types-BuvMT1ta.d.ts → types-Cosv4nol.d.ts} +1 -1
- package/dist/{types-BKHBmSQN.d.mts → types-DtiHAXQB.d.mts} +1 -1
- package/dist/{types-B6aU8oT-.d.ts → types-YJ55P7A_.d.ts} +1 -1
- package/package.json +3 -4
- package/register/export.mjs +5 -1
- package/register/loader.mjs +293 -292
- package/register/utils.mjs +43 -70
package/register/export.mjs
CHANGED
|
@@ -27,7 +27,11 @@ export default ['Addon', 'Arg', 'Assign', 'BadGatewayException', 'BadRequestExce
|
|
|
27
27
|
'setLogger',
|
|
28
28
|
'setMeta',
|
|
29
29
|
'useS', 'wait', 'OneFile', 'ManyFiles',
|
|
30
|
-
'Rule','Required','Optional',
|
|
30
|
+
'Rule','Required','Optional',
|
|
31
|
+
'validate',
|
|
32
|
+
'Min','Max','Enum','OneOf','Nested',
|
|
33
|
+
|
|
34
|
+
'Doc','DocGenerator',
|
|
31
35
|
'pick','omit','partial',
|
|
32
36
|
'functionToClass','objectToClass'
|
|
33
37
|
|
package/register/loader.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { fileURLToPath, pathToFileURL } from 'url'
|
|
2
2
|
import { writeFile } from 'fs/promises'
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
basename,
|
|
5
|
+
dirname,
|
|
6
|
+
isAbsolute,
|
|
7
|
+
relative,
|
|
8
|
+
resolve as resolvePath,
|
|
9
9
|
} from 'path'
|
|
10
10
|
import { createRequire } from 'module'
|
|
11
11
|
import ts from 'typescript'
|
|
@@ -13,7 +13,8 @@ import chokidar from 'chokidar'
|
|
|
13
13
|
import Debug from 'debug'
|
|
14
14
|
import { compile, genUnImportRet, handleClassTypes, slash } from './utils.mjs'
|
|
15
15
|
|
|
16
|
-
const require = createRequire(
|
|
16
|
+
const require = createRequire(
|
|
17
|
+
import.meta.url)
|
|
17
18
|
const debug = Debug('phecda-server/loader')
|
|
18
19
|
|
|
19
20
|
const isLowVersion = parseFloat(process.version.slice(1)) < 18.19
|
|
@@ -22,8 +23,8 @@ let port
|
|
|
22
23
|
let config
|
|
23
24
|
const workdir = process.cwd()
|
|
24
25
|
const configPath = resolvePath(
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
workdir,
|
|
27
|
+
process.env.PS_CONFIG_FILE || 'ps.json',
|
|
27
28
|
)
|
|
28
29
|
|
|
29
30
|
// unimport
|
|
@@ -34,337 +35,337 @@ const dtsPath = process.env.PS_DTS_PATH || 'ps.d.ts'
|
|
|
34
35
|
const watchFiles = new Set()
|
|
35
36
|
const filesRecord = new Map()
|
|
36
37
|
const moduleGraph = {}
|
|
37
|
-
// ts
|
|
38
|
+
// ts
|
|
38
39
|
let tsconfig = {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
module: ts.ModuleKind.ESNext,
|
|
41
|
+
moduleResolution: ts.ModuleResolutionKind.NodeNext,
|
|
41
42
|
}
|
|
42
43
|
const EXTENSIONS = [ts.Extension.Ts, ts.Extension.Tsx, ts.Extension.Mts]
|
|
43
44
|
const tsconfigPath = resolvePath(process.cwd(), 'tsconfig.json')
|
|
44
45
|
const tsRet = ts.readConfigFile(tsconfigPath, ts.sys.readFile)
|
|
45
46
|
if (!tsRet.error) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
47
|
+
const { error, options } = ts.parseJsonConfigFileContent(
|
|
48
|
+
tsRet.config,
|
|
49
|
+
ts.sys,
|
|
50
|
+
dirname(tsconfigPath),
|
|
51
|
+
)
|
|
52
|
+
if (!error)
|
|
53
|
+
tsconfig = options
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const moduleResolutionCache = ts.createModuleResolutionCache(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
ts.sys.getCurrentDirectory(),
|
|
58
|
+
x => x,
|
|
59
|
+
tsconfig,
|
|
59
60
|
)
|
|
60
61
|
const host = {
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
fileExists: ts.sys.fileExists,
|
|
63
|
+
readFile: ts.sys.readFile,
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
if (isLowVersion)
|
|
66
|
-
|
|
67
|
+
await initialize()
|
|
67
68
|
|
|
68
69
|
export async function initialize(data) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
70
|
+
if (data)
|
|
71
|
+
port = data.port
|
|
72
|
+
|
|
73
|
+
debug('read config...')
|
|
74
|
+
|
|
75
|
+
config = require(configPath)
|
|
76
|
+
|
|
77
|
+
if (!config.paths)
|
|
78
|
+
config.paths = {}
|
|
79
|
+
|
|
80
|
+
const loaderPath = process.env.PS_LOADER_PATH
|
|
81
|
+
|
|
82
|
+
if (loaderPath) {
|
|
83
|
+
const loader = await
|
|
84
|
+
import (loaderPath.startsWith('.') ? resolvePath(workdir, loaderPath) : loaderPath)
|
|
85
|
+
|
|
86
|
+
if (typeof loader.load === 'function')
|
|
87
|
+
customLoad = loader.load
|
|
88
|
+
|
|
89
|
+
if (typeof loader.resolve === 'function')
|
|
90
|
+
customResolve = loader.resolve
|
|
91
|
+
}
|
|
92
|
+
if (IS_DEV) {
|
|
93
|
+
chokidar.watch(configPath, { persistent: true }).on('change', () => {
|
|
94
|
+
port.postMessage(
|
|
95
|
+
JSON.stringify({
|
|
96
|
+
type: 'relaunch',
|
|
97
|
+
}),
|
|
98
|
+
)
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!config.unimport)
|
|
103
|
+
return
|
|
104
|
+
|
|
105
|
+
unimportRet = await genUnImportRet(config.unimport)
|
|
106
|
+
if (unimportRet) {
|
|
107
|
+
debug('auto import...')
|
|
108
|
+
await unimportRet.init()
|
|
109
|
+
|
|
110
|
+
const unimportDtsPath = resolvePath(workdir, dtsPath)
|
|
111
|
+
writeFile(
|
|
112
|
+
unimportDtsPath,
|
|
113
|
+
handleClassTypes(
|
|
114
|
+
await unimportRet.generateTypeDeclarations({
|
|
115
|
+
resolvePath: (i) => {
|
|
116
|
+
if (i.from.startsWith('.') || isAbsolute(i.from)) {
|
|
117
|
+
const related = slash(
|
|
118
|
+
relative(dirname(unimportDtsPath), i.from).replace(/\.ts(x)?$/, ''),
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
return !related.startsWith('.') ? `./${related}` : related
|
|
122
|
+
}
|
|
123
|
+
return i.from
|
|
124
|
+
},
|
|
125
|
+
}),
|
|
126
|
+
),
|
|
127
|
+
)
|
|
128
|
+
}
|
|
127
129
|
}
|
|
128
130
|
|
|
129
131
|
function addUrlToGraph(url, parent) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
+
if (!(url in moduleGraph))
|
|
133
|
+
moduleGraph[url] = new Set()
|
|
132
134
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
+
moduleGraph[url].add(parent)
|
|
136
|
+
return url + (filesRecord.has(url) ? `?t=${filesRecord.get(url)}` : '')
|
|
135
137
|
}
|
|
136
138
|
|
|
137
139
|
function getFileMid(file) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
140
|
+
const filename = basename(file)
|
|
141
|
+
const ret = filename.split('.')
|
|
142
|
+
if (!['js', 'mjs', 'cjs', 'ts', 'tsx', 'mts', 'cts'].includes(ret.pop()))
|
|
143
|
+
return ''
|
|
144
|
+
if (!ret[0]) // .dockerfile
|
|
145
|
+
return ''
|
|
146
|
+
|
|
147
|
+
return ret[1]
|
|
146
148
|
}
|
|
147
149
|
|
|
148
|
-
export const resolve = async
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
150
|
+
export const resolve = async(specifier, context, nextResolve) => {
|
|
151
|
+
if (customResolve) {
|
|
152
|
+
const url = await customResolve(specifier, context)
|
|
153
|
+
if (url) {
|
|
154
|
+
return {
|
|
155
|
+
format: 'ts',
|
|
156
|
+
url,
|
|
157
|
+
shortCircuit: true,
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
159
161
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
162
|
+
// entrypoint
|
|
163
|
+
if (!context.parentURL)
|
|
164
|
+
return nextResolve(specifier)
|
|
163
165
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
// @todo skip resolve to improve performance
|
|
167
|
+
// if (context.parentURL.includes('/node_modules/') && specifier.includes('/node_modules/'))
|
|
168
|
+
// return nextResolve(specifier)
|
|
167
169
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// import among files in local project
|
|
177
|
-
if (
|
|
178
|
-
resolvedModule
|
|
179
|
-
&& !resolvedModule.resolvedFileName.includes('/node_modules/')
|
|
180
|
-
&& EXTENSIONS.includes(resolvedModule.extension)
|
|
181
|
-
) {
|
|
182
|
-
const url = addUrlToGraph(
|
|
183
|
-
pathToFileURL(resolvedModule.resolvedFileName).href,
|
|
184
|
-
context.parentURL.split('?')[0],
|
|
185
|
-
)
|
|
170
|
+
const { resolvedModule } = ts.resolveModuleName(
|
|
171
|
+
specifier,
|
|
172
|
+
fileURLToPath(context.parentURL),
|
|
173
|
+
tsconfig,
|
|
174
|
+
host,
|
|
175
|
+
moduleResolutionCache,
|
|
176
|
+
)
|
|
186
177
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
178
|
+
// import among files in local project
|
|
179
|
+
if (
|
|
180
|
+
resolvedModule &&
|
|
181
|
+
!resolvedModule.resolvedFileName.includes('/node_modules/') &&
|
|
182
|
+
EXTENSIONS.includes(resolvedModule.extension)
|
|
183
|
+
) {
|
|
184
|
+
const url = addUrlToGraph(
|
|
185
|
+
pathToFileURL(resolvedModule.resolvedFileName).href,
|
|
186
|
+
context.parentURL.split('?')[0],
|
|
187
|
+
)
|
|
188
|
+
|
|
189
|
+
const importerMid = getFileMid(context.parentURL)
|
|
190
|
+
const sourceMid = getFileMid(resolvedModule.resolvedFileName)
|
|
191
|
+
if (config.resolve && importerMid && sourceMid) {
|
|
192
|
+
const resolver = config.resolve.find(
|
|
193
|
+
item => item.source === sourceMid && item.importer === importerMid,
|
|
194
|
+
)
|
|
195
|
+
if (resolver) {
|
|
196
|
+
return {
|
|
197
|
+
format: 'ts',
|
|
198
|
+
url: pathToFileURL(resolvePath(workdir, resolver.path)).href,
|
|
199
|
+
shortCircuit: true,
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return {
|
|
205
|
+
format: 'ts',
|
|
206
|
+
url,
|
|
207
|
+
shortCircuit: true,
|
|
208
|
+
}
|
|
198
209
|
}
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
210
|
|
|
202
|
-
|
|
203
|
-
format: 'ts',
|
|
204
|
-
url,
|
|
205
|
-
shortCircuit: true,
|
|
206
|
-
}
|
|
207
|
-
}
|
|
211
|
+
const resolveRet = await nextResolve(specifier)
|
|
208
212
|
|
|
209
|
-
|
|
213
|
+
// ts resolve fail in some cases
|
|
214
|
+
if (resolveRet.url && isAbsolute(resolveRet.url)) {
|
|
215
|
+
const [path, query] = resolveRet.url.split('?')
|
|
216
|
+
resolveRet.url = pathToFileURL(path).href + (query ? `?${query}` : '')
|
|
217
|
+
}
|
|
210
218
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
resolveRet.url = pathToFileURL(path).href + (query ? `?${query}` : '')
|
|
215
|
-
}
|
|
219
|
+
return resolveRet
|
|
220
|
+
}
|
|
221
|
+
// @todo the first params may be url or path, need to distinguish
|
|
216
222
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
if (context.importAttributes.ps) {
|
|
224
|
-
mode = context.importAttributes.ps
|
|
225
|
-
delete context.importAttributes.ps
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
url = url.split('?')[0]
|
|
229
|
-
|
|
230
|
-
if (
|
|
231
|
-
!url.includes('/node_modules/')
|
|
232
|
-
&& url.startsWith('file://')
|
|
233
|
-
&& !watchFiles.has(url)
|
|
234
|
-
&& !isLowVersion
|
|
235
|
-
) {
|
|
236
|
-
watchFiles.add(url)
|
|
237
|
-
|
|
238
|
-
if (IS_DEV && mode !== 'not-hmr') {
|
|
239
|
-
if (isModuleFileUrl(url)) {
|
|
240
|
-
port.postMessage(
|
|
241
|
-
JSON.stringify({
|
|
242
|
-
type: 'init',
|
|
243
|
-
files: [fileURLToPath(url)],
|
|
244
|
-
}),
|
|
245
|
-
)
|
|
246
|
-
}
|
|
223
|
+
export const load = async(url, context, nextLoad) => {
|
|
224
|
+
let mode
|
|
225
|
+
if (context.importAttributes.ps) {
|
|
226
|
+
mode = context.importAttributes.ps
|
|
227
|
+
delete context.importAttributes.ps
|
|
228
|
+
}
|
|
247
229
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
230
|
+
url = url.split('?')[0]
|
|
231
|
+
|
|
232
|
+
if (!url.includes('/node_modules/') &&
|
|
233
|
+
url.startsWith('file://') &&
|
|
234
|
+
!watchFiles.has(url) &&
|
|
235
|
+
!isLowVersion
|
|
236
|
+
) {
|
|
237
|
+
watchFiles.add(url)
|
|
238
|
+
|
|
239
|
+
if (IS_DEV && mode !== 'not-hmr') {
|
|
240
|
+
if (isModuleFileUrl(url)) {
|
|
241
|
+
port.postMessage(
|
|
242
|
+
JSON.stringify({
|
|
243
|
+
type: 'init',
|
|
244
|
+
files: [fileURLToPath(url)],
|
|
245
|
+
}),
|
|
246
|
+
)
|
|
247
|
+
}
|
|
253
248
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
249
|
+
chokidar.watch(fileURLToPath(url), { persistent: true }).on(
|
|
250
|
+
'change',
|
|
251
|
+
debounce(() => {
|
|
252
|
+
try {
|
|
253
|
+
const files = [...findTopScope(url, Date.now())].reverse()
|
|
254
|
+
|
|
255
|
+
port.postMessage(
|
|
256
|
+
JSON.stringify({
|
|
257
|
+
type: 'change',
|
|
258
|
+
files,
|
|
259
|
+
}),
|
|
260
|
+
)
|
|
261
|
+
} catch (e) {
|
|
262
|
+
port.postMessage(
|
|
263
|
+
JSON.stringify({
|
|
264
|
+
type: 'relaunch',
|
|
265
|
+
}),
|
|
266
|
+
)
|
|
267
|
+
}
|
|
268
|
+
}),
|
|
266
269
|
)
|
|
267
|
-
|
|
268
|
-
}),
|
|
269
|
-
)
|
|
270
|
+
}
|
|
270
271
|
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
272
|
+
// after hmr
|
|
273
|
+
if (customLoad) {
|
|
274
|
+
const source = await customLoad(url, context)
|
|
275
|
+
if (source) {
|
|
276
|
+
return {
|
|
277
|
+
format: 'module',
|
|
278
|
+
source,
|
|
279
|
+
shortCircuit: true,
|
|
280
|
+
}
|
|
281
|
+
}
|
|
281
282
|
}
|
|
282
|
-
}
|
|
283
|
-
// resolveModuleName failed
|
|
284
|
-
// I don't know why it failed
|
|
285
|
-
if (!context.format && url.endsWith('.ts'))
|
|
286
|
-
context.format = 'ts'
|
|
287
283
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
if (
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
284
|
+
|
|
285
|
+
// resolveModuleName failed
|
|
286
|
+
// I don't know why it failed
|
|
287
|
+
if ( url.endsWith('.ts'))
|
|
288
|
+
context.format = 'ts'
|
|
289
|
+
|
|
290
|
+
// module-typescript???
|
|
291
|
+
|
|
292
|
+
if (context.format === 'ts') {
|
|
293
|
+
const { source } = await nextLoad(url, context)
|
|
294
|
+
|
|
295
|
+
const code = typeof source === 'string' ? source : Buffer.from(source).toString()
|
|
296
|
+
|
|
297
|
+
const compiled = await compile(code, url, config?.swc)
|
|
298
|
+
|
|
299
|
+
if (unimportRet) {
|
|
300
|
+
const { injectImports } = unimportRet
|
|
301
|
+
|
|
302
|
+
return {
|
|
303
|
+
format: 'module',
|
|
304
|
+
source: (
|
|
305
|
+
await injectImports(
|
|
306
|
+
compiled,
|
|
307
|
+
slash(url.startsWith('file://') ? fileURLToPath(url) : url),
|
|
308
|
+
)
|
|
309
|
+
).code,
|
|
310
|
+
shortCircuit: true,
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return {
|
|
314
|
+
format: 'module',
|
|
315
|
+
source: compiled,
|
|
316
|
+
shortCircuit: true,
|
|
317
|
+
}
|
|
318
|
+
} else {
|
|
319
|
+
return nextLoad(url, context)
|
|
314
320
|
}
|
|
315
|
-
}
|
|
316
|
-
else {
|
|
317
|
-
return nextLoad(url, context)
|
|
318
|
-
}
|
|
319
321
|
}
|
|
320
322
|
|
|
321
323
|
function findTopScope(url, time, modules = new Set()) {
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
return modules
|
|
324
|
+
filesRecord.set(url, time)
|
|
325
|
+
if (isModuleFileUrl(url)) {
|
|
326
|
+
modules.add(fileURLToPath(url))
|
|
327
|
+
} else {
|
|
328
|
+
if (!moduleGraph[url])
|
|
329
|
+
throw new Error('root file update')
|
|
330
|
+
for (const i of[...moduleGraph[url]]) findTopScope(i, time, modules)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return modules
|
|
333
334
|
}
|
|
334
335
|
|
|
335
336
|
function debounce(cb, timeout = 500) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
337
|
+
let timer
|
|
338
|
+
return (...args) => {
|
|
339
|
+
if (timer)
|
|
340
|
+
return
|
|
341
|
+
|
|
342
|
+
timer = setTimeout(() => {
|
|
343
|
+
cb(...args)
|
|
344
|
+
timer = undefined
|
|
345
|
+
}, timeout)
|
|
346
|
+
}
|
|
346
347
|
}
|
|
347
348
|
|
|
348
349
|
export function isModuleFileUrl(url) {
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
350
|
+
const midName = getFileMid(url)
|
|
351
|
+
if (!midName)
|
|
352
|
+
return false
|
|
353
|
+
if (
|
|
354
|
+
[
|
|
355
|
+
'controller',
|
|
356
|
+
'rpc',
|
|
357
|
+
'service',
|
|
358
|
+
'module',
|
|
359
|
+
'extension',
|
|
360
|
+
'ext',
|
|
361
|
+
'guard',
|
|
362
|
+
'addon',
|
|
363
|
+
'filter',
|
|
364
|
+
'pipe',
|
|
365
|
+
'solo',
|
|
366
|
+
].includes(midName)
|
|
367
|
+
)
|
|
368
|
+
return true
|
|
369
|
+
|
|
370
|
+
return config.moduleFile && config.moduleFile.includes(midName)
|
|
371
|
+
}
|