Skip to content

Commit

Permalink
fix: move fast-glob and minimatch as dev-dependencies (#2452)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Mar 6, 2024
1 parent 4ccaaa6 commit cf13b31
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 115 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,8 @@
},
"dependencies": {
"cron-parser": "^4.6.0",
"fast-glob": "^3.3.2",
"ioredis": "^5.3.2",
"lodash": "^4.17.21",
"minimatch": "^9.0.3",
"msgpackr": "^1.10.1",
"node-abort-controller": "^3.1.1",
"semver": "^7.5.4",
Expand All @@ -76,7 +74,6 @@
"@semantic-release/release-notes-generator": "^10.0.3",
"@types/chai": "^4.3.1",
"@types/chai-as-promised": "^7.1.5",
"@types/glob": "^7.2.0",
"@types/lodash.defaults": "^4.2.7",
"@types/lodash.isarguments": "^3.1.7",
"@types/mocha": "^5.2.7",
Expand All @@ -98,10 +95,12 @@
"eslint-plugin-prettier": "4.2.1",
"eslint-plugin-promise": "6.0.0",
"eslint-plugin-tsdoc": "^0.2.16",
"fast-glob": "^3.3.2",
"husky": "^8.0.1",
"istanbul": "^0.4.5",
"lint-staged": "13.0.3",
"madge": "^5.0.1",
"minimatch": "^9.0.3",
"mocha": "^10.0.0",
"mocha-lcov-reporter": "^1.3.0",
"moment": "^2.29.4",
Expand Down
54 changes: 37 additions & 17 deletions src/commands/script-loader.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { createHash } from 'crypto';
import { Minimatch } from 'minimatch';
import * as fg from 'fast-glob';
import * as path from 'path';
import * as fs from 'fs';
import { RedisClient } from '../interfaces';
Expand Down Expand Up @@ -75,19 +73,8 @@ export class ScriptLoaderError extends Error {
}
}

const hasMagic = (pattern: string | string[]): boolean => {
if (!Array.isArray(pattern)) {
pattern = [pattern];
}
for (const p of pattern) {
if (new Minimatch(p, GlobOptions).hasMagic()) {return true;}
}
return false;
};

const isPossiblyMappedPath = (path: string) =>
path && ['~', '<'].includes(path[0]);
const hasFilenamePattern = (path: string) => hasMagic(path);

/**
* Lua script loader with include support
Expand Down Expand Up @@ -203,6 +190,43 @@ export class ScriptLoader {
throw new ScriptLoaderError(msg, file.path, stack, pos.line, pos.column);
}

const minimatch = await import('minimatch');

if (!minimatch) {
console.warn('Install minimatch as dev-dependency');
}

const Minimatch = minimatch.Minimatch || class Empty {};

const fg = await import('fast-glob');

if (!fg) {
console.warn('Install fast-glob as dev-dependency');
}

const nonOp = () => {
return [''];
};
const glob = (fg as any)?.default.glob || nonOp;

const hasMagic = (pattern: string | string[]): boolean => {
if (!Array.isArray(pattern)) {
pattern = [pattern];
}
for (const p of pattern) {
if ((new Minimatch(p, GlobOptions) as any).hasMagic()) {
return true;
}
}
return false;
};

const hasFilenamePattern = (path: string) => hasMagic(path);

async function getFilenamesByPattern(pattern: string): Promise<string[]> {
return glob(pattern, { dot: true });
}

let res;
let content = file.content;

Expand Down Expand Up @@ -497,10 +521,6 @@ function splitFilename(filePath: string): {
return { name, numberOfKeys };
}

async function getFilenamesByPattern(pattern: string): Promise<string[]> {
return fg.glob(pattern, { dot: true });
}

// Determine the project root
// https://stackoverflow.com/a/18721515
function getPkgJsonDir(): string {
Expand Down
Loading

0 comments on commit cf13b31

Please sign in to comment.