Files
flipper/desktop/flipper-ui-core/src/utils/pathUtils.tsx
Michel Weststrate 129cbd6f7b Move changelog loading to server
Summary: per title

Reviewed By: aigoncharov

Differential Revision: D32723706

fbshipit-source-id: ce5108da9f5da6fdfa7d1a66a31a4f8f430eb78d
2021-12-08 04:30:56 -08:00

33 lines
1.1 KiB
TypeScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
// We use sync access once per startup.
/* eslint-disable node/no-sync */
import path from 'path';
import {getRenderHostInstance} from '../RenderHost';
/**
* @deprecated
*/
export function getStaticPath(
relativePath: string = '.',
{asarUnpacked}: {asarUnpacked: boolean} = {asarUnpacked: false},
) {
const staticDir = getRenderHostInstance().serverConfig.paths.staticPath;
const absolutePath = path.resolve(staticDir, relativePath);
// Unfortunately, path.resolve, fs.pathExists, fs.read etc do not automatically work with asarUnpacked files.
// All these functions still look for files in "app.asar" even if they are unpacked.
// Looks like automatic resolving for asarUnpacked files only work for "child_process" module.
// So we're using a hack here to actually look to "app.asar.unpacked" dir instead of app.asar package.
return asarUnpacked
? absolutePath.replace('app.asar', 'app.asar.unpacked')
: absolutePath;
}