66 * the root directory of this source tree.
77 */
88
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';
1011
1112import PIOHome from '../home' ;
1213import { PIO_CORE_VERSION_SPEC } from '../constants' ;
@@ -21,28 +22,10 @@ export default class InstallationManager {
2122
2223 constructor ( disableAutoUpdates = false ) {
2324 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 ;
4629 }
4730
4831 onDidStatusChange ( ) {
@@ -68,7 +51,39 @@ export default class InstallationManager {
6851 return new Date ( ) . getTime ( ) - parseInt ( lockTime ) <= this . LOCK_TIMEOUT ;
6952 }
7053
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+
7183 async check ( ) {
84+ // Create stages if needed
85+ this . createStages ( ) ;
86+
7287 let result = true ;
7388 for ( const stage of this . stages ) {
7489 try {
@@ -77,13 +92,16 @@ export default class InstallationManager {
7792 }
7893 } catch ( err ) {
7994 result = false ;
80- console . warn ( err ) ;
95+ console . warn ( 'Installation stage check failed:' , err . message || err ) ;
8196 }
8297 }
8398 return result ;
8499 }
85100
86101 async install ( progress ) {
102+ // Ensure stages are created
103+ this . createStages ( ) ;
104+
87105 const stageIncrementTotal = 100 / this . stages . length ;
88106 // shutdown all PIO Home servers which block python.exe on Windows
89107 await PIOHome . shutdownAllServers ( ) ;
@@ -99,6 +117,15 @@ export default class InstallationManager {
99117 }
100118
101119 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 ;
103130 }
104131}
0 commit comments