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({
|
await tar.list({
|
||||||
file: tarPath,
|
file: tarPath,
|
||||||
filter: path => path === filePath,
|
filter: entryPath => path.normalize(entryPath) === filePath,
|
||||||
onentry(entry: FileStat) {
|
onentry(entry: FileStat) {
|
||||||
entry.on("data", chunk => {
|
entry.on("data", chunk => {
|
||||||
fileChunks.push(chunk);
|
fileChunks.push(chunk);
|
||||||
@ -41,7 +41,9 @@ export async function listTarEntries(filePath: string): Promise<string[]> {
|
|||||||
const entries: string[] = [];
|
const entries: string[] = [];
|
||||||
await tar.list({
|
await tar.list({
|
||||||
file: filePath,
|
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;
|
return entries;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ interface ExtensionState {
|
|||||||
|
|
||||||
@observer
|
@observer
|
||||||
export class Extensions extends React.Component {
|
export class Extensions extends React.Component {
|
||||||
private supportedFormats = [".tar", ".tgz"];
|
private supportedFormats = ["tar", "tgz"];
|
||||||
|
|
||||||
private installPathValidator: InputValidator = {
|
private installPathValidator: InputValidator = {
|
||||||
message: <Trans>Invalid URL or absolute path</Trans>,
|
message: <Trans>Invalid URL or absolute path</Trans>,
|
||||||
@ -187,15 +187,17 @@ export class Extensions extends React.Component {
|
|||||||
await Promise.all(
|
await Promise.all(
|
||||||
requests
|
requests
|
||||||
.filter(req => !req.data && req.filePath)
|
.filter(req => !req.data && req.filePath)
|
||||||
.map(request => {
|
.map(async request => {
|
||||||
return fse.readFile(request.filePath).then(data => {
|
try {
|
||||||
|
const data = await fse.readFile(request.filePath);
|
||||||
request.data = data;
|
request.data = data;
|
||||||
preloadedRequests.push(request);
|
preloadedRequests.push(request);
|
||||||
}).catch(error => {
|
return request;
|
||||||
|
} catch(error) {
|
||||||
if (showError) {
|
if (showError) {
|
||||||
Notifications.error(`Error while reading "${request.filePath}": ${String(error)}`);
|
Notifications.error(`Error while reading "${request.filePath}": ${String(error)}`);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -206,7 +208,12 @@ export class Extensions extends React.Component {
|
|||||||
const tarFiles = await listTarEntries(filePath);
|
const tarFiles = await listTarEntries(filePath);
|
||||||
|
|
||||||
// tarball from npm contains single root folder "package/*"
|
// 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 packedInRootFolder = tarFiles.every(entry => entry.startsWith(rootFolder));
|
||||||
const manifestLocation = packedInRootFolder ? path.join(rootFolder, manifestFilename) : manifestFilename;
|
const manifestLocation = packedInRootFolder ? path.join(rootFolder, manifestFilename) : manifestFilename;
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user