Skip to content

Commit

Permalink
refactor(archive,async,cli,csv,dotenv,encoding,expect,fmt,front-matte…
Browse files Browse the repository at this point in the history
…r,fs,http,internal,log,net,path,semver,testing,text,webgpu,yaml): enable `"exactOptionalPropertyTypes"` option (#5892)
  • Loading branch information
petamoriken authored Sep 4, 2024
1 parent 6aaf191 commit 4d4bd0e
Show file tree
Hide file tree
Showing 52 changed files with 403 additions and 272 deletions.
26 changes: 16 additions & 10 deletions archive/tar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const USTAR_MAGIC_HEADER = "ustar\u000000" as const;
* Simple file reader
*/
class FileReader implements Reader {
#file?: Deno.FsFile;
#file: Deno.FsFile | undefined;
#filePath: string;

constructor(filePath: string) {
Expand Down Expand Up @@ -112,7 +112,7 @@ function formatHeader(data: TarData): Uint8Array {
const buffer = new Uint8Array(HEADER_LENGTH);
let offset = 0;
for (const { field, length } of USTAR_STRUCTURE) {
const entry = encoder.encode(data[field as keyof TarData] || "");
const entry = encoder.encode(data[field as keyof TarData] ?? "");
buffer.set(entry, offset);
offset += length;
}
Expand Down Expand Up @@ -334,7 +334,7 @@ export class Tar {
}
}

source = source || {};
source = source ?? {};

// set meta data
let info: Deno.FileInfo | undefined;
Expand All @@ -351,8 +351,8 @@ export class Tar {
const mtime = Math.floor(
source.mtime ?? (info?.mtime ?? new Date()).valueOf() / 1000,
);
const uid = source.uid || 0;
const gid = source.gid || 0;
const uid = source.uid ?? 0;
const gid = source.gid ?? 0;

if (typeof source.owner === "string" && source.owner.length >= 32) {
throw new Error(
Expand All @@ -375,7 +375,6 @@ export class Tar {
: (info?.isDirectory ? FileTypes.directory : FileTypes.file);
const tarData: TarDataWithSource = {
fileName,
fileNamePrefix,
fileMode: pad(mode, 7),
uid: pad(uid, 7),
gid: pad(gid, 7),
Expand All @@ -384,11 +383,18 @@ export class Tar {
checksum: " ",
type: type.toString(),
ustar: USTAR_MAGIC_HEADER,
owner: source.owner || "",
group: source.group || "",
filePath: source.filePath,
reader: source.reader,
owner: source.owner ?? "",
group: source.group ?? "",
};
if (fileNamePrefix !== undefined) {
tarData.fileNamePrefix = fileNamePrefix;
}
if (source.filePath !== undefined) {
tarData.filePath = source.filePath;
}
if (source.reader !== undefined) {
tarData.reader = source.reader;
}

// calculate the checksum
let checksum = 0;
Expand Down
8 changes: 5 additions & 3 deletions archive/untar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export class TarEntry implements Reader {
this.#reader = reader;

// File Size
this.#size = this.fileSize || 0;
this.#size = this.fileSize ?? 0;
// Entry Size
const blocks = Math.ceil(this.#size / HEADER_LENGTH);
this.#entrySize = blocks * HEADER_LENGTH;
Expand Down Expand Up @@ -259,7 +259,7 @@ export class TarEntry implements Reader {
const n = await readBlock(this.#reader, block);
const bytesLeft = this.#size - this.#read;

this.#read += n || 0;
this.#read += n ?? 0;
if (n === null || bytesLeft <= 0) {
if (n === null) this.#consumed = true;
return null;
Expand Down Expand Up @@ -449,7 +449,9 @@ export class Untar {
});

meta.fileSize = parseInt(decoder.decode(header.fileSize), 8);
meta.type = FileTypes[parseInt(meta.type!)] ?? meta.type;
if (meta.type !== undefined) {
meta.type = FileTypes[parseInt(meta.type!)] ?? meta.type;
}

// Only create the `linkName` property for symbolic links to minimize
// the effect on existing code that only deals with non-links.
Expand Down
15 changes: 8 additions & 7 deletions archive/untar_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,16 @@ export class UntarStream
};
}

yield {
path: ("prefix" in header && header.prefix.length
? header.prefix + "/"
: "") + header.name,
const entry: TarStreamEntry = {
path: (
"prefix" in header && header.prefix.length ? header.prefix + "/" : ""
) + header.name,
header,
readable: ["1", "2", "3", "4", "5", "6"].includes(header.typeflag)
? undefined
: this.#readableFile(header.size),
};
if (!["1", "2", "3", "4", "5", "6"].includes(header.typeflag)) {
entry.readable = this.#readableFile(header.size);
}
yield entry;
}
}

Expand Down
2 changes: 1 addition & 1 deletion archive/untar_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ async function createTar(entries: TestEntry[]): Promise<Tar> {
contentSize: file.content.byteLength,
};
} else {
options = { filePath: file.filePath };
options = { filePath: file.filePath! };
}

await tar.append(file.name, options);
Expand Down
1 change: 1 addition & 0 deletions async/retry_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Deno.test("retry() fails after five errors by default", async () => {
Deno.test("retry() fails after five errors when undefined is passed", async () => {
const fiveErrors = generateErroringFunction(5);
await assertRejects(() =>
// @ts-expect-error: explicitly giving undefined
retry(fiveErrors, {
maxAttempts: undefined,
minTimeout: 100,
Expand Down
Loading

0 comments on commit 4d4bd0e

Please sign in to comment.