-
Notifications
You must be signed in to change notification settings - Fork 630
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolve files to real paths when
unstable_enableSymlinks
(#925)
Summary: Pull Request resolved: #925 This makes a minimally invasive change to `metro-resolver` to run source file and asset resolutions through a new `getRealPath` method of `FileSystem`. Custom `resolveRequest` implementations are not affected - for the time being they're expected to take responsibility for returning real paths on their own, but they may now use `content.unstable_getRealPath` to do so. This is not intended as a final design, but the resolver changes will dovetail into planned DependencyGraph work where we'll need to track non-existent resolution candidates (by their "candidate path", but ultimately resolve to real paths). Changelog: [Experimental] Implement `resolver.unstable_enableSymlinks` Reviewed By: jacdebug Differential Revision: D42847996 fbshipit-source-id: b67ce7a689afc4074080d1e1c47042057904384c
- Loading branch information
1 parent
6e6f36f
commit a1e233c
Showing
12 changed files
with
147 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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. | ||
* | ||
* @flow strict-local | ||
* @format | ||
* @oncall react_native | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {ResolutionContext} from '../index'; | ||
|
||
const FailedToResolvePathError = require('../errors/FailedToResolvePathError'); | ||
const Resolver = require('../index'); | ||
import {createResolutionContext} from './utils'; | ||
|
||
const fileMap = { | ||
'/root/project/foo.js': '', | ||
'/root/project/baz/index.js': '', | ||
'/root/project/baz.js': {realPath: null}, | ||
'/root/project/link-to-foo.js': {realPath: '/root/project/foo.js'}, | ||
}; | ||
|
||
const CONTEXT: ResolutionContext = { | ||
...createResolutionContext(fileMap, {enableSymlinks: true}), | ||
originModulePath: '/root/project/foo.js', | ||
}; | ||
|
||
it('resolves to a real path when the chosen candidate is a symlink', () => { | ||
expect(Resolver.resolve(CONTEXT, './link-to-foo', null)).toEqual({ | ||
type: 'sourceFile', | ||
filePath: '/root/project/foo.js', | ||
}); | ||
}); | ||
|
||
it('does not resolve to a broken symlink', () => { | ||
// ./baz.js is a broken link, baz/index.js is real | ||
expect(() => Resolver.resolve(CONTEXT, './baz.js', null)).toThrow( | ||
FailedToResolvePathError, | ||
); | ||
expect(Resolver.resolve(CONTEXT, './baz', null)).toEqual({ | ||
type: 'sourceFile', | ||
filePath: '/root/project/baz/index.js', | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters