11import assert from "node:assert/strict" ;
22import { createHmac , timingSafeEqual } from "node:crypto" ;
3- import { mkdirSync , readFileSync , rmSync , writeFileSync } from "node:fs" ;
3+ import {
4+ cpSync ,
5+ mkdirSync ,
6+ mkdtempSync ,
7+ readFileSync ,
8+ rmSync ,
9+ writeFileSync ,
10+ } from "node:fs" ;
11+ import { tmpdir } from "node:os" ;
412import { dirname , join } from "node:path" ;
513import { fileURLToPath , pathToFileURL } from "node:url" ;
614
715const __dirname = dirname ( fileURLToPath ( import . meta. url ) ) ;
816const sourceRoot = join ( __dirname , ".." ) ;
9- const packageRoot = join ( sourceRoot , "node_modules" ) ;
1017
1118function writeRuntimeStub ( path , source ) {
1219 mkdirSync ( dirname ( path ) , { recursive : true } ) ;
1320 writeFileSync ( path , source ) ;
1421}
1522
16- function installRuntimeStubs ( ) {
23+ function installRuntimeStubs ( packageRoot ) {
1724 rmSync ( packageRoot , { force : true , recursive : true } ) ;
1825
1926 writeRuntimeStub (
@@ -178,7 +185,12 @@ function signWebhook(rawBody, secret) {
178185}
179186
180187async function main ( ) {
181- installRuntimeStubs ( ) ;
188+ const runtimeRoot = mkdtempSync ( join ( tmpdir ( ) , "makepay-medusa-test-" ) ) ;
189+ const packageRoot = join ( runtimeRoot , "node_modules" ) ;
190+ const runtimeDistRoot = join ( runtimeRoot , "dist" ) ;
191+
192+ installRuntimeStubs ( packageRoot ) ;
193+ cpSync ( join ( sourceRoot , "dist" ) , runtimeDistRoot , { recursive : true } ) ;
182194
183195 try {
184196 const pkg = JSON . parse (
@@ -201,7 +213,7 @@ async function main() {
201213 }
202214
203215 const moduleUrl = pathToFileURL (
204- join ( sourceRoot , "dist/ providers/makepay/index.js" ) ,
216+ join ( runtimeDistRoot , "providers/makepay/index.js" ) ,
205217 ) ;
206218 const makePayUrl = pathToFileURL (
207219 join ( packageRoot , "@makecrypto/makepay/index.js" ) ,
@@ -400,7 +412,7 @@ async function main() {
400412
401413 console . log ( "MakePay Medusa provider source verified." ) ;
402414 } finally {
403- rmSync ( packageRoot , { force : true , recursive : true } ) ;
415+ rmSync ( runtimeRoot , { force : true , recursive : true } ) ;
404416 }
405417}
406418
0 commit comments