From 8e9f1df1cec1ef23f9e12dcd0e661c8c9454d8de Mon Sep 17 00:00:00 2001 From: Mihajlo Date: Tue, 12 Oct 2021 16:45:39 +0200 Subject: [PATCH] chore: fixing the error when using in angular, added isNode check for imports --- src/utils/tmpFiles.ts | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/utils/tmpFiles.ts b/src/utils/tmpFiles.ts index 4ddc620..84d2415 100644 --- a/src/utils/tmpFiles.ts +++ b/src/utils/tmpFiles.ts @@ -1,7 +1,10 @@ -import * as path from 'path' -import { getRealPath, folderExists, createFolder } from '@sasjs/utils' +import { isNode } from '../utils' export const getTmpFolderPath = async () => { + if (!isNode()) return 'Error: not node environment' + + const { getRealPath, folderExists, createFolder } = require('@sasjs/utils/file') + const path = require('path') const tmpFolderPath = path.join(__dirname, '..', 'tmp') if (!(await folderExists(tmpFolderPath))) await createFolder(tmpFolderPath) @@ -9,8 +12,20 @@ export const getTmpFolderPath = async () => { return tmpFolderPath } -export const getTmpFilesFolderPath = async () => - path.join(await getTmpFolderPath(), 'files') +export const getTmpFilesFolderPath = async () => { + if (!isNode()) return 'Error: not node environment' -export const getTmpLogFolderPath = async () => - path.join(await getTmpFolderPath(), 'log') + const { getRealPath, folderExists, createFolder } = require('@sasjs/utils/file') + const path = require('path') + + return path.join(await getTmpFolderPath(), 'files') +} + +export const getTmpLogFolderPath = async () => { + if (!isNode()) return 'Error: not node environment' + + const { getRealPath, folderExists, createFolder } = require('@sasjs/utils/file') + const path = require('path') + + return path.join(await getTmpFolderPath(), 'log') +}