Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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;
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;
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});
}
});
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) {
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()
});
}