stitch icon indicating copy to clipboard operation
stitch copied to clipboard

Make caching a little smarter.

Open masegraye opened this issue 13 years ago • 4 comments

CommonJS dictates that if a module has been required in the past, its exports should be cached and returned the next time require is called for that module in the same runtime.

Currently, Stitch does not return cached modules if they're only found after adding "/index" to the require name.

Example module structure:

mf/
    index.coffee
    events.coffee

If I call:

require("mf/events");
require("mf/events");

the contents of mf/events.coffee will only be executed once, as expected. However, if I call:

require("mf");
require("mf");

the contents of mf/index.coffee will be executed twice. This fixes that.

masegraye avatar Mar 01 '12 04:03 masegraye

Fantastic. Could you add a test case for this too?

sstephenson avatar Mar 01 '12 05:03 sstephenson

Word.

masegraye avatar Mar 01 '12 05:03 masegraye

Done, by the by. :)

masegraye avatar Mar 05 '12 06:03 masegraye

Bump.

masegraye avatar Jul 25 '12 05:07 masegraye