How to use the path.isAbsolute 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 Akryum / monorepo-run / src / util / find-executable.js View on Github external
exports.findExecutable = (command, cwd, options) => {
  // If we have an absolute path then we take it.
  if (path.isAbsolute(command)) {
    return command
  }
  let dir = path.dirname(command)
  if (dir !== '.') {
    // We have a directory and the directory is relative (see above). Make the path absolute
    // to the current working directory.
    return path.join(cwd, command)
  }
  let paths
  // The options can override the PATH. So consider that PATH if present.
  if (options && options.env) {
    // Path can be named in many different ways and for the execution it doesn't matter
    for (let key of Object.keys(options.env)) {
      if (key.toLowerCase() === 'path') {
        if (typeof options.env[key] === 'string') {
          paths = options.env[key].split(path.delimiter)
github joefitzgerald / go-plus / lib / output-panel.js View on Github external
linkClicked(text: string, dir: string) {
    const { file, line = 1, column = 0 } = parseGoPosition(text)

    let filepath
    if (path.isAbsolute(file)) {
      filepath = file
    } else {
      const base = dir || projectPath()
      if (!base) {
        return
      }
      filepath = path.join(base, file)
    }

    const col = column && column > 0 ? column - 1 : 0
    openFile(filepath, { row: line - 1, column: col }).catch(err => {
      console.log('could not access ' + file, err) // eslint-disable-line no-console
    })
  }
github asciidoctor / asciidoctor-vscode / src / features / previewContentProvider.ts View on Github external
private fixHref(resource: vscode.Uri, href: string): string {
		if (!href) {
			return href;
		}

		// Use href if it is already an URL
		const hrefUri = vscode.Uri.parse(href);
		if (['http', 'https'].indexOf(hrefUri.scheme) >= 0) {
			return hrefUri.toString();
		}

		// Use href as file URI if it is absolute
		if (path.isAbsolute(href) || hrefUri.scheme === 'file') {
			return vscode.Uri.file(href)
				.with({ scheme: 'vscode-resource' })
				.toString();
		}

		// Use a workspace relative path if there is a workspace
		let root = vscode.workspace.getWorkspaceFolder(resource);
		if (root) {
			return vscode.Uri.file(path.join(root.uri.fsPath, href))
				.with({ scheme: 'vscode-resource' })
				.toString();
		}

		// Otherwise look relative to the asciidoc file
		return vscode.Uri.file(path.join(path.dirname(resource.fsPath), href))
			.with({ scheme: 'vscode-resource' })
github bespoken / bst / lib / client / module-manager.ts View on Github external
public constructor(private directory: string) {
        // If the directory path is not absolute, make it so
        if (!path.isAbsolute(directory)) {
            this.directory = path.join(process.cwd(), this.directory);
        }
    }
github fusionjs / fusionjs / fusion-cli / build / get-webpack-config.js View on Github external
devtoolModuleFilenameTemplate: (info /*: Object */) => {
        // always return absolute paths in order to get sensible source map explorer visualization
        return path.isAbsolute(info.absoluteResourcePath)
          ? info.absoluteResourcePath
          : path.join(dir, info.absoluteResourcePath);
      },
    },
github yarnpkg / yarn / packages / pkg-tests / pkg-tests-specs / sources / script.js View on Github external
async ({path, run, source}) => {
          await run(`install`);

          const {stdout} = await run(`bin`, `has-bin-entries`);

          expect(isAbsolute(stdout.trim())).toEqual(true);
        },
      ),
github whxaxes / mus / lib / index.js View on Github external
const cb = () => {
      if (!path.extname(filePath)) {
        filePath += `.${this.ext}`;
      }

      return path.isAbsolute(filePath)
        ? filePath
        : path.resolve(this.baseDir, filePath);
    };
github vuejs / vuepress / packages / @vuepress / core / lib / dev.js View on Github external
function normalizeWatchFilePath (filepath, baseDir) {
  const { isAbsolute, relative } = require('path')
  if (isAbsolute(filepath)) {
    return relative(baseDir, filepath)
  }
  return filepath
}
github pmq20 / node-packer / vendor / node-v6.9.1 / lib / module.js View on Github external
Module._findPath = function(request, paths, isMain) {
  if (path.isAbsolute(request) ||
      '/__enclose_io_memfs__' == request.substring(0, '/__enclose_io_memfs__'.length) ||
      '\\__enclose_io_memfs__' == request.substring(0, '\\__enclose_io_memfs__'.length)) {
    paths = [''];
  } else if (!paths || paths.length === 0) {
    return false;
  }

  const cacheKey = JSON.stringify({request: request, paths: paths});
  if (Module._pathCache[cacheKey]) {
    return Module._pathCache[cacheKey];
  }

  var exts;
  const trailingSlash = request.length > 0 &&
                        request.charCodeAt(request.length - 1) === 47/*/*/;