How to use the realpathSync function from fs-extra

Find comprehensive JavaScript fs-extra.realpathSync code examples handpicked from public code repositorys.

fs-extra.realpathSync resolves the real path of a given file or directory synchronously, resolving any symbolic links along the way.

103
104
105
106
107
108
109
110
111
112
var dirs = [];
var files = [];
fns.sort().filter(function (fn) {
  var fullPath = fspath.join(path, fn);
  // we use fs.realpathSync to also resolve Symbolic Link
  var absoluteFullPath = fs.realpathSync(fspath.join(root, fullPath));
  if (fn[0] != ".") {
    var stats = fs.lstatSync(absoluteFullPath);
    if (stats.isDirectory()) {
      dirs.push(fn);
fork icon0
star icon2
watch icon0

34
35
36
37
38
39
40
41
42
43
44
45
function forgivingWhichSync (cmd) {
    const whichResult = which.sync(cmd, { nothrow: true });


    // On null, returns empty string to maintain backwards compatibility
    // realpathSync follows symlinks
    return whichResult === null ? '' : fs.realpathSync(whichResult);
}


module.exports.list_images_using_avdmanager = function () {
    return execa('avdmanager', ['list', 'avd']).then(({ stdout: output }) => {
fork icon0
star icon0
watch icon1

+ 3 other calls in file

How does fs-extra.realpathSync work?

fs-extra.realpathSync is a synchronous method in the fs-extra library for resolving a given path to the absolute path, following any symbolic links or mount points encountered in the process. It operates similarly to fs.realpathSync but offers additional functionality and works across different operating systems.

119
120
121
122
123
124
125
126
127
128
}

if (!stats.isFile(localPath)) {
  return;
}
const source = fs.realpathSync(path.join(jlab.linkedPackages[name], rest));
if (source === fs.realpathSync(localPath)) {
  return;
}
fs.watchFile(source, { interval: 500 }, function (curr) {
fork icon0
star icon0
watch icon1

+ 35 other calls in file

39
40
41
42
43
44
45
46
47
48
// 这里的 filePath 没有做同样的处理,可能会导致 import 指向
// 源代码文件,导致文件被意外修改
filePath = fs.realpathSync(filePath);
const prefixs = Object.keys(pathAlias);
if (prefixs.includes(name)) {
    return promoteRelativePath(path.relative(filePath, fs.realpathSync(resolveScriptPath(pathAlias[name]))));
}
const reg = new RegExp(`^(${prefixs.join('|')})/(.*)`);
name = name.replace(reg, function (m, $1, $2) {
    return promoteRelativePath(path.relative(filePath, path.join(pathAlias[$1], $2)));
fork icon0
star icon0
watch icon1

+ 13 other calls in file

Ai Example

1
2
3
4
5
6
7
const fse = require("fs-extra");

const path = "./my-symlink";
const resolvedPath = fse.realpathSync(path);

console.log(resolvedPath);
// Output: /Users/myuser/my-project/real-path-to-file

In this example, we're using fs-extra.realpathSync to resolve the real path of the symbolic link at ./my-symlink. The function returns the real path to the file or directory that the symbolic link points to, which is then logged to the console.

237
238
239
240
241
242
243
244
245
246
const destFile = path.join(targetDir, path.basename(obj.src));

let project_ref;
const link = !!(options && options.link);
if (link) {
    const trueSrc = fs.realpathSync(srcFile);
    // Create a symlink in the expected place, so that uninstall can use it.
    if (options && options.force) {
        copyFile(plugin_dir, trueSrc, project_dir, destFile, link);
    } else {
fork icon0
star icon0
watch icon0

+ 5 other calls in file

function icon

fs-extra.readFileSync is the most popular function in fs-extra (9724 examples)