Skip to content

Commit

Permalink
Merge pull request #415 from mrmlnc/update_ts_config
Browse files Browse the repository at this point in the history
Update TS config
  • Loading branch information
mrmlnc committed Aug 3, 2023
2 parents b775344 + 8c2abb7 commit 1a7cf04
Show file tree
Hide file tree
Showing 32 changed files with 384 additions and 268 deletions.
24 changes: 15 additions & 9 deletions src/benchmark/suites/product/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@ type GlobImplementation = 'fast-glob' | 'fdir' | 'node-glob';
type GlobImplFunction = (...args: any[]) => Promise<unknown[]>;

class Glob {
constructor(private readonly _cwd: string, private readonly _pattern: string) {}
readonly #cwd: string;
readonly #pattern: string;

constructor(cwd: string, pattern: string) {
this.#cwd = cwd;
this.#pattern = pattern;
}

public async measureNodeGlob(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importNodeGlob);

await this._measure(() => glob.glob(this._pattern, {
cwd: this._cwd,
await this.#measure(() => glob.glob(this.#pattern, {
cwd: this.#cwd,
nodir: true,
}));
}

public async measureFastGlob(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importCurrentFastGlob);

await this._measure(() => glob(this._pattern, {
cwd: this._cwd,
await this.#measure(() => glob(this.#pattern, {
cwd: this.#cwd,
unique: false,
followSymbolicLinks: false,
concurrency: Number.POSITIVE_INFINITY,
Expand All @@ -38,13 +44,13 @@ class Glob {
.withBasePath()
.withRelativePaths()
// Other solutions do not include hidden files by default
.globWithOptions([this._pattern], { dot: false })
.crawl(this._cwd);
.globWithOptions([this.#pattern], { dot: false })
.crawl(this.#cwd);

await this._measure(() => fdir.withPromise());
await this.#measure(() => fdir.withPromise());
}

private async _measure(function_: GlobImplFunction): Promise<void> {
async #measure(function_: GlobImplFunction): Promise<void> {
const timeStart = utils.timeStart();

const matches = await function_();
Expand Down
22 changes: 14 additions & 8 deletions src/benchmark/suites/product/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@ type GlobImplementation = 'fast-glob' | 'node-glob';
type GlobImplFunction = (...args: any[]) => Promise<unknown[]>;

class Glob {
constructor(private readonly _cwd: string, private readonly _pattern: string) {}
readonly #cwd: string;
readonly #pattern: string;

constructor(cwd: string, pattern: string) {
this.#cwd = cwd;
this.#pattern = pattern;
}

public async measureNodeGlob(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importNodeGlob);

const entries: string[] = [];

const stream = glob.globStream(this._pattern, {
cwd: this._cwd,
const stream = glob.globStream(this.#pattern, {
cwd: this.#cwd,
nodir: true,
});

Expand All @@ -31,16 +37,16 @@ class Glob {
});
});

await this._measure(() => action);
await this.#measure(() => action);
}

public async measureFastGlob(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importCurrentFastGlob);

const entries: string[] = [];

const stream = glob.stream(this._pattern, {
cwd: this._cwd,
const stream = glob.stream(this.#pattern, {
cwd: this.#cwd,
unique: false,
followSymbolicLinks: false,
concurrency: Number.POSITIVE_INFINITY,
Expand All @@ -56,10 +62,10 @@ class Glob {
});
});

await this._measure(() => action);
await this.#measure(() => action);
}

private async _measure(function_: GlobImplFunction): Promise<void> {
async #measure(function_: GlobImplFunction): Promise<void> {
const timeStart = utils.timeStart();

const matches = await function_();
Expand Down
24 changes: 15 additions & 9 deletions src/benchmark/suites/product/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,28 @@ type GlobImplementation = 'fast-glob' | 'fdir' | 'node-glob';
type GlobImplFunction = (...args: any[]) => unknown[];

class Glob {
constructor(private readonly _cwd: string, private readonly _pattern: string) {}
readonly #cwd: string;
readonly #pattern: string;

constructor(cwd: string, pattern: string) {
this.#cwd = cwd;
this.#pattern = pattern;
}

public async measureNodeGlob(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importNodeGlob);

this._measure(() => glob.globSync(this._pattern, {
cwd: this._cwd,
this.#measure(() => glob.globSync(this.#pattern, {
cwd: this.#cwd,
nodir: true,
}));
}

public async measureFastGlob(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importCurrentFastGlob);

this._measure(() => glob.sync(this._pattern, {
cwd: this._cwd,
this.#measure(() => glob.sync(this.#pattern, {
cwd: this.#cwd,
unique: false,
followSymbolicLinks: false,
}));
Expand All @@ -37,13 +43,13 @@ class Glob {
.withBasePath()
.withRelativePaths()
// Other solutions do not include hidden files by default
.globWithOptions([this._pattern], { dot: false })
.crawl(this._cwd);
.globWithOptions([this.#pattern], { dot: false })
.crawl(this.#cwd);

this._measure(() => fdir.sync());
this.#measure(() => fdir.sync());
}

private _measure(function_: GlobImplFunction): void {
#measure(function_: GlobImplFunction): void {
const timeStart = utils.timeStart();

const matches = function_();
Expand Down
19 changes: 11 additions & 8 deletions src/benchmark/suites/regression/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

import * as fastGlobCurrent from '../../..';
import * as utils from '../../utils';

import type * as fastGlobCurrent from '../../..';

type GlobImplementation = 'current' | 'previous';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type GlobImplFunction = (...args: any[]) => Promise<unknown[]>;
type GlobOptions = fastGlobCurrent.Options;

class Glob {
private readonly _options: fastGlobCurrent.Options;
readonly #pattern: string;
readonly #options: GlobOptions;

constructor(private readonly _pattern: string, options: fastGlobCurrent.Options) {
this._options = {
constructor(pattern: string, options: GlobOptions) {
this.#pattern = pattern;
this.#options = {
unique: false,
followSymbolicLinks: false,
concurrency: Number.POSITIVE_INFINITY,
Expand All @@ -26,16 +29,16 @@ class Glob {
const glob = await utils.importAndMeasure(utils.importPreviousFastGlob);

// @ts-expect-error remove this line after the next major release.
await this._measure(() => glob(this._pattern, this._options));
await this.#measure(() => glob(this.#pattern, this.#options));
}

public async measureCurrentVersion(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importCurrentFastGlob);

await this._measure(() => glob(this._pattern, this._options));
await this.#measure(() => glob(this.#pattern, this.#options));
}

private async _measure(function_: GlobImplFunction): Promise<void> {
async #measure(function_: GlobImplFunction): Promise<void> {
const timeStart = utils.timeStart();

const matches = await function_();
Expand All @@ -57,7 +60,7 @@ class Glob {
const cwd = path.join(process.cwd(), args[0]);
const pattern = args[1];
const impl = args[2] as GlobImplementation;
const options = JSON.parse(process.env.BENCHMARK_OPTIONS ?? '{}') as GlobOptions;
const options = JSON.parse(process.env['BENCHMARK_OPTIONS'] ?? '{}') as GlobOptions;

const glob = new Glob(pattern, {
cwd,
Expand Down
19 changes: 11 additions & 8 deletions src/benchmark/suites/regression/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

import * as fastGlobCurrent from '../../..';
import * as utils from '../../utils';

import type * as fastGlobCurrent from '../../..';

type GlobImplementation = 'current' | 'previous';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type GlobImplFunction = (...args: any[]) => ReturnType<typeof fastGlobCurrent.stream>;
type GlobOptions = fastGlobCurrent.Options;

class Glob {
private readonly _options: fastGlobCurrent.Options;
readonly #pattern: string;
readonly #options: GlobOptions;

constructor(private readonly _pattern: string, options: fastGlobCurrent.Options) {
this._options = {
constructor(pattern: string, options: GlobOptions) {
this.#pattern = pattern;
this.#options = {
unique: false,
followSymbolicLinks: false,
concurrency: Number.POSITIVE_INFINITY,
Expand All @@ -26,16 +29,16 @@ class Glob {
const glob = await utils.importAndMeasure(utils.importPreviousFastGlob);

// @ts-expect-error remove this line after the next major release.
await this._measure(() => glob.stream(this._pattern, this._options));
await this.#measure(() => glob.stream(this.#pattern, this.#options));
}

public async measureCurrentVersion(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importCurrentFastGlob);

await this._measure(() => glob.stream(this._pattern, this._options));
await this.#measure(() => glob.stream(this.#pattern, this.#options));
}

private async _measure(function_: GlobImplFunction): Promise<void> {
async #measure(function_: GlobImplFunction): Promise<void> {
const entries: string[] = [];

const timeStart = utils.timeStart();
Expand Down Expand Up @@ -69,7 +72,7 @@ class Glob {
const cwd = path.join(process.cwd(), args[0]);
const pattern = args[1];
const impl = args[2] as GlobImplementation;
const options = JSON.parse(process.env.BENCHMARK_OPTIONS ?? '{}') as GlobOptions;
const options = JSON.parse(process.env['BENCHMARK_OPTIONS'] ?? '{}') as GlobOptions;

const glob = new Glob(pattern, {
cwd,
Expand Down
19 changes: 11 additions & 8 deletions src/benchmark/suites/regression/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

import * as fastGlobCurrent from '../../..';
import * as utils from '../../utils';

import type * as fastGlobCurrent from '../../..';

type GlobImplementation = 'current' | 'previous';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type GlobImplFunction = (...args: any[]) => unknown[];
type GlobOptions = fastGlobCurrent.Options;

class Glob {
private readonly _options: fastGlobCurrent.Options;
readonly #pattern: string;
readonly #options: GlobOptions;

constructor(private readonly _pattern: string, options: fastGlobCurrent.Options) {
this._options = {
constructor(pattern: string, options: GlobOptions) {
this.#pattern = pattern;
this.#options = {
unique: false,
followSymbolicLinks: false,
...options,
Expand All @@ -25,16 +28,16 @@ class Glob {
const glob = await utils.importAndMeasure(utils.importPreviousFastGlob);

// @ts-expect-error remove this line after the next major release.
this._measure(() => glob.sync(this._pattern, this._options));
this.#measure(() => glob.sync(this.#pattern, this.#options));
}

public async measureCurrentVersion(): Promise<void> {
const glob = await utils.importAndMeasure(utils.importCurrentFastGlob);

this._measure(() => glob.sync(this._pattern, this._options));
this.#measure(() => glob.sync(this.#pattern, this.#options));
}

private _measure(function_: GlobImplFunction): void {
#measure(function_: GlobImplFunction): void {
const timeStart = utils.timeStart();

const matches = function_();
Expand All @@ -56,7 +59,7 @@ class Glob {
const cwd = path.join(process.cwd(), args[0]);
const pattern = args[1];
const impl = args[2] as GlobImplementation;
const options = JSON.parse(process.env.BENCHMARK_OPTIONS ?? '{}') as GlobOptions;
const options = JSON.parse(process.env['BENCHMARK_OPTIONS'] ?? '{}') as GlobOptions;

const glob = new Glob(pattern, {
cwd,
Expand Down
5 changes: 3 additions & 2 deletions src/providers/async.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ import * as assert from 'node:assert';

import * as sinon from 'sinon';

import Settings, { Options } from '../settings';
import Settings from '../settings';
import * as tests from '../tests';
import ReaderAsync from '../readers/async';
import ProviderAsync from './async';

import type { Options } from '../settings';
import type { Entry, EntryItem, ErrnoException } from '../types';
import type ReaderStream from '../readers/stream';
import type { Task } from '../managers/tasks';

class TestProvider extends ProviderAsync {
protected _reader: ReaderAsync = sinon.createStubInstance(ReaderAsync) as unknown as ReaderAsync;
protected override _reader: ReaderAsync = sinon.createStubInstance(ReaderAsync) as unknown as ReaderAsync;

constructor(options?: Options) {
super(new Settings(options));
Expand Down
9 changes: 8 additions & 1 deletion src/providers/async.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import ReaderAsync from '../readers/async';
import Provider from './provider';

import type Settings from '../settings';
import type { Task } from '../managers/tasks';
import type { Entry, EntryItem, ReaderOptions } from '../types';

export default class ProviderAsync extends Provider<Promise<EntryItem[]>> {
protected _reader: ReaderAsync = new ReaderAsync(this._settings);
protected _reader: ReaderAsync;

constructor(settings: Settings) {
super(settings);

this._reader = new ReaderAsync(settings);
}

public async read(task: Task): Promise<EntryItem[]> {
const root = this._getRootDirectory(task);
Expand Down
Loading

0 comments on commit 1a7cf04

Please sign in to comment.