phecda-server 8.0.1 → 8.1.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.
Files changed (40) hide show
  1. package/bin/cli.mjs +18 -3
  2. package/dist/{chunk-G5IH3TP7.mjs → chunk-BLLRB5DQ.mjs} +14 -6
  3. package/dist/{chunk-LD7YMHIE.js → chunk-HKN3AAB2.js} +14 -6
  4. package/dist/helper.js +2 -2
  5. package/dist/helper.mjs +1 -1
  6. package/dist/http/elysia/index.js +17 -17
  7. package/dist/http/elysia/index.mjs +1 -1
  8. package/dist/http/express/index.js +16 -16
  9. package/dist/http/express/index.mjs +1 -1
  10. package/dist/http/fastify/index.js +16 -16
  11. package/dist/http/fastify/index.mjs +1 -1
  12. package/dist/http/h3/index.js +17 -17
  13. package/dist/http/h3/index.mjs +1 -1
  14. package/dist/http/hono/index.js +14 -14
  15. package/dist/http/hono/index.mjs +1 -1
  16. package/dist/http/hyper-express/index.js +15 -15
  17. package/dist/http/hyper-express/index.mjs +1 -1
  18. package/dist/http/koa/index.js +16 -16
  19. package/dist/http/koa/index.mjs +1 -1
  20. package/dist/index.js +20 -20
  21. package/dist/index.mjs +1 -1
  22. package/dist/rpc/bullmq/index.js +6 -6
  23. package/dist/rpc/bullmq/index.mjs +1 -1
  24. package/dist/rpc/electron/index.js +5 -5
  25. package/dist/rpc/electron/index.mjs +1 -1
  26. package/dist/rpc/kafka/index.js +6 -6
  27. package/dist/rpc/kafka/index.mjs +1 -1
  28. package/dist/rpc/nats/index.js +6 -6
  29. package/dist/rpc/nats/index.mjs +1 -1
  30. package/dist/rpc/rabbitmq/index.js +6 -6
  31. package/dist/rpc/rabbitmq/index.mjs +1 -1
  32. package/dist/rpc/redis/index.js +6 -6
  33. package/dist/rpc/redis/index.mjs +1 -1
  34. package/dist/rpc/ws/index.js +5 -5
  35. package/dist/rpc/ws/index.mjs +1 -1
  36. package/package.json +2 -2
  37. package/register/export.mjs +7 -7
  38. package/register/index.mjs +27 -0
  39. package/register/loader.mjs +65 -65
  40. package/register/utils.mjs +12 -8
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkLD7YMHIEjs = require('../../chunk-LD7YMHIE.js');
5
+ var _chunkHKN3AAB2js = require('../../chunk-HKN3AAB2.js');
6
6
 
7
7
 
8
8
 
@@ -17,18 +17,18 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
17
17
  const sc = _nats.StringCodec.call(void 0, );
18
18
  const subscriptionMap = {};
19
19
  const existQueue = /* @__PURE__ */ new Set();
20
- const metaMap = _chunkLD7YMHIEjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
20
+ const metaMap = _chunkHKN3AAB2js.createControllerMetaMap.call(void 0, meta, (meta2) => {
21
21
  const { controller, rpc, method, tag } = meta2.data;
22
22
  if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _2 => _2.queue]) !== void 0) {
23
23
  debug(`register method "${method}" in module "${tag}"`);
24
24
  return true;
25
25
  }
26
26
  });
