Skip to content

Commit

Permalink
🐛 chore(core): Add compilation files fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception committed Nov 6, 2023
1 parent 45b4976 commit 2f51a9b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/core/src/cli/compilationFixes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Fixes -> Error: Dynamic require of "fs" is not supported
// Issue link: https://github.com/evanw/esbuild/issues/1921
const DYNAMIC_REQUIRE_FS_FIX = `
// ---- DYNAMIC_REQUIRE_FS_FIX ----
var require = (await import("node:module")).createRequire(import.meta.url);
var __filename = (await import("node:url")).fileURLToPath(import.meta.url);
var __dirname = (await import("node:path")).dirname(__filename);
// ---- DYNAMIC_REQUIRE_FS_FIX ----
`.trim()

// Fixes -> Error: Cannot find module '../package.json'
// This issue is related to the Playwright test runner.
const PLAYWRIGHT_RELATIVE_PACKAGE_IMPORT_FIX = `
// ---- PLAYWRIGHT_RELATIVE_PACKAGE_IMPORT_FIX ----
var originalRequireResolve = require.resolve;
require.resolve = (id, ...args) => {
if (id.endsWith("/package.json")) {
id = require("node:path").join(process.cwd(), "package.json");
}
return originalRequireResolve(id, ...args);
}
// ---- PLAYWRIGHT_RELATIVE_PACKAGE_IMPORT_FIX ----
`.trim()

export const FIXES_BANNER = `
/// ######## BANNER WITH FIXES START ########
${DYNAMIC_REQUIRE_FS_FIX}
${PLAYWRIGHT_RELATIVE_PACKAGE_IMPORT_FIX}
/// ######## BANNER WITH FIXES END ########
`.trimStart()
4 changes: 4 additions & 0 deletions packages/core/src/cli/compileWalletSetupFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import path 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'

Expand All @@ -22,6 +23,9 @@ export async function compileWalletSetupFunctions(walletSetupDir: string) {
splitting: true,
sourcemap: false,
config: false,
banner: {
js: FIXES_BANNER
},
esbuildOptions(options) {
options.drop = ['console', 'debugger']
}
Expand Down

0 comments on commit 2f51a9b

Please sign in to comment.