mirror of
https://github.com/zebrajr/react.git
synced 2026-01-15 12:15:22 +00:00
Use fbjs package from npm, gulp
This reworks a few things in building and distributing React. The biggest change is using fbjs to share dependencies with other libraries. We're also using Gulp for some build steps.
This commit is contained in:
1
scripts/jest/environment.js
Normal file
1
scripts/jest/environment.js
Normal file
@@ -0,0 +1 @@
|
||||
__DEV__ = true;
|
||||
71
scripts/jest/jest.d.ts
vendored
Normal file
71
scripts/jest/jest.d.ts
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
declare var jasmine: any;
|
||||
|
||||
declare function afterEach(fn: any): any;
|
||||
declare function beforeEach(fn: any): any;
|
||||
declare function describe(name: string, fn: any): void;
|
||||
declare var it: {
|
||||
(name: string, fn: any): void;
|
||||
only: (name: string, fn: any) => void;
|
||||
}
|
||||
declare function expect(val: any): Expect;
|
||||
declare var jest: Jest;
|
||||
declare function pit(name: string, fn: any): void;
|
||||
declare function spyOn(obj: any, key: string): any;
|
||||
declare function xdescribe(name: string, fn: any): void;
|
||||
declare function xit(name: string, fn: any): void;
|
||||
|
||||
interface Expect {
|
||||
not: Expect
|
||||
toThrow(message?: string): void
|
||||
toBe(value: any): void
|
||||
toEqual(value: any): void
|
||||
toBeFalsy(): void
|
||||
toBeTruthy(): void
|
||||
toBeNull(): void
|
||||
toBeUndefined(): void
|
||||
toBeDefined(): void
|
||||
toMatch(regexp: RegExp): void
|
||||
toContain(string: string): void
|
||||
toBeCloseTo(number: number, delta: number): void
|
||||
toBeGreaterThan(number: number): void
|
||||
toBeLessThan(number: number): void
|
||||
toBeCalled(): void
|
||||
toBeCalledWith(...arguments): void
|
||||
lastCalledWith(...arguments): void
|
||||
}
|
||||
|
||||
interface Jest {
|
||||
autoMockOff(): void
|
||||
autoMockOn(): void
|
||||
clearAllTimers(): void
|
||||
dontMock(moduleName: string): void
|
||||
genMockFromModule(moduleObj: Object): Object
|
||||
genMockFunction(): MockFunction
|
||||
genMockFn(): MockFunction
|
||||
mock(moduleName: string): void
|
||||
runAllTicks(): void
|
||||
runAllTimers(): void
|
||||
runOnlyPendingTimers(): void
|
||||
setMock(moduleName: string, moduleExports: Object): void
|
||||
}
|
||||
|
||||
interface MockFunction {
|
||||
(...arguments): any
|
||||
mock: {
|
||||
calls: Array<Array<any>>
|
||||
instances: Array<Object>
|
||||
}
|
||||
mockClear(): void
|
||||
mockImplementation(fn: Function): MockFunction
|
||||
mockImpl(fn: Function): MockFunction
|
||||
mockReturnThis(): MockFunction
|
||||
mockReturnValue(value: any): MockFunction
|
||||
mockReturnValueOnce(value: any): MockFunction
|
||||
}
|
||||
|
||||
// Allow importing jasmine-check
|
||||
declare module 'jasmine-check' {
|
||||
export function install(global?: any): void;
|
||||
}
|
||||
declare var check: any;
|
||||
declare var gen: any;
|
||||
50
scripts/jest/preprocessor.js
Normal file
50
scripts/jest/preprocessor.js
Normal file
@@ -0,0 +1,50 @@
|
||||
'use strict';
|
||||
|
||||
var babel = require('babel');
|
||||
var coffee = require('coffee-script');
|
||||
|
||||
var tsPreprocessor = require('./ts-preprocessor');
|
||||
|
||||
var defaultLibraries = [
|
||||
require.resolve('./jest.d.ts'),
|
||||
require.resolve('../../src/isomorphic/modern/class/React.d.ts'),
|
||||
];
|
||||
|
||||
var ts = tsPreprocessor(defaultLibraries);
|
||||
|
||||
// This assumes the module map has been built. This might not be safe.
|
||||
// We should consider consuming this from a built fbjs module from npm.
|
||||
var moduleMap = require('fbjs/module-map');
|
||||
var babelPluginDEV = require('fbjs/scripts/babel/dev-expression');
|
||||
var babelPluginRequires = require('fbjs/scripts/babel/rewrite-requires');
|
||||
|
||||
module.exports = {
|
||||
process: function(src, path) {
|
||||
if (path.match(/\.coffee$/)) {
|
||||
return coffee.compile(src, {'bare': true});
|
||||
}
|
||||
if (path.match(/\.ts$/) && !path.match(/\.d\.ts$/)) {
|
||||
return ts.compile(src, path);
|
||||
}
|
||||
// TODO: make sure this stays in sync with gulpfile
|
||||
if (!path.match(/\/node_modules\//) && !path.match(/\/third_party\//)) {
|
||||
var rv = babel.transform(src, {
|
||||
nonStandard: true,
|
||||
blacklist: [
|
||||
'spec.functionName',
|
||||
'validation.react',
|
||||
],
|
||||
optional: [
|
||||
'es7.trailingFunctionCommas',
|
||||
],
|
||||
plugins: [babelPluginDEV, babelPluginRequires],
|
||||
ignore: ['third_party'],
|
||||
filename: path,
|
||||
retainLines: true,
|
||||
_moduleMap: moduleMap,
|
||||
}).code;
|
||||
return rv;
|
||||
}
|
||||
return src;
|
||||
},
|
||||
};
|
||||
73
scripts/jest/ts-preprocessor.js
Normal file
73
scripts/jest/ts-preprocessor.js
Normal file
@@ -0,0 +1,73 @@
|
||||
'use strict';
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var ts = require('typescript');
|
||||
|
||||
var tsOptions = {module: 'commonjs'};
|
||||
|
||||
function formatErrorMessage(error) {
|
||||
return (
|
||||
error.file.filename + '(' +
|
||||
error.file.getLineAndCharacterFromPosition(error.start).line +
|
||||
'): ' +
|
||||
error.messageText
|
||||
);
|
||||
}
|
||||
|
||||
function compile(defaultLib, content, contentFilename) {
|
||||
var output = null;
|
||||
var compilerHost = {
|
||||
getSourceFile: function(filename, languageVersion) {
|
||||
if (filename === contentFilename) {
|
||||
return ts.createSourceFile(filename, content, 'ES5', '0');
|
||||
}
|
||||
return defaultLib;
|
||||
},
|
||||
writeFile: function(name, text, writeByteOrderMark) {
|
||||
if (output === null) {
|
||||
output = text;
|
||||
} else {
|
||||
throw new Error('Expected only one dependency.');
|
||||
}
|
||||
},
|
||||
getCanonicalFileName: function(filename) {
|
||||
return filename;
|
||||
},
|
||||
getCurrentDirectory: function() {
|
||||
return '';
|
||||
},
|
||||
getNewLine: function() {
|
||||
return '\n';
|
||||
},
|
||||
};
|
||||
var program = ts.createProgram([contentFilename], tsOptions, compilerHost);
|
||||
var errors = program.getDiagnostics();
|
||||
if (!errors.length) {
|
||||
var checker = program.getTypeChecker(true);
|
||||
errors = checker.getDiagnostics();
|
||||
checker.emitFiles();
|
||||
}
|
||||
if (errors.length) {
|
||||
throw new Error(errors.map(formatErrorMessage).join('\n'));
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
module.exports = function(defaultLibs) {
|
||||
var defaultLibSource = fs.readFileSync(
|
||||
path.join(path.dirname(require.resolve('typescript')), 'lib.d.ts')
|
||||
);
|
||||
|
||||
for (var i = 0; i < defaultLibs.length; i++) {
|
||||
defaultLibSource += '\n' + fs.readFileSync(defaultLibs[i]);
|
||||
}
|
||||
|
||||
var defaultLibSourceFile = ts.createSourceFile(
|
||||
'lib.d.ts', defaultLibSource, 'ES5'
|
||||
);
|
||||
|
||||
return {
|
||||
compile: compile.bind(null, defaultLibSourceFile),
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user