From ed35f9f0cbab37b0929550c3cc60dddc66e0f6f8 Mon Sep 17 00:00:00 2001 From: Katsute <58778985+Katsute@users.noreply.github.com> Date: Sun, 5 Mar 2023 12:08:03 -0500 Subject: [PATCH] Update to glob v9 (#107) --- package-lock.json | 83 ++++++++++++----------------------------------- package.json | 6 ++-- src/lib/glob.ts | 42 ++++++++++++++---------- src/lib/unique.ts | 2 +- tsconfig.json | 1 + 5 files changed, 50 insertions(+), 84 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5c4454ff..d27fdc98 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,21 +1,21 @@ { "name": "code-background", - "version": "2.5.0", + "version": "2.5.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "code-background", - "version": "2.5.0", + "version": "2.5.1", "license": "GPL-2.0-only", "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", @@ -43,9 +43,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "18.14.1", - "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.1.tgz", - "integrity": "sha512-QH+37Qds3E0eDlReeboBxfHbX9omAcBCXEzswCu6jySP642jiM3cYSIkU/REqwhCUqXdonHFuBfJDiAJxMNhaQ==", + "version": "18.14.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.6.tgz", + "integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==", "dev": true }, "node_modules/@types/tmp": { @@ -547,18 +547,17 @@ "optional": true }, "node_modules/glob": { - "version": "8.1.0", - "resolved": "https://registry.npmjs.org/glob/-/glob-8.1.0.tgz", - "integrity": "sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==", + "version": "9.2.1", + "resolved": "https://registry.npmjs.org/glob/-/glob-9.2.1.tgz", + "integrity": "sha512-Pxxgq3W0HyA3XUvSXcFhRSs+43Jsx0ddxcFrbjxNGkL2Ak5BAUBxLqI5G6ADDeCHLfzzXFhe0b1yYcctGmytMA==", "dependencies": { "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^5.0.1", - "once": "^1.3.0" + "minimatch": "^7.4.1", + "minipass": "^4.2.4", + "path-scurry": "^1.6.1" }, "engines": { - "node": ">=12" + "node": ">=16 || 14 >=14.17" }, "funding": { "url": "https://github.com/sponsors/isaacs" @@ -573,14 +572,17 @@ } }, "node_modules/glob/node_modules/minimatch": { - "version": "5.1.6", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-5.1.6.tgz", - "integrity": "sha512-lKwV/1brpG6mBUFHtb7NUmtABCb2WZZmm2wNiOA5hAb8VdCS4B3dtMWyvcoViccwAW/COERjXLt0zP1zXUN26g==", + "version": "7.4.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-7.4.2.tgz", + "integrity": "sha512-xy4q7wou3vUoC9k1xGTXc+awNdGaGVHtFUaey8tiX4H1QRc04DZ/rmDFwNm2EBsuYEhAZ6SgMmYf3InGY6OauA==", "dependencies": { "brace-expansion": "^2.0.1" }, "engines": { "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" } }, "node_modules/has": { @@ -818,7 +820,6 @@ "version": "4.2.4", "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.4.tgz", "integrity": "sha512-lwycX3cBMTvcejsHITUgYj6Gy6A7Nh4Q6h9NP4sTHY1ccJlC7yKzDmiShEHsJ16Jf1nKGDEaiHxiltsJEvk0nQ==", - "dev": true, "engines": { "node": ">=8" } @@ -954,7 +955,6 @@ "version": "1.6.1", "resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.6.1.tgz", "integrity": "sha512-OW+5s+7cw6253Q4E+8qQ/u1fVvcJQCJo/VFD8pje+dbJCF1n5ZRMV2AEHbGp+5Q7jxQIYJxkHopnj6nzdGeZLA==", - "dev": true, "dependencies": { "lru-cache": "^7.14.1", "minipass": "^4.0.2" @@ -970,7 +970,6 @@ "version": "7.18.1", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.1.tgz", "integrity": "sha512-8/HcIENyQnfUTCDizRu9rrDyG6XG/21M4X7/YEGZeD76ZJilFPAUVb/2zysFf7VVO1LEjCDFyHp8pMMvozIrvg==", - "dev": true, "engines": { "node": ">=12" } @@ -1095,48 +1094,6 @@ "url": "https://github.com/sponsors/isaacs" } }, - "node_modules/rimraf/node_modules/brace-expansion": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz", - "integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==", - "dev": true, - "dependencies": { - "balanced-match": "^1.0.0" - } - }, - "node_modules/rimraf/node_modules/glob": { - "version": "9.2.1", - "resolved": "https://registry.npmjs.org/glob/-/glob-9.2.1.tgz", - "integrity": "sha512-Pxxgq3W0HyA3XUvSXcFhRSs+43Jsx0ddxcFrbjxNGkL2Ak5BAUBxLqI5G6ADDeCHLfzzXFhe0b1yYcctGmytMA==", - "dev": true, - "dependencies": { - "fs.realpath": "^1.0.0", - "minimatch": "^7.4.1", - "minipass": "^4.2.4", - "path-scurry": "^1.6.1" - }, - "engines": { - "node": ">=16 || 14 >=14.17" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/rimraf/node_modules/minimatch": { - "version": "7.4.2", - "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-7.4.2.tgz", - "integrity": "sha512-xy4q7wou3vUoC9k1xGTXc+awNdGaGVHtFUaey8tiX4H1QRc04DZ/rmDFwNm2EBsuYEhAZ6SgMmYf3InGY6OauA==", - "dev": true, - "dependencies": { - "brace-expansion": "^2.0.1" - }, - "engines": { - "node": ">=10" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, "node_modules/safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", diff --git a/package.json b/package.json index 50b85746..2d269f8c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "theme": "dark" }, "publisher": "Katsute", - "version": "2.5.0", + "version": "2.5.1", "private": true, "engines": { "vscode": "^1.76.0" @@ -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", diff --git a/src/lib/glob.ts b/src/lib/glob.ts index 8e8a431c..4f25d578 100644 --- a/src/lib/glob.ts +++ b/src/lib/glob.ts @@ -16,14 +16,15 @@ * 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) @@ -31,26 +32,33 @@ const filter = (v: string) => { // images only 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 + '"'); } \ No newline at end of file diff --git a/src/lib/unique.ts b/src/lib/unique.ts index b461ca6b..1bfb5603 100644 --- a/src/lib/unique.ts +++ b/src/lib/unique.ts @@ -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; \ No newline at end of file +export const unique: (v: string, i: number, self: string[]) => boolean = (v: string, i: number, self: string[]) => self.indexOf(v) === i; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index c3a77426..58f11e76 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "target": "ES2020", "module": "commonjs", + "esModuleInterop": true, "strict": true, "alwaysStrict": true, "sourceMap": true,