Skip to content

Commit

Permalink
feat: add glob pattern support for entrypoints
Browse files Browse the repository at this point in the history
This commit introduces the ability to use glob patterns for specifying
entrypoints in the `isolatedDecl` function. The `is-glob` package is
added as a dependency to facilitate this. The path resolution for
writing output files is also updated from `path.join` to `path.resolve`
for better path handling.
  • Loading branch information
ryoppippi committed Aug 6, 2024
1 parent 2b04fa5 commit 2fda154
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Binary file modified bun.lockb
Binary file not shown.
23 changes: 19 additions & 4 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import path from 'node:path';
import { oxcTransform } from 'unplugin-isolated-decl/api';
import type { BunPlugin } from 'bun';
import { type BunPlugin, Glob } from 'bun';

// @ts-expect-error no type
import _isGlob from 'is-glob';

// eslint-disable-next-line ts/no-unsafe-assignment
const isGlob: (str: string) => boolean = _isGlob;

export type TransformResult = {
sourceText: string;
Expand Down Expand Up @@ -30,8 +36,17 @@ function isolatedDecl(options: Options = {}): BunPlugin {
const resolvedOptions = { forceGenerate: false, ...options } satisfies Options;

for (const entry of entrypoints) {
const source = await Bun.file(entry).text();
entriies.push({ id: entry, source });
if (isGlob(entry)) {
const globs = new Glob(entry);
for await (const entry of globs.scan()) {
const source = await Bun.file(entry).text();
entriies.push({ id: entry, source });
}
}
else {
const source = await Bun.file(entry).text();
entriies.push({ id: entry, source });
}
}

await Promise.all(
Expand All @@ -51,7 +66,7 @@ function isolatedDecl(options: Options = {}): BunPlugin {
const dtsID = id
.replace(/^.*\//, '')
.replace(/\.[jtm]s$/, '.d.ts');
return Bun.write(path.join(outdir, dtsID), sourceText);
return Bun.write(path.resolve(outdir, dtsID), sourceText);
}),
);
},
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"@ryoppippi/eslint-config": "npm:@jsr/ryoppippi__eslint-config",
"@types/bun": "latest",
"eslint": "^9.8.0",
"eslint-plugin-format": "^0.1.2"
"eslint-plugin-format": "^0.1.2",
"is-glob": "^4.0.3"
}
}

0 comments on commit 2fda154

Please sign in to comment.