1
0
mirror of https://github.com/lensapp/lens.git synced 2025-05-20 05:10:56 +00:00

Fix extensions installation on Windows

Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
Lauri Nevala 2020-12-01 16:04:52 +02:00
parent 4161ee832c
commit b8ca4add53
3 changed files with 19 additions and 10 deletions

View File

@ -15,7 +15,7 @@ export function readFileFromTar<R = Buffer>({ tarPath, filePath, parseJson }: Re
await tar.list({
file: tarPath,
filter: path => path === filePath,
filter: entryPath => path.normalize(entryPath) === filePath,
onentry(entry: FileStat) {
entry.on("data", chunk => {
fileChunks.push(chunk);
@ -41,7 +41,9 @@ export async function listTarEntries(filePath: string): Promise<string[]> {
const entries: string[] = [];
await tar.list({
file: filePath,
onentry: (entry: FileStat) => entries.push(entry.path as any as string),
onentry: (entry: FileStat) => {
entries.push(path.normalize(entry.path as any as string))
},
});
return entries;
}

View File

@ -114,7 +114,7 @@ export class ExtensionDiscovery {
// chokidar works better than fs.watch
chokidar.watch(this.localFolderPath, {
// Dont watch recursively into subdirectories
depth: 0,
depth: 1,
// Try to wait until the file has been completely copied.
// The OS might emit an event for added file even it's not completely written to the filesysten.
awaitWriteFinish: {
@ -189,7 +189,7 @@ export class ExtensionDiscovery {
*/
async uninstallExtension(absolutePath: string) {
logger.info(`${logModule} Uninstalling ${absolutePath}`);
const exists = await fs.pathExists(absolutePath);
if (!exists) {

View File

@ -47,7 +47,7 @@ interface ExtensionState {
@observer
export class Extensions extends React.Component {
private supportedFormats = [".tar", ".tgz"];
private supportedFormats = ["tar", "tgz"];
private installPathValidator: InputValidator = {
message: <Trans>Invalid URL or absolute path</Trans>,
@ -187,15 +187,17 @@ export class Extensions extends React.Component {
await Promise.all(
requests
.filter(req => !req.data && req.filePath)
.map(request => {
return fse.readFile(request.filePath).then(data => {
.map(async request => {
try {
const data = fse.readFileSync(request.filePath);
request.data = data;
preloadedRequests.push(request);
}).catch(error => {
return request;
} catch(error) {
if (showError) {
Notifications.error(`Error while reading "${request.filePath}": ${String(error)}`);
}
});
};
})
);
@ -206,7 +208,12 @@ export class Extensions extends React.Component {
const tarFiles = await listTarEntries(filePath);
// tarball from npm contains single root folder "package/*"
const rootFolder = tarFiles[0].split("/")[0];
const firstFile = tarFiles[0];
if (!firstFile) {
throw new Error(`invalid extension bundle, ${manifestFilename} not found`);
}
const rootFolder = path.normalize(firstFile).split(path.sep)[0];
const packedInRootFolder = tarFiles.every(entry => entry.startsWith(rootFolder));
const manifestLocation = packedInRootFolder ? path.join(rootFolder, manifestFilename) : manifestFilename;