Skip to content

Commit

Permalink
chore: lint everything
Browse files Browse the repository at this point in the history
  • Loading branch information
boneskull committed Aug 1, 2024
1 parent a1f692d commit 1aba3d0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
9 changes: 5 additions & 4 deletions src/impvol-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -38,8 +39,8 @@ let tmp: string;
let uint8: Uint8Array;

export const initialize: InitializeHook<ImpVolInitData> = ({
tmp: _tmp,
sab,
tmp: _tmp,
}) => {
tmp = _tmp;
uint8 = new Uint8Array(sab);
Expand All @@ -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:
Expand Down
31 changes: 16 additions & 15 deletions src/impvol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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);
Expand All @@ -71,11 +72,11 @@ export class ImportableVolume extends Volume {
debug('Instantiated ImportableVolume with temp file: %s', tmp);

register<ImpVolInitData>(HOOKS_PATH, {
parentURL: IMPVOL_URL,
data: {
tmp,
sab,
tmp,
},
parentURL: IMPVOL_URL,
});
}

Expand All @@ -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();
Expand Down Expand Up @@ -127,53 +128,53 @@ 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;
update(this);
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;
update(this);
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;
update(this);
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;
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type ImpVolInitData = {
tmp: string;
sab: SharedArrayBuffer;
tmp: string;
};
5 changes: 3 additions & 2 deletions test/impvol.spec.ts
Original file line number Diff line number Diff line change
@@ -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__';

Expand Down

0 comments on commit 1aba3d0

Please sign in to comment.