From 1aba3d09d09f818d997b829fbe24ac96a18b20d7 Mon Sep 17 00:00:00 2001 From: Christopher Hiller Date: Thu, 1 Aug 2024 11:21:13 -0700 Subject: [PATCH] chore: lint everything --- src/impvol-hooks.ts | 9 +++++---- src/impvol.ts | 31 ++++++++++++++++--------------- src/types.ts | 2 +- test/impvol.spec.ts | 5 +++-- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/impvol-hooks.ts b/src/impvol-hooks.ts index 08c1315..94b5f2e 100644 --- a/src/impvol-hooks.ts +++ b/src/impvol-hooks.ts @@ -17,13 +17,14 @@ import { } from 'node:module'; import path from 'node:path'; import {fileURLToPath} from 'node:url'; + import {type ImpVolInitData} from './types.js'; const debug = Debug('impvol:hooks'); const PROTOCOL = 'impvol'; -let vol: Volume | undefined; +let vol: undefined | Volume; /** * Gets or sets & gets the {@link vol} singleton @@ -38,8 +39,8 @@ let tmp: string; let uint8: Uint8Array; export const initialize: InitializeHook = ({ - tmp: _tmp, sab, + tmp: _tmp, }) => { tmp = _tmp; uint8 = new Uint8Array(sab); @@ -53,12 +54,12 @@ const DISALLOWED_FORMATS = new Set(['builtin']); function guessFormat(specifier: string): ModuleFormat | undefined { const ext = path.extname(specifier); switch (ext) { - case '.mjs': - return 'module'; case '.cjs': return 'commonjs'; case '.json': return 'json'; + case '.mjs': + return 'module'; case '.wasm': return 'wasm'; default: diff --git a/src/impvol.ts b/src/impvol.ts index 5b03bbf..d015196 100644 --- a/src/impvol.ts +++ b/src/impvol.ts @@ -12,11 +12,12 @@ import { fromBinarySnapshotSync, toBinarySnapshotSync, } from 'memfs/lib/snapshot/binary.js'; -import {Volume, type DirectoryJSON} from 'memfs/lib/volume.js'; +import {type DirectoryJSON, Volume} from 'memfs/lib/volume.js'; import {mkdtempSync, writeFileSync} from 'node:fs'; import {register} from 'node:module'; import path from 'node:path'; import {tmpdir} from 'os'; + import {HOOKS_PATH, IMPVOL_URL} from './paths.js'; import {type ImpVolInitData} from './types.js'; @@ -58,7 +59,7 @@ function update(impvol: ImportableVolume): void { } export class ImportableVolume extends Volume { - constructor(props?: {Node?: Node; Link?: Link; File?: File}) { + constructor(props?: {File?: File; Link?: Link; Node?: Node}) { super(props); const sab = new SharedArrayBuffer(1); const uint8 = new Uint8Array(sab); @@ -71,11 +72,11 @@ export class ImportableVolume extends Volume { debug('Instantiated ImportableVolume with temp file: %s', tmp); register(HOOKS_PATH, { - parentURL: IMPVOL_URL, data: { - tmp, sab, + tmp, }, + parentURL: IMPVOL_URL, }); } @@ -88,7 +89,7 @@ export class ImportableVolume extends Volume { public static create( this: void, - volumeOrJson?: Volume | DirectoryJSON, + volumeOrJson?: DirectoryJSON | Volume, cwd = '/', ): ImportableVolume { const impVol = new ImportableVolume(); @@ -127,20 +128,20 @@ export class ImportableVolume extends Volume { // TODO: probably need more here, but this is a start. Also: consider doing // something else. Object.assign(ImportableVolume.prototype, { - writeFileBase(this: ImportableVolume, ...args: unknown[]): unknown { + linkBase(this: ImportableVolume, ...args: unknown[]): unknown { // @ts-expect-error private // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - const returnValue = Volume.prototype.writeFileBase.call( + const returnValue = Volume.prototype.linkBase.call( this, ...args, ) as unknown; update(this); return returnValue; }, - unlinkBase(this: ImportableVolume, ...args: unknown[]): unknown { + symlinkBase(this: ImportableVolume, ...args: unknown[]): unknown { // @ts-expect-error private // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - const returnValue = Volume.prototype.unlinkBase.call( + const returnValue = Volume.prototype.symlinkBase.call( this, ...args, ) as unknown; @@ -148,10 +149,10 @@ Object.assign(ImportableVolume.prototype, { return returnValue; }, - writevBase(this: ImportableVolume, ...args: unknown[]): unknown { + unlinkBase(this: ImportableVolume, ...args: unknown[]): unknown { // @ts-expect-error private // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - const returnValue = Volume.prototype.writevBase.call( + const returnValue = Volume.prototype.unlinkBase.call( this, ...args, ) as unknown; @@ -159,10 +160,10 @@ Object.assign(ImportableVolume.prototype, { return returnValue; }, - linkBase(this: ImportableVolume, ...args: unknown[]): unknown { + writeFileBase(this: ImportableVolume, ...args: unknown[]): unknown { // @ts-expect-error private // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - const returnValue = Volume.prototype.linkBase.call( + const returnValue = Volume.prototype.writeFileBase.call( this, ...args, ) as unknown; @@ -170,10 +171,10 @@ Object.assign(ImportableVolume.prototype, { return returnValue; }, - symlinkBase(this: ImportableVolume, ...args: unknown[]): unknown { + writevBase(this: ImportableVolume, ...args: unknown[]): unknown { // @ts-expect-error private // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access - const returnValue = Volume.prototype.symlinkBase.call( + const returnValue = Volume.prototype.writevBase.call( this, ...args, ) as unknown; diff --git a/src/types.ts b/src/types.ts index bec7dc3..71e118d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,4 +1,4 @@ export type ImpVolInitData = { - tmp: string; sab: SharedArrayBuffer; + tmp: string; }; diff --git a/test/impvol.spec.ts b/test/impvol.spec.ts index ffbf5d8..b040962 100644 --- a/test/impvol.spec.ts +++ b/test/impvol.spec.ts @@ -1,8 +1,9 @@ +// eslint-disable-next-line n/no-missing-import +import {Volume} from 'memfs/lib/volume.js'; import assert from 'node:assert'; import {describe, it} from 'node:test'; + import {ImportableVolume, impvol} from '../src/impvol.js'; -// eslint-disable-next-line n/no-missing-import -import {Volume} from 'memfs/lib/volume.js'; const TEST_DIR = '/__impvol__';