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

🐛 chore(core): Add compilation files fixes #982

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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