Skip to content

Commit

Permalink
➖ chore(core): Remove ts-import dependency (#971)
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception authored Oct 31, 2023
1 parent a3c1a72 commit 14b3766
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 72 deletions.
1 change: 0 additions & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"esbuild": "^0.19.5",
"fs-extra": "^11.1.1",
"gradient-string": "^2.0.2",
"ts-import": "5.0.0-beta.0",
"unzipper": "^0.10.14",
"zod": "^3.22.4"
},
Expand Down
16 changes: 1 addition & 15 deletions packages/core/src/utils/importWalletSetupFile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import path from 'node:path'
import * as tsImport from 'ts-import'
import { z } from 'zod'
import type { WalletSetupFunction } from '../defineWalletSetup'
import { ensureCacheDirExists } from '../ensureCacheDirExists'

// TODO: Add hash length validation.
const WalletSetupModule = z.object({
Expand All @@ -12,19 +9,8 @@ const WalletSetupModule = z.object({
})
})

const TS_IMPORT_CACHE_DIR = path.join(ensureCacheDirExists(), '.cache-ts-import')

export async function importWalletSetupFile(walletSetupFilePath: string) {
// TODO: We should write our version of `ts-import` that utilizes the same logic as `getWalletSetupFuncHash`.
// Note: This might not work correctly on Windows!
const walletSetupModule = await tsImport.load(walletSetupFilePath, {
useCache: false, // TODO: This option does not work :(
transpileOptions: {
cache: {
dir: TS_IMPORT_CACHE_DIR
}
}
})
const walletSetupModule = await import(walletSetupFilePath)

const result = WalletSetupModule.safeParse(walletSetupModule)
if (!result.success) {
Expand Down
26 changes: 0 additions & 26 deletions packages/core/test/utils/importWalletSetupFile.test.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
import path from 'node:path'
import * as tsImport from 'ts-import'
import { afterAll, describe, expect, it, vi } from 'vitest'
import { importWalletSetupFile } from '../../src/utils/importWalletSetupFile'

vi.mock('ts-import', async () => {
return {
load: async (tsRelativePath: string) => {
return await import(tsRelativePath)
}
}
})

vi.mock('../../src/ensureCacheDirExists', async () => {
return {
ensureCacheDirExists: vi.fn(() => '/tmp')
Expand Down Expand Up @@ -56,22 +46,6 @@ describe('importWalletSetupFile', () => {
)
})

it('calls tsImport.load with correct arguments', async () => {
const loadSpy = vi.spyOn(tsImport, 'load')

const validFilePath = './valid.setup.ts'
await importWalletSetupFile(validFilePath)

expect(loadSpy).toHaveBeenCalledWith(validFilePath, {
useCache: false,
transpileOptions: {
cache: {
dir: path.join('/tmp', '.cache-ts-import')
}
}
})
})

it('returns the hash and function of a valid wallet setup file', async () => {
const validFilePath = './valid.setup.ts'
const result = await importWalletSetupFile(validFilePath)
Expand Down
37 changes: 7 additions & 30 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14b3766

Please sign in to comment.