@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
86 lines • 5.22 kB
TypeScript
import * as fs from 'fs';
import { interfaces } from 'inversify';
import { EnvVariablesServer } from '../common/env-variables/index.js';
import { ILogger } from '../common/logger.js';
import { FileSystemLocking } from './filesystem-locking.js';
export declare const BundledResourceProvider: symbol & interfaces.Abstract<BundledResourceProvider>;
/**
* Provides paths to resources that are bundled with the application, in a form that can also be used by
* processes which do not run inside the application, such as shells, debug adapters or other external tools.
*
* When an Electron application is packaged with `asar: true`, the resources of the application are stored in
* an `app.asar` archive. Paths pointing into such an archive can only be read through Electron's patched `fs`
* module, so handing them to an external process fails. Therefore, always resolve a bundled resource through
* this service before passing its path to a process outside of the application.
*/
export interface BundledResourceProvider {
/**
* Resolve the given path of a bundled file or directory to a path that external processes can read.
*
* If the resource is not packaged into an archive, its path is returned unchanged. Otherwise the copy that
* the packaging step has left outside of the archive is used, if it is complete, and the resource is
* extracted from the archive into the configuration directory as a last resort.
*
* Results are cached, so that a resource is extracted at most once per application version.
*
* @param resourcePath the path of the bundled resource, typically resolved against `__dirname`.
* @returns the path to use outside of the application.
* @throws if the resource does not exist or cannot be made available.
*/
resolveExternalPath(resourcePath: string): Promise<string>;
}
export declare class BundledResourceProviderImpl implements BundledResourceProvider {
protected readonly logger: ILogger;
protected readonly envVariablesServer: EnvVariablesServer;
protected readonly fileSystemLocking: FileSystemLocking;
/** The folder within the configuration directory into which resources are extracted. */
protected readonly extractionFolder = "bundled-resources";
/** Resources extracted for another application version are removed when they are older than this. */
protected readonly staleExtractionAge: number;
protected readonly resolved: Map<string, Promise<string>>;
protected temporaryExtractionPath: Promise<string> | undefined;
resolveExternalPath(resourcePath: string): Promise<string>;
protected doResolveExternalPath(resourcePath: string): Promise<string>;
/**
* Find the archive that the given resource is packaged into, if any.
*
* @returns the path of the archive, i.e. the shortest prefix of the given path ending in an `.asar` segment,
* which is also how Electron itself determines the archive that a path refers to.
*/
protected findArchivePath(resourcePath: string): string | undefined;
/**
* Whether every file of the given resource is already available at the given target path. Packaging tools
* only unpack the files that the application configured them to unpack, so a partial copy must be ignored.
*/
protected isExtracted(resourcePath: string, targetPath: string): Promise<boolean>;
protected extract(resourcePath: string, targetPath: string): Promise<void>;
/**
* Collect the files of the given resource as paths relative to it. The relative path of a resource that is
* a plain file is the empty string.
*/
protected collectFiles(resourcePath: string, relativePath?: string): Promise<string[]>;
protected copyFile(sourcePath: string, targetPath: string): Promise<void>;
protected isUpToDate(targetPath: string, sourceStat: fs.Stats): Promise<boolean>;
/**
* The directory into which resources of the given archive are extracted. It is specific to the content of
* the archive, so that updating the application invalidates previously extracted copies.
*/
protected getExtractionPath(archivePath: string): Promise<string>;
/**
* Fallback for applications whose configuration directory cannot be written to. The directory is unique to
* this run of the application, so that resources are extracted again whenever the application is started.
*/
protected getTemporaryExtractionPath(): Promise<string>;
/**
* Identify the content of the given archive. `process.noAsar` is toggled around the synchronous `stat` call
* to get the stats of the archive file itself rather than of the directory that it appears as.
*/
protected getArchiveStamp(archivePath: string): string;
/**
* Remove resources that were extracted from an earlier version of the archive, unless they were used
* recently, because another application instance may still be running on that version.
*/
protected removeStaleExtractions(extractionRoot: string, prefix: string, currentPath: string): void;
protected exists(targetPath: string): Promise<boolean>;
}
//# sourceMappingURL=bundled-resource-provider.d.ts.map