Minor questions on new module BNF

Jeff Morrison lbljeffmo at gmail.com
Wed Jun 5 15:41:09 PDT 2013


I haven't played with Browserify too much myself (shame on me), but from 
my own understanding of it and after talking to a friend who is more 
familiar, yes I believe so.

We "link" our modules statically on the server to build a dependency 
graph before we push to production. This linking step is based on 
require() call expressions found in the module, no matter where the call 
expression is located in the module. If we find one, it becomes a 
blocking dependency for the file. (we also have a separate API for 
non-blocking dependencies, but that's not too pertinent to this thread)

So the following two modules will become "available for execution" at 
the same time -- when (or some point after) both Dep1 and Dep2 have been 
downloaded but not necessarily evaluated:

/**
  * ModuleA
  */
var Dep1 = require('Dep1'); // evaluate Dep1 synchronously if we haven't 
already
var Dep2 = require('Dep2'); // evaluate Dep2 synchronously if we haven't 
already
function foo() {
   Dep1.blah();
}
function bar() {
   Dep2.blah();
}
export.foo = foo;
export.bar = bar;

/**
  * ModuleB
  */
function foo() {
   require('Dep1').blah(); // evaluate Dep1 synchronously if we haven't 
already
}
function bar() {
   require('Dep2').blah(); // evaluate Dep2 synchronously if we haven't 
already
}

The only difference between the two modules is that ModuleA will force 
evaluattion of both Dep1 and Dep2 when it runs, and ModuleB will not 
force execution until runtime invocation in one of the foo/bar functions.

-Jeff

On 6/5/13 7:55 AM, Brendan Eich wrote:
> Jeff Morrison wrote:
>> require() is a synchronous call in to our module system, and we don't 
>> execute a given module until all of its require() dependencies have 
>> been downloaded.
>
> Hi Jeff, catching up (sorry if I missed it): do you do a 
> browserify-style analysis for require("...") calls and hoist|uniq 
> them, then prefetch them?
>
> /be



More information about the es-discuss mailing list