diff --git a/packages/imperative/src/events/__tests__/__integration__/EventEmitter.integration.test.ts b/packages/imperative/src/events/__tests__/__integration__/EventEmitter.integration.test.ts index 86f12f02bb..fb2718e3a5 100644 --- a/packages/imperative/src/events/__tests__/__integration__/EventEmitter.integration.test.ts +++ b/packages/imperative/src/events/__tests__/__integration__/EventEmitter.integration.test.ts @@ -46,7 +46,7 @@ describe("Event Emitter", () => { const eventType = EventUtils.isSharedEvent(eventName) ? EventTypes.ZoweSharedEvents : EventUtils.isUserEvent(eventName) ? EventTypes.ZoweUserEvents : EventTypes.SharedEvents; - const eventDir = EventUtils.getEventDir(eventType, appName); + const eventDir = EventUtils.getEventDir(appName); if (!fs.existsSync(eventDir)) return false; if (fs.existsSync(path.join(eventDir, appName, eventName))) return true; return false; diff --git a/packages/imperative/src/events/src/Event.ts b/packages/imperative/src/events/src/Event.ts index a4f435840e..7cd302b037 100644 --- a/packages/imperative/src/events/src/Event.ts +++ b/packages/imperative/src/events/src/Event.ts @@ -45,7 +45,7 @@ export class Event implements IEventJson { * * @returns {Object} The JSON representation of the event. */ - public toJson() { + public toJson(): IEventJson { return { eventTime: this.eventTime, eventName: this.eventName, diff --git a/packages/imperative/src/events/src/EventUtils.ts b/packages/imperative/src/events/src/EventUtils.ts index 1c3fd9ee37..2881b2228b 100644 --- a/packages/imperative/src/events/src/EventUtils.ts +++ b/packages/imperative/src/events/src/EventUtils.ts @@ -17,6 +17,7 @@ import { ConfigUtils } from "../../config/src/ConfigUtils"; import { IEventDisposable } from "./doc"; import { Event } from "./Event"; import { EventProcessor } from "./EventProcessor"; +import { IO } from "../../io"; /** * A collection of helper functions related to event processing, including: @@ -63,16 +64,15 @@ export class EventUtils { * @static * @param {string} appName - The name of the application. */ - public static validateAppName(appName: string) { + public static validateAppName(appName: string): void { const appList = this.getListOfApps(); + if (appList.includes(appName)) return; // Performing `appList.find(app => app.includes(appName))` will allow for "tags" (or suffixes) coming from `getListOfApps()` // However, we do not want this behavior because it will allow partial application names to be used // Hence why we should probably match the application name with the exact profileType in `extenders.json` - if (appName !== "Zowe" && !appList.includes(appName)) { - throw new ImperativeError({ - msg: `Application name not found: ${appName}. Please use an application name from the list:\n- ${appList.join("\n- ")}` - }); - } + throw new ImperativeError({ + msg: `Application name not found: ${appName}. Please use an application name from the list:\n- ${appList.join("\n- ")}` + }); } /** @@ -98,14 +98,12 @@ export class EventUtils { /** * Determines the directory path for storing event files based on the event type and application name. * - * @param {EventTypes} eventType - The type of event. * @param {string} appName - The name of the application. * @return {string} The directory path. */ - public static getEventDir(eventType: EventTypes, appName: string): string { + public static getEventDir(appName: string): string { this.validateAppName(appName); - return eventType === EventTypes.SharedEvents || eventType === EventTypes.UserEvents ? - join(".events", appName) : ".events"; + return join(".events", appName); } /** @@ -116,7 +114,7 @@ export class EventUtils { public static ensureEventsDirExists(directoryPath: string) { try { if (!fs.existsSync(directoryPath)) { - fs.mkdirSync(directoryPath); + IO.mkdirp(directoryPath); } } catch (err) { throw new ImperativeError({ msg: `Unable to create '.events' directory. Path: ${directoryPath}`, causeErrors: err }); @@ -147,10 +145,9 @@ export class EventUtils { * @return {IEventDisposable} An interface for managing the subscription. */ public static createSubscription(eeInst: EventProcessor, eventName: string, eventType: EventTypes): IEventDisposable { - const dir = EventUtils.getEventDir(eventType, eeInst.appName); const zoweDir = ConfigUtils.getZoweDir(); - this.ensureEventsDirExists(join(zoweDir, '.events')); - this.ensureEventsDirExists(join(zoweDir, dir)); + const dir = join(zoweDir, EventUtils.getEventDir(eeInst.appName)); + this.ensureEventsDirExists(dir); const filePath = join(zoweDir, dir, eventName); this.ensureFileExists(filePath); diff --git a/packages/imperative/src/events/src/doc/IEventJson.ts b/packages/imperative/src/events/src/doc/IEventJson.ts index 5189be5733..65cc7d9d03 100644 --- a/packages/imperative/src/events/src/doc/IEventJson.ts +++ b/packages/imperative/src/events/src/doc/IEventJson.ts @@ -41,5 +41,5 @@ export interface IEventJson { /** * List of watchers to eventually close */ - subscriptions: fs.FSWatcher[]; + subscriptions?: fs.FSWatcher[]; }