From 77d8cbc68acf93db2446c6711884d33bb8ced702 Mon Sep 17 00:00:00 2001 From: Christoph Pojer Date: Wed, 1 Mar 2017 08:05:59 -0800 Subject: [PATCH] Fix lint errors 2/2 Reviewed By: jeanlauliac Differential Revision: D4628330 fbshipit-source-id: 94fad1294e22fa0073e15843f94241ae778112a0 --- packages/metro-bundler/blacklist.js | 2 +- .../src/Bundler/__tests__/Bundle-test.js | 52 +++++------ packages/metro-bundler/src/Bundler/index.js | 5 +- .../src/Bundler/source-map/encode.js | 6 +- .../worker/__tests__/inline-test.js | 22 ++--- .../worker/extract-dependencies.js | 7 +- .../src/ModuleGraph/__tests__/Graph-test.js | 86 ++++++++++--------- .../src/ModuleGraph/node-haste/HasteFS.js | 8 +- .../__tests__/collect-dependencies-test.js | 40 +++++---- .../worker/__tests__/optimize-module-test.js | 1 + .../worker/__tests__/transform-module-test.js | 44 +++++----- .../ModuleGraph/worker/transform-module.js | 4 +- .../src/Resolver/__tests__/Resolver-test.js | 41 ++------- packages/metro-bundler/src/Resolver/index.js | 5 +- .../src/Resolver/polyfills/Number.es6.js | 1 + .../src/Resolver/polyfills/error-guard.js | 2 + packages/metro-bundler/src/Server/index.js | 6 +- .../src/lib/relativizeSourceMap.js | 4 +- .../node-haste/DependencyGraph/HasteMap.js | 1 + .../src/node-haste/__mocks__/graceful-fs.js | 8 +- .../__tests__/DependencyGraph-test.js | 2 +- .../metro-bundler/src/node-haste/index.js | 4 +- packages/metro-bundler/transformer.js | 4 +- 23 files changed, 176 insertions(+), 179 deletions(-) diff --git a/packages/metro-bundler/blacklist.js b/packages/metro-bundler/blacklist.js index 9a6b08c8..3ae74047 100644 --- a/packages/metro-bundler/blacklist.js +++ b/packages/metro-bundler/blacklist.js @@ -29,7 +29,7 @@ function escapeRegExp(pattern) { } else if (typeof pattern === 'string') { var escaped = pattern.replace(/[\-\[\]\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&'); // convert the '/' into an escaped local file separator - return escaped.replace(/\//g,'\\' + path.sep); + return escaped.replace(/\//g, '\\' + path.sep); } else { throw new Error('Unexpected packager blacklist pattern: ' + pattern); } diff --git a/packages/metro-bundler/src/Bundler/__tests__/Bundle-test.js b/packages/metro-bundler/src/Bundler/__tests__/Bundle-test.js index 0cafff1a..a35770cd 100644 --- a/packages/metro-bundler/src/Bundler/__tests__/Bundle-test.js +++ b/packages/metro-bundler/src/Bundler/__tests__/Bundle-test.js @@ -12,7 +12,6 @@ jest.disableAutomock(); const Bundle = require('../Bundle'); const ModuleTransport = require('../../lib/ModuleTransport'); -const SourceMapGenerator = require('source-map').SourceMapGenerator; const crypto = require('crypto'); describe('Bundle', () => { @@ -107,33 +106,37 @@ describe('Bundle', () => { }); }); - it('should insert modules in a deterministic order, independent from timing of the wrapping process', () => { - const moduleTransports = [ - createModuleTransport({name: 'module1'}), - createModuleTransport({name: 'module2'}), - createModuleTransport({name: 'module3'}), - ]; + it('inserts modules in a deterministic order, independent of timing of the wrapper process', + () => { + const moduleTransports = [ + createModuleTransport({name: 'module1'}), + createModuleTransport({name: 'module2'}), + createModuleTransport({name: 'module3'}), + ]; - const resolves = {}; - const resolver = { - wrapModule({name}) { - return new Promise(resolve => resolves[name] = resolve); - }, - }; + const resolves = {}; + const resolver = { + wrapModule({name}) { + return new Promise(resolve => { + resolves[name] = resolve; + }); + }, + }; - const promise = Promise.all( - moduleTransports.map(m => bundle.addModule(resolver, null, {isPolyfill: () => false}, m))) - .then(() => { - expect(bundle.getModules()) - .toEqual(moduleTransports); - }); + const promise = Promise.all(moduleTransports.map( + m => bundle.addModule(resolver, null, {isPolyfill: () => false}, m) + )).then(() => { + expect(bundle.getModules()) + .toEqual(moduleTransports); + }); - resolves.module2({code: ''}); - resolves.module3({code: ''}); - resolves.module1({code: ''}); + resolves.module2({code: ''}); + resolves.module3({code: ''}); + resolves.module1({code: ''}); - return promise; - }); + return promise; + }, + ); }); describe('sourcemap bundle', () => { @@ -268,7 +271,6 @@ describe('Bundle', () => { describe('getEtag()', function() { it('should return an etag', function() { - var bundle = new Bundle({sourceMapUrl: 'test_url'}); bundle.finalize({}); var eTag = crypto.createHash('md5').update(bundle.getSource()).digest('hex'); expect(bundle.getEtag()).toEqual(eTag); diff --git a/packages/metro-bundler/src/Bundler/index.js b/packages/metro-bundler/src/Bundler/index.js index 7ad32fbd..15b06b0c 100644 --- a/packages/metro-bundler/src/Bundler/index.js +++ b/packages/metro-bundler/src/Bundler/index.js @@ -38,7 +38,10 @@ const VERSION = require('../../package.json').version; import type AssetServer from '../AssetServer'; import type Module, {HasteImpl} from '../node-haste/Module'; import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse'; -import type {Options as JSTransformerOptions, TransformOptions} from '../JSTransformer/worker/worker'; +import type { + Options as JSTransformerOptions, + TransformOptions, +} from '../JSTransformer/worker/worker'; import type {Reporter} from '../lib/reporting'; import type GlobalTransformCache from '../lib/GlobalTransformCache'; diff --git a/packages/metro-bundler/src/Bundler/source-map/encode.js b/packages/metro-bundler/src/Bundler/source-map/encode.js index 04bf463a..cc05fa10 100644 --- a/packages/metro-bundler/src/Bundler/source-map/encode.js +++ b/packages/metro-bundler/src/Bundler/source-map/encode.js @@ -8,13 +8,14 @@ * * @flow */ + /** * Copyright 2011 Mozilla Foundation and contributors * Licensed under the New BSD license. See LICENSE or: * http://opensource.org/licenses/BSD-3-Clause * * Based on the Base 64 VLQ implementation in Closure Compiler: - * https://code.google.com/p/closure-compiler/source/browse/trunk/src/com/google/debugging/sourcemap/Base64VLQ.java + * https://git.io/vymuA * * Copyright 2011 The Closure Compiler Authors. All rights reserved. * Redistribution and use in source and binary forms, with or without @@ -107,7 +108,8 @@ function toVLQSigned(value) { * V8 OPTIMIZATION! */ function encode(value: number, buffer: Buffer, position: number): number { - let digit, vlq = toVLQSigned(value); + let vlq = toVLQSigned(value); + let digit; do { digit = vlq & VLQ_BASE_MASK; vlq >>>= VLQ_BASE_SHIFT; diff --git a/packages/metro-bundler/src/JSTransformer/worker/__tests__/inline-test.js b/packages/metro-bundler/src/JSTransformer/worker/__tests__/inline-test.js index 821aaf4c..d2a10f55 100644 --- a/packages/metro-bundler/src/JSTransformer/worker/__tests__/inline-test.js +++ b/packages/metro-bundler/src/JSTransformer/worker/__tests__/inline-test.js @@ -8,6 +8,8 @@ */ 'use strict'; +/* eslint-disable max-len */ + jest.disableAutomock(); const inline = require('../inline'); const {transform, transformFromAst} = require('babel-core'); @@ -205,7 +207,9 @@ describe('inline constants', () => { var b = a.ReactNative.Platform.select({}); }`; const {ast} = inline('arbitrary.js', {code}, {platform: 'ios'}); - expect(toString(ast)).toEqual(normalize(code.replace(/ReactNative\.Platform\.select[^;]+/, '1'))); + expect(toString(ast)).toEqual( + normalize(code.replace(/ReactNative\.Platform\.select[^;]+/, '1')), + ); }); it('replaces React.Platform.select in the code if React is a top level import', () => { @@ -237,7 +241,9 @@ describe('inline constants', () => { var b = a.ReactNative.Platform.select; }`; const {ast} = inline('arbitrary.js', {code}, {platform: 'android'}); - expect(toString(ast)).toEqual(normalize(code.replace(/ReactNative.Platform\.select[^;]+/, '2'))); + expect(toString(ast)).toEqual( + normalize(code.replace(/ReactNative.Platform\.select[^;]+/, '2')), + ); }); it('replaces require("react-native").Platform.select in the code', () => { @@ -269,18 +275,6 @@ describe('inline constants', () => { normalize(code.replace(/process\.env\.NODE_ENV/, '"production"'))); }); - it('replaces process.env.NODE_ENV in the code', () => { - const code = `function a() { - if (process.env.NODE_ENV === 'production') { - return require('Prod'); - } - return require('Dev'); - }`; - const {ast} = inline('arbitrary.js', {code}, {dev: true}); - expect(toString(ast)).toEqual( - normalize(code.replace(/process\.env\.NODE_ENV/, '"development"'))); - }); - it('accepts an AST as input', function() { const code = 'function ifDev(a,b){return __DEV__?a:b;}'; const {ast} = inline('arbitrary.hs', {ast: toAst(code)}, {dev: false}); diff --git a/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js b/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js index d88407f1..1ce908b9 100644 --- a/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js +++ b/packages/metro-bundler/src/JSTransformer/worker/extract-dependencies.js @@ -33,7 +33,12 @@ function extractDependencies(code: string) { const node = path.node; const callee = node.callee; const arg = node.arguments[0]; - if (callee.type !== 'Identifier' || callee.name !== 'require' || !arg || arg.type !== 'StringLiteral') { + if ( + callee.type !== 'Identifier' || + callee.name !== 'require' || + !arg || + arg.type !== 'StringLiteral' + ) { return; } dependencyOffsets.push(arg.start); diff --git a/packages/metro-bundler/src/ModuleGraph/__tests__/Graph-test.js b/packages/metro-bundler/src/ModuleGraph/__tests__/Graph-test.js index 7183c7b0..621f489d 100644 --- a/packages/metro-bundler/src/ModuleGraph/__tests__/Graph-test.js +++ b/packages/metro-bundler/src/ModuleGraph/__tests__/Graph-test.js @@ -208,50 +208,52 @@ describe('Graph:', () => { }); }); - it('calls back with an array of modules in depth-first traversal order, regardless of the order of resolution', done => { - load.stub.reset(); - resolve.stub.reset(); + it('resolves modules in depth-first traversal order, regardless of the order of resolution', + done => { + load.stub.reset(); + resolve.stub.reset(); - const ids = [ - 'a', - 'b', - 'c', 'd', - 'e', - 'f', 'g', - 'h', - ]; - ids.forEach(id => { - const path = idToPath(id); - resolve.stub.withArgs(id).yields(null, path); - load.stub.withArgs(path).yields(null, createFile(id), []); - }); - load.stub.withArgs(idToPath('a')).yields(null, createFile('a'), ['b', 'e', 'h']); - load.stub.withArgs(idToPath('b')).yields(null, createFile('b'), ['c', 'd']); - load.stub.withArgs(idToPath('e')).yields(null, createFile('e'), ['f', 'g']); + const ids = [ + 'a', + 'b', + 'c', 'd', + 'e', + 'f', 'g', + 'h', + ]; + ids.forEach(id => { + const path = idToPath(id); + resolve.stub.withArgs(id).yields(null, path); + load.stub.withArgs(path).yields(null, createFile(id), []); + }); + load.stub.withArgs(idToPath('a')).yields(null, createFile('a'), ['b', 'e', 'h']); + load.stub.withArgs(idToPath('b')).yields(null, createFile('b'), ['c', 'd']); + load.stub.withArgs(idToPath('e')).yields(null, createFile('e'), ['f', 'g']); - // load certain ids later - ['b', 'e', 'h'].forEach(id => resolve.stub.withArgs(id).resetBehavior()); - resolve.stub.withArgs('h').func = (a, b, c, d, callback) => { - callback(null, idToPath('h')); - ['e', 'b'].forEach( - id => resolve.stub.withArgs(id).yield(null, idToPath(id))); - }; + // load certain ids later + ['b', 'e', 'h'].forEach(id => resolve.stub.withArgs(id).resetBehavior()); + resolve.stub.withArgs('h').func = (a, b, c, d, callback) => { + callback(null, idToPath('h')); + ['e', 'b'].forEach( + id => resolve.stub.withArgs(id).yield(null, idToPath(id))); + }; - graph(['a'], anyPlatform, noOpts, (error, result) => { - expect(error).toEqual(null); - expect(result.modules).toEqual([ - createModule('a', ['b', 'e', 'h']), - createModule('b', ['c', 'd']), - createModule('c'), - createModule('d'), - createModule('e', ['f', 'g']), - createModule('f'), - createModule('g'), - createModule('h'), - ]); - done(); - }); - }); + graph(['a'], anyPlatform, noOpts, (error, result) => { + expect(error).toEqual(null); + expect(result.modules).toEqual([ + createModule('a', ['b', 'e', 'h']), + createModule('b', ['c', 'd']), + createModule('c'), + createModule('d'), + createModule('e', ['f', 'g']), + createModule('f'), + createModule('g'), + createModule('h'), + ]); + done(); + }); + }, + ); it('calls back with the resolved modules of the entry points', done => { load.stub.reset(); @@ -274,7 +276,7 @@ describe('Graph:', () => { }); }); - it('calls back with the resolved modules of the entry points if one entry point is a dependency of another', done => { + it('resolves modules for all entry points correctly if one is a dependency of another', done => { load.stub.reset(); resolve.stub.reset(); diff --git a/packages/metro-bundler/src/ModuleGraph/node-haste/HasteFS.js b/packages/metro-bundler/src/ModuleGraph/node-haste/HasteFS.js index 11717926..c48f7c25 100644 --- a/packages/metro-bundler/src/ModuleGraph/node-haste/HasteFS.js +++ b/packages/metro-bundler/src/ModuleGraph/node-haste/HasteFS.js @@ -25,7 +25,9 @@ module.exports = class HasteFS { } closest(path: string, fileName: string): ?string { - let {dir, root} = parse(path); + const parsedPath = parse(path); + const root = parsedPath.root; + let dir = parsedPath.dir; do { const candidate = join(dir, fileName); if (this.files.has(candidate)) { @@ -63,7 +65,9 @@ module.exports = class HasteFS { function buildDirectorySet(files) { const directories = new Set(); files.forEach(path => { - let {dir, root} = parse(path); + const parsedPath = parse(path); + const root = parsedPath.root; + let dir = parsedPath.dir; while (dir !== '.' && dir !== root && !directories.has(dir)) { directories.add(dir); dir = dirname(dir); diff --git a/packages/metro-bundler/src/ModuleGraph/worker/__tests__/collect-dependencies-test.js b/packages/metro-bundler/src/ModuleGraph/worker/__tests__/collect-dependencies-test.js index 72d9a6f3..5ce6310a 100644 --- a/packages/metro-bundler/src/ModuleGraph/worker/__tests__/collect-dependencies-test.js +++ b/packages/metro-bundler/src/ModuleGraph/worker/__tests__/collect-dependencies-test.js @@ -63,27 +63,29 @@ describe('dependency collection from ASTs:', () => { .toEqual(any(String)); }); - it('replaces all required module ID strings with array lookups and keeps the ID as second argument', () => { - const ast = astFromCode(` - const a = require('b/lib/a'); - const b = require(123); - exports.do = () => require("do"); - if (!something) { - require("setup/something"); - } - `); + it('replaces all required module ID strings with array lookups, keeps the ID as second argument', + () => { + const ast = astFromCode(` + const a = require('b/lib/a'); + const b = require(123); + exports.do = () => require("do"); + if (!something) { + require("setup/something"); + } + `); - const {dependencyMapName} = collectDependencies(ast); + const {dependencyMapName} = collectDependencies(ast); - expect(codeFromAst(ast)).toEqual(comparableCode(` - const a = require(${dependencyMapName}[0], 'b/lib/a'); - const b = require(123); - exports.do = () => require(${dependencyMapName}[1], "do"); - if (!something) { - require(${dependencyMapName}[2], "setup/something"); - } - `)); - }); + expect(codeFromAst(ast)).toEqual(comparableCode(` + const a = require(${dependencyMapName}[0], 'b/lib/a'); + const b = require(123); + exports.do = () => require(${dependencyMapName}[1], "do"); + if (!something) { + require(${dependencyMapName}[2], "setup/something"); + } + `)); + }, + ); }); describe('Dependency collection from optimized ASTs:', () => { diff --git a/packages/metro-bundler/src/ModuleGraph/worker/__tests__/optimize-module-test.js b/packages/metro-bundler/src/ModuleGraph/worker/__tests__/optimize-module-test.js index e94f8a07..efec7f3a 100644 --- a/packages/metro-bundler/src/ModuleGraph/worker/__tests__/optimize-module-test.js +++ b/packages/metro-bundler/src/ModuleGraph/worker/__tests__/optimize-module-test.js @@ -94,4 +94,5 @@ function findLast(code, needle) { return {line: line + 1, column}; } } + return null; } diff --git a/packages/metro-bundler/src/ModuleGraph/worker/__tests__/transform-module-test.js b/packages/metro-bundler/src/ModuleGraph/worker/__tests__/transform-module-test.js index ceda733c..105e84b4 100644 --- a/packages/metro-bundler/src/ModuleGraph/worker/__tests__/transform-module-test.js +++ b/packages/metro-bundler/src/ModuleGraph/worker/__tests__/transform-module-test.js @@ -19,8 +19,6 @@ const {parse} = require('babylon'); const generate = require('babel-generator').default; const {traverse} = require('babel-core'); -const {any, objectContaining} = jasmine; - describe('transforming JS modules:', () => { const filename = 'arbitrary'; @@ -47,7 +45,7 @@ describe('transforming JS modules:', () => { it('passes through file name and code', done => { transformModule(sourceCode, options(), (error, result) => { - expect(result).toEqual(objectContaining({ + expect(result).toEqual(expect.objectContaining({ code: sourceCode, file: filename, })); @@ -59,36 +57,39 @@ describe('transforming JS modules:', () => { const hasteID = 'TheModule'; const codeWithHasteID = `/** @providesModule ${hasteID} */`; transformModule(codeWithHasteID, options(), (error, result) => { - expect(result).toEqual(objectContaining({hasteID})); + expect(result).toEqual(expect.objectContaining({hasteID})); done(); }); }); it('sets `type` to `"module"` by default', done => { transformModule(sourceCode, options(), (error, result) => { - expect(result).toEqual(objectContaining({type: 'module'})); + expect(result).toEqual(expect.objectContaining({type: 'module'})); done(); }); }); it('sets `type` to `"script"` if the input is a polyfill', done => { transformModule(sourceCode, {...options(), polyfill: true}, (error, result) => { - expect(result).toEqual(objectContaining({type: 'script'})); + expect(result).toEqual(expect.objectContaining({type: 'script'})); done(); }); }); - it('calls the passed-in transform function with code, file name, and options for all passed in variants', done => { - const variants = {dev: {dev: true}, prod: {dev: false}}; + it('calls the passed-in transform function with code, file name, and options ' + + 'for all passed in variants', + done => { + const variants = {dev: {dev: true}, prod: {dev: false}}; - transformModule(sourceCode, options(variants), () => { - expect(transformer.transform) - .toBeCalledWith(sourceCode, filename, variants.dev); - expect(transformer.transform) - .toBeCalledWith(sourceCode, filename, variants.prod); - done(); - }); - }); + transformModule(sourceCode, options(variants), () => { + expect(transformer.transform) + .toBeCalledWith(sourceCode, filename, variants.dev); + expect(transformer.transform) + .toBeCalledWith(sourceCode, filename, variants.prod); + done(); + }); + }, + ); it('calls back with any error yielded by the transform function', done => { const error = new Error(); @@ -114,7 +115,7 @@ describe('transforming JS modules:', () => { }); }); - it('wraps the code produced by the transform function into an immediately invoked function expression for polyfills', done => { + it('wraps the code produced by the transform function into an IIFE for polyfills', done => { transformModule(sourceCode, {...options(), polyfill: true}, (error, result) => { expect(error).toEqual(null); @@ -131,20 +132,21 @@ describe('transforming JS modules:', () => { const column = code.indexOf('code'); const consumer = new SourceMapConsumer(map); expect(consumer.originalPositionFor({line: 1, column})) - .toEqual(objectContaining({line: 1, column: sourceCode.indexOf('code')})); + .toEqual(expect.objectContaining({line: 1, column: sourceCode.indexOf('code')})); done(); }); }); it('extracts dependencies (require calls)', done => { - const dep1 = 'foo', dep2 = 'bar'; + const dep1 = 'foo'; + const dep2 = 'bar'; const code = `require('${dep1}'),require('${dep2}')`; const {body} = parse(code).program; transformer.transform.stub.returns(transformResult(body)); transformModule(code, options(), (error, result) => { expect(result.transformed.default) - .toEqual(objectContaining({dependencies: [dep1, dep2]})); + .toEqual(expect.objectContaining({dependencies: [dep1, dep2]})); done(); }); }); @@ -190,7 +192,7 @@ describe('transforming JS modules:', () => { it('does not create source maps for JSON files', done => { transformModule('{}', {...options(), filename: 'some.json'}, (error, result) => { expect(result.transformed.default) - .toEqual(objectContaining({map: null})); + .toEqual(expect.objectContaining({map: null})); done(); }); }); diff --git a/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js b/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js index 9f670e4c..c451e03f 100644 --- a/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js +++ b/packages/metro-bundler/src/ModuleGraph/worker/transform-module.js @@ -44,7 +44,8 @@ function transformModule( callback: Callback, ): void { if (options.filename.endsWith('.json')) { - return transformJSON(code, options, callback); + transformJSON(code, options, callback); + return; } const {filename, transformer, variants = defaultVariants} = options; @@ -86,6 +87,7 @@ function transformModule( type: options.polyfill ? 'script' : 'module', }); }); + return; } function transformJSON(json, options, callback) { diff --git a/packages/metro-bundler/src/Resolver/__tests__/Resolver-test.js b/packages/metro-bundler/src/Resolver/__tests__/Resolver-test.js index cff9d5dc..821282d4 100644 --- a/packages/metro-bundler/src/Resolver/__tests__/Resolver-test.js +++ b/packages/metro-bundler/src/Resolver/__tests__/Resolver-test.js @@ -237,40 +237,6 @@ describe('Resolver', function() { }); }); - it('should get dependencies with polyfills', function() { - var module = createModule('index'); - var deps = [module]; - - var depResolver = new Resolver({ - projectRoot: '/root', - }); - - DependencyGraph.prototype.getDependencies.mockImplementation(function() { - return Promise.resolve(new ResolutionResponseMock({ - dependencies: deps, - mainModuleId: 'index', - })); - }); - - const polyfill = {}; - DependencyGraph.prototype.createPolyfill.mockReturnValueOnce(polyfill); - return depResolver - .getDependencies( - '/root/index.js', - {dev: true}, - undefined, - undefined, - createGetModuleId() - ).then(function(result) { - expect(result.mainModuleId).toEqual('index'); - expect(DependencyGraph.mock.instances[0].getDependencies) - .toBeCalledWith({entryPath: '/root/index.js', recursive: true}); - expect(result.dependencies[0]).toBe(polyfill); - expect(result.dependencies[result.dependencies.length - 1]) - .toBe(module); - }); - }); - it('should pass in more polyfills', function() { var module = createModule('index'); var deps = [module]; @@ -296,7 +262,9 @@ describe('Resolver', function() { createGetModuleId() ).then(result => { expect(result.mainModuleId).toEqual('index'); - expect(DependencyGraph.prototype.createPolyfill.mock.calls[result.dependencies.length - 2]).toEqual([ + const calls = + DependencyGraph.prototype.createPolyfill.mock.calls[result.dependencies.length - 2]; + expect(calls).toEqual([ {file: 'some module', id: 'some module', dependencies: [ @@ -444,7 +412,8 @@ describe('Resolver', function() { expect(processedCode).toEqual([ '(function(global) {', 'global.fetch = () => 1;', - "\n})(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);", + '\n})' + + "(typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : this);", ].join('')); }); }); diff --git a/packages/metro-bundler/src/Resolver/index.js b/packages/metro-bundler/src/Resolver/index.js index 4e92c0ef..63245edd 100644 --- a/packages/metro-bundler/src/Resolver/index.js +++ b/packages/metro-bundler/src/Resolver/index.js @@ -76,7 +76,8 @@ class Resolver { }, platforms: new Set(opts.platforms), preferNativePlatform: true, - providesModuleNodeModules: opts.providesModuleNodeModules || defaults.providesModuleNodeModules, + providesModuleNodeModules: + opts.providesModuleNodeModules || defaults.providesModuleNodeModules, reporter: opts.reporter, resetCache: opts.resetCache, roots: opts.projectRoots, @@ -261,7 +262,7 @@ function defineModuleCode(moduleName, code, verboseName = '', dev = true) { ].join(''); } -function definePolyfillCode(code,) { +function definePolyfillCode(code) { return [ '(function(global) {', code, diff --git a/packages/metro-bundler/src/Resolver/polyfills/Number.es6.js b/packages/metro-bundler/src/Resolver/polyfills/Number.es6.js index 4b0964e2..bd669c3c 100644 --- a/packages/metro-bundler/src/Resolver/polyfills/Number.es6.js +++ b/packages/metro-bundler/src/Resolver/polyfills/Number.es6.js @@ -27,6 +27,7 @@ if (Number.MIN_SAFE_INTEGER === undefined) { }); } if (!Number.isNaN) { + // eslint-disable-next-line max-len // https://github.com/dherman/tc39-codex-wiki/blob/master/data/es6/number/index.md#polyfill-for-numberisnan const globalIsNaN = global.isNaN; Object.defineProperty(Number, 'isNaN', { diff --git a/packages/metro-bundler/src/Resolver/polyfills/error-guard.js b/packages/metro-bundler/src/Resolver/polyfills/error-guard.js index 08060295..b9330506 100644 --- a/packages/metro-bundler/src/Resolver/polyfills/error-guard.js +++ b/packages/metro-bundler/src/Resolver/polyfills/error-guard.js @@ -52,6 +52,7 @@ const ErrorUtils = { } finally { _inGuard--; } + return null; }, applyWithGuardIfNeeded(fun, context, args) { if (ErrorUtils.inGuard()) { @@ -59,6 +60,7 @@ const ErrorUtils = { } else { ErrorUtils.applyWithGuard(fun, context, args); } + return null; }, inGuard() { return _inGuard; diff --git a/packages/metro-bundler/src/Server/index.js b/packages/metro-bundler/src/Server/index.js index 32ddfc73..c77bea8d 100644 --- a/packages/metro-bundler/src/Server/index.js +++ b/packages/metro-bundler/src/Server/index.js @@ -43,7 +43,8 @@ const { } = require('../Logger'); function debounceAndBatch(fn, delay) { - let timeout, args = []; + let args = []; + let timeout; return value => { args.push(value); clearTimeout(timeout); @@ -957,7 +958,8 @@ class Server { 'entryModuleOnly', false, ), - generateSourceMaps: minify || !dev || this._getBoolOptionFromQuery(urlObj.query, 'babelSourcemap', false), + generateSourceMaps: + minify || !dev || this._getBoolOptionFromQuery(urlObj.query, 'babelSourcemap', false), assetPlugins, }; } diff --git a/packages/metro-bundler/src/lib/relativizeSourceMap.js b/packages/metro-bundler/src/lib/relativizeSourceMap.js index c09cc3d4..4b9050d8 100644 --- a/packages/metro-bundler/src/lib/relativizeSourceMap.js +++ b/packages/metro-bundler/src/lib/relativizeSourceMap.js @@ -17,11 +17,11 @@ import type {MixedSourceMap} from './SourceMap'; function relativizeSourceMapInternal(sourceMap: any, sourcesRoot: string) { if (sourceMap.sections) { - for (var i = 0; i < sourceMap.sections.length; i++) { + for (let i = 0; i < sourceMap.sections.length; i++) { relativizeSourceMapInternal(sourceMap.sections[i].map, sourcesRoot); } } else { - for (var i = 0; i < sourceMap.sources.length; i++) { + for (let i = 0; i < sourceMap.sources.length; i++) { sourceMap.sources[i] = path.relative(sourcesRoot, sourceMap.sources[i]); } } diff --git a/packages/metro-bundler/src/node-haste/DependencyGraph/HasteMap.js b/packages/metro-bundler/src/node-haste/DependencyGraph/HasteMap.js index 975cd305..d869f17c 100644 --- a/packages/metro-bundler/src/node-haste/DependencyGraph/HasteMap.js +++ b/packages/metro-bundler/src/node-haste/DependencyGraph/HasteMap.js @@ -87,6 +87,7 @@ class HasteMap extends EventEmitter { return this._processHasteModule(absPath, invalidated); } } + return null; }); } diff --git a/packages/metro-bundler/src/node-haste/__mocks__/graceful-fs.js b/packages/metro-bundler/src/node-haste/__mocks__/graceful-fs.js index bd429181..638b6c8f 100644 --- a/packages/metro-bundler/src/node-haste/__mocks__/graceful-fs.js +++ b/packages/metro-bundler/src/node-haste/__mocks__/graceful-fs.js @@ -37,7 +37,7 @@ fs.realpath.mockImplementation((filepath, callback) => { if (node && typeof node === 'object' && node.SYMLINK != null) { return callback(null, node.SYMLINK); } - callback(null, filepath); + return callback(null, filepath); }); fs.readdirSync.mockImplementation(filepath => Object.keys(getToNode(filepath))); @@ -58,7 +58,7 @@ fs.readdir.mockImplementation((filepath, callback) => { return callback(new Error(filepath + ' is not a directory.')); } - callback(null, Object.keys(node)); + return callback(null, Object.keys(node)); }); fs.readFile.mockImplementation(function(filepath, encoding, callback) { @@ -76,9 +76,9 @@ fs.readFile.mockImplementation(function(filepath, encoding, callback) { callback(new Error('Error readFile a dir: ' + filepath)); } if (node == null) { - callback(Error('No such file: ' + filepath)); + return callback(Error('No such file: ' + filepath)); } else { - callback(null, node); + return callback(null, node); } } catch (e) { return callback(e); diff --git a/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js b/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js index e3449e62..86149ac9 100644 --- a/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js +++ b/packages/metro-bundler/src/node-haste/__tests__/DependencyGraph-test.js @@ -748,7 +748,7 @@ describe('DependencyGraph', function() { }); }); - it('should work with packages', function() { + it('should work with packages with a trailing slash', function() { var root = '/root'; setMockFileSystem({ 'root': { diff --git a/packages/metro-bundler/src/node-haste/index.js b/packages/metro-bundler/src/node-haste/index.js index 5600b090..a60c7daa 100644 --- a/packages/metro-bundler/src/node-haste/index.js +++ b/packages/metro-bundler/src/node-haste/index.js @@ -130,7 +130,9 @@ class DependencyGraph extends EventEmitter { moduleOptions: this._opts.moduleOptions, reporter: this._opts.reporter, getClosestPackage: filePath => { - let {dir, root} = path.parse(filePath); + const parsedPath = path.parse(filePath); + const root = parsedPath.root; + let dir = parsedPath.dir; do { const candidate = path.join(dir, 'package.json'); if (this._hasteFS.exists(candidate)) { diff --git a/packages/metro-bundler/transformer.js b/packages/metro-bundler/transformer.js index f60b6e5a..88e22d52 100644 --- a/packages/metro-bundler/transformer.js +++ b/packages/metro-bundler/transformer.js @@ -35,7 +35,7 @@ const getBabelRC = (function() { return babelRC; } - babelRC = { plugins: [] }; // empty babelrc + babelRC = {plugins: []}; // empty babelrc // Let's look for the .babelrc in the first project root. // In the future let's look into adding a command line option to specify @@ -54,7 +54,7 @@ const getBabelRC = (function() { ); // Require the babel-preset's listed in the default babel config - babelRC.presets = babelRC.presets.map((preset) => require('babel-preset-' + preset)); + babelRC.presets = babelRC.presets.map(preset => require('babel-preset-' + preset)); babelRC.plugins = resolvePlugins(babelRC.plugins); } else { // if we find a .babelrc file we tell babel to use it