Skip to content

Commit

Permalink
kill shouldThrowOnUnresolvedErrors option
Browse files Browse the repository at this point in the history
Summary: Removes the `shouldThrowOnUnresolvedErrors` option, as now it is only ever `() => true`

Reviewed By: davidaurelio

Differential Revision: D4237711

fbshipit-source-id: 9460f0f0c50dc0d08d17cb7bdeb995825f7051f3
  • Loading branch information
cpojer authored and Facebook Github Bot committed Nov 30, 2016
1 parent 4902a03 commit b1fd7bd
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ type ResolveOptions = {|
|};

const platforms = new Set(defaults.platforms);
const returnTrue = () => true;

exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
const {
Expand Down Expand Up @@ -87,7 +86,6 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
platform,
platforms,
preferNativePlatform: true,
shouldThrowOnUnresolvedErrors: returnTrue,
});
}

Expand Down
1 change: 0 additions & 1 deletion packager/react-packager/src/Resolver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class Resolver {
preferNativePlatform: true,
watch: opts.watch,
cache: opts.cache,
shouldThrowOnUnresolvedErrors: () => true,
transformCode: opts.transformCode,
transformCacheKey: opts.transformCacheKey,
extraNodeModules: opts.extraNodeModules,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ import type Module from '../Module';
import type ModuleCache from '../ModuleCache';
import type ResolutionResponse from './ResolutionResponse';

const emptyModule = require.resolve('./assets/empty-module.js');

type DirExistsFn = (filePath: string) => boolean;

type Options = {
Expand All @@ -43,7 +41,6 @@ type Options = {
platform: string,
platforms: Set<string>,
preferNativePlatform: boolean,
shouldThrowOnUnresolvedErrors: () => boolean,
};

class ResolutionRequest {
Expand All @@ -58,7 +55,7 @@ class ResolutionRequest {
_platform: string;
_platforms: Set<string>;
_preferNativePlatform: boolean;
_shouldThrowOnUnresolvedErrors: () => boolean;
static emptyModule: string;

constructor({
dirExists,
Expand All @@ -71,7 +68,6 @@ class ResolutionRequest {
platform,
platforms,
preferNativePlatform,
shouldThrowOnUnresolvedErrors,
}: Options) {
this._dirExists = dirExists;
this._entryPath = entryPath;
Expand All @@ -83,7 +79,6 @@ class ResolutionRequest {
this._platform = platform;
this._platforms = platforms;
this._preferNativePlatform = preferNativePlatform;
this._shouldThrowOnUnresolvedErrors = shouldThrowOnUnresolvedErrors;
this._resetResolutionCache();
}

Expand All @@ -109,38 +104,16 @@ class ResolutionRequest {
return result;
};

const forgive = (error) => {
if (
error.type !== 'UnableToResolveError' ||
this._shouldThrowOnUnresolvedErrors(this._entryPath, this._platform)
) {
throw error;
}

debug(
'Unable to resolve module %s from %s',
toModuleName,
fromModule.path
);
return null;
};

if (!this._helpers.isNodeModulesDir(fromModule.path)
&& !(isRelativeImport(toModuleName) || isAbsolutePath(toModuleName))) {
return this._tryResolve(
() => this._resolveHasteDependency(fromModule, toModuleName),
() => this._resolveNodeDependency(fromModule, toModuleName)
).then(
cacheResult,
forgive,
);
).then(cacheResult);
}

return this._resolveNodeDependency(fromModule, toModuleName)
.then(
cacheResult,
forgive,
);
.then(cacheResult);
}

getOrderedDependencies({
Expand Down Expand Up @@ -311,7 +284,11 @@ class ResolutionRequest {
return this._redirectRequire(fromModule, potentialModulePath).then(
realModuleName => {
if (realModuleName === false) {
return this._loadAsFile(emptyModule, fromModule, toModuleName);
return this._loadAsFile(
ResolutionRequest.emptyModule,
fromModule,
toModuleName,
);
}

return this._tryResolve(
Expand All @@ -330,7 +307,11 @@ class ResolutionRequest {
realModuleName => {
// exclude
if (realModuleName === false) {
return this._loadAsFile(emptyModule, fromModule, toModuleName);
return this._loadAsFile(
ResolutionRequest.emptyModule,
fromModule,
toModuleName,
);
}

if (isRelativeImport(realModuleName) || isAbsolutePath(realModuleName)) {
Expand Down Expand Up @@ -526,4 +507,6 @@ function isRelativeImport(filePath) {
return /^[.][.]?(?:[/]|$)/.test(filePath);
}

ResolutionRequest.emptyModule = require.resolve('./assets/empty-module.js');

module.exports = ResolutionRequest;
Loading

0 comments on commit b1fd7bd

Please sign in to comment.