Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
sero committed Jul 2, 2024
1 parent d2cf5f7 commit 51ad296
Showing 1 changed file with 61 additions and 42 deletions.
103 changes: 61 additions & 42 deletions packages/cache/src/cli/compileWalletSetupFunctions.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,48 @@
import path from 'node:path'
import { globSync } from 'glob'
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}')
function escapeWindowsFilePath(filePath: string, platform: string) {
if (platform !== 'win32') return filePath;
filePath.replace(/\//g, '\\')
return filePath.replace(/\\/g, '\\\\')
}

export async function compileWalletSetupFunctions(walletSetupDir: string, debug: boolean) {
const escapeWindowsFilePath = (filePath: string) => {
filePath.replace(/\//g, '\\')
const n = filePath.replace(/\\/g, '\\\\')
console.log(n, 'n', filePath)
return n
}
const outDir = path.join(ensureCacheDirExists(), OUT_DIR_NAME)
console.log(process.platform, 'platform')
const setupPath = process.platform === 'win32' ? escapeWindowsFilePath(walletSetupDir) : walletSetupDir
console.log(setupPath, 'setupPath')
const globPattern = createGlobPattern(setupPath)
const fullPath = path.join(process.cwd(), globPattern)
console.log(fullPath, 'fp')
const fileList = globSync('*.setup.{ts,js,mjs}')
console.log(fileList, 'fl')
export async function compileWalletSetupFunctions(
walletSetupDir: string,
debug: boolean
) {
const outDir = path.join(ensureCacheDirExists(), OUT_DIR_NAME);

// **Refined Glob Pattern:**
const globPattern = path.join(walletSetupDir, '**', '*.setup.{ts,js,mjs}');

const platform = process.platform
// Get file paths using glob, ensuring proper path handling
const p = escapeWindowsFilePath(globPattern, platform)
console.log('path', p)
// const fileList = globSync(escapeWindowsFilePath(globPattern, ''));
// const fileList = await glob(escapeWindowsFilePath(globPattern, platform))
const fileList = [new URL('file:\\' + path.join(process.cwd(), 'test/wallet-setup/connected.setup.ts')), new URL('file:\\' + path.join(process.cwd(), 'test/wallet-setup/basic.setup.ts'))]
// const fileList = ['test/wallet-setup/connected.setup.ts', 'test/wallet-setup/basic.setup.ts']
if (debug) {
console.log('[DEBUG] Found the following wallet setup files:')
console.log(fileList, globPattern, outDir, '\n')
console.log('[DEBUG] Found the following wallet setup files:');
console.log(fileList, '\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')
);
}
// TODO: This error message is copied over from another function. Refactor this.
if (!fileList.length) {
throw new Error(
Expand All @@ -39,27 +53,32 @@ 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']
}
})


try {
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']
}
})
} catch (e) {
console.log(e)
}
return outDir
}
}

0 comments on commit 51ad296

Please sign in to comment.