strip-provides-module.js 844 B

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * Copyright (c) 2013-present, Facebook, Inc.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. 'use strict';
  8. var PluginError = require('plugin-error');
  9. var through = require('through2');
  10. var PM_REGEXP = require('./shared/provides-module').regexp;
  11. module.exports = function(opts) {
  12. function transform(file, enc, cb) {
  13. if (file.isNull()) {
  14. cb(null, file);
  15. return;
  16. }
  17. if (file.isStream()) {
  18. cb(new PluginError('module-map', 'Streaming not supported'));
  19. return;
  20. }
  21. // Get the @providesModule piece out of the file and save that.
  22. var contents = file.contents.toString().replace(PM_REGEXP, '');
  23. file.contents = new Buffer(contents);
  24. this.push(file);
  25. cb();
  26. }
  27. return through.obj(transform);
  28. };