2015-09-22 16:00:04 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
2016-11-08 20:19:36 +00:00
|
|
|
'use strict';
|
2015-09-22 16:00:04 +00:00
|
|
|
|
2016-11-08 20:19:36 +00:00
|
|
|
const ReactPackager = require('../../packager/react-packager');
|
|
|
|
|
|
|
|
const denodeify = require('denodeify');
|
2015-09-22 16:00:04 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
function dependencies(argv, config, args, packagerInstance) {
|
|
|
|
const rootModuleAbsolutePath = args.entryFile;
|
2015-09-22 16:00:04 +00:00
|
|
|
if (!fs.existsSync(rootModuleAbsolutePath)) {
|
2016-07-30 15:59:16 +00:00
|
|
|
return Promise.reject(`File ${rootModuleAbsolutePath} does not exist`);
|
2015-09-22 16:00:04 +00:00
|
|
|
}
|
|
|
|
|
2016-07-01 13:56:11 +00:00
|
|
|
const transformModulePath =
|
|
|
|
args.transformer ? path.resolve(args.transformer) :
|
|
|
|
typeof config.getTransformModulePath === 'function' ? config.getTransformModulePath() :
|
|
|
|
undefined;
|
2016-06-22 15:08:28 +00:00
|
|
|
|
2015-10-05 16:15:09 +00:00
|
|
|
const packageOpts = {
|
|
|
|
projectRoots: config.getProjectRoots(),
|
2016-09-23 14:59:59 +00:00
|
|
|
blacklistRE: config.getBlacklistRE(),
|
2016-11-28 15:27:09 +00:00
|
|
|
getTransformOptions: config.getTransformOptions,
|
2017-02-27 18:48:17 +00:00
|
|
|
hasteImpl: config.hasteImpl,
|
2016-06-22 15:08:28 +00:00
|
|
|
transformModulePath: transformModulePath,
|
2016-04-28 13:32:52 +00:00
|
|
|
extraNodeModules: config.extraNodeModules,
|
2015-10-20 18:51:15 +00:00
|
|
|
verbose: config.verbose,
|
2015-09-22 16:00:04 +00:00
|
|
|
};
|
|
|
|
|
2015-10-05 16:15:09 +00:00
|
|
|
const relativePath = packageOpts.projectRoots.map(root =>
|
2015-09-22 16:00:04 +00:00
|
|
|
path.relative(
|
|
|
|
root,
|
|
|
|
rootModuleAbsolutePath
|
|
|
|
)
|
|
|
|
)[0];
|
|
|
|
|
2015-09-29 05:40:56 +00:00
|
|
|
const options = {
|
|
|
|
platform: args.platform,
|
|
|
|
entryFile: relativePath,
|
|
|
|
};
|
|
|
|
|
2015-09-22 16:00:04 +00:00
|
|
|
const writeToFile = args.output;
|
|
|
|
const outStream = writeToFile
|
|
|
|
? fs.createWriteStream(args.output)
|
|
|
|
: process.stdout;
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
return Promise.resolve((packagerInstance ?
|
2016-04-11 16:23:06 +00:00
|
|
|
packagerInstance.getOrderedDependencyPaths(options) :
|
|
|
|
ReactPackager.getOrderedDependencyPaths(packageOpts, options)).then(
|
|
|
|
deps => {
|
|
|
|
deps.forEach(modulePath => {
|
|
|
|
// Temporary hack to disable listing dependencies not under this directory.
|
|
|
|
// Long term, we need either
|
|
|
|
// (a) JS code to not depend on anything outside this directory, or
|
|
|
|
// (b) Come up with a way to declare this dependency in Buck.
|
|
|
|
const isInsideProjectRoots = packageOpts.projectRoots.filter(
|
|
|
|
root => modulePath.startsWith(root)
|
|
|
|
).length > 0;
|
2015-09-22 16:00:04 +00:00
|
|
|
|
2016-04-11 16:23:06 +00:00
|
|
|
if (isInsideProjectRoots) {
|
|
|
|
outStream.write(modulePath + '\n');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return writeToFile
|
2016-11-08 20:19:36 +00:00
|
|
|
? denodeify(outStream.end).bind(outStream)()
|
2016-04-11 16:23:06 +00:00
|
|
|
: Promise.resolve();
|
2016-03-18 19:44:01 +00:00
|
|
|
}
|
2016-04-11 16:23:06 +00:00
|
|
|
));
|
2015-09-22 16:00:04 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
module.exports = {
|
|
|
|
name: 'dependencies',
|
|
|
|
func: dependencies,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
command: '--entry-file <path>',
|
|
|
|
description: 'Absolute path to the root JS file',
|
|
|
|
}, {
|
|
|
|
command: '--output [path]',
|
|
|
|
description: 'File name where to store the output, ex. /tmp/dependencies.txt',
|
|
|
|
}, {
|
|
|
|
command: '--platform [extension]',
|
|
|
|
description: 'The platform extension used for selecting modules',
|
|
|
|
}, {
|
|
|
|
command: '--transformer [path]',
|
|
|
|
description: 'Specify a custom transformer to be used'
|
|
|
|
}, {
|
|
|
|
command: '--verbose',
|
|
|
|
description: 'Enables logging',
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|