generated from stacksjs/ts-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
8 changed files
with
50 additions
and
140 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"name": "bun-plugin-dts-auto", | ||
"name": "bun-plugin-dtsx", | ||
"type": "module", | ||
"version": "0.20.6", | ||
"description": "A Bun Bundler plugin that auto generates your d.ts types.", | ||
"description": "A Bun Bundler plugin that auto generates your d.ts types extremely fast.", | ||
"author": "Chris Breuer <[email protected]>", | ||
"license": "MIT", | ||
"homepage": "https://github.com/stacksjs/bun-plugin-dts-auto#readme", | ||
|
@@ -15,12 +15,13 @@ | |
}, | ||
"keywords": [ | ||
"dts", | ||
"oxc", | ||
"dtsx", | ||
"emit", | ||
"generation", | ||
"typescript", | ||
"types", | ||
"auto", | ||
"stacks", | ||
"bun", | ||
"plugin", | ||
"package" | ||
|
@@ -36,11 +37,11 @@ | |
}, | ||
"module": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"files": ["dist", "README.md", "LICENSE.md"], | ||
"files": ["LICENSE.md", "README.md", "dist"], | ||
"scripts": { | ||
"build": "bun build.ts", | ||
"lint": "biome check .", | ||
"lint:fix": "biome check --fix .", | ||
"lint": "bunx eslint .", | ||
"lint:fix": "bunx eslint . --fix", | ||
"fresh": "bunx rimraf node_modules/ bun.lock && bun i", | ||
"commit": "git cz", | ||
"changelog": "bunx changelogen --output CHANGELOG.md", | ||
|
@@ -50,12 +51,11 @@ | |
"typecheck": "bun tsc --noEmit" | ||
}, | ||
"dependencies": { | ||
"oxc-transform": "^0.30.5" | ||
"@stacksjs/dtsx": "^0.2.2" | ||
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.9.3", | ||
"@commitlint/cli": "^19.5.0", | ||
"@stacksjs/biome-config": "^0.1.5", | ||
"@stacksjs/eslint-config": "^3.8.1-beta.2", | ||
"@types/bun": "^1.1.10", | ||
"bumpp": "^9.6.1", | ||
"changelogen": "^0.5.7", | ||
|
@@ -65,22 +65,12 @@ | |
"simple-git-hooks": "^2.11.1", | ||
"typescript": "^5.6.2" | ||
}, | ||
"optionalDependencies": { | ||
"@oxc-transform/binding-win32-x64-msvc": "0.30.5", | ||
"@oxc-transform/binding-win32-arm64-msvc": "0.30.5", | ||
"@oxc-transform/binding-linux-x64-gnu": "0.30.5", | ||
"@oxc-transform/binding-linux-arm64-gnu": "0.30.5", | ||
"@oxc-transform/binding-linux-x64-musl": "0.30.5", | ||
"@oxc-transform/binding-linux-arm64-musl": "0.30.5", | ||
"@oxc-transform/binding-darwin-x64": "0.30.5", | ||
"@oxc-transform/binding-darwin-arm64": "0.30.5" | ||
}, | ||
"simple-git-hooks": { | ||
"pre-commit": "bun lint-staged", | ||
"commit-msg": "bunx --no -- commitlint --edit $1" | ||
}, | ||
"lint-staged": { | ||
"*.{js,jsx,ts,tsx,vue}": "biome check --fix ." | ||
"*.{js,jsx,ts,tsx}": "bunx eslint . --fix" | ||
}, | ||
"config": { | ||
"commitizen": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,35 @@ | ||
import fs from 'node:fs' | ||
import path from 'node:path' | ||
import type { DtsGenerationOption } from '@stacksjs/dtsx' | ||
import type { BunPlugin } from 'bun' | ||
import { isolatedDeclaration } from 'oxc-transform' | ||
import type { DtsOptions } from './types' | ||
import process from 'node:process' | ||
import { generate } from '@stacksjs/dtsx' | ||
|
||
export async function generate(options?: DtsOptions): Promise<void> { | ||
const cwd = options?.cwd ?? process.cwd() | ||
const root = options?.root ?? 'src' | ||
const outdir = options?.outdir ?? './dist/' | ||
const files = options?.files | ||
|
||
const rootDir = path.join(cwd, root) | ||
|
||
if (files) { | ||
const f = Array.isArray(files) ? files : [files] | ||
for (const file of f) { | ||
await processFile(path.join(cwd, file), rootDir, cwd, outdir) | ||
} | ||
} else { | ||
const glob = new Bun.Glob('**/*.ts') | ||
for await (const file of glob.scan({ cwd: rootDir, absolute: true })) { | ||
await processFile(file, rootDir, cwd, outdir) | ||
} | ||
} | ||
} | ||
|
||
async function processFile(file: string, rootDir: string, cwd: string, outdir: string) { | ||
if (fs.existsSync(file)) { | ||
const ts = fs.readFileSync(file, 'utf-8') | ||
const dts = isolatedDeclaration(file, ts, { sourcemap: false }) | ||
const code = dts.code | ||
const relativePath = path.relative(rootDir, file) | ||
const outputPath = path.join(cwd, outdir, relativePath.replace(/\.ts$/, '.d.ts')) | ||
write(outputPath, code) | ||
} else { | ||
console.warn(`File not found: ${file}`) | ||
} | ||
} | ||
|
||
function write(file: string, content: string) { | ||
const dir = path.dirname(file) | ||
fs.mkdirSync(dir, { recursive: true }) | ||
fs.writeFileSync(file, content) | ||
} | ||
|
||
export function dts(options?: DtsOptions): BunPlugin { | ||
export function dts(options?: DtsGenerationOption): BunPlugin { | ||
return { | ||
name: 'bun-plugin-dts-auto', | ||
name: 'bun-plugin-dtsx', | ||
|
||
async setup(build) { | ||
const root = options?.root ?? build.config.root ?? './src/' | ||
const outdir = options?.outdir ?? './dist/' | ||
const cwd = options?.cwd ?? process.cwd() | ||
const files = options?.files | ||
const root = options?.root ?? build.config.root | ||
const entrypoints = options?.entrypoints ?? build.config.entrypoints | ||
const outdir = options?.outdir ?? build.config.outdir | ||
const keepComments = options?.keepComments ?? true | ||
const clean = options?.clean ?? false | ||
const tsconfigPath = options?.tsconfigPath ?? './tsconfig.json' | ||
|
||
await generate({ | ||
...options, | ||
cwd, | ||
root, | ||
entrypoints, | ||
outdir, | ||
cwd, | ||
files, | ||
keepComments, | ||
clean, | ||
tsconfigPath, | ||
}) | ||
}, | ||
} | ||
} | ||
|
||
export * from './types' | ||
export type { DtsGenerationOption } | ||
|
||
export default dts |
This file was deleted.
Oops, something went wrong.