// CJS
if (require.main === module) {
console.log("이 스크립트는 직접 실행되었습니다.");
} else {
console.log("이 스크립트는 다른 파일에서 import되어 실행되었습니다.");
}
// ESM
import { fileURLToPath } from "url";
import path from "path";
const currentFile = fileURLToPath(import.meta.url);
const executedFile = process.argv[1];
const isDirectlyExecuted =
path.resolve(executedFile) === path.resolve(currentFile);
if (isDirectlyExecuted) {
console.log("이 스크립트는 직접 실행되었습니다.");
} else {
console.log("executedFile:", path.resolve(executedFile));
console.log("currentFile:", path.resolve(currentFile));
console.log("이 스크립트는 모듈로 임포트되어 실행되었습니다.");
}