Skip to content

Commit

Permalink
workers/scan-file: readFile -> open
Browse files Browse the repository at this point in the history
  • Loading branch information
VandeurenGlenn committed Aug 11, 2024
1 parent 88dab32 commit 8f31de4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/stages/workers/scan-file.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import * as modReplacements from 'module-replacements';
import {ts as sg} from '@ast-grep/napi';
import {readFile} from 'node:fs/promises';
import dedent from 'dedent';
import pc from 'picocolors';
import {type FileReplacement} from './../../shared-types.js';
import {suggestReplacement} from './../../suggest-replacement.js';
import {parentPort} from 'node:worker_threads';
import {open} from 'node:fs/promises';

async function scanFile(
filePath: string,
Expand Down Expand Up @@ -85,9 +85,11 @@ async function scanTask(
replacements: modReplacements.ModuleReplacement[]
) {
try {
const contents = await readFile(file, 'utf8');
const fd = await open(file);
const contents = await fd.readFile({encoding: 'utf-8'});
const lines = contents.split('\n');
const scanResult = await scanFile(file, contents, lines, replacements);
await fd.close();

parentPort?.postMessage({type: 'result', value: scanResult});
} catch (err) {
Expand Down

0 comments on commit 8f31de4

Please sign in to comment.