phecda-server 5.0.1 → 5.0.2

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/bin/schema.json CHANGED
@@ -38,6 +38,13 @@
38
38
  },
39
39
  "description": "Including the module's file middle name, such as controller mapping to xx.controller.ts"
40
40
  },
41
+ "virtualFile": {
42
+ "type": "object",
43
+ "additionalProperties": {
44
+ "type": "string"
45
+ },
46
+ "description": "Virtual module, just like in Vite."
47
+ },
41
48
  "unimport": {
42
49
  "type": "object",
43
50
  "description": "Includes the arguments passed to unimport and 'dtsPath' that specifies the location for generating type files."
package/dist/test.js CHANGED
@@ -55,7 +55,14 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
55
55
  else
56
56
  ret[item.type] = args[item.index];
57
57
  });
58
- return (isAgent ? Agent : request(app))[ret.func](ret.url).query(ret.query).set(ret.headers).send(ret.body);
58
+ let agent2 = (isAgent ? Agent : request(app))[ret.func](ret.url);
59
+ if (Object.keys(ret.query).length > 0)
60
+ agent2 = agent2.query(ret.query);
61
+ if (Object.keys(ret.headers).length > 0)
62
+ agent2 = agent2.set(ret.headers);
63
+ if (Object.keys(ret.body).length > 0)
64
+ agent2 = agent2.send(ret.body);
65
+ return agent2;
59
66
  };
60
67
  }
61
68
  });
package/dist/test.mjs CHANGED
@@ -55,7 +55,14 @@ async function TestHttp(app, { moduleMap, meta }, isAgent = true) {
55
55
  else
56
56
  ret[item.type] = args[item.index];
57
57
  });
58
- return (isAgent ? Agent : request(app))[ret.func](ret.url).query(ret.query).set(ret.headers).send(ret.body);
58
+ let agent2 = (isAgent ? Agent : request(app))[ret.func](ret.url);
59
+ if (Object.keys(ret.query).length > 0)
60
+ agent2 = agent2.query(ret.query);
61
+ if (Object.keys(ret.headers).length > 0)
62
+ agent2 = agent2.set(ret.headers);
63
+ if (Object.keys(ret.body).length > 0)
64
+ agent2 = agent2.send(ret.body);
65
+ return agent2;
59
66
  };
60
67
  }
61
68
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "5.0.1",
3
+ "version": "5.0.2",
4
4
  "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor ",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -51,14 +51,18 @@ export async function initialize(data) {
51
51
  )
52
52
 
53
53
  config = require(configPath)
54
+ if (!config.virtualFile)
55
+ config.virtualFile = {}
54
56
 
55
- chokidar.watch(configPath, { persistent: true }).on('change', () => {
56
- port.postMessage(
57
- JSON.stringify({
58
- type: 'relaunch',
59
- }),
60
- )
61
- })
57
+ if (!process.env.PS_HMR_BAN) {
58
+ chokidar.watch(configPath, { persistent: true }).on('change', () => {
59
+ port.postMessage(
60
+ JSON.stringify({
61
+ type: 'relaunch',
62
+ }),
63
+ )
64
+ })
65
+ }
62
66
 
63
67
  if (!config.unimport)
64
68
  return
@@ -96,6 +100,14 @@ function getFileMid(file) {
96
100
  }
97
101
 
98
102
  export const resolve = async (specifier, context, nextResolve) => {
103
+ // virtual file
104
+ if (config.virtualFile[specifier]) {
105
+ return {
106
+ format: 'ts',
107
+ url: specifier,
108
+ shortCircuit: true,
109
+ }
110
+ }
99
111
  // entrypoint
100
112
  if (!context.parentURL) {
101
113
  entryUrl = specifier
@@ -107,6 +119,7 @@ export const resolve = async (specifier, context, nextResolve) => {
107
119
  shortCircuit: true,
108
120
  }
109
121
  }
122
+ // url import
110
123
  if (/^file:\/\/\//.test(specifier) && extname(specifier) === '.ts') {
111
124
  const url = addUrlToGraph(specifier, context.parentURL.split('?')[0])
112
125
 
@@ -116,6 +129,8 @@ export const resolve = async (specifier, context, nextResolve) => {
116
129
  shortCircuit: true,
117
130
  }
118
131
  }
132
+
133
+ // hmr import
119
134
  if (
120
135
  context.parentURL.includes('/node_modules/phecda-server')
121
136
  && isAbsolute(specifier)
@@ -125,6 +140,7 @@ export const resolve = async (specifier, context, nextResolve) => {
125
140
  .slice(1)
126
141
  context.parentURL = entryUrl
127
142
  }
143
+
128
144
  // import/require from external library
129
145
  if (context.parentURL.includes('/node_modules/'))
130
146
  return nextResolve(specifier)
@@ -167,10 +183,20 @@ export const resolve = async (specifier, context, nextResolve) => {
167
183
  shortCircuit: true,
168
184
  }
169
185
  }
186
+
170
187
  return nextResolve(specifier)
171
188
  }
189
+ // @todo the first params may be url or path, need to distinguish
172
190
 
173
191
  export const load = async (url, context, nextLoad) => {
192
+ if (config.virtualFile[url]) {
193
+ return {
194
+ format: 'module',
195
+ source: config.virtualFile[url],
196
+ shortCircuit: true,
197
+ }
198
+ }
199
+
174
200
  url = url.split('?')[0]
175
201
  if (
176
202
  !url.includes('/node_modules/')
@@ -244,7 +270,9 @@ export const load = async (url, context, nextLoad) => {
244
270
  const { injectImports } = unimportRet
245
271
  return {
246
272
  format: 'module',
247
- source: (await injectImports(compiled)).code,
273
+ source: (
274
+ await injectImports(compiled, (url.startsWith('file://') ? fileURLToPath(url) : url).replace(/\\/g, '/'))
275
+ ).code,
248
276
  shortCircuit: true,
249
277
  }
250
278
  }