mirror of
https://github.com/SukkaW/Surge.git
synced 2026-01-29 01:51:52 +08:00
Refactor: make ESLint happy
This commit is contained in:
@@ -1,43 +0,0 @@
|
||||
import { dirname } from 'path';
|
||||
import fs from 'fs';
|
||||
import fsp from 'fs/promises';
|
||||
|
||||
const peekStatus = new WeakMap<Promise<any>, 'pending' | 'rejected' | 'fulfilled'>();
|
||||
export function track<T>(promise: Promise<T>): Promise<T> {
|
||||
// only set to pending if not already tracked
|
||||
if (!peekStatus.has(promise)) {
|
||||
peekStatus.set(promise, 'pending');
|
||||
}
|
||||
|
||||
// Observe the promise, saving the fulfillment in a closure scope.
|
||||
return promise.then(
|
||||
(v) => {
|
||||
peekStatus.set(promise, 'fulfilled');
|
||||
return v;
|
||||
},
|
||||
(e) => {
|
||||
peekStatus.set(promise, 'rejected');
|
||||
throw e;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
export function peek(promise: Promise<any>): 'pending' | 'rejected' | 'fulfilled' | 'unknown' {
|
||||
return peekStatus.get(promise) ?? 'unknown';
|
||||
}
|
||||
|
||||
interface Write {
|
||||
(
|
||||
destination: string,
|
||||
input: NodeJS.TypedArray | string,
|
||||
): Promise<unknown>
|
||||
}
|
||||
|
||||
export const writeFile: Write = async (destination: string, input) => {
|
||||
const dir = dirname(destination);
|
||||
|
||||
if (!fs.existsSync(dir)) {
|
||||
await fsp.mkdir(dir, { recursive: true });
|
||||
}
|
||||
return fsp.writeFile(destination, input, { encoding: 'utf-8' });
|
||||
};
|
||||
@@ -4,9 +4,8 @@ import picocolors from 'picocolors';
|
||||
import type { Span } from '../trace';
|
||||
import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { fastStringArrayJoin } from './misc';
|
||||
import { fastStringArrayJoin, writeFile } from './misc';
|
||||
import { readFileByLine } from './fetch-text-by-line';
|
||||
import { writeFile } from './bun';
|
||||
|
||||
export async function compareAndWriteFile(span: Span, linesA: string[], filePath: string) {
|
||||
let isEqual = true;
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { dirname } from 'path';
|
||||
import fs from 'fs';
|
||||
import fsp from 'fs/promises';
|
||||
|
||||
export const isTruthy = <T>(i: T | 0 | '' | false | null | undefined): i is T => !!i;
|
||||
|
||||
export const fastStringArrayJoin = (arr: string[], sep: string) => {
|
||||
@@ -11,8 +15,16 @@ export const fastStringArrayJoin = (arr: string[], sep: string) => {
|
||||
return result;
|
||||
};
|
||||
|
||||
export const fastStringArrayJoin2 = (arr: string[], sep: string) => {
|
||||
return arr.reduce((acc, cur, index) => {
|
||||
return index === 0 ? cur : acc + sep + cur;
|
||||
}, '');
|
||||
interface Write {
|
||||
(
|
||||
destination: string,
|
||||
input: NodeJS.TypedArray | string,
|
||||
): Promise<unknown>
|
||||
}
|
||||
|
||||
export const writeFile: Write = async (destination: string, input, dir = dirname(destination)) => {
|
||||
if (!fs.existsSync(dir)) {
|
||||
await fsp.mkdir(dir, { recursive: true });
|
||||
}
|
||||
return fsp.writeFile(destination, input, { encoding: 'utf-8' });
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user