Skip to content

Commit

Permalink
Merge pull request #31 from humanmade/fix-eval-on-install
Browse files Browse the repository at this point in the history
Fix modules.php paths
  • Loading branch information
roborourke authored Feb 4, 2020
2 parents e8e70d5 + 8846fd6 commit 3347ad9
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions inc/composer/class-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public function generate_module_manifest() {
$file = str_replace( $vendor_dir, '', $file );

// Add the require line to the file.
$module_loader .= "\n// Load {$package->getName()}.\nrequire_once __DIR__ . '{$file}';";
// ~~DIR~~ is used because composer plugin files are eval'd during an
// install action and directory and file path constants get replaced.
$module_loader .= "\n// Load {$package->getName()}.\nrequire_once ~~DIR~~ . '{$file}';";
}

// Get custom module entrypoints.
Expand All @@ -118,7 +120,7 @@ public function generate_module_manifest() {

$files = array_filter( (array) $config['entrypoint'], 'file_exists' );
$files = array_map( function ( $file ) {
return "require_once dirname( __DIR__ ) . DIRECTORY_SEPARATOR . '{$file}';";
return "require_once dirname( ~~DIR~~ ) . DIRECTORY_SEPARATOR . '{$file}';";
}, $files );
$files = implode( "\n", $files );

Expand All @@ -127,6 +129,9 @@ public function generate_module_manifest() {
}
}

// Replace ~~DIR~~ with __DIR__.
$module_loader = str_replace( '~~', '__', $module_loader );

// Write the loader file.
file_put_contents( $vendor_dir . DIRECTORY_SEPARATOR . 'modules.php', "{$module_loader}\n" );
}
Expand Down

0 comments on commit 3347ad9

Please sign in to comment.