Skip to content

Commit

Permalink
chore: several minor adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbbreuer committed Nov 8, 2024
1 parent c2ecc45 commit a6ef9a1
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 19 deletions.
1 change: 1 addition & 0 deletions .vscode/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ davidanson
degit
deps
destructurable
dtsx
entrypoints
heroicons
lockb
Expand Down
11 changes: 2 additions & 9 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { log } from '@stacksjs/cli'
import { fs } from '@stacksjs/storage'
import { generateDeclarationsFromFiles } from './src/generate'
import { dts } from 'bun-plugin-dtsx'

log.info('Building...')

Expand All @@ -12,16 +12,9 @@ await Bun.build({
format: 'esm',
target: 'bun',
minify: true,
plugins: [dts()],
})

try {
await generateDeclarationsFromFiles()
console.log('Generated declarations')
}
catch (error) {
console.error('Error generating declarations:', error)
}

// prepare dist for publishing
await fs.move('./dist/bin/cli.js', './dist/cli.js')
await fs.move('./dist/src/index.js', './dist/index.js')
Expand Down
Binary file modified bun.lockb
Binary file not shown.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@
"@stacksjs/eslint-config": "^3.8.1-beta.2",
"@types/bun": "^1.1.13",
"bun-config": "^0.1.1",
"bun-plugin-dtsx": "^0.21.2",
"tinyglobby": "^0.2.10",
"vitepress": "^1.5.0"
},
"simple-git-hooks": {
"pre-commit": "bunx lint-staged"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": "bunx eslint . --fix"
"*.{js,ts}": "bunx eslint . --fix"
}
}
1 change: 0 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import { loadConfig } from 'bun-config'
// eslint-disable-next-line antfu/no-top-level-await
export const config: DtsGenerationConfig = await loadConfig({
name: 'dts',
cwd: resolve('./', __dirname.includes('node_modules') ? '../../..' : '..'),
defaultConfig: {
cwd: process.cwd(),
root: './src',
Expand Down
14 changes: 7 additions & 7 deletions src/generate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DtsGenerationConfig, DtsGenerationOption } from './types'
import { mkdir, rm } from 'node:fs/promises'
import { dirname, join, parse, relative } from 'node:path'
import process from 'node:process'
import { glob } from 'tinyglobby'
import { config } from './config'
import { extract } from './extract'
Expand Down Expand Up @@ -35,12 +36,14 @@ export async function generateDeclarationsFromFiles(options?: DtsGenerationConfi
await rm(options.outdir, { recursive: true, force: true })
}

const cwd = options?.cwd || process.cwd()
let files: string[]

if (options?.entrypoints) {
files = await glob(options.entrypoints, { cwd: options.root ?? `${options.cwd}/src`, absolute: true })
files = await glob(options.entrypoints, { cwd: options.root ?? `${cwd}/src`, absolute: true })
}
else {
files = await getAllTypeScriptFiles(options?.root ?? `${options?.cwd}/src`)
files = await getAllTypeScriptFiles(options?.root ?? `${cwd}/src`)
}

for (const file of files) {
Expand All @@ -51,11 +54,8 @@ export async function generateDeclarationsFromFiles(options?: DtsGenerationConfi
const parsedPath = parse(relativePath)
const outputPath = join(options?.outdir ?? './dist', `${parsedPath.name}.d.ts`)

// Ensure the directory exists
await mkdir(dirname(outputPath), { recursive: true })

// Write the declarations without additional formatting
await writeToFile(outputPath, fileDeclarations)
await mkdir(dirname(outputPath), { recursive: true }) // Ensure the directory exists
await writeToFile(outputPath, fileDeclarations) // Write the declarations without additional formatting
}
else {
console.warn(`No declarations extracted for ${file}`)
Expand Down
5 changes: 4 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DtsGenerationConfig } from './types'
import { readdir } from 'node:fs/promises'
import { extname, join } from 'node:path'
import process from 'node:process'
import { config } from './config'

export async function writeToFile(filePath: string, content: string): Promise<void> {
Expand All @@ -21,7 +22,9 @@ export async function getAllTypeScriptFiles(directory?: string): Promise<string[

export async function checkIsolatedDeclarations(options?: DtsGenerationConfig): Promise<boolean> {
try {
const tsconfigPath = options?.tsconfigPath || join(options?.cwd ?? './', 'tsconfig.json')
const cwd = options?.cwd || process.cwd()
const tsconfigPath = options?.tsconfigPath || join(cwd, 'tsconfig.json')
console.log('tsconfigPath', tsconfigPath)
const tsconfig = await import(tsconfigPath)

return tsconfig.compilerOptions?.isolatedDeclarations === true
Expand Down

0 comments on commit a6ef9a1

Please sign in to comment.