Had a play with this over the weekend and seem to be getting some where.
First test I tried though is absolute, and its falling over trying to import
/tests/modules/1.0/absolute/b.js from
/tests/modules/1.0/absolute/submodule/a.js
Now b.js exists but a.js is including it via the term "b" which to me would mean its expecting it to be in the same folder but its not. That got me thinking that I've not got my head around this correctly.
I need to ask some questions though just to clear up some queries to make sure I have a understanding of how all this is to work (sorry but I struggle with NASA style clarity of language alot, prefer samples).
-
Module identifiers may be "relative" or "top-level". A module identifier is "relative" if the first term is "." or ".."So if "." or ".." then it HAS to be top-level. As in it has to be relative from the root:
So in file /work/test.js:
require("a") --> /a ?
require("./b" --> /work/b
require("/c") --> /c
require("../d") --> /d
I'd have thought require("a") would look in the same folder as the calling file? Confused :(
-
Top-level identifiers are resolved off the conceptual module name space root.
Does this answer my query above? What the hell is the conceptual module name space root? :)
-
Relative identifiers are resolved relative to the identifier of the module in which "require" is written and called
I think this is the reason my codes not running. Heres how I "think" it should be working, please correct me if wrong:
/modules/1.0/absolute/program requires:
- "test" --> Who's working directory should be the same as program (/modules/1.0/absolute)
- "submodule/a" --> same wd as test (think this is where I'm going wrong though, think I'm assuming its wd is /modules/1.0/absolute/submodule)
- "b" --> same wd as test
/modules/1.0/absolute/test requires nothing
/modules/1.0/absolute/submodule/a requires
- "b" --> but its looking relative in /modules/1.0/absolute/submodule so does not find it as it "should" be looking in /modules/1.0/absolute as thats where "a" was originally included from? EG the working directory should not have changed
//modules/1.0/absolute/b requires nothing
Hmmm even writting it out here has made it a little clear but would still like something to double check if someone could?
-
If there is a dependency cycle, the foreign module may not
have finished executing at the time it is required by one of its
transitive dependencies; in this case, the object returned by "require"
must contain at least the exports that the foreign module has prepared
before the call to require that led to the current module's execution.Do you mean module a includes b which includes c which in turn includes a? So a never returns. How the heck do you stop that happening?
Cheers
Pete