docs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
Create a utility that resolves file paths to their canonical absolute paths, handling symbolic links and relative paths.
You need to implement a Node.js module that provides a function to resolve paths to their canonical form. The function should:
Create a file pathResolver.js that exports a function named resolveCanonicalPath:
inputPath (string)Provides an in-memory filesystem implementation for testing purposes.
// pathResolver.test.js
const MemoryFs = require('metro-memory-fs');
const { resolveCanonicalPath } = require('./pathResolver');
const fs = new MemoryFs();
fs.writeFileSync('/home/user/document.txt', 'content');
const result = resolveCanonicalPath(fs, '/home/user/document.txt');
// Expected: '/home/user/document.txt'// pathResolver.test.js
const MemoryFs = require('metro-memory-fs');
const { resolveCanonicalPath } = require('./pathResolver');
const fs = new MemoryFs();
fs.writeFileSync('/home/target.txt', 'data');
fs.symlinkSync('/home/target.txt', '/home/link.txt');
const result = resolveCanonicalPath(fs, '/home/link.txt');
// Expected: '/home/target.txt'// pathResolver.test.js
const MemoryFs = require('metro-memory-fs');
const { resolveCanonicalPath } = require('./pathResolver');
const fs = new MemoryFs();
fs.mkdirSync('/real/path', { recursive: true });
fs.writeFileSync('/real/path/file.txt', 'content');
fs.symlinkSync('/real/path', '/link1');
fs.symlinkSync('/link1', '/link2');
const result = resolveCanonicalPath(fs, '/link2/file.txt');
// Expected: '/real/path/file.txt'