Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert code to ESM #471

Closed
wants to merge 4 commits into from
Closed
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
32 changes: 18 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,18 @@
"engines": {
"node": ">=18.18.0"
},
"type": "module",
"main": "build/index.js",
"typings": "build/index.d.ts",
"files": [
"build",
"!build/{benchmark,tests}",
"!build/**/*.map",
"!build/**/*.spec.*"
"build/index.cjs",
"build/index.d.cts"
],
"exports": {
".": {
"default": "./build/index.cjs"
}
},
"keywords": [
"glob",
"patterns",
Expand All @@ -27,6 +31,8 @@
],
"devDependencies": {
"@nodelib/fs.macchiato": "^3.0.0",
"@nodelib/fs.stat": "^4.0.0",
"@nodelib/fs.walk": "^3.0.1",
"@types/glob-parent": "^5.1.3",
"@types/merge2": "^1.4.4",
"@types/micromatch": "^4.0.9",
Expand All @@ -35,27 +41,24 @@
"@types/picomatch": "^3.0.1",
"@types/sinon": "^17.0.3",
"bencho": "^0.1.1",
"dts-bundle-generator": "^9.5.1",
"esbuild": "^0.24.0",
"eslint": "9.14.0",
"eslint-config-mrmlnc": "^5.0.0",
"execa": "^7.2.0",
"fast-glob": "^3.3.2",
"glob": "^11.0.0",
"glob-parent": "^6.0.2",
"hereby": "^1.10.0",
"merge2": "^1.4.1",
"micromatch": "^4.0.8",
"mocha": "^10.8.2",
"rimraf": "^6.0.1",
"sinon": "^19.0.2",
"snap-shot-it": "^7.9.10",
"tinyglobby": "^0.2.10",
"typescript": "^5.7.2"
},
"dependencies": {
"@nodelib/fs.stat": "^4.0.0",
"@nodelib/fs.walk": "^3.0.0",
"glob-parent": "^6.0.2",
"merge2": "^1.4.1",
"micromatch": "^4.0.8"
},
"scripts": {
"clean": "rimraf out build",
"lint": "eslint \"src/**/*.ts\" --cache",
Expand All @@ -68,10 +71,11 @@
"_build:compile": "npm run clean && npm run compile",
"build": "npm run _build:compile && npm run lint && npm test",
"watch": "npm run _build:compile -- -- --sourceMap --watch",
"_bundle:dts": "tsc --emitDeclarationOnly --outDir ./build",
"_bundle:ts": "esbuild --bundle ./src/index.ts --outfile=./build/index.js --platform=node --target=node18.18 --format=cjs",
"_bundle:dts": "dts-bundle-generator ./src/index.ts --out-file=./build/index.d.cts --export-referenced-types=false --external-inlines=@nodelib/fs.walk @nodelib/fs.scandir @nodelib/fs.stat",
"_bundle:ts": "npm run _bundle:ts:cjs",
"_bundle:ts:cjs": "esbuild --bundle ./out/index.js --outfile=./build/index.cjs --platform=node --target=node18.18 --format=cjs",
"_bundle:build": "npm run _bundle:dts && npm run _bundle:ts",
"_bundle:test:replace": "cp ./build/index.js ./out",
"_bundle:test:replace": "cp ./build/index.cjs ./out",
"_bundle:test": "npm run _bundle:test:replace",
"bundle": "npm run _build:compile && npm run _bundle:build && npm run _bundle:test",
"bench:async": "npm run bench:product:async && npm run bench:regression:async",
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/suites/overhead/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as util from 'node:util';

import * as bencho from 'bencho';

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

type MeasurableImplementation = 'fast-glob' | 'fs-walk';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/suites/overhead/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

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

import type { Entry } from '@nodelib/fs.walk';

Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/suites/overhead/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

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

type MeasurableImplementation = 'fast-glob' | 'fs-walk';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/suites/product/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

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

type GlobImplementation = 'fast-glob' | 'node-glob' | 'tinyglobby';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/suites/product/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

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

type GlobImplementation = 'fast-glob' | 'node-glob';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
2 changes: 1 addition & 1 deletion src/benchmark/suites/product/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

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

type GlobImplementation = 'fast-glob' | 'node-glob' | 'tinyglobby';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/regression/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

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

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

type GlobImplementation = 'current' | 'previous';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/regression/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

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

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

type GlobImplementation = 'current' | 'previous';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/suites/regression/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import * as path from 'node:path';

import * as bencho from 'bencho';

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

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

type GlobImplementation = 'current' | 'previous';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
4 changes: 2 additions & 2 deletions src/benchmark/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { performance } from 'node:perf_hooks';

import * as bencho from 'bencho';

import type * as currentVersion from '..';
import type * as currentVersion from '../index.js';
import type * as previousVersion from 'fast-glob';
import type * as glob from 'glob';
import type * as tg from 'tinyglobby';
Expand All @@ -20,7 +20,7 @@ export function getMemory(): number {
}

export function importCurrentFastGlob(): Promise<typeof currentVersion> {
return import('..');
return import('../index.js');
}

export function importPreviousFastGlob(): Promise<typeof previousVersion> {
Expand Down
12 changes: 6 additions & 6 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import * as assert from 'node:assert';

import { describe, it } from 'mocha';

import * as tests from './tests';
import * as fg from '.';
import * as tests from './tests/index.js';
import * as fg from './index.js';

import type { EntryItem, ErrnoException } from './types';
import type { EntryItem, ErrnoException } from './types/index.js';

// Only for validating the input data.
const invalidInputData = null as unknown as string;
Expand Down Expand Up @@ -59,7 +59,7 @@ describe('Package', () => {

describe('.sync', () => {
it('should be an alias for the .globSync method', () => {
// eslint-disable-next-line import/no-deprecated, @typescript-eslint/no-deprecated
// eslint-disable-next-line @typescript-eslint/no-deprecated
assert.strictEqual(fg.sync, fg.globSync);
});
});
Expand Down Expand Up @@ -112,7 +112,7 @@ describe('Package', () => {

describe('.async', () => {
it('should be an alias for the .glob method', () => {
// eslint-disable-next-line import/no-deprecated, @typescript-eslint/no-deprecated
// eslint-disable-next-line @typescript-eslint/no-deprecated
assert.strictEqual(fg.async, fg.glob);
});
});
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('Package', () => {

describe('.stream', () => {
it('should be an alias for the .globStream method', () => {
// eslint-disable-next-line import/no-deprecated, @typescript-eslint/no-deprecated
// eslint-disable-next-line @typescript-eslint/no-deprecated
assert.strictEqual(fg.stream, fg.globStream);
});
});
Expand Down
16 changes: 8 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as taskManager from './managers/tasks';
import Settings from './settings';
import * as utils from './utils';
import { ProviderAsync, ProviderStream, ProviderSync } from './providers';
import { ReaderAsync, ReaderStream, ReaderSync } from './readers';

import type { Options as OptionsInternal } from './settings';
import type { Entry as EntryInternal, EntryItem, FileSystemAdapter as FileSystemAdapterInternal, Pattern as PatternInternal } from './types';
import * as taskManager from './managers/tasks.js';
import Settings from './settings.js';
import * as utils from './utils/index.js';
import { ProviderAsync, ProviderStream, ProviderSync } from './providers/index.js';
import { ReaderAsync, ReaderStream, ReaderSync } from './readers/index.js';

import type { Options as OptionsInternal } from './settings.js';
import type { Entry as EntryInternal, EntryItem, FileSystemAdapter as FileSystemAdapterInternal, Pattern as PatternInternal } from './types/index.js';

type InputPattern = PatternInternal | readonly PatternInternal[];

Expand Down
8 changes: 4 additions & 4 deletions src/managers/tasks.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import * as assert from 'node:assert';

import { describe, it } from 'mocha';

import Settings from '../settings';
import * as tests from '../tests';
import * as manager from './tasks';
import Settings from '../settings.js';
import * as tests from '../tests/index.js';
import * as manager from './tasks.js';

import type { PatternsGroup } from '../types';
import type { PatternsGroup } from '../types/index.js';

describe('Managers → Task', () => {
describe('.generate', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/managers/tasks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as utils from '../utils';
import * as utils from '../utils/index.js';

import type Settings from '../settings';
import type { Pattern, PatternsGroup } from '../types';
import type Settings from '../settings.js';
import type { Pattern, PatternsGroup } from '../types/index.js';

export interface Task {
base: string;
Expand Down
18 changes: 9 additions & 9 deletions src/providers/async.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import * as assert from 'node:assert';
import * as sinon from 'sinon';
import { describe, it } from 'mocha';

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

import type { IReaderAsync } from '../readers';
import type { Options } from '../settings';
import type { Entry, EntryItem, ErrnoException } from '../types';
import type { Task } from '../managers/tasks';
import Settings from '../settings.js';
import * as tests from '../tests/index.js';
import { ReaderAsync } from '../readers/index.js';
import { ProviderAsync } from './async.js';

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

type StubbedReaderAsync = sinon.SinonStubbedInstance<IReaderAsync>;

Expand Down
10 changes: 5 additions & 5 deletions src/providers/async.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Provider } from './provider';
import { Provider } from './provider.js';

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

export class ProviderAsync extends Provider<Promise<EntryItem[]>> {
readonly #reader: IReaderAsync;
Expand Down
10 changes: 5 additions & 5 deletions src/providers/filters/deep.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as assert from 'node:assert';

import { describe, it } from 'mocha';

import Settings from '../../settings';
import * as tests from '../../tests';
import DeepFilter from './deep';
import Settings from '../../settings.js';
import * as tests from '../../tests/index.js';
import DeepFilter from './deep.js';

import type { EntryFilterFunction, Pattern, Entry } from '../../types';
import type { Options } from '../../settings';
import type { EntryFilterFunction, Pattern, Entry } from '../../types/index.js';
import type { Options } from '../../settings.js';

interface FilterOptions {
base?: string;
Expand Down
8 changes: 4 additions & 4 deletions src/providers/filters/deep.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as utils from '../../utils';
import PartialMatcher from '../matchers/partial';
import * as utils from '../../utils/index.js';
import PartialMatcher from '../matchers/partial.js';

import type { MicromatchOptions, Entry, EntryFilterFunction, Pattern, PatternRe } from '../../types';
import type Settings from '../../settings';
import type { MicromatchOptions, Entry, EntryFilterFunction, Pattern, PatternRe } from '../../types/index.js';
import type Settings from '../../settings.js';

export default class DeepFilter {
readonly #settings: Settings;
Expand Down
10 changes: 5 additions & 5 deletions src/providers/filters/entry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import * as path from 'node:path';

import { describe, it } from 'mocha';

import Settings from '../../settings';
import * as tests from '../../tests';
import EntryFilter from './entry';
import Settings from '../../settings.js';
import * as tests from '../../tests/index.js';
import EntryFilter from './entry.js';

import type { EntryFilterFunction, Pattern, Entry } from '../../types';
import type { Options } from '../../settings';
import type { EntryFilterFunction, Pattern, Entry } from '../../types/index.js';
import type { Options } from '../../settings.js';

interface FilterOptions {
positive: Pattern[];
Expand Down
6 changes: 3 additions & 3 deletions src/providers/filters/entry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as utils from '../../utils';
import * as utils from '../../utils/index.js';

import type Settings from '../../settings';
import type { MicromatchOptions, Entry, EntryFilterFunction, Pattern, PatternRe } from '../../types';
import type Settings from '../../settings.js';
import type { MicromatchOptions, Entry, EntryFilterFunction, Pattern, PatternRe } from '../../types/index.js';

interface PatternsRegexSet {
positive: {
Expand Down
10 changes: 5 additions & 5 deletions src/providers/filters/error.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import * as assert from 'node:assert';

import { describe, it } from 'mocha';

import Settings from '../../settings';
import * as tests from '../../tests';
import ErrorFilter from './error';
import Settings from '../../settings.js';
import * as tests from '../../tests/index.js';
import ErrorFilter from './error.js';

import type { ErrorFilterFunction } from '../../types';
import type { Options } from '../../settings';
import type { ErrorFilterFunction } from '../../types/index.js';
import type { Options } from '../../settings.js';

function getErrorFilterInstance(options?: Options): ErrorFilter {
const settings = new Settings(options);
Expand Down
Loading
Loading