11/* eslint-disable no-console */
2- import fs from 'fs' ;
3- import path from 'path' ;
2+ import fs from 'node: fs' ;
3+ import { dirname , resolve as resolvePath } from 'node: path' ;
44import type { ValidationError } from 'yup' ;
55
6- import { buildExternalAssetFilePath } from '../../../ configs/app/utils' ;
6+ import { buildExternalAssetFilePath } from 'configs/app/utils' ;
77import schema from './schema' ;
88import schemaMultichain from './schema_multichain' ;
9+ import { fileURLToPath } from 'node:url' ;
10+
11+ const currentFilePath = fileURLToPath ( import . meta. url ) ;
12+ const distDir = dirname ( currentFilePath ) ;
913
1014const silent = process . argv . includes ( '--silent' ) ;
1115
@@ -80,7 +84,7 @@ async function getExternalJsonContent(envName: string): Promise<string | void> {
8084 return new Promise ( ( resolve , reject ) => {
8185 const fileName = `./public${ buildExternalAssetFilePath ( envName , 'https://foo.bar/baz.json' ) } ` ;
8286
83- fs . readFile ( path . resolve ( __dirname , fileName ) , 'utf8' , ( err , data ) => {
87+ fs . readFile ( resolvePath ( distDir , '..' , fileName ) , 'utf8' , ( err , data ) => {
8488 if ( err ) {
8589 console . log ( `🚨 Unable to read file: ${ fileName } ` ) ;
8690 reject ( err ) ;
@@ -96,8 +100,8 @@ async function checkPlaceholdersCongruity(envsMap: Record<string, string>) {
96100 try {
97101 ! silent && console . log ( `🌀 Checking environment variables and their placeholders congruity...` ) ;
98102
99- const runTimeEnvs = await getEnvsPlaceholders ( path . resolve ( __dirname , '.env.registry' ) ) ;
100- const buildTimeEnvs = await getEnvsPlaceholders ( path . resolve ( __dirname , '.env' ) ) ;
103+ const runTimeEnvs = await getEnvsPlaceholders ( resolvePath ( distDir , '..' , '.env.registry' ) ) ;
104+ const buildTimeEnvs = await getEnvsPlaceholders ( resolvePath ( distDir , '..' , '.env' ) ) ;
101105 const envs = Object . keys ( envsMap ) . filter ( ( env ) => ! buildTimeEnvs . includes ( env ) ) ;
102106
103107 const inconsistencies : Array < string > = [ ] ;
@@ -121,7 +125,7 @@ async function checkPlaceholdersCongruity(envsMap: Record<string, string>) {
121125
122126 ! silent && console . log ( '👍 All good!\n' ) ;
123127 } catch ( error ) {
124- console . log ( '🚨 Congruity check failed.\n' ) ;
128+ console . log ( '🚨 Congruity check failed.\n' , error ) ;
125129 throw error ;
126130 }
127131}
0 commit comments