feat(build): add file access utility

This commit is contained in:
2026-07-29 21:47:05 +02:00
parent 6549d5acb6
commit 02a1c2cd02
+47
View File
@@ -0,0 +1,47 @@
/*
Copyright 2026 Seekra
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { access, constants, stat } from 'node:fs/promises';
export const checkFileReadAccess = async function checkFileWriteAccess (path) {
try {
await access(path, constants.F_OK | constants.R_OK);
return true;
} catch (err) {
if (err.code === 'ENOENT' || err.code === 'EACCES') return false;
else throw err;
}
};
export const exists = async function exists (path) {
try {
await access(path, constants.F_OK);
return true;
} catch (err) {
if (err.code === 'ENOENT') return false;
else throw err;
}
};
export const isDirectory = async function isDirectory (path) {
try {
const stats = await stat(path);
return stats.isDirectory();
} catch (err) {
if (err.code === 'ENOENT' || err.code === 'EACCES') return false;
else throw err;
}
};