27
- _chunkLD7YMHIEjs.detectAopDep.call(void 0, meta, {
27
+ _chunkHKN3AAB2js.detectAopDep.call(void 0, meta, {
28
28
  addons: globalAddons,
29
29
  guards: globalGuards
30
30
  }, "rpc");
31
- _chunkLD7YMHIEjs.Context.applyAddons(globalAddons, nc, "nats");
31
+ _chunkHKN3AAB2js.Context.applyAddons(globalAddons, nc, "nats");
32
32
  async function subscribeQueues() {
33
33
  existQueue.clear();
34
34
  for (const [tag, record] of metaMap) {
@@ -56,12 +56,12 @@ async function bind(nc, { moduleMap, meta }, opts = {}) {
56
56
  const meta2 = metaMap.get(tag)[method];
57
57
  const { data: { rpc: { isEvent } = {} } } = meta2;
58
58
  if (isEvent) msg.respond("{}");
59
- const aop = _chunkLD7YMHIEjs.Context.getAop(meta2, {
59
+ const aop = _chunkHKN3AAB2js.Context.getAop(meta2, {
60
60
  globalFilter,
61
61
  globalGuards,
62
62
  globalPipe
63
63
  });
64
- const context = new (0, _chunkLD7YMHIEjs.Context)({
64
+ const context = new (0, _chunkHKN3AAB2js.Context)({
65
65
  type: "nats",
66
66
  category: "rpc",
67
67
  moduleMap,
@@ -2,7 +2,7 @@ import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
4
  detectAopDep
5
- } from "../../chunk-G5IH3TP7.mjs";
5
+ } from "../../chunk-BLLRB5DQ.mjs";
6
6
  import {
7
7
  HMR,
8
8
  __name
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkLD7YMHIEjs = require('../../chunk-LD7YMHIE.js');
5
+ var _chunkHKN3AAB2js = require('../../chunk-HKN3AAB2.js');
6
6
 
7
7
 
8
8
 
@@ -13,19 +13,19 @@ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
13
13
  var debug = _debug2.default.call(void 0, "phecda-server/rabbitmq");
14
14
  async function bind(ch, { moduleMap, meta }, opts = {}) {
15
15
  const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts;
16
- const metaMap = _chunkLD7YMHIEjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
16
+ const metaMap = _chunkHKN3AAB2js.createControllerMetaMap.call(void 0, meta, (meta2) => {
17
17
  const { controller, rpc, method, tag } = meta2.data;
18
18
  if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
19
19
  debug(`register method "${method}" in module "${tag}"`);
20
20
  return true;
21
21
  }
22
22
  });
23
- _chunkLD7YMHIEjs.detectAopDep.call(void 0, meta, {
23
+ _chunkHKN3AAB2js.detectAopDep.call(void 0, meta, {
24
24
  guards: globalGuards,
25
25
  addons: globalAddons
26
26
  }, "rpc");
27
27
  const existQueue = /* @__PURE__ */ new Set();
28
- _chunkLD7YMHIEjs.Context.applyAddons(globalAddons, ch, "rabbitmq");
28
+ _chunkHKN3AAB2js.Context.applyAddons(globalAddons, ch, "rabbitmq");
29
29
  async function subscribeQueues() {
30
30
  existQueue.clear();
31
31
  for (const [tag, record] of metaMap) {
@@ -57,12 +57,12 @@ async function bind(ch, { moduleMap, meta }, opts = {}) {
57
57
  debug(`invoke method "${method}" in module "${tag}"`);
58
58
  const meta2 = metaMap.get(tag)[method];
59
59
  const { data: { rpc: { isEvent } = {} } } = meta2;
60
- const aop = _chunkLD7YMHIEjs.Context.getAop(meta2, {
60
+ const aop = _chunkHKN3AAB2js.Context.getAop(meta2, {
61
61
  globalFilter,
62
62
  globalGuards,
63
63
  globalPipe
64
64
  });
65
- const context = new (0, _chunkLD7YMHIEjs.Context)({
65
+ const context = new (0, _chunkHKN3AAB2js.Context)({
66
66
  type: "rabbitmq",
67
67
  category: "rpc",
68
68
  moduleMap,
@@ -2,7 +2,7 @@ import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
4
  detectAopDep
5
- } from "../../chunk-G5IH3TP7.mjs";
5
+ } from "../../chunk-BLLRB5DQ.mjs";
6
6
  import {
7
7
  HMR,
8
8
  __name
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkLD7YMHIEjs = require('../../chunk-LD7YMHIE.js');
5
+ var _chunkHKN3AAB2js = require('../../chunk-HKN3AAB2.js');
6
6
 
7
7
 
8
8
 
@@ -13,19 +13,19 @@ var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
13
13
  var debug = _debug2.default.call(void 0, "phecda-server/redis");
14
14
  function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
15
15
  const { globalGuards, globalFilter, globalPipe, globalAddons = [], defaultQueue } = opts;
16
- const metaMap = _chunkLD7YMHIEjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
16
+ const metaMap = _chunkHKN3AAB2js.createControllerMetaMap.call(void 0, meta, (meta2) => {
17
17
  const { controller, rpc, method, tag } = meta2.data;
18
18
  if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
19
19
  debug(`register method "${method}" in module "${tag}"`);
20
20
  return true;
21
21
  }
22
22
  });
23
- _chunkLD7YMHIEjs.detectAopDep.call(void 0, meta, {
23
+ _chunkHKN3AAB2js.detectAopDep.call(void 0, meta, {
24
24
  guards: globalGuards,
25
25
  addons: globalAddons
26
26
  }, "rpc");
27
27
  const existQueue = /* @__PURE__ */ new Set();
28
- _chunkLD7YMHIEjs.Context.applyAddons(globalAddons, {
28
+ _chunkHKN3AAB2js.Context.applyAddons(globalAddons, {
29
29
  pub,
30
30
  sub
31
31
  }, "redis");
@@ -54,12 +54,12 @@ function bind({ sub, pub }, { moduleMap, meta }, opts = {}) {
54
54
  if (_ps !== 1) return;
55
55
  const meta2 = metaMap.get(tag)[method];
56
56
  const { data: { rpc: { isEvent } = {} } } = meta2;
57
- const aop = _chunkLD7YMHIEjs.Context.getAop(meta2, {
57
+ const aop = _chunkHKN3AAB2js.Context.getAop(meta2, {
58
58
  globalFilter,
59
59
  globalGuards,
60
60
  globalPipe
61
61
  });
62
- const context = new (0, _chunkLD7YMHIEjs.Context)({
62
+ const context = new (0, _chunkHKN3AAB2js.Context)({
63
63
  type: "redis",
64
64
  category: "rpc",
65
65
  moduleMap,
@@ -2,7 +2,7 @@ import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
4
  detectAopDep
5
- } from "../../chunk-G5IH3TP7.mjs";
5
+ } from "../../chunk-BLLRB5DQ.mjs";
6
6
  import {
7
7
  HMR,
8
8
  __name
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkLD7YMHIEjs = require('../../chunk-LD7YMHIE.js');
5
+ var _chunkHKN3AAB2js = require('../../chunk-HKN3AAB2.js');
6
6
 
7
7
 
8
8
  var _chunk4LLLQOMFjs = require('../../chunk-4LLLQOMF.js');
@@ -13,14 +13,14 @@ var debug = _debug2.default.call(void 0, "phecda-server/ws");
13
13
  function bind(wss, data, opts = {}) {
14
14
  const { globalGuards, globalAddons, globalFilter, globalPipe } = opts;
15
15
  const { moduleMap, meta } = data;
16
- const metaMap = _chunkLD7YMHIEjs.createControllerMetaMap.call(void 0, meta, (meta2) => {
16
+ const metaMap = _chunkHKN3AAB2js.createControllerMetaMap.call(void 0, meta, (meta2) => {
17
17
  const { controller, rpc, method, tag } = meta2.data;
18
18
  if (controller === "rpc" && _optionalChain([rpc, 'optionalAccess', _ => _.queue]) !== void 0) {
19
19
  debug(`register method "${method}" in module "${tag}"`);
20
20
  return true;
21
21
  }
22
22
  });
23
- _chunkLD7YMHIEjs.detectAopDep.call(void 0, meta, {
23
+ _chunkHKN3AAB2js.detectAopDep.call(void 0, meta, {
24
24
  guards: globalGuards,
25
25
  addons: globalAddons
26
26
  }, "rpc");
@@ -32,12 +32,12 @@ function bind(wss, data, opts = {}) {
32
32
  if (_ps !== 1) return;
33
33
  const meta2 = metaMap.get(tag)[method];
34
34
  const { data: { rpc: { isEvent } = {} } } = meta2;
35
- const aop = _chunkLD7YMHIEjs.Context.getAop(meta2, {
35
+ const aop = _chunkHKN3AAB2js.Context.getAop(meta2, {
36
36
  globalFilter,
37
37
  globalGuards,
38
38
  globalPipe
39
39
  });
40
- const context = new (0, _chunkLD7YMHIEjs.Context)({
40
+ const context = new (0, _chunkHKN3AAB2js.Context)({
41
41
  type: "ws",
42
42
  category: "rpc",
43
43
  meta: meta2,
@@ -2,7 +2,7 @@ import {
2
2
  Context,
3
3
  createControllerMetaMap,
4
4
  detectAopDep
5
- } from "../../chunk-G5IH3TP7.mjs";
5
+ } from "../../chunk-BLLRB5DQ.mjs";
6
6
  import {
7
7
  __name
8
8
  } from "../../chunk-NQ55PA2X.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "8.0.1",
3
+ "version": "8.1.0",
4
4
  "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
@@ -158,7 +158,7 @@
158
158
  "fs-extra": "^11.2.0",
159
159
  "picocolors": "^1.0.0",
160
160
  "ts-mixer": "^6.0.4",
161
- "phecda-core": "5.0.1"
161
+ "phecda-core": "5.1.0"
162
162
  },
163
163
  "devDependencies": {
164
164
  "@koa/router": "^12.0.1",
@@ -20,20 +20,20 @@ export default ['Addon', 'Arg', 'Assign', 'BadGatewayException', 'BadRequestExce
20
20
  'Watcher', 'WorkerException',
21
21
  'addAddon', 'addDecoToClass',
22
22
  'addFilter', 'addGuard', 'addPipe', 'emitter',
23
- 'getMergedMeta','getMeta', 'getMetaKey', 'getMetaParams', 'getOwnMeta', 'getOwnMetaKey', 'getOwnMetaParams',
23
+ 'getMergedMeta', 'getMeta', 'getMetaKey', 'getMetaParams', 'getOwnMeta', 'getOwnMetaKey', 'getOwnMetaParams',
24
24
  'getTag',
25
25
  'isPhecda', 'log', 'phecdaNamespace', 'runMiddleware',
26
26
  'setInject',
27
27
  'setLogger',
28
28
  'setMeta',
29
29
  'useS', 'wait', 'OneFile', 'ManyFiles',
30
- 'Rule','Required','Optional',
30
+ 'Rule', 'Required', 'Optional',
31
31
  'validate',
32
- 'Min','Max','Enum','OneOf','Nested',
33
-
34
- 'Doc','DocGenerator',
35
- 'pick','omit','partial',
36
- 'functionToClass','objectToClass'
32
+ 'Min', 'Max', 'Enum', 'OneOf', 'Nested',
33
+ 'Const',
34
+ 'Doc', 'DocGenerator',
35
+ 'pick', 'omit', 'partial',
36
+ 'functionToClass', 'objectToClass'
37
37
 
38
38
 
39
39
  ]
@@ -2,6 +2,7 @@ import { register } from 'node:module'
2
2
  import { MessageChannel } from 'node:worker_threads'
3
3
  import { isPhecda, log } from '../dist/index.mjs'
4
4
  import { RELAUNCH, RELOAD } from '../dist/helper.mjs'
5
+ import inspector from 'inspector'
5
6
  const { port1, port2 } = new MessageChannel()
6
7
 
7
8
  register('./loader.mjs', {
@@ -47,3 +48,29 @@ process.on('unhandledRejection', (err) => {
47
48
 
48
49
  console.error(err)
49
50
  })
51
+
52
+
53
+ process.on('message', (data) => {
54
+ if (data.type === 'inspect') {
55
+ if (inspector.url()) {
56
+ inspector.close();
57
+ log('close inspector', 'info');
58
+ } else {
59
+ const { arg } = data
60
+
61
+ if (arg) {
62
+ if (arg.includes(':')) {
63
+ const [host, port] = arg.split(':')
64
+ inspector.open(Number(port), host)
65
+ } else {
66
+ inspector.open(Number(arg))
67
+ }
68
+ }else {
69
+ inspector.open();
70
+ }
71
+ // address already in use
72
+ if (inspector.url())
73
+ log(`open "devtools://devtools/bundled/js_app.html?experiments=true&v8only=true&ws=${inspector.url().replace("ws://", '')}" in browser`, 'info');
74
+ }
75
+ }
76
+ })
@@ -35,7 +35,7 @@ const dtsPath = process.env.PS_DTS_PATH || 'ps.d.ts'
35
35
  const watchFiles = new Set()
36
36
  const filesRecord = new Map()
37
37
  const moduleGraph = {}
38
- // ts
38
+ // ts
39
39
  let tsconfig = {
40
40
  module: ts.ModuleKind.ESNext,
41
41
  moduleResolution: ts.ModuleResolutionKind.NodeNext,
@@ -81,7 +81,7 @@ export async function initialize(data) {
81
81
 
82
82
  if (loaderPath) {
83
83
  const loader = await
84
- import (loaderPath.startsWith('.') ? resolvePath(workdir, loaderPath) : loaderPath)
84
+ import(loaderPath.startsWith('.') ? resolvePath(workdir, loaderPath) : loaderPath)
85
85
 
86
86
  if (typeof loader.load === 'function')
87
87
  customLoad = loader.load
@@ -147,80 +147,80 @@ function getFileMid(file) {
147
147
  return ret[1]
148
148
  }
149
149
 
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
- }
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,
159
158
  }
160
159
  }
160
+ }
161
161
 
162
- // entrypoint
163
- if (!context.parentURL)
164
- return nextResolve(specifier)
162
+ // entrypoint
163
+ if (!context.parentURL)
164
+ return nextResolve(specifier)
165
165
 
166
- // @todo skip resolve to improve performance
167
- // if (context.parentURL.includes('/node_modules/') && specifier.includes('/node_modules/'))
168
- // return nextResolve(specifier)
166
+ // @todo skip resolve to improve performance
167
+ // if (context.parentURL.includes('/node_modules/') && specifier.includes('/node_modules/'))
168
+ // return nextResolve(specifier)
169
169
 
170
- const { resolvedModule } = ts.resolveModuleName(
171
- specifier,
172
- fileURLToPath(context.parentURL),
173
- tsconfig,
174
- host,
175
- moduleResolutionCache,
170
+ const { resolvedModule } = ts.resolveModuleName(
171
+ specifier,
172
+ fileURLToPath(context.parentURL),
173
+ tsconfig,
174
+ host,
175
+ moduleResolutionCache,
176
+ )
177
+
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],
176
187
  )
177
188
 
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],
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,
187
194
  )
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
- }
195
+ if (resolver) {
196
+ return {
197
+ format: 'ts',
198
+ url: pathToFileURL(resolvePath(workdir, resolver.path)).href,
199
+ shortCircuit: true,
201
200
  }
202
201
  }
203
-
204
- return {
205
- format: 'ts',
206
- url,
207
- shortCircuit: true,
208
- }
209
202
  }
210
203
 
211
- const resolveRet = await nextResolve(specifier)
212
-
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}` : '')
204
+ return {
205
+ format: 'ts',
206
+ url,
207
+ shortCircuit: true,
217
208
  }
209
+ }
210
+
211
+ const resolveRet = await nextResolve(specifier)
218
212
 
219
- return resolveRet
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}` : '')
220
217
  }
221
- // @todo the first params may be url or path, need to distinguish
222
218
 
223
- export const load = async(url, context, nextLoad) => {
219
+ return resolveRet
220
+ }
221
+ // @todo the first params may be url or path, need to distinguish
222
+
223
+ export const load = async (url, context, nextLoad) => {
224
224
  let mode
225
225
  if (context.importAttributes.ps) {
226
226
  mode = context.importAttributes.ps
@@ -281,13 +281,13 @@ export const load = async(url, context, nextLoad) => {
281
281
  }
282
282
  }
283
283
 
284
-
284
+
285
285
  // resolveModuleName failed
286
286
  // I don't know why it failed
287
- if ( url.endsWith('.ts'))
287
+ if (url.endsWith('.ts'))
288
288
  context.format = 'ts'
289
289
 
290
- // module-typescript???
290
+ // module-typescript???
291
291
 
292
292
  if (context.format === 'ts') {
293
293
  const { source } = await nextLoad(url, context)
@@ -298,7 +298,7 @@ export const load = async(url, context, nextLoad) => {
298
298
 
299
299
  if (unimportRet) {
300
300
  const { injectImports } = unimportRet
301
-
301
+
302
302
  return {
303
303
  format: 'module',
304
304
  source: (
@@ -327,7 +327,7 @@ function findTopScope(url, time, modules = new Set()) {
327
327
  } else {
328
328
  if (!moduleGraph[url])
329
329
  throw new Error('root file update')
330
- for (const i of[...moduleGraph[url]]) findTopScope(i, time, modules)
330
+ for (const i of [...moduleGraph[url]]) findTopScope(i, time, modules)
331
331
  }
332
332
 
333
333
  return modules
@@ -1,6 +1,9 @@
1
1
  import { basename } from 'path'
2
2
  import { transform } from '@swc-node/core'
3
3
  import psExports from './export.mjs'
4
+ import { fileURLToPath } from 'node:url'
5
+ import path from 'node:path'
6
+
4
7
  const injectInlineSourceMap = ({ code, map }) => {
5
8
  if (map) {
6
9
  const base64Map = Buffer.from(map, 'utf8').toString('base64')
@@ -10,33 +13,34 @@ const injectInlineSourceMap = ({ code, map }) => {
10
13
  return code
11
14
  }
12
15
 
13
- export async function compile(sourcecode, filename, config = {}) {
14
- if (filename.endsWith('.d.ts'))
16
+ export async function compile(sourcecode, url, config = {}) {
17
+ if (url.endsWith('.d.ts'))
15
18
  return ''
16
19
 
20
+ const filename = path.basename(url.startsWith('file:') ? fileURLToPath(url) : url)
21
+
17
22
  const { code, map } = await transform(sourcecode, filename, {
18
- sourcemap: true,
19
23
  module: 'es6',
20
24
  emitDecoratorMetadata: true,
21
25
  experimentalDecorators: true,
22
26
  esModuleInterop: false,
27
+ sourcemap:false,
23
28
  ...config
24
29
  })
25
-
26
30
  return injectInlineSourceMap({ code, map })
27
31
  }
28
32
 
29
33
  export async function genUnImportRet(opts) {
30
34
  try {
31
35
  const { createUnimport } = await
32
- import ('unimport')
36
+ import('unimport')
33
37
  return createUnimport({
34
38
  ...opts,
35
39
 
36
40
  presets: [{
37
- from: 'phecda-server',
38
- imports: psExports,
39
- }, ]
41
+ from: 'phecda-server',
42
+ imports: psExports,
43
+ },]
40
44
  .concat(opts.presets || []),
41
45
  })
42
46
  } catch (e) {