Skip to content

Commit f7422a5

Browse files
authored
fix: automatically add types in generated tsconfig (#19)
1 parent 4b7b548 commit f7422a5

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

build.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ export default defineBuildConfig({
1414
},
1515
],
1616
declaration: true,
17-
externals: ['#imports', 'h3', 'nitropack'],
17+
externals: ['#imports', 'h3', 'nitropack', 'nitro-opentelemetry'],
1818
})

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@
6060
"nitropack": "^2.10.4",
6161
"typescript": "^5.6.2",
6262
"unbuild": "^2.0.0",
63-
"vitest": "^2.1.5"
63+
"vitest": "^2.1.5",
64+
"nitro-opentelemetry": "link:./"
6465
},
6566
"packageManager": "pnpm@9.15.4",
6667
"dependencies": {

playground/tsconfig.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
11
// https://nitro.unjs.io/guide/typescript
22
{
3-
"extends": "./.nitro/types/tsconfig.json",
4-
"compilerOptions": {
5-
"types": [
6-
"nitro-opentelemetry"
7-
]
8-
}
3+
"extends": "./.nitro/types/tsconfig.json"
94
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/module.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import MagicString from 'magic-string'
66
import { getPresetFile, isPresetEntry } from './presets'
77
import { normalize } from "pathe"
88
import type { Nuxt } from "@nuxt/schema"
9-
import { fileURLToPath } from 'node:url'
109
import defu from 'defu'
1110

1211
async function module(nitro: Nitro) {
@@ -17,7 +16,7 @@ async function module(nitro: Nitro) {
1716
nitro.options.entry = await getPresetFile(nitro)
1817
}
1918

20-
if(nitro.options.otel?.preset !== false) {
19+
if (nitro.options.otel?.preset !== false) {
2120
nitro.hooks.hook('rollup:before', (nitro, rollupConfig) => {
2221
if (!rollupConfig.plugins) rollupConfig.plugins = [];
2322
const plugins = rollupConfig.plugins
@@ -30,7 +29,7 @@ async function module(nitro: Nitro) {
3029
return true
3130
});
3231
}
33-
32+
3433
(rollupConfig.plugins as Plugin[]).push({
3534
name: 'inject-init-plugin',
3635
async transform(code, id) {
@@ -39,7 +38,7 @@ async function module(nitro: Nitro) {
3938
if (normalizedId.includes('runtime/entries') || this.getModuleInfo(id)?.isEntry) {
4039
const s = new MagicString(code)
4140
s.prepend(`import '#nitro-opentelemetry/init';`)
42-
41+
4342
return {
4443
code: s.toString(),
4544
map: s.generateMap({ hires: true }),
@@ -85,7 +84,11 @@ async function module(nitro: Nitro) {
8584
inline: [nitro.options.errorHandler]
8685
})
8786
}
88-
87+
nitro.options.typescript.tsConfig = defu(nitro.options.typescript.tsConfig, {
88+
compilerOptions: {
89+
types: ['nitro-opentelemetry']
90+
}
91+
})
8992
nitro.options.plugins.push(await resolvePath('nitro-opentelemetry/runtime/plugin', {
9093
extensions: ['.mjs', '.ts']
9194
}))

test/fixtures/basic/tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
{
2-
"extends": "./.nitro/types/tsconfig.json",
3-
"compilerOptions": {
4-
"types": ["nitro-opentelemetry"]
5-
}
2+
"extends": "./.nitro/types/tsconfig.json"
63
}

0 commit comments

Comments
 (0)