|
2 | 2 | * External dependencies |
3 | 3 | */ |
4 | 4 | const fs = require( 'fs-extra' ); |
| 5 | +const path = require( 'path' ); |
5 | 6 | const { execSync, spawnSync } = require( 'child_process' ); |
6 | 7 |
|
7 | 8 | /** |
@@ -405,120 +406,68 @@ function doRunStandalonePluginTests( settings ) { |
405 | 406 | // Buffer built plugins array. |
406 | 407 | let builtPlugins = []; |
407 | 408 |
|
408 | | - // Buffer contents of plugins JSON file. |
409 | | - let pluginsJsonFileContent = ''; |
| 409 | + // Resolve the absolute path to the plugins.json file. |
| 410 | + const pluginsFile = path.join( |
| 411 | + __dirname, |
| 412 | + '../../../' + settings.pluginsJsonFile |
| 413 | + ); |
410 | 414 |
|
411 | 415 | try { |
412 | | - pluginsJsonFileContent = fs.readFileSync( |
413 | | - settings.pluginsJsonFile, |
414 | | - 'utf-8' |
415 | | - ); |
416 | | - } catch ( e ) { |
417 | | - log( |
418 | | - formats.error( |
419 | | - `Error reading file at "${ settings.pluginsJsonFile }". ${ e }` |
420 | | - ) |
421 | | - ); |
422 | | - } |
423 | | - |
424 | | - // Validate that the plugins JSON file contains content before proceeding. |
425 | | - if ( '' === pluginsJsonFileContent || ! pluginsJsonFileContent ) { |
426 | | - log( |
427 | | - formats.error( |
428 | | - `Contents of file at "${ settings.pluginsJsonFile }" could not be read, or are empty.` |
429 | | - ) |
430 | | - ); |
431 | | - } |
432 | | - |
433 | | - const pluginsConfig = JSON.parse( pluginsJsonFileContent ); |
434 | | - |
435 | | - // Check for valid and not empty object resulting from plugins JSON file parse. |
436 | | - if ( |
437 | | - 'object' !== typeof pluginsConfig || |
438 | | - 0 === Object.keys( pluginsConfig ).length |
439 | | - ) { |
440 | | - log( |
441 | | - formats.error( |
442 | | - `File at "settings.pluginsJsonFile" parsed, but detected empty/non valid JSON object.` |
443 | | - ) |
444 | | - ); |
445 | | - |
446 | | - // Return with exit code 1 to trigger a failure in the test pipeline. |
447 | | - process.exit( 1 ); |
448 | | - } |
449 | | - |
450 | | - const standalonePlugins = pluginsConfig.modules; |
451 | | - if ( ! standalonePlugins ) { |
452 | | - log( |
453 | | - formats.error( |
454 | | - 'The given module configuration is invalid, the modules are missing, or they are misspelled.' |
455 | | - ) |
456 | | - ); |
457 | | - |
458 | | - // Return with exit code 1 to trigger a failure in the test pipeline. |
459 | | - process.exit( 1 ); |
460 | | - } |
461 | | - |
462 | | - // Create an array of plugins from entries in plugins JSON file. |
463 | | - builtPlugins = Object.keys( standalonePlugins ) |
464 | | - .filter( ( item ) => { |
465 | | - if ( |
466 | | - ! fs.pathExistsSync( |
467 | | - `${ settings.builtPluginsDir }${ standalonePlugins[ item ].slug }` |
468 | | - ) |
469 | | - ) { |
470 | | - log( |
471 | | - formats.error( |
472 | | - `Built plugin path "${ settings.builtPluginsDir }${ standalonePlugins[ item ].slug }" not found, skipping and removing from plugin list` |
| 416 | + // Read the plugins.json file synchronously. |
| 417 | + const { modules, plugins } = require( pluginsFile ); |
| 418 | + |
| 419 | + // Create an array of plugins from entries in plugins JSON file. |
| 420 | + builtPlugins = Object.keys( modules ) |
| 421 | + .filter( ( item ) => { |
| 422 | + if ( |
| 423 | + ! fs.pathExistsSync( |
| 424 | + `${ settings.builtPluginsDir }${ modules[ item ].slug }` |
473 | 425 | ) |
474 | | - ); |
475 | | - return false; |
476 | | - } |
477 | | - return true; |
478 | | - } ) |
479 | | - .map( ( item ) => standalonePlugins[ item ].slug ); |
480 | | - |
481 | | - // Append plugins into array. |
482 | | - const plugins = pluginsConfig.plugins; |
483 | | - if ( ! plugins ) { |
484 | | - log( |
485 | | - formats.error( |
486 | | - 'The given plugin configuration is invalid, the plugins are missing, or they are misspelled.' |
487 | | - ) |
488 | | - ); |
489 | | - |
490 | | - // Return with exit code 1 to trigger a failure in the test pipeline. |
491 | | - process.exit( 1 ); |
492 | | - } |
493 | | - |
494 | | - // Create an array of plugins from entries in plugins JSON file. |
495 | | - builtPlugins = builtPlugins.concat( |
496 | | - Object.values( plugins ) |
497 | | - .filter( ( plugin ) => { |
498 | | - try { |
499 | | - fs.copySync( |
500 | | - `${ settings.pluginsDir }${ plugin.slug }/`, |
501 | | - `${ settings.builtPluginsDir }${ plugin.slug }/`, |
502 | | - { |
503 | | - overwrite: true, |
504 | | - } |
505 | | - ); |
506 | | - log( |
507 | | - formats.success( `Copied plugin "${ plugin.slug }".\n` ) |
508 | | - ); |
509 | | - return true; |
510 | | - } catch ( e ) { |
511 | | - // Handle the error appropriately |
| 426 | + ) { |
512 | 427 | log( |
513 | 428 | formats.error( |
514 | | - `Error copying plugin "${ plugin.slug }": ${ e.message }` |
| 429 | + `Built plugin path "${ settings.builtPluginsDir }${ modules[ item ].slug }" not found, skipping and removing from plugin list` |
515 | 430 | ) |
516 | 431 | ); |
517 | 432 | return false; |
518 | 433 | } |
| 434 | + return true; |
519 | 435 | } ) |
520 | | - .map( ( plugin ) => plugin.slug ) |
521 | | - ); |
| 436 | + .map( ( item ) => modules[ item ].slug ); |
| 437 | + |
| 438 | + // Create an array of plugins from entries in plugins JSON file. |
| 439 | + builtPlugins = builtPlugins.concat( |
| 440 | + Object.values( plugins ) |
| 441 | + .filter( ( plugin ) => { |
| 442 | + try { |
| 443 | + fs.copySync( |
| 444 | + `${ settings.pluginsDir }${ plugin.slug }/`, |
| 445 | + `${ settings.builtPluginsDir }${ plugin.slug }/`, |
| 446 | + { |
| 447 | + overwrite: true, |
| 448 | + } |
| 449 | + ); |
| 450 | + log( |
| 451 | + formats.success( |
| 452 | + `Copied plugin "${ plugin.slug }".\n` |
| 453 | + ) |
| 454 | + ); |
| 455 | + return true; |
| 456 | + } catch ( e ) { |
| 457 | + // Handle the error appropriately |
| 458 | + log( |
| 459 | + formats.error( |
| 460 | + `Error copying plugin "${ plugin.slug }": ${ e.message }` |
| 461 | + ) |
| 462 | + ); |
| 463 | + return false; |
| 464 | + } |
| 465 | + } ) |
| 466 | + .map( ( plugin ) => plugin.slug ) |
| 467 | + ); |
| 468 | + } catch ( error ) { |
| 469 | + throw Error( `Error reading file at "${ pluginsFile }": ${ error }` ); |
| 470 | + } |
522 | 471 |
|
523 | 472 | // For each built plugin, copy the test assets. |
524 | 473 | builtPlugins.forEach( ( plugin ) => { |
|
0 commit comments