Skip to content

Commit 40fa470

Browse files
authored
Merge pull request #3 from sirius-tedarik/fix-issue-1
fix(*): generate simple dts that references to src
2 parents 5a55cd5 + 6a98853 commit 40fa470

File tree

7 files changed

+33
-8
lines changed

7 files changed

+33
-8
lines changed

.gitignore

-3
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ dist
102102

103103
# vuepress v2.x temp and cache directory
104104
.temp
105-
.cache
106105

107106
# Docusaurus cache and generated files
108107
.docusaurus
@@ -135,8 +134,6 @@ dist
135134

136135
# The `outDir` for declarations
137136
lib/
138-
# Build cache manifests
139-
*.tsbuildinfo
140137

141138
# others
142139
experiments

.moon/toolchain.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
$schema: "https://moonrepo.dev/schemas/toolchain.json"
22

33
bun:
4-
version: "1.1.7"
4+
version: "1.1.8"
55
dependencyVersionFormat: "workspace"
66
syncProjectWorkspaceDependencies: true

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
"main": "dist/index.js",
77
"module": "dist/index.js",
8+
"types": "dist/index.d.ts",
89
"files": ["dist", "src"],
9-
"types": "src/index.ts",
1010

1111
"devDependencies": {
1212
"@sirutils/builder": "workspace:*"

packages/seql/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
"main": "dist/index.js",
77
"module": "dist/index.js",
8+
"types": "dist/index.d.ts",
89
"files": ["dist", "src"],
9-
"types": "src/index.ts",
1010

1111
"devDependencies": {
1212
"@sirutils/builder": "workspace:*"

tools/builder/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
"main": "dist/index.js",
1111
"module": "dist/index.js",
12-
"types": "src/index.ts",
12+
"types": "dist/index.d.ts",
1313
"files": ["dist", "./command.js", "src"],
1414

1515
"devDependencies": {},

tools/builder/src/plugins.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { join } from 'path'
2+
import { existsSync, mkdirSync } from 'node:fs'
3+
4+
import type { BunPlugin } from 'bun'
5+
6+
export const definitionGeneratorPlugin: BunPlugin = {
7+
name: 'Definition Generator Plugin',
8+
async setup(build) {
9+
const entrypoints = [...build.config.entrypoints].sort()
10+
11+
const outDir = build.config.outdir || './dist'
12+
if (!existsSync(outDir)) {
13+
mkdirSync(outDir)
14+
}
15+
16+
await Promise.all(
17+
entrypoints.map(entry => {
18+
const srcFile = entry.replace(/^.*\//, '')
19+
const dtsFile = srcFile.replace(/\.[jtm]s$/, '.d.ts')
20+
const outFile = join(outDir, dtsFile)
21+
22+
return Bun.write(outFile, `export * from "../src/${srcFile}"`)
23+
})
24+
)
25+
},
26+
}

tools/builder/src/utils.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { join } from 'path'
22
import type { BunPlugin } from 'bun'
33

4+
import { definitionGeneratorPlugin } from './plugins'
5+
46
export const dependencies = async (cwd = process.cwd()): Promise<string[]> => {
57
const pkg = await Bun.file(join(cwd, './package.json')).json()
68

@@ -23,7 +25,7 @@ export const build = async (
2325
) => {
2426
const entryPoints = paths.map(p => join(cwd, p))
2527
const outDir = join(cwd, './dist')
26-
const plugins: BunPlugin[] = []
28+
const plugins: BunPlugin[] = [definitionGeneratorPlugin]
2729

2830
await Bun.build({
2931
entrypoints: entryPoints,

0 commit comments

Comments
 (0)