Skip to content

Commit

Permalink
Update to glob v9 (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
Katsute authored Mar 5, 2023
1 parent 8bc1316 commit ed35f9f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 84 deletions.
83 changes: 20 additions & 63 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"theme": "dark"
},
"publisher": "Katsute",
"version": "2.5.0",
"version": "2.5.1",
"private": true,
"engines": {
"vscode": "^1.76.0"
Expand Down Expand Up @@ -329,12 +329,12 @@
"homepage": "https://github.com/KatsuteDev/Background#readme",
"dependencies": {
"@vscode/sudo-prompt": "9.3.1",
"glob": "8.1.0",
"glob": "9.2.1",
"tmp": "0.2.1"
},
"devDependencies": {
"@types/glob": "8.1.0",
"@types/node": "18.14.1",
"@types/node": "18.14.6",
"@types/tmp": "0.2.3",
"@types/vscode": "1.76.0",
"@vscode/vsce": "2.18.0",
Expand Down
42 changes: 25 additions & 17 deletions src/lib/glob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,49 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

import { glob, IOptions } from "glob";
import { globSync } from "glob";
import { GlobOptions } from "glob/dist/cjs";

import * as path from "path";

import { extensions } from "../command/config/file";
import { unique } from "./unique";

const filter = (v: string) => { // images only
const filter: (v: string) => boolean = (v : string) => {
const ext: string = path.extname(v);
for(const m of extensions())
if(`.${m}` === ext)
return true;
return false;
}

const options: IOptions = {
const options: GlobOptions = {
absolute: true,
nodir: true,
nosort: true
nodir: true
}

export const count: (globs: string | string[]) => number = (globs: string | string[]) => {
export const count: (glob: string | string[]) => number = (glob: string | string[]) => {
let i = 0;
for(const g of (Array.isArray(globs) ? globs : [globs]).filter(unique))
i += +g.startsWith("https://") || glob.sync(g, options).filter(filter).length;
return i;
}

export const resolve: (globs: string | string[]) => string[] = (globs: string | string[]) => {
let p: string[] = [];
for(const g of (Array.isArray(globs) ? globs : [globs]).filter(unique))
let globs: string[] = [];
for(const g of (Array.isArray(glob) ? glob.filter(unique) : [glob]))
if(g.startsWith("https://"))
p.push(`"${g}"`);
i++;
else
for(const f of glob.sync(g, options).filter(filter))
p.push(`"vscode-file://vscode-app/${f.replace(/^\/+/gm, "")}"`);
return p.filter(unique);
globs.push(g);

return i + (globSync(globs, options) as string[]).filter(filter).filter(unique).length;
}

export const resolve: (glob: string | string[]) => string[] = (glob: string | string[]) => {
let p: string[] = [];
let globs: string[] = [];

(Array.isArray(glob) ? glob.filter(unique) : [glob]).forEach(g => (g.startsWith("https://") ? p : globs).push(g));

return p.concat((globSync(globs, options) as string[])
.filter(filter)
.map(path => `vscode-file://vscode-app/${path.replace(/\\/gm, '/').replace(/^\/+/gm, "")}`))
.filter(unique)
.map(path => '"' + path + '"');
}
2 changes: 1 addition & 1 deletion src/lib/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

export const unique = (v: string, i: number, self: string[]) => self.indexOf(v) === i;
export const unique: (v: string, i: number, self: string[]) => boolean = (v: string, i: number, self: string[]) => self.indexOf(v) === i;
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"esModuleInterop": true,
"strict": true,
"alwaysStrict": true,
"sourceMap": true,
Expand Down

0 comments on commit ed35f9f

Please sign in to comment.