├── .editorconfig ├── .eslintignore ├── .eslintrc.js ├── .flowconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md ├── actions │ └── yarn-install │ │ └── action.yml ├── dependabot.yml ├── scripts │ ├── install_codecov.sh │ └── publish.sh └── workflows │ ├── build-test-and-deploy.yml │ ├── deploy-website.yml │ ├── nightly-tests.yml │ └── test.yml ├── .gitignore ├── .prettierrc ├── .watchmanconfig ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── babel.config.js ├── codecov.yml ├── docs ├── API.md ├── Bundling.md ├── CLI.md ├── Caching.md ├── Concepts.md ├── Configuration.md ├── GettingStarted.md ├── LocalDevelopment.md ├── ModuleAPI.md ├── PackageExports.md ├── Resolution.md ├── SourceMapFormat.md └── Troubleshooting.md ├── flow-typed ├── accepts.js ├── console.js.flow ├── environment │ ├── bom.js │ ├── cssom.js │ ├── dom.js │ ├── node.js │ ├── serviceworkers.js │ └── streams.js ├── eventemitter3.js.flow ├── fb-watchman.js ├── graceful-fs.js ├── jest-snapshot-serializer-raw.js ├── jest-worker.js ├── jest.js ├── node.js ├── npm │ ├── babel-plugin-tester_v6.x.x.js │ ├── babel-traverse_v7.x.x.js │ ├── babel-types_v7.x.x.js │ ├── babel_v7.x.x.js │ ├── chalk_v4.x.x.js │ ├── ci-info_v2.x.x.js │ ├── connect_v3.x.x.js │ ├── debug_v4.4.x.js │ ├── exponential-backoff_v3.x.x.js │ ├── https-proxy-agent_v7.x.x.js │ ├── react-test-renderer_v16.x.x.js │ ├── strip-ansi_v3.x.x.js │ ├── ws_v7.x.x.js │ └── yargs_v17.x.x.js ├── perf_hooks.js ├── prettier.js └── uglify.js ├── jest.config.js ├── metro.code-workspace ├── package.json ├── packages ├── .gitignore ├── buck-worker-tool │ ├── .npmignore │ ├── package.json │ └── src │ │ ├── CommandFailedError.js │ │ ├── __tests__ │ │ └── worker-test.js │ │ ├── profiling.js │ │ ├── third-party │ │ ├── JSONStream.js │ │ └── LICENSE.MIT │ │ └── worker-tool.js ├── metro-babel-register │ ├── .npmignore │ ├── package.json │ └── src │ │ ├── __tests__ │ │ └── parses-without-transpilation-test.js │ │ ├── babel-register.js │ │ └── plugins │ │ └── babel-plugin-metro-replace-ts-require-assignment.js ├── metro-babel-transformer │ ├── .npmignore │ ├── package.json │ ├── src │ │ ├── __tests__ │ │ │ └── transform-test.js │ │ └── index.js │ └── types │ │ └── index.d.ts ├── metro-cache-key │ ├── .npmignore │ ├── package.json │ └── src │ │ ├── __tests__ │ │ └── index-test.js │ │ └── index.js ├── metro-cache │ ├── .npmignore │ ├── package.json │ ├── src │ │ ├── Cache.js │ │ ├── __tests__ │ │ │ ├── Cache-test.js │ │ │ └── stableHash-test.js │ │ ├── index.js │ │ ├── stableHash.js │ │ ├── stores │ │ │ ├── AutoCleanFileStore.js │ │ │ ├── FileStore.js │ │ │ ├── HttpError.js │ │ │ ├── HttpGetStore.js │ │ │ ├── HttpStore.js │ │ │ ├── NetworkError.js │ │ │ └── __tests__ │ │ │ │ ├── AutoCleanFileStore-test.js │ │ │ │ ├── FileStore-test.js │ │ │ │ ├── HttpGetStore-test.js │ │ │ │ └── HttpStore-test.js │ │ └── types.flow.js │ └── types │ │ ├── Cache.d.ts │ │ ├── index.d.ts │ │ ├── stableHash.d.ts │ │ ├── stores │ │ ├── AutoCleanFileStore.d.ts │ │ ├── FileStore.d.ts │ │ ├── HttpGetStore.d.ts │ │ └── HttpStore.d.ts │ │ └── types.d.ts ├── metro-config │ ├── .npmignore │ ├── README.md │ ├── package.json │ ├── src │ │ ├── __mocks__ │ │ │ └── cosmiconfig.js │ │ ├── __tests__ │ │ │ ├── __snapshots__ │ │ │ │ └── loadConfig-test.js.snap │ │ │ └── loadConfig-test.js │ │ ├── configTypes.flow.js │ │ ├── defaults │ │ │ ├── __tests__ │ │ │ │ └── exclusionList-test.js │ │ │ ├── defaults.js │ │ │ ├── exclusionList.js │ │ │ ├── index.js │ │ │ └── validConfig.js │ │ ├── index.js │ │ └── loadConfig.js │ └── types │ │ ├── configTypes.d.ts │ │ ├── defaults │ │ └── index.d.ts │ │ ├── index.d.ts │ │ └── loadConfig.d.ts ├── metro-core │ ├── .npmignore │ ├── README.md │ ├── package.json │ ├── src │ │ ├── Logger.js │ │ ├── Terminal.js │ │ ├── __tests__ │ │ │ ├── Logger-test.js │ │ │ ├── Terminal-test.js │ │ │ └── canonicalize-test.js │ │ ├── canonicalize.js │ │ ├── errors.js │ │ ├── errors │ │ │ ├── AmbiguousModuleResolutionError.js │ │ │ └── PackageResolutionError.js │ │ └── index.js │ └── types │ │ ├── Terminal.d.ts │ │ └── index.d.ts ├── metro-file-map │ ├── .npmignore │ ├── README.md │ ├── package.json │ ├── src │ │ ├── Watcher.js │ │ ├── __tests__ │ │ │ ├── __snapshots__ │ │ │ │ └── index-test.js.snap │ │ │ ├── dependencyExtractor.js │ │ │ ├── haste_impl.js │ │ │ ├── includes_dotfiles-test.js │ │ │ ├── index-test.js │ │ │ ├── test_dotfiles_root │ │ │ │ ├── .eslintrc.js │ │ │ │ └── index.js │ │ │ └── worker-test.js │ │ ├── cache │ │ │ ├── DiskCacheManager.js │ │ │ └── __tests__ │ │ │ │ └── DiskCacheManager-test.js │ │ ├── constants.js │ │ ├── crawlers │ │ │ ├── __fixtures__ │ │ │ │ ├── directory │ │ │ │ │ ├── bar.js │ │ │ │ │ └── other.file │ │ │ │ ├── foo.js │ │ │ │ ├── ignored │ │ │ │ │ └── hidden.js │ │ │ │ ├── link-to-directory │ │ │ │ └── link-to-foo.js │ │ │ ├── __tests__ │ │ │ │ ├── integration-test.js │ │ │ │ ├── node-test.js │ │ │ │ └── watchman-test.js │ │ │ ├── node │ │ │ │ ├── hasNativeFindSupport.js │ │ │ │ └── index.js │ │ │ └── watchman │ │ │ │ ├── __tests__ │ │ │ │ ├── index-test.js │ │ │ │ └── planQuery-test.js │ │ │ │ ├── index.js │ │ │ │ └── planQuery.js │ │ ├── flow-types.js │ │ ├── index.js │ │ ├── lib │ │ │ ├── FileProcessor.js │ │ │ ├── RootPathUtils.js │ │ │ ├── TreeFS.js │ │ │ ├── __tests__ │ │ │ │ ├── FileProcessor-test.js │ │ │ │ ├── RootPathUtils-test.js │ │ │ │ ├── TreeFS-test.js │ │ │ │ ├── checkWatchmanCapabilities-test.js │ │ │ │ ├── dependencyExtractor-test.js │ │ │ │ ├── normalizePathSeparatorsToSystem-test.js │ │ │ │ └── rootRelativeCacheKeys-test.js │ │ │ ├── checkWatchmanCapabilities.js │ │ │ ├── dependencyExtractor.js │ │ │ ├── fast_path.js │ │ │ ├── normalizePathSeparatorsToPosix.js │ │ │ ├── normalizePathSeparatorsToSystem.js │ │ │ ├── rootRelativeCacheKeys.js │ │ │ └── sorting.js │ │ ├── plugins │ │ │ ├── HastePlugin.js │ │ │ ├── MockPlugin.js │ │ │ ├── haste │ │ │ │ ├── DuplicateHasteCandidatesError.js │ │ │ │ ├── HasteConflictsError.js │ │ │ │ ├── __tests__ │ │ │ │ │ ├── HastePlugin-test.js │ │ │ │ │ └── getPlatformExtension-test.js │ │ │ │ ├── computeConflicts.js │ │ │ │ └── getPlatformExtension.js │ │ │ └── mocks │ │ │ │ ├── __tests__ │ │ │ │ ├── MockPlugin-test.js │ │ │ │ └── getMockName-test.js │ │ │ │ └── getMockName.js │ │ ├── watchers │ │ │ ├── AbstractWatcher.js │ │ │ ├── FallbackWatcher.js │ │ │ ├── NativeWatcher.js │ │ │ ├── RecrawlWarning.js │ │ │ ├── WatchmanWatcher.js │ │ │ ├── __tests__ │ │ │ │ ├── WatchmanWatcher-test.js │ │ │ │ ├── helpers.js │ │ │ │ └── integration-test.js │ │ │ └── common.js │ │ ├── worker.js │ │ └── workerExclusionList.js │ └── types │ │ ├── Watcher.d.ts │ │ ├── cache │ │ └── DiskCacheManager.d.ts │ │ ├── flow-types.d.ts │ │ ├── index.d.ts │ │ └── lib │ │ └── DuplicateHasteCandidatesError.d.ts ├── metro-memory-fs │ ├── .npmignore │ ├── package.json │ └── src │ │ ├── __tests__ │ │ ├── __snapshots__ │ │ │ └── index-test.js.snap │ │ └── index-test.js │ │ └── index.js ├── metro-minify-terser │ ├── .npmignore │ ├── package.json │ └── src │ │ ├── __tests__ │ │ ├── minify-test.js │ │ └── terser-issue-1341-test.js │ │ ├── index.js │ │ └── minifier.js ├── metro-resolver │ ├── .npmignore │ ├── README.md │ ├── package.json │ ├── src │ │ ├── PackageExportsResolve.js │ │ ├── PackageImportsResolve.js │ │ ├── PackageResolve.js │ │ ├── __tests__ │ │ │ ├── __snapshots__ │ │ │ │ └── index-test.js.snap │ │ │ ├── assets-test.js │ │ │ ├── browser-spec-test.js │ │ │ ├── index-test.js │ │ │ ├── package-exports-test.js │ │ │ ├── package-imports-test.js │ │ │ ├── platform-extensions-test.js │ │ │ ├── symlinks-test.js │ │ │ └── utils.js │ │ ├── createDefaultContext.js │ │ ├── errors │ │ │ ├── FailedToResolveNameError.js │ │ │ ├── FailedToResolvePathError.js │ │ │ ├── FailedToResolveUnsupportedError.js │ │ │ ├── InvalidPackageConfigurationError.js │ │ │ ├── InvalidPackageError.js │ │ │ ├── PackageImportNotResolvedError.js │ │ │ ├── PackagePathNotExportedError.js │ │ │ └── formatFileCandidates.js │ │ ├── index.js │ │ ├── resolve.js │ │ ├── resolveAsset.js │ │ ├── types.js │ │ └── utils │ │ │ ├── isAssetFile.js │ │ │ ├── isSubpathDefinedInExportsLike.js │ │ │ ├── matchSubpathFromExportsLike.js │ │ │ ├── matchSubpathPattern.js │ │ │ ├── reduceExportsLikeMap.js │ │ │ └── toPosixPath.js │ └── types │ │ ├── index.d.ts │ │ └── types.d.ts ├── metro-runtime │ ├── .npmignore │ ├── package.json │ └── src │ │ ├── modules │ │ ├── HMRClient.js │ │ ├── __tests__ │ │ │ ├── HMRClient-test.js │ │ │ └── __snapshots__ │ │ │ │ └── HMRClient-test.js.snap │ │ ├── asyncRequire.js │ │ ├── empty-module.js │ │ ├── null-module.js │ │ ├── types.flow.js │ │ └── vendor │ │ │ ├── eventemitter3.js │ │ │ └── eventemitter3.js.flow │ │ └── polyfills │ │ ├── .babelrc.js │ │ ├── __tests__ │ │ ├── MetroFastRefreshMockRuntime.js │ │ ├── fast-refresh-integration-test.js │ │ └── require-test.js │ │ └── require.js ├── metro-source-map │ ├── .npmignore │ ├── README.md │ ├── package.json │ ├── src │ │ ├── B64Builder.js │ │ ├── BundleBuilder.js │ │ ├── Consumer │ │ │ ├── AbstractConsumer.js │ │ │ ├── DelegatingConsumer.js │ │ │ ├── MappingsConsumer.js │ │ │ ├── SectionsConsumer.js │ │ │ ├── constants.js │ │ │ ├── createConsumer.js │ │ │ ├── index.js │ │ │ ├── normalizeSourcePath.js │ │ │ ├── positionMath.js │ │ │ ├── search.js │ │ │ └── types.flow.js │ │ ├── Generator.js │ │ ├── __tests__ │ │ │ ├── B64Builder-test.js │ │ │ ├── BundleBuilder-test.js │ │ │ ├── Consumer-test.js │ │ │ ├── Generator-test.js │ │ │ ├── __fixtures__ │ │ │ │ ├── 1.json │ │ │ │ ├── 2.json │ │ │ │ ├── ignore_1.json │ │ │ │ ├── ignore_2.json │ │ │ │ ├── merged_1_2.json │ │ │ │ └── merged_ignore.json │ │ │ ├── __snapshots__ │ │ │ │ └── source-map-test.js.snap │ │ │ ├── composeSourceMaps-test.js │ │ │ ├── generateFunctionMap-test.js │ │ │ └── source-map-test.js │ │ ├── composeSourceMaps.js │ │ ├── encode.js │ │ ├── generateFunctionMap.js │ │ └── source-map.js │ └── types │ │ └── source-map.d.ts ├── metro-symbolicate │ ├── .npmignore │ ├── package.json │ └── src │ │ ├── ChromeHeapSnapshot.js │ │ ├── GoogleIgnoreListConsumer.js │ │ ├── SourceMetadataMapConsumer.js │ │ ├── Symbolication.js │ │ ├── __tests__ │ │ ├── ChromeHeapSnapshotProcessor-test.js │ │ ├── GoogleIgnoreListConsumer-test.js │ │ ├── SourceMetadataMapConsumer-test.js │ │ ├── Symbolication-test.js │ │ ├── __fixtures__ │ │ │ ├── GenSampleHeapSnapshotBundle.js.heaptimeline │ │ │ ├── GenSampleHeapSnapshotBundle.js.map │ │ │ ├── coverageStackTrace.json │ │ │ ├── coverageStackTraceCJS.json │ │ │ ├── directory │ │ │ │ ├── foo.js.map │ │ │ │ ├── subdir1 │ │ │ │ │ └── bar.js.map │ │ │ │ └── test.stack │ │ │ ├── hermes.js.hbc.map │ │ │ ├── hermesStackTrace.json │ │ │ ├── hermesStackTraceCJS-SegmentID.json │ │ │ ├── hermesStackTraceCJS.json │ │ │ ├── hermescjs.js.hbc.map │ │ │ ├── testfile.attribution.input │ │ │ ├── testfile.cpuprofile │ │ │ ├── testfile.cpuprofile.map │ │ │ ├── testfile.js.map │ │ │ ├── testfile.node.stack │ │ │ ├── testfile.partial.js.map │ │ │ ├── testfile.profmap │ │ │ ├── testfile.ram.js.map │ │ │ ├── testfile.ram.stack │ │ │ ├── testfile.sectioned.js.map │ │ │ ├── testfile.stack │ │ │ ├── with-function-map.js.map │ │ │ ├── with-function-map.stack │ │ │ ├── with-ignore-list.js.map │ │ │ └── with-ignore-list.stack │ │ ├── __snapshots__ │ │ │ ├── symbolicate-heap-snapshot-test.js.snap │ │ │ └── symbolicate-test.js.snap │ │ ├── symbolicate-heap-snapshot-test.js │ │ └── symbolicate-test.js │ │ ├── index.js │ │ └── symbolicate.js ├── metro-transform-plugins │ ├── .npmignore │ ├── package.json │ └── src │ │ ├── __mocks__ │ │ └── test-helpers.js │ │ ├── __tests__ │ │ ├── __snapshots__ │ │ │ └── inline-requires-plugin-test.js.snap │ │ ├── addParamsToDefineCall-test.js │ │ ├── constant-folding-plugin-test.js │ │ ├── import-export-plugin-test.js │ │ ├── inline-plugin-test.js │ │ ├── inline-requires-plugin-test.js │ │ ├── normalizePseudoGlobals-test.js │ │ └── validateOutputAst.js │ │ ├── addParamsToDefineCall.js │ │ ├── constant-folding-plugin.js │ │ ├── import-export-plugin.js │ │ ├── index.js │ │ ├── inline-plugin.js │ │ ├── inline-requires-plugin.js │ │ ├── normalizePseudoGlobals.js │ │ └── utils │ │ └── createInlinePlatformChecks.js ├── metro-transform-worker │ ├── .npmignore │ ├── package.json │ ├── src │ │ ├── __mocks__ │ │ │ └── index.js │ │ ├── __tests__ │ │ │ ├── __snapshots__ │ │ │ │ └── index-test.js.snap │ │ │ └── index-test.js │ │ ├── index.js │ │ └── utils │ │ │ ├── assetTransformer.js │ │ │ └── getMinifier.js │ └── types │ │ └── index.d.ts ├── metro │ ├── .npmignore │ ├── README.md │ ├── package.json │ ├── src │ │ ├── Assets.js │ │ ├── Bundler.js │ │ ├── Bundler │ │ │ ├── __tests__ │ │ │ │ ├── __snapshots__ │ │ │ │ │ └── util-test.js.snap │ │ │ │ └── util-test.js │ │ │ └── util.js │ │ ├── DeltaBundler.js │ │ ├── DeltaBundler │ │ │ ├── DeltaCalculator.js │ │ │ ├── Graph.js │ │ │ ├── Serializers │ │ │ │ ├── __tests__ │ │ │ │ │ ├── __snapshots__ │ │ │ │ │ │ └── getRamBundleInfo-test.js.snap │ │ │ │ │ ├── baseJSBundle-test.js │ │ │ │ │ ├── getAllFiles-test.js │ │ │ │ │ ├── getAssets-test.js │ │ │ │ │ ├── getRamBundleInfo-test.js │ │ │ │ │ └── sourceMapString-test.js │ │ │ │ ├── baseJSBundle.js │ │ │ │ ├── getAllFiles.js │ │ │ │ ├── getAssets.js │ │ │ │ ├── getExplodedSourceMap.js │ │ │ │ ├── getRamBundleInfo.js │ │ │ │ ├── helpers │ │ │ │ │ ├── __tests__ │ │ │ │ │ │ ├── getTransitiveDependencies-test.js │ │ │ │ │ │ └── js-test.js │ │ │ │ │ ├── getInlineSourceMappingURL.js │ │ │ │ │ ├── getSourceMapInfo.js │ │ │ │ │ ├── getTransitiveDependencies.js │ │ │ │ │ ├── js.js │ │ │ │ │ └── processModules.js │ │ │ │ ├── hmrJSBundle.js │ │ │ │ ├── sourceMapGenerator.js │ │ │ │ ├── sourceMapObject.js │ │ │ │ └── sourceMapString.js │ │ │ ├── Transformer.js │ │ │ ├── Worker.flow.js │ │ │ ├── Worker.js │ │ │ ├── WorkerFarm.js │ │ │ ├── __fixtures__ │ │ │ │ └── hasteImpl.js │ │ │ ├── __tests__ │ │ │ │ ├── DeltaBundler-test.js │ │ │ │ ├── DeltaCalculator-context-test.js │ │ │ │ ├── DeltaCalculator-test.js │ │ │ │ ├── Graph-test.js │ │ │ │ ├── Transformer-test.js │ │ │ │ ├── WorkerFarm-test.js │ │ │ │ ├── __snapshots__ │ │ │ │ │ ├── Graph-test.js.snap │ │ │ │ │ └── resolver-test.js.snap │ │ │ │ ├── buildSubgraph-test.js │ │ │ │ ├── mergeDeltas-test.js │ │ │ │ └── resolver-test.js │ │ │ ├── buildSubgraph.js │ │ │ ├── getTransformCacheKey.js │ │ │ ├── mergeDeltas.js │ │ │ └── types.flow.js │ │ ├── HmrServer.js │ │ ├── IncrementalBundler.js │ │ ├── IncrementalBundler │ │ │ ├── GraphNotFoundError.js │ │ │ ├── ResourceNotFoundError.js │ │ │ └── RevisionNotFoundError.js │ │ ├── ModuleGraph │ │ │ ├── test-helpers.js │ │ │ └── worker │ │ │ │ ├── JsFileWrapping.js │ │ │ │ ├── __tests__ │ │ │ │ ├── JsFileWrapping-test.js │ │ │ │ ├── __snapshots__ │ │ │ │ │ └── collectDependencies-test.js.snap │ │ │ │ ├── collectDependencies-test.js │ │ │ │ └── importLocationsPlugin-test.js │ │ │ │ ├── collectDependencies.js │ │ │ │ ├── generateImportNames.js │ │ │ │ └── importLocationsPlugin.js │ │ ├── Server.js │ │ ├── Server │ │ │ ├── MultipartResponse.js │ │ │ ├── __tests__ │ │ │ │ ├── MultipartResponse-test.js │ │ │ │ └── Server-test.js │ │ │ └── symbolicate.js │ │ ├── __mocks__ │ │ │ └── debug.js │ │ ├── __tests__ │ │ │ ├── Assets-test.js │ │ │ └── HmrServer-test.js │ │ ├── cli-utils.js │ │ ├── cli.js │ │ ├── cli │ │ │ ├── __tests__ │ │ │ │ └── parseKeyValueParamArray-test.js │ │ │ └── parseKeyValueParamArray.js │ │ ├── commands │ │ │ ├── build.js │ │ │ ├── dependencies.js │ │ │ └── serve.js │ │ ├── index.flow.js │ │ ├── index.js │ │ ├── integration_tests │ │ │ ├── __tests__ │ │ │ │ ├── __snapshots__ │ │ │ │ │ ├── build-errors-test.js.snap │ │ │ │ │ ├── build-test.js.snap │ │ │ │ │ ├── buildGraph-test.js.snap │ │ │ │ │ ├── import-export-test.js.snap │ │ │ │ │ ├── rambundle-test.js.snap │ │ │ │ │ ├── require-context-test.js.snap │ │ │ │ │ └── server-test.js.snap │ │ │ │ ├── build-errors-test.js │ │ │ │ ├── build-test.js │ │ │ │ ├── buildGraph-test.js │ │ │ │ ├── import-export-test.js │ │ │ │ ├── rambundle-test.js │ │ │ │ ├── require-context-test.js │ │ │ │ ├── require-resolveWeak-test.js │ │ │ │ ├── server-test.js │ │ │ │ ├── server-torn-down-test.js │ │ │ │ └── sourcemap-test.js │ │ │ ├── basic_bundle │ │ │ │ ├── AssetRegistry.js │ │ │ │ ├── Bar.js │ │ │ │ ├── ErrorBundle.js │ │ │ │ ├── Foo.js │ │ │ │ ├── TestBigInt.js │ │ │ │ ├── TestBundle.js │ │ │ │ ├── TestPolyfill.js │ │ │ │ ├── TypeScript.ts │ │ │ │ ├── build-errors │ │ │ │ │ ├── cannot-resolve-import.js │ │ │ │ │ ├── cannot-resolve-multi-line-import-with-escapes.js │ │ │ │ │ ├── cannot-resolve-multi-line-import.js │ │ │ │ │ ├── cannot-resolve-require-with-embedded-comment.js │ │ │ │ │ ├── cannot-resolve-require.js │ │ │ │ │ ├── cannot-resolve-specifier-with-escapes.js │ │ │ │ │ ├── inline-requires-cannot-resolve-import.js │ │ │ │ │ └── inline-requires-cannot-resolve-require.js │ │ │ │ ├── excluded_from_file_map.js │ │ │ │ ├── import-export │ │ │ │ │ ├── export-1.js │ │ │ │ │ ├── export-2.js │ │ │ │ │ ├── export-3.js │ │ │ │ │ ├── export-4.js │ │ │ │ │ ├── export-5.js │ │ │ │ │ ├── export-6.js │ │ │ │ │ ├── export-7.js │ │ │ │ │ ├── export-8.js │ │ │ │ │ ├── export-null.js │ │ │ │ │ ├── export-primitive-default.js │ │ │ │ │ ├── index.js │ │ │ │ │ └── utils.js │ │ │ │ ├── loadBundleAsyncForTest.js │ │ │ │ ├── not_a_source_file.xyz │ │ │ │ ├── polyfill.js │ │ │ │ ├── require-context │ │ │ │ │ ├── conflict.js │ │ │ │ │ ├── empty.js │ │ │ │ │ ├── matching.js │ │ │ │ │ ├── mode-eager.js │ │ │ │ │ ├── mode-lazy-once.js │ │ │ │ │ ├── mode-lazy.js │ │ │ │ │ ├── mode-sync.js │ │ │ │ │ ├── subdir-conflict │ │ │ │ │ │ └── index.js │ │ │ │ │ ├── subdir │ │ │ │ │ │ ├── a.js │ │ │ │ │ │ ├── b.js │ │ │ │ │ │ ├── c.js │ │ │ │ │ │ └── nested │ │ │ │ │ │ │ └── d.js │ │ │ │ │ └── utils.js │ │ │ │ ├── require-resolveWeak │ │ │ │ │ ├── import-and-resolveWeak.js │ │ │ │ │ ├── multiple.js │ │ │ │ │ ├── never-required.js │ │ │ │ │ ├── require-and-resolveWeak.js │ │ │ │ │ ├── subdir │ │ │ │ │ │ ├── counter-module.js │ │ │ │ │ │ └── throwing-module.js │ │ │ │ │ └── utils.js │ │ │ │ └── test.png │ │ │ ├── execBundle.js │ │ │ └── metro.config.js │ │ ├── lib │ │ │ ├── BatchProcessor.js │ │ │ ├── CountingSet.js │ │ │ ├── JsonReporter.js │ │ │ ├── RamBundleParser.js │ │ │ ├── TerminalReporter.js │ │ │ ├── __mocks__ │ │ │ │ ├── GlobalTransformCache.js │ │ │ │ ├── declareOpts.js │ │ │ │ └── getAbsolutePath.js │ │ │ ├── __tests__ │ │ │ │ ├── BatchProcessor-test.js │ │ │ │ ├── CountingSet-test.js │ │ │ │ ├── JsonReporter-test.js │ │ │ │ ├── __snapshots__ │ │ │ │ │ └── contextModuleTemplates-test.js.snap │ │ │ │ ├── bundleToString-test.js │ │ │ │ ├── contextModule-test.js │ │ │ │ ├── contextModuleTemplates-test.js │ │ │ │ ├── debounceAsyncQueue-test.js │ │ │ │ ├── formatBundlingError-test.js │ │ │ │ ├── getGraphId-test.js │ │ │ │ ├── getMaxWorkers-test.js │ │ │ │ ├── getPreludeCode-test.js │ │ │ │ ├── logToConsole-test.js │ │ │ │ ├── parseCustomResolverOptions-test.js │ │ │ │ ├── parseCustomTransformOptions-test.js │ │ │ │ └── parseOptionsFromUrl-test.js │ │ │ ├── bundleToString.js │ │ │ ├── contextModule.js │ │ │ ├── contextModuleTemplates.js │ │ │ ├── countLines.js │ │ │ ├── createModuleIdFactory.js │ │ │ ├── createWebsocketServer.js │ │ │ ├── debounceAsyncQueue.js │ │ │ ├── formatBundlingError.js │ │ │ ├── getAppendScripts.js │ │ │ ├── getGraphId.js │ │ │ ├── getMaxWorkers.js │ │ │ ├── getPreludeCode.js │ │ │ ├── getPrependedScripts.js │ │ │ ├── logToConsole.js │ │ │ ├── parseCustomResolverOptions.js │ │ │ ├── parseCustomTransformOptions.js │ │ │ ├── parseJsonBody.js │ │ │ ├── parseOptionsFromUrl.js │ │ │ ├── relativizeSourceMap.js │ │ │ ├── reporting.js │ │ │ ├── splitBundleOptions.js │ │ │ └── transformHelpers.js │ │ ├── node-haste │ │ │ ├── DependencyGraph.js │ │ │ ├── DependencyGraph │ │ │ │ ├── ModuleResolution.js │ │ │ │ └── createFileMap.js │ │ │ ├── Module.js │ │ │ ├── ModuleCache.js │ │ │ ├── Package.js │ │ │ ├── __mocks__ │ │ │ │ └── graceful-fs.js │ │ │ ├── __tests__ │ │ │ │ └── Module-test.js │ │ │ └── lib │ │ │ │ ├── AssetPaths.js │ │ │ │ ├── __tests__ │ │ │ │ ├── AssetPaths-test.js │ │ │ │ └── parsePlatformFilePath-test.js │ │ │ │ └── parsePlatformFilePath.js │ │ └── shared │ │ │ ├── output │ │ │ ├── RamBundle.js │ │ │ ├── RamBundle │ │ │ │ ├── as-assets.js │ │ │ │ ├── as-indexed-file.js │ │ │ │ ├── buildSourcemapWithMetadata.js │ │ │ │ ├── magic-number.js │ │ │ │ ├── util.js │ │ │ │ └── write-sourcemap.js │ │ │ ├── __tests__ │ │ │ │ ├── __snapshots__ │ │ │ │ │ └── meta-test.js.snap │ │ │ │ └── meta-test.js │ │ │ ├── bundle.flow.js │ │ │ ├── bundle.js │ │ │ ├── meta.js │ │ │ ├── unbundle.js │ │ │ └── writeFile.js │ │ │ └── types.flow.js │ └── types │ │ ├── Asset.d.ts │ │ ├── Bundler.d.ts │ │ ├── DeltaBundler.d.ts │ │ ├── DeltaBundler │ │ ├── Graph.d.ts │ │ ├── Serializers │ │ │ └── getRamBundleInfo.d.ts │ │ ├── Worker.d.ts │ │ └── types.d.ts │ │ ├── IncrementalBundler.d.ts │ │ ├── ModuleGraph │ │ └── worker │ │ │ └── collectDependencies.d.ts │ │ ├── Server.d.ts │ │ ├── Server │ │ └── MultipartResponse.d.ts │ │ ├── index.d.ts │ │ ├── lib │ │ ├── CountingSet.d.ts │ │ ├── TerminalReporter.d.ts │ │ ├── contextModule.d.ts │ │ ├── getGraphId.d.ts │ │ └── reporting.d.ts │ │ ├── node-haste │ │ └── DependencyGraph.d.ts │ │ └── shared │ │ ├── output │ │ └── bundle.d.ts │ │ └── types.d.ts └── ob1 │ ├── .npmignore │ ├── README.md │ ├── package.json │ └── src │ ├── __flowtests__ │ └── ob1-flowtest.js │ ├── __tests__ │ └── ob1-test.js │ └── ob1.js ├── scripts ├── __tests__ │ ├── babel-lib-defs-test.js │ └── subpackages-test.js ├── _getPackages.js ├── babelJestTransformer.js ├── build.js ├── eslint │ ├── base.js │ ├── rules │ │ ├── __tests__ │ │ │ └── strictly-null-test.js │ │ ├── sort-imports.js │ │ └── strictly-null.js │ └── typescript.js ├── mapCoverage.js ├── setupJest.js ├── support │ ├── generateBabelFlowLibraryDefinitions.js │ ├── generateBabelTypesFlowLibraryDefinition.js │ └── updateBabelTraverseFlowLibraryDefinition.js ├── updateBabelFlowLibraryDefinitions.js └── updateVersion.js ├── tsconfig.json ├── website ├── README.md ├── docusaurus.config.js ├── package.json ├── sidebars.json ├── src │ ├── css │ │ └── custom.scss │ └── pages │ │ ├── help │ │ └── index.js │ │ ├── index.js │ │ └── styles.module.css ├── static │ ├── CNAME │ └── img │ │ ├── content │ │ ├── atom.png │ │ ├── high-speed-train.png │ │ └── scales.png │ │ ├── favicon.png │ │ ├── language.svg │ │ ├── metro.svg │ │ ├── opengraph.png │ │ └── oss_logo.svg └── yarn.lock └── yarn.lock /.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor code style configuration 2 | # http://editorconfig.org/ 3 | 4 | root = true 5 | 6 | [*] 7 | end_of_line = lf 8 | insert_final_newline = true 9 | indent_style = space 10 | indent_size = 2 11 | trim_trailing_whitespace = true 12 | 13 | [*.md] 14 | trim_trailing_whitespace = false 15 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | !.eslintrc.js 2 | **/coverage/** 3 | **/node_modules/** 4 | **/vendor/** 5 | bin/ 6 | docs/ 7 | examples/react-native 8 | flow-typed/** 9 | packages/*/build/** 10 | website/ 11 | **/third-party/** 12 | scripts/eslint/rules/sort-imports.js 13 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = { 14 | extends: './scripts/eslint/base', 15 | overrides: [ 16 | { 17 | files: ['flow-typed/**/*.js'], 18 | rules: { 19 | 'babel/quotes': 'off', 20 | 'lint/flow-function-shape': 'off', 21 | }, 22 | }, 23 | { 24 | files: ['package.json'], 25 | parser: 'jsonc-eslint-parser', 26 | }, 27 | { 28 | files: ['packages/*/types/**/*.d.ts'], 29 | extends: './scripts/eslint/typescript', 30 | }, 31 | { 32 | files: ['packages/metro-source-map/**/*.js'], 33 | rules: { 34 | 'operator-assignment': ['error', 'never'], 35 | }, 36 | }, 37 | { 38 | files: ['scripts/**/*.js'], 39 | rules: { 40 | 'babel/func-params-comma-dangle': 'off', 41 | 'import/no-extraneous-dependencies': 'off', 42 | }, 43 | }, 44 | ], 45 | }; 46 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | /packages/.*/build/.* 3 | /\.hg/.* 4 | # this transient dep bundles tests with their package, which flow attempts to parse 5 | # and crashes out as the test includes purposely malformed json 6 | \(/.*\)?/node_modules/resolve/test/.* 7 | 8 | [options] 9 | emoji=true 10 | 11 | format.bracket_spacing=false 12 | 13 | munge_underscores=true 14 | enums=true 15 | 16 | module.name_mapper='\(metro-[^/]*\)' -> '/packages/\1/src/index.js' 17 | 18 | suppress_type=$FlowIssue 19 | suppress_type=$FlowFixMe 20 | suppress_type=$FlowFixMeProps 21 | suppress_type=$FlowFixMeState 22 | suppress_type=$FlowFixMeEmpty 23 | suppress_type=$FlowExpectedError 24 | 25 | [lints] 26 | sketchy-null-number=warn 27 | sketchy-null-mixed=warn 28 | sketchy-number=warn 29 | untyped-type-import=warn 30 | nonstrict-import=warn 31 | deprecated-type=error 32 | unsafe-getters-setters=warn 33 | unnecessary-invariant=warn 34 | unused-promise=error 35 | 36 | [strict] 37 | deprecated-type 38 | nonstrict-import 39 | sketchy-null 40 | unclear-type 41 | unsafe-getters-setters 42 | untyped-import 43 | untyped-type-import 44 | 45 | [version] 46 | ^0.272.2 47 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Integration tests require LF line endings 2 | * text=auto eol=lf 3 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Do you want to request a *feature* or report a *bug*?** 4 | 5 | **What is the current behavior?** 6 | 7 | **If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can `yarn install` and `yarn test`.** 8 | 9 | **What is the expected behavior?** 10 | 11 | **Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.** 12 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Summary 4 | 5 | 6 | 7 | 15 | Changelog: 16 | 17 | ## Test plan 18 | 19 | 20 | -------------------------------------------------------------------------------- /.github/actions/yarn-install/action.yml: -------------------------------------------------------------------------------- 1 | name: Install Dependencies 2 | inputs: 3 | node-version: 4 | type: string 5 | required: false 6 | default: '20.x' 7 | no-lockfile: 8 | type: string 9 | required: false 10 | default: 'false' 11 | 12 | runs: 13 | using: "composite" 14 | steps: 15 | - uses: actions/setup-node@v4 16 | name: Setup Node With Yarn Cache 17 | with: 18 | node-version: ${{ inputs.node-version }} 19 | check-latest: true 20 | cache: ${{ inputs.no-lockfile == 'false' && 'yarn' || '' }} 21 | cache-dependency-path: ${{ inputs.no-lockfile == 'false' && 'yarn.lock' || '' }} 22 | - name: Install Dependencies 23 | run: yarn install ${{ inputs.no-lockfile == 'false' && '--frozen-lockfile' || '--no-lockfile' }} --non-interactive --ignore-scripts 24 | shell: bash 25 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Dependabot configuration 2 | # https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file 3 | 4 | version: 2 5 | updates: 6 | - package-ecosystem: npm 7 | directory: '/packages' 8 | schedule: 9 | interval: weekly 10 | - package-ecosystem: github-actions 11 | directory: '/' 12 | schedule: 13 | interval: weekly 14 | -------------------------------------------------------------------------------- /.github/scripts/install_codecov.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Install Codecov Uploader 4 | # See https://docs.codecov.com/docs/codecov-uploader#using-the-uploader-with-codecovio-cloud 5 | 6 | CODECOV_URL="https://uploader.codecov.io" 7 | 8 | curl "${CODECOV_URL}/verification.gpg" | gpg --no-default-keyring --keyring trustedkeys.gpg --import 9 | curl -Os "${CODECOV_URL}/latest/linux/codecov" 10 | curl -Os "${CODECOV_URL}/latest/linux/codecov.SHA256SUM" 11 | curl -Os "${CODECOV_URL}/latest/linux/codecov.SHA256SUM.sig" 12 | 13 | gpgv codecov.SHA256SUM.sig codecov.SHA256SUM 14 | shasum -a 256 -c codecov.SHA256SUM 15 | 16 | chmod +x codecov 17 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | on: 3 | workflow_call: 4 | inputs: 5 | node-version: 6 | type: string 7 | required: false 8 | default: '20.x' 9 | runs-on: 10 | type: string 11 | required: false 12 | default: 'ubuntu-latest' 13 | no-lockfile: 14 | type: string 15 | required: false 16 | default: 'false' 17 | 18 | jobs: 19 | test: 20 | name: "Tests [Node.js ${{ inputs.node-version }}, ${{ inputs.runs-on }}, ${{ inputs.no-lockfile == 'false' && 'Using yarn.lock' || 'Ignoring yarn.lock' }}]" 21 | runs-on: ${{ inputs.runs-on }} 22 | steps: 23 | - uses: actions/checkout@v4 24 | - uses: ./.github/actions/yarn-install 25 | with: 26 | node-version: ${{ inputs.node-version }} 27 | no-lockfile: ${{ inputs.no-lockfile }} 28 | - name: Run Jest Tests 29 | run: yarn jest --ci --maxWorkers 4 --reporters=default --reporters=jest-junit --rootdir='./' 30 | env: 31 | NIGHTLY_TESTS_NO_LOCKFILE: ${{ inputs.no-lockfile }} 32 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .eslintcache 2 | /node_modules 3 | /packages/*/node_modules/ 4 | /coverage 5 | /reports 6 | npm-debug.log* 7 | packages/*/build/ 8 | 9 | website/build/ 10 | website/i18n/* 11 | website/node_modules 12 | website/translated_docs 13 | .idea 14 | .vscode 15 | .docusaurus 16 | .cache-loader 17 | yarn-error.log 18 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "arrowParens": "avoid", 3 | "bracketSameLine": true, 4 | "bracketSpacing": false, 5 | "requirePragma": true, 6 | "singleQuote": true, 7 | "trailingComma": "all", 8 | "overrides": [ 9 | { 10 | "files": [ 11 | "*.js", 12 | "*.flow" 13 | ], 14 | "options": { 15 | "parser": "hermes" 16 | } 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | [] 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in the [releases](https://github.com/facebook/metro/releases) section. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Meta Platforms, Inc. and affiliates. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | # Codecov configuration 2 | # https://docs.codecov.com/docs/codecovyml-reference 3 | 4 | coverage: 5 | status: 6 | project: 7 | default: 8 | informational: true 9 | patch: 10 | default: 11 | informational: true 12 | 13 | ignore: 14 | - babel.config.js 15 | - eslint-rules/ 16 | - scripts/ 17 | -------------------------------------------------------------------------------- /docs/Troubleshooting.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: troubleshooting 3 | title: Troubleshooting 4 | --- 5 | 6 | Uh oh, something went wrong? Use this guide to resolve issues with Metro. 7 | 8 | 1. Clear Watchman watches: `watchman watch-del-all` 9 | 2. Delete `node_modules` and run `yarn install` 10 | 3. Reset Metro's cache by passing the `--reset-cache` flag, or adding `resetCache: true` to your Metro configuration file. 11 | 4. Remove the cache: `rm -rf ${TMPDIR:-/tmp}/metro-*` 12 | 5. Update Metro to the [latest version](https://www.npmjs.com/package/metro) 13 | 14 | ### Still unresolved? 15 | 16 | See the [Help](/help) pages. 17 | -------------------------------------------------------------------------------- /flow-typed/accepts.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | declare module 'accepts' { 13 | import type {IncomingMessage} from 'http'; 14 | declare module.exports: (req: IncomingMessage) => { 15 | types: () => string[], 16 | }; 17 | } 18 | -------------------------------------------------------------------------------- /flow-typed/console.js.flow: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow 8 | * @format 9 | */ 10 | 11 | 'use strict'; 12 | 13 | // $FlowFixMe[unsupported-syntax] 14 | declare module 'console' { 15 | declare export class Console { 16 | constructor(stdout: mixed, stderr: mixed): void; 17 | assert(value: mixed, message?: string, ...messageParts: Array): void; 18 | dir(data: mixed, options?: Object): void; 19 | 20 | error(msg: string, ...msgParts: Array): void; 21 | error(data: mixed): void; 22 | 23 | info(msg: string, ...msgParts: Array): void; 24 | info(data: mixed): void; 25 | 26 | log(msg: string, ...msgParts: Array): void; 27 | log(data: mixed): void; 28 | 29 | time(label: string): void; 30 | timeEnd(label: string): void; 31 | trace(msg: string, ...msgParts: Array): void; 32 | 33 | warn(msg: string, ...msgParts: Array): void; 34 | warn(data: mixed): void; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /flow-typed/graceful-fs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | // $FlowFixMe[unsupported-syntax] 13 | declare module 'graceful-fs' { 14 | declare module.exports: { 15 | ...$Exports<'fs'>, 16 | gracefulify(fs: {...}): void, 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /flow-typed/jest-snapshot-serializer-raw.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | */ 10 | 11 | declare module 'jest-snapshot-serializer-raw' { 12 | declare opaque type Wrapper; 13 | declare export function wrap(value: string): Wrapper; 14 | declare export function test(value: mixed): boolean; 15 | declare export function print(value: Wrapper): string; 16 | } 17 | -------------------------------------------------------------------------------- /flow-typed/npm/babel-plugin-tester_v6.x.x.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | */ 10 | 11 | // Partial typings for babel-plugin-tester. Add APIs as you need them. 12 | 13 | declare module 'babel-plugin-tester' { 14 | import typeof * as Babel from '@babel/core'; 15 | import type {BabelCoreOptions, PluginObj} from '@babel/core'; 16 | 17 | declare type PluginTesterOptions = { 18 | babelOptions?: BabelCoreOptions, 19 | plugin: (babel: Babel) => PluginObj, 20 | pluginOptions?: TOpts, 21 | tests: $ReadOnly<{ 22 | [title: string]: $ReadOnly<{ 23 | code: string, 24 | output?: string, 25 | error?: string, 26 | snapshot?: boolean, 27 | ... 28 | }>, 29 | }>, 30 | }; 31 | 32 | declare function pluginTester( 33 | opts: PluginTesterOptions, 34 | ): void; 35 | 36 | declare module.exports: typeof pluginTester; 37 | } 38 | -------------------------------------------------------------------------------- /flow-typed/npm/ci-info_v2.x.x.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | // $FlowFixMe[unsupported-syntax] 13 | declare module 'ci-info' { 14 | declare module.exports: { 15 | isCI: boolean, 16 | name: string, 17 | isPR: boolean, 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /flow-typed/npm/exponential-backoff_v3.x.x.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow 8 | * @format 9 | */ 10 | 11 | // https://github.com/coveooss/exponential-backoff 12 | // https://www.npmjs.com/package/exponential-backoff 13 | 14 | declare module 'exponential-backoff' { 15 | declare export type BackoffOptions = Partial; 16 | declare type IBackOffOptions = { 17 | delayFirstAttempt: boolean, 18 | jitter: 'none' | 'full', 19 | maxDelay: number, 20 | numOfAttempts: number, 21 | retry: (e: any, attemptNumber: number) => boolean | Promise, 22 | startingDelay: number, 23 | timeMultiple: number, 24 | }; 25 | declare type BackOff = ( 26 | request: () => Promise, 27 | options?: BackoffOptions, 28 | ) => Promise; 29 | declare module.exports: { 30 | backOff: BackOff, 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /flow-typed/npm/https-proxy-agent_v7.x.x.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow 8 | * @format 9 | */ 10 | 11 | declare module 'https-proxy-agent' { 12 | type HttpHeaders = {[key: string]: string | Array}; 13 | 14 | declare export type HttpsProxyAgentOptions = tls$connectOptions & 15 | http$agentOptions & { 16 | headers?: HttpHeaders | (() => HttpHeaders), 17 | ... 18 | }; 19 | 20 | declare export class HttpsProxyAgent extends http$Agent { 21 | static protocols: ['http', 'https']; 22 | +proxy: URL; 23 | proxyHeaders: HttpHeaders | (() => HttpHeaders); 24 | connectOpts: tls$connectOptions; 25 | constructor(proxy: string | URL, opts?: HttpsProxyAgentOptions): this; 26 | connect( 27 | req: http$requestOptions, 28 | opts: http$agentOptions, 29 | ): Promise; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /flow-typed/npm/strip-ansi_v3.x.x.js: -------------------------------------------------------------------------------- 1 | /** 2 | * (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary. 3 | * 4 | * @flow strict-local 5 | * @format 6 | * @oncall code_indexing 7 | */ 8 | 9 | declare module 'strip-ansi' { 10 | declare module.exports: (string: string) => string; 11 | } 12 | -------------------------------------------------------------------------------- /metro.code-workspace: -------------------------------------------------------------------------------- 1 | { 2 | "folders": [ 3 | { 4 | "path": "." 5 | } 6 | ], 7 | "extensions": { 8 | "recommendations": [ 9 | "dbaeumer.vscode-eslint", 10 | "editorconfig.editorconfig", 11 | "esbenp.prettier-vscode", 12 | "flowtype.flow-for-vscode", 13 | ], 14 | }, 15 | "settings": { 16 | "editor.formatOnSave": true, 17 | "flow.pathToFlow": "${workspaceFolder}/node_modules/.bin/flow", 18 | "javascript.validate.enable": false 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /packages/.gitignore: -------------------------------------------------------------------------------- 1 | /*/build/ 2 | /*/node_modules/ 3 | -------------------------------------------------------------------------------- /packages/buck-worker-tool/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/buck-worker-tool/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "buck-worker-tool", 3 | "version": "0.82.4", 4 | "description": "Implementation of the Buck worker protocol for Node.js.", 5 | "license": "MIT", 6 | "main": "src/worker-tool.js", 7 | "exports": { 8 | ".": "./src/worker-tool.js", 9 | "./package.json": "./package.json", 10 | "./private/*": "./src/*.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "dependencies": { 15 | "duplexer": "^0.1.1", 16 | "flow-enums-runtime": "^0.0.6", 17 | "invariant": "^2.2.4", 18 | "jsonparse": "^1.2.0", 19 | "through": ">=2.2.7 <3" 20 | }, 21 | "devDependencies": { 22 | "metro-memory-fs": "0.82.4" 23 | }, 24 | "scripts": { 25 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 26 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 27 | }, 28 | "engines": { 29 | "node": ">=18.18" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/buck-worker-tool/src/CommandFailedError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | /** 15 | * Thrown to indicate the command failed and already output relevant error 16 | * information on the console. 17 | */ 18 | class CommandFailedError extends Error { 19 | constructor() { 20 | super( 21 | 'The Buck worker-tool command failed. Diagnostics should have ' + 22 | 'been printed on the standard error output.', 23 | ); 24 | } 25 | } 26 | 27 | module.exports = CommandFailedError; 28 | -------------------------------------------------------------------------------- /packages/buck-worker-tool/src/third-party/LICENSE.MIT: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2011 Dominic Tarr 4 | 5 | Permission is hereby granted, free of charge, 6 | to any person obtaining a copy of this software and 7 | associated documentation files (the "Software"), to 8 | deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, 10 | merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom 12 | the Software is furnished to do so, 13 | subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice 16 | shall be included in all copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 19 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 20 | OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 21 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR 22 | ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /packages/metro-babel-register/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-babel-register/src/__tests__/parses-without-transpilation-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @oncall react_native 8 | * @format 9 | * @flow strict 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const {promises: fsPromises} = require('fs'); 15 | const vm = require('vm'); 16 | 17 | test('can be loaded directly without transpilation', async () => { 18 | const code = await fsPromises.readFile( 19 | require.resolve('../babel-register'), 20 | 'utf8', 21 | ); 22 | expect(() => new vm.Script(code)).not.toThrow(); 23 | }); 24 | -------------------------------------------------------------------------------- /packages/metro-babel-register/src/plugins/babel-plugin-metro-replace-ts-require-assignment.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | // Replace `import thing = require('thing')` with `const thing = require('thing')` which allows us to keep CJS semantics 14 | 15 | module.exports = ({template}) => { 16 | const moduleExportsDeclaration = template(` 17 | import NAME from 'IMPORT'; 18 | `); 19 | return { 20 | name: 'metro-replace-ts-require-assignment', 21 | visitor: { 22 | TSImportEqualsDeclaration(path) { 23 | const {node} = path; 24 | 25 | path.replaceWith( 26 | moduleExportsDeclaration({ 27 | IMPORT: node.moduleReference.expression, 28 | NAME: node.id, 29 | }), 30 | ); 31 | }, 32 | }, 33 | }; 34 | }; 35 | -------------------------------------------------------------------------------- /packages/metro-babel-transformer/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-babel-transformer/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-babel-transformer", 3 | "version": "0.82.4", 4 | "description": "🚇 Base Babel transformer for Metro.", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git@github.com:facebook/metro.git" 17 | }, 18 | "scripts": { 19 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 20 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 21 | }, 22 | "keywords": [ 23 | "transformer", 24 | "metro" 25 | ], 26 | "license": "MIT", 27 | "dependencies": { 28 | "@babel/core": "^7.25.2", 29 | "flow-enums-runtime": "^0.0.6", 30 | "hermes-parser": "0.28.1", 31 | "nullthrows": "^1.1.1" 32 | }, 33 | "engines": { 34 | "node": ">=18.18" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /packages/metro-cache-key/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-cache-key/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-cache-key", 3 | "version": "0.82.4", 4 | "description": "🚇 Cache key utility.", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git@github.com:facebook/metro.git" 17 | }, 18 | "scripts": { 19 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 20 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 21 | }, 22 | "license": "MIT", 23 | "devDependencies": { 24 | "metro-memory-fs": "0.82.4" 25 | }, 26 | "dependencies": { 27 | "flow-enums-runtime": "^0.0.6" 28 | }, 29 | "engines": { 30 | "node": ">=18.18" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/metro-cache-key/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const crypto = require('crypto'); 15 | const fs = require('fs'); 16 | 17 | function getCacheKey(files: Array): string { 18 | return files 19 | .reduce( 20 | (hash, file) => hash.update('\0', 'utf8').update(fs.readFileSync(file)), 21 | crypto.createHash('md5'), 22 | ) 23 | .digest('hex'); 24 | } 25 | 26 | module.exports = getCacheKey; 27 | -------------------------------------------------------------------------------- /packages/metro-cache/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-cache/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-cache", 3 | "version": "0.82.4", 4 | "description": "🚇 Cache layers for Metro.", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git@github.com:facebook/metro.git" 17 | }, 18 | "scripts": { 19 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 20 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 21 | }, 22 | "dependencies": { 23 | "exponential-backoff": "^3.1.1", 24 | "flow-enums-runtime": "^0.0.6", 25 | "https-proxy-agent": "^7.0.5", 26 | "metro-core": "0.82.4" 27 | }, 28 | "devDependencies": { 29 | "metro-memory-fs": "0.82.4" 30 | }, 31 | "license": "MIT", 32 | "engines": { 33 | "node": ">=18.18" 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /packages/metro-cache/src/__tests__/stableHash-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const stableHash = require('../stableHash'); 14 | 15 | describe('stableHash', () => { 16 | test('ensures that the hash implementation supports switched order properties', () => { 17 | const sortedHash = stableHash({ 18 | a: 3, 19 | b: 4, 20 | c: { 21 | d: 'd', 22 | e: 'e', 23 | }, 24 | }); 25 | 26 | const unsortedHash = stableHash({ 27 | b: 4, 28 | c: { 29 | e: 'e', 30 | d: 'd', 31 | }, 32 | a: 3, 33 | }); 34 | 35 | expect(unsortedHash).toEqual(sortedHash); 36 | }); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/metro-cache/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const Cache = require('./Cache'); 15 | const stableHash = require('./stableHash'); 16 | const AutoCleanFileStore = require('./stores/AutoCleanFileStore'); 17 | const FileStore = require('./stores/FileStore'); 18 | const HttpGetStore = require('./stores/HttpGetStore'); 19 | const HttpStore = require('./stores/HttpStore'); 20 | 21 | export type {Options as FileOptions} from './stores/FileStore'; 22 | export type {Options as HttpOptions} from './stores/HttpStore'; 23 | export type {CacheStore} from './types.flow'; 24 | 25 | module.exports.AutoCleanFileStore = AutoCleanFileStore; 26 | module.exports.Cache = Cache; 27 | module.exports.FileStore = FileStore; 28 | module.exports.HttpGetStore = HttpGetStore; 29 | module.exports.HttpStore = HttpStore; 30 | 31 | module.exports.stableHash = stableHash; 32 | -------------------------------------------------------------------------------- /packages/metro-cache/src/stableHash.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const crypto = require('crypto'); 15 | const canonicalize = require('metro-core/src/canonicalize'); 16 | 17 | function stableHash(value: mixed): Buffer { 18 | return ( 19 | crypto 20 | .createHash('md5') 21 | /* $FlowFixMe(>=0.95.0 site=react_native_fb) This comment suppresses an 22 | * error found when Flow v0.95 was deployed. To see the error, delete this 23 | * comment and run Flow. */ 24 | .update(JSON.stringify(value, canonicalize)) 25 | .digest('buffer') 26 | ); 27 | } 28 | 29 | module.exports = stableHash; 30 | -------------------------------------------------------------------------------- /packages/metro-cache/src/stores/HttpError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | class HttpError extends Error { 14 | code: number; 15 | 16 | constructor(message: string, code: number) { 17 | super(message); 18 | 19 | this.code = code; 20 | } 21 | } 22 | 23 | module.exports = HttpError; 24 | -------------------------------------------------------------------------------- /packages/metro-cache/src/stores/NetworkError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | class NetworkError extends Error { 14 | code: string; 15 | 16 | constructor(message: string, code: string) { 17 | super(message); 18 | 19 | this.code = code; 20 | } 21 | } 22 | 23 | module.exports = NetworkError; 24 | -------------------------------------------------------------------------------- /packages/metro-cache/src/types.flow.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | export interface CacheStore { 15 | name?: string; 16 | get(key: Buffer): ?T | Promise; 17 | set(key: Buffer, value: T): void | Promise; 18 | clear(): void | Promise; 19 | } 20 | -------------------------------------------------------------------------------- /packages/metro-cache/types/Cache.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import {CacheStore} from './types'; 12 | 13 | /** 14 | * Main cache class. Receives an array of cache instances, and sequentially 15 | * traverses them to return a previously stored value. It also ensures setting 16 | * the value in all instances. 17 | * 18 | * All get/set operations are logged via Metro's logger. 19 | */ 20 | export default class Cache { 21 | constructor(stores: ReadonlyArray>); 22 | get(key: Buffer): Promise; 23 | set(key: Buffer, value: T): Promise; 24 | get isDisabled(): boolean; 25 | } 26 | -------------------------------------------------------------------------------- /packages/metro-cache/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | // 12 | 13 | import Cache from './Cache'; 14 | import stableHash from './stableHash'; 15 | import AutoCleanFileStore from './stores/AutoCleanFileStore'; 16 | import FileStore from './stores/FileStore'; 17 | import HttpGetStore from './stores/HttpGetStore'; 18 | import HttpStore from './stores/HttpStore'; 19 | 20 | export type {Options as FileOptions} from './stores/FileStore'; 21 | export type {Options as HttpOptions} from './stores/HttpStore'; 22 | export type {CacheStore} from './types'; 23 | 24 | export interface MetroCache { 25 | AutoCleanFileStore: typeof AutoCleanFileStore; 26 | Cache: typeof Cache; 27 | FileStore: typeof FileStore; 28 | HttpGetStore: typeof HttpGetStore; 29 | HttpStore: typeof HttpStore; 30 | stableHash: typeof stableHash; 31 | } 32 | 33 | export { 34 | AutoCleanFileStore, 35 | Cache, 36 | FileStore, 37 | HttpGetStore, 38 | HttpStore, 39 | stableHash, 40 | }; 41 | -------------------------------------------------------------------------------- /packages/metro-cache/types/stableHash.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export default function stableHash(value: unknown): Buffer; 12 | -------------------------------------------------------------------------------- /packages/metro-cache/types/stores/AutoCleanFileStore.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type FileStore from './FileStore'; 12 | 13 | export default class AutoCleanFileStore extends FileStore {} 14 | -------------------------------------------------------------------------------- /packages/metro-cache/types/stores/FileStore.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export interface Options { 12 | root: string; 13 | } 14 | 15 | export default class FileStore { 16 | constructor(options: Options); 17 | get(key: Buffer): Promise; 18 | set(key: Buffer, value: T): Promise; 19 | clear(): void; 20 | } 21 | -------------------------------------------------------------------------------- /packages/metro-cache/types/stores/HttpGetStore.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type {Options} from './HttpStore'; 12 | 13 | export default class HttpGetStore { 14 | constructor(options: Options); 15 | get(key: Buffer): Promise; 16 | set(key: Buffer, value: T): Promise; 17 | clear(): void; 18 | } 19 | -------------------------------------------------------------------------------- /packages/metro-cache/types/stores/HttpStore.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export interface Options { 12 | endpoint: string; 13 | family?: 4 | 6; 14 | timeout?: number; 15 | key?: string | ReadonlyArray | Buffer | ReadonlyArray; 16 | cert?: string | ReadonlyArray | Buffer | ReadonlyArray; 17 | ca?: string | ReadonlyArray | Buffer | ReadonlyArray; 18 | } 19 | 20 | export default class HttpStore { 21 | constructor(options: Options); 22 | get(key: Buffer): Promise; 23 | set(key: Buffer, value: T): Promise; 24 | clear(): void; 25 | } 26 | -------------------------------------------------------------------------------- /packages/metro-cache/types/types.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export interface CacheStore { 12 | get(key: Buffer): T | undefined | Promise | Promise; 13 | set(key: Buffer, value: T): void | Promise; 14 | clear(): void | Promise; 15 | } 16 | -------------------------------------------------------------------------------- /packages/metro-config/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-config/README.md: -------------------------------------------------------------------------------- 1 | # Metro Config 2 | 3 | 🚇 Config resolver and transformer for [Metro](https://metrobundler.dev/). 4 | -------------------------------------------------------------------------------- /packages/metro-config/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-config", 3 | "version": "0.82.4", 4 | "description": "🚇 Config parser for Metro.", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js", 13 | "./src/defaults": "./src/defaults/index.js" 14 | }, 15 | "repository": { 16 | "type": "git", 17 | "url": "git@github.com:facebook/metro.git" 18 | }, 19 | "scripts": { 20 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 21 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 22 | }, 23 | "license": "MIT", 24 | "dependencies": { 25 | "connect": "^3.6.5", 26 | "cosmiconfig": "^5.0.5", 27 | "flow-enums-runtime": "^0.0.6", 28 | "jest-validate": "^29.7.0", 29 | "metro": "0.82.4", 30 | "metro-cache": "0.82.4", 31 | "metro-core": "0.82.4", 32 | "metro-runtime": "0.82.4" 33 | }, 34 | "devDependencies": { 35 | "@types/connect": "^3.4.35", 36 | "metro-babel-register": "0.82.4", 37 | "pretty-format": "^29.7.0" 38 | }, 39 | "engines": { 40 | "node": ">=18.18" 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/metro-config/src/__mocks__/cosmiconfig.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | let resolvedConfig = {}; 14 | let loadHasBeenCalled = false; 15 | let returnNull = false; 16 | 17 | const cosmiconfig = jest.fn(() => ({ 18 | search: async () => 19 | returnNull 20 | ? null 21 | : { 22 | filepath: '/metro.config.js', 23 | config: resolvedConfig, 24 | }, 25 | load: async path => { 26 | loadHasBeenCalled = true; 27 | return { 28 | filepath: path, 29 | config: resolvedConfig, 30 | }; 31 | }, 32 | })); 33 | 34 | cosmiconfig.setResolvedConfig = config => { 35 | resolvedConfig = config; 36 | }; 37 | 38 | cosmiconfig.setReturnNull = shouldReturnNull => { 39 | returnNull = shouldReturnNull; 40 | }; 41 | 42 | cosmiconfig.reset = () => { 43 | loadHasBeenCalled = false; 44 | returnNull = false; 45 | }; 46 | 47 | cosmiconfig.hasLoadBeenCalled = () => { 48 | return loadHasBeenCalled; 49 | }; 50 | 51 | module.exports = cosmiconfig; 52 | -------------------------------------------------------------------------------- /packages/metro-config/src/defaults/validConfig.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | module.exports = (async () => { 15 | const defaultConfig = await require('./index')('/path/to/project'); 16 | const validConfig = { 17 | ...defaultConfig, 18 | resolver: { 19 | ...defaultConfig.resolver, 20 | resolveRequest: function CustomResolver() {}, 21 | hasteImplModulePath: './path', 22 | }, 23 | server: { 24 | ...defaultConfig.server, 25 | unstable_serverRoot: '', 26 | }, 27 | transformer: { 28 | ...defaultConfig.transformer, 29 | getTransformOptions: function getTransformOptions() {}, 30 | }, 31 | serializer: { 32 | ...defaultConfig.serializer, 33 | customSerializer: function customSerializer() {}, 34 | }, 35 | }; 36 | 37 | return validConfig; 38 | }: () => any); 39 | -------------------------------------------------------------------------------- /packages/metro-config/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | /*:: 15 | export type * from './configTypes.flow'; 16 | */ 17 | 18 | try { 19 | require('metro-babel-register').unstable_registerForMetroMonorepo(); 20 | } catch {} 21 | 22 | const getDefaultConfig = require('./defaults'); 23 | const {loadConfig, mergeConfig, resolveConfig} = require('./loadConfig'); 24 | 25 | module.exports = { 26 | loadConfig, 27 | resolveConfig, 28 | mergeConfig, 29 | getDefaultConfig, 30 | }; 31 | -------------------------------------------------------------------------------- /packages/metro-config/types/defaults/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type {ConfigT} from '../configTypes'; 12 | 13 | export default interface getDefaultConfig { 14 | (rootPath: string | null): Promise; 15 | getDefaultValues: (rootPath: string | null) => ConfigT; 16 | } 17 | -------------------------------------------------------------------------------- /packages/metro-config/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import getDefaultConfig from './defaults'; 12 | import {loadConfig, mergeConfig, resolveConfig} from './loadConfig'; 13 | 14 | export * from './configTypes'; 15 | export {loadConfig, mergeConfig, resolveConfig, getDefaultConfig}; 16 | -------------------------------------------------------------------------------- /packages/metro-config/types/loadConfig.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type {ConfigT, InputConfigT, YargArguments} from './configTypes'; 12 | 13 | export interface CosmiConfigResult { 14 | filepath: string; 15 | isEmpty: boolean; 16 | config: 17 | | ((partialConfig: ConfigT) => Promise) 18 | | ((partialConfig: ConfigT) => ConfigT) 19 | | InputConfigT; 20 | } 21 | 22 | export function loadConfig( 23 | argv?: YargArguments, 24 | defaultConfigOverrides?: InputConfigT, 25 | ): Promise; 26 | 27 | export function resolveConfig( 28 | filePath?: string, 29 | cwd?: string, 30 | ): Promise; 31 | 32 | export function mergeConfig( 33 | defaultConfig: InputConfigT, 34 | ...configs: InputConfigT[] 35 | ): ConfigT; 36 | -------------------------------------------------------------------------------- /packages/metro-core/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-core/README.md: -------------------------------------------------------------------------------- 1 | # Metro 2 | 3 | 🚇 This package contains core files for [Metro](https://metrobundler.dev/). 4 | 5 | (TODO) 6 | -------------------------------------------------------------------------------- /packages/metro-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-core", 3 | "version": "0.82.4", 4 | "description": "🚇 Metro's core package.", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git@github.com:facebook/metro.git" 17 | }, 18 | "scripts": { 19 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 20 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 21 | }, 22 | "dependencies": { 23 | "flow-enums-runtime": "^0.0.6", 24 | "lodash.throttle": "^4.1.1", 25 | "metro-resolver": "0.82.4" 26 | }, 27 | "license": "MIT", 28 | "engines": { 29 | "node": ">=18.18" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/metro-core/src/canonicalize.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | function canonicalize(key: string, value: mixed): mixed { 15 | if ( 16 | // eslint-disable-next-line lint/strictly-null 17 | value === null || 18 | typeof value !== 'object' || 19 | Array.isArray(value) 20 | ) { 21 | return value; 22 | } 23 | 24 | const keys = Object.keys(value).sort(); 25 | const length = keys.length; 26 | const object: {[string]: mixed} = {}; 27 | 28 | for (let i = 0; i < length; i++) { 29 | object[keys[i]] = value[keys[i]]; 30 | } 31 | 32 | return object; 33 | } 34 | 35 | module.exports = canonicalize; 36 | -------------------------------------------------------------------------------- /packages/metro-core/src/errors.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const AmbiguousModuleResolutionError = require('./errors/AmbiguousModuleResolutionError'); 15 | const PackageResolutionError = require('./errors/PackageResolutionError'); 16 | 17 | module.exports = { 18 | AmbiguousModuleResolutionError, 19 | PackageResolutionError, 20 | }; 21 | -------------------------------------------------------------------------------- /packages/metro-core/src/errors/AmbiguousModuleResolutionError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {DuplicateHasteCandidatesError} from 'metro-file-map'; 15 | 16 | class AmbiguousModuleResolutionError extends Error { 17 | fromModulePath: string; 18 | hasteError: DuplicateHasteCandidatesError; 19 | 20 | constructor( 21 | fromModulePath: string, 22 | hasteError: DuplicateHasteCandidatesError, 23 | ) { 24 | super( 25 | `Ambiguous module resolution from \`${fromModulePath}\`: ` + 26 | hasteError.message, 27 | ); 28 | this.fromModulePath = fromModulePath; 29 | this.hasteError = hasteError; 30 | } 31 | } 32 | 33 | module.exports = AmbiguousModuleResolutionError; 34 | -------------------------------------------------------------------------------- /packages/metro-core/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const AmbiguousModuleResolutionError = require('./errors/AmbiguousModuleResolutionError'); 15 | const PackageResolutionError = require('./errors/PackageResolutionError'); 16 | const Logger = require('./Logger'); 17 | const Terminal = require('./Terminal'); 18 | 19 | module.exports = { 20 | AmbiguousModuleResolutionError, 21 | Logger, 22 | PackageResolutionError, 23 | Terminal, 24 | }; 25 | -------------------------------------------------------------------------------- /packages/metro-core/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | /// 12 | 13 | export * from './Terminal'; 14 | -------------------------------------------------------------------------------- /packages/metro-file-map/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-file-map/README.md: -------------------------------------------------------------------------------- 1 | # \[Experimental\] Metro File Map 2 | 3 | 🚇 File system crawling, watching and mapping for [Metro](https://metrobundler.dev/). 4 | 5 | Originally a fork of [`jest-haste-map`](https://github.com/facebook/jest/tree/main/packages/jest-haste-map). 6 | 7 | This entire package should be considered "experimental" for the time being - 8 | the API is considered internal and changes will not be semver-breaking. 9 | 10 | If you need to rely on `metro-file-map` APIs directly please 11 | [raise an issue](https://github.com/facebook/metro/issues/new) to discuss your 12 | use case. 13 | -------------------------------------------------------------------------------- /packages/metro-file-map/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-file-map", 3 | "version": "0.82.4", 4 | "description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git@github.com:facebook/metro.git" 17 | }, 18 | "scripts": { 19 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 20 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 21 | }, 22 | "license": "MIT", 23 | "dependencies": { 24 | "debug": "^4.4.0", 25 | "fb-watchman": "^2.0.0", 26 | "flow-enums-runtime": "^0.0.6", 27 | "graceful-fs": "^4.2.4", 28 | "invariant": "^2.2.4", 29 | "jest-worker": "^29.7.0", 30 | "micromatch": "^4.0.4", 31 | "nullthrows": "^1.1.1", 32 | "walker": "^1.0.7" 33 | }, 34 | "devDependencies": { 35 | "slash": "^3.0.0" 36 | }, 37 | "engines": { 38 | "node": ">=18.18" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/__tests__/dependencyExtractor.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | const blockCommentRe = /\/\*[^]*?\*\//g; 12 | const lineCommentRe = /\/\/.*/g; 13 | const LOAD_MODULE_RE = 14 | /(?:^|[^.]\s*)(\bloadModule\s*?\(\s*?)([`'"])([^`'"]+)(\2\s*?\))/g; 15 | 16 | export function extract(code, filePath, defaultDependencyExtractor) { 17 | const dependencies = defaultDependencyExtractor(code); 18 | 19 | const addDependency = (match, pre, quot, dep, post) => { 20 | dependencies.add(dep); 21 | return match; 22 | }; 23 | 24 | code 25 | .replace(blockCommentRe, '') 26 | .replace(lineCommentRe, '') 27 | .replace(LOAD_MODULE_RE, addDependency); 28 | 29 | return dependencies; 30 | } 31 | 32 | let cacheKey; 33 | 34 | export function getCacheKey() { 35 | return cacheKey; 36 | } 37 | 38 | export function setCacheKey(key) { 39 | cacheKey = key; 40 | } 41 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/__tests__/haste_impl.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const path = require('path'); 14 | let cacheKey; 15 | 16 | module.exports = { 17 | getCacheKey() { 18 | return cacheKey; 19 | }, 20 | 21 | getHasteName(filename) { 22 | if ( 23 | filename.includes('__mocks__') || 24 | filename.includes('NoHaste') || 25 | filename.includes(path.sep + 'module_dir' + path.sep) || 26 | filename.includes(path.sep + 'sourcemaps' + path.sep) 27 | ) { 28 | return undefined; 29 | } 30 | 31 | return filename 32 | .substr(filename.lastIndexOf(path.sep) + 1) 33 | .replace(/(\.(android|ios|native))?\.js$/, ''); 34 | }, 35 | 36 | setCacheKey(key) { 37 | cacheKey = key; 38 | }, 39 | }; 40 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/__tests__/test_dotfiles_root/.eslintrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/__tests__/test_dotfiles_root/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/crawlers/__fixtures__/directory/bar.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/crawlers/__fixtures__/directory/other.file: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/metro/15fef8ebcf5ae0a13e7f0925a22d4211dde95e02/packages/metro-file-map/src/crawlers/__fixtures__/directory/other.file -------------------------------------------------------------------------------- /packages/metro-file-map/src/crawlers/__fixtures__/foo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/crawlers/__fixtures__/ignored/hidden.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/crawlers/__fixtures__/link-to-directory: -------------------------------------------------------------------------------- 1 | directory -------------------------------------------------------------------------------- /packages/metro-file-map/src/crawlers/__fixtures__/link-to-foo.js: -------------------------------------------------------------------------------- 1 | foo.js -------------------------------------------------------------------------------- /packages/metro-file-map/src/crawlers/node/hasNativeFindSupport.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | import {spawn} from 'child_process'; 13 | 14 | export default async function hasNativeFindSupport(): Promise { 15 | try { 16 | return await new Promise(resolve => { 17 | // Check the find binary supports the non-POSIX -iname parameter wrapped in parens. 18 | const args = [ 19 | '.', 20 | '-type', 21 | 'f', 22 | '(', 23 | '-iname', 24 | '*.ts', 25 | '-o', 26 | '-iname', 27 | '*.js', 28 | ')', 29 | ]; 30 | const child = spawn('find', args, {cwd: __dirname}); 31 | child.on('error', () => { 32 | resolve(false); 33 | }); 34 | child.on('exit', code => { 35 | resolve(code === 0); 36 | }); 37 | }); 38 | } catch { 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/lib/__tests__/normalizePathSeparatorsToSystem-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | describe('normalizePathSeparatorsToSystem', () => { 14 | test('does nothing on posix', () => { 15 | jest.resetModules(); 16 | jest.mock('path', () => jest.requireActual('path').posix); 17 | const normalizePathSeparatorsToSystem = 18 | require('../normalizePathSeparatorsToSystem').default; 19 | expect(normalizePathSeparatorsToSystem('foo/bar/baz.js')).toEqual( 20 | 'foo/bar/baz.js', 21 | ); 22 | }); 23 | 24 | test('replace slashes on windows', () => { 25 | jest.resetModules(); 26 | jest.mock('path', () => jest.requireActual('path').win32); 27 | const normalizePathSeparatorsToSystem = 28 | require('../normalizePathSeparatorsToSystem').default; 29 | expect(normalizePathSeparatorsToSystem('foo/bar/baz.js')).toEqual( 30 | 'foo\\bar\\baz.js', 31 | ); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/lib/normalizePathSeparatorsToPosix.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | import * as path from 'path'; 12 | 13 | let normalizePathSeparatorsToPosix: (string: string) => string; 14 | if (path.sep === '/') { 15 | normalizePathSeparatorsToPosix = (filePath: string): string => filePath; 16 | } else { 17 | normalizePathSeparatorsToPosix = (filePath: string): string => 18 | filePath.replace(/\\/g, '/'); 19 | } 20 | 21 | export default normalizePathSeparatorsToPosix; 22 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/lib/normalizePathSeparatorsToSystem.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | import * as path from 'path'; 12 | 13 | let normalizePathSeparatorsToSystem: (string: string) => string; 14 | if (path.sep === '/') { 15 | normalizePathSeparatorsToSystem = (filePath: string): string => filePath; 16 | } else { 17 | normalizePathSeparatorsToSystem = (filePath: string): string => 18 | filePath.replace(/\//g, path.sep); 19 | } 20 | 21 | export default normalizePathSeparatorsToSystem; 22 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/lib/sorting.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | */ 10 | 11 | // Utilities for working with Array.prototype.sort 12 | 13 | export function compareStrings(a: null | string, b: null | string): number { 14 | if (a == null) { 15 | return b == null ? 0 : -1; 16 | } 17 | if (b == null) { 18 | return 1; 19 | } 20 | return a.localeCompare(b); 21 | } 22 | 23 | export function chainComparators( 24 | ...comparators: Array<(a: T, b: T) => number> 25 | ): (a: T, b: T) => number { 26 | return (a, b) => { 27 | for (const comparator of comparators) { 28 | const result = comparator(a, b); 29 | if (result !== 0) { 30 | return result; 31 | } 32 | } 33 | return 0; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/plugins/haste/__tests__/getPlatformExtension-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import getPlatformExtension from '../getPlatformExtension'; 12 | 13 | const PLATFORMS = new Set(['ios', 'android']); 14 | 15 | describe('getPlatformExtension', () => { 16 | test('should get platform ext', () => { 17 | expect(getPlatformExtension('a.ios.js', PLATFORMS)).toBe('ios'); 18 | expect(getPlatformExtension('a.android.js', PLATFORMS)).toBe('android'); 19 | expect(getPlatformExtension('c.android/a.ios.js', PLATFORMS)).toBe('ios'); 20 | expect(getPlatformExtension('/b/c/a.ios.js', PLATFORMS)).toBe('ios'); 21 | expect(getPlatformExtension('/b/c/a@1.5x.ios.png', PLATFORMS)).toBe('ios'); 22 | expect(getPlatformExtension('/b/c/a@1.5x.lol.png', PLATFORMS)).toBe(null); 23 | expect(getPlatformExtension('/b/c/a.lol.png', PLATFORMS)).toBe(null); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/plugins/haste/getPlatformExtension.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | // Extract platform extension: index.ios.js -> ios 12 | export default function getPlatformExtension( 13 | file: string, 14 | platforms: $ReadOnlySet, 15 | ): ?string { 16 | const last = file.lastIndexOf('.'); 17 | const secondToLast = file.lastIndexOf('.', last - 1); 18 | if (secondToLast === -1) { 19 | return null; 20 | } 21 | const platform = file.substring(secondToLast + 1, last); 22 | return platforms.has(platform) ? platform : null; 23 | } 24 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/plugins/mocks/__tests__/getMockName-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import getMockName from '../getMockName'; 12 | import path from 'path'; 13 | 14 | describe('getMockName', () => { 15 | test('extracts mock name from file path', () => { 16 | expect(getMockName(path.join('a', '__mocks__', 'c.js'))).toBe('c'); 17 | 18 | expect(getMockName(path.join('a', '__mocks__', 'c', 'd.js'))).toBe( 19 | path.join('c', 'd').replace(/\\/g, '/'), 20 | ); 21 | }); 22 | }); 23 | -------------------------------------------------------------------------------- /packages/metro-file-map/src/plugins/mocks/getMockName.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | import * as path from 'path'; 12 | 13 | const MOCKS_PATTERN = path.sep + '__mocks__' + path.sep; 14 | 15 | const getMockName = (filePath: string): string => { 16 | const mockPath = filePath.split(MOCKS_PATTERN)[1]; 17 | return mockPath 18 | .substring(0, mockPath.lastIndexOf(path.extname(mockPath))) 19 | .replaceAll('\\', '/'); 20 | }; 21 | 22 | export default getMockName; 23 | -------------------------------------------------------------------------------- /packages/metro-file-map/types/Watcher.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export type HealthCheckResult = 12 | | {type: 'error'; timeout: number; error: Error; watcher: string | null} 13 | | { 14 | type: 'success'; 15 | timeout: number; 16 | timeElapsed: number; 17 | watcher: string | null; 18 | } 19 | | { 20 | type: 'timeout'; 21 | timeout: number; 22 | watcher: string | null; 23 | pauseReason: string | null; 24 | }; 25 | -------------------------------------------------------------------------------- /packages/metro-file-map/types/cache/DiskCacheManager.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type { 12 | BuildParameters, 13 | CacheData, 14 | CacheManager, 15 | CacheManagerWriteOptions, 16 | } from '../flow-types'; 17 | 18 | export interface DiskCacheConfig { 19 | buildParameters: BuildParameters; 20 | cacheFilePrefix?: string | null; 21 | cacheDirectory?: string | null; 22 | } 23 | 24 | export class DiskCacheManager implements CacheManager { 25 | constructor(options: DiskCacheConfig); 26 | static getCacheFilePath( 27 | buildParameters: BuildParameters, 28 | cacheFilePrefix?: string | null, 29 | cacheDirectory?: string | null, 30 | ): string; 31 | getCacheFilePath(): string; 32 | read(): Promise; 33 | write( 34 | getSnapshot: () => CacheData, 35 | opts: CacheManagerWriteOptions, 36 | ): Promise; 37 | end(): Promise; 38 | } 39 | -------------------------------------------------------------------------------- /packages/metro-file-map/types/lib/DuplicateHasteCandidatesError.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type {DuplicatesSet} from '../flow-types'; 12 | 13 | export class DuplicateHasteCandidatesError extends Error { 14 | hasteName: string; 15 | platform: string | null; 16 | supportsNativePlatform: boolean; 17 | duplicatesSet: DuplicatesSet; 18 | constructor( 19 | name: string, 20 | platform: string, 21 | supportsNativePlatform: boolean, 22 | duplicatesSet: DuplicatesSet, 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /packages/metro-memory-fs/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-memory-fs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-memory-fs", 3 | "version": "0.82.4", 4 | "description": "🚇 A memory-based implementation of `fs` useful for testing.", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git@github.com:facebook/metro.git" 17 | }, 18 | "scripts": { 19 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 20 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 21 | }, 22 | "license": "MIT", 23 | "dependencies": { 24 | "flow-enums-runtime": "^0.0.6" 25 | }, 26 | "engines": { 27 | "node": ">=18.18" 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /packages/metro-minify-terser/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-minify-terser/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-minify-terser", 3 | "version": "0.82.4", 4 | "description": "🚇 Minifier for Metro based on Terser.", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git@github.com:facebook/metro.git" 17 | }, 18 | "scripts": { 19 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 20 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 21 | }, 22 | "license": "MIT", 23 | "dependencies": { 24 | "flow-enums-runtime": "^0.0.6", 25 | "terser": "^5.15.0" 26 | }, 27 | "engines": { 28 | "node": ">=18.18" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/metro-minify-terser/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const minifier = require('./minifier'); 15 | 16 | module.exports = minifier; 17 | -------------------------------------------------------------------------------- /packages/metro-resolver/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-resolver/README.md: -------------------------------------------------------------------------------- 1 | # metro-resolver 2 | 3 | 🚇 [Metro](https://metrobundler.dev/) resolution logic 4 | -------------------------------------------------------------------------------- /packages/metro-resolver/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-resolver", 3 | "version": "0.82.4", 4 | "description": "🚇 Implementation of Metro's resolution logic.", 5 | "main": "src/index.js", 6 | "exports": { 7 | ".": "./src/index.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src": "./src/index.js", 11 | "./src/*.js": "./src/*.js", 12 | "./src/*": "./src/*.js" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git@github.com:facebook/metro.git" 17 | }, 18 | "scripts": { 19 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 20 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 21 | }, 22 | "license": "MIT", 23 | "engines": { 24 | "node": ">=18.18" 25 | }, 26 | "devDependencies": { 27 | "metro": "0.82.4" 28 | }, 29 | "dependencies": { 30 | "flow-enums-runtime": "^0.0.6" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/__tests__/__snapshots__/index-test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`throws on invalid package name 1`] = ` 4 | "The package \`/root/node_modules/invalid/package.json\` is invalid because it specifies a \`main\` module field that could not be resolved (\`/root/node_modules/invalid/main\`. None of these files exist: 5 | 6 | * /root/node_modules/invalid/main(.js|.jsx|.json|.ts|.tsx) 7 | * /root/node_modules/invalid/main/index(.js|.jsx|.json|.ts|.tsx)" 8 | `; 9 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/createDefaultContext.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | import type {ResolutionContext} from './types'; 13 | import type {TransformResultDependency} from 'metro/src/DeltaBundler/types.flow'; 14 | 15 | import {redirectModulePath} from './PackageResolve'; 16 | 17 | type PartialContext = $ReadOnly<{ 18 | ...ResolutionContext, 19 | redirectModulePath?: ResolutionContext['redirectModulePath'], 20 | }>; 21 | 22 | /** 23 | * Helper used by the `metro` package to create the `ResolutionContext` object. 24 | * As context values can be overridden by callers, this occurs externally to 25 | * `resolve.js`. 26 | */ 27 | function createDefaultContext( 28 | context: PartialContext, 29 | dependency: TransformResultDependency, 30 | ): ResolutionContext { 31 | return { 32 | redirectModulePath: (modulePath: string) => 33 | redirectModulePath(context, modulePath), 34 | dependency, 35 | ...context, 36 | }; 37 | } 38 | 39 | module.exports = createDefaultContext; 40 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/errors/FailedToResolveNameError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | class FailedToResolveNameError extends Error { 15 | dirPaths: $ReadOnlyArray; 16 | extraPaths: $ReadOnlyArray; 17 | 18 | constructor( 19 | dirPaths: $ReadOnlyArray, 20 | extraPaths: $ReadOnlyArray, 21 | ) { 22 | const displayDirPaths = dirPaths.concat(extraPaths); 23 | const hint = displayDirPaths.length ? ' or in these directories:' : ''; 24 | super( 25 | `Module does not exist in the Haste module map${hint}\n` + 26 | displayDirPaths.map(dirPath => ` ${dirPath}`).join('\n') + 27 | '\n', 28 | ); 29 | 30 | this.dirPaths = dirPaths; 31 | this.extraPaths = extraPaths; 32 | } 33 | } 34 | 35 | module.exports = FailedToResolveNameError; 36 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/errors/FailedToResolvePathError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {FileAndDirCandidates} from '../types'; 15 | 16 | const formatFileCandidates = require('./formatFileCandidates'); 17 | 18 | class FailedToResolvePathError extends Error { 19 | candidates: FileAndDirCandidates; 20 | 21 | constructor(candidates: FileAndDirCandidates) { 22 | super( 23 | 'The module could not be resolved because none of these files exist:\n\n' + 24 | [candidates.file, candidates.dir] 25 | .filter(Boolean) 26 | .map(candidates => ` * ${formatFileCandidates(candidates)}`) 27 | .join('\n'), 28 | ); 29 | this.candidates = candidates; 30 | } 31 | } 32 | 33 | module.exports = FailedToResolvePathError; 34 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/errors/FailedToResolveUnsupportedError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | class FailedToResolveUnsupportedError extends Error { 15 | constructor(message: string) { 16 | super(message); 17 | } 18 | } 19 | 20 | module.exports = FailedToResolveUnsupportedError; 21 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/errors/InvalidPackageConfigurationError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | /** 13 | * Raised when a package contains an invalid `package.json` configuration. 14 | */ 15 | export default class InvalidPackageConfigurationError extends Error { 16 | /** 17 | * The description of the error cause. 18 | */ 19 | reason: string; 20 | 21 | /** 22 | * Absolute path of the package being resolved. 23 | */ 24 | packagePath: string; 25 | 26 | constructor( 27 | opts: $ReadOnly<{ 28 | reason: string, 29 | packagePath: string, 30 | }>, 31 | ) { 32 | super( 33 | `The package ${opts.packagePath} contains an invalid package.json ` + 34 | 'configuration. Consider raising this issue with the package ' + 35 | 'maintainer(s).\nReason: ' + 36 | opts.reason, 37 | ); 38 | // $FlowFixMe[unsafe-object-assign] 39 | Object.assign(this, opts); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/errors/PackageImportNotResolvedError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | /** 13 | * Raised when package imports do not define or permit a target subpath in the 14 | * package for the given import specifier. 15 | */ 16 | export default class PackageImportNotResolvedError extends Error { 17 | /** 18 | * Either the import specifier read, or the absolute path of the module being 19 | * resolved (used when import specifier is externally remapped). 20 | */ 21 | +importSpecifier: string; 22 | 23 | /** 24 | * The description of the error cause. 25 | */ 26 | +reason: string; 27 | 28 | constructor( 29 | opts: $ReadOnly<{ 30 | importSpecifier: string, 31 | reason: string, 32 | }>, 33 | ) { 34 | super( 35 | `The path for ${opts.importSpecifier} could not be resolved.\nReason: ` + 36 | opts.reason, 37 | ); 38 | this.importSpecifier = opts.importSpecifier; 39 | this.reason = opts.reason; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/errors/PackagePathNotExportedError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | /** 13 | * Raised when package exports do not define or permit a target subpath in the 14 | * package for the given module. 15 | */ 16 | export default class PackagePathNotExportedError extends Error {} 17 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/errors/formatFileCandidates.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {FileCandidates} from '../types'; 15 | 16 | function formatFileCandidates(candidates: FileCandidates): string { 17 | if (candidates.type === 'asset') { 18 | return candidates.name; 19 | } 20 | let formatted = candidates.filePathPrefix; 21 | if (candidates.candidateExts.length) { 22 | formatted += '(' + candidates.candidateExts.filter(Boolean).join('|') + ')'; 23 | } 24 | return formatted; 25 | } 26 | 27 | module.exports = formatFileCandidates; 28 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | export type { 15 | AssetFileResolution, 16 | CustomResolutionContext, 17 | CustomResolver, 18 | CustomResolverOptions, 19 | DoesFileExist, 20 | FileAndDirCandidates, 21 | FileCandidates, 22 | FileResolution, 23 | FileSystemLookup, 24 | ResolutionContext, 25 | Resolution, 26 | ResolveAsset, 27 | Result, 28 | } from './types'; 29 | 30 | const Resolver = { 31 | FailedToResolveNameError: require('./errors/FailedToResolveNameError'), 32 | FailedToResolvePathError: require('./errors/FailedToResolvePathError'), 33 | FailedToResolveUnsupportedError: require('./errors/FailedToResolveUnsupportedError'), 34 | formatFileCandidates: require('./errors/formatFileCandidates'), 35 | InvalidPackageError: require('./errors/InvalidPackageError'), 36 | resolve: require('./resolve'), 37 | }; 38 | 39 | module.exports = Resolver; 40 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/resolveAsset.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | import type {AssetResolution, ResolutionContext} from './types'; 13 | 14 | import path from 'path'; 15 | 16 | /** 17 | * Resolve a file path as an asset. Returns the set of files found after 18 | * expanding asset resolutions (e.g. `icon@2x.png`). Users may override this 19 | * behaviour via `context.resolveAsset`. 20 | */ 21 | export default function resolveAsset( 22 | context: ResolutionContext, 23 | filePath: string, 24 | ): AssetResolution | null { 25 | const dirPath = path.dirname(filePath); 26 | const extension = path.extname(filePath); 27 | const basename = path.basename(filePath, extension); 28 | 29 | try { 30 | if (!/@\d+(?:\.\d+)?x$/.test(basename)) { 31 | const assets = context.resolveAsset(dirPath, basename, extension); 32 | if (assets != null) { 33 | return { 34 | type: 'assetFiles', 35 | filePaths: assets, 36 | }; 37 | } 38 | } 39 | } catch (e) {} 40 | 41 | return null; 42 | } 43 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/utils/isAssetFile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | import path from 'path'; 13 | 14 | /** 15 | * Determine if a file path should be considered an asset file based on the 16 | * given `assetExts`. 17 | */ 18 | export default function isAssetFile( 19 | filePath: string, 20 | assetExts: $ReadOnlySet, 21 | ): boolean { 22 | const baseName = path.basename(filePath); 23 | 24 | for (let i = baseName.length - 1; i >= 0; i--) { 25 | if (baseName[i] === '.') { 26 | const ext = baseName.slice(i + 1); 27 | 28 | if (assetExts.has(ext)) { 29 | return true; 30 | } 31 | } 32 | } 33 | 34 | return false; 35 | } 36 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/utils/isSubpathDefinedInExportsLike.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | /** 13 | * Identifies whether the given subpath is defined in the given "exports"-like 14 | * mapping. Does not reduce exports conditions (therefore does not identify 15 | * whether the subpath is mapped to a value). 16 | */ 17 | import type {NormalizedExportsLikeMap} from '../types'; 18 | 19 | import {matchSubpathPattern} from './matchSubpathPattern'; 20 | 21 | export function isSubpathDefinedInExportsLike( 22 | exportsLikeMap: NormalizedExportsLikeMap, 23 | subpath: string, 24 | ): boolean { 25 | if (exportsLikeMap.has(subpath)) { 26 | return true; 27 | } 28 | 29 | // Attempt to match after expanding any subpath pattern keys 30 | for (const key of exportsLikeMap.keys()) { 31 | if ( 32 | key.split('*').length === 2 && 33 | matchSubpathPattern(key, subpath) != null 34 | ) { 35 | return true; 36 | } 37 | } 38 | 39 | return false; 40 | } 41 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/utils/matchSubpathPattern.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | /** 13 | * If a subpath pattern expands to the passed subpath, return the subpath match 14 | * (value to substitute for '*'). Otherwise, return `null`. 15 | * 16 | * See https://nodejs.org/docs/latest-v19.x/api/packages.html#subpath-patterns. 17 | */ 18 | export function matchSubpathPattern( 19 | subpathPattern: string, 20 | subpath: string, 21 | ): string | null { 22 | const [patternBase, patternTrailer] = subpathPattern.split('*'); 23 | 24 | if ( 25 | subpath.startsWith(patternBase) && 26 | (patternTrailer.length === 0 || 27 | (subpath.endsWith(patternTrailer) && 28 | subpath.length >= subpathPattern.length)) 29 | ) { 30 | return subpath.substring( 31 | patternBase.length, 32 | subpath.length - patternTrailer.length, 33 | ); 34 | } 35 | 36 | return null; 37 | } 38 | -------------------------------------------------------------------------------- /packages/metro-resolver/src/utils/toPosixPath.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | import path from 'path'; 13 | 14 | const MATCH_NON_POSIX_PATH_SEPS = new RegExp('\\' + path.win32.sep, 'g'); 15 | 16 | /** 17 | * Replace path separators in the passed string to coerce to a POSIX path. This 18 | * is a no-op on POSIX systems. 19 | */ 20 | export default function toPosixPath(relativePathOrSpecifier: string): string { 21 | if (path.sep === path.posix.sep) { 22 | return relativePathOrSpecifier; 23 | } 24 | 25 | return relativePathOrSpecifier.replace( 26 | MATCH_NON_POSIX_PATH_SEPS, 27 | path.posix.sep, 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /packages/metro-resolver/types/index.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export * from './types'; 12 | 13 | import {Resolution, ResolutionContext} from './types'; 14 | 15 | export function resolve( 16 | context: ResolutionContext, 17 | moduleName: string, 18 | platform: string | null, 19 | ): Resolution; 20 | -------------------------------------------------------------------------------- /packages/metro-runtime/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-runtime/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-runtime", 3 | "version": "0.82.4", 4 | "description": "🚇 Module required for evaluating Metro bundles.", 5 | "exports": { 6 | "./package.json": "./package.json", 7 | "./modules/asyncRequire": "./src/modules/asyncRequire.js", 8 | "./modules/empty-module": "./src/modules/empty-module.js", 9 | "./modules/HMRClient": "./src/modules/HMRClient.js", 10 | "./modules/null-module": "./src/modules/null-module.js", 11 | "./polyfills/require": "./src/polyfills/require.js", 12 | "./private/*": "./src/*.js", 13 | "./src/*.js": "./src/*.js", 14 | "./src/*": "./src/*.js" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git@github.com:facebook/metro.git" 19 | }, 20 | "scripts": { 21 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 22 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 23 | }, 24 | "license": "MIT", 25 | "dependencies": { 26 | "@babel/runtime": "^7.25.0", 27 | "flow-enums-runtime": "^0.0.6" 28 | }, 29 | "devDependencies": { 30 | "@babel/core": "^7.25.2", 31 | "react": "19.1.0", 32 | "react-refresh": "^0.14.0", 33 | "react-test-renderer": "19.1.0" 34 | }, 35 | "engines": { 36 | "node": ">=18.18" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/metro-runtime/src/modules/empty-module.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | -------------------------------------------------------------------------------- /packages/metro-runtime/src/modules/null-module.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | module.exports = null; 12 | -------------------------------------------------------------------------------- /packages/metro-runtime/src/polyfills/.babelrc.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = { 14 | plugins: [ 15 | require.resolve('@babel/plugin-transform-flow-strip-types'), 16 | require.resolve('@babel/plugin-proposal-nullish-coalescing-operator'), 17 | require.resolve('@babel/plugin-proposal-optional-chaining'), 18 | ], 19 | }; 20 | -------------------------------------------------------------------------------- /packages/metro-source-map/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-source-map/README.md: -------------------------------------------------------------------------------- 1 | # Metro 2 | 3 | 🚇 The source map generator for [Metro](https://metrobundler.dev/). 4 | 5 | (TODO) 6 | -------------------------------------------------------------------------------- /packages/metro-source-map/src/Consumer/createConsumer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {MixedSourceMap} from '../source-map'; 15 | import type {IConsumer} from './types.flow'; 16 | 17 | const invariant = require('invariant'); 18 | 19 | function createConsumer(sourceMap: MixedSourceMap): IConsumer { 20 | invariant( 21 | (sourceMap.version: mixed) === '3' || sourceMap.version === 3, 22 | `Unrecognized source map format version: ${sourceMap.version}`, 23 | ); 24 | const MappingsConsumer = require('./MappingsConsumer'); 25 | const SectionsConsumer = require('./SectionsConsumer'); 26 | 27 | // eslint-disable-next-line lint/strictly-null 28 | if (sourceMap.mappings === undefined) { 29 | return new SectionsConsumer(sourceMap); 30 | } 31 | return new MappingsConsumer(sourceMap); 32 | } 33 | 34 | module.exports = createConsumer; 35 | -------------------------------------------------------------------------------- /packages/metro-source-map/src/Consumer/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | // Implements an API-compatible subset of source-map's `SourceMapConsumer`. 15 | const DelegatingConsumer = require('./DelegatingConsumer'); 16 | 17 | module.exports = DelegatingConsumer; 18 | -------------------------------------------------------------------------------- /packages/metro-source-map/src/Consumer/search.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | function greatestLowerBound( 15 | elements: $ReadOnlyArray, 16 | target: U, 17 | comparator: (U, T) => number, 18 | ): ?number { 19 | let first = 0; 20 | let it = 0; 21 | let count = elements.length; 22 | let step; 23 | while (count > 0) { 24 | it = first; 25 | step = Math.floor(count / 2); 26 | it = it + step; 27 | if (comparator(target, elements[it]) >= 0) { 28 | first = ++it; 29 | count = count - (step + 1); 30 | } else { 31 | count = step; 32 | } 33 | } 34 | return first ? first - 1 : null; 35 | } 36 | 37 | module.exports = {greatestLowerBound}; 38 | -------------------------------------------------------------------------------- /packages/metro-source-map/src/__tests__/__fixtures__/1.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "foo.js", 4 | "sourceRoot": "", 5 | "sources": ["foo.ts"], 6 | "names": ["Greeter", "Greeter.constructor", "Greeter.greet"], 7 | "mappings": "AAAA,IAAM,OAAO;IAGTA,SAHEA,OAAOA,CAGGA,IAAIA;QACZC,IAAIA,CAACA,IAAIA,GAAGA,IAAIA,CAACA;IACrBA,CAACA;IAEDD,uBAAKA,GAALA;QACIE,OAAOA,CAACA,GAAGA,CAACA,QAAQA,GAAIA,IAAIA,CAACA,IAAIA,GAAGA,GAAGA,CAACA,CAACA;IAC7CA,CAACA;IACLF,cAACA;AAADA,CAACA,AAVD,IAUC" 8 | } 9 | -------------------------------------------------------------------------------- /packages/metro-source-map/src/__tests__/__fixtures__/2.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "file": "foo.minified.js", 4 | "sources": ["foo.js"], 5 | "names": ["Greeter", "name", "this", "prototype", "greet", "console", "log"], 6 | "mappings": "AAAA,GAAIA,SAAU,WACV,QAASA,SAAQC,MACbC,KAAKD,KAAOA,KAEhBD,QAAQG,UAAUC,MAAQ,WACtBC,QAAQC,IAAI,SAAWJ,KAAKD,KAAO,KAEvC,OAAOD" 7 | } 8 | -------------------------------------------------------------------------------- /packages/metro-source-map/src/__tests__/__fixtures__/merged_1_2.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "sources": ["foo.ts"], 4 | "x_facebook_sources": [null], 5 | "names": ["Greeter", "Greeter.constructor", "Greeter.greet"], 6 | "mappings": "AAAA,GAAM,SAAO,WAGTA,QAHEA,SAGUA,MACRC,KAAKA,KAAOA,KAGhBD,QAAAA,UAAAA,MAAAA,WACIE,QAAQA,IAAIA,SAAYA,KAAKA,KAAOA,KAE5CF,OAAAA", 7 | "file": "foo.minified.js" 8 | } 9 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-symbolicate", 3 | "version": "0.82.4", 4 | "description": "🚇 A tool to find the source location from JS bundles and stack traces.", 5 | "license": "MIT", 6 | "main": "./src/index.js", 7 | "bin": "./src/index.js", 8 | "exports": { 9 | ".": "./src/index.js", 10 | "./package.json": "./package.json", 11 | "./private/*": "./src/*.js", 12 | "./src": "./src/index.js", 13 | "./src/*.js": "./src/*.js", 14 | "./src/*": "./src/*.js" 15 | }, 16 | "repository": { 17 | "type": "git", 18 | "url": "git@github.com:facebook/metro.git" 19 | }, 20 | "scripts": { 21 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 22 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 23 | }, 24 | "keywords": [ 25 | "metro" 26 | ], 27 | "dependencies": { 28 | "flow-enums-runtime": "^0.0.6", 29 | "invariant": "^2.2.4", 30 | "metro-source-map": "0.82.4", 31 | "nullthrows": "^1.1.1", 32 | "source-map": "^0.5.6", 33 | "vlq": "^1.0.0" 34 | }, 35 | "engines": { 36 | "node": ">=18.18" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/coverageStackTrace.json: -------------------------------------------------------------------------------- 1 | { 2 | "executedFunctions": [ 3 | { 4 | "line": 0, 5 | "column": 25522, 6 | "SourceURL": "main.js" 7 | }, 8 | { 9 | "line": 0, 10 | "column": 25877, 11 | "SourceURL": "main.js" 12 | }, 13 | { 14 | "line": 0, 15 | "column": 139, 16 | "SourceURL": "seg-1.js" 17 | } 18 | ] 19 | } 20 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/coverageStackTraceCJS.json: -------------------------------------------------------------------------------- 1 | { 2 | "executedFunctions": [ 3 | { 4 | "line": 0, 5 | "column": 23819 6 | }, 7 | { 8 | "line": 0, 9 | "column": 22579 10 | }, 11 | { 12 | "line": 51, 13 | "column": 27 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/directory/foo.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["/js/react-native-github/Libraries/BatchedBridge/BatchedBridge.js"],"names":["BatchedBridge","require","Object","defineProperty","global","configurable","value","module","exports"],"mappings":"AAUA;;AAIA,IAAMA,aAAa,GAAG,KAAAC,OAAA,mEAAA,GAAtB;AAQAC,MAAM,CAACC,cAAPD,CAAsBE,MAAtBF,EAA8B,mBAA9BA,EAAmD;AACjDG,EAAAA,YAAY,EAAE,IADmC;AAEjDC,EAAAA,KAAK,EAAEN;AAF0C,CAAnDE;AAKAK,MAAM,CAACC,OAAPD,GAAiBP,aAAjBO"} 2 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/directory/test.stack: -------------------------------------------------------------------------------- 1 | someFunc@foo.js:4:0 2 | someOtherFunc@subdir1/bar.js:255:6 3 | fn@fileThatDoesntExist.js:10:20 4 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/hermesStackTrace.json: -------------------------------------------------------------------------------- 1 | { 2 | "callstack": [ 3 | { 4 | "CJSModuleOffset": 0, 5 | "FunctionID": 50, 6 | "ByteCodeOffset": 58, 7 | "SourceURL": "/a/b/c/main.jsbundle" 8 | }, 9 | { 10 | "CJSModuleOffset": 0, 11 | "FunctionID": 290, 12 | "ByteCodeOffset": 3, 13 | "SourceURL": "/a/b/c/main.jsbundle" 14 | }, 15 | { 16 | "CJSModuleOffset": 0, 17 | "FunctionID": 3, 18 | "ByteCodeOffset": 4, 19 | "SourceURL": "seg-1.js" 20 | }, 21 | { 22 | "CJSModuleOffset": 0, 23 | "FunctionID": 3, 24 | "ByteCodeOffset": 4, 25 | "SourceURL": "seg-16.js" 26 | }, 27 | { 28 | "CJSModuleOffset": 0, 29 | "FunctionID": 3, 30 | "ByteCodeOffset": 4, 31 | "SourceURL": "seg-1.js", 32 | "StackFrameRegOffs": 1912, 33 | "SourceLocation": "file.js:23:14" 34 | }, 35 | { 36 | "NativeCode": true 37 | } 38 | ] 39 | } 40 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/hermesStackTraceCJS-SegmentID.json: -------------------------------------------------------------------------------- 1 | { 2 | "callstack": [ 3 | { 4 | "SegmentID": 0, 5 | "FunctionID": 270, 6 | "ByteCodeOffset": 12, 7 | "SourceURL": "Fb4aBundle.js" 8 | }, 9 | { 10 | "SegmentID": 51, 11 | "FunctionID": 3, 12 | "ByteCodeOffset": 4, 13 | "SourceURL": "Fb4aBundle.js" 14 | }, 15 | { 16 | "SegmentID": 51, 17 | "FunctionID": 3, 18 | "ByteCodeOffset": 4, 19 | "SourceURL": "seg-5.js" 20 | }, 21 | { 22 | "SegmentID": 51, 23 | "FunctionID": 3, 24 | "ByteCodeOffset": 4, 25 | "SourceURL": "Fb4aBundle.js", 26 | "StackFrameRegOffs": 1219, 27 | "SourceLocation": "file.js:12:11" 28 | }, 29 | { 30 | "NativeCode": true 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/hermesStackTraceCJS.json: -------------------------------------------------------------------------------- 1 | { 2 | "callstack": [ 3 | { 4 | "CJSModuleOffset": 0, 5 | "FunctionID": 270, 6 | "ByteCodeOffset": 12, 7 | "SourceURL": "Fb4aBundle.js" 8 | }, 9 | { 10 | "CJSModuleOffset": 51, 11 | "FunctionID": 3, 12 | "ByteCodeOffset": 4, 13 | "SourceURL": "Fb4aBundle.js" 14 | }, 15 | { 16 | "CJSModuleOffset": 51, 17 | "FunctionID": 3, 18 | "ByteCodeOffset": 4, 19 | "SourceURL": "seg-5.js" 20 | }, 21 | { 22 | "CJSModuleOffset": 51, 23 | "FunctionID": 3, 24 | "ByteCodeOffset": 4, 25 | "SourceURL": "Fb4aBundle.js", 26 | "StackFrameRegOffs": 1219, 27 | "SourceLocation": "file.js:12:11" 28 | }, 29 | { 30 | "NativeCode": true 31 | } 32 | ] 33 | } 34 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.attribution.input: -------------------------------------------------------------------------------- 1 | {"functionId":1,"location":{"virtualOffset":22},"usage":[]} 2 | {"functionId":2,"location":{"virtualOffset":99},"usage":[]} 3 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.cpuprofile: -------------------------------------------------------------------------------- 1 | { 2 | "stackFrames": { 3 | "1": { 4 | "funcVirtAddr": "0", 5 | "offset": "0", 6 | "name": "global+0", 7 | "category": "JavaScript" 8 | }, 9 | "2": { 10 | "funcVirtAddr": "0", 11 | "offset": "55", 12 | "name": "global+55", 13 | "category": "JavaScript" 14 | }, 15 | "3": { 16 | "funcVirtAddr": "67", 17 | "offset": "16", 18 | "name": "entryPoint+16", 19 | "category": "JavaScript", 20 | "parent": 2 21 | }, 22 | "4": { 23 | "funcVirtAddr": "89", 24 | "offset": "0", 25 | "name": "helper+0", 26 | "category": "JavaScript", 27 | "parent": 3 28 | }, 29 | "5": { 30 | "funcVirtAddr": "89", 31 | "offset": "146", 32 | "name": "helper+146", 33 | "category": "JavaScript", 34 | "parent": 3 35 | }, 36 | "6": { 37 | "name": "[Native]4367295792", 38 | "category": "Native", 39 | "parent": 5 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.cpuprofile.map: -------------------------------------------------------------------------------- 1 | { 2 | "version": 3, 3 | "sources": [ 4 | "temp/bench.js" 5 | ], 6 | "x_facebook_sources": [ 7 | [ 8 | { 9 | "names": ["","entryPoint","helper"], 10 | "mappings": "AAA,uBCC,JCI,RFe" 11 | } 12 | ] 13 | ], 14 | "mappings": "AACC,uDAmBU,YAnBY,gBACd,MAGU,wFAKA,WACT,iBACC,IAAD,YACU,cAAA,YAHY,eAAb;" 15 | } 16 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["thrower.js"],"names":["notCalled","alsoNotCalled","throws6a","Error","throws6","throws6b","throws4","obj","throws5","apply","this","throws2","throws3","throws1","throws0","t","eval","o","forEach","call","arguments","arg","err","print","stack"],"mappings":"CAAA,WAGE,SAASA,YACP,SAASC,IACPA,IAEFA,IACAD,YAIF,SAASE,WACP,MAAM,IAAIC,MAAM,wBAGlB,SAASC,UACP,MAAM,IAAID,MAAM,wBAGlB,SAASE,WACP,MAAM,IAAIF,MAAM,wBAYlB,SAASG,UACPC,IAAIC,EAAQC,MAAMC,MAAON,QAASA,QAASA,UAG7C,SAASO,UACPJ,IAAIK,IAGN,SAASC,UAELF,UAIJ,SAASG,UACPD,UAxBF,IAAIN,KACFQ,EAAS,WACPC,KAAK,eAEPC,EAAS,cACJC,QAAQC,KAAKC,UAAW,SAASC,GAAOA,QAsB/C,IACEP,UACA,MAAOQ,GACPC,MAAMD,EAAIE,QAtDd"} 2 | 3 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.node.stack: -------------------------------------------------------------------------------- 1 | TypeError: undefined is not a function 2 | at throws6 (/js/thrower.min.js:1:161) 3 | at /js/thrower.min.js:1:488 4 | at forEach ([native code]) 5 | at o (/js/thrower.min.js:1:464) 6 | at throws4 (/js/thrower.min.js:1:276) 7 | at eval (eval at /js/thrower.min.js:1:451) 8 | at t (/js/thrower.min.js:1:420) 9 | at throws2 (/js/thrower.min.js:1:333) 10 | at throws1 (/js/thrower.min.js:1:362) 11 | at throws0 (/js/thrower.min.js:1:391) 12 | at /js/thrower.min.js:1:506 13 | at global code (/js/thrower.min.js:1:534) 14 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.partial.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["foo.js"],"names":[],"mappings":"K,CACC,K,CACC,K"} 2 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.profmap: -------------------------------------------------------------------------------- 1 | JS_0000_xxxxxxxxxxxxxxxxxxxxxx (unknown) 373 2 | JS_0001_xxxxxxxxxxxxxxxxxxxxxx garbage 296 3 | JS_0002_xxxxxxxxxxxxxxxxxxxxxx name 1234 4 | JS_0003_xxxxxxxxxxxxxxxxxxxxxx (unknown) 5678 5 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.ram.stack: -------------------------------------------------------------------------------- 1 | Object.throwSmthInner@seg-1_2.js:6:13 2 | Object.throwSmth@seg-1_1.js:8:18 3 | makeItThrowInner@1.js:15:9 4 | makeItThrow@1.js:11:5 5 | 1.js:6:7 6 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/testfile.stack: -------------------------------------------------------------------------------- 1 | throws6@thrower.min.js:1:161 2 | thrower.min.js:1:488 3 | forEach@[native code] 4 | o@thrower.min.js:1:464 5 | throws4@thrower.min.js:1:276 6 | eval code 7 | eval@[native code] 8 | t@thrower.min.js:1:420 9 | throws2@thrower.min.js:1:333 10 | throws1@thrower.min.js:1:362 11 | throws0@thrower.min.js:1:391 12 | thrower.min.js:1:506 13 | global code@thrower.min.js:1:534 14 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/with-function-map.stack: -------------------------------------------------------------------------------- 1 | Object.throwSmthInner@bundle.js:427:174 2 | Object.throwSmth@bundle.js:426:200 3 | makeItThrowInner@bundle.js:425:311 4 | makeItThrow@bundle.js:425:253 5 | unknown@bundle.js:425:206 6 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/__tests__/__fixtures__/with-ignore-list.stack: -------------------------------------------------------------------------------- 1 | Object.throwSmthInner@bundle.js:427:174 2 | r@bundle.js:2:0 3 | -------------------------------------------------------------------------------- /packages/metro-symbolicate/src/index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /** 3 | * Copyright (c) Meta Platforms, Inc. and affiliates. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | * 8 | * @flow strict-local 9 | * @format 10 | * @oncall react_native 11 | */ 12 | 13 | 'use strict'; 14 | 15 | // $FlowFixMe[unused-promise] 16 | require('./symbolicate.js')().then(code => process.exit(code)); 17 | -------------------------------------------------------------------------------- /packages/metro-transform-plugins/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-transform-plugins/src/__tests__/validateOutputAst.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const t = require('@babel/types'); 14 | 15 | module.exports = function validateOutputAst(ast: BabelNode) { 16 | const seenNodes = new Set(); 17 | t.traverseFast(ast, function enter(node) { 18 | if (seenNodes.has(node)) { 19 | throw new Error( 20 | 'Found a duplicate node in the output, which can cause' + 21 | ' undefined behavior in Babel.', 22 | ); 23 | } 24 | seenNodes.add(node); 25 | }); 26 | }; 27 | -------------------------------------------------------------------------------- /packages/metro-transform-plugins/src/addParamsToDefineCall.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | /** 15 | * Simple way of adding additional parameters to the end of the define calls. 16 | * 17 | * This is used to add extra information to the generaic compiled modules (like 18 | * the dependencyMap object or the list of inverse dependencies). 19 | */ 20 | function addParamsToDefineCall( 21 | code: string, 22 | ...paramsToAdd: Array 23 | ): string { 24 | const index = code.lastIndexOf(')'); 25 | const params = paramsToAdd.map(param => 26 | param !== undefined ? JSON.stringify(param) : 'undefined', 27 | ); 28 | 29 | return code.slice(0, index) + ',' + params.join(',') + code.slice(index); 30 | } 31 | 32 | module.exports = addParamsToDefineCall; 33 | -------------------------------------------------------------------------------- /packages/metro-transform-worker/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro-transform-worker/src/__mocks__/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = function (data, callback) { 14 | callback(null, {}); 15 | }; 16 | -------------------------------------------------------------------------------- /packages/metro-transform-worker/src/utils/getMinifier.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {Minifier} from '../index.js'; 15 | 16 | function getMinifier(minifierPath: string): Minifier { 17 | // Note: minifierPath should be an absolute path OR a module name here! 18 | // The options allow relative paths but they HAVE to be normalized at 19 | // any entry point that accepts them... 20 | try { 21 | // $FlowFixMe TODO t0 cannot do require with literal 22 | return require(minifierPath); 23 | } catch (e) { 24 | throw new Error( 25 | 'A problem occurred while trying to fetch the minifier. Path: "' + 26 | minifierPath + 27 | '", error message: ' + 28 | e.message, 29 | ); 30 | } 31 | } 32 | 33 | module.exports = getMinifier; 34 | -------------------------------------------------------------------------------- /packages/metro/.npmignore: -------------------------------------------------------------------------------- 1 | **/__mocks__/ 2 | **/__tests__/ 3 | /build/ 4 | /src.real/ 5 | /types/ 6 | yarn.lock 7 | -------------------------------------------------------------------------------- /packages/metro/README.md: -------------------------------------------------------------------------------- 1 | # Metro 2 | 3 | 🚇 The JavaScript bundler for React Native. 4 | 5 | - **🚅 Fast**: We aim for sub-second reload cycles, fast startup and quick bundling speeds. 6 | - **⚖️ Scalable**: Works with thousands of modules in a single application. 7 | - **⚛️ Integrated**: Supports every React Native project out of the box. 8 | 9 | This project was previously part of the [react-native](https://github.com/facebook/react-native) repository. In this smaller repository it is easier for the team working on Metro to respond to both issues and pull requests. See [react-native#13976](https://github.com/facebook/react-native/issues/13976) for the initial announcement. 10 | -------------------------------------------------------------------------------- /packages/metro/src/Bundler/__tests__/__snapshots__/util-test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Util generates a local asset for a given descriptor 1`] = ` 4 | "module.exports = require(\\"react-native-module/asset-resolver\\").registerAsset({ 5 | \\"__packager_asset\\": true, 6 | \\"hash\\": \\"9ec9c5721fcd5cc401b4499a0cc8878bc1a18bb5\\", 7 | \\"height\\": 24, 8 | \\"name\\": \\"my-asset\\", 9 | \\"scales\\": [1, 1.5, 2, 3, 4], 10 | \\"type\\": \\"png\\", 11 | \\"width\\": 240 12 | });" 13 | `; 14 | -------------------------------------------------------------------------------- /packages/metro/src/Bundler/__tests__/util-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const {generateAssetCodeFileAst} = require('../util'); 14 | const babelGenerate = require('@babel/generator').default; 15 | 16 | describe('Util', () => { 17 | const assetDescriptor = { 18 | __packager_asset: true, 19 | fileSystemLocation: '/foo/bar', 20 | hash: '9ec9c5721fcd5cc401b4499a0cc8878bc1a18bb5', 21 | height: 24, 22 | name: 'my-asset', 23 | scales: [1, 1.5, 2, 3, 4], 24 | type: 'png', 25 | width: 240, 26 | }; 27 | 28 | test('generates a local asset for a given descriptor', () => { 29 | const {code} = babelGenerate( 30 | generateAssetCodeFileAst( 31 | 'react-native-module/asset-resolver', 32 | assetDescriptor, 33 | ), 34 | ); 35 | 36 | expect(code).toMatchSnapshot(); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /packages/metro/src/DeltaBundler/Serializers/helpers/getInlineSourceMappingURL.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | function getInlineSourceMappingURL(sourceMap: string): string { 15 | const base64 = Buffer.from(sourceMap).toString('base64'); 16 | return `data:application/json;charset=utf-8;base64,${base64}`; 17 | } 18 | 19 | module.exports = getInlineSourceMappingURL; 20 | -------------------------------------------------------------------------------- /packages/metro/src/DeltaBundler/Serializers/sourceMapString.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {Module} from '../types.flow'; 15 | import type {SourceMapGeneratorOptions} from './sourceMapGenerator'; 16 | 17 | const { 18 | sourceMapGenerator, 19 | sourceMapGeneratorNonBlocking, 20 | } = require('./sourceMapGenerator'); 21 | 22 | function sourceMapString( 23 | modules: $ReadOnlyArray>, 24 | options: SourceMapGeneratorOptions, 25 | ): string { 26 | return sourceMapGenerator(modules, options).toString(undefined, { 27 | excludeSource: options.excludeSource, 28 | }); 29 | } 30 | 31 | async function sourceMapStringNonBlocking( 32 | modules: $ReadOnlyArray>, 33 | options: SourceMapGeneratorOptions, 34 | ): Promise { 35 | const generator = await sourceMapGeneratorNonBlocking(modules, options); 36 | return generator.toString(undefined, { 37 | excludeSource: options.excludeSource, 38 | }); 39 | } 40 | 41 | module.exports = { 42 | sourceMapString, 43 | sourceMapStringNonBlocking, 44 | }; 45 | -------------------------------------------------------------------------------- /packages/metro/src/DeltaBundler/Worker.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | /*:: 15 | export type * from './Worker.flow'; 16 | */ 17 | 18 | try { 19 | require('metro-babel-register').unstable_registerForMetroMonorepo(); 20 | } catch {} 21 | 22 | module.exports = require('./Worker.flow'); 23 | -------------------------------------------------------------------------------- /packages/metro/src/DeltaBundler/__fixtures__/hasteImpl.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const fs = require('fs'); 14 | 15 | /** 16 | * Simple hasteImpl that parses @providesModule annotation from JS modules. 17 | */ 18 | module.exports = { 19 | getHasteName(filename: string) { 20 | const matches = fs 21 | .readFileSync(filename, 'utf8') 22 | .match(/@providesModule ([^\n]+)/); 23 | 24 | if (!matches) { 25 | return undefined; 26 | } 27 | 28 | return matches[1]; 29 | }, 30 | getCacheKey() { 31 | return 'hasteImplFixture'; 32 | }, 33 | }; 34 | -------------------------------------------------------------------------------- /packages/metro/src/IncrementalBundler/GraphNotFoundError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {GraphId} from '../lib/getGraphId'; 15 | 16 | class GraphNotFoundError extends Error { 17 | graphId: GraphId; 18 | 19 | constructor(graphId: GraphId) { 20 | super(`The graph \`${graphId}\` was not found.`); 21 | this.graphId = graphId; 22 | } 23 | } 24 | 25 | module.exports = GraphNotFoundError; 26 | -------------------------------------------------------------------------------- /packages/metro/src/IncrementalBundler/ResourceNotFoundError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | class ResourceNotFoundError extends Error { 15 | resourcePath: string; 16 | 17 | constructor(resourcePath: string) { 18 | super(`The resource \`${resourcePath}\` was not found.`); 19 | this.resourcePath = resourcePath; 20 | } 21 | } 22 | 23 | module.exports = ResourceNotFoundError; 24 | -------------------------------------------------------------------------------- /packages/metro/src/IncrementalBundler/RevisionNotFoundError.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {RevisionId} from '../IncrementalBundler'; 15 | 16 | class RevisionNotFoundError extends Error { 17 | revisionId: RevisionId; 18 | 19 | constructor(revisionId: RevisionId) { 20 | super(`The revision \`${revisionId}\` was not found.`); 21 | this.revisionId = revisionId; 22 | } 23 | } 24 | 25 | module.exports = RevisionNotFoundError; 26 | -------------------------------------------------------------------------------- /packages/metro/src/ModuleGraph/worker/__tests__/__snapshots__/collectDependencies-test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`Evaluating static arguments throws on tagged template literals 1`] = `"Invalid call at line 1: require(tag\`left-pad\`)"`; 4 | 5 | exports[`Evaluating static arguments throws template literals with dyncamic interpolations 1`] = `"Invalid call at line 1: require(\`left\${foo}pad\`)"`; 6 | 7 | exports[`Evaluating static arguments throws when requiring non-strings 1`] = `"Invalid call at line 1: require(1)"`; 8 | -------------------------------------------------------------------------------- /packages/metro/src/ModuleGraph/worker/generateImportNames.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const traverse = require('@babel/traverse').default; 14 | const nullthrows = require('nullthrows'); 15 | 16 | /** 17 | * Select unused names for "metroImportDefault" and "metroImportAll", by 18 | * calling "generateUid". 19 | */ 20 | function generateImportNames(ast: BabelNode): { 21 | importAll: string, 22 | importDefault: string, 23 | } { 24 | let importDefault; 25 | let importAll; 26 | 27 | traverse(ast, { 28 | Program(path) { 29 | importAll = path.scope.generateUid('$$_IMPORT_ALL'); 30 | importDefault = path.scope.generateUid('$$_IMPORT_DEFAULT'); 31 | 32 | path.stop(); 33 | }, 34 | }); 35 | 36 | return { 37 | importAll: nullthrows(importAll), 38 | importDefault: nullthrows(importDefault), 39 | }; 40 | } 41 | 42 | module.exports = generateImportNames; 43 | -------------------------------------------------------------------------------- /packages/metro/src/__mocks__/debug.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | interface DebugFN { 14 | (...args: Array): void; 15 | enabled: () => boolean; 16 | } 17 | 18 | function debug(namespace: string): DebugFN { 19 | const fn = (...args: Array) => {}; 20 | fn.enabled = () => false; 21 | return fn; 22 | } 23 | 24 | debug.enable = (match: string) => {}; 25 | debug.disable = () => {}; 26 | 27 | module.exports = debug; 28 | -------------------------------------------------------------------------------- /packages/metro/src/cli-utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const fs = require('fs'); 15 | 16 | exports.watchFile = async function ( 17 | filename: string, 18 | callback: () => any, 19 | ): Promise { 20 | fs.watchFile(filename, () => { 21 | callback(); 22 | }); 23 | 24 | await callback(); 25 | }; 26 | 27 | exports.makeAsyncCommand = 28 | (command: (argv: T) => Promise): ((argv: T) => void) => 29 | (argv: T) => { 30 | Promise.resolve(command(argv)).catch(error => { 31 | console.error(error.stack); 32 | process.exitCode = 1; 33 | }); 34 | }; 35 | -------------------------------------------------------------------------------- /packages/metro/src/cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | /** 3 | * Copyright (c) Meta Platforms, Inc. and affiliates. 4 | * 5 | * This source code is licensed under the MIT license found in the 6 | * LICENSE file in the root directory of this source tree. 7 | * 8 | * @flow strict-local 9 | * @format 10 | * @oncall react_native 11 | */ 12 | 13 | 'use strict'; 14 | 15 | try { 16 | // $FlowFixMe[untyped-import] 17 | require('metro-babel-register').unstable_registerForMetroMonorepo(); 18 | } catch {} 19 | 20 | const {attachMetroCli} = require('./index'); 21 | const yargs = require('yargs'); 22 | 23 | // $FlowFixMe[unused-promise] 24 | attachMetroCli(yargs.demandCommand(1)).argv; 25 | -------------------------------------------------------------------------------- /packages/metro/src/cli/parseKeyValueParamArray.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | export default function coerceKeyValueArray( 13 | keyValueArray: $ReadOnlyArray, 14 | ): { 15 | [key: string]: string, 16 | __proto__: null, 17 | } { 18 | const result: {[key: string]: string, __proto__: null} = Object.create(null); 19 | for (const item of keyValueArray) { 20 | if (item.indexOf('=') === -1) { 21 | throw new Error('Expected parameter to include "=" but found: ' + item); 22 | } 23 | if (item.indexOf('&') !== -1) { 24 | throw new Error('Parameter cannot include "&" but found: ' + item); 25 | } 26 | const params = new URLSearchParams(item); 27 | params.forEach((value, key) => { 28 | // $FlowExpectedError[prop-missing] 29 | result[key] = value; 30 | }); 31 | } 32 | return result; 33 | } 34 | -------------------------------------------------------------------------------- /packages/metro/src/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | /*:: 15 | export type * from './index.flow'; 16 | */ 17 | 18 | try { 19 | require('metro-babel-register').unstable_registerForMetroMonorepo(); 20 | } catch {} 21 | 22 | module.exports = require('./index.flow'); 23 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/__tests__/__snapshots__/build-test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`builds a simple bundle 1`] = ` 4 | Object { 5 | "Bar": Object { 6 | "foo": "foo", 7 | "type": "bar", 8 | }, 9 | "Foo": Object { 10 | "asset": Object { 11 | "__packager_asset": true, 12 | "hash": "77d45c1f7fa73c0f6c444a830dc42f67", 13 | "height": 8, 14 | "httpServerLocation": "/assets", 15 | "name": "test", 16 | "scales": Array [ 17 | 1, 18 | ], 19 | "type": "png", 20 | "width": 8, 21 | }, 22 | "type": "foo", 23 | }, 24 | "TypeScript": Object { 25 | "B": [Function], 26 | "test": true, 27 | "type": "TypeScript", 28 | }, 29 | } 30 | `; 31 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/__tests__/__snapshots__/rambundle-test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`builds and executes a RAM bundle 1`] = ` 4 | Object { 5 | "Bar": Object { 6 | "foo": "foo", 7 | "type": "bar", 8 | }, 9 | "Foo": Object { 10 | "asset": Object { 11 | "__packager_asset": true, 12 | "hash": "77d45c1f7fa73c0f6c444a830dc42f67", 13 | "height": 8, 14 | "httpServerLocation": "/assets", 15 | "name": "test", 16 | "scales": Array [ 17 | 1, 18 | ], 19 | "type": "png", 20 | "width": 8, 21 | }, 22 | "type": "foo", 23 | }, 24 | "TypeScript": Object { 25 | "B": [Function], 26 | "test": true, 27 | "type": "TypeScript", 28 | }, 29 | } 30 | `; 31 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/__tests__/import-export-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const Metro = require('../../..'); 14 | const execBundle = require('../execBundle'); 15 | 16 | jest.unmock('cosmiconfig'); 17 | 18 | jest.setTimeout(30 * 1000); 19 | 20 | test('builds a simple bundle', async () => { 21 | const config = await Metro.loadConfig({ 22 | config: require.resolve('../metro.config.js'), 23 | }); 24 | 25 | const result = await Metro.runBuild(config, { 26 | entry: 'import-export/index.js', 27 | }); 28 | 29 | const object = execBundle(result.code); 30 | const cjs = await object.asyncImportCJS; 31 | 32 | expect(object).toMatchSnapshot(); 33 | expect(cjs).toEqual(expect.objectContaining(cjs.default)); 34 | 35 | await expect(object.asyncImportCJS).resolves.toMatchSnapshot(); 36 | await expect(object.asyncImportESM).resolves.toMatchSnapshot(); 37 | }); 38 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/AssetRegistry.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = { 14 | registerAsset(data: mixed): mixed { 15 | return data; 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/Bar.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const Foo = require('./Foo'); 14 | 15 | module.exports = {type: 'bar', foo: Foo.type}; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/ErrorBundle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | // Add a random require to fill the bundle with some sourcecode. 14 | require('./AssetRegistry'); 15 | 16 | const calcSum = (value: string) => { 17 | // some random function 18 | const error = new Error('SOURCEMAP: value: ' + value); 19 | 20 | return error; 21 | }; 22 | 23 | module.exports = (calcSum('anything'): Error); 24 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/Foo.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const asset = require('./test.png'); 14 | 15 | module.exports = {type: 'foo', asset}; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/TestBigInt.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | 'use strict'; 12 | 13 | // $FlowFixMe[signature-verification-failure] 14 | var a = 2n; 15 | // $FlowFixMe[signature-verification-failure] 16 | var b = 3n; 17 | module.exports = a ** b; 18 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/TestBundle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const Bar = require('./Bar'); 14 | const Foo = require('./Foo'); 15 | // $FlowFixMe: Flow doesn't understand TypeScript 16 | const TypeScript = require('./TypeScript'); 17 | 18 | Object.keys({...Bar}); 19 | 20 | module.exports = {Foo, Bar, TypeScript}; 21 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/TestPolyfill.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = global.POLYFILL_IS_INJECTED; 14 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/TypeScript.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | export const type = 'TypeScript' as string 9 | export const test = true as boolean 10 | 11 | // Exporting default interface was broken before Babel 7.0.0-beta.56 12 | export default interface A {} 13 | 14 | export class B { 15 | constructor(public name: string){} 16 | } 17 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/build-errors/cannot-resolve-import.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | // $FlowExpectedError[cannot-resolve-module] 12 | import type DoesNotExistT from './does-not-exist'; 13 | 14 | // $FlowExpectedError[cannot-resolve-module] 15 | import DoesNotExist from './does-not-exist'; 16 | 17 | global.x = (DoesNotExist: DoesNotExistT); 18 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import-with-escapes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | /* eslint-disable no-unused-vars */ 12 | 13 | // $FlowExpectedError[cannot-resolve-module] 14 | import type DoesNotExistT from './does-not\'"-exist'; 15 | 16 | import { 17 | aaaaaaaaaa, 18 | bbbbbbbbbb, 19 | cccccccccc, 20 | dddddddddd, 21 | eeeeeeeeee, 22 | ffffffffff, 23 | gggggggggg, 24 | hhhhhhhhhh, 25 | iiiiiiiiii, 26 | // $FlowExpectedError[cannot-resolve-module] 27 | } from './does-not\'"-exist'; 28 | 29 | global.x = (aaaaaaaaaa: DoesNotExistT); 30 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/build-errors/cannot-resolve-multi-line-import.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | /* eslint-disable no-unused-vars */ 12 | 13 | // $FlowExpectedError[cannot-resolve-module] 14 | import type DoesNotExistT from './does-not-exist'; 15 | 16 | import { 17 | aaaaaaaaaa, 18 | bbbbbbbbbb, 19 | cccccccccc, 20 | dddddddddd, 21 | eeeeeeeeee, 22 | ffffffffff, 23 | gggggggggg, 24 | hhhhhhhhhh, 25 | iiiiiiiiii, 26 | // $FlowExpectedError[cannot-resolve-module] 27 | } from './does-not-exist'; 28 | 29 | global.x = (aaaaaaaaaa: DoesNotExistT); 30 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require-with-embedded-comment.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | // $FlowExpectedError[cannot-resolve-module] 12 | import type DoesNotExistT from './foo'; 13 | 14 | // $FlowExpectedError[cannot-resolve-module] 15 | const DoesNotExist = require('./foo' /* ./foo */); 16 | 17 | global.x = (DoesNotExist: DoesNotExistT); 18 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/build-errors/cannot-resolve-require.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | // $FlowExpectedError[cannot-resolve-module] 12 | import type DoesNotExistT from './does-not-exist'; 13 | 14 | // $FlowExpectedError[cannot-resolve-module] 15 | const DoesNotExist = require('./does-not-exist'); 16 | 17 | global.x = (DoesNotExist: DoesNotExistT); 18 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/build-errors/cannot-resolve-specifier-with-escapes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | /* eslint-disable no-unused-vars */ 12 | 13 | // $FlowExpectedError[cannot-resolve-module] 14 | import type DoesNotExistT from './does-not\'"-exist'; 15 | 16 | // $FlowExpectedError[cannot-resolve-module] 17 | import {DoesNotExist} from './does-not\'"-exist'; 18 | 19 | global.x = (DoesNotExist: DoesNotExistT); 20 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-import.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | // $FlowExpectedError[cannot-resolve-module] 12 | import type DoesNotExistT from './does-not-exist'; 13 | 14 | // $FlowExpectedError[cannot-resolve-module] 15 | import DoesNotExist from './does-not-exist'; 16 | 17 | global.x = (DoesNotExist: DoesNotExistT); 18 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/build-errors/inline-requires-cannot-resolve-require.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | // $FlowExpectedError[cannot-resolve-module] 12 | import type DoesNotExistT from './does-not-exist'; 13 | 14 | // $FlowExpectedError[cannot-resolve-module] 15 | const DoesNotExist = require('./does-not-exist'); 16 | 17 | global.x = (DoesNotExist: DoesNotExistT); 18 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/excluded_from_file_map.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | export default '/* secret */'; 12 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-1.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | export default 'export-1: DEFAULT'; 14 | 15 | export const foo = 'export-1: FOO'; 16 | 17 | export function myFunction(): string { 18 | return 'export-1: MY_FUNCTION'; 19 | } 20 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-2.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | export default 'export-2: DEFAULT'; 14 | 15 | export const foo = 'export-2: FOO'; 16 | 17 | export function myFunction(): string { 18 | return 'export-2: MY_FUNCTION'; 19 | } 20 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-3.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | export default 'export-3: DEFAULT'; 14 | 15 | export const foo = 'export-3: FOO'; 16 | 17 | export function myFunction(): string { 18 | return 'export-3: MY_FUNCTION'; 19 | } 20 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-4.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | export default 'export-4: DEFAULT'; 14 | 15 | export const foo = 'export-4: FOO'; 16 | 17 | export function myFunction(): string { 18 | return 'export-4: MY_FUNCTION'; 19 | } 20 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-5.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = { 14 | foo: 'export-5: FOO', 15 | }; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-6.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | export default 'export-6: DEFAULT'; 14 | 15 | export const foo = 'export-6: FOO'; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-7.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = { 14 | foo: 'export-7: FOO', 15 | }; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-8.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | export default 'export-8: DEFAULT'; 14 | 15 | export const foo = 'export-8: FOO'; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-null.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | export default null; 14 | 15 | export const foo = 'export-null: FOO'; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/export-primitive-default.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | export default 'export-primitive-default: DEFAULT'; 14 | 15 | export const foo = 'export-primitive-default: FOO'; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/import-export/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | export type RequireWithUnstableImportMaybeSync = { 12 | (id: string | number): mixed, 13 | unstable_importMaybeSync: (id: string) => mixed, 14 | }; 15 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/loadBundleAsyncForTest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | 'use strict'; 12 | 13 | declare var __METRO_GLOBAL_PREFIX__: string; 14 | declare var __DOWNLOAD_AND_EXEC_FOR_TESTS__: (path: string) => Promise; 15 | 16 | const key = `${global.__METRO_GLOBAL_PREFIX__ ?? ''}__loadBundleAsync`; 17 | 18 | global[key] = async function loadBundleAsyncForTest(path: string) { 19 | await __DOWNLOAD_AND_EXEC_FOR_TESTS__(path); 20 | }; 21 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/not_a_source_file.xyz: -------------------------------------------------------------------------------- 1 | /* secret */ 2 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/polyfill.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | // Inject something into the global object so we can verify that this file 14 | // is indeed evaluated. 15 | global.POLYFILL_IS_INJECTED = 'POLYFILL_IS_INJECTED'; 16 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/conflict.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithContext} from './utils'; 12 | 13 | import {copyContextToObject} from './utils'; 14 | 15 | const normalModule = require('./subdir-conflict'); 16 | 17 | declare var require: RequireWithContext; 18 | const contextModule = require.context<$FlowFixMe>('./subdir-conflict'); 19 | 20 | function main() { 21 | return { 22 | normalModule, 23 | contextModule: copyContextToObject(contextModule), 24 | }; 25 | } 26 | 27 | module.exports = (main(): mixed); 28 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/empty.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithContext} from './utils'; 12 | 13 | declare var require: RequireWithContext; 14 | 15 | const empty = require.context<$FlowFixMe>('./no-such-dir'); 16 | 17 | function main() { 18 | try { 19 | empty('./no-such-file.js'); 20 | } catch (e) { 21 | return {error: {message: e.message, code: e.code}}; 22 | } 23 | return null; 24 | } 25 | 26 | module.exports = (main(): mixed); 27 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/matching.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithContext} from './utils'; 12 | 13 | declare var require: RequireWithContext; 14 | 15 | const ab = require.context<$FlowFixMe>('./subdir', false, /\/(a|b)\.js$/); 16 | const abc = require.context<$FlowFixMe>('./subdir', false); 17 | const abcd = require.context<$FlowFixMe>('./subdir', true); 18 | 19 | function main() { 20 | return { 21 | ab: ab.keys(), 22 | abc: abc.keys(), 23 | abcd: abcd.keys(), 24 | }; 25 | } 26 | 27 | module.exports = (main(): mixed); 28 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/mode-eager.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithContext} from './utils'; 12 | 13 | import {awaitProperties, copyContextToObject} from './utils'; 14 | 15 | declare var require: RequireWithContext; 16 | 17 | function main() { 18 | return awaitProperties<$FlowFixMe>( 19 | copyContextToObject<$FlowFixMe>( 20 | require.context('./subdir', undefined, undefined, 'eager'), 21 | ), 22 | ); 23 | } 24 | 25 | module.exports = (main(): mixed); 26 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy-once.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithContext} from './utils'; 12 | 13 | import {awaitProperties, copyContextToObject} from './utils'; 14 | 15 | declare var require: RequireWithContext; 16 | 17 | function main() { 18 | return awaitProperties<$FlowFixMe>( 19 | copyContextToObject<$FlowFixMe>( 20 | require.context('./subdir', undefined, undefined, 'lazy-once'), 21 | ), 22 | ); 23 | } 24 | 25 | module.exports = (main(): mixed); 26 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/mode-lazy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithContext} from './utils'; 12 | 13 | import {awaitProperties, copyContextToObject} from './utils'; 14 | 15 | declare var require: RequireWithContext; 16 | 17 | function main() { 18 | return awaitProperties<$FlowFixMe>( 19 | copyContextToObject<$FlowFixMe>( 20 | require.context('./subdir', undefined, undefined, 'lazy'), 21 | ), 22 | ); 23 | } 24 | 25 | module.exports = (main(): mixed); 26 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/mode-sync.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithContext} from './utils'; 12 | 13 | import {copyContextToObject} from './utils'; 14 | 15 | declare var require: RequireWithContext; 16 | 17 | function main(): mixed { 18 | return copyContextToObject( 19 | // $FlowFixMe[underconstrained-implicit-instantiation] 20 | require.context('./subdir', undefined, undefined, 'sync'), 21 | ); 22 | } 23 | 24 | module.exports = (main(): mixed); 25 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/subdir-conflict/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | module.exports = 'contents of subdir-conflict/index.js'; 12 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/subdir/a.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | module.exports = 'a'; 12 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/subdir/b.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | export default 'b'; 12 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/subdir/c.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | module.exports = 'c'; 12 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/subdir/nested/d.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | module.exports = 'd'; 12 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-context/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow 9 | */ 10 | 11 | type ContextModule = { 12 | (key: string): T, 13 | keys(): Array, 14 | }; 15 | 16 | export type RequireWithContext = { 17 | (id: string): any, 18 | resolve: (id: string, options?: {paths?: Array, ...}) => string, 19 | cache: any, 20 | main: typeof module, 21 | context( 22 | name: string, 23 | recursive?: boolean, 24 | filter?: RegExp, 25 | mode?: 'sync' | 'eager' | 'lazy' | 'lazy-once', 26 | ): ContextModule, 27 | }; 28 | 29 | export function copyContextToObject(ctx: ContextModule): { 30 | [key: string]: T, 31 | } { 32 | return Object.fromEntries(ctx.keys().map(key => [key, ctx(key)])); 33 | } 34 | 35 | export function awaitProperties( 36 | obj: $ReadOnly<{[key: string]: Promise}>, 37 | ): Promise<{[key: string]: T}> { 38 | const result: {[string]: T} = {}; 39 | return Promise.all( 40 | Object.keys(obj).map(key => { 41 | return obj[key].then(value => (result[key] = value)); 42 | }), 43 | ).then(() => result); 44 | } 45 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-resolveWeak/import-and-resolveWeak.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithResolveWeak} from './utils'; 12 | 13 | declare var require: RequireWithResolveWeak; 14 | 15 | async function main() { 16 | const moduleId = require.resolveWeak('./subdir/counter-module'); 17 | 18 | // Require the module statically via its path, spelled slightly differently 19 | (await import('./subdir/counter-module.js')).increment(); 20 | 21 | const dynamicRequire = require; 22 | 23 | // Require the module dynamically via its ID 24 | const timesIncremented = dynamicRequire(moduleId).increment(); 25 | 26 | return { 27 | moduleId, 28 | // Should be 2, proving there's just one module instance 29 | timesIncremented, 30 | }; 31 | } 32 | 33 | module.exports = (main(): mixed); 34 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-resolveWeak/multiple.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithResolveWeak} from './utils'; 12 | 13 | declare var require: RequireWithResolveWeak; 14 | 15 | async function main() { 16 | return { 17 | counterModuleId1: require.resolveWeak('./subdir/counter-module'), 18 | counterModuleId2: require.resolveWeak('./subdir/counter-module.js'), 19 | throwingModuleId: require.resolveWeak('./subdir/throwing-module.js'), 20 | }; 21 | } 22 | 23 | module.exports = (main(): mixed); 24 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-resolveWeak/never-required.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithResolveWeak} from './utils'; 12 | 13 | declare var require: RequireWithResolveWeak; 14 | 15 | function main() { 16 | return { 17 | moduleId: require.resolveWeak('./subdir/throwing-module'), 18 | }; 19 | } 20 | 21 | module.exports = (main(): mixed); 22 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-resolveWeak/require-and-resolveWeak.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | import type {RequireWithResolveWeak} from './utils'; 12 | 13 | declare var require: RequireWithResolveWeak; 14 | 15 | function main() { 16 | const moduleId = require.resolveWeak('./subdir/counter-module'); 17 | 18 | const dynamicRequire = require; 19 | 20 | // Require the module dynamically via its ID 21 | dynamicRequire(moduleId).increment(); 22 | 23 | // Require the module statically via its path, spelled slightly differently 24 | const timesIncremented = require('./subdir/counter-module.js').increment(); 25 | 26 | return { 27 | moduleId, 28 | // Should be 2, proving there's just one module instance 29 | timesIncremented, 30 | }; 31 | } 32 | 33 | module.exports = (main(): mixed); 34 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-resolveWeak/subdir/counter-module.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | let count: number = 0; 12 | 13 | module.exports = { 14 | increment(): number { 15 | ++count; 16 | return count; 17 | }, 18 | }; 19 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-resolveWeak/subdir/throwing-module.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | */ 10 | 11 | throw new Error('This module cannot be evaluated.'); 12 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/require-resolveWeak/utils.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow 9 | */ 10 | 11 | export type RequireWithResolveWeak = { 12 | (id: string | number): any, 13 | resolveWeak: (id: string) => string | number, 14 | }; 15 | -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/basic_bundle/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/metro/15fef8ebcf5ae0a13e7f0925a22d4211dde95e02/packages/metro/src/integration_tests/basic_bundle/test.png -------------------------------------------------------------------------------- /packages/metro/src/integration_tests/execBundle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const vm = require('vm'); 15 | 16 | module.exports = function execBundle(code: string, context: any = {}): mixed { 17 | if (vm.isContext(context)) { 18 | return vm.runInContext(code, context); 19 | } 20 | return vm.runInNewContext(code, context); 21 | }; 22 | -------------------------------------------------------------------------------- /packages/metro/src/lib/__mocks__/GlobalTransformCache.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | function get(): null { 15 | return null; 16 | } 17 | 18 | module.exports = {get}; 19 | -------------------------------------------------------------------------------- /packages/metro/src/lib/__mocks__/declareOpts.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = function (declared: Object): (opts: any) => any { 14 | return function (opts: Object) { 15 | for (var p in declared) { 16 | if (opts[p] == null && declared[p].default != null) { 17 | opts[p] = declared[p].default; 18 | } 19 | } 20 | return opts; 21 | }; 22 | }; 23 | -------------------------------------------------------------------------------- /packages/metro/src/lib/__mocks__/getAbsolutePath.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const path = require('path'); 15 | 16 | module.exports = (file: string, roots: $ReadOnlyArray): string => 17 | path.resolve(roots[0], file); 18 | -------------------------------------------------------------------------------- /packages/metro/src/lib/__tests__/formatBundlingError-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | */ 10 | 11 | import {UnableToResolveError} from '../../node-haste/DependencyGraph/ModuleResolution'; 12 | import formatBundlingError from '../formatBundlingError'; 13 | 14 | describe('formatBundlingError', () => { 15 | test('UnableToResolveError', () => { 16 | expect( 17 | formatBundlingError( 18 | new UnableToResolveError('/origin/module.js', 'target', 'message'), 19 | ), 20 | ).toMatchObject({ 21 | name: 'Error', 22 | type: 'UnableToResolveError', 23 | message: 24 | 'Unable to resolve module target from /origin/module.js: message', 25 | originModulePath: '/origin/module.js', 26 | targetModuleName: 'target', 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/metro/src/lib/countLines.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const newline = /\r\n?|\n|\u2028|\u2029/g; 15 | 16 | const countLines = (string: string): number => 17 | (string.match(newline) || []).length + 1; 18 | 19 | module.exports = countLines; 20 | -------------------------------------------------------------------------------- /packages/metro/src/lib/createModuleIdFactory.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | function createModuleIdFactory(): (path: string) => number { 15 | const fileToIdMap: Map = new Map(); 16 | let nextId = 0; 17 | return (path: string) => { 18 | let id = fileToIdMap.get(path); 19 | if (typeof id !== 'number') { 20 | id = nextId++; 21 | fileToIdMap.set(path, id); 22 | } 23 | return id; 24 | }; 25 | } 26 | 27 | module.exports = createModuleIdFactory; 28 | -------------------------------------------------------------------------------- /packages/metro/src/lib/getMaxWorkers.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const os = require('os'); 15 | 16 | module.exports = (workers: ?number): number => { 17 | // $FlowFixMe[prop-missing] Missing Flow lib def for availableParallelism 18 | const cores = os.availableParallelism(); 19 | return typeof workers === 'number' && Number.isInteger(workers) 20 | ? Math.min(cores, workers > 0 ? workers : 1) 21 | : Math.max(1, Math.ceil(cores * (0.5 + 0.5 * Math.exp(-cores * 0.07)) - 1)); 22 | }; 23 | -------------------------------------------------------------------------------- /packages/metro/src/lib/parseCustomResolverOptions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {CustomResolverOptions} from '../../../metro-resolver/src/types'; 15 | 16 | const nullthrows = require('nullthrows'); 17 | 18 | const PREFIX = 'resolver.'; 19 | 20 | module.exports = function parseCustomResolverOptions(urlObj: { 21 | +query?: {[string]: string, ...}, 22 | ... 23 | }): CustomResolverOptions { 24 | const customResolverOptions: { 25 | __proto__: null, 26 | [string]: mixed, 27 | ... 28 | } = Object.create(null); 29 | const query = nullthrows(urlObj.query); 30 | 31 | Object.keys(query).forEach((key: string) => { 32 | if (key.startsWith(PREFIX)) { 33 | customResolverOptions[key.substr(PREFIX.length)] = query[key]; 34 | } 35 | }); 36 | 37 | return customResolverOptions; 38 | }; 39 | -------------------------------------------------------------------------------- /packages/metro/src/lib/parseCustomTransformOptions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {CustomTransformOptions} from 'metro-transform-worker'; 15 | 16 | const nullthrows = require('nullthrows'); 17 | 18 | const PREFIX = 'transform.'; 19 | 20 | module.exports = function parseCustomTransformOptions(urlObj: { 21 | +query?: {[string]: string, ...}, 22 | ... 23 | }): CustomTransformOptions { 24 | const customTransformOptions = Object.create(null); 25 | const query = nullthrows(urlObj.query); 26 | 27 | Object.keys(query).forEach((key: string) => { 28 | if (key.startsWith(PREFIX)) { 29 | // $FlowFixMe[prop-missing] 30 | customTransformOptions[key.substr(PREFIX.length)] = query[key]; 31 | } 32 | }); 33 | 34 | return customTransformOptions; 35 | }; 36 | -------------------------------------------------------------------------------- /packages/metro/src/lib/relativizeSourceMap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {MixedSourceMap} from 'metro-source-map'; 15 | 16 | const path = require('path'); 17 | 18 | function relativizeSourceMapInline( 19 | sourceMap: MixedSourceMap, 20 | sourcesRoot: string, 21 | ): void { 22 | // eslint-disable-next-line lint/strictly-null 23 | if (sourceMap.mappings === undefined) { 24 | for (let i = 0; i < sourceMap.sections.length; i++) { 25 | relativizeSourceMapInline(sourceMap.sections[i].map, sourcesRoot); 26 | } 27 | } else { 28 | for (let i = 0; i < sourceMap.sources.length; i++) { 29 | sourceMap.sources[i] = path.relative(sourcesRoot, sourceMap.sources[i]); 30 | } 31 | } 32 | } 33 | 34 | module.exports = relativizeSourceMapInline; 35 | -------------------------------------------------------------------------------- /packages/metro/src/node-haste/Module.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type ModuleCache from './ModuleCache'; 15 | import type Package from './Package'; 16 | 17 | import path from 'path'; 18 | 19 | class Module { 20 | path: string; 21 | 22 | _moduleCache: ModuleCache; 23 | _sourceCode: ?string; 24 | 25 | constructor(file: string, moduleCache: ModuleCache) { 26 | if (!path.isAbsolute(file)) { 27 | throw new Error('Expected file to be absolute path but got ' + file); 28 | } 29 | 30 | this.path = file; 31 | this._moduleCache = moduleCache; 32 | } 33 | 34 | getPackage(): ?Package { 35 | return this._moduleCache.getPackageForModule(this)?.pkg; 36 | } 37 | 38 | invalidate() {} 39 | } 40 | 41 | module.exports = Module; 42 | -------------------------------------------------------------------------------- /packages/metro/src/node-haste/Package.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | import type {PackageJson} from 'metro-resolver/src/types'; 15 | 16 | const fs = require('fs'); 17 | const path = require('path'); 18 | 19 | class Package { 20 | path: string; 21 | 22 | _root: string; 23 | _content: ?PackageJson; 24 | 25 | constructor({file}: {file: string, ...}) { 26 | this.path = path.resolve(file); 27 | this._root = path.dirname(this.path); 28 | this._content = null; 29 | } 30 | 31 | invalidate() { 32 | this._content = null; 33 | } 34 | 35 | read(): PackageJson { 36 | if (this._content == null) { 37 | this._content = JSON.parse(fs.readFileSync(this.path, 'utf8')); 38 | } 39 | return this._content; 40 | } 41 | } 42 | 43 | module.exports = Package; 44 | -------------------------------------------------------------------------------- /packages/metro/src/node-haste/__mocks__/graceful-fs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict 9 | */ 10 | 11 | 'use strict'; 12 | 13 | module.exports = require('fs'); 14 | -------------------------------------------------------------------------------- /packages/metro/src/node-haste/__tests__/Module-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const Module = require('../Module'); 14 | const ModuleCache = require('../ModuleCache'); 15 | 16 | describe('Module', () => { 17 | let moduleCache; 18 | let module; 19 | 20 | beforeEach(() => { 21 | moduleCache = new ModuleCache({}); 22 | 23 | module = new Module('/root/to/file.js', moduleCache); 24 | }); 25 | 26 | test('Returns the correct values for many properties and methods', () => { 27 | expect(module.path).toBe('/root/to/file.js'); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/metro/src/shared/output/RamBundle/magic-number.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | module.exports = 0xfb0bd1e5; 15 | -------------------------------------------------------------------------------- /packages/metro/src/shared/output/RamBundle/write-sourcemap.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const writeFile = require('../writeFile'); 15 | 16 | function writeSourcemap( 17 | fileName: string, 18 | contents: string, 19 | log: (...args: Array) => void, 20 | ): Promise { 21 | if (!fileName) { 22 | return Promise.resolve(); 23 | } 24 | log('Writing sourcemap output to:', fileName); 25 | const writeMap = writeFile(fileName, contents); 26 | // $FlowFixMe[unused-promise] 27 | writeMap.then(() => log('Done writing sourcemap output')); 28 | return writeMap; 29 | } 30 | 31 | module.exports = writeSourcemap; 32 | -------------------------------------------------------------------------------- /packages/metro/src/shared/output/__tests__/__snapshots__/meta-test.js.snap: -------------------------------------------------------------------------------- 1 | // Jest Snapshot v1, https://goo.gl/fbAQLP 2 | 3 | exports[`exports the block list creator 1`] = ` 4 | Object { 5 | "data": Array [ 6 | 56, 7 | 131, 8 | 13, 9 | 89, 10 | 254, 11 | 63, 12 | 108, 13 | 210, 14 | 213, 15 | 112, 16 | 53, 17 | 173, 18 | 11, 19 | 21, 20 | 31, 21 | 184, 22 | 133, 23 | 221, 24 | 114, 25 | 86, 26 | 1, 27 | ], 28 | "type": "Buffer", 29 | } 30 | `; 31 | -------------------------------------------------------------------------------- /packages/metro/src/shared/output/__tests__/meta-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const meta = require('../meta'); 15 | 16 | test('exports the block list creator', () => { 17 | expect(meta('some formatted code', 'utf8')).toMatchSnapshot(); 18 | }); 19 | -------------------------------------------------------------------------------- /packages/metro/src/shared/output/bundle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | /*:: 15 | export type * from './bundle.flow'; 16 | */ 17 | 18 | try { 19 | require('metro-babel-register').unstable_registerForMetroMonorepo(); 20 | } catch {} 21 | 22 | module.exports = require('./bundle.flow'); 23 | -------------------------------------------------------------------------------- /packages/metro/src/shared/output/unbundle.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | /* This is for retro-compatibility of React Native with older versions of 15 | * Metro. Use the `RamBundle` module directly. */ 16 | module.exports = require('./RamBundle'); 17 | -------------------------------------------------------------------------------- /packages/metro/src/shared/output/writeFile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const fs = require('fs'); 15 | const throat = require('throat'); 16 | 17 | const writeFile: typeof fs.promises.writeFile = throat( 18 | 128, 19 | fs.promises.writeFile, 20 | ); 21 | 22 | module.exports = writeFile; 23 | -------------------------------------------------------------------------------- /packages/metro/types/Asset.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export interface AssetDataWithoutFiles { 12 | readonly __packager_asset: boolean; 13 | readonly fileSystemLocation: string; 14 | readonly hash: string; 15 | readonly height?: number; 16 | readonly httpServerLocation: string; 17 | readonly name: string; 18 | readonly scales: number[]; 19 | readonly type: string; 20 | readonly width?: number; 21 | } 22 | 23 | export interface AssetData extends AssetDataWithoutFiles { 24 | readonly files: string[]; 25 | } 26 | -------------------------------------------------------------------------------- /packages/metro/types/Bundler.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type {TransformResultWithSource} from './DeltaBundler'; 12 | import type {TransformOptions} from './DeltaBundler/Worker'; 13 | import type DependencyGraph from './node-haste/DependencyGraph'; 14 | import type {EventEmitter} from 'events'; 15 | import type {ConfigT} from 'metro-config'; 16 | 17 | export interface BundlerOptions { 18 | readonly hasReducedPerformance?: boolean; 19 | readonly watch?: boolean; 20 | } 21 | 22 | export default class Bundler { 23 | constructor(config: ConfigT, options?: BundlerOptions); 24 | 25 | getWatcher(): EventEmitter; 26 | 27 | end(): Promise; 28 | 29 | getDependencyGraph(): Promise; 30 | 31 | transformFile( 32 | filePath: string, 33 | transformOptions: TransformOptions, 34 | /** Optionally provide the file contents, this can be used to provide virtual contents for a file. */ 35 | fileBuffer?: Buffer, 36 | ): Promise>; 37 | 38 | ready(): Promise; 39 | } 40 | -------------------------------------------------------------------------------- /packages/metro/types/DeltaBundler/Graph.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type { 12 | Dependencies, 13 | GraphInputOptions, 14 | MixedOutput, 15 | Module, 16 | Options, 17 | TransformInputOptions, 18 | } from './types'; 19 | 20 | export interface Result { 21 | added: Map>; 22 | modified: Map>; 23 | deleted: Set; 24 | } 25 | 26 | export class Graph { 27 | entryPoints: ReadonlySet; 28 | transformOptions: TransformInputOptions; 29 | dependencies: Dependencies; 30 | constructor(options: GraphInputOptions); 31 | traverseDependencies( 32 | paths: ReadonlyArray, 33 | options: Options, 34 | ): Promise>; 35 | initialTraverseDependencies(options: Options): Promise>; 36 | markModifiedContextModules( 37 | filePath: string, 38 | modifiedPaths: Set, 39 | ): void; 40 | } 41 | -------------------------------------------------------------------------------- /packages/metro/types/DeltaBundler/Serializers/getRamBundleInfo.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import {ModuleTransportLike} from '../../shared/types'; 12 | 13 | export interface RamBundleInfo { 14 | getDependencies: (filePath: string) => Set; 15 | startupModules: Readonly; 16 | lazyModules: Readonly; 17 | groups: Map>; 18 | } 19 | -------------------------------------------------------------------------------- /packages/metro/types/DeltaBundler/Worker.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type {TransformResult} from './types'; 12 | import type { 13 | JsTransformerConfig, 14 | JsTransformOptions, 15 | } from 'metro-transform-worker'; 16 | 17 | type LogEntry = unknown; 18 | 19 | export type TransformOptions = JsTransformOptions; 20 | 21 | declare function transform( 22 | filename: string, 23 | transformOptions: JsTransformOptions, 24 | projectRoot: string, 25 | transformerConfig: TransformerConfig, 26 | fileBuffer?: Buffer, 27 | ): Promise; 28 | 29 | export interface Worker { 30 | readonly transform: typeof transform; 31 | } 32 | 33 | export interface TransformerConfig { 34 | transformerPath: string; 35 | transformerConfig: JsTransformerConfig; 36 | } 37 | 38 | interface Data { 39 | readonly result: TransformResult; 40 | readonly sha1: string; 41 | readonly transformFileStartLogEntry: LogEntry; 42 | readonly transformFileEndLogEntry: LogEntry; 43 | } 44 | 45 | declare const worker: Worker; 46 | 47 | export default worker; 48 | -------------------------------------------------------------------------------- /packages/metro/types/ModuleGraph/worker/collectDependencies.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export type ContextMode = 'sync' | 'eager' | 'lazy' | 'lazy-once'; 12 | 13 | export interface ContextFilter { 14 | pattern: string; 15 | flags: string; 16 | } 17 | 18 | export interface RequireContextParams { 19 | /* Should search for files recursively. Optional, default `true` when `require.context` is used */ 20 | readonly recursive: boolean; 21 | /* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */ 22 | readonly filter: Readonly; 23 | /** Mode for resolving dynamic dependencies. Defaults to `sync` */ 24 | readonly mode: ContextMode; 25 | } 26 | 27 | export type DynamicRequiresBehavior = 'throwAtRuntime' | 'reject'; 28 | -------------------------------------------------------------------------------- /packages/metro/types/Server/MultipartResponse.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type {IncomingMessage, ServerResponse} from 'http'; 12 | 13 | export type Data = string | Buffer | Uint8Array; 14 | export interface Headers { 15 | [name: string]: string | number; 16 | } 17 | 18 | export default class MultipartResponse { 19 | static wrapIfSupported( 20 | req: IncomingMessage, 21 | res: ServerResponse, 22 | ): MultipartResponse | ServerResponse; 23 | static serializeHeaders(headers: Headers): string; 24 | res: ServerResponse; 25 | headers: Headers; 26 | constructor(res: ServerResponse); 27 | writeChunk(headers: Headers | null, data?: Data, isLast?: boolean): void; 28 | writeHead(status: number, headers?: Headers): void; 29 | setHeader(name: string, value: string | number): void; 30 | end(data?: Data): void; 31 | } 32 | -------------------------------------------------------------------------------- /packages/metro/types/lib/CountingSet.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export interface ReadOnlyCountingSet extends Iterable { 12 | has(item: T): boolean; 13 | [Symbol.iterator](): Iterator; 14 | readonly size: number; 15 | count(item: T): number; 16 | forEach( 17 | callbackFn: ( 18 | this: ThisT, 19 | value: T, 20 | key: T, 21 | set: ReadOnlyCountingSet, 22 | ) => unknown, 23 | thisArg: ThisT, 24 | ): void; 25 | } 26 | 27 | export default class CountingSet implements ReadOnlyCountingSet { 28 | constructor(items?: Iterable); 29 | get size(): number; 30 | has(item: T): boolean; 31 | add(item: T): void; 32 | delete(item: T): void; 33 | keys(): Iterator; 34 | values(): Iterator; 35 | [Symbol.iterator](): Iterator; 36 | count(item: T): number; 37 | clear(): void; 38 | forEach( 39 | callbackFn: ( 40 | this: ThisT, 41 | value: T, 42 | key: T, 43 | set: ReadOnlyCountingSet, 44 | ) => unknown, 45 | thisArg: ThisT, 46 | ): void; 47 | toJSON(): unknown; 48 | } 49 | -------------------------------------------------------------------------------- /packages/metro/types/lib/TerminalReporter.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import {ReportableEvent} from './reporting'; 12 | import {Terminal} from 'metro-core'; 13 | 14 | export type TerminalReportableEvent = 15 | | ReportableEvent 16 | | { 17 | buildID: string; 18 | type: 'bundle_transform_progressed_throttled'; 19 | transformedFileCount: number; 20 | totalFileCount: number; 21 | }; 22 | 23 | export class TerminalReporter { 24 | constructor(terminal: Terminal); 25 | readonly terminal: Terminal; 26 | update(event: TerminalReportableEvent): void; 27 | } 28 | -------------------------------------------------------------------------------- /packages/metro/types/lib/contextModule.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import type {ContextMode} from '../ModuleGraph/worker/collectDependencies'; 12 | 13 | export interface RequireContext { 14 | /* Should search for files recursively. Optional, default `true` when `require.context` is used */ 15 | readonly recursive: boolean; 16 | /* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */ 17 | readonly filter: RegExp; 18 | /** Mode for resolving dynamic dependencies. Defaults to `sync` */ 19 | readonly mode: ContextMode; 20 | /** Absolute path of the directory to search in */ 21 | readonly from: string; 22 | } 23 | -------------------------------------------------------------------------------- /packages/metro/types/lib/getGraphId.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | export type GraphId = string; 12 | -------------------------------------------------------------------------------- /packages/metro/types/shared/output/bundle.d.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | import Server from '../../Server'; 12 | import {OutputOptions, RequestOptions} from '../../shared/types'; 13 | 14 | export function build( 15 | packagerClient: Server, 16 | requestOptions: RequestOptions, 17 | ): Promise<{ 18 | code: string; 19 | map: string; 20 | }>; 21 | 22 | export function save( 23 | bundle: { 24 | code: string; 25 | map: string; 26 | }, 27 | options: OutputOptions, 28 | log: (...args: string[]) => void, 29 | ): Promise; 30 | 31 | export const formatName: string; 32 | -------------------------------------------------------------------------------- /packages/ob1/.npmignore: -------------------------------------------------------------------------------- 1 | BUCK 2 | **/__mocks__/ 3 | **/__tests__/ 4 | /build/ 5 | /src.real/ 6 | /types/ 7 | yarn.lock 8 | -------------------------------------------------------------------------------- /packages/ob1/README.md: -------------------------------------------------------------------------------- 1 | # ob1 2 | 3 | A small library for working with 0- and 1-based offsets in a type-checked way. 4 | -------------------------------------------------------------------------------- /packages/ob1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ob1", 3 | "version": "0.82.4", 4 | "description": "A small library for working with 0- and 1-based offsets in a type-checked way.", 5 | "main": "src/ob1.js", 6 | "exports": { 7 | ".": "./src/ob1.js", 8 | "./package.json": "./package.json", 9 | "./private/*": "./src/*.js", 10 | "./src/*.js": "./src/*.js", 11 | "./src/*": "./src/*.js" 12 | }, 13 | "repository": { 14 | "type": "git", 15 | "url": "git@github.com:facebook/metro.git" 16 | }, 17 | "scripts": { 18 | "prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src", 19 | "cleanup-release": "test ! -e build && mv src build && mv src.real src" 20 | }, 21 | "keywords": [ 22 | "metro" 23 | ], 24 | "license": "MIT", 25 | "dependencies": { 26 | "flow-enums-runtime": "^0.0.6" 27 | }, 28 | "engines": { 29 | "node": ">=18.18" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/ob1/src/__tests__/ob1-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow strict-local 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const {add, add0, add1, get0, get1, inc, neg, sub, sub1} = require('../ob1'); 15 | 16 | const FORTY_TWO_0 = add0(42); 17 | const FORTY_TWO_1 = add1(41); 18 | 19 | describe('ob1', () => { 20 | test('add', () => { 21 | expect(get0(add(FORTY_TWO_0, 3))).toBe(45); 22 | expect(get1(add(FORTY_TWO_1, 3))).toBe(45); 23 | }); 24 | 25 | test('sub', () => { 26 | expect(get0(sub(FORTY_TWO_0, 3))).toBe(39); 27 | expect(get1(sub(FORTY_TWO_1, 3))).toBe(39); 28 | }); 29 | 30 | test('neg', () => { 31 | expect(get0(neg(FORTY_TWO_0))).toBe(-42); 32 | }); 33 | 34 | test('inc', () => { 35 | expect(get0(inc(FORTY_TWO_0))).toBe(43); 36 | expect(get1(inc(FORTY_TWO_1))).toBe(43); 37 | }); 38 | 39 | test('add1', () => { 40 | expect(get1(add1(FORTY_TWO_0))).toBe(43); 41 | }); 42 | 43 | test('sub1', () => { 44 | expect(get0(sub1(FORTY_TWO_1))).toBe(41); 45 | }); 46 | }); 47 | -------------------------------------------------------------------------------- /scripts/__tests__/babel-lib-defs-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | import generateBabelFlowLibraryDefinitions from '../support/generateBabelFlowLibraryDefinitions'; 14 | import {promises as fsPromises} from 'fs'; 15 | 16 | test('Babel Flow library definitions should be up to date', async () => { 17 | // Run `yarn update-babel-flow-lib-defs` in the Metro monorepo if this test fails. 18 | const contentByFilePath = await generateBabelFlowLibraryDefinitions(); 19 | expect(contentByFilePath).toBeInstanceOf(Map); 20 | expect(contentByFilePath.size).toBe(2); 21 | for (const [filePath, content] of contentByFilePath) { 22 | expect(await fsPromises.readFile(filePath, 'utf8')).toEqual(content); 23 | } 24 | }); 25 | -------------------------------------------------------------------------------- /scripts/_getPackages.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | const fs = require('fs'); 12 | const path = require('path'); 13 | 14 | const PACKAGES_DIR = path.resolve(__dirname, '../packages'); 15 | 16 | // Get absolute paths of all directories under packages/* 17 | module.exports = function getPackages() { 18 | return fs 19 | .readdirSync(PACKAGES_DIR) 20 | .map(file => path.resolve(PACKAGES_DIR, file)) 21 | .filter(f => fs.lstatSync(path.resolve(f)).isDirectory()); 22 | }; 23 | -------------------------------------------------------------------------------- /scripts/babelJestTransformer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @flow 8 | * @format 9 | * @oncall react_native 10 | */ 11 | 12 | 'use strict'; 13 | 14 | const {createTransformer} = require('babel-jest').default; 15 | 16 | const BABEL_CONFIG_PATH = require.resolve('../babel.config.js'); 17 | 18 | const transformer /*: any */ = createTransformer({ 19 | configFile: BABEL_CONFIG_PATH, 20 | }); 21 | 22 | module.exports = transformer; 23 | -------------------------------------------------------------------------------- /scripts/eslint/typescript.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | const path = require('path'); 14 | 15 | require('eslint-plugin-lint').load(path.join(__dirname, 'rules')); 16 | 17 | /** 18 | * ESLint config for TypeScript definition files (.d.ts). 19 | * 20 | * @type {import('eslint').Linter.Config} 21 | */ 22 | module.exports = { 23 | extends: [ 24 | 'eslint:recommended', 25 | 'plugin:@typescript-eslint/recommended', 26 | 'prettier', 27 | ], 28 | plugins: ['@typescript-eslint'], 29 | parser: '@typescript-eslint/parser', 30 | }; 31 | -------------------------------------------------------------------------------- /scripts/setupJest.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @oncall react_native 9 | */ 10 | 11 | 'use strict'; 12 | 13 | // Make sure nothing registers Babel on top of Jest's setup during tests. 14 | require('metro-babel-register').unstable_registerForMetroMonorepo = () => {}; 15 | -------------------------------------------------------------------------------- /scripts/updateBabelFlowLibraryDefinitions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | * 7 | * @format 8 | * @flow strict-local 9 | * @oncall react_native 10 | */ 11 | 12 | /** 13 | * This script updates all flow types. Run it every time you upgrade babel 14 | */ 15 | 16 | import generateBabelFlowLibraryDefinitions from './support/generateBabelFlowLibraryDefinitions'; 17 | import {promises as fsPromises} from 'fs'; 18 | 19 | async function main() { 20 | const newContentByFile = await generateBabelFlowLibraryDefinitions(); 21 | await Promise.all( 22 | Array.from(newContentByFile.entries(), ([path, content]) => 23 | fsPromises.writeFile(path, content), 24 | ), 25 | ); 26 | } 27 | 28 | main().catch(error => console.error(error)); 29 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "@tsconfig/node20/tsconfig.json", 3 | "include": ["./packages/*/types/**/*.d.ts"], 4 | "compilerOptions": { 5 | "noEmit": true, 6 | "baseUrl": ".", 7 | "skipLibCheck": false, 8 | "paths": { 9 | "metro": ["./packages/metro/types"], 10 | "metro/src/*": ["./packages/metro/types/*"], 11 | "metro-*": ["./packages/metro-*/types"], 12 | // Mappings for main entry points which are not "src/index.js". Required 13 | // only for this tsconfig - external consumers will read the "main" field 14 | // and find the adjacent typedef file. 15 | "metro-source-map": ["./packages/metro-source-map/types/source-map.d.ts"] 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /website/README.md: -------------------------------------------------------------------------------- 1 | You will need Node 6 or newer in order to build the Metro website. 2 | 3 | # Run the server 4 | 5 | The first time, get all the dependencies loaded via 6 | 7 | ``` 8 | yarn 9 | ``` 10 | 11 | in the root directory. 12 | 13 | Then, run the server via 14 | 15 | ``` 16 | npm start 17 | Open http://localhost:3000 18 | ``` 19 | 20 | Anytime you change the contents, just refresh the page and it's going to be 21 | updated 22 | 23 | # Publish the website 24 | 25 | The Metro website is hosted as a GitHub page. A static site is generated by 26 | `server/generate.js` and its output is pushed to the `gh-pages` branch by 27 | CircleCI whenever `main` is updated. 28 | 29 | To deploy the website manually, run the following command as a Git user with 30 | write permissions: 31 | 32 | ``` 33 | DEPLOY_USER=facebook GIT_USER=metro-bot CIRCLE_PROJECT_USERNAME=facebook CIRCLE_PROJECT_REPONAME=metro npm run gh-pages 34 | ``` 35 | 36 | ## Staging 37 | 38 | Run the above command against your own fork of `facebook/metro`: 39 | 40 | ``` 41 | DEPLOY_USER=YOUR_GITHUB_USERNAME GIT_USER=YOUR_GITHUB_USERNAME CIRCLE_PROJECT_USERNAME=YOUR_GITHUB_USERNAME CIRCLE_PROJECT_REPONAME=metro npm run gh-pages 42 | ``` 43 | -------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "metro-website", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "docusaurus": "docusaurus", 7 | "start": "docusaurus start", 8 | "build": "docusaurus build", 9 | "swizzle": "docusaurus swizzle", 10 | "deploy": "docusaurus deploy", 11 | "clear": "docusaurus clear", 12 | "serve": "docusaurus serve" 13 | }, 14 | "dependencies": { 15 | "@docusaurus/core": "^3.6.3", 16 | "@docusaurus/preset-classic": "^3.6.3", 17 | "@mdx-js/react": "^3.1.0", 18 | "classnames": "^2.5.1", 19 | "docusaurus-plugin-internaldocs-fb": "^1.19.1", 20 | "docusaurus-plugin-sass": "^0.2.6", 21 | "prism-react-renderer": "^2.4.0", 22 | "react": "^18.3.1", 23 | "react-dom": "^18.3.1", 24 | "react-github-btn": "^1.4.0", 25 | "sass": "^1.82.0" 26 | }, 27 | "devDependencies": { 28 | "@docusaurus/module-type-aliases": "3.6.3", 29 | "@docusaurus/types": "3.6.3", 30 | "prettier": "3.4.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /website/sidebars.json: -------------------------------------------------------------------------------- 1 | { 2 | "docs": { 3 | "Introduction": ["getting-started", "concepts"], 4 | "API Reference": ["api", "module-api", "configuration", "cli"], 5 | "Guides": ["package-exports", "troubleshooting"], 6 | "Contributing": ["local-development"], 7 | "Deep Dives": ["bundling", "caching", "resolution", "source-map-format"] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /website/src/pages/styles.module.css: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | * This source code is licensed under the MIT license found in the 5 | * LICENSE file in the root directory of this source tree. 6 | */ 7 | 8 | .heroBanner { 9 | padding: 2.5rem 0; 10 | text-align: center; 11 | position: relative; 12 | overflow: hidden; 13 | } 14 | 15 | .heroBannerLogo { 16 | max-width: 170px; 17 | max-height: 170px; 18 | } 19 | 20 | .heroButtons { 21 | display: flex; 22 | justify-content: center 23 | } 24 | 25 | .blockContainer { 26 | display: flex; 27 | flex-direction: column; 28 | align-items: center; 29 | } 30 | 31 | .blockImage { 32 | max-width: 80px; 33 | margin-bottom: 20px; 34 | } 35 | 36 | .video { 37 | width: 100%; 38 | max-width: 560px; 39 | aspect-ratio: 1.777; 40 | } 41 | -------------------------------------------------------------------------------- /website/static/CNAME: -------------------------------------------------------------------------------- 1 | metrobundler.dev 2 | -------------------------------------------------------------------------------- /website/static/img/content/atom.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/metro/15fef8ebcf5ae0a13e7f0925a22d4211dde95e02/website/static/img/content/atom.png -------------------------------------------------------------------------------- /website/static/img/content/high-speed-train.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/metro/15fef8ebcf5ae0a13e7f0925a22d4211dde95e02/website/static/img/content/high-speed-train.png -------------------------------------------------------------------------------- /website/static/img/content/scales.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/metro/15fef8ebcf5ae0a13e7f0925a22d4211dde95e02/website/static/img/content/scales.png -------------------------------------------------------------------------------- /website/static/img/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/metro/15fef8ebcf5ae0a13e7f0925a22d4211dde95e02/website/static/img/favicon.png -------------------------------------------------------------------------------- /website/static/img/opengraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/facebook/metro/15fef8ebcf5ae0a13e7f0925a22d4211dde95e02/website/static/img/opengraph.png --------------------------------------------------------------------------------