feat(globby): update definitions for globby 8.0

This commit is contained in:
Emilio Martinez
2018-06-13 23:47:15 -07:00
parent ac8c4cb9c0
commit 582c37431d
3 changed files with 131 additions and 16 deletions

View File

@@ -1,24 +1,71 @@
import { IOptions } from 'glob';
import globby = require("globby");
import globby = require('globby');
(async () => {
let result: string[];
/**
* Standard `pattern` usage
*/
result = await globby('*.tmp');
result = await globby(['a.tmp', '*.tmp', '!{c,d,e}.tmp']);
result = globby.sync('*.tmp');
result = globby.sync(['a.tmp', '*.tmp', '!{c,d,e}.tmp']);
result = await globby('*.tmp', Object.freeze({ignore: Object.freeze([])}));
result = globby.sync('*.tmp', Object.freeze({ignore: Object.freeze([])}));
/**
* `expandDirectories` option
*/
result = await globby('*.tmp', { expandDirectories: false });
result = globby.sync('*.tmp', { expandDirectories: false });
result = await globby('*.tmp', { expandDirectories: ['a*', 'b*'] });
result = globby.sync('*.tmp', { expandDirectories: ['a*', 'b*'] });
result = await globby('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp']
}
});
result = globby.sync('*.tmp', {
expandDirectories: {
files: ['a', 'b'],
extensions: ['tmp']
}
});
/**
* Options passed through from `fast-glob`
*/
result = await globby('*.tmp', { ignore: ['**/b.tmp'] });
result = globby.sync('*.tmp', { ignore: ['**/b.tmp'] });
})();
const tasks: Array<{
pattern: string,
options: IOptions
}> = globby.generateGlobTasks(['*.tmp', '!b.tmp'], {ignore: ['c.tmp']});
pattern: string;
options: IOptions;
}> = globby.generateGlobTasks(['*.tmp', '!b.tmp'], { ignore: ['c.tmp'] });
console.log(globby.hasMagic('**'));
console.log(globby.hasMagic(['**', 'path1', 'path2']));
console.log(!globby.hasMagic(['path1', 'path2']));
(async () => {
let result: (path: string) => boolean;
/**
* Standard `gitignore` usage
*/
result = await globby.gitignore();
result = globby.gitignore.sync();
/** With options */
result = await globby.gitignore({
cwd: __dirname,
ignore: ['**/b.tmp']
});
result = globby.gitignore.sync({
cwd: __dirname,
ignore: ['**/b.tmp']
});
})();

View File

@@ -1,37 +1,99 @@
// Type definitions for globby 6.1
// Type definitions for globby 8.0
// Project: https://github.com/sindresorhus/globby#readme
// Definitions by: Douglas Duteil <https://github.com/douglasduteil>
// Ika <https://github.com/ikatyang>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
import { IOptions } from 'glob';
import { IOptions as NodeGlobOptions } from 'glob';
import { Options as FastGlobOptions } from 'fast-glob';
type ExpandDirectoriesOption = boolean | string[] | { files: string[]; extensions: string[] };
interface Options extends FastGlobOptions {
/**
* If set to `true`, `globby` will automatically glob directories for you.
* If you define an `Array` it will only glob files that matches the patterns inside the Array.
* You can also define an `Object` with `files` and `extensions` like below:
*
* ```js
* (async () => {
* const paths = await globby('images', {
* expandDirectories: {
* files: ['cat', 'unicorn', '*.jpg'],
* extensions: ['png']
* }
* });
* console.log(paths);
* //=> ['cat.png', 'unicorn.png', 'cow.jpg', 'rainbow.jpg']
* })();
* ```
*
* Note that if you set this option to `false`, you won't get back matched directories unless
* you set `onlyFiles: false`.
*/
expandDirectories?: ExpandDirectoriesOption;
/**
* Respect ignore patterns in `.gitignore` files that apply to the globbed files.
*/
gitignore?: boolean;
}
/**
* Returns a `Promise<Array>` of matching paths.
*/
declare function globby(patterns: string | string[], options?: IOptions): Promise<string[]>;
declare function globby(patterns: string | string[], options?: Options): Promise<string[]>;
declare namespace globby {
/**
* Returns an `Array` of matching paths.
*/
function sync(patterns: string | string[], options?: IOptions): string[];
function sync(patterns: string | string[], options?: Options): string[];
/**
* Returns an `Array<Object>` in the format `{ pattern: string, opts: Object }`,
* which can be passed as arguments to [node-glob](https://github.com/isaacs/node-glob).
* which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob).
* This is useful for other globbing-related packages.
*
* Note that you should avoid running the same tasks multiple times as they contain a file system cache.
* Instead, run this method each time to ensure file system changes are taken into consideration.
*/
function generateGlobTasks(patterns: string | string[], options?: IOptions): Array<{pattern: string, options: IOptions}>;
function generateGlobTasks(patterns: string | string[], options?: Options): Array<{ pattern: string; options: Options }>;
/**
* Returns a `boolean` of whether there are any special glob characters in the patterns.
* Returns a boolean of whether there are any special glob characters in the `patterns`.
*
* Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not be considered a magic pattern.
* If the pattern has a brace expansion, like `a/{b/c,x/y}`, then that is considered magical, unless `nobrace: true` is set.
* Note that the options affect the results. If `noext: true` is set, then `+(a|b)` will not
* be considered a magic pattern. If the pattern has a brace expansion, like `a/{b/c,x/y}`,
* then that is considered magical, unless `nobrace: true` is set.
*
* This function is backed by [`node-glob`](https://github.com/isaacs/node-glob#globhasmagicpattern-options)
*/
function hasMagic(patterns: string | string[], options?: IOptions): boolean;
function hasMagic(patterns: string | string[], options?: NodeGlobOptions): boolean;
/**
* Returns a Promise<(path: string) => boolean> indicating whether a given path is ignored
* via a `.gitignore` file.
*
* Takes `cwd?: string` and `ignore?: string[]` as options. `.gitignore` files matched by the
* ignore config are not used for the resulting filter function.
*
* ```js
* const {gitignore} = require('globby');
*
* (async () => {
* const isIgnored = await gitignore();
* console.log(isIgnored('some/file'));
* })();
* ```
*/
function gitignore(options?: { cwd?: string; ignore?: string[]; }): Promise<(path: string) => boolean>;
namespace gitignore {
/**
* Returns a `(path: string) => boolean` indicating whether a given path is ignored via a `.gitignore` file.
*
* Takes the same options as `globby.gitignore`.
*/
function sync(options?: { cwd?: string; ignore?: string[]; }): (path: string) => boolean;
}
}
export = globby;

View File

@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"fast-glob": "^2.0.2"
}
}