Skip to content

Commit

Permalink
Merge pull request cypht-org#1264 from jacob-js/js_modules-fix
Browse files Browse the repository at this point in the history
Include js_modules files content in the final generated site.js
  • Loading branch information
kroky authored Oct 3, 2024
2 parents 068c970 + 13507e4 commit 8839654
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
4 changes: 1 addition & 3 deletions modules/core/output_modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -561,11 +561,9 @@ protected function output() {
$mod = str_replace(array('modules', DIRECTORY_SEPARATOR), '', $rel_name);
if (in_array($mod, $mods, true) && is_readable(sprintf("%ssite.js", $name))) {
$res .= '<script type="text/javascript" src="'.WEB_ROOT.sprintf("%ssite.js", $rel_name).'"></script>';
$res .= '<script type="module">';
foreach (glob($name.'js_modules' . DIRECTORY_SEPARATOR . '*.js') as $js) {
$res .= 'import "./'.WEB_ROOT.str_replace(APP_PATH, '', $js).'";';
$res .= '<script type="text/javascript" src="'.WEB_ROOT.str_replace(APP_PATH, '', $js).'"></script>';
}
$res .= '</script>';
}
}
if ($core) {
Expand Down
7 changes: 5 additions & 2 deletions scripts/config_gen.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,12 @@ function get_module_assignments($settings) {
$mods = get_modules($settings);
foreach ($mods as $mod) {
printf("scanning module %s ...\n", $mod);
if (is_readable(sprintf("modules/%s/site.js", $mod))) {
$js .= str_replace("'use strict';", '', file_get_contents(sprintf("modules/%s/site.js", $mod)));
foreach (glob('modules' . DIRECTORY_SEPARATOR . $mod . DIRECTORY_SEPARATOR . 'js_modules' . DIRECTORY_SEPARATOR . '*.js') as $js_module) {
$js .= file_get_contents($js_module);
}
if (is_readable(sprintf("modules/%s/site.js", $mod))) {
$js .= str_replace("'use strict';", '', file_get_contents(sprintf("modules/%s/site.js", $mod)));
}
if (is_readable(sprintf("modules/%s/site.css", $mod))) {
$css .= file_get_contents(sprintf("modules/%s/site.css", $mod));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/modules/core/output_modules_debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function test_page_js_debug() {
$this->assertEquals(array('<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script><script type="text/javascript" src="third_party/cash.min.js"></script><script type="text/javascript" src="third_party/resumable.min.js"></script><script type="text/javascript" src="third_party/ays-beforeunload-shim.js"></script><script type="text/javascript" src="third_party/jquery.are-you-sure.js"></script><script type="text/javascript" src="third_party/sortable.min.js"></script><script type="text/javascript" src="third_party/forge.min.js"></script><script type="text/javascript" src="modules/core/site.js"></script>'), $res->output_response);
$test->handler_response = array('encrypt_ajax_requests' => true, 'router_module_list' => array('imap'));
$res = $test->run();
$this->assertEquals(array('<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script><script type="text/javascript" src="third_party/cash.min.js"></script><script type="text/javascript" src="third_party/resumable.min.js"></script><script type="text/javascript" src="third_party/ays-beforeunload-shim.js"></script><script type="text/javascript" src="third_party/jquery.are-you-sure.js"></script><script type="text/javascript" src="third_party/sortable.min.js"></script><script type="text/javascript" src="third_party/forge.min.js"></script><script type="text/javascript" src="modules/core/site.js"></script><script type="text/javascript" src="modules/imap/site.js"></script><script type="module">import "./modules/imap/js_modules/Hm_Message.js";</script>'), $res->output_response);
$this->assertEquals(array('<script type="text/javascript" src="vendor/twbs/bootstrap/dist/js/bootstrap.bundle.min.js"></script><script type="text/javascript" src="third_party/cash.min.js"></script><script type="text/javascript" src="third_party/resumable.min.js"></script><script type="text/javascript" src="third_party/ays-beforeunload-shim.js"></script><script type="text/javascript" src="third_party/jquery.are-you-sure.js"></script><script type="text/javascript" src="third_party/sortable.min.js"></script><script type="text/javascript" src="third_party/forge.min.js"></script><script type="text/javascript" src="modules/core/site.js"></script><script type="text/javascript" src="modules/imap/site.js"></script><script type="text/javascript" src="modules/imap/js_modules/Hm_Message.js"></script>'), $res->output_response);
}
/**
* @preserveGlobalState disabled
Expand Down

0 comments on commit 8839654

Please sign in to comment.