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'
1211import { build , context } from 'esbuild'
1312import type { Plugin , PluginBuild , BuildOptions } from 'esbuild'
14- import * as glob from 'glob'
1513import fs from 'fs'
1614import path from 'path'
1715import { removePrivateFields } from './remove-private-fields'
1816import { 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
2620const readJsonExports = ( path : string ) => JSON . parse ( fs . readFileSync ( path , 'utf-8' ) ) . exports
2721
@@ -31,9 +25,18 @@ const [packageJsonExports, jsrJsonExports] = ['./package.json', './jsr.json'].ma
3125validateExports ( packageJsonExports , jsrJsonExports , 'jsr.json' )
3226validateExports ( 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+ }
110116await removePrivateFields ( dtsEntries )
0 commit comments