lstat panicks if file doesnt exist
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user