Created
October 27, 2022 16:42
-
-
Save cooljl31/2a50421a4ddaaefc1735dbe0bb5ac2dc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import glob from 'fast-glob' | |
import nodeURL from 'url' | |
import process from 'process' | |
/** Returns pathnames matching the given pattern. */ | |
const sync = (source: string) => glob.sync(source, options()) as string[] | |
/** Returns pathnames matching the given pattern. */ | |
const async = (source: string) => glob(source, options()) as Promise<string[]> | |
/** Metadata context-specific to the current process. */ | |
const meta = { | |
/** URL href of the current working directory. */ | |
get cwd() { | |
return nodeURL.pathToFileURL(process.cwd()).href as string | |
}, | |
/** URL href of the currently running file. */ | |
get url() { | |
return new URL( | |
meta.cwd + | |
Error() | |
.stack.match(/ eval \((.+?):/)[1] | |
.replace(nodeURL.pathToFileURL(process.cwd()).pathname, '') | |
).href | |
}, | |
} | |
/** Internal options used for globbing. */ | |
const options = () => ({ | |
cwd: nodeURL.fileURLToPath(new URL('.', meta.url)), | |
ignore: ['**/node_modules/**'], | |
}) | |
export { sync as default, meta, sync, async } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment