diff --git a/box.json b/box.json index 6d59f39d..624ee131 100644 --- a/box.json +++ b/box.json @@ -27,13 +27,13 @@ "name": [ "*.php", "*.xml", - "*.sh" + "*.sh", + "*.jar" ], "exclude": [ "Tests", "tests", "Docs", - "node_modules", "pix" ] } diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 91d43b25..8b62d0f4 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -9,6 +9,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). The format of this change log follows the advice given at [Keep a CHANGELOG](http://keepachangelog.com). ## [Unreleased] +### Fixed +- Fix the `mustache` command to work from within the PHAR archive. + ## [4.1.3] - 2023-09-08 ### Changed - Updated project dependencies to current [moodle-cs](https://github.com/moodlehq/moodle-cs), [moodle-local_moodlecheck](https://github.com/moodlehq/moodle-local_moodlecheck) and [moodle-local_ci](https://github.com/moodlehq/moodle-local_ci) versions. Also, to various internal / development tools. diff --git a/src/Command/MustacheCommand.php b/src/Command/MustacheCommand.php index d671f577..45cb29f7 100644 --- a/src/Command/MustacheCommand.php +++ b/src/Command/MustacheCommand.php @@ -52,9 +52,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int $jarFile = $this->resolveJarFile(); // This is a workaround to execute mustache_lint.php file from within a phar. + // (by copying both the script and the jar file to a temporary directory) $filesystem = new Filesystem(); - $wrapper = tempnam(sys_get_temp_dir(), 'mustache-linter-wrapper'); + $tmpDir = sys_get_temp_dir(); + $wrapper = tempnam($tmpDir, 'mustache-linter-wrapper'); + $jarTmpFile = $tmpDir . '/vnu.jar'; $filesystem->dumpFile($wrapper, sprintf('copy($jarFile, $jarTmpFile, true); $code = 0; foreach ($files as $file) { @@ -68,7 +72,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int 'php', $wrapper, '--filename=' . $file, - '--validator=' . $jarFile, + '--validator=' . $jarTmpFile, '--basename=' . $this->moodle->directory, ]; // _JAVA_OPTIONS is something Travis CI started to set in Trusty. This breaks Mustache because @@ -82,6 +86,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int } $filesystem->remove($wrapper); + $filesystem->remove($jarTmpFile); return $code; } @@ -94,6 +99,11 @@ private function resolveJarFile(): string // Check if locally installed. $file = __DIR__ . '/../../vendor/moodlehq/moodle-local_ci/node_modules/vnu-jar/build/dist/vnu.jar'; if (is_file($file)) { + if (\Phar::running() !== '') { + // No need to use realpath() when running from a phar. + return $file; + } + return realpath($file); }