mirror of
https://github.com/facebook/react.git
synced 2026-02-26 00:55:04 +00:00
Built files look the same up to parenthesization and quoting. This only saves 1.5 seconds out of ~20 on a clean build but it's a little simpler.
59 lines
1.6 KiB
JavaScript
Executable File
59 lines
1.6 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
// -*- mode: js -*-
|
|
// vim: set ft=javascript :
|
|
"use strict";
|
|
|
|
var babel = require('babel-core');
|
|
|
|
var constants = require('../vendor/constants')(babel);
|
|
|
|
require("commoner").version(
|
|
require("../package.json").version
|
|
).resolve(function(id) {
|
|
var context = this;
|
|
|
|
// Note that the result of context.getProvidedP() is cached for the
|
|
// duration of the build, so it is both consistent and cheap to
|
|
// evaluate multiple times.
|
|
return context.getProvidedP().then(function(idToPath) {
|
|
// If a module declares its own identifier using @providesModule
|
|
// then that identifier will be a key in the idToPath object.
|
|
if (idToPath.hasOwnProperty(id)) {
|
|
return context.readFileP(idToPath[id]);
|
|
}
|
|
|
|
// Otherwise assume the identifier maps directly to a path in the
|
|
// filesystem.
|
|
return context.readModuleP(id);
|
|
});
|
|
|
|
}).process(function(id, source) {
|
|
var context = this;
|
|
|
|
// This is where JSX, ES6, etc. desugaring happens.
|
|
source = babel.transform(source, {
|
|
blacklist: ['spec.functionName', 'validation.react'],
|
|
plugins: [constants],
|
|
filename: id
|
|
}).code;
|
|
|
|
if (context.config.mocking) {
|
|
// Make sure there is exactly one newline at the end of the module.
|
|
source = source.replace(/\s+$/m, "\n");
|
|
|
|
return context.getProvidedP().then(function(idToPath) {
|
|
if (id !== "mock-modules" &&
|
|
id !== "mocks" &&
|
|
id !== "test/all" &&
|
|
idToPath.hasOwnProperty("mock-modules")) {
|
|
return source + '\nrequire("mock-modules").register(' +
|
|
JSON.stringify(id) + ', module);\n';
|
|
}
|
|
|
|
return source;
|
|
});
|
|
}
|
|
|
|
return source;
|
|
});
|