Skip to content

Commit d29982c

Browse files
authored
chore: replace arg and glob with Bun native APIs in build script
1 parent 16215d5 commit d29982c

3 files changed

Lines changed: 40 additions & 160 deletions

File tree

‎build/build.ts‎

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,17 @@
55
Copyright (c) 2022 Taishi Naritomi
66
*/
77

8-
/// <reference types="bun-types/bun" />
8+
/// <reference types="bun-types" />
99

10-
import arg from 'arg'
11-
import { $ } from 'bun'
10+
import { $, Glob } from 'bun'
1211
import { build, context } from 'esbuild'
1312
import type { Plugin, PluginBuild, BuildOptions } from 'esbuild'
14-
import * as glob from 'glob'
1513
import fs from 'fs'
1614
import path from 'path'
1715
import { removePrivateFields } from './remove-private-fields'
1816
import { validateExports } from './validate-exports'
1917

20-
const args = arg({
21-
'--watch': Boolean,
22-
})
23-
24-
const isWatch = args['--watch'] || false
18+
const isWatch = process.argv.includes('--watch')
2519

2620
const readJsonExports = (path: string) => JSON.parse(fs.readFileSync(path, 'utf-8')).exports
2721

@@ -31,9 +25,18 @@ const [packageJsonExports, jsrJsonExports] = ['./package.json', './jsr.json'].ma
3125
validateExports(packageJsonExports, jsrJsonExports, 'jsr.json')
3226
validateExports(jsrJsonExports, packageJsonExports, 'package.json')
3327

34-
const entryPoints = glob.sync('./src/**/*.ts', {
35-
ignore: ['./src/**/*.test.ts', './src/mod.ts', './src/middleware.ts', './src/deno/**/*.ts'],
36-
})
28+
const ignorePatterns = [
29+
'src/**/*.test.ts',
30+
'src/mod.ts',
31+
'src/middleware.ts',
32+
'src/deno/**/*.ts',
33+
].map((pattern) => new Glob(pattern))
34+
const entryPoints: string[] = []
35+
for await (const file of new Glob('src/**/*.ts').scan('.')) {
36+
if (!ignorePatterns.some((ignore) => ignore.match(file))) {
37+
entryPoints.push(file)
38+
}
39+
}
3740

3841
/*
3942
This plugin is inspired by the following.
@@ -101,10 +104,13 @@ await Promise.all([
101104
runBuild(esmConfig),
102105
runBuild(cjsConfig),
103106
$`tsc ${
104-
isWatch ? '-w' : ''
107+
isWatch ? ['-w'] : []
105108
} --emitDeclarationOnly --declaration --project tsconfig.build.json`.nothrow(),
106109
])
107110

108111
// Remove #private fields
109-
const dtsEntries = glob.globSync('./dist/types/**/*.d.ts')
112+
const dtsEntries: string[] = []
113+
for await (const file of new Glob('dist/types/**/*.d.ts').scan('.')) {
114+
dtsEntries.push(file)
115+
}
110116
await removePrivateFields(dtsEntries)

0 commit comments

Comments
 (0)