mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-03-19 15:01:06 +08:00
fix(node-utils): Do not throw if readFile path is not resolved.
This commit is contained in:
parent
9df6579198
commit
b451c29b4a
@ -27,14 +27,9 @@ async function readFile(filePath) {
|
||||
`Could not read file, file path should be a string, received ${JSON.stringify(filePath)}.`
|
||||
);
|
||||
}
|
||||
if (filePath !== path.resolve(filePath)) {
|
||||
throw new Error(
|
||||
`Could not read file, file path was not resolved, received ${JSON.stringify(filePath)}.`
|
||||
);
|
||||
}
|
||||
try {
|
||||
// By specifying encoding, readFile returns a string instead of a buffer.
|
||||
const file = await readFilePromise(filePath, 'utf8');
|
||||
const file = await readFilePromise(path.resolve(filePath), 'utf8');
|
||||
return file;
|
||||
} catch (error) {
|
||||
if (error.code === 'ENOENT' || error.code === 'EISDIR') {
|
||||
|
@ -35,9 +35,3 @@ test('readFile error id filepath is not a string', async () => {
|
||||
'Could not read file, file path should be a string, received {}.'
|
||||
);
|
||||
});
|
||||
|
||||
test('readFile errors if path is not already resolved', async () => {
|
||||
await expect(readFile('./readFile/readFile.txt')).rejects.toThrow(
|
||||
'Could not read file, file path was not resolved, received "./readFile/readFile.txt".'
|
||||
);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user