Move the ambiguous error to its own file

Reviewed By: davidaurelio

Differential Revision: D7180925

fbshipit-source-id: 4b92397a768e0d9cda102d4b237bc39d2b38b443
This commit is contained in:
Peter van der Zee 2018-03-25 13:27:42 -07:00 committed by Facebook Github Bot
parent 094489f6e1
commit 94028f16c1
8 changed files with 44 additions and 29 deletions

View File

@ -12,6 +12,7 @@
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
},
"dependencies": {
"jest-haste-map": "^22.4.2",
"lodash.throttle": "^4.1.1",
"wordwrap": "^1.0.0"
}

View File

@ -0,0 +1,32 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
* @format
*/
'use strict';
const {DuplicateHasteCandidatesError} = require('jest-haste-map').ModuleMap;
class AmbiguousModuleResolutionError extends Error {
fromModulePath: string;
hasteError: DuplicateHasteCandidatesError;
constructor(
fromModulePath: string,
hasteError: DuplicateHasteCandidatesError,
) {
super(
`Ambiguous module resolution from \`${fromModulePath}\`: ` +
hasteError.message,
);
this.fromModulePath = fromModulePath;
this.hasteError = hasteError;
}
}
module.exports = AmbiguousModuleResolutionError;

View File

@ -10,4 +10,8 @@
'use strict';
module.exports = {};
const AmbiguousModuleResolutionError = require('./AmbiguousModuleResolutionError');
module.exports = {
AmbiguousModuleResolutionError,
};

View File

@ -10,12 +10,14 @@
'use strict';
const AmbiguousModuleResolutionError = require('./errors/AmbiguousModuleResolutionError');
const Logger = require('./Logger');
const Terminal = require('./Terminal');
const formatBanner = require('./formatBanner');
module.exports = {
AmbiguousModuleResolutionError,
Logger,
Terminal,
formatBanner,

View File

@ -4916,9 +4916,7 @@ describe('traverseDependencies', function() {
await getOrderedDependenciesAsJSON(dgraph, root + '/index.js');
throw new Error('expected `getOrderedDependenciesAsJSON` to fail');
} catch (error) {
const {
AmbiguousModuleResolutionError,
} = require('../../node-haste/DependencyGraph/ResolutionRequest');
const {AmbiguousModuleResolutionError} = require('metro-core');
if (!(error instanceof AmbiguousModuleResolutionError)) {
throw error;
}

View File

@ -15,9 +15,7 @@ const path = require('path');
const reporting = require('./reporting');
const throttle = require('lodash.throttle');
const {
AmbiguousModuleResolutionError,
} = require('../node-haste/DependencyGraph/ResolutionRequest');
const {AmbiguousModuleResolutionError} = require('metro-core');
const {formatBanner} = require('metro-core');
import type {

View File

@ -15,9 +15,7 @@ const serializeError = require('serialize-error');
const {
UnableToResolveError,
} = require('../node-haste/DependencyGraph/ModuleResolution');
const {
AmbiguousModuleResolutionError,
} = require('../node-haste/DependencyGraph/ResolutionRequest');
const {AmbiguousModuleResolutionError} = require('metro-core');
export type CustomError = Error & {|
status?: number,

View File

@ -12,6 +12,7 @@
const path = require('path');
const {AmbiguousModuleResolutionError} = require('metro-core');
const {DuplicateHasteCandidatesError} = require('jest-haste-map').ModuleMap;
const {formatFileCandidates, InvalidPackageError} = require('metro-resolver');
@ -60,7 +61,6 @@ type Options<TModule, TPackage> = {|
class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
_immediateResolutionCache: {[key: string]: TModule, __proto__: null};
_options: Options<TModule, TPackage>;
static AmbiguousModuleResolutionError: Class<AmbiguousModuleResolutionError>;
static PackageResolutionError: Class<PackageResolutionError>;
constructor(options: Options<TModule, TPackage>) {
@ -123,23 +123,6 @@ function getResolutionCacheKey(modulePath, depName) {
return `${path.resolve(modulePath)}:${depName}`;
}
class AmbiguousModuleResolutionError extends Error {
fromModulePath: string;
hasteError: DuplicateHasteCandidatesError;
constructor(
fromModulePath: string,
hasteError: DuplicateHasteCandidatesError,
) {
super(
`Ambiguous module resolution from \`${fromModulePath}\`: ` +
hasteError.message,
);
this.fromModulePath = fromModulePath;
this.hasteError = hasteError;
}
}
class PackageResolutionError extends Error {
originModulePath: string;
packageError: InvalidPackageError;
@ -165,7 +148,6 @@ class PackageResolutionError extends Error {
}
}
ResolutionRequest.AmbiguousModuleResolutionError = AmbiguousModuleResolutionError;
ResolutionRequest.PackageResolutionError = PackageResolutionError;
module.exports = ResolutionRequest;