Skip to content

Commit

Permalink
Remove index.mjs and fix type declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesrosiers committed Jan 13, 2025
1 parent d1f6a41 commit 637b712
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 85 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# build target
/index.mjs

# test
/.tap

Expand Down
109 changes: 54 additions & 55 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,65 @@ interface PatternParams {
mark?: string
}

export interface Ignore {
/**
* Adds one or several rules to the current manager.
* @param {string[]} patterns
* @returns IgnoreBase
*/
add(
patterns: string | Ignore | readonly (string | Ignore)[] | PatternParams
): this

/**
* Filters the given array of pathnames, and returns the filtered array.
* NOTICE that each path here should be a relative path to the root of your repository.
* @param paths the array of paths to be filtered.
* @returns The filtered array of paths
*/
filter(pathnames: readonly Pathname[]): Pathname[]
/**
* Creates new ignore manager.
*/
declare function ignore(options?: ignore.Options): ignore.Ignore
declare namespace ignore {
interface Ignore {
/**
* Adds one or several rules to the current manager.
* @param {string[]} patterns
* @returns IgnoreBase
*/
add(
patterns: string | Ignore | readonly (string | Ignore)[] | PatternParams
): this

/**
* Creates a filter function which could filter
* an array of paths with Array.prototype.filter.
*/
createFilter(): (pathname: Pathname) => boolean
/**
* Filters the given array of pathnames, and returns the filtered array.
* NOTICE that each path here should be a relative path to the root of your repository.
* @param paths the array of paths to be filtered.
* @returns The filtered array of paths
*/
filter(pathnames: readonly Pathname[]): Pathname[]

/**
* Returns Boolean whether pathname should be ignored.
* @param {string} pathname a path to check
* @returns boolean
*/
ignores(pathname: Pathname): boolean
/**
* Creates a filter function which could filter
* an array of paths with Array.prototype.filter.
*/
createFilter(): (pathname: Pathname) => boolean

/**
* Returns whether pathname should be ignored or unignored
* @param {string} pathname a path to check
* @returns TestResult
*/
test(pathname: Pathname): TestResult
/**
* Returns Boolean whether pathname should be ignored.
* @param {string} pathname a path to check
* @returns boolean
*/
ignores(pathname: Pathname): boolean

/**
* Debugs ignore rules and returns the checking result, which is
* equivalent to `git check-ignore -v`.
* @returns TestResult
*/
checkIgnore(pathname: Pathname): TestResult
}
/**
* Returns whether pathname should be ignored or unignored
* @param {string} pathname a path to check
* @returns TestResult
*/
test(pathname: Pathname): TestResult

export interface Options {
ignorecase?: boolean
// For compatibility
ignoreCase?: boolean
allowRelativePaths?: boolean
}
/**
* Debugs ignore rules and returns the checking result, which is
* equivalent to `git check-ignore -v`.
* @returns TestResult
*/
checkIgnore(pathname: Pathname): TestResult
}

/**
* Creates new ignore manager.
*/
declare function ignore(options?: Options): Ignore
declare function isPathValid (pathname: string): boolean
interface Options {
ignorecase?: boolean
// For compatibility
ignoreCase?: boolean
allowRelativePaths?: boolean
}

export default ignore
export {
isPathValid
function isPathValid(pathname: string): boolean
}

export = ignore
6 changes: 1 addition & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,6 @@ const factory = options => new Ignore(options)
const isPathValid = path =>
checkPath(path && checkPath.convert(path), path, RETURN_FALSE)

factory.isPathValid = isPathValid


// Windows
// --------------------------------------------------------------
Expand Down Expand Up @@ -771,7 +769,5 @@ if (

// COMMONJS_EXPORTS ////////////////////////////////////////////////////////////

// Fixes typescript
factory.default = factory

module.exports = factory
module.exports.isPathValid = isPathValid
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
"version": "7.0.0",
"description": "Ignore is a manager and filter for .gitignore rules, the one used by eslint, gitbook and many others.",
"main": "index.js",
"module": "index.mjs",
"types": "index.d.ts",
"files": [
"legacy.js",
"index.js",
"index.mjs",
"index.d.ts",
"LICENSE-MIT"
],
"scripts": {
"prepublishOnly": "npm run build",
"build": "babel -o legacy.js index.js && node ./scripts/build.js",
"build": "babel -o legacy.js index.js",
"test:lint": "eslint .",
"test:ts": "ts-node ./test/ts/simple.ts",
"test:ts:16": "ts-node --compilerOptions '{\"moduleResolution\": \"Node16\", \"module\": \"Node16\"}' ./test/ts/simple.ts",
Expand Down
18 changes: 0 additions & 18 deletions scripts/build.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/ts/simple.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import ignore, {isPathValid} from '../../index.mjs' // eslint-disable-line import/extensions
import ignore, {isPathValid} from '../../index.js' // eslint-disable-line import/extensions

const equal = (actual, expect, message) => {
if (actual !== expect) {
Expand Down
1 change: 1 addition & 0 deletions test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"compilerOptions": {
"esModuleInterop": true
}
}

0 comments on commit 637b712

Please sign in to comment.