Skip to content

Commit 5724b18

Browse files
committed
fix: running the bundle in dev mode
1 parent 118c85e commit 5724b18

File tree

2 files changed

+32
-19
lines changed
  • resources/js/electron-plugin

2 files changed

+32
-19
lines changed

resources/js/electron-plugin/dist/server/php.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ function shouldMigrateDatabase(store) {
3232
&& process.env.NODE_ENV !== 'development';
3333
}
3434
function shouldOptimize(store) {
35-
return store.get('optimized_version') !== app.getVersion()
36-
&& process.env.NODE_ENV !== 'development';
35+
return store.get('optimized_version') !== app.getVersion();
3736
}
3837
function getPhpPort() {
3938
return __awaiter(this, void 0, void 0, function* () {
@@ -207,6 +206,7 @@ function serveApp(secret, apiPort, phpIniSettings) {
207206
name: 'nativephp',
208207
});
209208
if (!runningSecureBuild()) {
209+
console.log('Linking storage path...');
210210
callPhpSync(['artisan', 'storage:link', '--force'], phpOptions, phpIniSettings);
211211
}
212212
if (shouldOptimize(store)) {
@@ -235,19 +235,24 @@ function serveApp(secret, apiPort, phpIniSettings) {
235235
}
236236
console.log('Starting PHP server...');
237237
const phpPort = yield getPhpPort();
238-
let serverPath = join(appPath, 'build', '__nativephp_app_bundle');
239-
if (!runningSecureBuild()) {
238+
let serverPath;
239+
let cwd;
240+
if (runningSecureBuild()) {
241+
serverPath = join(appPath, 'build', '__nativephp_app_bundle');
242+
}
243+
else {
240244
console.log('* * * Running from source * * *');
241245
serverPath = join(appPath, 'vendor', 'laravel', 'framework', 'src', 'Illuminate', 'Foundation', 'resources', 'server.php');
246+
cwd = join(appPath, 'public');
242247
}
243248
const phpServer = callPhp(['-S', `127.0.0.1:${phpPort}`, serverPath], {
244-
cwd: join(appPath, 'public'),
249+
cwd: cwd,
245250
env
246251
}, phpIniSettings);
247252
const portRegex = /Development Server \(.*:([0-9]+)\) started/gm;
248253
phpServer.stdout.on('data', (data) => {
249254
if (parseInt(process.env.SHELL_VERBOSITY) > 0) {
250-
console.log(data.toString());
255+
console.log(data.toString().trim());
251256
}
252257
});
253258
phpServer.stderr.on('data', (data) => {
@@ -263,11 +268,12 @@ function serveApp(secret, apiPort, phpIniSettings) {
263268
}
264269
else {
265270
if (error.includes('[NATIVE_EXCEPTION]:')) {
271+
let logFile = join(storagePath, 'logs', 'laravel.log');
266272
console.log();
267273
console.error('Error in PHP:');
268274
console.error(' ' + error.split('[NATIVE_EXCEPTION]:')[1].trim());
269275
console.log('Please check your log file:');
270-
console.log(' ' + join(appPath, 'storage', 'logs', 'laravel.log'));
276+
console.log(' ' + logFile);
271277
console.log();
272278
}
273279
}

resources/js/electron-plugin/src/server/php.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ function shouldMigrateDatabase(store) {
3131
}
3232

3333
function shouldOptimize(store) {
34-
return store.get('optimized_version') !== app.getVersion()
35-
&& process.env.NODE_ENV !== 'development';
34+
return store.get('optimized_version') !== app.getVersion();
3635
}
3736

3837
async function getPhpPort() {
@@ -253,7 +252,7 @@ function getDefaultEnvironmentVariables(secret, apiPort): EnvironmentVariables {
253252
};
254253

255254
// Only add cache paths if in production mode
256-
if(runningSecureBuild()) {
255+
if (runningSecureBuild()) {
257256
variables.APP_SERVICES_CACHE = join(bootstrapCache, 'services.php');
258257
variables.APP_PACKAGES_CACHE = join(bootstrapCache, 'packages.php');
259258
variables.APP_CONFIG_CACHE = join(bootstrapCache, 'config.php');
@@ -296,6 +295,7 @@ function serveApp(secret, apiPort, phpIniSettings): Promise<ProcessResult> {
296295
// Make sure the storage path is linked - as people can move the app around, we
297296
// need to run this every time the app starts
298297
if (!runningSecureBuild()) {
298+
console.log('Linking storage path...');
299299
callPhpSync(['artisan', 'storage:link', '--force'], phpOptions, phpIniSettings)
300300
}
301301

@@ -333,33 +333,38 @@ function serveApp(secret, apiPort, phpIniSettings): Promise<ProcessResult> {
333333
const phpPort = await getPhpPort();
334334

335335

336-
let serverPath = join(appPath, 'build', '__nativephp_app_bundle');
336+
let serverPath: string;
337+
let cwd: string;
337338

338-
if (!runningSecureBuild()) {
339+
if (runningSecureBuild()) {
340+
serverPath = join(appPath, 'build', '__nativephp_app_bundle');
341+
} else {
339342
console.log('* * * Running from source * * *');
340343
serverPath = join(appPath, 'vendor', 'laravel', 'framework', 'src', 'Illuminate', 'Foundation', 'resources', 'server.php');
344+
cwd = join(appPath, 'public');
341345
}
342346

343347
const phpServer = callPhp(['-S', `127.0.0.1:${phpPort}`, serverPath], {
344-
cwd: join(appPath, 'public'),
348+
cwd: cwd,
345349
env
346350
}, phpIniSettings)
347351

348352
const portRegex = /Development Server \(.*:([0-9]+)\) started/gm
349353

354+
// Show urls called
350355
phpServer.stdout.on('data', (data) => {
351356
// [Tue Jan 14 19:51:00 2025] 127.0.0.1:52779 [POST] URI: /_native/api/events
352357

353358
if (parseInt(process.env.SHELL_VERBOSITY) > 0) {
354-
console.log(data.toString());
359+
console.log(data.toString().trim());
355360
}
356361
})
357362

358-
363+
// Show PHP errors and indicate which port the server is running on
359364
phpServer.stderr.on('data', (data) => {
360365
const error = data.toString();
361366
const match = portRegex.exec(data.toString());
362-
// console.log('E:', error);
367+
363368
if (match) {
364369
const port = parseInt(match[1]);
365370
console.log("PHP Server started on port: ", port);
@@ -368,23 +373,25 @@ function serveApp(secret, apiPort, phpIniSettings): Promise<ProcessResult> {
368373
process: phpServer,
369374
});
370375
} else {
371-
372-
// Starting at [NATIVE_EXCEPTION]:
373376
if (error.includes('[NATIVE_EXCEPTION]:')) {
377+
let logFile = join(storagePath, 'logs', 'laravel.log');
378+
374379
console.log();
375380
console.error('Error in PHP:');
376381
console.error(' ' + error.split('[NATIVE_EXCEPTION]:')[1].trim());
377382
console.log('Please check your log file:');
378-
console.log(' ' + join(appPath, 'storage', 'logs', 'laravel.log'));
383+
console.log(' ' + logFile);
379384
console.log();
380385
}
381386
}
382387
});
383388

389+
// Log when any error occurs (not started, not killed, couldn't send message, etc)
384390
phpServer.on('error', (error) => {
385391
reject(error)
386392
});
387393

394+
// Log when the PHP server exits
388395
phpServer.on('close', (code) => {
389396
console.log(`PHP server exited with code ${code}`);
390397
});

0 commit comments

Comments
 (0)