Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jul 3, 2024
2 parents 85931c2 + 03230f2 commit 85ad59b
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
21 changes: 7 additions & 14 deletions packages/cache/src/cli/compileWalletSetupFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from 'node:path'
import path, { posix, win32 } from 'node:path'
import { glob } from 'glob'
import { build } from 'tsup'
import { ensureCacheDirExists } from '../ensureCacheDirExists'
Expand All @@ -16,7 +16,7 @@ export async function compileWalletSetupFunctions(
const globPattern = path.join(walletSetupDir, '**', '*.setup.{ts,js,mjs}');

// Use glob to find files, ensuring proper path handling
const fileList = await glob(globPattern, { absolute: true, windowsPathsNoEscape: true });
const fileList: string[] = await glob(globPattern, { absolute: false, windowsPathsNoEscape: true });

if (debug) {
console.log('[DEBUG] Found the following wallet setup files:');
Expand All @@ -32,23 +32,16 @@ export async function compileWalletSetupFunctions(
].join('\n')
);
}
// TODO: This error message is copied over from another function. Refactor this.
if (!fileList.length) {
throw new Error(
[
`No wallet setup files found at ${walletSetupDir}`,
'Remember that all wallet setup files must end with `.setup.{ts,js,mjs}` extension!'
].join('\n')
)
}


const normalized = fileList.map((file) => {
return file.split(win32.sep).join(posix.sep)
})

try {
await build({
name: 'cli-build',
silent: true,
entry: fileList,
entry: normalized,
clean: true,
outDir,
format: 'esm',
Expand All @@ -67,7 +60,7 @@ export async function compileWalletSetupFunctions(
}
})
} catch (e) {
console.log(e)
console.log('error within compile', e)
}
return outDir
}
3 changes: 0 additions & 3 deletions packages/cache/src/createCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import { triggerCacheCreation } from './utils/triggerCacheCreation'

export async function createCache(walletSetupDirPath: string, downloadExtension: () => Promise<string>, force = false) {
const setupFunctions = await getUniqueWalletSetupFunctions(walletSetupDirPath)

const cacheCreationPromises = await triggerCacheCreation(setupFunctions, downloadExtension, force)

if (cacheCreationPromises.length === 0) {
console.log('No new setup functions to cache. Exiting...')
return
}

// TODO: This line has no unit test. Not sure how to do it. Look into it later.
await Promise.all(cacheCreationPromises)

Expand Down
1 change: 0 additions & 1 deletion packages/cache/src/utils/getWalletSetupFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@ export async function getWalletSetupFiles(walletSetupDirPath: string) {
].join('\n')
)
}

return fileList
}
4 changes: 2 additions & 2 deletions packages/cache/src/utils/importWalletSetupFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const WalletSetupModule = z.object({
})

export async function importWalletSetupFile(walletSetupFilePath: string) {
const walletSetupModule = await import(walletSetupFilePath)

const fileToImport = process.platform === 'win32' ? 'file:\\\\\\' + walletSetupFilePath : walletSetupFilePath
const walletSetupModule = await import(fileToImport)
const result = WalletSetupModule.safeParse(walletSetupModule)
if (!result.success) {
throw new Error(
Expand Down

0 comments on commit 85ad59b

Please sign in to comment.