Skip to content

Commit e742da9

Browse files
committed
refactor: use fs/promises
1 parent 64f3362 commit e742da9

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
runs-on: ${{ matrix.os }}
1616
strategy:
1717
matrix:
18-
node-version: [10, 12]
18+
node-version: [10.23.3, 12]
1919
os: [ubuntu-latest, windows-latest, macOS-latest]
2020

2121
steps:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"coffeescript"
1919
],
2020
"engines": {
21-
"node": ">= 9.11.2"
21+
"node": ">= 10.x"
2222
},
2323
"files": [
2424
"dist/"

src/modules/tagInfo.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,19 @@
1-
import { readFile, access } from 'fs';
1+
import fs, { promises as fsPromises } from 'fs';
22
import { resolve, dirname } from 'path';
33

44
import type { PreprocessorArgs } from '../types';
55
import { getLanguage } from './language';
66
import { isValidLocalPath } from './utils';
77

8+
const { access, readFile } = fsPromises;
9+
810
const resolveSrc = (importerFile: string, srcPath: string) =>
911
resolve(dirname(importerFile), srcPath);
1012

11-
const getSrcContent = (file: string): Promise<string> => {
12-
return new Promise((resolve, reject) => {
13-
readFile(file, (error: Error, data: unknown) => {
14-
// istanbul ignore if
15-
if (error) reject(error);
16-
else resolve(data.toString());
17-
});
18-
});
19-
};
20-
2113
async function doesFileExist(file: string) {
22-
return new Promise((resolve) => access(file, 0, (err) => resolve(!err)));
14+
return access(file, fs.constants.F_OK)
15+
.then(() => true)
16+
.catch(() => false);
2317
}
2418

2519
export const getTagInfo = async ({
@@ -44,10 +38,10 @@ export const getTagInfo = async ({
4438
if (isValidLocalPath(path)) {
4539
path = resolveSrc(filename, path);
4640
if (await doesFileExist(path)) {
47-
content = await getSrcContent(path);
41+
content = (await readFile(path)).toString();
4842
dependencies.push(path);
4943
} else {
50-
console.warn(`[svelte-preprocess] The file "${path}" was not found.`);
44+
console.warn(`[svelte-preprocess] The file "${path}" was not found.`);
5145
}
5246
}
5347
}

0 commit comments

Comments
 (0)