From 412771475c540b6f85d75d9dcd5a39a6e0753582 Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Fri, 8 Dec 2023 11:07:55 -0800 Subject: [PATCH] Apply sort-imports lint rule to all files Summary: Changelog: [Internal] Reviewed By: robhogan Differential Revision: D51946975 fbshipit-source-id: e31c7ccf68f6a6aa4b9fdc154d0d7e4712935d6c --- .../metro-cache/src/stores/HttpGetStore.js | 2 +- packages/metro-config/src/configTypes.flow.js | 5 ++--- packages/metro-config/src/defaults/index.js | 4 ++-- packages/metro-file-map/src/Watcher.js | 12 ++++++------ .../src/crawlers/__tests__/node-test.js | 2 +- .../src/crawlers/__tests__/watchman-test.js | 2 +- .../metro-file-map/src/crawlers/node/index.js | 2 +- .../crawlers/watchman/__tests__/index-test.js | 1 + packages/metro-file-map/src/flow-types.js | 2 +- packages/metro-file-map/src/index.js | 18 +++++++++--------- packages/metro-file-map/src/lib/MockMap.js | 1 + .../metro-file-map/src/lib/MutableHasteMap.js | 2 +- .../src/lib/__tests__/TreeFS-test.js | 2 +- .../__tests__/rootRelativeCacheKeys-test.js | 1 - .../src/watchers/FSEventsWatcher.js | 2 +- .../metro-file-map/src/watchers/NodeWatcher.js | 2 +- .../src/watchers/WatchmanWatcher.js | 4 ++-- .../watchers/__tests__/WatchmanWatcher-test.js | 3 ++- .../src/watchers/__tests__/helpers.js | 10 +++++----- .../src/watchers/__tests__/integration-test.js | 6 +++--- packages/metro-file-map/src/worker.js | 2 +- .../src/PackageExportsResolve.js | 2 +- packages/metro-resolver/src/PackageResolve.js | 2 +- .../src/__tests__/assets-test.js | 2 +- .../metro-resolver/src/__tests__/index-test.js | 3 ++- .../src/__tests__/package-exports-test.js | 2 +- .../src/__tests__/platform-extensions-test.js | 2 +- .../src/__tests__/symlinks-test.js | 3 ++- .../metro-resolver/src/createDefaultContext.js | 2 +- packages/metro-resolver/src/resolve.js | 6 +++--- .../metro-runtime/src/modules/HMRClient.js | 1 - .../__tests__/MetroFastRefreshMockRuntime.js | 7 +++---- .../src/__tests__/generateFunctionMap-test.js | 2 +- .../src/generateFunctionMap.js | 2 +- .../__tests__/inline-requires-plugin-test.js | 4 ++-- packages/metro-transform-worker/src/index.js | 2 +- packages/metro/src/Bundler.js | 2 +- .../metro/src/DeltaBundler/DeltaCalculator.js | 5 +++-- packages/metro/src/DeltaBundler/Graph.js | 6 +++--- .../Serializers/helpers/__tests__/js-test.js | 3 +-- .../Serializers/sourceMapGenerator.js | 12 ++++++------ packages/metro/src/DeltaBundler/Transformer.js | 1 + .../__tests__/DeltaBundler-test.js | 4 ++-- .../__tests__/DeltaCalculator-context-test.js | 9 +++++---- .../__tests__/DeltaCalculator-test.js | 6 +++--- .../src/DeltaBundler/__tests__/Graph-test.js | 9 ++++----- packages/metro/src/DeltaBundler/types.flow.js | 2 +- .../__tests__/collectDependencies-test.js | 2 +- .../ModuleGraph/worker/collectDependencies.js | 2 +- packages/metro/src/Server.js | 7 +++---- packages/metro/src/Server/MultipartResponse.js | 1 + .../Server/__tests__/MultipartResponse-test.js | 2 +- .../metro/src/Server/__tests__/Server-test.js | 8 ++++---- packages/metro/src/Server/symbolicate.js | 3 +-- packages/metro/src/__tests__/HmrServer-test.js | 6 +++--- packages/metro/src/commands/build.js | 8 ++++---- packages/metro/src/commands/dependencies.js | 2 +- packages/metro/src/commands/serve.js | 2 +- packages/metro/src/index.flow.js | 4 ++-- .../__tests__/build-errors-test.js | 4 +--- .../basic_bundle/require-context/conflict.js | 4 ++-- .../basic_bundle/require-context/mode-eager.js | 3 ++- .../require-context/mode-lazy-once.js | 3 ++- .../basic_bundle/require-context/mode-lazy.js | 3 ++- .../basic_bundle/require-context/mode-sync.js | 3 ++- .../src/lib/__tests__/contextModule-test.js | 2 +- packages/metro/src/lib/contextModule.js | 5 +++-- .../metro/src/lib/contextModuleTemplates.js | 5 +++-- packages/metro/src/lib/reporting.js | 4 ++-- packages/metro/src/lib/transformHelpers.js | 5 ++--- .../metro/src/node-haste/DependencyGraph.js | 12 ++++++------ .../DependencyGraph/ModuleResolution.js | 12 ++++++------ packages/metro/src/shared/types.flow.js | 2 +- scripts/__tests__/babel-lib-defs-test.js | 2 +- scripts/__tests__/subpackages-test.js | 2 +- .../generateBabelFlowLibraryDefinitions.js | 4 ++-- scripts/updateBabelFlowLibraryDefinitions.js | 2 +- 77 files changed, 157 insertions(+), 153 deletions(-) diff --git a/packages/metro-cache/src/stores/HttpGetStore.js b/packages/metro-cache/src/stores/HttpGetStore.js index c10c077c25..9dc163651a 100644 --- a/packages/metro-cache/src/stores/HttpGetStore.js +++ b/packages/metro-cache/src/stores/HttpGetStore.js @@ -10,9 +10,9 @@ 'use strict'; -import type {HttpOptions} from 'metro-cache'; import type HttpError from './HttpError'; import type NetworkError from './NetworkError'; +import type {HttpOptions} from 'metro-cache'; const HttpStore = require('./HttpStore'); const {Logger} = require('metro-core'); diff --git a/packages/metro-config/src/configTypes.flow.js b/packages/metro-config/src/configTypes.flow.js index 393c26c732..2c1f27b4b8 100644 --- a/packages/metro-config/src/configTypes.flow.js +++ b/packages/metro-config/src/configTypes.flow.js @@ -10,6 +10,7 @@ 'use strict'; +import type {IntermediateStackFrame} from '../../metro/src/Server/symbolicate'; import type {HandleFunction, Server} from 'connect'; import type {CacheStore} from 'metro-cache'; import typeof MetroCache from 'metro-cache'; @@ -17,8 +18,6 @@ import type {CacheManagerFactory} from 'metro-file-map'; import type {CustomResolver} from 'metro-resolver'; import type {JsTransformerConfig} from 'metro-transform-worker'; import type {TransformResult} from 'metro/src/DeltaBundler'; -import type MetroServer from 'metro/src/Server'; - import type { DeltaResult, Module, @@ -26,7 +25,7 @@ import type { SerializerOptions, } from 'metro/src/DeltaBundler/types.flow.js'; import type {Reporter} from 'metro/src/lib/reporting'; -import type {IntermediateStackFrame} from '../../metro/src/Server/symbolicate'; +import type MetroServer from 'metro/src/Server'; export type ExtraTransformOptions = { +preloadedModules?: {[path: string]: true, ...} | false, diff --git a/packages/metro-config/src/defaults/index.js b/packages/metro-config/src/defaults/index.js index fbbdf8430d..9a1ab9a943 100644 --- a/packages/metro-config/src/defaults/index.js +++ b/packages/metro-config/src/defaults/index.js @@ -15,13 +15,13 @@ import type {ConfigT} from '../configTypes.flow'; const { DEFAULT_METRO_MINIFIER_PATH, + additionalExts, assetExts, assetResolutions, - additionalExts, defaultCreateModuleIdFactory, + noopPerfLoggerFactory, platforms, sourceExts, - noopPerfLoggerFactory, } = require('./defaults'); const exclusionList = require('./exclusionList'); const {FileStore} = require('metro-cache'); diff --git a/packages/metro-file-map/src/Watcher.js b/packages/metro-file-map/src/Watcher.js index 1d9a1fb614..e7f182e266 100644 --- a/packages/metro-file-map/src/Watcher.js +++ b/packages/metro-file-map/src/Watcher.js @@ -20,17 +20,17 @@ import type { import type {WatcherOptions as WatcherBackendOptions} from './watchers/common'; import type {AbortSignal} from 'node-abort-controller'; -import watchmanCrawl from './crawlers/watchman'; import nodeCrawl from './crawlers/node'; -import WatchmanWatcher from './watchers/WatchmanWatcher'; +import watchmanCrawl from './crawlers/watchman'; +import {ADD_EVENT, CHANGE_EVENT} from './watchers/common'; import FSEventsWatcher from './watchers/FSEventsWatcher'; import NodeWatcher from './watchers/NodeWatcher'; -import * as path from 'path'; -import * as fs from 'fs'; -import {ADD_EVENT, CHANGE_EVENT} from './watchers/common'; +import WatchmanWatcher from './watchers/WatchmanWatcher'; import EventEmitter from 'events'; -import {performance} from 'perf_hooks'; +import * as fs from 'fs'; import nullthrows from 'nullthrows'; +import * as path from 'path'; +import {performance} from 'perf_hooks'; const debug = require('debug')('Metro:Watcher'); diff --git a/packages/metro-file-map/src/crawlers/__tests__/node-test.js b/packages/metro-file-map/src/crawlers/__tests__/node-test.js index 76bb3fa5c2..0dfc299016 100644 --- a/packages/metro-file-map/src/crawlers/__tests__/node-test.js +++ b/packages/metro-file-map/src/crawlers/__tests__/node-test.js @@ -8,8 +8,8 @@ * @oncall react_native */ -import {AbortController} from 'node-abort-controller'; import TreeFS from '../../lib/TreeFS'; +import {AbortController} from 'node-abort-controller'; jest.useRealTimers(); diff --git a/packages/metro-file-map/src/crawlers/__tests__/watchman-test.js b/packages/metro-file-map/src/crawlers/__tests__/watchman-test.js index 75b500fcbf..e4cc0dce40 100644 --- a/packages/metro-file-map/src/crawlers/__tests__/watchman-test.js +++ b/packages/metro-file-map/src/crawlers/__tests__/watchman-test.js @@ -8,8 +8,8 @@ * @oncall react_native */ -import {AbortController} from 'node-abort-controller'; import TreeFS from '../../lib/TreeFS'; +import {AbortController} from 'node-abort-controller'; const path = require('path'); diff --git a/packages/metro-file-map/src/crawlers/node/index.js b/packages/metro-file-map/src/crawlers/node/index.js index f0dc36f869..36265542b8 100644 --- a/packages/metro-file-map/src/crawlers/node/index.js +++ b/packages/metro-file-map/src/crawlers/node/index.js @@ -16,8 +16,8 @@ import type { IgnoreMatcher, } from '../../flow-types'; -import hasNativeFindSupport from './hasNativeFindSupport'; import * as fastPath from '../../lib/fast_path'; +import hasNativeFindSupport from './hasNativeFindSupport'; import {spawn} from 'child_process'; import * as fs from 'graceful-fs'; import {platform} from 'os'; diff --git a/packages/metro-file-map/src/crawlers/watchman/__tests__/index-test.js b/packages/metro-file-map/src/crawlers/watchman/__tests__/index-test.js index 44e30bbe8f..7167447b53 100644 --- a/packages/metro-file-map/src/crawlers/watchman/__tests__/index-test.js +++ b/packages/metro-file-map/src/crawlers/watchman/__tests__/index-test.js @@ -10,6 +10,7 @@ */ import type {CrawlerOptions} from '../../../flow-types'; + import TreeFS from '../../../lib/TreeFS'; import watchmanCrawl from '../index'; import EventEmitter from 'events'; diff --git a/packages/metro-file-map/src/flow-types.js b/packages/metro-file-map/src/flow-types.js index d6b1573e67..36f7c4f2a0 100644 --- a/packages/metro-file-map/src/flow-types.js +++ b/packages/metro-file-map/src/flow-types.js @@ -11,7 +11,7 @@ 'use strict'; -import type {PerfLoggerFactory, RootPerfLogger, PerfLogger} from 'metro-config'; +import type {PerfLogger, PerfLoggerFactory, RootPerfLogger} from 'metro-config'; import type {AbortSignal} from 'node-abort-controller'; export type {PerfLoggerFactory, PerfLogger}; diff --git a/packages/metro-file-map/src/index.js b/packages/metro-file-map/src/index.js index e15823c64f..fa080f441c 100644 --- a/packages/metro-file-map/src/index.js +++ b/packages/metro-file-map/src/index.js @@ -9,7 +9,6 @@ * @oncall react_native */ -import type {IJestWorker} from 'jest-worker'; import type { BuildParameters, BuildResult, @@ -19,24 +18,25 @@ import type { CanonicalPath, ChangeEvent, ChangeEventMetadata, - CrawlerOptions, Console, + CrawlerOptions, EventsQueue, FileData, FileMetaData, FileSystem, - HType, HasteMapData, HasteMapItem, + HType, MutableFileSystem, Path, - PerfLoggerFactory, PerfLogger, + PerfLoggerFactory, RawMockMap, ReadOnlyRawMockMap, - WorkerMetadata, WatchmanClocks, + WorkerMetadata, } from './flow-types'; +import type {IJestWorker} from 'jest-worker'; import {DiskCacheManager} from './cache/DiskCacheManager'; import H from './constants'; @@ -44,19 +44,19 @@ import getMockName from './getMockName'; import checkWatchmanCapabilities from './lib/checkWatchmanCapabilities'; import {DuplicateError} from './lib/DuplicateError'; import * as fastPath from './lib/fast_path'; +import MockMapImpl from './lib/MockMap'; +import MutableHasteMap from './lib/MutableHasteMap'; import normalizePathSeparatorsToSystem from './lib/normalizePathSeparatorsToSystem'; import TreeFS from './lib/TreeFS'; -import MutableHasteMap from './lib/MutableHasteMap'; import {Watcher} from './Watcher'; import {worker} from './worker'; import EventEmitter from 'events'; import invariant from 'invariant'; import {Worker} from 'jest-worker'; -import * as path from 'path'; import {AbortController} from 'node-abort-controller'; -import {performance} from 'perf_hooks'; import nullthrows from 'nullthrows'; -import MockMapImpl from './lib/MockMap'; +import * as path from 'path'; +import {performance} from 'perf_hooks'; const debug = require('debug')('Metro:FileMap'); diff --git a/packages/metro-file-map/src/lib/MockMap.js b/packages/metro-file-map/src/lib/MockMap.js index 5165d8b0e0..9ed6a46531 100644 --- a/packages/metro-file-map/src/lib/MockMap.js +++ b/packages/metro-file-map/src/lib/MockMap.js @@ -10,6 +10,7 @@ */ import type {MockMap as IMockMap, Path, RawMockMap} from '../flow-types'; + import {resolve} from './fast_path'; export default class MockMap implements IMockMap { diff --git a/packages/metro-file-map/src/lib/MutableHasteMap.js b/packages/metro-file-map/src/lib/MutableHasteMap.js index a73544cc9f..c83589cde4 100644 --- a/packages/metro-file-map/src/lib/MutableHasteMap.js +++ b/packages/metro-file-map/src/lib/MutableHasteMap.js @@ -13,10 +13,10 @@ import type { Console, DuplicatesIndex, DuplicatesSet, - HTypeValue, HasteMap, HasteMapItem, HasteMapItemMetaData, + HTypeValue, Path, RawHasteMap, ReadOnlyRawHasteMap, diff --git a/packages/metro-file-map/src/lib/__tests__/TreeFS-test.js b/packages/metro-file-map/src/lib/__tests__/TreeFS-test.js index c611d2bc7a..9f9bad394b 100644 --- a/packages/metro-file-map/src/lib/__tests__/TreeFS-test.js +++ b/packages/metro-file-map/src/lib/__tests__/TreeFS-test.js @@ -9,8 +9,8 @@ * @oncall react_native */ -import type TreeFS from '../TreeFS'; import type {FileData} from '../../flow-types'; +import type TreeFS from '../TreeFS'; let mockPathModule; jest.mock('path', () => mockPathModule); diff --git a/packages/metro-file-map/src/lib/__tests__/rootRelativeCacheKeys-test.js b/packages/metro-file-map/src/lib/__tests__/rootRelativeCacheKeys-test.js index dea70ba72b..a0620bc0f4 100644 --- a/packages/metro-file-map/src/lib/__tests__/rootRelativeCacheKeys-test.js +++ b/packages/metro-file-map/src/lib/__tests__/rootRelativeCacheKeys-test.js @@ -9,7 +9,6 @@ */ import type {BuildParameters} from '../../flow-types'; - import typeof PathModule from 'path'; import rootRelativeCacheKeys from '../rootRelativeCacheKeys'; diff --git a/packages/metro-file-map/src/watchers/FSEventsWatcher.js b/packages/metro-file-map/src/watchers/FSEventsWatcher.js index bec0c08541..bf30356b10 100644 --- a/packages/metro-file-map/src/watchers/FSEventsWatcher.js +++ b/packages/metro-file-map/src/watchers/FSEventsWatcher.js @@ -13,6 +13,7 @@ import type {Stats} from 'fs'; // $FlowFixMe[cannot-resolve-module] - Optional, Darwin only import type {FSEvents} from 'fsevents'; +import {isIncluded, typeFromStat} from './common'; // $FlowFixMe[untyped-import] - anymatch import anymatch from 'anymatch'; import EventEmitter from 'events'; @@ -20,7 +21,6 @@ import {promises as fsPromises} from 'fs'; import * as path from 'path'; // $FlowFixMe[untyped-import] - walker import walker from 'walker'; -import {isIncluded, typeFromStat} from './common'; const debug = require('debug')('Metro:FSEventsWatcher'); diff --git a/packages/metro-file-map/src/watchers/NodeWatcher.js b/packages/metro-file-map/src/watchers/NodeWatcher.js index 483f2b3678..0fd1d6a990 100644 --- a/packages/metro-file-map/src/watchers/NodeWatcher.js +++ b/packages/metro-file-map/src/watchers/NodeWatcher.js @@ -15,8 +15,8 @@ 'use strict'; -import type {WatcherOptions} from './common'; import type {ChangeEventMetadata} from '../flow-types'; +import type {WatcherOptions} from './common'; import type {FSWatcher, Stats} from 'fs'; const common = require('./common'); diff --git a/packages/metro-file-map/src/watchers/WatchmanWatcher.js b/packages/metro-file-map/src/watchers/WatchmanWatcher.js index dd85588f90..3a0d571337 100644 --- a/packages/metro-file-map/src/watchers/WatchmanWatcher.js +++ b/packages/metro-file-map/src/watchers/WatchmanWatcher.js @@ -9,15 +9,15 @@ * @oncall react_native */ -import type {WatcherOptions} from './common'; import type {ChangeEventMetadata} from '../flow-types'; +import type {WatcherOptions} from './common'; import type { Client, WatchmanClockResponse, WatchmanFileChange, WatchmanQuery, - WatchmanSubscriptionEvent, WatchmanSubscribeResponse, + WatchmanSubscriptionEvent, WatchmanWatchResponse, } from 'fb-watchman'; diff --git a/packages/metro-file-map/src/watchers/__tests__/WatchmanWatcher-test.js b/packages/metro-file-map/src/watchers/__tests__/WatchmanWatcher-test.js index 968caa87c4..f4cccde538 100644 --- a/packages/metro-file-map/src/watchers/__tests__/WatchmanWatcher-test.js +++ b/packages/metro-file-map/src/watchers/__tests__/WatchmanWatcher-test.js @@ -10,10 +10,11 @@ */ import type { - WatchmanSubscribeResponse, WatchmanClockResponse, + WatchmanSubscribeResponse, WatchmanWatchResponse, } from 'fb-watchman'; + import WatchmanWatcher from '../WatchmanWatcher'; import EventEmitter from 'events'; diff --git a/packages/metro-file-map/src/watchers/__tests__/helpers.js b/packages/metro-file-map/src/watchers/__tests__/helpers.js index 58ead90d7a..e852e5d435 100644 --- a/packages/metro-file-map/src/watchers/__tests__/helpers.js +++ b/packages/metro-file-map/src/watchers/__tests__/helpers.js @@ -9,17 +9,17 @@ * @oncall react_native */ +import type {ChangeEventMetadata} from '../../flow-types'; import type {WatcherOptions} from '../common'; -import NodeWatcher from '../NodeWatcher'; import FSEventsWatcher from '../FSEventsWatcher'; +import NodeWatcher from '../NodeWatcher'; import WatchmanWatcher from '../WatchmanWatcher'; -import type {ChangeEventMetadata} from '../../flow-types'; -import {promises as fsPromises} from 'fs'; import {execSync} from 'child_process'; -import {join} from 'path'; -import os from 'os'; +import {promises as fsPromises} from 'fs'; import invariant from 'invariant'; +import os from 'os'; +import {join} from 'path'; jest.useRealTimers(); diff --git a/packages/metro-file-map/src/watchers/__tests__/integration-test.js b/packages/metro-file-map/src/watchers/__tests__/integration-test.js index e95bc941fc..3c6cf4751f 100644 --- a/packages/metro-file-map/src/watchers/__tests__/integration-test.js +++ b/packages/metro-file-map/src/watchers/__tests__/integration-test.js @@ -9,13 +9,13 @@ * @oncall react_native */ -import type {EventHelpers} from './helpers'; import type {WatcherOptions} from '../common'; +import type {EventHelpers} from './helpers'; import FSEventsWatcher from '../FSEventsWatcher'; -import {createTempWatchRoot, startWatching, WATCHERS} from './helpers'; -import os from 'os'; +import {WATCHERS, createTempWatchRoot, startWatching} from './helpers'; import {promises as fsPromises} from 'fs'; +import os from 'os'; import {join} from 'path'; const {mkdir, writeFile, rm, symlink, unlink} = fsPromises; diff --git a/packages/metro-file-map/src/worker.js b/packages/metro-file-map/src/worker.js index c48993ad1d..3021a022e6 100644 --- a/packages/metro-file-map/src/worker.js +++ b/packages/metro-file-map/src/worker.js @@ -18,8 +18,8 @@ const H = require('./constants'); const dependencyExtractor = require('./lib/dependencyExtractor'); const excludedExtensions = require('./workerExclusionList'); const {createHash} = require('crypto'); -const fs = require('graceful-fs'); const {promises: fsPromises} = require('fs'); +const fs = require('graceful-fs'); const path = require('path'); const PACKAGE_JSON = path.sep + 'package.json'; diff --git a/packages/metro-resolver/src/PackageExportsResolve.js b/packages/metro-resolver/src/PackageExportsResolve.js index 803296f4d9..4e5eae737d 100644 --- a/packages/metro-resolver/src/PackageExportsResolve.js +++ b/packages/metro-resolver/src/PackageExportsResolve.js @@ -17,12 +17,12 @@ import type { ResolutionContext, } from './types'; -import path from 'path'; import InvalidPackageConfigurationError from './errors/InvalidPackageConfigurationError'; import PackagePathNotExportedError from './errors/PackagePathNotExportedError'; import resolveAsset from './resolveAsset'; import isAssetFile from './utils/isAssetFile'; import toPosixPath from './utils/toPosixPath'; +import path from 'path'; /** * Resolve a package subpath based on the entry points defined in the package's diff --git a/packages/metro-resolver/src/PackageResolve.js b/packages/metro-resolver/src/PackageResolve.js index 55d5e434c2..f077f44c01 100644 --- a/packages/metro-resolver/src/PackageResolve.js +++ b/packages/metro-resolver/src/PackageResolve.js @@ -11,8 +11,8 @@ import type {PackageInfo, PackageJson, ResolutionContext} from './types'; -import path from 'path'; import toPosixPath from './utils/toPosixPath'; +import path from 'path'; /** * Resolve the main entry point subpath for a package. diff --git a/packages/metro-resolver/src/__tests__/assets-test.js b/packages/metro-resolver/src/__tests__/assets-test.js index 91a0515129..6b9ff340ee 100644 --- a/packages/metro-resolver/src/__tests__/assets-test.js +++ b/packages/metro-resolver/src/__tests__/assets-test.js @@ -11,9 +11,9 @@ 'use strict'; -import path from 'path'; import Resolver from '../index'; import {createResolutionContext} from './utils'; +import path from 'path'; describe('asset resolutions', () => { const baseContext = { diff --git a/packages/metro-resolver/src/__tests__/index-test.js b/packages/metro-resolver/src/__tests__/index-test.js index b6e1f3bedc..0f206278a2 100644 --- a/packages/metro-resolver/src/__tests__/index-test.js +++ b/packages/metro-resolver/src/__tests__/index-test.js @@ -13,9 +13,10 @@ import type {ResolutionContext} from '../index'; +import {createResolutionContext} from './utils'; + const FailedToResolvePathError = require('../errors/FailedToResolvePathError'); const Resolver = require('../index'); -import {createResolutionContext} from './utils'; const fileMap = { '/root/project/foo.js': '', diff --git a/packages/metro-resolver/src/__tests__/package-exports-test.js b/packages/metro-resolver/src/__tests__/package-exports-test.js index 9b2787f30d..a277bdd42d 100644 --- a/packages/metro-resolver/src/__tests__/package-exports-test.js +++ b/packages/metro-resolver/src/__tests__/package-exports-test.js @@ -9,9 +9,9 @@ * @oncall react_native */ -import path from 'path'; import Resolver from '../index'; import {createPackageAccessors, createResolutionContext} from './utils'; +import path from 'path'; // Tests validating Package Exports resolution behaviour. See RFC0534: // https://github.com/react-native-community/discussions-and-proposals/blob/master/proposals/0534-metro-package-exports-support.md diff --git a/packages/metro-resolver/src/__tests__/platform-extensions-test.js b/packages/metro-resolver/src/__tests__/platform-extensions-test.js index 4583dec600..d3d2ee219d 100644 --- a/packages/metro-resolver/src/__tests__/platform-extensions-test.js +++ b/packages/metro-resolver/src/__tests__/platform-extensions-test.js @@ -11,8 +11,8 @@ import type {ResolutionContext} from '../index'; -import Resolver from '../index'; import FailedToResolvePathError from '../errors/FailedToResolvePathError'; +import Resolver from '../index'; import {createResolutionContext} from './utils'; const fileMap = { diff --git a/packages/metro-resolver/src/__tests__/symlinks-test.js b/packages/metro-resolver/src/__tests__/symlinks-test.js index 9096e3436a..9a2d0361b0 100644 --- a/packages/metro-resolver/src/__tests__/symlinks-test.js +++ b/packages/metro-resolver/src/__tests__/symlinks-test.js @@ -13,9 +13,10 @@ import type {ResolutionContext} from '../index'; +import {createResolutionContext} from './utils'; + const FailedToResolvePathError = require('../errors/FailedToResolvePathError'); const Resolver = require('../index'); -import {createResolutionContext} from './utils'; const fileMap = { '/root/project/foo.js': '', diff --git a/packages/metro-resolver/src/createDefaultContext.js b/packages/metro-resolver/src/createDefaultContext.js index d318774b89..d56e14b790 100644 --- a/packages/metro-resolver/src/createDefaultContext.js +++ b/packages/metro-resolver/src/createDefaultContext.js @@ -9,8 +9,8 @@ * @oncall react_native */ -import type {TransformResultDependency} from 'metro/src/DeltaBundler/types.flow'; import type {ResolutionContext} from './types'; +import type {TransformResultDependency} from 'metro/src/DeltaBundler/types.flow'; import {redirectModulePath} from './PackageResolve'; diff --git a/packages/metro-resolver/src/resolve.js b/packages/metro-resolver/src/resolve.js index 3ddd677452..9c88ce8819 100644 --- a/packages/metro-resolver/src/resolve.js +++ b/packages/metro-resolver/src/resolve.js @@ -19,17 +19,17 @@ import type { Result, } from './types'; -import path from 'path'; import FailedToResolveNameError from './errors/FailedToResolveNameError'; import FailedToResolvePathError from './errors/FailedToResolvePathError'; +import formatFileCandidates from './errors/formatFileCandidates'; import InvalidPackageConfigurationError from './errors/InvalidPackageConfigurationError'; import InvalidPackageError from './errors/InvalidPackageError'; import PackagePathNotExportedError from './errors/PackagePathNotExportedError'; -import formatFileCandidates from './errors/formatFileCandidates'; -import {getPackageEntryPoint} from './PackageResolve'; import {resolvePackageTargetFromExports} from './PackageExportsResolve'; +import {getPackageEntryPoint} from './PackageResolve'; import resolveAsset from './resolveAsset'; import isAssetFile from './utils/isAssetFile'; +import path from 'path'; function resolve( context: ResolutionContext, diff --git a/packages/metro-runtime/src/modules/HMRClient.js b/packages/metro-runtime/src/modules/HMRClient.js index 751da32fc7..0ad4c2b4c4 100644 --- a/packages/metro-runtime/src/modules/HMRClient.js +++ b/packages/metro-runtime/src/modules/HMRClient.js @@ -11,7 +11,6 @@ 'use strict'; import type {HmrModule} from './types.flow'; - import type {HmrMessage, HmrUpdate} from './types.flow'; const EventEmitter = require('./vendor/eventemitter3'); diff --git a/packages/metro-runtime/src/polyfills/__tests__/MetroFastRefreshMockRuntime.js b/packages/metro-runtime/src/polyfills/__tests__/MetroFastRefreshMockRuntime.js index ea2f55ab28..aa3728c888 100644 --- a/packages/metro-runtime/src/polyfills/__tests__/MetroFastRefreshMockRuntime.js +++ b/packages/metro-runtime/src/polyfills/__tests__/MetroFastRefreshMockRuntime.js @@ -9,14 +9,13 @@ * @oncall react_native */ -import {transformSync} from '@babel/core'; -import fs from 'fs'; - +import type {DefineFn, RequireFn} from '../require'; import typeof React from 'react'; import typeof ReactRefreshRuntime from 'react-refresh/runtime'; import typeof ReactTestRenderer from 'react-test-renderer'; -import type {DefineFn, RequireFn} from '../require'; +import {transformSync} from '@babel/core'; +import fs from 'fs'; type RuntimeGlobal = Object; diff --git a/packages/metro-source-map/src/__tests__/generateFunctionMap-test.js b/packages/metro-source-map/src/__tests__/generateFunctionMap-test.js index 5ce262b19e..4c619ae54b 100644 --- a/packages/metro-source-map/src/__tests__/generateFunctionMap-test.js +++ b/packages/metro-source-map/src/__tests__/generateFunctionMap-test.js @@ -11,8 +11,8 @@ 'use strict'; -import type {MetroBabelFileMetadata} from 'metro-babel-transformer'; import type {Context} from '../generateFunctionMap'; +import type {MetroBabelFileMetadata} from 'metro-babel-transformer'; const { functionMapBabelPlugin, diff --git a/packages/metro-source-map/src/generateFunctionMap.js b/packages/metro-source-map/src/generateFunctionMap.js index 9e773fcd07..bb8a3f2699 100644 --- a/packages/metro-source-map/src/generateFunctionMap.js +++ b/packages/metro-source-map/src/generateFunctionMap.js @@ -11,11 +11,11 @@ 'use strict'; -import type {MetroBabelFileMetadata} from 'metro-babel-transformer'; import type {FBSourceFunctionMap} from './source-map'; import type {PluginObj} from '@babel/core'; import type {NodePath} from '@babel/traverse'; import type {Node} from '@babel/types'; +import type {MetroBabelFileMetadata} from 'metro-babel-transformer'; import traverse from '@babel/traverse'; import { diff --git a/packages/metro-transform-plugins/src/__tests__/inline-requires-plugin-test.js b/packages/metro-transform-plugins/src/__tests__/inline-requires-plugin-test.js index 4d9430cdca..d3f6541a92 100644 --- a/packages/metro-transform-plugins/src/__tests__/inline-requires-plugin-test.js +++ b/packages/metro-transform-plugins/src/__tests__/inline-requires-plugin-test.js @@ -11,10 +11,10 @@ 'use strict'; -const babel = require('@babel/core'); const inlineRequiresPlugin = require('../inline-requires-plugin'); -const pluginTester = require('babel-plugin-tester'); const validateOutputAst = require('./validateOutputAst'); +const babel = require('@babel/core'); +const pluginTester = require('babel-plugin-tester'); pluginTester({ babelOptions: { diff --git a/packages/metro-transform-worker/src/index.js b/packages/metro-transform-worker/src/index.js index aebc3406fb..e5f1d55439 100644 --- a/packages/metro-transform-worker/src/index.js +++ b/packages/metro-transform-worker/src/index.js @@ -45,10 +45,10 @@ const { } = require('metro-source-map'); const metroTransformPlugins = require('metro-transform-plugins'); const countLines = require('metro/src/lib/countLines'); +const collectDependencies = require('metro/src/ModuleGraph/worker/collectDependencies'); const { InvalidRequireCallError: InternalInvalidRequireCallError, } = require('metro/src/ModuleGraph/worker/collectDependencies'); -const collectDependencies = require('metro/src/ModuleGraph/worker/collectDependencies'); const generateImportNames = require('metro/src/ModuleGraph/worker/generateImportNames'); const JsFileWrapping = require('metro/src/ModuleGraph/worker/JsFileWrapping'); const nullthrows = require('nullthrows'); diff --git a/packages/metro/src/Bundler.js b/packages/metro/src/Bundler.js index 80bad14167..f32590b0aa 100644 --- a/packages/metro/src/Bundler.js +++ b/packages/metro/src/Bundler.js @@ -13,8 +13,8 @@ import type {TransformResultWithSource} from './DeltaBundler'; import type {TransformOptions} from './DeltaBundler/Worker'; -import type {ConfigT} from 'metro-config/src/configTypes.flow'; import type EventEmitter from 'events'; +import type {ConfigT} from 'metro-config/src/configTypes.flow'; const Transformer = require('./DeltaBundler/Transformer'); const DependencyGraph = require('./node-haste/DependencyGraph'); diff --git a/packages/metro/src/DeltaBundler/DeltaCalculator.js b/packages/metro/src/DeltaBundler/DeltaCalculator.js index da104ac7e7..61cfb48d3c 100644 --- a/packages/metro/src/DeltaBundler/DeltaCalculator.js +++ b/packages/metro/src/DeltaBundler/DeltaCalculator.js @@ -11,12 +11,13 @@ 'use strict'; -import path from 'path'; -import {Graph} from './Graph'; import type {DeltaResult, Options} from './types.flow'; import type {RootPerfLogger} from 'metro-config'; import type {ChangeEventMetadata} from 'metro-file-map'; +import {Graph} from './Graph'; +import path from 'path'; + const debug = require('debug')('Metro:DeltaCalculator'); const {EventEmitter} = require('events'); diff --git a/packages/metro/src/DeltaBundler/Graph.js b/packages/metro/src/DeltaBundler/Graph.js index 2ea655c002..4a51282c60 100644 --- a/packages/metro/src/DeltaBundler/Graph.js +++ b/packages/metro/src/DeltaBundler/Graph.js @@ -29,8 +29,8 @@ * nodes and entries in the importBundleNodes set. */ -import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies'; import type {RequireContext} from '../lib/contextModule'; +import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies'; import type { Dependencies, Dependency, @@ -42,13 +42,13 @@ import type { TransformResultDependency, } from './types.flow'; -import CountingSet from '../lib/CountingSet'; import { deriveAbsolutePathFromContext, fileMatchesContext, } from '../lib/contextModule'; - +import CountingSet from '../lib/CountingSet'; import * as path from 'path'; + const invariant = require('invariant'); const nullthrows = require('nullthrows'); diff --git a/packages/metro/src/DeltaBundler/Serializers/helpers/__tests__/js-test.js b/packages/metro/src/DeltaBundler/Serializers/helpers/__tests__/js-test.js index c6cdd4c576..e5d1a3a182 100644 --- a/packages/metro/src/DeltaBundler/Serializers/helpers/__tests__/js-test.js +++ b/packages/metro/src/DeltaBundler/Serializers/helpers/__tests__/js-test.js @@ -12,10 +12,9 @@ import type {Dependency} from '../../../types.flow'; import CountingSet from '../../../../lib/CountingSet'; - -import {wrap as raw} from 'jest-snapshot-serializer-raw'; import createModuleIdFactory from '../../../../lib/createModuleIdFactory'; import {wrapModule} from '../js'; +import {wrap as raw} from 'jest-snapshot-serializer-raw'; import nullthrows from 'nullthrows'; let myModule; diff --git a/packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js b/packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js index 1557d63c7d..d15b8cf18a 100644 --- a/packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js +++ b/packages/metro/src/DeltaBundler/Serializers/sourceMapGenerator.js @@ -13,12 +13,6 @@ import type {Module} from '../types.flow'; -export type SourceMapGeneratorOptions = $ReadOnly<{ - excludeSource: boolean, - processModuleFilter: (module: Module<>) => boolean, - shouldAddToIgnoreList: (module: Module<>) => boolean, -}>; - const getSourceMapInfo = require('./helpers/getSourceMapInfo'); const {isJsModule} = require('./helpers/js'); const { @@ -26,6 +20,12 @@ const { fromRawMappingsNonBlocking, } = require('metro-source-map'); +export type SourceMapGeneratorOptions = $ReadOnly<{ + excludeSource: boolean, + processModuleFilter: (module: Module<>) => boolean, + shouldAddToIgnoreList: (module: Module<>) => boolean, +}>; + function getSourceMapInfosImpl( isBlocking: boolean, onDone: ($ReadOnlyArray>) => void, diff --git a/packages/metro/src/DeltaBundler/Transformer.js b/packages/metro/src/DeltaBundler/Transformer.js index 1a61f49d2e..fe788627a8 100644 --- a/packages/metro/src/DeltaBundler/Transformer.js +++ b/packages/metro/src/DeltaBundler/Transformer.js @@ -14,6 +14,7 @@ import type {TransformResult, TransformResultWithSource} from '../DeltaBundler'; import type {TransformerConfig, TransformOptions} from './Worker'; import type {ConfigT} from 'metro-config/src/configTypes.flow'; + import crypto from 'crypto'; const getTransformCacheKey = require('./getTransformCacheKey'); diff --git a/packages/metro/src/DeltaBundler/__tests__/DeltaBundler-test.js b/packages/metro/src/DeltaBundler/__tests__/DeltaBundler-test.js index ab862aab52..7c4b43070e 100644 --- a/packages/metro/src/DeltaBundler/__tests__/DeltaBundler-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/DeltaBundler-test.js @@ -13,12 +13,12 @@ import type {TransformResultDependency} from '../types.flow'; -jest.mock('../DeltaCalculator'); - const DeltaBundler = require('../../DeltaBundler'); const DeltaCalculator = require('../DeltaCalculator'); const {EventEmitter} = require('events'); +jest.mock('../DeltaCalculator'); + describe('DeltaBundler', () => { let deltaBundler; diff --git a/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-context-test.js b/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-context-test.js index 41f8eddc62..f5657f85ad 100644 --- a/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-context-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-context-test.js @@ -11,11 +11,15 @@ 'use strict'; -import type {Options, TransformResultDependency} from '../types.flow'; import type {Result} from '../Graph'; +import type {Options, TransformResultDependency} from '../types.flow'; + import CountingSet from '../../lib/CountingSet'; import {Graph} from '../Graph'; +const DeltaCalculator = require('../DeltaCalculator'); +const {EventEmitter} = require('events'); + const traverseDependencies = jest.spyOn( Graph.prototype, 'traverseDependencies', @@ -29,9 +33,6 @@ const markModifiedContextModules = jest.spyOn( 'markModifiedContextModules', ); -const DeltaCalculator = require('../DeltaCalculator'); -const {EventEmitter} = require('events'); - describe('DeltaCalculator + require.context', () => { let deltaCalculator; let fileWatcher; diff --git a/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js b/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js index 7c00ffba74..6f3dcbac95 100644 --- a/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js @@ -9,16 +9,16 @@ * @oncall react_native */ +import type {Graph as GraphType, Result} from '../Graph'; import type { + Dependency, Module, Options, - Dependency, TransformResultDependency, } from '../types.flow'; -import type {Graph as GraphType, Result} from '../Graph'; -import path from 'path'; import CountingSet from '../../lib/CountingSet'; +import path from 'path'; jest.mock('../../Bundler'); diff --git a/packages/metro/src/DeltaBundler/__tests__/Graph-test.js b/packages/metro/src/DeltaBundler/__tests__/Graph-test.js index bec2570adb..68d50f47da 100644 --- a/packages/metro/src/DeltaBundler/__tests__/Graph-test.js +++ b/packages/metro/src/DeltaBundler/__tests__/Graph-test.js @@ -32,6 +32,8 @@ * boxes/lines as needed). */ +import type {RequireContext} from '../../lib/contextModule'; +import type {Result} from '../Graph'; import type { Dependency, MixedOutput, @@ -42,14 +44,11 @@ import type { TransformResultDependency, TransformResultWithSource, } from '../types.flow'; -import type {Result} from '../Graph'; -import type {RequireContext} from '../../lib/contextModule'; -import CountingSet from '../../lib/CountingSet'; import {deriveAbsolutePathFromContext} from '../../lib/contextModule'; -import nullthrows from 'nullthrows'; - +import CountingSet from '../../lib/CountingSet'; import {Graph} from '../Graph'; +import nullthrows from 'nullthrows'; const {objectContaining} = expect; diff --git a/packages/metro/src/DeltaBundler/types.flow.js b/packages/metro/src/DeltaBundler/types.flow.js index 45dbdc8647..e6cba821b3 100644 --- a/packages/metro/src/DeltaBundler/types.flow.js +++ b/packages/metro/src/DeltaBundler/types.flow.js @@ -11,8 +11,8 @@ 'use strict'; -import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies'; import type {RequireContext} from '../lib/contextModule'; +import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies'; import type {Graph} from './Graph'; import type {JsTransformOptions} from 'metro-transform-worker'; diff --git a/packages/metro/src/ModuleGraph/worker/__tests__/collectDependencies-test.js b/packages/metro/src/ModuleGraph/worker/__tests__/collectDependencies-test.js index 33d5841559..28aff2e52e 100644 --- a/packages/metro/src/ModuleGraph/worker/__tests__/collectDependencies-test.js +++ b/packages/metro/src/ModuleGraph/worker/__tests__/collectDependencies-test.js @@ -23,8 +23,8 @@ import type {NodePath} from '@babel/traverse'; const {codeFromAst, comparableCode} = require('../../test-helpers'); const collectDependencies = require('../collectDependencies'); const {codeFrameColumns} = require('@babel/code-frame'); -const babylon = require('@babel/parser'); const {transformFromAstSync} = require('@babel/core'); +const babylon = require('@babel/parser'); const t = require('@babel/types'); const dedent = require('dedent'); const nullthrows = require('nullthrows'); diff --git a/packages/metro/src/ModuleGraph/worker/collectDependencies.js b/packages/metro/src/ModuleGraph/worker/collectDependencies.js index 613f87b84b..2c62faca7f 100644 --- a/packages/metro/src/ModuleGraph/worker/collectDependencies.js +++ b/packages/metro/src/ModuleGraph/worker/collectDependencies.js @@ -17,11 +17,11 @@ import type { AsyncDependencyType, } from 'metro/src/DeltaBundler/types.flow.js'; -const crypto = require('crypto'); const generate = require('@babel/generator').default; const template = require('@babel/template').default; const traverse = require('@babel/traverse').default; const types = require('@babel/types'); +const crypto = require('crypto'); const nullthrows = require('nullthrows'); const {isImport} = types; diff --git a/packages/metro/src/Server.js b/packages/metro/src/Server.js index a001ccb46e..7909d64fe0 100644 --- a/packages/metro/src/Server.js +++ b/packages/metro/src/Server.js @@ -11,7 +11,6 @@ 'use strict'; -import type {StackFrameOutput} from './Server/symbolicate'; import type {AssetData} from './Assets'; import type {ExplodedSourceMap} from './DeltaBundler/Serializers/getExplodedSourceMap'; import type {RamBundleInfo} from './DeltaBundler/Serializers/getRamBundleInfo'; @@ -25,6 +24,7 @@ import type { import type {RevisionId} from './IncrementalBundler'; import type {GraphId} from './lib/getGraphId'; import type {Reporter} from './lib/reporting'; +import type {StackFrameOutput} from './Server/symbolicate'; import type { BundleOptions, GraphOptions, @@ -61,10 +61,9 @@ const parseOptionsFromUrl = require('./lib/parseOptionsFromUrl'); const splitBundleOptions = require('./lib/splitBundleOptions'); const transformHelpers = require('./lib/transformHelpers'); const parsePlatformFilePath = require('./node-haste/lib/parsePlatformFilePath'); +const MultipartResponse = require('./Server/MultipartResponse'); const symbolicate = require('./Server/symbolicate'); const {codeFrameColumns} = require('@babel/code-frame'); -const MultipartResponse = require('./Server/MultipartResponse'); -const {performance} = require('perf_hooks'); const debug = require('debug')('Metro:Server'); const fs = require('graceful-fs'); const invariant = require('invariant'); @@ -73,10 +72,10 @@ const { Logger, Logger: {createActionStartEntry, createActionEndEntry, log}, } = require('metro-core'); - const mime = require('mime-types'); const nullthrows = require('nullthrows'); const path = require('path'); +const {performance} = require('perf_hooks'); const querystring = require('querystring'); const url = require('url'); diff --git a/packages/metro/src/Server/MultipartResponse.js b/packages/metro/src/Server/MultipartResponse.js index 8d48560ea8..0fe85b581e 100644 --- a/packages/metro/src/Server/MultipartResponse.js +++ b/packages/metro/src/Server/MultipartResponse.js @@ -11,6 +11,7 @@ 'use strict'; import type {IncomingMessage, ServerResponse} from 'http'; + const accepts = require('accepts'); const CRLF = '\r\n'; diff --git a/packages/metro/src/Server/__tests__/MultipartResponse-test.js b/packages/metro/src/Server/__tests__/MultipartResponse-test.js index 05db6a8d95..b4b41e8a27 100644 --- a/packages/metro/src/Server/__tests__/MultipartResponse-test.js +++ b/packages/metro/src/Server/__tests__/MultipartResponse-test.js @@ -11,8 +11,8 @@ 'use strict'; -import invariant from 'invariant'; import MultipartResponse from '../MultipartResponse'; +import invariant from 'invariant'; describe('MultipartResponse', () => { it('forwards calls to response', () => { diff --git a/packages/metro/src/Server/__tests__/Server-test.js b/packages/metro/src/Server/__tests__/Server-test.js index bc430bb77a..64678edb55 100644 --- a/packages/metro/src/Server/__tests__/Server-test.js +++ b/packages/metro/src/Server/__tests__/Server-test.js @@ -18,16 +18,16 @@ import type { TransformResultDependency, } from '../../DeltaBundler/types.flow'; -// $FlowFixMe[untyped-import] -import MockResponse from 'mock-res'; +import CountingSet from '../../lib/CountingSet'; +import {mergeConfig} from 'metro-config/src'; // $FlowFixMe[untyped-import] import MockRequest from 'mock-req'; -import {mergeConfig} from 'metro-config/src'; +// $FlowFixMe[untyped-import] +import MockResponse from 'mock-res'; const ResourceNotFoundError = require('../../IncrementalBundler/ResourceNotFoundError'); const {getDefaultValues} = require('metro-config/src/defaults'); const path = require('path'); -import CountingSet from '../../lib/CountingSet'; jest .mock('jest-worker', () => ({})) diff --git a/packages/metro/src/Server/symbolicate.js b/packages/metro/src/Server/symbolicate.js index 330ada7bd1..07a9118871 100644 --- a/packages/metro/src/Server/symbolicate.js +++ b/packages/metro/src/Server/symbolicate.js @@ -11,10 +11,9 @@ 'use strict'; import type { - MetroSourceMapSegmentTuple, FBSourceFunctionMap, + MetroSourceMapSegmentTuple, } from '../../../metro-source-map/src/source-map'; - import type {ExplodedSourceMap} from '../DeltaBundler/Serializers/getExplodedSourceMap'; import type {ConfigT} from 'metro-config/src/configTypes.flow'; diff --git a/packages/metro/src/__tests__/HmrServer-test.js b/packages/metro/src/__tests__/HmrServer-test.js index f3da93f280..d15ef86110 100644 --- a/packages/metro/src/__tests__/HmrServer-test.js +++ b/packages/metro/src/__tests__/HmrServer-test.js @@ -9,18 +9,18 @@ * @oncall react_native */ -import type {HmrClientMessage} from 'metro-runtime/src/modules/types.flow'; +import type {TransformResultDependency} from '../DeltaBundler/types.flow'; import type {Client} from '../HmrServer'; -import {mergeConfig} from 'metro-config'; +import type {HmrClientMessage} from 'metro-runtime/src/modules/types.flow'; import DeltaBundler from '../DeltaBundler'; import IncrementalBundler from '../IncrementalBundler'; import EventEmitter from 'events'; +import {mergeConfig} from 'metro-config'; const HmrServer = require('../HmrServer'); const getGraphId = require('../lib/getGraphId'); const {getDefaultValues} = require('metro-config/src/defaults'); -import type {TransformResultDependency} from '../DeltaBundler/types.flow'; jest.mock('../lib/transformHelpers', () => ({ getResolveDependencyFn: diff --git a/packages/metro/src/commands/build.js b/packages/metro/src/commands/build.js index f66678d6e5..da63296f30 100644 --- a/packages/metro/src/commands/build.js +++ b/packages/metro/src/commands/build.js @@ -9,13 +9,13 @@ * @oncall react_native */ -import parseKeyValueParamArray from '../cli/parseKeyValueParamArray'; - +import type {RunBuildOptions} from '../index'; import type {CustomTransformOptions} from 'metro-babel-transformer'; import type {CustomResolverOptions} from 'metro-resolver'; -import type {RunBuildOptions} from '../index'; -import typeof Yargs from 'yargs'; import type {ModuleObject} from 'yargs'; +import typeof Yargs from 'yargs'; + +import parseKeyValueParamArray from '../cli/parseKeyValueParamArray'; const {makeAsyncCommand} = require('../cli-utils'); const TerminalReporter = require('../lib/TerminalReporter'); diff --git a/packages/metro/src/commands/dependencies.js b/packages/metro/src/commands/dependencies.js index 009fd4ddb9..57faf22cea 100644 --- a/packages/metro/src/commands/dependencies.js +++ b/packages/metro/src/commands/dependencies.js @@ -12,8 +12,8 @@ 'use strict'; import type {ConfigT} from 'metro-config'; -import typeof Yargs from 'yargs'; import type {ModuleObject} from 'yargs'; +import typeof Yargs from 'yargs'; const {makeAsyncCommand} = require('../cli-utils'); const Server = require('../Server'); diff --git a/packages/metro/src/commands/serve.js b/packages/metro/src/commands/serve.js index 84d0f5d7e5..c69a08e1a1 100644 --- a/packages/metro/src/commands/serve.js +++ b/packages/metro/src/commands/serve.js @@ -11,8 +11,8 @@ 'use strict'; -import typeof Yargs from 'yargs'; import type {ModuleObject} from 'yargs'; +import typeof Yargs from 'yargs'; const {makeAsyncCommand, watchFile} = require('../cli-utils'); const {loadConfig, resolveConfig} = require('metro-config'); diff --git a/packages/metro/src/index.flow.js b/packages/metro/src/index.flow.js index 737109525a..cc69e480c2 100644 --- a/packages/metro/src/index.flow.js +++ b/packages/metro/src/index.flow.js @@ -11,11 +11,10 @@ 'use strict'; -import type {HandleFunction} from 'connect'; -import type {CustomResolverOptions} from 'metro-resolver'; import type {ReadOnlyGraph} from './DeltaBundler'; import type {ServerOptions} from './Server'; import type {OutputOptions, RequestOptions} from './shared/types.flow.js'; +import type {HandleFunction} from 'connect'; import type {Server as HttpServer} from 'http'; import type {Server as HttpsServer} from 'https'; import type { @@ -24,6 +23,7 @@ import type { MetroConfig, Middleware, } from 'metro-config/src/configTypes.flow'; +import type {CustomResolverOptions} from 'metro-resolver'; import type {CustomTransformOptions} from 'metro-transform-worker'; import typeof Yargs from 'yargs'; diff --git a/packages/metro/src/integration_tests/__tests__/build-errors-test.js b/packages/metro/src/integration_tests/__tests__/build-errors-test.js index 859e245442..fd6e36c9f8 100644 --- a/packages/metro/src/integration_tests/__tests__/build-errors-test.js +++ b/packages/metro/src/integration_tests/__tests__/build-errors-test.js @@ -12,12 +12,10 @@ 'use strict'; const Metro = require('../../..'); +const path = require('path'); jest.unmock('cosmiconfig'); - jest.setTimeout(30 * 1000); - -const path = require('path'); const BUILD_ERRORS_SRC_DIR = path.resolve(__dirname, '..', 'basic_bundle', 'build-errors') + path.sep; diff --git a/packages/metro/src/integration_tests/basic_bundle/require-context/conflict.js b/packages/metro/src/integration_tests/basic_bundle/require-context/conflict.js index 1e9ce0ab52..ea2f5ab5a4 100644 --- a/packages/metro/src/integration_tests/basic_bundle/require-context/conflict.js +++ b/packages/metro/src/integration_tests/basic_bundle/require-context/conflict.js @@ -12,9 +12,9 @@ import type {RequireWithContext} from './utils'; import {copyContextToObject} from './utils'; -declare var require: RequireWithContext; - const normalModule = require('./subdir-conflict'); + +declare var require: RequireWithContext; const contextModule = require.context<$FlowFixMe>('./subdir-conflict'); function main() { diff --git a/packages/metro/src/integration_tests/basic_bundle/require-context/mode-eager.js b/packages/metro/src/integration_tests/basic_bundle/require-context/mode-eager.js index d0b9f931e6..ca8f6f7850 100644 --- a/packages/metro/src/integration_tests/basic_bundle/require-context/mode-eager.js +++ b/packages/metro/src/integration_tests/basic_bundle/require-context/mode-eager.js @@ -8,9 +8,10 @@ * @flow strict-local */ -import {copyContextToObject, awaitProperties} from './utils'; import type {RequireWithContext} from './utils'; +import {awaitProperties, copyContextToObject} from './utils'; + declare var require: RequireWithContext; function main() { diff --git a/packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js b/packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js index 06efa84e34..a1430b80fb 100644 --- a/packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js +++ b/packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js @@ -8,9 +8,10 @@ * @flow strict-local */ -import {copyContextToObject, awaitProperties} from './utils'; import type {RequireWithContext} from './utils'; +import {awaitProperties, copyContextToObject} from './utils'; + declare var require: RequireWithContext; function main() { diff --git a/packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy.js b/packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy.js index 895f61595d..6ed188fd0d 100644 --- a/packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy.js +++ b/packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy.js @@ -8,9 +8,10 @@ * @flow strict-local */ -import {copyContextToObject, awaitProperties} from './utils'; import type {RequireWithContext} from './utils'; +import {awaitProperties, copyContextToObject} from './utils'; + declare var require: RequireWithContext; function main() { diff --git a/packages/metro/src/integration_tests/basic_bundle/require-context/mode-sync.js b/packages/metro/src/integration_tests/basic_bundle/require-context/mode-sync.js index 223cb5dfc8..06c09366f2 100644 --- a/packages/metro/src/integration_tests/basic_bundle/require-context/mode-sync.js +++ b/packages/metro/src/integration_tests/basic_bundle/require-context/mode-sync.js @@ -8,9 +8,10 @@ * @flow strict-local */ -import {copyContextToObject} from './utils'; import type {RequireWithContext} from './utils'; +import {copyContextToObject} from './utils'; + declare var require: RequireWithContext; function main(): mixed { diff --git a/packages/metro/src/lib/__tests__/contextModule-test.js b/packages/metro/src/lib/__tests__/contextModule-test.js index 558f1f1e04..f2274dd89e 100644 --- a/packages/metro/src/lib/__tests__/contextModule-test.js +++ b/packages/metro/src/lib/__tests__/contextModule-test.js @@ -10,8 +10,8 @@ */ import { - fileMatchesContext, deriveAbsolutePathFromContext, + fileMatchesContext, } from '../contextModule'; describe('deriveAbsolutePathFromContext', () => { diff --git a/packages/metro/src/lib/contextModule.js b/packages/metro/src/lib/contextModule.js index 96b5d827a6..b7421f17d2 100644 --- a/packages/metro/src/lib/contextModule.js +++ b/packages/metro/src/lib/contextModule.js @@ -9,13 +9,14 @@ * @oncall react_native */ -import crypto from 'crypto'; -import path from 'path'; import type { ContextMode, RequireContextParams, } from '../ModuleGraph/worker/collectDependencies'; + +import crypto from 'crypto'; import nullthrows from 'nullthrows'; +import path from 'path'; export type RequireContext = $ReadOnly<{ /* Should search for files recursively. Optional, default `true` when `require.context` is used */ diff --git a/packages/metro/src/lib/contextModuleTemplates.js b/packages/metro/src/lib/contextModuleTemplates.js index 1380d8c7a9..e701a8de14 100644 --- a/packages/metro/src/lib/contextModuleTemplates.js +++ b/packages/metro/src/lib/contextModuleTemplates.js @@ -9,10 +9,11 @@ * @oncall react_native */ -import * as path from 'path'; -import * as os from 'os'; import type {ContextMode} from '../ModuleGraph/worker/collectDependencies'; +import * as os from 'os'; +import * as path from 'path'; + function createFileMap( modulePath: string, files: string[], diff --git a/packages/metro/src/lib/reporting.js b/packages/metro/src/lib/reporting.js index 5ee1e0f0d1..f2432992d9 100644 --- a/packages/metro/src/lib/reporting.js +++ b/packages/metro/src/lib/reporting.js @@ -11,10 +11,10 @@ 'use strict'; +import type {Terminal} from 'metro-core'; +import type {HealthCheckResult, WatcherStatus} from 'metro-file-map'; import type {CustomResolverOptions} from 'metro-resolver'; import type {CustomTransformOptions} from 'metro-transform-worker'; -import type {HealthCheckResult, WatcherStatus} from 'metro-file-map'; -import type {Terminal} from 'metro-core'; const chalk = require('chalk'); const stripAnsi = require('strip-ansi'); diff --git a/packages/metro/src/lib/transformHelpers.js b/packages/metro/src/lib/transformHelpers.js index 5771976df0..af5cd16366 100644 --- a/packages/metro/src/lib/transformHelpers.js +++ b/packages/metro/src/lib/transformHelpers.js @@ -19,15 +19,14 @@ import type { TransformResultDependency, } from '../DeltaBundler/types.flow'; import type {TransformOptions} from '../DeltaBundler/Worker'; +import type {ResolverInputOptions} from '../shared/types.flow'; +import type {RequireContext} from './contextModule'; import type {ConfigT} from 'metro-config/src/configTypes.flow'; import type {Type} from 'metro-transform-worker'; -import type {RequireContext} from './contextModule'; import {getContextModuleTemplate} from './contextModuleTemplates'; import isAssetFile from 'metro-resolver/src/utils/isAssetFile'; -import type {ResolverInputOptions} from '../shared/types.flow'; - type InlineRequiresRaw = {+blockList: {[string]: true, ...}, ...} | boolean; type TransformOptionsWithRawInlines = { diff --git a/packages/metro/src/node-haste/DependencyGraph.js b/packages/metro/src/node-haste/DependencyGraph.js index 07f2db6655..9c82de1aaf 100644 --- a/packages/metro/src/node-haste/DependencyGraph.js +++ b/packages/metro/src/node-haste/DependencyGraph.js @@ -9,6 +9,11 @@ * @oncall react_native */ +import type { + BundlerResolution, + TransformResultDependency, +} from '../DeltaBundler/types.flow'; +import type {ResolverInputOptions} from '../shared/types.flow'; import type Package from './Package'; import type {ConfigT} from 'metro-config/src/configTypes.flow'; import type MetroFileMap, { @@ -21,7 +26,6 @@ import type MetroFileMap, { import {DuplicateHasteCandidatesError} from 'metro-file-map'; -const canonicalize = require('metro-core/src/canonicalize'); const createFileMap = require('./DependencyGraph/createFileMap'); const {ModuleResolver} = require('./DependencyGraph/ModuleResolution'); const ModuleCache = require('./ModuleCache'); @@ -32,14 +36,10 @@ const { Logger: {createActionStartEntry, createActionEndEntry, log}, PackageResolutionError, } = require('metro-core'); +const canonicalize = require('metro-core/src/canonicalize'); const {InvalidPackageError} = require('metro-resolver'); const nullthrows = require('nullthrows'); const path = require('path'); -import type {ResolverInputOptions} from '../shared/types.flow'; -import type { - BundlerResolution, - TransformResultDependency, -} from '../DeltaBundler/types.flow'; const NULL_PLATFORM = Symbol(); diff --git a/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js b/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js index 92a62db9e3..f0e80fccaa 100644 --- a/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js +++ b/packages/metro/src/node-haste/DependencyGraph/ModuleResolution.js @@ -11,6 +11,12 @@ 'use strict'; +import type { + BundlerResolution, + TransformResultDependency, +} from '../../DeltaBundler/types.flow'; +import type {Reporter} from '../../lib/reporting'; +import type {ResolverInputOptions} from '../../shared/types.flow'; import type { CustomResolver, DoesFileExist, @@ -19,7 +25,6 @@ import type { Resolution, ResolveAsset, } from 'metro-resolver'; -import type {ResolverInputOptions} from '../../shared/types.flow'; import type {PackageInfo, PackageJson} from 'metro-resolver/src/types'; const {codeFrameColumns} = require('@babel/code-frame'); @@ -29,11 +34,6 @@ const Resolver = require('metro-resolver'); const createDefaultContext = require('metro-resolver/src/createDefaultContext'); const path = require('path'); const util = require('util'); -import type { - BundlerResolution, - TransformResultDependency, -} from '../../DeltaBundler/types.flow'; -import type {Reporter} from '../../lib/reporting'; export type DirExistsFn = (filePath: string) => boolean; diff --git a/packages/metro/src/shared/types.flow.js b/packages/metro/src/shared/types.flow.js index 2d4fd618b8..f5e60128d3 100644 --- a/packages/metro/src/shared/types.flow.js +++ b/packages/metro/src/shared/types.flow.js @@ -16,6 +16,7 @@ import type { TransformInputOptions, } from '../DeltaBundler/types.flow'; import type {TransformProfile} from 'metro-babel-transformer'; +import type {CustomResolverOptions} from 'metro-resolver'; import type { MetroSourceMapSegmentTuple, MixedSourceMap, @@ -24,7 +25,6 @@ import type { CustomTransformOptions, MinifierOptions, } from 'metro-transform-worker'; -import type {CustomResolverOptions} from 'metro-resolver'; type BundleType = | 'bundle' diff --git a/scripts/__tests__/babel-lib-defs-test.js b/scripts/__tests__/babel-lib-defs-test.js index 25b22a108d..2beb6d9c00 100644 --- a/scripts/__tests__/babel-lib-defs-test.js +++ b/scripts/__tests__/babel-lib-defs-test.js @@ -10,8 +10,8 @@ 'use strict'; -import {promises as fsPromises} from 'fs'; import generateBabelFlowLibraryDefinitions from '../support/generateBabelFlowLibraryDefinitions'; +import {promises as fsPromises} from 'fs'; test('Babel Flow library definitions should be up to date', async () => { // Run `yarn update-babel-flow-lib-defs` in the Metro monorepo if this test fails. diff --git a/scripts/__tests__/subpackages-test.js b/scripts/__tests__/subpackages-test.js index aded59f290..9ea89280c4 100644 --- a/scripts/__tests__/subpackages-test.js +++ b/scripts/__tests__/subpackages-test.js @@ -11,8 +11,8 @@ 'use strict'; const getPackages = require('../_getPackages'); -const METRO_VERSION = require('../../packages/metro/package.json').version; const ENGINES = require('../../package.json').engines; +const METRO_VERSION = require('../../packages/metro/package.json').version; const fs = require('fs'); const path = require('path'); diff --git a/scripts/support/generateBabelFlowLibraryDefinitions.js b/scripts/support/generateBabelFlowLibraryDefinitions.js index 7143f012fc..cd340c53e4 100644 --- a/scripts/support/generateBabelFlowLibraryDefinitions.js +++ b/scripts/support/generateBabelFlowLibraryDefinitions.js @@ -13,9 +13,9 @@ * This script updates all flow types. Run it every time you upgrade babel */ -import * as prettier from 'prettier'; -import updateBabelTraverseFlowLibraryDefinition from './updateBabelTraverseFlowLibraryDefinition'; import generateBabelTypesFlowLibraryDefinition from './generateBabelTypesFlowLibraryDefinition'; +import updateBabelTraverseFlowLibraryDefinition from './updateBabelTraverseFlowLibraryDefinition'; +import * as prettier from 'prettier'; export default async function main(): Promise< Map, diff --git a/scripts/updateBabelFlowLibraryDefinitions.js b/scripts/updateBabelFlowLibraryDefinitions.js index f0b9c06f18..3155ea652b 100644 --- a/scripts/updateBabelFlowLibraryDefinitions.js +++ b/scripts/updateBabelFlowLibraryDefinitions.js @@ -13,8 +13,8 @@ * This script updates all flow types. Run it every time you upgrade babel */ -import {promises as fsPromises} from 'fs'; import generateBabelFlowLibraryDefinitions from './support/generateBabelFlowLibraryDefinitions'; +import {promises as fsPromises} from 'fs'; async function main() { const newContentByFile = await generateBabelFlowLibraryDefinitions();