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

Add missing functionality for glob compatibility #279

Closed
simlu opened this issue Apr 20, 2019 · 4 comments
Closed

Add missing functionality for glob compatibility #279

simlu opened this issue Apr 20, 2019 · 4 comments

Comments

@simlu
Copy link
Collaborator

simlu commented Apr 20, 2019

The ultimate goal is to get this library into a state where we can use it to power very efficient glob matching. The functionality is almost there. Missing:

  • Arbitrary depth matching of specific patterns, e.g. *(pattern), @(pattern) etc. Have to better understand how pattern are used with file extensions, e.g. what does 'source/*(some|file).py' mean?
  • Full regex support. Maybe we can just support that inside ()?

See here for more information: https://facelessuser.github.io/wcmatch/glob/#syntax

Once equivalent functionality is fully supported it should be possible to write a glob library powered by object-scan.

@simlu
Copy link
Collaborator Author

simlu commented Oct 18, 2020

Regex support is WIP here: https://github.com/blackflux/object-scan/pull/1247/files

@simlu
Copy link
Collaborator Author

simlu commented Oct 22, 2020

This might not be that hard actually:

const isEqual = require('lodash.isequal');
const fs = require('smart-fs');
const path = require('path');
const objectScan = require('object-scan');

const list = (needles, folder) => objectScan(needles, {
  breakFn: ({ key, value, isMatch, context }) => {
    const p = path.join(folder, ...key);
    const stats = fs.lstatSync(p);
    const isDir = stats.isDirectory();
    const isFile = stats.isFile();
    if (isDir) {
      fs.readdirSync(p).forEach((f) => {
        value[f] = {};
      });
    } else if (isFile && isMatch) {
      context.push(path.join(...key));
    }
  }
})({}, []);

const p = path.join(__dirname, 'node_modules');
const r1 = list(['**'], p);
const r2 = fs.walkDir(p);
console.log(isEqual(r1.sort(), r2.sort()));

@simlu
Copy link
Collaborator Author

simlu commented Jun 19, 2022

Should have everything available now to write a glob library 👍

@simlu
Copy link
Collaborator Author

simlu commented Jun 19, 2022

Closing this. Eventually someone might build a glob library on this. Maybe me, maybe not =)

@simlu simlu closed this as completed Jun 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant