@@ -3,32 +3,32 @@ import path from 'node:path';
3
3
import { mkdirSync , mkdtempSync , writeFileSync } from 'node:fs' ;
4
4
import Container from 'typedi' ;
5
5
import { InstanceSettings } from 'n8n-core' ;
6
- import { Logger } from '@/Logger' ;
7
6
7
+ /**
8
+ * Create a temp .n8n user dir for benchmarking.
9
+ */
8
10
export function n8nDir ( ) {
9
- const baseDirPath = path . join ( tmpdir ( ) , 'n8n-benchmarks/' ) ;
11
+ const tempBaseDir = path . join ( tmpdir ( ) , 'n8n-benchmarks/' ) ;
10
12
11
- mkdirSync ( baseDirPath , { recursive : true } ) ;
13
+ mkdirSync ( tempBaseDir , { recursive : true } ) ;
12
14
13
- const userDir = mkdtempSync ( baseDirPath ) ;
15
+ const tempUserHomeDir = mkdtempSync ( tempBaseDir ) ;
14
16
15
- const n8nDirPath = path . join ( userDir , '.n8n' ) ;
17
+ const tempN8nDir = path . join ( tempUserHomeDir , '.n8n' ) ;
16
18
17
- mkdirSync ( n8nDirPath ) ;
19
+ mkdirSync ( tempN8nDir ) ;
18
20
19
21
writeFileSync (
20
- path . join ( n8nDirPath , 'config' ) ,
22
+ path . join ( tempN8nDir , 'config' ) ,
21
23
JSON . stringify ( { encryptionKey : 'temp_encryption_key' , instanceId : 'temp-123' } ) ,
22
24
'utf-8' ,
23
25
) ;
24
26
25
- // @TODO : Find better approach than overriding like this
26
- // Setting N8N_USER_FOLDER has no effect
27
- const instanceSettings = Container . get ( InstanceSettings ) ;
28
- instanceSettings . n8nFolder = n8nDirPath ;
29
- Container . set ( InstanceSettings , instanceSettings ) ;
27
+ process . env . N8N_USER_FOLDER = tempUserHomeDir ;
30
28
31
- Container . get ( Logger ) . info (
32
- `[Benchmarking] Temp .n8n dir location: ${ instanceSettings . n8nFolder } ` ,
33
- ) ;
29
+ /**
30
+ * `typedi` has already instantiated `InstanceSettings` using the default user home,
31
+ * so re-instantiate it to ensure it picks up the temp user home dir path.
32
+ */
33
+ Container . set ( InstanceSettings , new InstanceSettings ( ) ) ;
34
34
}
0 commit comments