@ditojs/server 1.19.1 → 1.20.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ditojs/server",
3
- "version": "1.19.1",
3
+ "version": "1.20.0",
4
4
  "type": "module",
5
5
  "description": "Dito.js Server – Dito.js is a declarative and modern web framework, based on Objection.js, Koa.js and Vue.js",
6
6
  "repository": "https://github.com/ditojs/dito/tree/master/packages/server",
@@ -25,10 +25,10 @@
25
25
  "node >= 18"
26
26
  ],
27
27
  "dependencies": {
28
- "@ditojs/admin": "^1.19.1",
29
- "@ditojs/build": "^1.19.0",
30
- "@ditojs/router": "^1.19.0",
31
- "@ditojs/utils": "^1.19.0",
28
+ "@ditojs/admin": "^1.20.0",
29
+ "@ditojs/build": "^1.20.0",
30
+ "@ditojs/router": "^1.20.0",
31
+ "@ditojs/utils": "^1.20.0",
32
32
  "@koa/cors": "^4.0.0",
33
33
  "@koa/multer": "^3.0.2",
34
34
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -41,7 +41,7 @@
41
41
  "file-type": "^18.0.0",
42
42
  "image-size": "^1.0.2",
43
43
  "is-svg": "^4.3.2",
44
- "koa": "^2.13.4",
44
+ "koa": "^2.14.0",
45
45
  "koa-bodyparser": "^4.3.0",
46
46
  "koa-compose": "^4.1.0",
47
47
  "koa-compress": "^5.1.0",
@@ -78,7 +78,7 @@
78
78
  "objection": "^3.0.1"
79
79
  },
80
80
  "devDependencies": {
81
- "@aws-sdk/client-s3": "^3.223.0",
81
+ "@aws-sdk/client-s3": "^3.224.0",
82
82
  "@types/koa-bodyparser": "^4.3.10",
83
83
  "@types/koa-compress": "^4.0.3",
84
84
  "@types/koa-logger": "^3.1.2",
@@ -87,12 +87,12 @@
87
87
  "@types/koa-session": "^5.10.6",
88
88
  "@types/koa-static": "^4.0.2",
89
89
  "@types/koa__cors": "^3.3.0",
90
- "@types/node": "^18.11.10",
90
+ "@types/node": "^18.11.11",
91
91
  "knex": "^2.3.0",
92
92
  "objection": "^3.0.1",
93
93
  "type-fest": "^3.3.0",
94
94
  "typescript": "^4.9.3"
95
95
  },
96
96
  "types": "types",
97
- "gitHead": "a1ea63d36d6a971c3645f7f7245a277607cdbbb9"
97
+ "gitHead": "049aa3611927f3f096bc6230f0ce93e1419303e4"
98
98
  }
@@ -8,7 +8,8 @@ import {
8
8
  } from '@originjs/vite-plugin-commonjs'
9
9
  import {
10
10
  createRollupImportsResolver,
11
- testModuleIdentifier
11
+ testModuleIdentifier,
12
+ getPostCssConfig
12
13
  } from '@ditojs/build'
13
14
  import { merge } from '@ditojs/utils'
14
15
  import { Controller } from './Controller.js'
@@ -126,6 +127,7 @@ export class AdminController extends Controller {
126
127
 
127
128
  async setupViteServer() {
128
129
  const config = this.getViteConfig()
130
+ const development = this.mode === 'development'
129
131
  const server = await createServer({
130
132
  ...config,
131
133
  server: {
@@ -135,12 +137,13 @@ export class AdminController extends Controller {
135
137
  // may be running multiple servers in parallel (e.g. e2e and dev).
136
138
  port: await getRandomFreePort()
137
139
  },
138
- watch: {
139
- // Watch the @ditojs packages while in dev mode, although they are
140
- // inside the node_modules folder.
141
- // TODO: This should only really be done if they are symlinked.
142
- ignored: ['!**/node_modules/@ditojs/**']
143
- }
140
+ ...(development && {
141
+ watch: {
142
+ // Watch the @ditojs packages while in dev mode, although they are
143
+ // inside the node_modules folder.
144
+ ignored: ['!**/node_modules/@ditojs/**']
145
+ }
146
+ })
144
147
  }
145
148
  })
146
149
 
@@ -192,31 +195,31 @@ export class AdminController extends Controller {
192
195
  }
193
196
  }],
