phecda-server 7.0.0-alpha.10 → 7.0.0-alpha.11

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/cli.mjs CHANGED
@@ -88,7 +88,7 @@ cli
88
88
  process.chdir(root)
89
89
 
90
90
  const tsconfigPath = options.tsconfig
91
- const psconfigPath = options.config
91
+ const psconfigPath = process.env.PS_CONFIG_FILE || options.config
92
92
 
93
93
  if (!fse.existsSync(tsconfigPath)) {
94
94
  log(`create ${tsconfigPath}`)
@@ -124,7 +124,7 @@ cli
124
124
  else
125
125
  process.env.NODE_ENV = 'development'
126
126
 
127
- process.env.PS_CONFIG_FILE = options.config
127
+ process.env.PS_CONFIG_FILE = process.env.PS_CONFIG_FILE || options.config
128
128
 
129
129
  log('process start!')
130
130
 
@@ -164,7 +164,7 @@ cli
164
164
  if (root)
165
165
  process.chdir(root)
166
166
  process.env.PS_GENERATE = 'true'
167
- process.env.PS_CONFIG_FILE = options.config
167
+ process.env.PS_CONFIG_FILE = process.env.PS_CONFIG_FILE || options.config
168
168
  startChild(file, options['--'])
169
169
  })
170
170
 
