From 47d50bbe554c1ab78a62e8d6dbd2f26693ae467a Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Tue, 10 Sep 2024 17:37:30 -0700 Subject: [PATCH] fix: Add previously exported types back in --- src/asar.ts | 25 +++++++++++++++++++++++-- src/disk.ts | 25 ++++++++++++++++++++++--- src/filesystem.ts | 11 +++++++---- 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/src/asar.ts b/src/asar.ts index 2d1b5cb..6b380d2 100644 --- a/src/asar.ts +++ b/src/asar.ts @@ -2,7 +2,12 @@ import * as path from 'path'; import minimatch from 'minimatch'; import fs from './wrapped-fs'; -import { Filesystem, FilesystemEntry } from './filesystem'; +import { + Filesystem, + FilesystemDirectoryEntry, + FilesystemEntry, + FilesystemLinkEntry, +} from './filesystem'; import * as disk from './disk'; import { crawl as crawlFilesystem, determineFileType } from './crawlfs'; import { IOptions } from 'glob'; @@ -192,7 +197,11 @@ export function getRawHeader(archivePath: string) { return disk.readArchiveHeaderSync(archivePath); } -export function listPackage(archivePath: string, options: { isPack: boolean }) { +export interface ListOptions { + isPack: boolean; +} + +export function listPackage(archivePath: string, options: ListOptions) { return disk.readFilesystemSync(archivePath).listFiles(options); } @@ -272,6 +281,18 @@ export function uncacheAll() { disk.uncacheAll(); } +// Legacy type exports to maintain compatibility with pre-TypeScript rewrite +// (https://github.com/electron/asar/blob/50b0c62e5b24c3d164687e6470b8658e09b09eea/lib/index.d.ts) +// These don't match perfectly and are technically still a breaking change but they're close enough +// to keep _most_ build pipelines out there from breaking. +export { EntryMetadata } from './filesystem'; +export { InputMetadata, DirectoryRecord, FileRecord, ArchiveHeader } from './disk'; +export type InputMetadataType = 'directory' | 'file' | 'link'; +export type DirectoryMetadata = FilesystemDirectoryEntry; +export type FileMetadata = FilesystemEntry; +export type LinkMetadata = FilesystemLinkEntry; + +// Export everything in default, too export default { createPackage, createPackageWithOptions, diff --git a/src/disk.ts b/src/disk.ts index 57e2133..ecb7263 100644 --- a/src/disk.ts +++ b/src/disk.ts @@ -1,9 +1,8 @@ import * as path from 'path'; import fs from './wrapped-fs'; import { Pickle } from './pickle'; -import { Filesystem, FilesystemEntry, FilesystemFileEntry } from './filesystem'; +import { Filesystem, FilesystemFileEntry } from './filesystem'; import { CrawledFileType } from './crawlfs'; -import { Stats } from 'fs'; let filesystemCache: Record = Object.create(null); @@ -80,7 +79,27 @@ export async function writeFilesystem( return writeFileListToStream(dest, filesystem, out, fileList, metadata); } -export function readArchiveHeaderSync(archivePath: string) { +export interface FileRecord extends FilesystemFileEntry { + integrity: { + hash: string; + algorithm: 'SHA256'; + blocks: string[]; + blockSize: number; + }; +} + +export type DirectoryRecord = { + files: Record; +}; + +export type ArchiveHeader = { + // The JSON parsed header string + header: DirectoryRecord; + headerString: string; + headerSize: number; +}; + +export function readArchiveHeaderSync(archivePath: string): ArchiveHeader { const fd = fs.openSync(archivePath, 'r'); let size: number; let headerBuf: Buffer; diff --git a/src/filesystem.ts b/src/filesystem.ts index 577beea..c4d68d5 100644 --- a/src/filesystem.ts +++ b/src/filesystem.ts @@ -11,22 +11,25 @@ const UINT32_MAX = 2 ** 32 - 1; const pipeline = promisify(stream.pipeline); -export type FilesystemDirectoryEntry = { - files: Record; +export type EntryMetadata = { unpacked?: boolean; }; +export type FilesystemDirectoryEntry = { + files: Record; +} & EntryMetadata; + export type FilesystemFileEntry = { unpacked: boolean; executable: boolean; offset: string; size: number; integrity: FileIntegrity; -}; +} & EntryMetadata; export type FilesystemLinkEntry = { link: string; -}; +} & EntryMetadata; export type FilesystemEntry = FilesystemDirectoryEntry | FilesystemFileEntry | FilesystemLinkEntry;