Skip to content

Commit

Permalink
fix fs imports
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgamero authored Nov 6, 2024
1 parent c0fe16a commit 03f0978
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
7 changes: 4 additions & 3 deletions src/types/privatekubectl.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as fileUtils from '../utilities/fileUtils'
import * as fs from 'fs'
import fs from 'node:fs'
import {
PrivateKubectl,
extractFileNames,
Expand All @@ -23,7 +23,7 @@ describe('Private kubectl', () => {
return '/tmp'
})

jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { })
jest.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
return 'test contents'
})
Expand All @@ -39,6 +39,7 @@ describe('Private kubectl', () => {
})

it('should replace filenames with shallow names for relative locations in tmp correctly', () => {

expect(
replaceFileNamesWithShallowNamesRelativeToTemp(testString)
).toEqual(
Expand All @@ -49,7 +50,7 @@ describe('Private kubectl', () => {
test('Should throw well defined Error on error from Azure', async () => {
const errorMsg = 'An error message'
jest.spyOn(exec, 'getExecOutput').mockImplementation(async () => {
return {exitCode: 1, stdout: '', stderr: errorMsg}
return { exitCode: 1, stdout: '', stderr: errorMsg }
})

await expect(mockKube.executeCommand('az', 'test')).rejects.toThrow(
Expand Down
5 changes: 2 additions & 3 deletions src/types/privatekubectl.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { Kubectl } from './kubectl'
import * as minimist from 'minimist'
import minimist from 'minimist'
import { ExecOptions, ExecOutput, getExecOutput } from '@actions/exec'
import * as core from '@actions/core'
import * as os from 'os'
import * as fs from 'fs'
import fs from 'node:fs'
import * as path from 'path'
import { getTempDirectory } from '../utilities/fileUtils'

Expand Down
6 changes: 3 additions & 3 deletions src/utilities/fileUtils.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as fileUtils from './fileUtils'

import * as yaml from 'js-yaml'
import * as fs from 'fs'
import fs from 'node:fs'
import * as path from 'path'
import {K8sObject} from '../types/k8sObject'
import { K8sObject } from '../types/k8sObject'

const sampleYamlUrl =
'https://raw.githubusercontent.com/kubernetes/website/main/content/en/examples/controllers/nginx-deployment.yaml'
Expand Down Expand Up @@ -107,7 +107,7 @@ describe('File utils', () => {

describe('moving files to temp', () => {
it('correctly moves the contents of a file to the temporary directory', () => {
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => {})
jest.spyOn(fs, 'writeFileSync').mockImplementation(() => { })
jest.spyOn(fs, 'readFileSync').mockImplementation((filename) => {
return 'test contents'
})
Expand Down
16 changes: 8 additions & 8 deletions src/utilities/fileUtils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as fs from 'fs'
import fs from 'node:fs'
import * as https from 'https'
import * as path from 'path'
import * as core from '@actions/core'
import * as os from 'os'
import * as yaml from 'js-yaml'
import {Errorable, succeeded, failed, Failed} from '../types/errorable'
import {getCurrentTime} from './timeUtils'
import {isHttpUrl} from './githubUtils'
import {K8sObject} from '../types/k8sObject'
import { Errorable, succeeded, failed, Failed } from '../types/errorable'
import { getCurrentTime } from './timeUtils'
import { isHttpUrl } from './githubUtils'
import { K8sObject } from '../types/k8sObject'

export const urlFileKind = 'urlfile'

Expand All @@ -32,7 +32,7 @@ export function writeObjectsToFile(inputObjects: any[]): string[] {
} else {
core.debug(
'Input object is not proper K8s resource object. Object: ' +
inputObjectString
inputObjectString
)
}
} catch (ex) {
Expand Down Expand Up @@ -73,7 +73,7 @@ export function moveFileToTmpDir(originalFilepath: string) {
const dirName = path.dirname(newPath)
if (!fs.existsSync(dirName)) {
core.debug(`path ${dirName} doesn't exist yet, making new dir...`)
fs.mkdirSync(dirName, {recursive: true})
fs.mkdirSync(dirName, { recursive: true })
}
core.debug(`writing contents to new path ${newPath}`)
fs.writeFileSync(path.join(newPath), contents)
Expand Down Expand Up @@ -207,7 +207,7 @@ function verifyYaml(filepath: string, url: string): Errorable<K8sObject[]> {
}
}

return {succeeded: true, result: inputObjects}
return { succeeded: true, result: inputObjects }
}

function recurisveManifestGetter(dirName: string): string[] {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs"
"module": "commonjs",
"esModuleInterop": true
},
"exclude": ["node_modules", "test", "src/**/*.test.ts"]
}

0 comments on commit 03f0978

Please sign in to comment.