commonize 717 B

123456789101112131415161718192021
  1. #!/usr/bin/env node
  2. require("commoner").resolve(function(id) {
  3. var context = this;
  4. return context.getProvidedP().then(function(idToPath) {
  5. // If a module declares its own identifier using @providesModule
  6. // then that identifier will be a key in the idToPath object.
  7. if (idToPath.hasOwnProperty(id))
  8. return context.readFileP(idToPath[id]);
  9. });
  10. }, function(id) {
  11. // Otherwise assume the identifier maps directly to a filesystem path.
  12. return this.readModuleP(id);
  13. }).process(function(id, source) {
  14. // As a simple example of a processing step, make sure the file ends
  15. // with exactly one newline character.
  16. return source.replace(/\s+$/m, "\n");
  17. });