Skip to content

Commit

Permalink
feat: 🎸 add realpathSync() method
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Jun 20, 2023
1 parent a1a61c5 commit f9a3cbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/fsa-to-node/FsaNodeFs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
getAppendFileOpts,
getDefaultOpts,
getReaddirOptions,
getRealpathOptions,
} from '../node/options';
import {
bufToUint8,
Expand Down Expand Up @@ -950,9 +951,15 @@ export class FsaNodeFs extends FsaNodeCore implements FsCallbackApi, FsSynchrono
}
};

public readonly realpathSync: FsSynchronousApi['realpathSync'] = (path: misc.PathLike, options?: opts.IRealpathOptions | string): misc.TDataOut => {
let filename = pathToFilename(path);
const {encoding} = getRealpathOptions(options);
if (filename[0] !== FsaToNodeConstants.Separator) filename = FsaToNodeConstants.Separator + filename;
return strToEncoding(filename, encoding);
}

public readonly openSync: FsSynchronousApi['openSync'] = notSupported;
public readonly readSync: FsSynchronousApi['readSync'] = notSupported;
public readonly realpathSync: FsSynchronousApi['realpathSync'] = notSupported;
public readonly writeSync: FsSynchronousApi['writeSync'] = notSupported;

public readonly chmodSync: FsSynchronousApi['chmodSync'] = noop;
Expand Down
8 changes: 8 additions & 0 deletions src/fsa-to-node/__tests__/FsaNodeFs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,14 @@ onlyOnNode20('FsaNodeFs', () => {
});
});

describe('.realpathSync()', () => {
test('returns file path', async () => {
const { fs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
const path = fs.realpathSync('folder/file');
expect(path).toBe('/folder/file');
});
});

describe('.copyFile()', () => {
test('can copy a file', async () => {
const { fs, mfs } = setup({ folder: { file: 'test' }, 'empty-folder': null, 'f.html': 'test' });
Expand Down

0 comments on commit f9a3cbe

Please sign in to comment.