File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed
lib/internal/bootstrap/switches Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 22
33const credentials = internalBinding ( 'credentials' ) ;
44const rawMethods = internalBinding ( 'process_methods' ) ;
5+ const {
6+ namespace : {
7+ addSerializeCallback,
8+ isBuildingSnapshot,
9+ } ,
10+ } = require ( 'internal/v8/startup_snapshot' ) ;
511
612process . abort = rawMethods . abort ;
713process . umask = wrappedUmask ;
@@ -107,6 +113,12 @@ function wrapPosixCredentialSetters(credentials) {
107113// directory is changed by `chdir`, it'll be updated.
108114let cachedCwd = '' ;
109115
116+ if ( isBuildingSnapshot ( ) ) {
117+ addSerializeCallback ( ( ) => {
118+ cachedCwd = '' ;
119+ } ) ;
120+ }
121+
110122function wrappedChdir ( directory ) {
111123 validateString ( directory , 'directory' ) ;
112124 rawMethods . chdir ( directory ) ;
Original file line number Diff line number Diff line change 1+ const {
2+ setDeserializeMainFunction,
3+ } = require ( 'v8' ) . startupSnapshot ;
4+
5+ // To make sure the cwd is present in the cache
6+ process . cwd ( ) ;
7+
8+ setDeserializeMainFunction ( ( ) => {
9+ console . log ( process . cwd ( ) ) ;
10+ } ) ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ // This tests that process.cwd() is accurate when
4+ // restoring state from a snapshot
5+
6+ require ( '../common' ) ;
7+ const { spawnSyncAndExitWithoutError } = require ( '../common/child_process' ) ;
8+ const tmpdir = require ( '../common/tmpdir' ) ;
9+ const fixtures = require ( '../common/fixtures' ) ;
10+ const fs = require ( 'fs' ) ;
11+
12+ tmpdir . refresh ( ) ;
13+ const blobPath = tmpdir . resolve ( 'snapshot.blob' ) ;
14+ const file = fixtures . path ( 'snapshot' , 'cwd.js' ) ;
15+
16+ const subdir = tmpdir . resolve ( 'foo' ) ;
17+ fs . mkdirSync ( subdir ) ;
18+
19+ {
20+ // Create the snapshot.
21+ spawnSyncAndExitWithoutError ( process . execPath , [
22+ '--snapshot-blob' ,
23+ blobPath ,
24+ '--build-snapshot' ,
25+ file ,
26+ ] , {
27+ cwd : tmpdir . path ,
28+ encoding : 'utf8'
29+ } , {
30+ status : 0 ,
31+ } ) ;
32+ }
33+
34+ {
35+ spawnSyncAndExitWithoutError ( process . execPath , [
36+ '--snapshot-blob' ,
37+ blobPath ,
38+ file ,
39+ ] , {
40+ cwd : subdir ,
41+ encoding : 'utf8'
42+ } , {
43+ status : 0 ,
44+ trim : true ,
45+ stdout : subdir ,
46+ } ) ;
47+ }
You can’t perform that action at this time.
0 commit comments