Only import what is necessary

This commit is contained in:
Corey Butler 2022-10-14 12:10:47 -05:00
parent 2bde77fdf0
commit bdc6f83c6d
No known key found for this signature in database
GPG Key ID: 2C6540ABFD72766C
3 changed files with 13 additions and 15 deletions

View File

@ -1,14 +1,13 @@
import Regex from './regex.js'
import path from 'path'
import fs from 'fs'
import core from '@actions/core'
import { join } from 'path'
import { statSync } from 'fs'
export default class Dockerfile extends Regex {
constructor (root = null) {
root = path.join(process.env.GITHUB_WORKSPACE, root)
root = join(process.env.GITHUB_WORKSPACE, root)
if (fs.statSync(root).isDirectory()) {
root = path.join(root, 'Dockerfile')
if (statSync(root).isDirectory()) {
root = join(root, 'Dockerfile')
}
super(root, /LABEL[\s\t]+version=[\t\s+]?[\"\']?([0-9\.]+)[\"\']?/i)

View File

@ -1,19 +1,19 @@
import fs from 'fs'
import path from 'path'
import { statSync, readFileSync } from 'fs'
import { resolve } from 'path'
export default class Regex {
constructor (root = './', pattern) {
root = path.resolve(root)
root = resolve(root)
if (fs.statSync(root).isDirectory()) {
if (statSync(root).isDirectory()) {
throw new Error(`${root} is a directory. The Regex tag identification strategy requires a file.`)
}
if (!fs.existsSync(root)) {
if (!existsSync(root)) {
throw new Error(`"${root}" does not exist.`)
}
this.content = fs.readFileSync(root).toString()
this.content = readFileSync(root).toString()
let content = pattern.exec(this.content)
if (!content) {

View File

@ -1,5 +1,5 @@
import core from '@actions/core'
import fs from 'fs'
import { readdirSync } from 'fs'
import path from 'path'
export default class Setup {
@ -11,8 +11,7 @@ export default class Setup {
.join('\n -> ')}`
)
const dir = fs
.readdirSync(path.resolve(process.env.GITHUB_WORKSPACE), { withFileTypes: true })
const dir = readdirSync(path.resolve(process.env.GITHUB_WORKSPACE), { withFileTypes: true })
.map(entry => {
return `${entry.isDirectory() ? '> ' : ' - '}${entry.name}`
})