From 4c64ab971b61ed61115dce8476ddb97d3a5cbbc9 Mon Sep 17 00:00:00 2001 From: Daniel Izdebski Date: Tue, 16 Jan 2024 11:29:57 +0100 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat(core):=20Add=20support=20for?= =?UTF-8?q?=20`.setup.mjs`=20files=20(#1072)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/cli/compileWalletSetupFunctions.ts | 4 ++-- packages/core/src/utils/getWalletSetupFiles.ts | 4 ++-- packages/core/src/utils/triggerCacheCreation.ts | 2 +- packages/core/test/utils/getWalletSetupFiles.test.ts | 9 +++++++-- packages/core/test/utils/triggerCacheCreation.test.ts | 2 +- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/core/src/cli/compileWalletSetupFunctions.ts b/packages/core/src/cli/compileWalletSetupFunctions.ts index c3f13bac5..45b00ab79 100644 --- a/packages/core/src/cli/compileWalletSetupFunctions.ts +++ b/packages/core/src/cli/compileWalletSetupFunctions.ts @@ -6,7 +6,7 @@ import { FIXES_BANNER } from './compilationFixes' const OUT_DIR_NAME = 'wallet-setup-dist' -const createGlobPattern = (walletSetupDir: string) => path.join(walletSetupDir, '**', '*.setup.{js,ts}') +const createGlobPattern = (walletSetupDir: string) => path.join(walletSetupDir, '**', '*.setup.{ts,js,mjs}') export async function compileWalletSetupFunctions(walletSetupDir: string, debug: boolean) { const outDir = path.join(ensureCacheDirExists(), OUT_DIR_NAME) @@ -24,7 +24,7 @@ export async function compileWalletSetupFunctions(walletSetupDir: string, debug: throw new Error( [ `No wallet setup files found at ${walletSetupDir}`, - 'Remember that all wallet setup files must end with `.setup.{js,ts}` extension!' + 'Remember that all wallet setup files must end with `.setup.{ts,js,mjs}` extension!' ].join('\n') ) } diff --git a/packages/core/src/utils/getWalletSetupFiles.ts b/packages/core/src/utils/getWalletSetupFiles.ts index ec153c4e8..41bd2f050 100644 --- a/packages/core/src/utils/getWalletSetupFiles.ts +++ b/packages/core/src/utils/getWalletSetupFiles.ts @@ -1,6 +1,6 @@ import fs from 'fs-extra' -const SETUP_FILE_FILTER_REGEX = /\.setup\.(js|ts)$/ +const SETUP_FILE_FILTER_REGEX = /\.setup\.(ts|js|mjs)$/ export async function getWalletSetupFiles(walletSetupDirPath: string) { await fs.access(walletSetupDirPath).catch((e) => { @@ -22,7 +22,7 @@ export async function getWalletSetupFiles(walletSetupDirPath: string) { throw new Error( [ `[GetWalletSetupFiles] No wallet setup files found at ${walletSetupDirPath}`, - 'Remember that all wallet setup files must end with `.setup.{js,ts}` extension!' + 'Remember that all wallet setup files must end with `.setup.{ts,js,mjs}` extension!' ].join('\n') ) } diff --git a/packages/core/src/utils/triggerCacheCreation.ts b/packages/core/src/utils/triggerCacheCreation.ts index 669115c17..d26ba2179 100644 --- a/packages/core/src/utils/triggerCacheCreation.ts +++ b/packages/core/src/utils/triggerCacheCreation.ts @@ -26,7 +26,7 @@ export async function triggerCacheCreation( await fs.remove(cachePath) } - const fileNameWithCorrectExtension = fileName.replace(/\.(js|ts)$/, '.{js,ts}') + const fileNameWithCorrectExtension = fileName.replace(/\.(ts|js|mjs)$/, '.{ts,js,mjs}') console.log(`Triggering cache creation for: ${funcHash} (${fileNameWithCorrectExtension})`) // We're not inferring the return type here to make sure we don't accidentally await the function. diff --git a/packages/core/test/utils/getWalletSetupFiles.test.ts b/packages/core/test/utils/getWalletSetupFiles.test.ts index b0e68957f..85fca2c4b 100644 --- a/packages/core/test/utils/getWalletSetupFiles.test.ts +++ b/packages/core/test/utils/getWalletSetupFiles.test.ts @@ -29,10 +29,14 @@ describe('getWalletSetupFiles', () => { await createFiles([ 'quack', 'quack.js', + 'quack.mjs', + 'quack.cjs', 'quack.ts', 'quack.tsx', 'quack.setup', 'quack.setup.js', + 'quack.setup.mjs', + 'quack.setup.cjs', 'quack.setup.ts', 'quack.setup.tsx' ]) @@ -66,8 +70,9 @@ describe('getWalletSetupFiles', () => { it('returns only valid setup files', async () => { const setupFiles = await getWalletSetupFiles(ROOT_DIR) - expect(setupFiles).toHaveLength(2) - expect(setupFiles).toContain('quack.setup.js') + expect(setupFiles).toHaveLength(3) expect(setupFiles).toContain('quack.setup.ts') + expect(setupFiles).toContain('quack.setup.js') + expect(setupFiles).toContain('quack.setup.mjs') }) }) diff --git a/packages/core/test/utils/triggerCacheCreation.test.ts b/packages/core/test/utils/triggerCacheCreation.test.ts index f25ed0fec..ed41eea7a 100644 --- a/packages/core/test/utils/triggerCacheCreation.test.ts +++ b/packages/core/test/utils/triggerCacheCreation.test.ts @@ -63,7 +63,7 @@ describe('triggerCacheCreation', () => { setupFunctions: ReturnType, hash: string ) { - const fileNameWithCorrectExtension = setupFunctions.get(hash)?.fileName?.replace(/\.(js|ts)$/, '.{js,ts}') + const fileNameWithCorrectExtension = setupFunctions.get(hash)?.fileName?.replace(/\.(ts|js|mjs)$/, '.{ts,js,mjs}') expect(createCacheForWalletSetupFunctionSpy).toHaveBeenNthCalledWith( n,