Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
},
"./builder": {
"import": "./dist/builder.mjs",
"require": "./dist/builder.cjs"
},
"./package.json": "./package.json"
}
}
1 change: 1 addition & 0 deletions src/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { Builder } from "./builder/index";
14 changes: 4 additions & 10 deletions src/builder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ import {
import { APIBuilder } from "./api-builder";
import type picomatch from "picomatch";

let pm: typeof picomatch | null = null;
/* c8 ignore next 6 */
try {
require.resolve("picomatch");
pm = require("picomatch");
} catch {
// do nothing
}

export class Builder<
TReturnType extends Output = PathsOutput,
TGlobFunction = typeof picomatch,
Expand Down Expand Up @@ -166,7 +157,8 @@ export class Builder<
patterns: string[],
...options: GlobParams<TGlobFunction> | []
) {
const globFn = (this.globFunction || pm) as GlobFunction | null;
const globFn = (this.globFunction ||
Builder.defaultGlobFunction) as GlobFunction | null;
/* c8 ignore next 5 */
if (!globFn) {
throw new Error("Please specify a glob function to use glob matching.");
Expand All @@ -180,4 +172,6 @@ export class Builder<
this.options.filters.push((path) => isMatch(path));
return this;
}

static defaultGlobFunction: typeof picomatch | null = null;
}
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
import { Builder } from "./builder";
import type picomatch from "picomatch";
import { Builder } from "./builder/index";

export { Builder as fdir };
export type Fdir = typeof Builder;

export * from "./types";

let pm: typeof picomatch | null = null;
/* c8 ignore next 6 */
try {
require.resolve("picomatch");
pm = require("picomatch");
} catch {
// do nothing
}

Builder.defaultGlobFunction = pm || null;
4 changes: 2 additions & 2 deletions tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { defineConfig } from 'tsdown/config'

export default defineConfig({
entry: 'src/index.ts',
entry: ['src/index.ts', 'src/builder.ts'],
format: ['cjs', 'esm'],
target: 'node12',
removeNodeProtocol: true,
dts: true,
exports: true,
fixedExtension: true
})
})