From dc412ce0bcaf9aaab985a8708620702c080e7266 Mon Sep 17 00:00:00 2001 From: Pascal Hartig Date: Mon, 4 Feb 2019 04:39:31 -0800 Subject: [PATCH] Replace ad-hoc home dir expansion with package Summary: Instead of replacing the tilde with home-dirs on an incomplete, ad-hoc basis, let's use a package for this. It also supports `~USER` resolution which someone might reasonbly expect to work if `~/DIR` is working. Reviewed By: jknoxville Differential Revision: D13940956 fbshipit-source-id: 5bfa9b8b2540fed8c05c856ff736e48e925f985d --- src/chrome/ScreenCaptureButtons.js | 11 +++++------ static/compilePlugins.js | 3 ++- static/index.js | 3 ++- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/chrome/ScreenCaptureButtons.js b/src/chrome/ScreenCaptureButtons.js index 178ef57dd..713155527 100644 --- a/src/chrome/ScreenCaptureButtons.js +++ b/src/chrome/ScreenCaptureButtons.js @@ -9,8 +9,9 @@ import {Button, ButtonGroup, Component} from 'flipper'; import {connect} from 'react-redux'; import AndroidDevice from '../devices/AndroidDevice'; import IOSDevice from '../devices/IOSDevice'; -import os from 'os'; +import expandTilde from 'expand-tilde'; import fs from 'fs'; +import os from 'os'; import adb from 'adbkit-fb'; import {exec, spawn} from 'child_process'; import {remote} from 'electron'; @@ -19,11 +20,9 @@ import {reportPlatformFailures} from '../utils/metrics'; let CAPTURE_LOCATION = remote.app.getPath('desktop'); try { - CAPTURE_LOCATION = - JSON.parse(window.process.env.CONFIG).screenCapturePath.replace( - /^~/, - os.homedir(), - ) || CAPTURE_LOCATION; + CAPTURE_LOCATION = expandTilde( + JSON.parse(window.process.env.CONFIG).screenCapturePath || CAPTURE_LOCATION, + ); } catch (e) {} import type BaseDevice from '../devices/BaseDevice'; diff --git a/static/compilePlugins.js b/static/compilePlugins.js index 7655232b6..39fb15208 100644 --- a/static/compilePlugins.js +++ b/static/compilePlugins.js @@ -11,6 +11,7 @@ const fs = require('fs'); const Metro = require('metro'); const util = require('util'); const recursiveReaddir = require('recursive-readdir'); +const expandTilde = require('expand-tilde'); const HOME_DIR = require('os').homedir(); /* eslint-disable prettier/prettier */ @@ -115,7 +116,7 @@ function pluginEntryPoints(additionalPaths = []) { return entryPoints; } function entryPointForPluginFolder(pluginPath) { - pluginPath = pluginPath.replace('~', HOME_DIR); + pluginPath = expandTilde(pluginPath); if (!fs.existsSync(pluginPath)) { return {}; } diff --git a/static/index.js b/static/index.js index 4d4188ca5..0385cfd34 100644 --- a/static/index.js +++ b/static/index.js @@ -16,6 +16,7 @@ const {exec} = require('child_process'); const compilePlugins = require('./compilePlugins.js'); const os = require('os'); const setup = require('./setup'); +const expandTilde = require('expand-tilde'); // disable electron security warnings: https://github.com/electron/electron/blob/master/docs/tutorial/security.md#security-native-capabilities-and-your-responsibility process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = true; @@ -42,7 +43,7 @@ const pluginPaths = config.pluginPaths path.join(__dirname, '..', 'src', 'plugins'), path.join(__dirname, '..', 'src', 'fb', 'plugins'), ) - .map(p => p.replace(/^~/, os.homedir())) + .map(expandTilde) .filter(fs.existsSync); process.env.CONFIG = JSON.stringify({