From 57213eb6d64119681cb266008c63ea7ee75b9316 Mon Sep 17 00:00:00 2001 From: JrMasterModelBuilder Date: Tue, 10 Oct 2023 01:27:51 -0400 Subject: [PATCH] Unnecessary function --- src/bundle.ts | 12 +++++++----- src/util.ts | 18 ------------------ src/util/mac.ts | 36 ++++++++++++++++++++++-------------- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/src/bundle.ts b/src/bundle.ts index eabad8d..5fcc0b1 100644 --- a/src/bundle.ts +++ b/src/bundle.ts @@ -20,7 +20,6 @@ import { fsLstatExists } from '@shockpkg/archive-files'; -import {once} from './util'; import {Queue} from './queue'; import {Projector} from './projector'; @@ -506,15 +505,18 @@ export abstract class Bundle { }> ) { const r = {...options} as IBundleResourceOptions; - const st = once(stat); + let st; if (!r.atime && r.atimeCopy) { - r.atime = (await st()).atime; + st = await stat(); + r.atime = st.atime; } if (!r.mtime && r.mtimeCopy) { - r.mtime = (await st()).mtime; + st ??= await stat(); + r.mtime = st.mtime; } if (typeof r.executable !== 'boolean' && r.executableCopy) { - r.executable = this._getResourceModeExecutable((await st()).mode); + st ??= await stat(); + r.executable = this._getResourceModeExecutable(st.mode); } return r; } diff --git a/src/util.ts b/src/util.ts index 11e467e..0a6d98c 100644 --- a/src/util.ts +++ b/src/util.ts @@ -2,24 +2,6 @@ import {inflateRaw} from 'node:zlib'; import {LAUNCHERS} from './launchers'; -/** - * Create return value once. - * - * @param create Create function. - * @returns Returned value. - */ -export function once(create: () => T): () => T { - let called = false; - let value: T; - return () => { - if (!called) { - value = create(); - called = true; - } - return value; - }; -} - /** * Trim dot flash from head of path. * diff --git a/src/util/mac.ts b/src/util/mac.ts index eeaec0d..c53628a 100644 --- a/src/util/mac.ts +++ b/src/util/mac.ts @@ -2,7 +2,7 @@ import {readFile} from 'node:fs/promises'; import {Plist, Value, ValueDict, ValueString} from '@shockpkg/plist-dom'; -import {once, launcher} from '../util'; +import {launcher} from '../util'; const FAT_MAGIC = 0xcafebabe; const MH_MAGIC = 0xfeedface; @@ -15,16 +15,6 @@ const CPU_TYPE_POWERPC = 0x00000012; const CPU_TYPE_I386 = 0x00000007; // const CPU_TYPE_X86_64 = 0x01000007; -const launcherMappings = once( - () => - new Map([ - [CPU_TYPE_POWERPC, 'mac-app-ppc'], - // [CPU_TYPE_POWERPC64, 'mac-app-ppc64'], - [CPU_TYPE_I386, 'mac-app-i386'] - // [CPU_TYPE_X86_64, 'mac-app-x86_64'] - ]) -); - export interface IMachoType { // /** @@ -239,9 +229,27 @@ export async function machoTypesFile(path: string) { */ export async function machoAppLauncherThin(type: Readonly) { const {cpuType} = type; - const id = launcherMappings().get(cpuType); - if (!id) { - throw new Error(`Unknown CPU type: 0x${cpuType.toString(16)}`); + let id = ''; + switch (cpuType) { + case CPU_TYPE_POWERPC: { + id = 'mac-app-ppc'; + break; + } + // case CPU_TYPE_POWERPC64: { + // id = 'mac-app-ppc64'; + // break; + // } + case CPU_TYPE_I386: { + id = 'mac-app-i386'; + break; + } + // case CPU_TYPE_X86_64: { + // id = 'mac-app-x86_64'; + // break; + // } + default: { + throw new Error(`Unknown CPU type: 0x${cpuType.toString(16)}`); + } } return launcher(id); }