Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add previously exported types back in #326

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/asar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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,
Expand Down
25 changes: 22 additions & 3 deletions src/disk.ts
Original file line number Diff line number Diff line change
@@ -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<string, Filesystem | undefined> = Object.create(null);

Expand Down Expand Up @@ -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<string, DirectoryRecord | FileRecord>;
};

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;
Expand Down
11 changes: 7 additions & 4 deletions src/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ const UINT32_MAX = 2 ** 32 - 1;

const pipeline = promisify(stream.pipeline);

export type FilesystemDirectoryEntry = {
files: Record<string, FilesystemEntry>;
export type EntryMetadata = {
unpacked?: boolean;
};

export type FilesystemDirectoryEntry = {
files: Record<string, FilesystemEntry>;
} & 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;

Expand Down