From 7dfbbc285661190a11b3c12c9ec6de058ebdb217 Mon Sep 17 00:00:00 2001 From: Daniel Imhoff Date: Sun, 3 Mar 2019 15:26:12 -0600 Subject: [PATCH] feat(process): add `getPathParts` to split path into parts --- packages/@ionic/utils-process/src/index.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/@ionic/utils-process/src/index.ts b/packages/@ionic/utils-process/src/index.ts index bf08f5f2e3..fdd3214b94 100644 --- a/packages/@ionic/utils-process/src/index.ts +++ b/packages/@ionic/utils-process/src/index.ts @@ -2,6 +2,7 @@ import { createCaseInsensitiveObject } from '@ionic/utils-object'; import { TERMINAL_INFO } from '@ionic/utils-terminal'; import * as Debug from 'debug'; import * as lodash from 'lodash'; +import * as pathlib from 'path'; import * as kill from 'tree-kill'; const debug = Debug('ionic:utils-process'); @@ -29,10 +30,17 @@ export function killProcessTree(pid: number, signal: string | number = 'SIGTERM' * sensitivity matters. This method creates an empty "`process.env`" object * type that works for all platforms. */ -export function createProcessEnv(...sources: { [key: string]: string | undefined; }[]): { [key: string]: string; } { +export function createProcessEnv(...sources: { [key: string]: string | undefined; }[]): NodeJS.ProcessEnv { return lodash.assign(TERMINAL_INFO.windows ? createCaseInsensitiveObject() : {}, ...sources); } +/** + * Split a PATH string into path parts. + */ +export function getPathParts(envpath = process.env.PATH || ''): string[] { + return envpath.split(pathlib.delimiter); +} + /** * Resolves when the given amount of milliseconds has passed. */