6
6
* the root directory of this source tree.
7
7
*/
8
8
9
- import * as pioNodeHelpers from 'pioarduino-node-helpers' ;
9
+ // DON'T import pioNodeHelpers here - it causes immediate initialization!
10
+ // import * as pioNodeHelpers from 'pioarduino-node-helpers';
10
11
11
12
import PIOHome from '../home' ;
12
13
import { PIO_CORE_VERSION_SPEC } from '../constants' ;
@@ -21,28 +22,10 @@ export default class InstallationManager {
21
22
22
23
constructor ( disableAutoUpdates = false ) {
23
24
const config = vscode . workspace . getConfiguration ( 'platformio-ide' ) ;
24
- this . stages = [
25
- new pioNodeHelpers . installer . pioarduinoCoreStage (
26
- {
27
- getValue : ( key ) => extension . context . globalState . get ( key ) ,
28
- setValue : ( key , value ) => extension . context . globalState . update ( key , value ) ,
29
- } ,
30
- this . onDidStatusChange . bind ( this ) ,
31
- {
32
- pioCoreVersionSpec : PIO_CORE_VERSION_SPEC ,
33
- useBuiltinPython : config . get ( 'useBuiltinPython' ) ,
34
- useBuiltinPIOCore : config . get ( 'useBuiltinPIOCore' ) ,
35
- useDevelopmentPIOCore : config . get ( 'useDevelopmentPIOCore' ) ,
36
- pythonPrompt : new PythonPrompt ( ) ,
37
- disableAutoUpdates : disableAutoUpdates ,
38
- predownloadedPackageDir : path . join (
39
- extension . context . extensionPath ,
40
- 'assets' ,
41
- 'predownloaded' ,
42
- ) ,
43
- } ,
44
- ) ,
45
- ] ;
25
+ this . config = config ;
26
+ this . disableAutoUpdates = disableAutoUpdates ;
27
+ // Create stages lazily - the node-helpers now handle offline checks internally
28
+ this . stages = null ;
46
29
}
47
30
48
31
onDidStatusChange ( ) {
@@ -68,7 +51,39 @@ export default class InstallationManager {
68
51
return new Date ( ) . getTime ( ) - parseInt ( lockTime ) <= this . LOCK_TIMEOUT ;
69
52
}
70
53
54
+ createStages ( ) {
55
+ if ( this . stages === null ) {
56
+ // Lazy load pioNodeHelpers only when needed
57
+ const pioNodeHelpers = require ( 'pioarduino-node-helpers' ) ;
58
+ this . stages = [
59
+ new pioNodeHelpers . installer . pioarduinoCoreStage (
60
+ {
61
+ getValue : ( key ) => extension . context . globalState . get ( key ) ,
62
+ setValue : ( key , value ) => extension . context . globalState . update ( key , value ) ,
63
+ } ,
64
+ this . onDidStatusChange . bind ( this ) ,
65
+ {
66
+ pioCoreVersionSpec : PIO_CORE_VERSION_SPEC ,
67
+ useBuiltinPython : this . config . get ( 'useBuiltinPython' ) ,
68
+ useBuiltinPIOCore : this . config . get ( 'useBuiltinPIOCore' ) ,
69
+ useDevelopmentPIOCore : this . config . get ( 'useDevelopmentPIOCore' ) ,
70
+ pythonPrompt : new PythonPrompt ( ) ,
71
+ disableAutoUpdates : this . disableAutoUpdates ,
72
+ predownloadedPackageDir : path . join (
73
+ extension . context . extensionPath ,
74
+ 'assets' ,
75
+ 'predownloaded' ,
76
+ ) ,
77
+ } ,
78
+ ) ,
79
+ ] ;
80
+ }
81
+ }
82
+
71
83
async check ( ) {
84
+ // Create stages if needed
85
+ this . createStages ( ) ;
86
+
72
87
let result = true ;
73
88
for ( const stage of this . stages ) {
74
89
try {
@@ -77,13 +92,16 @@ export default class InstallationManager {
77
92
}
78
93
} catch ( err ) {
79
94
result = false ;
80
- console . warn ( err ) ;
95
+ console . warn ( 'Installation stage check failed:' , err . message || err ) ;
81
96
}
82
97
}
83
98
return result ;
84
99
}
85
100
86
101
async install ( progress ) {
102
+ // Ensure stages are created
103
+ this . createStages ( ) ;
104
+
87
105
const stageIncrementTotal = 100 / this . stages . length ;
88
106
// shutdown all PIO Home servers which block python.exe on Windows
89
107
await PIOHome . shutdownAllServers ( ) ;
@@ -99,6 +117,15 @@ export default class InstallationManager {
99
117
}
100
118
101
119
destroy ( ) {
102
- return this . stages . map ( ( stage ) => stage . destroy ( ) ) ;
120
+ if ( this . stages ) {
121
+ for ( const stage of this . stages ) {
122
+ try {
123
+ if ( stage && typeof stage . destroy === 'function' ) {
124
+ stage . destroy ( ) ;
125
+ }
126
+ } catch ( err ) { }
127
+ }
128
+ }
129
+ this . stages = null ;
103
130
}
104
131
}
0 commit comments