totaljs / framework

Node.js framework
http://www.totaljs.com
Other
4.36k stars 450 forks source link

Improved /dependencies file require() logic for relative/absolute paths #601

Closed TemaSM closed 6 years ago

TemaSM commented 6 years ago

Current /dependencies file logic doesn't allow to use paths relative to root of Total.js project, only absolute like this:

module  (1 minute) : ~/Volumes/Development/modules/Miscellaneous/clienterror.js

If resolution fails, Total.js throws Error.

This commit changes behavior of resolving & requiring deps, so everyone may use both absolute & relative paths for deps:

Absolute (wherever the file is located):

module  (1 minute) : ~/Volumes/Development/modules/Miscellaneous/clienterror.js 

Relative to project root

module  (1 minute) : ~/plugins/clienterror.js
// or
module  (1 minute) : ~./plugins/clienterror.js

The behavior similar to Node.js core modules resolving - first it tries to locate file locally relative to project root, then it tries to locate it via absolute path.

So, now you can use your /dependencies wherever they are located in (absolutely static or relatively path)