lstat panicks if file doesnt exist

This commit is contained in:
2022-06-08 10:09:14 -05:00
parent 588ee08d10
commit f0c3f7db1a
6 changed files with 14 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
import { build, BuildFailure } from 'esbuild'
import {
existsSync,
lstatSync,
readdirSync,
readFileSync,
@@ -47,7 +48,7 @@ async function compileProject(
}
//add UserScript header
if (lstatSync(outPath).isFile()) {
if (existsSync(outPath)) {
if (!error) {
let content = readFileSync(outPath).toString()
writeFileSync(outPath, metaString + content)
@@ -59,7 +60,7 @@ async function compileProject(
return [metaJson, error]
}
if (!lstatSync('package.json').isFile()) {
if (!existsSync('package.json') || !lstatSync('package.json').isFile()) {
console.error('package.json not found, unwilling to run')
process.exit(1)
}
@@ -81,7 +82,9 @@ readdirSync(DistBase).forEach(file => unlinkSync(`${DistBase}/${file}`))
if (
!name.endsWith('_') &&
existsSync(path.dir) &&
lstatSync(path.dir).isDirectory() &&
existsSync(path.main) &&
lstatSync(path.main).isFile()
) {
let [meta, error] = await compileProject(name)

View File

@@ -1,4 +1,4 @@
import { lstatSync, readFileSync } from 'fs'
import { existsSync, lstatSync, readFileSync } from 'fs'
import { BaseUrl, FileUrl, ScriptPath, SupportUrl } from './paths'
import {
UserScriptMeta,
@@ -29,7 +29,7 @@ export default function (name: string): [UserScriptMetaFull, string] {
let metaPath = ScriptPath(name).meta
if (lstatSync(metaPath).isFile()) {
if (existsSync(metaPath) && lstatSync(metaPath).isFile()) {
try {
let args: UserScriptMetaPartial = JSON.parse(
readFileSync(metaPath).toString()