package/dist/test.d.mts CHANGED
@@ -11,7 +11,7 @@ declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
11
11
  type SuperTestRequest<T> = {
12
12
  [K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
13
13
  };
14
- declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "use" | "on" | "set" | "query" | "type" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "key" | "pfx" | "cert"> & {
14
+ declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "query" | "set" | "key" | "use" | "on" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
15
15
  module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
16
16
  }>;
17
17
 
package/dist/test.d.ts CHANGED
@@ -11,7 +11,7 @@ declare function TestFactory<T extends Construct[]>(...Modules: T): Promise<{
11
11
  type SuperTestRequest<T> = {
12
12
  [K in keyof T]: T[K] extends (...args: infer R) => any ? (...args: R) => Test : never;
13
13
  };
14
- declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "use" | "on" | "set" | "query" | "type" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "key" | "pfx" | "cert"> & {
14
+ declare function TestHttp(app: Server | any, { moduleMap, meta }: Awaited<ReturnType<typeof Factory>>, isAgent?: boolean): Promise<supertest.SuperTestWithHost<Test> & Pick<supertest.Request, "type" | "query" | "set" | "key" | "use" | "on" | "accept" | "auth" | "withCredentials" | "retry" | "ok" | "redirects" | "timeout" | "buffer" | "serialize" | "parse" | "ca" | "pfx" | "cert"> & {
15
15
  module: <T extends Construct>(Module: T) => SuperTestRequest<PickFunc<InstanceType<T>>>;
16
16
  }>;
17
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phecda-server",
3
- "version": "7.0.0-alpha.10",
3
+ "version": "7.0.0-alpha.11",
4
4
  "description": "server framework that provide IOC/type-reuse/http&rpc-adaptor",
5
5
  "author": "fgsreally",
6
6
  "license": "MIT",
@@ -148,7 +148,6 @@
148
148
  "picocolors": "^1.0.0",
149
149
  "reflect-metadata": "^0.1.13",
150
150
  "ts-mixer": "^6.0.4",
151
- "unconfig": "^0.6.0",
152
151
  "phecda-core": "4.1.0-alpha.0"
153
152
  },
154
153
  "devDependencies": {
@@ -178,7 +177,7 @@
178
177
  "nats": "^2.22.0",
179
178
  "supertest": "^6.3.3",
180
179
  "tsup": "^8.1.0",
181
- "typescript": "^5.4.5",
180
+ "typescript": "^5.7.2",
182
181
  "unimport": "^3.7.1"
183
182
  },
184
183
  "scripts": {
@@ -3,18 +3,18 @@ import { writeFile } from 'fs/promises'
3
3
  import {
4
4
  basename,
5
5
  dirname,
6
- extname,
7
6
  isAbsolute,
8
7
  relative,
9
8
  resolve as resolvePath,
10
9
  } from 'path'
11
10
  import { existsSync } from 'fs'
11
+ import { createRequire } from 'module'
12
12
  import ts from 'typescript'
13
13
  import chokidar from 'chokidar'
14
14
  import Debug from 'debug'
15
- import { loadConfig } from 'unconfig'
16
15
  import { compile, genUnImportRet, handleClassTypes, slash } from './utils.mjs'
17
16
 
17
+ const require = createRequire(import.meta.url)
18
18
  const debug = Debug('phecda-server/loader')
19
19
 
20
20
  const isLowVersion = parseFloat(process.version.slice(1)) < 18.19
@@ -72,16 +72,17 @@ export async function initialize(data) {
72
72
 
73
73
  debug('read config...')
74
74
 
75
- const unconfigRet = await loadConfig({
76
- sources: [
77
- {
78
- files: configPath,
79
- extensions: ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json', ''],
80
- },
81
- ],
82
- merge: false,
83
- })
84
- config = unconfigRet.config
75
+ config = require(configPath)
76
+ // const unconfigRet = await loadConfig({
77
+ // sources: [
78
+ // {
79
+ // files: configPath,
80
+ // extensions: ['ts', 'mts', 'cts', 'js', 'mjs', 'cjs', 'json', ''],
81
+ // },
82
+ // ],
83
+ // merge: false,
84
+ // })
85
+ // config = unconfigRet.config
85
86
  if (!config.virtualFile)
86
87
  config.virtualFile = {}
87
88
  if (!config.paths)
@@ -170,14 +171,15 @@ export const resolve = async (specifier, context, nextResolve) => {
170
171
  }
171
172
  // url import
172
173
  // it seems useless
173
- if (/^file:\/\/\//.test(specifier) && extname(specifier) === '.ts') {
174
- const url = addUrlToGraph(specifier, context.parentURL.split('?')[0])
175
- return {
176
- format: 'ts',
177
- url,
178
- shortCircuit: true,
179
- }
180
- }
174
+ // if (/^file:\/\/\//.test(specifier) && extname(specifier) === '.ts') {
175
+ // const url = addUrlToGraph(specifier, context.parentURL.split('?')[0])
176
+ // return {
177
+ // format: 'ts',
178
+ // url,
179
+ // shortCircuit: true,
180
+ // }
181
+ // }
182
+
181
183
 
182
184
  // hmr import
183
185
  if (
@@ -201,7 +203,7 @@ export const resolve = async (specifier, context, nextResolve) => {
201
203
  moduleResolutionCache,
202
204
  )
203
205
 
204
- // import between loacl projects
206
+ // import among files in local project
205
207
  if (
206
208
  resolvedModule
207
209
  && !resolvedModule.resolvedFileName.includes('/node_modules/')
@@ -234,6 +236,7 @@ export const resolve = async (specifier, context, nextResolve) => {
234
236
  }
235
237
  }
236
238
 
239
+
237
240
  const resolveRet = await nextResolve(specifier)
238
241
 
239
242
  // ts resolve fail in some cases
@@ -245,6 +248,9 @@ export const resolve = async (specifier, context, nextResolve) => {
245
248
  // @todo the first params may be url or path, need to distinguish
246
249
 
247
250
  export const load = async (url, context, nextLoad) => {
251
+
252
+
253
+
248
254
  if (config.virtualFile[url]) {
249
255
  return {
250
256
  format: 'module',
@@ -253,6 +259,14 @@ export const load = async (url, context, nextLoad) => {
253
259
  }
254
260
  }
255
261
 
262
+ let mode
263
+ if (context.importAttributes.ps) {
264
+ mode = context.importAttributes.ps
265
+ delete context.importAttributes.ps
266
+ }
267
+
268
+
269
+
256
270
  url = url.split('?')[0]
257
271
  if (
258
272
  !url.includes('/node_modules/')
@@ -262,7 +276,7 @@ export const load = async (url, context, nextLoad) => {
262
276
  ) {
263
277
  watchFiles.add(url)
264
278
 
265
- if (IS_DEV) {
279
+ if (IS_DEV && mode !== 'not-hmr') {
266
280
  if (isModuleFileUrl(url)) {
267
281
  port.postMessage(
268
282
  JSON.stringify({
@@ -306,10 +320,14 @@ export const load = async (url, context, nextLoad) => {
306
320
 
307
321
  const code
308
322
  = typeof source === 'string' ? source : Buffer.from(source).toString()
323
+
309
324
  const compiled = (await compile(code, url)).replace(/_ts_metadata\(\"design:paramtypes\"\,/g, '_ts_metadata("design:paramtypes",()=>')// handle cycle
310
325
 
311
326
  if (unimportRet) {
327
+
328
+
312
329
  const { injectImports } = unimportRet
330
+
313
331
  return {
314
332
  format: 'module',
315
333
  source: (
@@ -20,6 +20,32 @@ export async function compile(sourcecode, filename) {
20
20
  emitDecoratorMetadata: true,
21
21
  experimentalDecorators: true,
22
22
  esModuleInterop: false,
23
+ swc: {
24
+
25
+ jsc: {
26
+ parser: {
27
+ syntax: "typescript",
28
+ importAttributes: true,
29
+ decorators: true,
30
+ tsx: false,
31
+ dynamicImport: true,
32
+ strictPropertyInitialization: false
33
+ },
34
+ experimental: {
35
+ keepImportAssertions: true
36
+ },
37
+ transform: {
38
+ legacyDecorator: true,
39
+ decoratorMetadata: true
40
+ }
41
+ // parser: {
42
+ // importAttributes: true
43
+ // },
44
+ // experimental: {
45
+ // keepImportAssertions: true
46
+ // }
47
+ }
48
+ }
23
49
  })
24
50
 
25
51
  return injectInlineSourceMap({ code, map })