Skip to content

Commit 3f9572c

Browse files
committed
fix: revert "refactor: use fs/promises"
This reverts commit e742da9.
1 parent 0d6872b commit 3f9572c

File tree

3 files changed

+17
-10
lines changed

3 files changed

+17
-10
lines changed

Diff for: .github/workflows/ci.yml

+1-1
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.23.3, 12]
18+
node-version: [10, 12]
1919
os: [ubuntu-latest, windows-latest, macOS-latest]
2020

2121
steps:

Diff for: package.json

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

Diff for: src/modules/tagInfo.ts

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
1-
import fs from 'fs';
1+
/* eslint-disable node/prefer-promises/fs */
2+
import { readFile, access } from 'fs';
23
import { resolve, dirname } from 'path';
34

45
import type { PreprocessorArgs } from '../types';
56
import { getLanguage } from './language';
67
import { isValidLocalPath } from './utils';
78

8-
const { access, readFile } = fs.promises;
9-
109
const resolveSrc = (importerFile: string, srcPath: string) =>
1110
resolve(dirname(importerFile), srcPath);
1211

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

1926
export const getTagInfo = async ({
@@ -38,10 +45,10 @@ export const getTagInfo = async ({
3845
if (isValidLocalPath(path)) {
3946
path = resolveSrc(filename, path);
4047
if (await doesFileExist(path)) {
41-
content = (await readFile(path)).toString();
48+
content = await getSrcContent(path);
4249
dependencies.push(path);
4350
} else {
44-
console.warn(`[svelte-preprocess] The file "${path}" was not found.`);
51+
console.warn(`[svelte-preprocess] The file "${path}" was not found.`);
4552
}
4653
}
4754
}

0 commit comments

Comments
 (0)