Skip to content

Commit cf14f19

Browse files
committed
refactor(contracts): rename getCurrentModulePath to getModulePathFromImportMeta for clarity and consistency
1 parent 2d6057a commit cf14f19

File tree

3 files changed

+37
-11
lines changed

3 files changed

+37
-11
lines changed

packages/contracts/dist/custom-network-signatures.cjs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5064,7 +5064,7 @@ function extractAbiMethods(networkCache, methodNames) {
50645064
}
50655065

50665066
// packages/contracts/src/custom-network-signatures.ts
5067-
function getCurrentModulePath() {
5067+
function getModulePathFromImportMeta() {
50685068
const moduleUrl = __import_meta__?.url;
50695069
if (typeof moduleUrl === "string") {
50705070
try {
@@ -5073,6 +5073,13 @@ function getCurrentModulePath() {
50735073
console.warn("Failed to resolve fileURLToPath from import.meta.url:", error);
50745074
}
50755075
}
5076+
return void 0;
5077+
}
5078+
function getCurrentModulePath() {
5079+
const modulePath = getModulePathFromImportMeta();
5080+
if (modulePath) {
5081+
return modulePath;
5082+
}
50765083
if (typeof __filename !== "undefined") {
50775084
return __filename;
50785085
}
@@ -5249,8 +5256,8 @@ module.exports = {
52495256
}
52505257
}
52515258
var mainScriptPath = import_path.default.resolve(process.argv[1] || "");
5252-
var currentModulePath = getCurrentModulePath();
5253-
var resolvedModulePath = currentModulePath ? import_path.default.resolve(currentModulePath) : void 0;
5259+
var modulePathFromMeta = getModulePathFromImportMeta();
5260+
var resolvedModulePath = modulePathFromMeta ? import_path.default.resolve(modulePathFromMeta) : void 0;
52545261
if (resolvedModulePath && mainScriptPath === resolvedModulePath) {
52555262
const jsonFilePath = process.argv[2];
52565263
const networkName = process.argv[3];

packages/contracts/dist/custom-network-signatures.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5028,7 +5028,7 @@ function extractAbiMethods(networkCache, methodNames) {
50285028
}
50295029

50305030
// packages/contracts/src/custom-network-signatures.ts
5031-
function getCurrentModulePath() {
5031+
function getModulePathFromImportMeta() {
50325032
const moduleUrl = import.meta?.url;
50335033
if (typeof moduleUrl === "string") {
50345034
try {
@@ -5037,6 +5037,13 @@ function getCurrentModulePath() {
50375037
console.warn("Failed to resolve fileURLToPath from import.meta.url:", error);
50385038
}
50395039
}
5040+
return void 0;
5041+
}
5042+
function getCurrentModulePath() {
5043+
const modulePath = getModulePathFromImportMeta();
5044+
if (modulePath) {
5045+
return modulePath;
5046+
}
50405047
if (typeof __filename !== "undefined") {
50415048
return __filename;
50425049
}
@@ -5213,8 +5220,8 @@ module.exports = {
52135220
}
52145221
}
52155222
var mainScriptPath = path.resolve(process.argv[1] || "");
5216-
var currentModulePath = getCurrentModulePath();
5217-
var resolvedModulePath = currentModulePath ? path.resolve(currentModulePath) : void 0;
5223+
var modulePathFromMeta = getModulePathFromImportMeta();
5224+
var resolvedModulePath = modulePathFromMeta ? path.resolve(modulePathFromMeta) : void 0;
52185225
if (resolvedModulePath && mainScriptPath === resolvedModulePath) {
52195226
const jsonFilePath = process.argv[2];
52205227
const networkName = process.argv[3];

packages/contracts/src/custom-network-signatures.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,9 @@ export interface BuildSignaturesFromContextResult {
5656
* Resolves the on-disk path of this module in both ESM and CJS bundles.
5757
* Falls back to __filename when bundlers strip import.meta.url.
5858
*/
59-
function getCurrentModulePath(): string | undefined {
59+
function getModulePathFromImportMeta(): string | undefined {
6060
const moduleUrl = (import.meta as unknown as { url?: string } | undefined)
6161
?.url;
62-
6362
if (typeof moduleUrl === 'string') {
6463
try {
6564
return fileURLToPath(moduleUrl);
@@ -71,6 +70,19 @@ function getCurrentModulePath(): string | undefined {
7170
}
7271
}
7372

73+
return undefined;
74+
}
75+
76+
/**
77+
* Resolves the on-disk path of this module in both ESM and CJS bundles.
78+
* Falls back to __filename when bundlers strip import.meta.url.
79+
*/
80+
function getCurrentModulePath(): string | undefined {
81+
const modulePath = getModulePathFromImportMeta();
82+
if (modulePath) {
83+
return modulePath;
84+
}
85+
7486
if (typeof __filename !== 'undefined') {
7587
return __filename;
7688
}
@@ -339,9 +351,9 @@ module.exports = {
339351
// process.argv[0] is the bun executable
340352
// process.argv[1] is the script being run
341353
const mainScriptPath = path.resolve(process.argv[1] || '');
342-
const currentModulePath = getCurrentModulePath();
343-
const resolvedModulePath = currentModulePath
344-
? path.resolve(currentModulePath)
354+
const modulePathFromMeta = getModulePathFromImportMeta();
355+
const resolvedModulePath = modulePathFromMeta
356+
? path.resolve(modulePathFromMeta)
345357
: undefined;
346358

347359
if (resolvedModulePath && mainScriptPath === resolvedModulePath) {

0 commit comments

Comments
 (0)