diff --git a/packages/cache/package.json b/packages/cache/package.json index c06037c4c..beaee8274 100644 --- a/packages/cache/package.json +++ b/packages/cache/package.json @@ -29,6 +29,7 @@ "types:check": "tsc --noEmit" }, "dependencies": { + "app-root-path": "3.1.0", "axios": "1.6.7", "chalk": "5.3.0", "commander": "12.0.0", diff --git a/packages/cache/src/cli/cliEntrypoint.ts b/packages/cache/src/cli/cliEntrypoint.ts index 9851573f4..934234764 100644 --- a/packages/cache/src/cli/cliEntrypoint.ts +++ b/packages/cache/src/cli/cliEntrypoint.ts @@ -1,4 +1,3 @@ -import os from 'node:os' import path from 'node:path' import chalk from 'chalk' import { Command } from 'commander' @@ -50,18 +49,6 @@ export const cliEntrypoint = async () => { console.log({ cacheDir: walletSetupDir, ...flags, headless: Boolean(process.env.HEADLESS) ?? false }, '\n') } - if (os.platform() === 'win32') { - console.log( - [ - chalk.redBright('🚨 Sorry, Windows is currently not supported. Please use WSL instead! 🚨'), - chalk.gray( - 'If you want to give it a crack over a hot cup of coffee and add Windows support yourself, please get in touch with the team on Discord so we can offer some guidance! 😇' - ) - ].join('\n') - ) - process.exit(1) - } - const compiledWalletSetupDirPath = await compileWalletSetupFunctions(walletSetupDir, flags.debug) // TODO: We should be using `prepareExtension` function from the wallet itself! diff --git a/packages/cache/src/cli/compileWalletSetupFunctions.ts b/packages/cache/src/cli/compileWalletSetupFunctions.ts index 45b00ab79..4c366edb2 100644 --- a/packages/cache/src/cli/compileWalletSetupFunctions.ts +++ b/packages/cache/src/cli/compileWalletSetupFunctions.ts @@ -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' @@ -6,13 +6,14 @@ import { FIXES_BANNER } from './compilationFixes' const OUT_DIR_NAME = 'wallet-setup-dist' -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) - const globPattern = createGlobPattern(walletSetupDir) - const fileList = await glob(globPattern) + // Use a normalized glob pattern + const globPattern = path.join(walletSetupDir, '**', '*.setup.{ts,js,mjs}') + + // Use glob to find files, ensuring proper path handling + const fileList: string[] = await glob(globPattern, { absolute: false, windowsPathsNoEscape: true }) if (debug) { console.log('[DEBUG] Found the following wallet setup files:') @@ -29,27 +30,34 @@ export async function compileWalletSetupFunctions(walletSetupDir: string, debug: ) } - await build({ - name: 'cli-build', - silent: true, - entry: fileList, - clean: true, - outDir, - format: 'esm', - splitting: true, - sourcemap: false, - config: false, - // TODO: Make this list configurable. - external: ['@synthetixio/synpress', '@playwright/test', 'playwright-core', 'esbuild', 'tsup'], - banner: { - js: FIXES_BANNER - }, - esbuildOptions(options) { - // TODO: In this step, if the debug file is present, we should modify `console.log` so it prints from which file the log is coming from. - // We're dropping `console.log` and `debugger` statements because they do not play nicely with the Playwright Test Runner. - options.drop = debug ? [] : ['console', 'debugger'] - } + const normalized = fileList.map((file) => { + return file.split(win32.sep).join(posix.sep) }) + try { + await build({ + name: 'cli-build', + silent: true, + entry: normalized, + clean: true, + outDir, + format: 'esm', + splitting: true, + sourcemap: false, + config: false, + // TODO: Make this list configurable. + external: ['@synthetixio/synpress', '@playwright/test', 'playwright-core', 'esbuild', 'tsup'], + banner: { + js: FIXES_BANNER + }, + esbuildOptions(options) { + // TODO: In this step, if the debug file is present, we should modify `console.log` so it prints from which file the log is coming from. + // We're dropping `console.log` and `debugger` statements because they do not play nicely with the Playwright Test Runner. + options.drop = debug ? [] : ['console', 'debugger'] + } + }) + } catch (e) { + console.log('error within compile', e) + } return outDir } diff --git a/packages/cache/src/createCache.ts b/packages/cache/src/createCache.ts index 90ee2b550..d0c16effc 100644 --- a/packages/cache/src/createCache.ts +++ b/packages/cache/src/createCache.ts @@ -3,14 +3,11 @@ import { triggerCacheCreation } from './utils/triggerCacheCreation' export async function createCache(walletSetupDirPath: string, downloadExtension: () => Promise, 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) diff --git a/packages/cache/src/utils/getWalletSetupFiles.ts b/packages/cache/src/utils/getWalletSetupFiles.ts index 41bd2f050..ccd6c8029 100644 --- a/packages/cache/src/utils/getWalletSetupFiles.ts +++ b/packages/cache/src/utils/getWalletSetupFiles.ts @@ -26,6 +26,5 @@ export async function getWalletSetupFiles(walletSetupDirPath: string) { ].join('\n') ) } - return fileList } diff --git a/packages/cache/src/utils/importWalletSetupFile.ts b/packages/cache/src/utils/importWalletSetupFile.ts index 498e86e65..ebae4ab90 100644 --- a/packages/cache/src/utils/importWalletSetupFile.ts +++ b/packages/cache/src/utils/importWalletSetupFile.ts @@ -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( diff --git a/packages/core/package.json b/packages/core/package.json index 332b9c4d0..0572ccc26 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -25,7 +25,7 @@ "types:check": "tsc --noEmit" }, "devDependencies": { - "@synthetixio/synpress-tsconfig": "0.0.1-alpha.7", + "@synthetixio/synpress-tsconfig": "workspace:*", "@types/node": "20.11.17", "rimraf": "5.0.5", "tsup": "8.0.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 10d809f51..9c7aac291 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -90,6 +90,9 @@ importers: packages/cache: dependencies: + app-root-path: + specifier: 3.1.0 + version: 3.1.0 axios: specifier: 1.6.7 version: 1.6.7 @@ -177,7 +180,7 @@ importers: version: 1.44.0 devDependencies: '@synthetixio/synpress-tsconfig': - specifier: 0.0.1-alpha.7 + specifier: workspace:* version: link:../tsconfig '@types/node': specifier: 20.11.17 @@ -203,10 +206,10 @@ importers: specifier: 0.0.1-alpha.7 version: link:../wallets/ethereum-wallet-mock '@synthetixio/synpress-cache': - specifier: 0.0.1-alpha.7 + specifier: workspace:* version: link:../packages/cache '@synthetixio/synpress-core': - specifier: 0.0.1-alpha.7 + specifier: workspace:* version: link:../packages/core '@synthetixio/synpress-metamask': specifier: 0.0.1-alpha.7 @@ -277,10 +280,10 @@ importers: specifier: 1.44.0 version: 1.44.0 '@synthetixio/synpress-cache': - specifier: 0.0.1-alpha.7 + specifier: workspace:* version: link:../../packages/cache '@synthetixio/synpress-core': - specifier: 0.0.1-alpha.7 + specifier: workspace:* version: link:../../packages/core '@viem/anvil': specifier: 0.0.7 @@ -2929,6 +2932,11 @@ packages: normalize-path: 3.0.0 picomatch: 2.3.1 + /app-root-path@3.1.0: + resolution: {integrity: sha512-biN3PwB2gUtjaYy/isrU3aNWI5w+fAfvHkSvCKeQGxhmYpwKFUxudR3Yya+KqVRHBmEDYh+/lTozYCFbmzX4nA==} + engines: {node: '>= 6.0.0'} + dev: false + /aproba@2.0.0: resolution: {integrity: sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==} dev: true diff --git a/release/package.json b/release/package.json index 6bb538a29..efd4295e2 100644 --- a/release/package.json +++ b/release/package.json @@ -39,8 +39,8 @@ }, "dependencies": { "@synthetixio/ethereum-wallet-mock": "0.0.1-alpha.7", - "@synthetixio/synpress-cache": "0.0.1-alpha.7", - "@synthetixio/synpress-core": "0.0.1-alpha.7", + "@synthetixio/synpress-cache": "workspace:*", + "@synthetixio/synpress-core": "workspace:*", "@synthetixio/synpress-metamask": "0.0.1-alpha.7" }, "devDependencies": { diff --git a/wallets/metamask/package.json b/wallets/metamask/package.json index d9b2eed90..23d7c826e 100644 --- a/wallets/metamask/package.json +++ b/wallets/metamask/package.json @@ -30,8 +30,8 @@ "types:check": "tsc --noEmit" }, "dependencies": { - "@synthetixio/synpress-cache": "0.0.1-alpha.7", - "@synthetixio/synpress-core": "0.0.1-alpha.7", + "@synthetixio/synpress-cache": "workspace:*", + "@synthetixio/synpress-core": "workspace:*", "@viem/anvil": "0.0.7", "fs-extra": "11.2.0", "zod": "3.22.4" diff --git a/wallets/metamask/test/wallet-setup/basic.setup.d.ts b/wallets/metamask/test/wallet-setup/basic.setup.d.ts deleted file mode 100644 index 1bc70ea7c..000000000 --- a/wallets/metamask/test/wallet-setup/basic.setup.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -export declare const SEED_PHRASE = 'test test test test test test test test test test test junk' -export declare const PASSWORD = 'Tester@1234' -declare const _default: { - hash: string - fn: import('@synthetixio/synpress-cache').WalletSetupFunction - walletPassword: string -} -export default _default -//# sourceMappingURL=basic.setup.d.ts.map diff --git a/wallets/metamask/test/wallet-setup/basic.setup.d.ts.map b/wallets/metamask/test/wallet-setup/basic.setup.d.ts.map deleted file mode 100644 index d4aad874b..000000000 --- a/wallets/metamask/test/wallet-setup/basic.setup.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"basic.setup.d.ts","sourceRoot":"","sources":["basic.setup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,WAAW,gEAAgE,CAAA;AAExF,eAAO,MAAM,QAAQ,gBAAgB,CAAA;;;;;;AAErC,wBAIE"} \ No newline at end of file