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');
|
|
|
|
|
2017-07-28 00:58:57 +00:00
|
|
|
const {ASSET_REGISTRY_PATH} = require('../core/Constants');
|
|
|
|
|
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)) {
|
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-05-11 19:43:49 +00:00
|
|
|
const transformModulePath = args.transformer
|
|
|
|
? path.resolve(args.transformer)
|
|
|
|
: typeof config.getTransformModulePath === 'function'
|
|
|
|
? config.getTransformModulePath()
|
|
|
|
: undefined;
|
2018-03-01 13:30:27 +00:00
|
|
|
|
2015-10-05 16:15:09 +00:00
|
|
|
const packageOpts = {
|
2017-07-28 00:58:57 +00:00
|
|
|
assetRegistryPath: ASSET_REGISTRY_PATH,
|
2018-03-01 13:30:27 +00:00
|
|
|
cacheStores: [],
|
2018-06-19 20:45:17 +00:00
|
|
|
projectRoot: config.getProjectRoot(),
|
2016-09-23 14:59:59 +00:00
|
|
|
blacklistRE: config.getBlacklistRE(),
|
2018-01-18 15:50:53 +00:00
|
|
|
dynamicDepsInPackages: config.dynamicDepsInPackages,
|
2017-07-22 04:52:40 +00:00
|
|
|
getPolyfills: config.getPolyfills,
|
2016-11-28 15:27:09 +00:00
|
|
|
getTransformOptions: config.getTransformOptions,
|
2018-01-30 19:20:20 +00:00
|
|
|
hasteImplModulePath: config.hasteImplModulePath,
|
2017-11-11 15:03:08 +00:00
|
|
|
postMinifyProcess: config.postMinifyProcess,
|
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,
|
2018-06-19 20:45:17 +00:00
|
|
|
watchFolders: config.getWatchFolders(),
|
2017-05-31 17:05:40 +00:00
|
|
|
workerPath: config.getWorkerPath(),
|
2015-09-22 16:00:04 +00:00
|
|
|
};
|
|
|
|
|
2018-06-19 20:45:17 +00:00
|
|
|
const relativePath = path.relative(
|
|
|
|
packageOpts.projectRoot,
|
|
|
|
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)
|
|
|
|
: Metro.getOrderedDependencyPaths(packageOpts, options)
|
|
|
|
).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-06-19 20:45:17 +00:00
|
|
|
packageOpts.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,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|