@@ -16,7 +16,12 @@ let TMP_DIR;
16
16
try {
17
17
TMP_DIR = os . tmpdir ( ) ;
18
18
} catch ( e ) {
19
- TMP_DIR = '/tmp' ; //maybe we can consider to use node_modules/.cache/adminforth here instead of tmp
19
+ // Cross-platform fallback for temp directory
20
+ if ( process . platform === 'win32' ) {
21
+ TMP_DIR = process . env . TEMP || process . env . TMP || 'C:\\Windows\\Temp' ;
22
+ } else {
23
+ TMP_DIR = '/tmp' ;
24
+ }
20
25
}
21
26
22
27
function stripAnsiCodes ( str ) {
@@ -62,7 +67,11 @@ function hashify(obj) {
62
67
function notifyWatcherIssue ( limit ) {
63
68
console . log ( 'Ran out of file handles after watching %s files.' , limit ) ;
64
69
console . log ( 'Falling back to polling which uses more CPU.' ) ;
65
- console . log ( 'Run ulimit -n 10000 to increase the limit for open files.' ) ;
70
+ if ( process . platform === 'win32' ) {
71
+ console . log ( 'On Windows, this is usually handled automatically by the system.' ) ;
72
+ } else {
73
+ console . log ( 'Run ulimit -n 10000 to increase the limit for open files.' ) ;
74
+ }
66
75
}
67
76
68
77
class CodeInjector implements ICodeInjector {
@@ -112,7 +121,7 @@ class CodeInjector implements ICodeInjector {
112
121
envOverrides ?: { [ key : string ] : string }
113
122
} ) {
114
123
const nodeBinary = process . execPath ; // Path to the Node.js binary running this script
115
- const npmPath = path . join ( path . dirname ( nodeBinary ) , ' npm' ) ; // Path to the npm executable
124
+ const npmPath = path . join ( path . dirname ( nodeBinary ) , process . platform === 'win32' ? ' npm.cmd' : 'npm' ) ; // Cross-platform npm executable
116
125
const env = {
117
126
VITE_ADMINFORTH_PUBLIC_PATH : this . adminforth . config . baseUrl ,
118
127
FORCE_COLOR : '1' ,
@@ -123,7 +132,13 @@ class CodeInjector implements ICodeInjector {
123
132
console . log ( `⚙️ exec: npm ${ command } ` ) ;
124
133
process . env . HEAVY_DEBUG && console . log ( `🪲 npm ${ command } cwd:` , cwd ) ;
125
134
process . env . HEAVY_DEBUG && console . time ( `npm ${ command } done in` ) ;
126
- const { stdout : out , stderr : err } = await execAsync ( `${ nodeBinary } ${ npmPath } ${ command } ` , {
135
+
136
+ // Cross-platform command execution
137
+ const commandToExecute = process . platform === 'win32'
138
+ ? `"${ nodeBinary } " "${ npmPath } " ${ command } `
139
+ : `${ nodeBinary } ${ npmPath } ${ command } ` ;
140
+
141
+ const { stdout : out , stderr : err } = await execAsync ( commandToExecute , {
127
142
cwd,
128
143
env,
129
144
} ) ;
@@ -317,9 +332,14 @@ class CodeInjector implements ICodeInjector {
317
332
318
333
await fsExtra . copy ( spaDir , this . spaTmpPath ( ) , {
319
334
filter : ( src ) => {
320
- // /adminforth/* used for local development and /dist/* used for production
321
- const filterPasses = ! src . includes ( '/adminforth/spa/node_modules' ) && ! src . includes ( '/adminforth/spa/dist' )
322
- && ! src . includes ( '/dist/spa/node_modules' ) && ! src . includes ( '/dist/spa/dist' ) ;
335
+ // Cross-platform path filtering for adminforth/* used for local development and /dist/* used for production
336
+ const adminforthSpaNodeModules = path . join ( 'adminforth' , 'spa' , 'node_modules' ) ;
337
+ const adminforthSpaDist = path . join ( 'adminforth' , 'spa' , 'dist' ) ;
338
+ const distSpaNodeModules = path . join ( 'dist' , 'spa' , 'node_modules' ) ;
339
+ const distSpaDist = path . join ( 'dist' , 'spa' , 'dist' ) ;
340
+
341
+ const filterPasses = ! src . includes ( adminforthSpaNodeModules ) && ! src . includes ( adminforthSpaDist )
342
+ && ! src . includes ( distSpaNodeModules ) && ! src . includes ( distSpaDist ) ;
323
343
if ( process . env . HEAVY_DEBUG && ! filterPasses ) {
324
344
console . log ( '🪲⚙️ fsExtra.copy filtered out' , src ) ;
325
345
}
@@ -357,8 +377,8 @@ class CodeInjector implements ICodeInjector {
357
377
await fsExtra . copy ( src , to , {
358
378
recursive : true ,
359
379
dereference : true ,
360
- // exclue if node_modules comes after /custom/ in path
361
- filter : ( src ) => ! src . includes ( '/ custom/ node_modules') ,
380
+ // exclude if node_modules comes after /custom/ in path
381
+ filter : ( src ) => ! src . includes ( path . join ( ' custom' , ' node_modules') ) ,
362
382
} ) ;
363
383
}
364
384
@@ -514,9 +534,9 @@ class CodeInjector implements ICodeInjector {
514
534
// we dont't need to add baseUrl in front of assets here, because it is already added by Vite/Vue
515
535
indexHtmlContent = indexHtmlContent . replace (
516
536
'/* IMPORTANT:ADMINFORTH FAVICON */' ,
517
- this . adminforth . config . customization . favicon ?. replace ( '@@/' , ` /assets/` )
537
+ this . adminforth . config . customization . favicon ?. replace ( '@@/' , ' /assets/' )
518
538
||
519
- ` /assets/favicon.png`
539
+ ' /assets/favicon.png'
520
540
) ;
521
541
await fs . promises . writeFile ( indexHtmlPath , indexHtmlContent ) ;
522
542
@@ -668,7 +688,7 @@ class CodeInjector implements ICodeInjector {
668
688
'change' ,
669
689
async ( file ) => {
670
690
process . env . HEAVY_DEBUG && console . log ( `🐛 File ${ file } changed (SPA), preparing sources...` ) ;
671
- await this . updatePartials ( { filesUpdated : [ file . replace ( spaPath + '/' , '' ) ] } ) ;
691
+ await this . updatePartials ( { filesUpdated : [ file . replace ( spaPath + path . sep , '' ) ] } ) ;
672
692
}
673
693
)
674
694
watcher . on ( 'fallback' , notifyWatcherIssue ) ;
@@ -725,7 +745,7 @@ class CodeInjector implements ICodeInjector {
725
745
'change' ,
726
746
async ( fileOrDir ) => {
727
747
// copy one file
728
- const relativeFilename = fileOrDir . replace ( customComponentsDir + '/' , '' ) ;
748
+ const relativeFilename = fileOrDir . replace ( customComponentsDir + path . sep , '' ) ;
729
749
if ( process . env . HEAVY_DEBUG ) {
730
750
console . log ( `🔎 fileOrDir ${ fileOrDir } changed` ) ;
731
751
console . log ( `🔎 relativeFilename ${ relativeFilename } ` ) ;
@@ -868,14 +888,14 @@ class CodeInjector implements ICodeInjector {
868
888
const command = 'run dev' ;
869
889
console . log ( `⚙️ spawn: npm ${ command } ...` ) ;
870
890
const nodeBinary = process . execPath ;
871
- const npmPath = path . join ( path . dirname ( nodeBinary ) , 'npm' ) ;
891
+ const npmPath = path . join ( path . dirname ( nodeBinary ) , process . platform === 'win32' ? 'npm.cmd' : 'npm' ) ;
872
892
const env = {
873
893
VITE_ADMINFORTH_PUBLIC_PATH : this . adminforth . config . baseUrl ,
874
894
FORCE_COLOR : '1' ,
875
895
...process . env ,
876
896
} ;
877
897
878
- const devServer = spawn ( ` ${ nodeBinary } ` , [ ` ${ npmPath } ` , ...command . split ( ' ' ) ] , {
898
+ const devServer = spawn ( nodeBinary , [ npmPath , ...command . split ( ' ' ) ] , {
879
899
cwd,
880
900
env,
881
901
} ) ;
0 commit comments