194
197
  build: {
195
- ...(development
196
- ? {}
197
- : {
198
- outDir: this.getPath('dist'),
199
- assetsDir: '.',
200
- emptyOutDir: true,
201
- chunkSizeWarningLimit: 1000,
202
- rollupOptions: {
203
- output: {
204
- manualChunks(id) {
205
- if (id.startsWith(views)) {
206
- return 'views'
207
- } else if (id.startsWith(cwd)) {
208
- return 'common'
209
- } else {
210
- const module = id.match(/node_modules\/([^/$]*)/)?.[1] || ''
211
- return testModuleIdentifier(module, coreDependencies)
212
- ? 'core'
213
- : 'vendor'
214
- }
198
+ ...(!development && {
199
+ outDir: this.getPath('dist'),
200
+ assetsDir: '.',
201
+ emptyOutDir: true,
202
+ chunkSizeWarningLimit: 1000,
203
+ rollupOptions: {
204
+ output: {
205
+ manualChunks(id) {
206
+ if (id.startsWith(views)) {
207
+ return 'views'
208
+ } else if (id.startsWith(cwd)) {
209
+ return 'common'
210
+ } else {
211
+ const module = id.match(/node_modules\/([^/$]*)/)?.[1] || ''
212
+ return testModuleIdentifier(module, coreDependencies)
213
+ ? 'core'
214
+ : 'vendor'
215
215
  }
216
216
  }
217
217
  }
218
218
  }
219
- )
219
+ })
220
+ },
221
+ css: {
222
+ postcss: getPostCssConfig()
220
223
  },
221
224
  optimizeDeps: {
222
225
  exclude: development ? ditoPackages : [],
@@ -1,13 +1,15 @@
1
- import { camelize } from '@ditojs/utils'
1
+ import { camelize, hyphenate } from '@ditojs/utils'
2
2
 
3
3
  export class Service {
4
4
  initialized = false
5
+ #loggerName
5
6
 
6
7
  constructor(app, name) {
7
8
  this.app = app
8
9
  this.name = camelize(
9
10
  (name || this.constructor.name).match(/^(.*?)(?:Service|)$/)[1]
10
11
  )
12
+ this.#loggerName = hyphenate(this.name)
11
13
  this.config = null
12
14
  }
13
15
 
@@ -29,9 +31,11 @@ export class Service {
29
31
  async stop() {
30
32
  }
31
33
 
34
+ // Only use this method to get a logger instance that is bound to the context,
35
+ // otherwise use the getter.
32
36
  getLogger(ctx) {
33
37
  const logger = ctx?.logger ?? this.app.logger
34
- return logger.child({ name: this.name })
38
+ return logger.child({ name: this.#loggerName })
35
39
  }
36
40
 
37
41
  get logger() {
package/src/utils/net.js CHANGED
@@ -4,7 +4,7 @@ export async function getRandomFreePort() {
4
4
  return new Promise((resolve, reject) => {
5
5
  const srv = net.createServer()
6
6
  srv.listen(0, () => {
7
- const port = srv.address().port
7
+ const { port } = srv.address()
8
8
  srv.close(err => {
9
9
  if (err) {
10
10
  reject(err)
package/types/index.d.ts CHANGED
@@ -32,6 +32,7 @@ import {
32
32
  SetReturnType
33
33
  } from 'type-fest'
34
34
  import { UserConfig } from 'vite'
35
+ import { Logger } from 'pino'
35
36
 
36
37
  export type Page<$Model extends Model = Model> = {
37
38
  total: number
@@ -402,6 +403,7 @@ export class Application<$Models extends Models = Models> {
402
403
  addControllers(controllers: ApplicationControllers, namespace?: string): void
403
404
  setupControllers(): Promise<void>
404
405
  getAdminViteConfig(config?: UserConfig): UserConfig
406
+ logger: Logger
405
407
  }
406
408
  export interface Application
407
409
  extends Omit<
@@ -1440,6 +1442,8 @@ export class Service {
1440
1442
  initialize(): void
1441
1443
  start(): Promise<void>
1442
1444
  stop(): Promise<void>
1445
+ get logger(): Logger
1446
+ getLogger(ctx: KoaContext): Logger
1443
1447
  }
1444
1448
  export type Services = Record<string, Class<Service> | Service>
1445
1449