Files
react-native/packager/src/node-haste/DependencyGraph/DependencyGraphHelpers.js
T
Christoph Pojer 5403946f09 Fix lint errors 1/n
Reviewed By: davidaurelio

Differential Revision: D4627645

fbshipit-source-id: 3cf368c6a24a555b7d0a39045f6ba6fd92ae34e1
2017-02-28 09:00:42 -08:00

58 lines
1.3 KiB
JavaScript

/**
* 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.
*
* @flow
*/
'use strict';
const path = require('path');
const NODE_MODULES = path.sep + 'node_modules' + path.sep;
class DependencyGraphHelpers {
_providesModuleNodeModules: Array<string>;
_assetExts: Array<string>;
constructor({providesModuleNodeModules, assetExts}: {
providesModuleNodeModules: Array<string>,
assetExts: Array<string>,
}) {
this._providesModuleNodeModules = providesModuleNodeModules;
this._assetExts = assetExts;
}
isNodeModulesDir(file: string) {
const index = file.lastIndexOf(NODE_MODULES);
if (index === -1) {
return false;
}
const parts = file.substr(index + 14).split(path.sep);
const dirs = this._providesModuleNodeModules;
for (let i = 0; i < dirs.length; i++) {
if (parts.indexOf(dirs[i]) > -1) {
return false;
}
}
return true;
}
isAssetFile(file: string) {
return this._assetExts.indexOf(this.extname(file)) !== -1;
}
extname(name: string) {
return path.extname(name).substr(1);
}
}
module.exports = DependencyGraphHelpers;