History

js: require: allow custom module search paths via mp.module_paths

Avi Halachmi (:avih) committed 6 years ago

Commit 4fc5cd31 parent 3d2e30d2 files · +18 −4Browse files

Showing the changes to player/javascript (1 of 2 files). Show all

Unified · Split

player/javascript/defaults.js+10−4
@@ -375,6 +375,8 @@ function process_timers() { · 374 unmodified lines
375375 - Module id supports mpv path enhancements, e.g. ~/foo, ~~/bar, ~~desktop/baz
376376 *********************************************************************/
377377
378+mp.module_paths = ["~~/scripts/modules.js"]; // global modules search paths
379+
378380 // Internal meta top-dirs. Users should not rely on these names.
379381 var MODULES_META = "~~modules",
380382 SCRIPTDIR_META = "~~scriptdir", // relative script path -> meta absolute id
@@ -389,10 +391,14 @@ function resolve_module_file(id) { · 8 unmodified lines
389391 return mp.utils.join_path(main_script[0], rest);
390392
391393 if (base == MODULES_META) {
392− var path = mp.find_config_file("scripts/modules.js/" + rest);
393− if (!path)
394− throw(Error("Cannot find module file '" + rest + "'"));
395− return path;
394+ for (var i = 0; i < mp.module_paths.length; i++) {
395+ try {
396+ var f = mp.utils.join_path(mp.module_paths[i], rest);
397+ mp.utils.read_file(f, 1); // throws on any error
398+ return f;
399+ } catch (e) {}
400+ }
401+ throw(Error("Cannot find module file '" + rest + "'"));
396402 }
397403
398404 return id + ".js";

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t