How to use file-uri-to-path - 5 common examples

To help you get started, we’ve selected a few file-uri-to-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 pikapkg / pack / src / index.ts View on Github external
import {ConsoleReporter, JSONReporter} from './reporters/index.js';
import {commands} from './commands/index.js';
import * as helpCommand from './commands/help.js';
import * as constants from './constants.js';
import { MessageError } from '@pika/types';
import Config from './config.js';
import handleSignals from './util/signal-handler.js';
import {boolify, boolifyWithDefault} from './util/conversion.js';
import map from './util/map.js';
import stripBOM from 'strip-bom';
import uri2path from 'file-uri-to-path';

const commander = new Command();

// @ts-ignore
const currentFilename = uri2path(import.meta.url);
function getVersion() {
  const packageJsonContent = fs.readFileSync(path.resolve(currentFilename, '../../package.json'), {encoding: 'utf-8'});
  const {version} = map(JSON.parse(stripBOM(packageJsonContent)));
  return version;
}

function findProjectRoot(base: string): string {
  let prev = null;
  let dir = base;

  do {
    if (fs.existsSync(path.join(dir, constants.NODE_PACKAGE_JSON))) {
      return dir;
    }

    prev = dir;
github pikapkg / pack / checkpoint / dist-src / index.js View on Github external
import loudRejection from 'loud-rejection';
import semver from 'semver';
import { ConsoleReporter, JSONReporter } from './reporters/index.js';
import { commands } from './commands/index.js';
import * as helpCommand from './commands/help.js';
import * as constants from './constants.js';
import { MessageError } from '@pika/types';
import Config from './config.js';
import handleSignals from './util/signal-handler.js';
import { boolify, boolifyWithDefault } from './util/conversion.js';
import map from './util/map.js';
import stripBOM from 'strip-bom';
import uri2path from 'file-uri-to-path';
const commander = new Command();
// @ts-ignore
const currentFilename = uri2path(import.meta.url);
function getVersion() {
    const packageJsonContent = fs.readFileSync(path.resolve(currentFilename, '../../package.json'), { encoding: 'utf-8' });
    const { version } = map(JSON.parse(stripBOM(packageJsonContent)));
    return version;
}
function findProjectRoot(base) {
    let prev = null;
    let dir = base;
    do {
        if (fs.existsSync(path.join(dir, constants.NODE_PACKAGE_JSON))) {
            return dir;
        }
        prev = dir;
        dir = path.dirname(dir);
    } while (dir !== prev);
    return base;
github zeit / hyper / app / ui / window.ts View on Github external
window.webContents.on('will-navigate', (event, url) => {
    const protocol = typeof url === 'string' && parseUrl(url).protocol;
    if (protocol === 'file:') {
      event.preventDefault();

      const path = fileUriToPath(url);

      rpc.emit('session data send', {data: path, escaped: true});
    } else if (protocol === 'http:' || protocol === 'https:') {
      event.preventDefault();
      rpc.emit('session data send', {data: url});
    }
  });
github firefox-devtools / vscode-firefox-debug / src / adapter / util / net.ts View on Github external
export async function getUri(uri: string): Promise {

	if (uri.startsWith('data:')) {
		return dataUriToBuffer(uri).toString();
	}

	if (uri.startsWith('file:')) {
		return await fs.readFile(fileUriToPath(uri), 'utf8');
	}

	if (!uri.startsWith('http:') && !uri.startsWith('https:')) {
		throw new Error(`Fetching ${uri} not supported`);
	}

	return await new Promise((resolve, reject) => {
		const parsedUrl = url.parse(uri);
		const get = (parsedUrl.protocol === 'https:') ? https.get : http.get;
		const options = Object.assign({ rejectUnauthorized: false }, parsedUrl) as https.RequestOptions;

		get(options, response => {
			let responseData = '';
			response.on('data', chunk => responseData += chunk);
			response.on('end', () => {
				if (response.statusCode === 200) {
github antew / elm-lsp / lib / language-server.ts View on Github external
async function validateTextDocument(change: TextDocumentChangeEvent): Promise {
      elm.ports.fileWatch.send({
        event: "update",
        file: path.relative(process.cwd(), uri2path(change.document.uri)),
        content: change.document.getText()
      });
    }

file-uri-to-path

Convert a file: URI to a file path

MIT
Latest version published 5 years ago

Package Health Score

65 / 100
Full package analysis

Popular file-uri-to-path functions