FFFF Add packager worker for Buck · devagul93/react-native@fa44607 · GitHub
Skip to content

Commit fa44607

Browse files
sam-swarrFacebook Github Bot 6
authored andcommitted
Add packager worker for Buck
Reviewed By: martinbigio Differential Revision: D3051886 fb-gh-sync-id: da19ee987c0ec04cde550147d57bd90d98712e14 shipit-source-id: da19ee987c0ec04cde550147d57bd90d98712e14
1 parent 22e55d4 commit fa44607

File tree

4 files changed

+78
-59
lines changed

4 files changed

+78
-59
lines changed

local-cli/bundle/buildBundle.js

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
9-
'use strict';
109

1110
const log = require('../util/log').out('bundle');
1211
const outputBundle = require('./output/bundle');
1312
const Promise = require('promise');
1413
const ReactPackager = require('../../packager/react-packager');
1514
const saveAssets = require('./saveAssets');
1615

17-
function buildBundle(args, config, output = outputBundle) {
16+
function buildBundle(args, config, output = outputBundle, packagerInstance) {
1817
return new Promise((resolve, reject) => {
1918

2019
// This is used by a bazillion of npm modules we don't control so we don't
@@ -38,25 +37,34 @@ function buildBundle(args, config, output = outputBundle) {
3837
platform: args.platform,
3938
};
4039

41-
const clientPromise = ReactPackager.createClientFor(options);
40+
var bundlePromise;
41+
if (packagerInstance) {
42+
bundlePromise = output.build(packagerInstance, requestOpts)
43+
.then(bundle => {
44+
output.save(bundle, args, log);
45+
return bundle;
46+
});
47+
} else {
48+
const clientPromise = ReactPackager.createClientFor(options);
4249

43-
// Build and save the bundle
44-
const bundlePromise = clientPromise
45-
.then(client => {
46-
log('Created ReactPackager');
47-
return output.build(client, requestOpts);
48-
})
49-
.then(bundle => {
50-
output.save(bundle, args, log);
51-
return bundle;
52-
});
50+
// Build and save the bundle
51+
bundlePromise = clientPromise
52+
.then(client => {
53+
log('Created ReactPackager');
54+
return output.build(client, requestOpts);
55+
})
56+
.then(bundle => {
57+
output.save(bundle, args, log);
58+
return bundle;
59+
});
5360

54-
// When we're done bundling, close the client
55-
Promise.all([clientPromise, bundlePromise])
56-
.then(([client]) => {
57-
log('Closing client');
58-
client.close();
59-
});
61+
// When we're done bundling, close the client
62+
Promise.all([clientPromise, bundlePromise])
63+
.then(([client]) => {
64+
log('Closing client');
65+
client.close();
66+
});
67+
}
6068

6169
// Save the assets of the bundle
6270
const assets = bundlePromise

local-cli/bundle/bundle.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
9-
'use strict';
109

1110
const buildBundle = require('./buildBundle');
1211
const bundleCommandLineArgs = require('./bundleCommandLineArgs');
@@ -17,17 +16,17 @@ const outputPrepack = require('./output/prepack');
1716
/**
1817
* Builds the bundle starting to look for dependencies at the given entry path.
1918
*/
20-
function bundleWithOutput(argv, config, output) {
19+
function bundleWithOutput(argv, config, output, packagerInstance) {
2120
const args = parseCommandLine(bundleCommandLineArgs, argv);
2221
if (!output) {
2322
output = args.prepack ? outputPrepack : outputBundle;
2423
}
25-
return buildBundle(args, config, output);
24+
return b 402E uildBundle(args, config, output, packagerInstance);
2625

2726
}
2827

29-
function bundle(argv, config) {
30-
return bundleWithOutput(argv, config);
28+
function bundle(argv, config, packagerInstance) {
29+
return bundleWithOutput(argv, config, undefined, packagerInstance);
3130
}
3231

3332
module.exports = bundle;

local-cli/bundle/unbundle.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
9-
'use strict';
109

1110
const bundleWithOutput = require('./bundle').withOutput;
1211
const outputUnbundle = require('./output/unbundle');
1312

1413
/**
1514
* Builds the bundle starting to look for dependencies at the given entry path.
1615
*/
17-
function unbundle(argv, config) {
18-
return bundleWithOutput(argv, config, outputUnbundle);
16+
function unbundle(argv, config, packagerInstance) {
17+
return bundleWithOutput(argv, config, outputUnbundle, packagerInstance);
1918
}
2019

2120
module.exports = 4B6C unbundle;

local-cli/dependencies/dependencies.js

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
* LICENSE file in the root directory of this source tree. An additional grant
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
9-
'use strict';
109

1110
const fs = require('fs');
12-
const log = require('../util/log').out('dependencies');
1311
const parseCommandLine = require('../util/parseCommandLine');
1412
const path = require('path');
1513
const Promise = require('promise');
@@ -18,13 +16,13 @@ const ReactPackager = require('../../packager/react-packager');
1816
/**
1917
* Returns the dependencies an entry path has.
2018
*/
21-
function dependencies(argv, config) {
19+
function dependencies(argv, config, packagerInstance) {
2220
return new Promise((resolve, reject) => {
23-
_dependencies(argv, config, resolve, reject);
21+
_dependencies(argv, config, resolve, reject, packagerInstance);
2422
});
2523
}
2624

27-
function _dependencies(argv, config, resolve, reject) {
25+
function _dependencies(argv, config, resolve, reject, packagerInstance) {
2826
const args = parseCommandLine([
2927
{
3028
command: 'entry-file',
@@ -82,35 +80,50 @@ function _dependencies(argv, config, resolve, reject) {
8280
? fs.createWriteStream(args.output)
8381
: process.stdout;
8482

85-
// TODO: allow to configure which logging namespaces should get logged
86-
// log('Running ReactPackager');
87-
// log('Waiting for the packager.');
88-
resolve(ReactPackager.createClientFor(packageOpts).then(client => {
89-
// log('Packager client was created');
90-
return client.getOrderedDependencyPaths(options)
91-
.then(deps => {
92-
// log('Packager returned dependencies');
93-
client.close();
4B6C
83+
if (packagerInstance) {
84+
resolve(packagerInstance.getOrderedDependencyPaths(options).then(
85+
deps => {
86+
return _dependenciesHandler(
87+
deps,
88+
packageOpts.projectRoots,
89+
outStream,
90+
writeToFile
91+
);
92+
}
93+
));
94+
} else {
95+
resolve(ReactPac 74B2 kager.createClientFor(packageOpts).then(client => {
96+
return client.getOrderedDependencyPaths(options)
97+
.then(deps => {
98+
client.close();
99+
return _dependenciesHandler(
100+
deps,
101+
packageOpts.projectRoots,
102+
outStream,
103+
writeToFile
104+
);
105+
});
106+
}));
107+
}
108+
}
94109

95-
deps.forEach(modulePath => {
96-
// Temporary hack to disable listing dependencies not under this directory.
97-
// Long term, we need either
98-
// (a) JS code to not depend on anything outside this directory, or
99-
// (b) Come up with a way to declare this dependency in Buck.
100-
const isInsideProjectRoots = packageOpts.projectRoots.filter(
101-
root => modulePath.startsWith(root)
102-
).length > 0;
110+
function _dependenciesHandler(deps, projectRoots, outStream, writeToFile) {
111+
deps.forEach(modulePath => {
112+
// Temporary hack to disable listing dependencies not under this directory.
113+
// Long term, we need either
114+
// (a) JS code to not depend on anything outside this directory, or
115+
// (b) Come up with a way to declare this dependency in Buck.
116+
const isInsideProjectRoots = projectRoots.filter(
117+
root => modulePath.startsWith(root)
118+
).length > 0;
103119

104-
if (isInsideProjectRoots) {
105-
outStream.write(modulePath + '\n');
106-
}
107-
});
108-
return writeToFile
109-
? Promise.denodeify(outStream.end).bind(outStream)()
110-
: Promise.resolve();
111-
// log('Wrote dependencies to output file');
112-
});
113-
}));
120+
if (isInsideProjectRoots) {
121+
outStream.write(modulePath + '\n');
122+
}
123+
});
124+
return writeToFile
125+
? Promise.denodeify(outStream.end).bind(outStream)()
126+
: Promise.resolve();
114127
}
115128

116129
module.exports = dependencies;

0 commit comments

Comments
 (0)