Skip to content

Commit baf479c

Browse files
author
Felix Rieseberg
authored
fix: Add previously exported types back in (#326)
1 parent 06312cd commit baf479c

File tree

3 files changed

+52
-9
lines changed

3 files changed

+52
-9
lines changed

src/asar.ts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@ import * as path from 'path';
22
import minimatch from 'minimatch';
33

44
import fs from './wrapped-fs';
5-
import { Filesystem, FilesystemEntry } from './filesystem';
5+
import {
6+
Filesystem,
7+
FilesystemDirectoryEntry,
8+
FilesystemEntry,
9+
FilesystemLinkEntry,
10+
} from './filesystem';
611
import * as disk from './disk';
712
import { crawl as crawlFilesystem, determineFileType } from './crawlfs';
813
import { IOptions } from 'glob';
@@ -192,7 +197,11 @@ export function getRawHeader(archivePath: string) {
192197
return disk.readArchiveHeaderSync(archivePath);
193198
}
194199

195-
export function listPackage(archivePath: string, options: { isPack: boolean }) {
200+
export interface ListOptions {
201+
isPack: boolean;
202+
}
203+
204+
export function listPackage(archivePath: string, options: ListOptions) {
196205
return disk.readFilesystemSync(archivePath).listFiles(options);
197206
}
198207

@@ -272,6 +281,18 @@ export function uncacheAll() {
272281
disk.uncacheAll();
273282
}
274283

284+
// Legacy type exports to maintain compatibility with pre-TypeScript rewrite
285+
// (https://github.com/electron/asar/blob/50b0c62e5b24c3d164687e6470b8658e09b09eea/lib/index.d.ts)
286+
// These don't match perfectly and are technically still a breaking change but they're close enough
287+
// to keep _most_ build pipelines out there from breaking.
288+
export { EntryMetadata } from './filesystem';
289+
export { InputMetadata, DirectoryRecord, FileRecord, ArchiveHeader } from './disk';
290+
export type InputMetadataType = 'directory' | 'file' | 'link';
291+
export type DirectoryMetadata = FilesystemDirectoryEntry;
292+
export type FileMetadata = FilesystemEntry;
293+
export type LinkMetadata = FilesystemLinkEntry;
294+
295+
// Export everything in default, too
275296
export default {
276297
createPackage,
277298
createPackageWithOptions,

src/disk.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import * as path from 'path';
22
import fs from './wrapped-fs';
33
import { Pickle } from './pickle';
4-
import { Filesystem, FilesystemEntry, FilesystemFileEntry } from './filesystem';
4+
import { Filesystem, FilesystemFileEntry } from './filesystem';
55
import { CrawledFileType } from './crawlfs';
6-
import { Stats } from 'fs';
76

87
let filesystemCache: Record<string, Filesystem | undefined> = Object.create(null);
98

@@ -80,7 +79,27 @@ export async function writeFilesystem(
8079
return writeFileListToStream(dest, filesystem, out, fileList, metadata);
8180
}
8281

83-
export function readArchiveHeaderSync(archivePath: string) {
82+
export interface FileRecord extends FilesystemFileEntry {
83+
integrity: {
84+
hash: string;
85+
algorithm: 'SHA256';
86+
blocks: string[];
87+
blockSize: number;
88+
};
89+
}
90+
91+
export type DirectoryRecord = {
92+
files: Record<string, DirectoryRecord | FileRecord>;
93+
};
94+
95+
export type ArchiveHeader = {
96+
// The JSON parsed header string
97+
header: DirectoryRecord;
98+
headerString: string;
99+
headerSize: number;
100+
};
101+
102+
export function readArchiveHeaderSync(archivePath: string): ArchiveHeader {
84103
const fd = fs.openSync(archivePath, 'r');
85104
let size: number;
86105
let headerBuf: Buffer;

src/filesystem.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,25 @@ const UINT32_MAX = 2 ** 32 - 1;
1111

1212
const pipeline = promisify(stream.pipeline);
1313

14-
export type FilesystemDirectoryEntry = {
15-
files: Record<string, FilesystemEntry>;
14+
export type EntryMetadata = {
1615
unpacked?: boolean;
1716
};
1817

18+
export type FilesystemDirectoryEntry = {
19+
files: Record<string, FilesystemEntry>;
20+
} & EntryMetadata;
21+
1922
export type FilesystemFileEntry = {
2023
unpacked: boolean;
2124
executable: boolean;
2225
offset: string;
2326
size: number;
2427
integrity: FileIntegrity;
25-
};
28+
} & EntryMetadata;
2629

2730
export type FilesystemLinkEntry = {
2831
link: string;
29-
};
32+
} & EntryMetadata;
3033

3134
export type FilesystemEntry = FilesystemDirectoryEntry | FilesystemFileEntry | FilesystemLinkEntry;
3235

0 commit comments

Comments
 (0)