How to use the path.toNamespacedPath function in path

To help you get started, we’ve selected a few path examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github graalvm / graaljs / test / parallel / test-path-makelong.js View on Github external
assert.strictEqual(path.toNamespacedPath(file),
                     `\\\\?\\${resolvedFile}`);
  assert.strictEqual(path.toNamespacedPath(`\\\\?\\${file}`),
                     `\\\\?\\${resolvedFile}`);
  assert.strictEqual(path.toNamespacedPath(
    '\\\\someserver\\someshare\\somefile'),
                     '\\\\?\\UNC\\someserver\\someshare\\somefile');
  assert.strictEqual(path.toNamespacedPath(
    '\\\\?\\UNC\\someserver\\someshare\\somefile'),
                     '\\\\?\\UNC\\someserver\\someshare\\somefile');
  assert.strictEqual(path.toNamespacedPath('\\\\.\\pipe\\somepipe'),
                     '\\\\.\\pipe\\somepipe');
}

assert.strictEqual(path.toNamespacedPath(''), '');
assert.strictEqual(path.toNamespacedPath(null), null);
assert.strictEqual(path.toNamespacedPath(100), 100);
assert.strictEqual(path.toNamespacedPath(path), path);
assert.strictEqual(path.toNamespacedPath(false), false);
assert.strictEqual(path.toNamespacedPath(true), true);

const emptyObj = {};
assert.strictEqual(path.posix.toNamespacedPath('/foo/bar'), '/foo/bar');
assert.strictEqual(path.posix.toNamespacedPath('foo/bar'), 'foo/bar');
assert.strictEqual(path.posix.toNamespacedPath(null), null);
assert.strictEqual(path.posix.toNamespacedPath(true), true);
assert.strictEqual(path.posix.toNamespacedPath(1), 1);
assert.strictEqual(path.posix.toNamespacedPath(), undefined);
assert.strictEqual(path.posix.toNamespacedPath(emptyObj), emptyObj);
if (common.isWindows) {
  // These tests cause resolve() to insert the cwd, so we cannot test them from
  // non-Windows platforms (easily)
github graalvm / graaljs / lib / fs.js View on Github external
function link(existingPath, newPath, callback) {
  callback = makeCallback(callback);

  existingPath = getValidatedPath(existingPath, 'existingPath');
  newPath = getValidatedPath(newPath, 'newPath');

  const req = new FSReqCallback();
  req.oncomplete = callback;

  binding.link(pathModule.toNamespacedPath(existingPath),
               pathModule.toNamespacedPath(newPath),
               req);
}
github graalvm / graaljs / graal-nodejs / lib / internal / modules / cjs / loader.js View on Github external
Module._extensions['.node'] = function(module, filename) {
  return process.dlopen(module, path.toNamespacedPath(filename));
};
github npm / tink / lib / pkgmap.js View on Github external
function readPkgMap (...p) {
  const resolved = path.resolve(...p)
  let modulesIdx = resolved.lastIndexOf('node_modules')
  while (modulesIdx !== -1) {
    let substr = resolved.substr(0, modulesIdx - 1)
    const pkgMapPath = path.join(substr, pkgMapName)
    let pkgMap
    if (pkgMapCache.has(pkgMapPath)) {
      pkgMap = pkgMapCache.get(pkgMapPath)
    } else {
      const p = path.toNamespacedPath(pkgMapPath)
      try {
        pkgMap = JSON.parse(fs.readFileSync(p))
        pkgMapCache.set(pkgMapPath, pkgMap)
      } catch (e) {
        if (e.code !== 'ENOENT') {
          throw e
        }
      }
    }
    if (pkgMap) {
      return { pkgMap, subPath: resolved.substr(modulesIdx - 1) }
    } else {
      modulesIdx = substr.lastIndexOf('node_modules')
    }
  }
  return null
github graalvm / graaljs / lib / internal / fs / promises.js View on Github external
async function unlink(path) {
  path = getValidatedPath(path);
  return binding.unlink(pathModule.toNamespacedPath(path), kUsePromises);
}
github graalvm / graaljs / lib / fs.js View on Github external
function readdirSync(path, options) {
  options = getOptions(options, {});
  path = getValidatedPath(path);
  const ctx = { path };
  const result = binding.readdir(pathModule.toNamespacedPath(path),
                                 options.encoding, !!options.withFileTypes,
                                 undefined, ctx);
  handleErrorFromBinding(ctx);
  return options.withFileTypes ? getDirents(path, result) : result;
}
github graalvm / graaljs / lib / internal / fs / promises.js View on Github external
async function readdir(path, options) {
  options = getOptions(options, {});
  path = getValidatedPath(path);
  const result = await binding.readdir(pathModule.toNamespacedPath(path),
                                       options.encoding,
                                       !!options.withFileTypes,
                                       kUsePromises);
  return options.withFileTypes ?
    getDirectoryEntriesPromise(path, result) :
    result;
}
github graalvm / graaljs / lib / internal / fs / promises.js View on Github external
async function open(path, flags, mode) {
  path = getValidatedPath(path);
  if (arguments.length < 2) flags = 'r';
  const flagsNumber = stringToFlags(flags);
  mode = parseMode(mode, 'mode', 0o666);
  return new FileHandle(
    await binding.openFileHandle(pathModule.toNamespacedPath(path),
                                 flagsNumber, mode, kUsePromises));
}
github graalvm / graaljs / lib / fs.js View on Github external
function openSync(path, flags, mode) {
  path = getValidatedPath(path);
  const flagsNumber = stringToFlags(flags || 'r');
  mode = parseMode(mode, 'mode', 0o666);

  const ctx = { path };
  const result = binding.open(pathModule.toNamespacedPath(path),
                              flagsNumber, mode,
                              undefined, ctx);
  handleErrorFromBinding(ctx);
  return result;
}