mirror of
https://github.com/zebrajr/react.git
synced 2025-12-07 00:20:28 +01:00
* Use relative paths in packages/react * Use relative paths in packages/react-art * Use relative paths in packages/react-cs * Use relative paths in other packages * Fix as many issues as I can This uncovered an interesting problem where ./b from package/src/a would resolve to a different instantiation of package/src/b in Jest. Either this is a showstopper or we can solve it by completely fobbidding remaining /src/. * Fix all tests It seems we can't use relative requires in tests anymore. Otherwise Jest becomes confused between real file and symlink. https://github.com/facebook/jest/issues/3830 This seems bad... Except that we already *don't* want people to create tests that import individual source files. All existing cases of us doing so are actually TODOs waiting to be fixed. So perhaps this requirement isn't too bad because it makes bad code looks bad. Of course, if we go with this, we'll have to lint against relative requires in tests. It also makes moving things more painful. * Prettier * Remove @providesModule * Fix remaining Haste imports I missed earlier * Fix up paths to reflect new flat structure * Fix Flow * Fix CJS and UMD builds * Fix FB bundles * Fix RN bundles * Prettier * Fix lint * Fix warning printing and error codes * Fix buggy return * Fix lint and Flow * Use Yarn on CI * Unbreak Jest * Fix lint * Fix aliased originals getting included in DEV Shouldn't affect correctness (they were ignored) but fixes DEV size regression. * Record sizes * Fix weird version in package.json * Tweak bundle labels * Get rid of output option by introducing react-dom/server.node * Reconciler should depend on prop-types * Update sizes last time
94 lines
2.8 KiB
JavaScript
94 lines
2.8 KiB
JavaScript
'use strict';
|
|
|
|
// React's test can only work in NODE_ENV=test because of how things
|
|
// are set up. So we might as well enforce it.
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
var fs = require('fs');
|
|
var path = require('path');
|
|
|
|
var babel = require('babel-core');
|
|
var coffee = require('coffee-script');
|
|
|
|
var tsPreprocessor = require('./ts-preprocessor');
|
|
var createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction');
|
|
|
|
// Use require.resolve to be resilient to file moves, npm updates, etc
|
|
var pathToBabel = path.join(
|
|
require.resolve('babel-core'),
|
|
'..',
|
|
'package.json'
|
|
);
|
|
var pathToModuleMap = require.resolve('fbjs/module-map');
|
|
var pathToBabelPluginDevWithCode = require.resolve(
|
|
'../error-codes/replace-invariant-error-codes'
|
|
);
|
|
var pathToBabelPluginModules = require.resolve(
|
|
'fbjs-scripts/babel-6/rewrite-modules'
|
|
);
|
|
var pathToBabelPluginAsyncToGenerator = require.resolve(
|
|
'babel-plugin-transform-async-to-generator'
|
|
);
|
|
var pathToBabelrc = path.join(__dirname, '..', '..', '.babelrc');
|
|
var pathToErrorCodes = require.resolve('../error-codes/codes.json');
|
|
|
|
// TODO: make sure this stays in sync with gulpfile
|
|
var babelOptions = {
|
|
plugins: [
|
|
pathToBabelPluginDevWithCode,
|
|
// Keep stacks detailed in tests.
|
|
// Don't put this in .babelrc so that we don't embed filenames
|
|
// into ReactART builds that include JSX.
|
|
// TODO: I have not verified that this actually works.
|
|
require.resolve('babel-plugin-transform-react-jsx-source'),
|
|
],
|
|
retainLines: true,
|
|
};
|
|
|
|
module.exports = {
|
|
process: function(src, filePath) {
|
|
// Resolve the path so we can tell our own packages from node_modules.
|
|
filePath = fs.realpathSync(filePath);
|
|
|
|
if (filePath.match(/\.coffee$/)) {
|
|
return coffee.compile(src, {bare: true});
|
|
}
|
|
if (filePath.match(/\.ts$/) && !filePath.match(/\.d\.ts$/)) {
|
|
return tsPreprocessor.compile(src, filePath);
|
|
}
|
|
if (
|
|
!filePath.match(/\/node_modules\//) &&
|
|
!filePath.match(/\/third_party\//)
|
|
) {
|
|
// for test files, we also apply the async-await transform, but we want to
|
|
// make sure we don't accidentally apply that transform to product code.
|
|
var isTestFile = !!filePath.match(/\/__tests__\//);
|
|
return babel.transform(
|
|
src,
|
|
Object.assign(
|
|
{filename: path.relative(process.cwd(), filePath)},
|
|
babelOptions,
|
|
isTestFile
|
|
? {
|
|
plugins: [pathToBabelPluginAsyncToGenerator].concat(
|
|
babelOptions.plugins
|
|
),
|
|
}
|
|
: {}
|
|
)
|
|
).code;
|
|
}
|
|
return src;
|
|
},
|
|
|
|
getCacheKey: createCacheKeyFunction([
|
|
__filename,
|
|
pathToBabel,
|
|
pathToBabelrc,
|
|
pathToModuleMap,
|
|
pathToBabelPluginDevWithCode,
|
|
pathToBabelPluginModules,
|
|
pathToErrorCodes,
|
|
]),
|
|
};
|