浏览代码

utils/server.js: cross-platform isMain check (#32674)

ycw 2 天之前
父节点
当前提交
3ef3070762
共有 1 个文件被更改,包括 2 次插入1 次删除
  1. 2 1
      utils/server.js

+ 2 - 1
utils/server.js

@@ -2,6 +2,7 @@ import http from 'http';
 import path from 'path';
 import os from 'os';
 import { createReadStream, existsSync, statSync, readdirSync } from 'fs';
+import { fileURLToPath } from 'url';
 
 function escapeHtml( str ) {
 
@@ -211,7 +212,7 @@ function tryListen( server, port, maxAttempts = 20 ) {
 }
 
 // CLI mode
-const isMain = process.argv[ 1 ] && path.resolve( process.argv[ 1 ] ) === path.resolve( import.meta.url.replace( 'file://', '' ) );
+const isMain = process.argv[ 1 ] && path.resolve( process.argv[ 1 ] ) === path.resolve( fileURLToPath( import.meta.url ) );
 
 if ( isMain ) {
 

粤ICP备19079148号