Skip to content

Commit

Permalink
Upgrade dev dependencies (#154)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <[email protected]>
  • Loading branch information
iamnapo and sindresorhus authored Oct 4, 2020
1 parent 39b7636 commit 52d02bb
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 105 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ os:
- windows
language: node_js
node_js:
- '14'
- '12'
- '10'
8 changes: 5 additions & 3 deletions gitignore.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,15 @@ const parseGitIgnore = (content, options) => {
};

const reduceIgnore = files => {
return files.reduce((ignores, file) => {
const ignores = gitIgnore();
for (const file of files) {
ignores.add(parseGitIgnore(file.content, {
cwd: file.cwd,
fileName: file.filePath
}));
return ignores;
}, gitIgnore());
}

return ignores;
};

const ensureAbsolutePathForCwd = (cwd, p) => {
Expand Down
8 changes: 4 additions & 4 deletions gitignore.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'path';
import test from 'ava';
import slash from 'slash';
import gitignore from './gitignore';
const path = require('path');
const test = require('ava');
const slash = require('slash');
const gitignore = require('./gitignore');

test('gitignore', async t => {
const cwd = path.join(__dirname, 'fixtures/gitignore');
Expand Down
80 changes: 40 additions & 40 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare namespace globby {

interface GlobTask {
readonly pattern: string;
readonly options: globby.GlobbyOptions;
readonly options: GlobbyOptions;
}

interface GitignoreOptions {
Expand All @@ -55,6 +55,11 @@ declare namespace globby {
}

interface Gitignore {
/**
@returns A filter function indicating whether a given path is ignored via a `.gitignore` file.
*/
sync: (options?: globby.GitignoreOptions) => globby.FilterFunction;

/**
`.gitignore` files matched by the ignore config are not used for the resulting filter function.
Expand All @@ -71,11 +76,6 @@ interface Gitignore {
```
*/
(options?: globby.GitignoreOptions): Promise<globby.FilterFunction>;

/**
@returns A filter function indicating whether a given path is ignored via a `.gitignore` file.
*/
sync(options?: globby.GitignoreOptions): globby.FilterFunction;
}

declare const globby: {
Expand All @@ -84,40 +84,14 @@ declare const globby: {
Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
@param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
@returns The matching paths.
@example
```
import globby = require('globby');
(async () => {
const paths = await globby(['*', '!cake']);
console.log(paths);
//=> ['unicorn', 'rainbow']
})();
```
*/
(
patterns: string | readonly string[],
options?: globby.GlobbyOptions
): Promise<string[]>;

/**
Find files and directories using glob patterns.
Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
@param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
@returns The matching paths.
*/
sync(
sync: (
patterns: string | readonly string[],
options?: globby.GlobbyOptions
): string[];
) => string[];

/**
Find files and directories using glob patterns.
Expand All @@ -139,10 +113,10 @@ declare const globby: {
})();
```
*/
stream(
stream: (
patterns: string | readonly string[],
options?: globby.GlobbyOptions
): NodeJS.ReadableStream;
) => NodeJS.ReadableStream;

/**
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.
Expand All @@ -151,10 +125,10 @@ declare const globby: {
@param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
@returns An object in the format `{pattern: string, options: object}`, which can be passed as arguments to [`fast-glob`](https://github.com/mrmlnc/fast-glob). This is useful for other globbing-related packages.
*/
generateGlobTasks(
generateGlobTasks: (
patterns: string | readonly string[],
options?: globby.GlobbyOptions
): globby.GlobTask[];
) => globby.GlobTask[];

/**
Note that the options affect the results.
Expand All @@ -165,12 +139,38 @@ declare const globby: {
@param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3).
@returns Whether there are any special glob characters in the `patterns`.
*/
hasMagic(
hasMagic: (
patterns: string | readonly string[],
options?: FastGlobOptions
): boolean;
) => boolean;

readonly gitignore: Gitignore;

/**
Find files and directories using glob patterns.
Note that glob patterns can only contain forward-slashes, not backward-slashes, so if you want to construct a glob pattern from path components, you need to use `path.posix.join()` instead of `path.join()`.
@param patterns - See the supported [glob patterns](https://github.com/sindresorhus/globby#globbing-patterns).
@param options - See the [`fast-glob` options](https://github.com/mrmlnc/fast-glob#options-3) in addition to the ones in this package.
@returns The matching paths.
@example
```
import globby = require('globby');
(async () => {
const paths = await globby(['*', '!cake']);
console.log(paths);
//=> ['unicorn', 'rainbow']
})();
```
*/
(
patterns: string | readonly string[],
options?: globby.GlobbyOptions
): Promise<string[]>;
};

export = globby;
28 changes: 16 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const checkCwdOption = (options = {}) => {
let stat;
try {
stat = fs.statSync(options.cwd);
} catch (_) {
} catch {
return;
}

Expand Down Expand Up @@ -56,7 +56,7 @@ const generateGlobTasks = (patterns, taskOptions) => {

const ignore = patterns
.slice(index)
.filter(isNegative)
.filter(pattern => isNegative(pattern))
.map(pattern => pattern.slice(1));

const options = {
Expand Down Expand Up @@ -138,26 +138,30 @@ module.exports = async (patterns, options) => {
module.exports.sync = (patterns, options) => {
const globTasks = generateGlobTasks(patterns, options);

const tasks = globTasks.reduce((tasks, task) => {
const tasks = [];
for (const task of globTasks) {
const newTask = getPattern(task, dirGlob.sync).map(globToTask(task));
return tasks.concat(newTask);
}, []);
tasks.push(...newTask);
}

const filter = getFilterSync(options);

return tasks.reduce(
(matches, task) => arrayUnion(matches, fastGlob.sync(task.pattern, task.options)),
[]
).filter(path_ => !filter(path_));
let matches = [];
for (const task of tasks) {
matches = arrayUnion(matches, fastGlob.sync(task.pattern, task.options));
}

return matches.filter(path_ => !filter(path_));
};

module.exports.stream = (patterns, options) => {
const globTasks = generateGlobTasks(patterns, options);

const tasks = globTasks.reduce((tasks, task) => {
const tasks = [];
for (const task of globTasks) {
const newTask = getPattern(task, dirGlob.sync).map(globToTask(task));
return tasks.concat(newTask);
}, []);
tasks.push(...newTask);
}

const filter = getFilterSync(options);
const filterStream = new FilterStream(p => !filter(p));
Expand Down
3 changes: 2 additions & 1 deletion index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ expectType<NodeJS.ReadableStream>(globbyStream('*.tmp', {ignore: ['**/b.tmp']}))
for await (const path of globbyStream('*.tmp')) {
streamResult.push(path);
}

// `NodeJS.ReadableStream` is not generic, unfortunately,
// so it seems `(string | Buffer)[]` is the best we can get here
expectType<(string | Buffer)[]>(streamResult);
expectType<Array<string | Buffer>>(streamResult);
})();

// GenerateGlobTasks
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"author": {
"email": "[email protected]",
"name": "Sindre Sorhus",
"url": "sindresorhus.com"
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=10"
Expand Down Expand Up @@ -65,14 +65,14 @@
"slash": "^3.0.0"
},
"devDependencies": {
"ava": "^2.1.0",
"get-stream": "^5.1.0",
"ava": "^3.13.0",
"get-stream": "^6.0.0",
"glob-stream": "^6.1.0",
"globby": "sindresorhus/globby#master",
"matcha": "^0.7.0",
"rimraf": "^3.0.0",
"tsd": "^0.11.0",
"xo": "^0.25.3"
"rimraf": "^3.0.2",
"tsd": "^0.13.1",
"xo": "^0.33.1"
},
"xo": {
"ignores": [
Expand Down
Loading

0 comments on commit 52d02bb

Please sign in to comment.