In some scenarios it's not desirable to build an entire project, or build files on change, but to build separate files on the fly as they are being loaded. This is a very common scenario in testing, where the test suite may need to be built, and the targets under test may also very well need to be built. Many test runners include the ability to load a module before running any tests, that enable such functionality – tape for instance, has this very feature.
Expected Behavior
When running tests, I expect to be able to load a special module, that hooks into the runtime environment and changes how modules are loaded. The precedent set by babel-register is good, and easy to work with.
There are essentially two scenarios that need to be covered:
-
Registered as the first import (or require) and thus overriding any subsequent imports – e.g.:
require('ez-build/JIT') // This overrides the normal loader
require('some-module') // This is now JIT compiled
-
Preloaded by node or another runtime, e.g.: node -r ez-build/JIT program.js or tape -r ez-build/JIT test/*.js
Passing options to ez-build is probably overkill, but could be implemented after the fact anyway.
For implementation inspiration, the babel-register source is a fairly simple read.
Current Behavior
Currently, it's not possible to run ez-build this way. You can run it interactively, which will recompile specific files as they change. Essentially this is the same as the JIT build explained above, it's just a different way of getting the names and paths of files being loaded.
Not having this functionality makes it more difficult to accurately test projects built with ez-build, since you effectively have to recreate the internal configuration of ez-build which is both difficult to get right, and may very well change over time which makes it difficult to maintain.
Considerations
Ideally, tests should test the optimized output of ez-build, not just intermediate output – however this would add considerable overhead in a development environment where you're constantly re-running tests. The overhead may not be very much, perhaps a few seconds at worst, which isn't too bad in a CI environment but is very cumbersome in a development environment. It's not immediately apparent to me how to achieve this. One way might be to have two different JIT modules, one for development, which really just JITs files as they are loaded, and a "production" JIT module which would first perform a --production build of the project, then remap all modules to the optimized output as opposed to individual files, and finally JIT any other modules being loaded (i.e. test modules.)
Ideally though, there should be no functional differences between intermediate builds and optimized builds – and if that's the case, this whole point is moot since it's fine to just JIT everything and never test the optimized output. That's clearly the cowboy option.
In some scenarios it's not desirable to build an entire project, or build files on change, but to build separate files on the fly as they are being loaded. This is a very common scenario in testing, where the test suite may need to be built, and the targets under test may also very well need to be built. Many test runners include the ability to load a module before running any tests, that enable such functionality – tape for instance, has this very feature.
Expected Behavior
When running tests, I expect to be able to load a special module, that hooks into the runtime environment and changes how modules are loaded. The precedent set by babel-register is good, and easy to work with.
There are essentially two scenarios that need to be covered:
Registered as the first
import(orrequire) and thus overriding any subsequent imports – e.g.:Preloaded by node or another runtime, e.g.:
node -r ez-build/JIT program.jsortape -r ez-build/JIT test/*.jsPassing options to ez-build is probably overkill, but could be implemented after the fact anyway.
For implementation inspiration, the babel-register source is a fairly simple read.
Current Behavior
Currently, it's not possible to run ez-build this way. You can run it interactively, which will recompile specific files as they change. Essentially this is the same as the JIT build explained above, it's just a different way of getting the names and paths of files being loaded.
Not having this functionality makes it more difficult to accurately test projects built with ez-build, since you effectively have to recreate the internal configuration of ez-build which is both difficult to get right, and may very well change over time which makes it difficult to maintain.
Considerations
Ideally, tests should test the optimized output of ez-build, not just intermediate output – however this would add considerable overhead in a development environment where you're constantly re-running tests. The overhead may not be very much, perhaps a few seconds at worst, which isn't too bad in a CI environment but is very cumbersome in a development environment. It's not immediately apparent to me how to achieve this. One way might be to have two different JIT modules, one for development, which really just JITs files as they are loaded, and a "production" JIT module which would first perform a
--productionbuild of the project, then remap all modules to the optimized output as opposed to individual files, and finally JIT any other modules being loaded (i.e. test modules.)Ideally though, there should be no functional differences between intermediate builds and optimized builds – and if that's the case, this whole point is moot since it's fine to just JIT everything and never test the optimized output. That's clearly the cowboy option.