Skip to content

Commit 6f5a65e

Browse files
committed
fix: refine cross-platform compatibility for script execution in index template
1 parent 3706caf commit 6f5a65e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

adminforth/commands/createApp/templates/index.ts.hbs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import express from 'express';
22
import AdminForth from 'adminforth';
33
import usersResource from "./resources/adminuser.js";
4+
import { fileURLToPath } from 'url';
5+
import path from 'path';
46

57
const ADMIN_BASE_URL = '';
68

@@ -55,9 +57,10 @@ export const admin = new AdminForth({
5557
],
5658
});
5759

58-
// Cross-platform check if script is executed directly
59-
const isMainModule = import.meta.url === new URL(process.argv[1], 'file:').href;
60-
if (isMainModule) {
60+
const currentFilePath = fileURLToPath(import.meta.url);
61+
const executedFilePath = path.resolve(process.argv[1]);
62+
63+
if (currentFilePath === executedFilePath) {
6164
const app = express();
6265
app.use(express.json());
6366

0 commit comments

Comments
 (0)