Skip to content

Commit

Permalink
install node_modules into buck-out
Browse files Browse the repository at this point in the history
Reviewed By: cpojer

Differential Revision: D4312220

fbshipit-source-id: 1449a194c557071bb5f0be6bc00dccef26c62b47
  • Loading branch information
davidaurelio authored and Facebook Github Bot committed Dec 13, 2016
1 parent f3a9dec commit 194604f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
7 changes: 4 additions & 3 deletions packager/react-packager/src/ModuleGraph/types.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import type {SourceMap} from './output/source-map';
import type {Console} from 'console';

export type Callback<A = void, B = void>
= (Error => mixed)
& ((null | void, A, B) => mixed);
= (Error => void)
& ((null | void, A, B) => void);

type Dependency = {|
id: string,
Expand Down Expand Up @@ -109,7 +109,6 @@ export type TransformFn = (
callback: Callback<TransformFnResult>
) => void;


export type TransformFnResult = {
ast: Object,
};
Expand All @@ -121,6 +120,8 @@ export type TransformResult = {|
map: ?Object,
|};

export type TransformVariants = {[key: string]: Object};

export type TransformedFile = {
code: string,
file: string,
Expand Down
4 changes: 2 additions & 2 deletions packager/react-packager/src/ModuleGraph/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
*/
'use strict';

const asyncify = require('async/asyncify');
const optimizeModule = require('./worker/optimize-module');
const transformModule = require('./worker/transform-module');
const wrapWorkerFn = require('./worker/wrap-worker-fn');
Expand All @@ -18,8 +19,7 @@ import type {OptimizationOptions} from './worker/optimize-module';
import type {TransformOptions} from './worker/transform-module';
import type {WorkerFnWithIO} from './worker/wrap-worker-fn';


exports.optimizeModule =
(wrapWorkerFn(optimizeModule): WorkerFnWithIO<OptimizationOptions>);
(wrapWorkerFn(asyncify(optimizeModule)): WorkerFnWithIO<OptimizationOptions>);
exports.transformModule =
(wrapWorkerFn(transformModule): WorkerFnWithIO<TransformOptions>);
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,20 @@ describe('optimizing JS modules', () => {
});
});

it('copies everything from the transformed file, except for transform results', done => {
optimizeModule(transformResult, optimizationOptions, (error, result) => {
const expected = JSON.parse(transformResult);
delete expected.transformed;
expect(result).toEqual(objectContaining(expected));
done();
});
it('copies everything from the transformed file, except for transform results', () => {
const result = optimizeModule(transformResult, optimizationOptions);
const expected = JSON.parse(transformResult);
delete expected.transformed;
expect(result).toEqual(objectContaining(expected));
});

describe('code optimization', () => {
let dependencyMapName, injectedVars, optimized, requireName;
beforeAll(done => {
optimizeModule(transformResult, optimizationOptions, (error, result) => {
optimized = result.transformed.default;
injectedVars = optimized.code.match(/function\(([^)]*)/)[1].split(',');
[requireName,,,, dependencyMapName] = injectedVars;
done();
});
beforeAll(() => {
const result = optimizeModule(transformResult, optimizationOptions);
optimized = result.transformed.default;
injectedVars = optimized.code.match(/function\(([^)]*)/)[1].split(',');
[requireName,,,, dependencyMapName] = injectedVars;
});

it('optimizes code', () => {
Expand All @@ -79,15 +75,12 @@ describe('optimizing JS modules', () => {
.toEqual(objectContaining(loc));
});

it('does not extract dependencies for polyfills', done => {
optimizeModule(
it('does not extract dependencies for polyfills', () => {
const result = optimizeModule(
transformResult,
{...optimizationOptions, isPolyfill: true},
(error, result) => {
expect(result.transformed.default.dependencies).toEqual([]);
done();
},
);
expect(result.transformed.default.dependencies).toEqual([]);
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const inline = require('../../JSTransformer/worker/inline').plugin;
const minify = require('../../JSTransformer/worker/minify');
const sourceMap = require('source-map');

import type {Callback, TransformedFile, TransformResult} from '../types.flow';
import type {TransformedFile, TransformResult} from '../types.flow';

export type OptimizationOptions = {|
dev: boolean,
Expand All @@ -27,19 +27,21 @@ export type OptimizationOptions = {|
|};

function optimizeModule(
json: string,
data: string | TransformedFile,
optimizationOptions: OptimizationOptions,
callback: Callback<TransformedFile>,
): void {
const data: TransformedFile = JSON.parse(json);
): TransformedFile {
if (typeof data === 'string') {
data = JSON.parse(data);
}
const {code, file, transformed} = data;
const result = {...data, transformed: {}};

//$FlowIssue #14545724
Object.entries(transformed).forEach(([k, t: TransformResult]: [*, TransformResult]) => {
result.transformed[k] = optimize(t, file, code, optimizationOptions);
});
callback(null, result);

return result;
}

function optimize(transformed, file, originalCode, options): TransformResult {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import type {
TransformFn,
TransformFnResult,
TransformResult,
TransformVariants,
} from '../types.flow';

type TransformVariants = {[key: string]: Object};
export type TransformOptions = {|
filename: string,
polyfill?: boolean,
Expand Down

0 comments on commit 194604f

Please sign in to comment.