mirror of
https://github.com/lensapp/lens.git
synced 2025-05-20 05:10:56 +00:00
Fix extensions installation on Windows (#1596)
* Fix extensions installation on Windows Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Get rid of readFileSync Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com> * Add missing semicolon Signed-off-by: Lauri Nevala <lauri.nevala@gmail.com>
This commit is contained in:
parent
06568fa232
commit
7b77f18376
@ -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;
|
||||
}
|
||||
|
||||
@ -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 = await fse.readFile(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;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user