2015-09-22 16:00:04 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2018-05-11 19:43:49 +00:00
|
|
|
*
|
|
|
|
* @format
|
2015-09-22 16:00:04 +00:00
|
|
|
*/
|
2018-05-11 19:43:49 +00:00
|
|
|
|
2016-11-08 20:19:36 +00:00
|
|
|
'use strict';
|
2015-09-22 16:00:04 +00:00
|
|
|
|
2017-11-29 14:51:30 +00:00
|
|
|
const Metro = require('metro');
|
2016-11-08 20:19:36 +00:00
|
|
|
|
|
|
|
const denodeify = require('denodeify');
|
2015-09-22 16:00:04 +00:00
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
|
2018-07-25 12:44:38 +00:00
|
|
|
async function dependencies(argv, configPromise, args, packagerInstance) {
|
2016-07-30 15:59:16 +00:00
|
|
|
const rootModuleAbsolutePath = args.entryFile;
|
2018-07-25 12:44:38 +00:00
|
|
|
const config = await configPromise;
|
2015-09-22 16:00:04 +00:00
|
|
|
if (!fs.existsSync(rootModuleAbsolutePath)) {
|
2018-05-11 19:43:49 +00:00
|
|
|
return Promise.reject(
|
|
|
|
new Error(`File ${rootModuleAbsolutePath} does not exist`),
|
|
|
|
);
|
2015-09-22 16:00:04 +00:00
|
|
|
}
|
|
|
|
|
2018-07-25 12:44:38 +00:00
|
|
|
config.cacheStores = [];
|
|
|
|
config.transformModulePath = args.transformer
|
2018-05-11 19:43:49 +00:00
|
|
|
? path.resolve(args.transformer)
|
2018-07-25 12:44:38 +00:00
|
|
|
: config.transformModulePath;
|
2015-09-22 16:00:04 +00:00
|
|
|
|
2018-06-19 20:45:17 +00:00
|
|
|
const relativePath = path.relative(
|
2018-07-25 12:44:40 +00:00
|
|
|
config.projectRoot,
|
2018-06-19 20:45:17 +00:00
|
|
|
rootModuleAbsolutePath,
|
|
|
|
);
|
2015-09-22 16:00:04 +00:00
|
|
|
|
2015-09-29 05:40:56 +00:00
|
|
|
const options = {
|
|
|
|
platform: args.platform,
|
|
|
|
entryFile: relativePath,
|
2017-06-01 20:51:58 +00:00
|
|
|
dev: args.dev,
|
2017-12-23 17:07:07 +00:00
|
|
|
minify: false,
|
2017-06-01 20:51:58 +00:00
|
|
|
generateSourceMaps: !args.dev,
|
2015-09-29 05:40:56 +00:00
|
|
|
};
|
|
|
|
|
2015-09-22 16:00:04 +00:00
|
|
|
const writeToFile = args.output;
|
|
|
|
const outStream = writeToFile
|
|
|
|
? fs.createWriteStream(args.output)
|
|
|
|
: process.stdout;
|
|
|
|
|
2018-05-11 19:43:49 +00:00
|
|
|
return Promise.resolve(
|
|
|
|
(packagerInstance
|
|
|
|
? packagerInstance.getOrderedDependencyPaths(options)
|
2018-07-25 12:44:42 +00:00
|
|
|
: Metro.getOrderedDependencyPaths(config, options)
|
2018-05-11 19:43:49 +00:00
|
|
|
).then(deps => {
|
2016-04-11 16:23:06 +00:00
|
|
|
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.
|
2018-05-11 19:43:49 +00:00
|
|
|
const isInsideProjectRoots =
|
2018-07-25 12:44:40 +00:00
|
|
|
config.watchFolders.filter(root => modulePath.startsWith(root))
|
2018-05-11 19:43:49 +00:00
|
|
|
.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();
|
2018-05-11 19:43:49 +00:00
|
|
|
}),
|
|
|
|
);
|
2015-09-22 16:00:04 +00:00
|
|
|
}
|
|
|
|
|
2016-07-30 15:59:16 +00:00
|
|
|
module.exports = {
|
|
|
|
name: 'dependencies',
|
2018-02-22 14:06:38 +00:00
|
|
|
description: 'lists dependencies',
|
2016-07-30 15:59:16 +00:00
|
|
|
func: dependencies,
|
|
|
|
options: [
|
|
|
|
{
|
|
|
|
command: '--entry-file <path>',
|
|
|
|
description: 'Absolute path to the root JS file',
|
2018-05-11 19:43:49 +00:00
|
|
|
},
|
|
|
|
{
|
2016-07-30 15:59:16 +00:00
|
|
|
command: '--output [path]',
|
2018-05-11 19:43:49 +00:00
|
|
|
description:
|
|
|
|
'File name where to store the output, ex. /tmp/dependencies.txt',
|
|
|
|
},
|
|
|
|
{
|
2016-07-30 15:59:16 +00:00
|
|
|
command: '--platform [extension]',
|
|
|
|
description: 'The platform extension used for selecting modules',
|
2018-05-11 19:43:49 +00:00
|
|
|
},
|
|
|
|
{
|
2016-07-30 15:59:16 +00:00
|
|
|
command: '--transformer [path]',
|
2018-05-11 19:43:49 +00:00
|
|
|
description: 'Specify a custom transformer to be used',
|
|
|
|
},
|
|
|
|
{
|
2017-06-13 16:11:57 +00:00
|
|
|
command: '--max-workers [number]',
|
2018-05-11 19:43:49 +00:00
|
|
|
description:
|
|
|
|
'Specifies the maximum number of workers the worker-pool ' +
|
2017-06-13 16:11:57 +00:00
|
|
|
'will spawn for transforming files. This defaults to the number of the ' +
|
|
|
|
'cores available on your machine.',
|
|
|
|
parse: (workers: string) => Number(workers),
|
2018-05-11 19:43:49 +00:00
|
|
|
},
|
|
|
|
{
|
2017-06-01 20:51:58 +00:00
|
|
|
command: '--dev [boolean]',
|
|
|
|
description: 'If false, skip all dev-only code path',
|
2018-05-11 19:43:49 +00:00
|
|
|
parse: val => (val === 'false' ? false : true),
|
2017-06-01 20:51:58 +00:00
|
|
|
default: true,
|
2018-05-11 19:43:49 +00:00
|
|
|
},
|
|
|
|
{
|
2016-07-30 15:59:16 +00:00
|
|
|
command: '--verbose',
|
|
|
|
description: 'Enables logging',
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|