Fix lint warnings in Bundler index

Summary: Fix lint warnings starting at Bundler index

Reviewed By: davidaurelio

Differential Revision: D4147587

fbshipit-source-id: 6d86bdd4d43a08661498c2bf8b6b21c8c3573d88
This commit is contained in:
Ovidiu Viorel Iepure 2016-11-08 12:19:38 -08:00 committed by Facebook Github Bot
parent 5a6d3f99e2
commit 3064549bca
2 changed files with 37 additions and 24 deletions

View File

@ -13,7 +13,6 @@
const assert = require('assert'); const assert = require('assert');
const fs = require('fs'); const fs = require('fs');
const path = require('path');
const Cache = require('../node-haste').Cache; const Cache = require('../node-haste').Cache;
const Transformer = require('../JSTransformer'); const Transformer = require('../JSTransformer');
const Resolver = require('../Resolver'); const Resolver = require('../Resolver');
@ -25,6 +24,14 @@ const imageSize = require('image-size');
const version = require('../../../../package.json').version; const version = require('../../../../package.json').version;
const denodeify = require('denodeify'); const denodeify = require('denodeify');
const {
sep: pathSeparator,
join: joinPath,
relative: relativePath,
dirname: pathDirname,
extname,
} = require('path');
import AssetServer from '../AssetServer'; import AssetServer from '../AssetServer';
import Module from '../node-haste/Module'; import Module from '../node-haste/Module';
import ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; import ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
@ -154,7 +161,7 @@ class Bundler {
'react-packager-cache', 'react-packager-cache',
version, version,
opts.cacheVersion, opts.cacheVersion,
opts.projectRoots.join(',').split(path.sep).join('-'), opts.projectRoots.join(',').split(pathSeparator).join('-'),
mtime, mtime,
]; ];
@ -191,8 +198,12 @@ class Bundler {
projectRoots: opts.projectRoots, projectRoots: opts.projectRoots,
resetCache: opts.resetCache, resetCache: opts.resetCache,
transformCode: transformCode:
(module, code, options) => (module, code, transformCodeOptions) => this._transformer.transformFile(
this._transformer.transformFile(module.path, code, options, transformCacheKey), module.path,
code,
transformCodeOptions,
transformCacheKey,
),
transformCacheKey, transformCacheKey,
}); });
@ -228,22 +239,22 @@ class Bundler {
}); });
} }
_sourceHMRURL(platform, path) { _sourceHMRURL(platform, hmrpath) {
return this._hmrURL( return this._hmrURL(
'', '',
platform, platform,
'bundle', 'bundle',
path, hmrpath,
); );
} }
_sourceMappingHMRURL(platform, path) { _sourceMappingHMRURL(platform, hmrpath) {
// Chrome expects `sourceURL` when eval'ing code // Chrome expects `sourceURL` when eval'ing code
return this._hmrURL( return this._hmrURL(
'\/\/# sourceURL=', '\/\/# sourceURL=',
platform, platform,
'map', 'map',
path, hmrpath,
); );
} }
@ -255,12 +266,12 @@ class Bundler {
} }
// Replaces '\' with '/' for Windows paths. // Replaces '\' with '/' for Windows paths.
if (path.sep === '\\') { if (pathSeparator === '\\') {
filePath = filePath.replace(/\\/g, '/'); filePath = filePath.replace(/\\/g, '/');
} }
const extensionStart = filePath.lastIndexOf('.'); const extensionStart = filePath.lastIndexOf('.');
let resource = filePath.substring( const resource = filePath.substring(
matchingRoot.length, matchingRoot.length,
extensionStart !== -1 ? extensionStart : undefined, extensionStart !== -1 ? extensionStart : undefined,
); );
@ -414,8 +425,9 @@ class Bundler {
const numModuleSystemDependencies = const numModuleSystemDependencies =
this._resolver.getModuleSystemDependencies({dev, unbundle}).length; this._resolver.getModuleSystemDependencies({dev, unbundle}).length;
const dependencyIndex =
(response.numPrependedDependencies || 0) + numModuleSystemDependencies;
const dependencyIndex = (response.numPrependedDependencies || 0) + numModuleSystemDependencies;
if (dependencyIndex in response.dependencies) { if (dependencyIndex in response.dependencies) {
entryFilePath = response.dependencies[dependencyIndex].path; entryFilePath = response.dependencies[dependencyIndex].path;
} }
@ -664,18 +676,18 @@ class Bundler {
_generateAssetObjAndCode(module, assetPlugins, platform: mixed = null) { _generateAssetObjAndCode(module, assetPlugins, platform: mixed = null) {
const relPath = getPathRelativeToRoot(this._projectRoots, module.path); const relPath = getPathRelativeToRoot(this._projectRoots, module.path);
var assetUrlPath = path.join('/assets', path.dirname(relPath)); var assetUrlPath = joinPath('/assets', pathDirname(relPath));
// On Windows, change backslashes to slashes to get proper URL path from file path. // On Windows, change backslashes to slashes to get proper URL path from file path.
if (path.sep === '\\') { if (pathSeparator === '\\') {
assetUrlPath = assetUrlPath.replace(/\\/g, '/'); assetUrlPath = assetUrlPath.replace(/\\/g, '/');
} }
// Test extension against all types supported by image-size module. // Test extension against all types supported by image-size module.
// If it's not one of these, we won't treat it as an image. // If it's not one of these, we won't treat it as an image.
let isImage = [ const isImage = [
'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff' 'png', 'jpg', 'jpeg', 'bmp', 'gif', 'webp', 'psd', 'svg', 'tiff'
].indexOf(path.extname(module.path).slice(1)) !== -1; ].indexOf(extname(module.path).slice(1)) !== -1;
return Promise.all([ return Promise.all([
isImage ? sizeOf(module.path) : null, isImage ? sizeOf(module.path) : null,
@ -685,7 +697,7 @@ class Bundler {
const assetData = res[1]; const assetData = res[1];
const asset = { const asset = {
__packager_asset: true, __packager_asset: true,
fileSystemLocation: path.dirname(module.path), fileSystemLocation: pathDirname(module.path),
httpServerLocation: assetUrlPath, httpServerLocation: assetUrlPath,
width: dimensions ? dimensions.width / module.resolution : undefined, width: dimensions ? dimensions.width / module.resolution : undefined,
height: dimensions ? dimensions.height / module.resolution : undefined, height: dimensions ? dimensions.height / module.resolution : undefined,
@ -718,10 +730,10 @@ class Bundler {
return asset; return asset;
} }
let [currentAssetPlugin, ...remainingAssetPlugins] = assetPlugins; const [currentAssetPlugin, ...remainingAssetPlugins] = assetPlugins;
/* $FlowFixMe: dynamic requires prevent static typing :'( */ /* $FlowFixMe: dynamic requires prevent static typing :'( */
let assetPluginFunction = require(currentAssetPlugin); const assetPluginFunction = require(currentAssetPlugin);
let result = assetPluginFunction(asset); const result = assetPluginFunction(asset);
// If the plugin was an async function, wait for it to fulfill before // If the plugin was an async function, wait for it to fulfill before
// applying the remaining plugins // applying the remaining plugins
@ -763,7 +775,7 @@ class Bundler {
? this._transformOptionsModule(mainModuleName, options, this) ? this._transformOptionsModule(mainModuleName, options, this)
: null; : null;
return Promise.resolve(extraOptions) return Promise.resolve(extraOptions)
.then(extraOptions => Object.assign(options, extraOptions)); .then(extraOpts => Object.assign(options, extraOpts));
} }
getResolver() { getResolver() {
@ -773,7 +785,7 @@ class Bundler {
function getPathRelativeToRoot(roots, absPath) { function getPathRelativeToRoot(roots, absPath) {
for (let i = 0; i < roots.length; i++) { for (let i = 0; i < roots.length; i++) {
const relPath = path.relative(roots[i], absPath); const relPath = relativePath(roots[i], absPath);
if (relPath[0] !== '.') { if (relPath[0] !== '.') {
return relPath; return relPath;
} }

View File

@ -19,7 +19,8 @@ const extractRequires = require('./lib/extractRequires');
const invariant = require('invariant'); const invariant = require('invariant');
const isAbsolutePath = require('absolute-path'); const isAbsolutePath = require('absolute-path');
const jsonStableStringify = require('json-stable-stringify'); const jsonStableStringify = require('json-stable-stringify');
const path = require('path');
const {join: joinPath, relative: relativePath, extname} = require('path');
import type Cache from './Cache'; import type Cache from './Cache';
import type ModuleCache from './ModuleCache'; import type ModuleCache from './ModuleCache';
@ -156,7 +157,7 @@ class Module {
return this.path; return this.path;
} }
return path.join(name, path.relative(p.root, this.path)).replace(/\\/g, '/'); return joinPath(name, relativePath(p.root, this.path)).replace(/\\/g, '/');
}); });
}) })
); );
@ -322,7 +323,7 @@ class Module {
} }
isJSON() { isJSON() {
return path.extname(this.path) === '.json'; return extname(this.path) === '.json';
} }
isAsset() { isAsset() {