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

Fix glob problems with path's in windows, safeGlobSync implemented. #2278

Merged
merged 3 commits into from Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/bin/actionhero.ts
Expand Up @@ -2,7 +2,6 @@

import * as path from "path";
import * as fs from "fs";
import * as glob from "glob";
import { program, InvalidArgumentError } from "commander";
import { typescript } from "../classes/process/typescript";
import { projectRoot } from "../classes/process/projectRoot";
Expand All @@ -15,6 +14,7 @@ import "../config/api";
import "../config/plugins";
import "../config/logger";
import "../config/routes";
import { safeGlobSync } from "../modules/utils/safeGlob";

export namespace ActionheroCLIRunner {
export async function run() {
Expand Down Expand Up @@ -70,7 +70,7 @@ export namespace ActionheroCLIRunner {
const matcher = `${realpath}/**/+(${
typescript ? `${match}.js|*.ts` : `${match}.js`
})`;
const files = ensureNoTsHeaderFiles(glob.sync(matcher));
const files = ensureNoTsHeaderFiles(safeGlobSync(matcher));
for (const i in files) {
const collection = await import(files[i]);
for (const j in collection) {
Expand Down
10 changes: 5 additions & 5 deletions src/classes/process.ts
@@ -1,5 +1,4 @@
import * as path from "path";
import * as glob from "glob";
import * as fs from "fs";
import { config } from "..";
import { log } from "../modules/log";
Expand All @@ -11,6 +10,7 @@ import { env } from "./process/env";
import { writePidFile, clearPidFile } from "./process/pid";
import { api } from "../index";
import { rebuildConfig } from "../modules/config";
import { safeGlobSync } from "../modules/utils/safeGlob";

export const fatalErrorCode = "FATAL_ACTIONHERO_ERROR";

Expand Down Expand Up @@ -62,15 +62,15 @@ export class Process {

// load initializers from core
initializerFiles = initializerFiles.concat(
glob.sync(
safeGlobSync(
path.join(__dirname, "..", "initializers", "**", "**/*(*.js|*.ts)")
)
);

// load initializers from project
config.general.paths.initializer.forEach((startPath: string) => {
initializerFiles = initializerFiles.concat(
glob.sync(path.join(startPath, "**", "**/*(*.js|*.ts)"))
safeGlobSync(path.join(startPath, "**", "**/*(*.js|*.ts)"))
);
});

Expand All @@ -84,12 +84,12 @@ export class Process {
if (plugin.initializers !== false) {
// old style at the root of the project
initializerFiles = initializerFiles.concat(
glob.sync(path.join(pluginPath, "initializers", "**", "*.js"))
safeGlobSync(path.join(pluginPath, "initializers", "**", "*.js"))
);

// new TS dist files
initializerFiles = initializerFiles.concat(
glob.sync(path.join(pluginPath, "dist", "initializers", "**", "*.js"))
safeGlobSync(path.join(pluginPath, "dist", "initializers", "**", "*.js"))
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/initializers/actions.ts
@@ -1,6 +1,6 @@
import * as glob from "glob";
import * as path from "path";
import { api, config, log, utils, Initializer, Action } from "../index";
import { safeGlobSync } from "../modules/utils/safeGlob";
import * as ActionModule from "./../modules/action";

export interface ActionsApi {
Expand Down Expand Up @@ -93,7 +93,7 @@ export class ActionsInitializer extends Initializer {
};

for (const p of config.general.paths.action) {
let files = glob.sync(path.join(p, "**", "**/*(*.js|*.ts)"));
let files = safeGlobSync(path.join(p, "**", "**/*(*.js|*.ts)"));
files = utils.ensureNoTsHeaderFiles(files);
for (const j in files) {
await api.actions.loadFile(files[j]);
Expand All @@ -105,10 +105,10 @@ export class ActionsInitializer extends Initializer {
const pluginPath: string = path.normalize(plugin.path);

// old style at the root of the project
let files = glob.sync(path.join(pluginPath, "actions", "**", "*.js"));
let files = safeGlobSync(path.join(pluginPath, "actions", "**", "*.js"));

files = files.concat(
glob.sync(path.join(pluginPath, "dist", "actions", "**", "*.js"))
safeGlobSync(path.join(pluginPath, "dist", "actions", "**", "*.js"))
);

utils
Expand Down
8 changes: 4 additions & 4 deletions src/initializers/servers.ts
@@ -1,7 +1,7 @@
import * as path from "path";
import * as glob from "glob";
import { api, config, log, utils, Initializer, Server } from "../index";
import { PluginConfig } from "../classes/config";
import { safeGlobSync } from "../modules/utils/safeGlob";

export interface ServersApi {
servers: {
Expand Down Expand Up @@ -39,7 +39,7 @@ export class Servers extends Initializer {

for (const i in serverFolders) {
const p = serverFolders[i];
files = files.concat(glob.sync(path.join(p, "**", "**/*(*.js|*.ts)")));
files = files.concat(safeGlobSync(path.join(p, "**", "**/*(*.js|*.ts)")));
}

for (const [_, plugin] of Object.entries(config.plugins as PluginConfig)) {
Expand All @@ -48,11 +48,11 @@ export class Servers extends Initializer {

// old style at the root of the project
files = files.concat(
glob.sync(path.join(pluginPath, "servers", "**", "*.js"))
safeGlobSync(path.join(pluginPath, "servers", "**", "*.js"))
);

files = files.concat(
glob.sync(path.join(pluginPath, "dist", "servers", "**", "*.js"))
safeGlobSync(path.join(pluginPath, "dist", "servers", "**", "*.js"))
);
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/initializers/tasks.ts
@@ -1,10 +1,9 @@
import * as glob from "glob";
import * as path from "path";
import { Plugin } from "node-resque";
import * as TaskModule from "./../modules/task";
import { api, config, log, utils, task, Initializer } from "../index";
import { Task } from "../classes/task";
import { PluginConfig } from "../classes/config";
import { safeGlobSync } from "../modules/utils/safeGlob";

const taskModule = task;

Expand Down Expand Up @@ -140,7 +139,7 @@ export class TasksInitializer extends Initializer {
await Promise.all(
utils
.ensureNoTsHeaderFiles(
glob.sync(path.join(p, "**", "**/*(*.js|*.ts)"))
safeGlobSync(path.join(p, "**", "**/*(*.js|*.ts)"))
)
.map((f) => api.tasks.loadFile(f, reload))
);
Expand All @@ -151,10 +150,10 @@ export class TasksInitializer extends Initializer {
const pluginPath = path.normalize(plugin.path);

// old style at the root of the project
let files = glob.sync(path.join(pluginPath, "tasks", "**", "*.js"));
let files = safeGlobSync(path.join(pluginPath, "tasks", "**", "*.js"));

files = files.concat(
glob.sync(path.join(pluginPath, "dist", "tasks", "**", "*.js"))
safeGlobSync(path.join(pluginPath, "dist", "tasks", "**", "*.js"))
);

utils.ensureNoTsHeaderFiles(files).forEach((f) => {
Expand Down
4 changes: 2 additions & 2 deletions src/modules/config.ts
@@ -1,6 +1,5 @@
import * as fs from "fs";
import * as path from "path";
import * as glob from "glob";
import { utils } from "./utils";
import { ensureNoTsHeaderFiles } from "./utils/ensureNoTsHeaderFiles";

Expand All @@ -20,6 +19,7 @@ import {
} from "./../classes/process/projectRoot";
import { RouteMethod, RoutesConfig, RouteType } from "..";
import { ActionheroConfigInterface } from "../classes/config";
import { safeGlobSync } from "./utils/safeGlob";

export function buildConfig() {
const configPaths: string[] = [];
Expand Down Expand Up @@ -133,7 +133,7 @@ export function buildConfig() {

const loadConfigDirectory = (configPath: string, watch: boolean) => {
const configFiles = ensureNoTsHeaderFiles(
glob.sync(path.join(configPath, "**", "**/*(*.js|*.ts)"))
safeGlobSync(path.join(configPath, "**", "**/*(*.js|*.ts)"))
);

let loadRetries = 0;
Expand Down
6 changes: 6 additions & 0 deletions src/modules/utils/safeGlob.ts
@@ -0,0 +1,6 @@
import * as glob from "glob";

export function safeGlobSync(match: string, args: glob.IOptions = {}) {
const isWindows = process.platform === "win32";
return glob.sync(match, {...args, windowsPathsNoEscape: isWindows})
}