Skip to content

Commit 85c9f87

Browse files
committed
feat: augment app.globals.d.ts to index.d.*ts files at build time
1 parent 614a52b commit 85c9f87

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

examples/basic-app/src/bootstrap/providers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { AppServiceProvider } from 'src/app/Providers/AppServiceProvider'
1313
/**
1414
* Default service provider have a priority ranging from 999-990
1515
* We recommend leaving the 900 range for the defaults.
16+
* Service provider names should be unique as duplicates might be filtered out
17+
* including custom providers matching core provider names
1618
*/
1719
export default <Array<new (_app: Application) => IServiceProvider>>[
1820
HttpServiceProvider,

examples/basic-app/src/routes/api.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// import { AuthMiddleware } from 'App/Http/Middlewares/AuthMiddleware'
1+
import { AuthMiddleware } from 'App/Http/Middlewares/AuthMiddleware'
22
import { Router } from '@h3ravel/router'
3-
// import { UserController } from 'App/Http/Controllers/UserController'
3+
import { UserController } from 'App/Http/Controllers/UserController'
44

55
export default (Route: Router) => {
66
Route.group({
@@ -10,7 +10,7 @@ export default (Route: Router) => {
1010
}
1111
]
1212
}, () => {
13-
// Route.apiResource('/users', UserController, [new AuthMiddleware()])
13+
Route.apiResource('/users', UserController, [new AuthMiddleware()])
1414
})
1515

1616
Route.get('/hello', () => 'Hello', 'hello.route')

examples/basic-app/src/server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import app from 'src/bootstrap/app'
55
new app().bootstrap();
66

77
['SIGINT', 'SIGTERM', 'SIGTSTP'].forEach(sig => process.on(sig, () => {
8-
process.exit(0);
9-
}));
8+
process.exit(0)
9+
}))

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@h3ravel/core",
3-
"version": "1.9.2",
3+
"version": "1.9.3",
44
"description": "Core application container, lifecycle management and service providers for H3ravel.",
55
"type": "module",
66
"main": "./dist/index.js",

tsdown.config.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type Options, defineConfig } from 'tsdown'
2-
import { copyFile, glob, mkdir } from 'node:fs/promises'
2+
import { copyFile, glob, mkdir, readFile, writeFile } from 'node:fs/promises'
33

44
import path from 'node:path'
55
import { exists, findUpConfig } from './utils/fs'
@@ -13,7 +13,9 @@ export const baseConfig: Options = {
1313
sourcemap: true,
1414
hooks (hooks) {
1515
hooks.hook('build:done', async (ctx) => {
16-
// Get the absolute base path
16+
// Get the absolute output directory
17+
const outDir = ctx.options.outDir ?? 'dist'
18+
// Get the absolute base directory
1719
const base = await findUpConfig('framework', 'package', ['json'])
1820
if (!base) return
1921
// Make globale DTS partern
@@ -29,6 +31,20 @@ export const baseConfig: Options = {
2931
// Copy required files only for current package
3032
if (await exists(entry) && entry.includes(ctx.options.cwd))
3133
copyFile(entry, target)
34+
// Augment the d.ts file to the index.d.ts
35+
if (entry.includes('.d.ts')) {
36+
for await (const indexFile of glob(path.join(outDir, 'index.d.*ts'))) {
37+
const reference = `/// <reference path="./${path.basename(entry)}" />\n`
38+
if (await exists(indexFile)) {
39+
let content = await readFile(indexFile, 'utf8')
40+
// Only add if it’s not already there
41+
if (!content.includes(reference.trim())) {
42+
content = reference + content
43+
await writeFile(indexFile, content, 'utf8')
44+
}
45+
}
46+
}
47+
}
3248
}
3349
})
3450
},

0 commit comments

Comments
 (0)