Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: Run on windows with cache #1161

Merged
merged 15 commits into from
Jul 9, 2024
1 change: 1 addition & 0 deletions packages/cache/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
13 changes: 0 additions & 13 deletions packages/cache/src/cli/cliEntrypoint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os from 'node:os'
import path from 'node:path'
import chalk from 'chalk'
import { Command } from 'commander'
Expand Down Expand Up @@ -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!
Expand Down
58 changes: 33 additions & 25 deletions packages/cache/src/cli/compileWalletSetupFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import path from 'node:path'
import path, { posix, win32 } from 'node:path'
import { glob } from 'glob'
import { build } from 'tsup'
import { ensureCacheDirExists } from '../ensureCacheDirExists'
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:')
Expand All @@ -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
}
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
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 13 additions & 5 deletions pnpm-lock.yaml

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

4 changes: 2 additions & 2 deletions release/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
4 changes: 2 additions & 2 deletions wallets/metamask/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 0 additions & 9 deletions wallets/metamask/test/wallet-setup/basic.setup.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion wallets/metamask/test/wallet-setup/basic.setup.d.ts.map

This file was deleted.

Loading