Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: facebook/metro
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.73.1
Choose a base ref
...
head repository: facebook/metro
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.73.2
Choose a head ref
  • 8 commits
  • 53 files changed
  • 6 contributors

Commits on Oct 6, 2022

  1. Annotate empty objects in xplat

    Reviewed By: pieterv
    
    Differential Revision: D40134090
    
    fbshipit-source-id: 3dd0bdb41ed559d9f72f0ff35c14e5551789fcc0
    SamChou19815 authored and facebook-github-bot committed Oct 6, 2022
    Copy the full SHA
    c0f88aa View commit details

Commits on Oct 7, 2022

  1. Make yarn and yarn jest react-native-codegen works on Windows wit…

    …h git (#34854)
    
    Summary:
    A few fixings to make `yarn jest react-native-doegen` works on Windows:
    
    - ~~Add a `.gitignore` file to tell git not to track generated/temporary files.~~
    - There is no `rm` on Windows, change it to `rimraf`.
    
    I have been using it in the last 3 months and it works perfectly on Windows, otherwise I could not even build the code in my laptop.
    
    ## Changelog
    
    [General] [Changed] - Make `yarn` and `yarn jest react-native-codegen` works on Windows with git
    
    X-link: facebook/react-native#34854
    
    Reviewed By: cortinico
    
    Differential Revision: D40059524
    
    Pulled By: cortinico
    
    fbshipit-source-id: e3cde2506c7d18c2b580099257637b90f4cb328c
    ZihanChen-MSFT authored and facebook-github-bot committed Oct 7, 2022
    Copy the full SHA
    fa10366 View commit details

Commits on Oct 11, 2022

  1. Use read-only version of Graph<T> where possible

    Summary:
    Creates a new interface type, `ReadOnlyGraph<T>`, for use in functions that should only read from a Graph instance and not mutate it. In particular this includes the `customSerializer` and `experimentalSerializerHook` functions, which may be user-supplied via config.
    
    This is not a breaking change since the serializer has always logically received a read-only graph. This diff merely codifies that in the Flow types.
    
    Changelog: [Internal]
    
    Reviewed By: huntie
    
    Differential Revision: D40233735
    
    fbshipit-source-id: d76482a9eaf344d6278430429eab6e9fef9a3627
    motiz88 authored and facebook-github-bot committed Oct 11, 2022
    Copy the full SHA
    728089f View commit details
  2. Convert Graph<T> to a class

    Summary: Converts `Graph<T>` to a class and all of `graphOperations.js`'s exports to methods on that class. `Graph<T>` has had opaque private state since D36403391 (832ee06), so here we take the next logical step to make it easier to work on.
    
    Reviewed By: huntie
    
    Differential Revision: D40233734
    
    fbshipit-source-id: 204183707c824f9801275dbdb34861db55366ac0
    motiz88 authored and facebook-github-bot committed Oct 11, 2022
    Copy the full SHA
    78634cb View commit details

Commits on Oct 12, 2022

  1. Deploy 0.189.0 to xplat

    Summary: Changelog: [Internal]
    
    Reviewed By: SamChou19815
    
    Differential Revision: D40320927
    
    fbshipit-source-id: 05c74ddf966ab25308237e265113d1cbb920d3c6
    pieterv authored and facebook-github-bot committed Oct 12, 2022
    Copy the full SHA
    5177582 View commit details

Commits on Oct 13, 2022

  1. Extract some crawl and watch management out of index.js

    Summary:
    Refactoring to begin the work of bringing crawl+watch closer together.
    
    This simply pulls some code out of the bloated `index.js` into a `Watcher` class, which is responsible for managing crawl and watch backends.
    
    The API is likely to change, but for now sticks to `crawl()` / `watch()` as separate instance methods (reflecting the current architecture) to minimise the churn in this diff.
    
    Changelog: Internal
    
    Reviewed By: motiz88
    
    Differential Revision: D39891465
    
    fbshipit-source-id: 8e3616847380bea7acf7117479a0a9a90526e19e
    robhogan authored and facebook-github-bot committed Oct 13, 2022
    Copy the full SHA
    dc02eac View commit details
  2. Align JS docs snippets to use single quotes

    Reviewed By: jacdebug
    
    Differential Revision: D40337918
    
    fbshipit-source-id: 6dfcb83d3976117d6642310e0658986daa537854
    huntie authored and facebook-github-bot committed Oct 13, 2022
    Copy the full SHA
    355f0d9 View commit details
  3. Release 0.73.2

    Reviewed By: jacdebug, voideanvalue
    
    Differential Revision: D40342897
    
    fbshipit-source-id: d36a11bd869647f0e31dd146782248e634186cf1
    motiz88 authored and facebook-github-bot committed Oct 13, 2022
    Copy the full SHA
    0006a7e View commit details
Showing with 1,524 additions and 1,428 deletions.
  1. +1 −1 .flowconfig
  2. +2 −2 docs/Configuration.md
  3. +1 −1 lerna.json
  4. +1 −1 package.json
  5. +2 −2 packages/buck-worker-tool/package.json
  6. +1 −1 packages/metro-babel-register/package.json
  7. +2 −2 packages/metro-babel-transformer/package.json
  8. +2 −2 packages/metro-cache-key/package.json
  9. +4 −4 packages/metro-cache/package.json
  10. +5 −5 packages/metro-config/package.json
  11. +6 −3 packages/metro-config/src/configTypes.flow.js
  12. +2 −2 packages/metro-core/package.json
  13. +1 −1 packages/metro-file-map/package.json
  14. +186 −0 packages/metro-file-map/src/Watcher.js
  15. +44 −132 packages/metro-file-map/src/index.js
  16. +1 −1 packages/metro-hermes-compiler/package.json
  17. +1 −1 packages/metro-inspector-proxy/package.json
  18. +1 −1 packages/metro-memory-fs/package.json
  19. +1 −1 packages/metro-minify-terser/package.json
  20. +1 −1 packages/metro-minify-uglify/package.json
  21. +1 −1 packages/metro-react-native-babel-preset/package.json
  22. +4 −4 packages/metro-react-native-babel-transformer/package.json
  23. +1 −1 packages/metro-react-native-interop-tools/package.json
  24. +1 −1 packages/metro-resolver/package.json
  25. +1 −1 packages/metro-runtime/package.json
  26. +3 −3 packages/metro-source-map/package.json
  27. +2 −2 packages/metro-symbolicate/package.json
  28. +2 −2 packages/metro-transform-plugins/package.json
  29. +11 −11 packages/metro-transform-worker/package.json
  30. +23 −23 packages/metro/package.json
  31. +3 −2 packages/metro/src/DeltaBundler.js
  32. +9 −17 packages/metro/src/DeltaBundler/DeltaCalculator.js
  33. +793 −0 packages/metro/src/DeltaBundler/Graph.js
  34. +2 −2 packages/metro/src/DeltaBundler/Serializers/baseBytecodeBundle.js
  35. +2 −2 packages/metro/src/DeltaBundler/Serializers/baseJSBundle.js
  36. +2 −2 packages/metro/src/DeltaBundler/Serializers/getAllFiles.js
  37. +2 −2 packages/metro/src/DeltaBundler/Serializers/getAssets.js
  38. +2 −2 packages/metro/src/DeltaBundler/Serializers/getRamBundleInfo.js
  39. +3 −3 packages/metro/src/DeltaBundler/Serializers/helpers/getTransitiveDependencies.js
  40. +5 −5 packages/metro/src/DeltaBundler/Serializers/hmrJSBundle.js
  41. +67 −41 packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-context-test.js
  42. +88 −46 packages/metro/src/DeltaBundler/__tests__/DeltaCalculator-test.js
  43. +200 −234 packages/metro/src/DeltaBundler/__tests__/{traverseDependencies-test.js → Graph-test.js}
  44. +2 −2 ...src/DeltaBundler/__tests__/__snapshots__/{traverseDependencies-test.js.snap → Graph-test.js.snap}
  45. +0 −833 packages/metro/src/DeltaBundler/graphOperations.js
  46. +14 −7 packages/metro/src/DeltaBundler/types.flow.js
  47. +2 −2 packages/metro/src/IncrementalBundler.js
  48. +4 −3 packages/metro/src/Server.js
  49. +2 −2 packages/metro/src/index.flow.js
  50. +1 −1 packages/metro/src/integration_tests/basic_bundle/require-context/utils.js
  51. +1 −1 packages/metro/src/lib/getAppendScripts.js
  52. +1 −1 packages/ob1/package.json
  53. +5 −5 yarn.lock
2 changes: 1 addition & 1 deletion .flowconfig
Original file line number Diff line number Diff line change
@@ -42,4 +42,4 @@ untyped-import
untyped-type-import

[version]
^0.188.1
^0.189.0
4 changes: 2 additions & 2 deletions docs/Configuration.md
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@ resolveRequest: (context, moduleName, platform) => {
// Resolve file path logic...
// NOTE: Throw an error if there is no resolution.
return {
filePath: "path/to/file",
filePath: 'path/to/file',
type: 'sourceFile',
};
}
@@ -445,7 +445,7 @@ This allows overriding and removing default config parameters such as `platforms

```js
// metro.config.js
const { mergeConfig } = require("metro-config");
const { mergeConfig } = require('metro-config');

const configA = {
/* general options */
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "2.4.0",
"version": "0.73.1",
"version": "0.73.2",
"npmClient": "yarn",
"useWorkspaces": true
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-react": "^7.30.1",
"eslint-plugin-relay": "^1.8.3",
"flow-bin": "^0.188.1",
"flow-bin": "^0.189.0",
"glob": "^7.1.1",
"hermes-eslint": "0.8.0",
"invariant": "^2.2.4",
4 changes: 2 additions & 2 deletions packages/buck-worker-tool/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "buck-worker-tool",
"version": "0.73.1",
"version": "0.73.2",
"description": "Implementation of the Buck worker protocol for Node.js.",
"license": "MIT",
"main": "src/worker-tool.js",
@@ -13,7 +13,7 @@
"through": ">=2.2.7 <3"
},
"devDependencies": {
"metro-memory-fs": "0.73.1"
"metro-memory-fs": "0.73.2"
},
"scripts": {
"prepare-release": "test -d build && rm -rf src.real && mv src src.real && mv build src",
2 changes: 1 addition & 1 deletion packages/metro-babel-register/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metro-babel-register",
"version": "0.73.1",
"version": "0.73.2",
"description": "🚇 babel/register configuration for Metro.",
"main": "src/babel-register.js",
"repository": {
4 changes: 2 additions & 2 deletions packages/metro-babel-transformer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metro-babel-transformer",
"version": "0.73.1",
"version": "0.73.2",
"description": "🚇 Base Babel transformer for Metro.",
"main": "src/index.js",
"repository": {
@@ -19,7 +19,7 @@
"dependencies": {
"@babel/core": "^7.14.0",
"hermes-parser": "0.8.0",
"metro-source-map": "0.73.1",
"metro-source-map": "0.73.2",
"nullthrows": "^1.1.1"
}
}
4 changes: 2 additions & 2 deletions packages/metro-cache-key/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metro-cache-key",
"version": "0.73.1",
"version": "0.73.2",
"description": "🚇 Cache key utility.",
"main": "src/index.js",
"repository": {
@@ -13,6 +13,6 @@
},
"license": "MIT",
"devDependencies": {
"metro-memory-fs": "0.73.1"
"metro-memory-fs": "0.73.2"
}
}
8 changes: 4 additions & 4 deletions packages/metro-cache/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metro-cache",
"version": "0.73.1",
"version": "0.73.2",
"description": "🚇 Cache layers for Metro.",
"main": "src/index.js",
"repository": {
@@ -12,11 +12,11 @@
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
},
"dependencies": {
"metro-core": "0.73.1",
"rimraf": "^2.5.4"
"metro-core": "0.73.2",
"rimraf": "^3.0.2"
},
"devDependencies": {
"metro-memory-fs": "0.73.1"
"metro-memory-fs": "0.73.2"
},
"license": "MIT"
}
10 changes: 5 additions & 5 deletions packages/metro-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metro-config",
"version": "0.73.1",
"version": "0.73.2",
"description": "🚇 Config parser for Metro.",
"main": "src/index.js",
"repository": {
@@ -15,10 +15,10 @@
"dependencies": {
"cosmiconfig": "^5.0.5",
"jest-validate": "^26.5.2",
"metro": "0.73.1",
"metro-cache": "0.73.1",
"metro-core": "0.73.1",
"metro-runtime": "0.73.1"
"metro": "0.73.2",
"metro-cache": "0.73.2",
"metro-core": "0.73.2",
"metro-runtime": "0.73.2"
},
"devDependencies": {
"pretty-format": "^26.5.2",
9 changes: 6 additions & 3 deletions packages/metro-config/src/configTypes.flow.js
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@ import type {JsTransformerConfig} from 'metro-transform-worker';
import type {TransformResult} from 'metro/src/DeltaBundler';
import type {
DeltaResult,
Graph,
Module,
ReadOnlyGraph,
SerializerOptions,
} from 'metro/src/DeltaBundler/types.flow.js';
import type {Reporter} from 'metro/src/lib/reporting';
@@ -110,10 +110,13 @@ type SerializerConfigT = {
customSerializer: ?(
entryPoint: string,
preModules: $ReadOnlyArray<Module<>>,
graph: Graph<>,
graph: ReadOnlyGraph<>,
options: SerializerOptions,
) => Promise<string | {code: string, map: string}>,
experimentalSerializerHook: (graph: Graph<>, delta: DeltaResult<>) => mixed,
experimentalSerializerHook: (
graph: ReadOnlyGraph<>,
delta: DeltaResult<>,
) => mixed,
getModulesRunBeforeMainModule: (entryFilePath: string) => Array<string>,
getPolyfills: ({platform: ?string, ...}) => $ReadOnlyArray<string>,
getRunModuleStatement: (number | string) => string,
4 changes: 2 additions & 2 deletions packages/metro-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metro-core",
"version": "0.73.1",
"version": "0.73.2",
"description": "🚇 Metro's core package.",
"main": "src/index.js",
"repository": {
@@ -13,7 +13,7 @@
},
"dependencies": {
"lodash.throttle": "^4.1.1",
"metro-resolver": "0.73.1"
"metro-resolver": "0.73.2"
},
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/metro-file-map/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "metro-file-map",
"version": "0.73.1",
"version": "0.73.2",
"description": "[Experimental] - 🚇 File crawling, watching and mapping for Metro",
"main": "src/index.js",
"repository": {
186 changes: 186 additions & 0 deletions packages/metro-file-map/src/Watcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow strict-local
*/

import type {
Console,
CrawlerOptions,
FileData,
InternalData,
Path,
PerfLogger,
} from './flow-types';
import type {WatcherOptions as WatcherBackendOptions} from './watchers/common';
import type {Stats} from 'fs';

import watchmanCrawl from './crawlers/watchman';
import nodeCrawl from './crawlers/node';
import WatchmanWatcher from './watchers/WatchmanWatcher';
import FSEventsWatcher from './watchers/FSEventsWatcher';
// $FlowFixMe[untyped-import] - it's a fork: https://github.com/facebook/jest/pull/10919
import NodeWatcher from './watchers/NodeWatcher';

const debug = require('debug')('Metro:Watcher');

const MAX_WAIT_TIME = 240000;

type WatcherOptions = {
abortSignal: AbortSignal,
computeSha1: boolean,
console: Console,
enableSymlinks: boolean,
extensions: $ReadOnlyArray<string>,
forceNodeFilesystemAPI: boolean,
ignore: string => boolean,
ignorePattern: RegExp,
initialData: InternalData,
perfLogger: ?PerfLogger,
roots: $ReadOnlyArray<string>,
rootDir: string,
useWatchman: boolean,
watch: boolean,
watchmanDeferStates: $ReadOnlyArray<string>,
};

interface WatcherBackend {
close(): Promise<void>;
}

export class Watcher {
_options: WatcherOptions;
_backends: $ReadOnlyArray<WatcherBackend> = [];

constructor(options: WatcherOptions) {
this._options = options;
}

async crawl(): Promise<?(
| Promise<{
changedFiles?: FileData,
hasteMap: InternalData,
removedFiles: FileData,
}>
| {changedFiles?: FileData, hasteMap: InternalData, removedFiles: FileData}
)> {
this._options.perfLogger?.point('crawl_start');

const options = this._options;
const ignore = (filePath: string) => options.ignore(filePath);
const crawl = options.useWatchman ? watchmanCrawl : nodeCrawl;
const crawlerOptions: CrawlerOptions = {
abortSignal: options.abortSignal,
computeSha1: options.computeSha1,
data: options.initialData,
enableSymlinks: options.enableSymlinks,
extensions: options.extensions,
forceNodeFilesystemAPI: options.forceNodeFilesystemAPI,
ignore,
perfLogger: options.perfLogger,
rootDir: options.rootDir,
roots: options.roots,
};

const retry = (error: Error) => {
if (crawl === watchmanCrawl) {
options.console.warn(
'metro-file-map: Watchman crawl failed. Retrying once with node ' +
'crawler.\n' +
" Usually this happens when watchman isn't running. Create an " +
"empty `.watchmanconfig` file in your project's root folder or " +
'initialize a git or hg repository in your project.\n' +
' ' +
error.toString(),
);
return nodeCrawl(crawlerOptions).catch(e => {
throw new Error(
'Crawler retry failed:\n' +
` Original error: ${error.message}\n` +
` Retry error: ${e.message}\n`,
);
});
}

throw error;
};

const logEnd = <T>(result: T): T => {
this._options.perfLogger?.point('crawl_end');
return result;
};

try {
return crawl(crawlerOptions).catch(retry).then(logEnd);
} catch (error) {
return retry(error).then(logEnd);
}
}

async watch(
onChange: (
type: string,
filePath: string,
root: string,
stat?: Stats,
) => void,
) {
const {extensions, ignorePattern, useWatchman} = this._options;

// WatchmanWatcher > FSEventsWatcher > sane.NodeWatcher
const WatcherImpl = useWatchman
? WatchmanWatcher
: FSEventsWatcher.isSupported()
? FSEventsWatcher
: NodeWatcher;

let watcher = 'node';
if (WatcherImpl === WatchmanWatcher) {
watcher = 'watchman';
} else if (WatcherImpl === FSEventsWatcher) {
watcher = 'fsevents';
}
debug(`Using watcher: ${watcher}`);
this._options.perfLogger?.annotate({string: {watcher}});

const createWatcherBackend = (root: Path): Promise<WatcherBackend> => {
const watcherOptions: WatcherBackendOptions = {
dot: true,
glob: [
// Ensure we always include package.json files, which are crucial for
/// module resolution.
'**/package.json',
...extensions.map(extension => '**/*.' + extension),
],
ignored: ignorePattern,
watchmanDeferStates: this._options.watchmanDeferStates,
};
const watcher = new WatcherImpl(root, watcherOptions);

return new Promise((resolve, reject) => {
const rejectTimeout = setTimeout(
() => reject(new Error('Failed to start watch mode.')),
MAX_WAIT_TIME,
);

watcher.once('ready', () => {
clearTimeout(rejectTimeout);
watcher.on('all', onChange);
resolve(watcher);
});
});
};

this._backends = await Promise.all(
this._options.roots.map(createWatcherBackend),
);
}

async close() {
await Promise.all(this._backends.map(watcher => watcher.close()));
}
}
Loading