Skip to content

fix: revert dependencies removal #80

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/local-cli/core/getCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const loadLocalCommands = (): Array<LocalCommandT> => [
require('../upgrade/upgrade'),
require('../logAndroid/logAndroid'),
require('../logIOS/logIOS'),
require('../dependencies/dependencies'),
require('../info/info'),
];

Expand Down
112 changes: 112 additions & 0 deletions packages/local-cli/dependencies/dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/

const Metro = require('metro');

const denodeify = require('denodeify');
const fs = require('fs');
const path = require('path');
const util = require('util');

async function dependencies(argv, configPromise, args, packagerInstance) {
const rootModuleAbsolutePath = args.entryFile;
const config = await configPromise;
if (!fs.existsSync(rootModuleAbsolutePath)) {
return Promise.reject(
new Error(`File ${rootModuleAbsolutePath} does not exist`)
);
}

config.cacheStores = [];

const relativePath = path.relative(
config.projectRoot,
rootModuleAbsolutePath
);

const options = {
platform: args.platform,
entryFile: relativePath,
dev: args.dev,
minify: false,
generateSourceMaps: !args.dev,
};

const writeToFile = args.output;
const outStream = writeToFile
? fs.createWriteStream(args.output)
: process.stdout;

const deps = packagerInstance
? await packagerInstance.getOrderedDependencyPaths(options)
: await Metro.getOrderedDependencyPaths(config, options);

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 =
config.watchFolders.filter(root => modulePath.startsWith(root)).length >
0;

if (isInsideProjectRoots) {
outStream.write(`${modulePath}\n`);
}
});
return writeToFile
? denodeify(outStream.end).bind(outStream)()
: Promise.resolve();
}

module.exports = {
name: 'dependencies',
description: 'lists dependencies',
func: util.deprecate(
dependencies,
'dependencies command was moved to metro, and will be removed from cli in next release'
),
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: '--max-workers [number]',
description:
'Specifies the maximum number of workers the worker-pool ' +
'will spawn for transforming files. This defaults to the number of the ' +
'cores available on your machine.',
parse: workers => Number(workers),
},
{
command: '--dev [boolean]',
description: 'If false, skip all dev-only code path',
parse: val => val !== 'false',
default: true,
},
{
command: '--verbose',
description: 'Enables logging',
default: false,
},
],
};