@ditojs/server 2.51.2 → 2.52.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": "2.51.2",
3
+ "version": "2.52.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",
@@ -26,10 +26,10 @@
26
26
  "node >= 18"
27
27
  ],
28
28
  "dependencies": {
29
- "@ditojs/admin": "^2.51.2",
30
- "@ditojs/build": "^2.51.2",
31
- "@ditojs/router": "^2.51.2",
32
- "@ditojs/utils": "^2.51.2",
29
+ "@ditojs/admin": "^2.52.0",
30
+ "@ditojs/build": "^2.52.0",
31
+ "@ditojs/router": "^2.52.0",
32
+ "@ditojs/utils": "^2.52.0",
33
33
  "@koa/cors": "^5.0.0",
34
34
  "@koa/multer": "^3.1.0",
35
35
  "@originjs/vite-plugin-commonjs": "^1.0.3",
@@ -90,5 +90,5 @@
90
90
  "objection": "^3.1.5",
91
91
  "typescript": "^5.8.3"
92
92
  },
93
- "gitHead": "6df9c1bdbf04e6d4e58f53cab7ad2475fbb08161"
93
+ "gitHead": "dbfde6b475d824a88fbbbc1e007fd264e80d46fb"
94
94
  }
@@ -64,6 +64,7 @@ export class Application extends Koa {
64
64
  #logger
65
65
 
66
66
  constructor({
67
+ basePath = process.cwd(),
67
68
  config = {},
68
69
  validator,
69
70
  router,
@@ -74,6 +75,7 @@ export class Application extends Koa {
74
75
  controllers
75
76
  } = {}) {
76
77
  super()
78
+ this.basePath = basePath
77
79
  this._configureEmitter(events)
78
80
  const {
79
81
  // Pluck keys out of `config.app` to keep them secret
@@ -430,9 +432,8 @@ export class Application extends Koa {
430
432
  }
431
433
 
432
434
  async loadAdminViteConfig() {
433
- const cwd = process.cwd()
434
435
  for (const extension of ['js', 'mjs', 'cjs', 'ts']) {
435
- const file = path.join(cwd, `admin.vite.config.${extension}`)
436
+ const file = path.join(this.basePath, `admin.vite.config.${extension}`)
436
437
  try {
437
438
  await fs.access(file)
438
439
  return (await import(file)).default
@@ -21,9 +21,8 @@ const defaultValues = {
21
21
  'now()': `knex.raw('CURRENT_TIMESTAMP')`
22
22
  }
23
23
 
24
- const migrationDir = path.join(process.cwd(), 'migrations')
25
-
26
24
  export async function createMigration(app, name, ...modelNames) {
25
+ const migrationDir = path.join(app.basePath, 'migrations')
27
26
  const models = modelNames.map(modelName => {
28
27
  const modelClass = app.models[modelName]
29
28
  if (!modelClass) {
@@ -6,7 +6,7 @@ import pluralize from 'pluralize'
6
6
  import { isFunction, isArray, camelize } from '@ditojs/utils'
7
7
 
8
8
  export async function seed(app) {
9
- const seedDir = path.join(process.cwd(), 'seeds')
9
+ const seedDir = path.join(app.basePath, 'seeds')
10
10
  const files = await fs.readdir(seedDir)
11
11
  const seeds = []
12
12
  // Create a lookup table with sort indices per model name.
@@ -164,7 +164,6 @@ export class AdminController extends Controller {
164
164
  defineViteConfig(config = {}) {
165
165
  const isDevelopment = this.mode === 'development'
166
166
 
167
- const cwd = process.cwd()
168
167
  const root = this.getPath('root')
169
168
  const base = `${this.url}/`
170
169
  const views = path.join(root, 'views')
@@ -205,10 +204,10 @@ export class AdminController extends Controller {
205
204
  chunkSizeWarningLimit: 1000,
206
205
  rollupOptions: {
207
206
  output: {
208
- manualChunks(id) {
207
+ manualChunks: id => {
209
208
  if (id.startsWith(views)) {
210
209
  return 'views'
211
- } else if (id.startsWith(cwd)) {
210
+ } else if (id.startsWith(this.app.basePath)) {
212
211
  return 'common'
213
212
  } else {
214
213
  const module = id.match(
@@ -136,7 +136,7 @@ export class Storage {
136
136
 
137
137
  _getPath(...parts) {
138
138
  return this.path
139
- ? path.join(this.path, ...parts)
139
+ ? path.resolve(this.app.basePath, this.path, ...parts)
140
140
  : undefined // So that it doesn't show up in JSON data.
141
141
  }
142
142
 
@@ -1,4 +1,4 @@
1
- import { isArray, isPlainObject } from '@ditojs/utils'
1
+ import { isPlainObject, isPlainArray } from '@ditojs/utils'
2
2
 
3
3
  /**
4
4
  * Converts Models to their external representation by calling the `$toJson()`
@@ -13,7 +13,7 @@ export function convertModelsToJson(value) {
13
13
  ? value.$toJson()
14
14
  : isPlainObject(value)
15
15
  ? convertToJsonObject(value)
16
- : isArray(value)
16
+ : isPlainArray(value)
17
17
  ? convertToJsonArray(value)
18
18
  : value
19
19
  }
package/types/index.d.ts CHANGED
@@ -352,6 +352,7 @@ interface AsyncRequestLocals {
352
352
 
353
353
  export class Application<$Models extends Models = Models> {
354
354
  constructor(options: {
355
+ basePath?: string
355
356
  config?: ApplicationConfig
356
357
  validator?: Validator
357
358
  // TODO: router types