-
Notifications
You must be signed in to change notification settings - Fork 113
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
Optimization of algorithms for complex patterns #156
Comments
Sorry, I originally put the wrong label. Why do you think that is incorrect behavior? In your code sample you have not specified an error handler. |
@mrmlnc the strange thing is why access to the directory that should not be accessed |
So, In version 3.0.0, you will be able to ignore errors. |
@mrmlnc It may not be clear enough. In fact, the key point of the problem is not to report the error or not, but why to access the directory that should not be accessed. Also, I found that node-glob is working properly. var glob = require('glob')
glob('+(dir|dir2)/one/**/*', {}, function (error, files) {
if (error) {
console.error(error)
return;
}
console.log(files);
}) result: [ 'dir/one/a',
'dir/one/a/1.js',
'dir/one/b',
'dir/one/b/2.js',
'dir2/one/a',
'dir2/one/a/1.js',
'dir2/one/b',
'dir2/one/b/2.js' ] |
I'm sorry, I think I misunderstood you. I think this related to the mechanism of creating tasks. Further basis on this tasks we crawl directories. In this case, we start reading directories from the root directory for Most likely the So, I think we need to fix it. |
I re-created the folder structure described in the first issue, and this is what I get with fast-glob:
I'm not sure how to reproduce the bug. But I'm still looking into it. |
Is the total 8.0K
drwxr-xr-x 4 keenwon keenwon 4.0K 2月 13 17:37 one
dr-x------ 2 root root 4.0K 2月 13 17:54 two |
Moving to the next milestone, because we are waiting for some staff from |
Just another try to split pattern into segments. This works for most of the patterns from the micromatch tests (random selection). 'use strict';
const mm = require('../micromatch');
const { Minimatch } = require('minimatch');
const utils = require('../fast-glob/out/utils');
const PATTERN = 'root/+(dir1|dir2)/one/**/*';
const mn = new Minimatch(PATTERN);
console.dir(mn, { colors: true });
const buildSegments = (tokens) => {
const segments = [];
let segment = '';
const state = {
parens: 0
};
let index = 0;
while (index < tokens.length) {
const token = tokens[index];
if (token.type === 'paren') {
if (token.value === '(') {
state.parens++;
}
if (token.value === ')') {
state.parens--;
}
}
if ((token.type === 'slash' && state.parens === 0)) {
segments.push(segment);
segment = '';
} else {
segment += token.value;
}
index++;
}
segments.push(segment);
return segments;
};
const makeSegments = (pattern) => {
const [result] = mm.parse(pattern);
if (pattern === '') {
return [];
}
// mm.parse returns [bos] for aa*.txt
if (result.tokens.length === 1 && result.tokens[0].type === 'bos') {
return [pattern];
}
return buildSegments(result.tokens);
};
const convertPatternsToSegments = (patterns) => patterns.map(makeSegments);
const prepare = (pattern) => {
return mm.braceExpand(PATTERN);
};
const makeRe = (segments) => {
return segments.map(segment => {
return segment.map(part => utils.pattern.isDynamicPattern(part) ? mm.makeRe(part) : part);
});
};
const patterns = prepare(PATTERN);
const segments = convertPatternsToSegments(patterns);
const final = makeRe(segments);
console.dir(final, { colors: true });
const parts = [
[
'root',
/^(?:(?=.)(?:dir1|dir2)+)$/,
'one',
/^(?:(?!\.)(?:(?:(?!(?:^|[\\/])\.).)*?)[\\/]?)$/,
/^(?:(?!\.)(?=.)[^\\/]*?[\\/]?)$/
]
];
const files = [
'root/dir1/a/1.js', // +, +, -
'root/dir1/b/2.js', // +, +, -
'root/dir1/two', // +, +, -
'root/dir2/one/a/1.js', // +, +, +, +, +
'root/dir2/one/b/2.js', // +, +, +, +, +
'root/fast-glob.js', // +, -
'root/package.json' // +, -
]; |
After several approaches, I got a working version. We will use partial matching in a deep filter, using positive and negative patterns. The entry filter will be use a full pattern matcher. I’m target this feature to the |
@mrmlnc Can we prioritize the issue, it is blocker for prettier and we want to use |
Thank you for your interest! When do you plan to release a new version of prettier? I planned to release a new version on February 15/16. Is this option suitable for you? I can release the beta version earlier so that you can adapt your processes. The current implementation works, but there is one unpleasant point — patterns like |
@mrmlnc February, original issue - prettier/prettier#6776, I think the beta release would be good, we could check if everything works as we expect |
You can use |
Will be available with |
Environment
Actual behavior
Steps to reproduce and Code sample
. ├── dir │ ├── one │ │ ├── a │ │ │ └── 1.js │ │ └── b │ │ └── 2.js │ └── two [error opening dir] ├── dir2 │ └── one │ ├── a │ │ └── 1.js │ └── b │ └── 2.js ├── fast-glob.js ├── package.json └── package-lock.json
current user doesn't have permission to access
dir/two
:The text was updated successfully, but these errors were encountered: