mirror of https://github.com/status-im/metro.git
Move the ambiguous error to its own file
Reviewed By: davidaurelio Differential Revision: D7180925 fbshipit-source-id: 4b92397a768e0d9cda102d4b237bc39d2b38b443
This commit is contained in:
parent
094489f6e1
commit
94028f16c1
|
@ -12,6 +12,7 @@
|
||||||
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
|
"cleanup-release": "test ! -e build && mv src build && mv src.real src"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"jest-haste-map": "^22.4.2",
|
||||||
"lodash.throttle": "^4.1.1",
|
"lodash.throttle": "^4.1.1",
|
||||||
"wordwrap": "^1.0.0"
|
"wordwrap": "^1.0.0"
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
|
@ -10,4 +10,8 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
module.exports = {};
|
const AmbiguousModuleResolutionError = require('./AmbiguousModuleResolutionError');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
AmbiguousModuleResolutionError,
|
||||||
|
};
|
||||||
|
|
|
@ -10,12 +10,14 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const AmbiguousModuleResolutionError = require('./errors/AmbiguousModuleResolutionError');
|
||||||
const Logger = require('./Logger');
|
const Logger = require('./Logger');
|
||||||
const Terminal = require('./Terminal');
|
const Terminal = require('./Terminal');
|
||||||
|
|
||||||
const formatBanner = require('./formatBanner');
|
const formatBanner = require('./formatBanner');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
AmbiguousModuleResolutionError,
|
||||||
Logger,
|
Logger,
|
||||||
Terminal,
|
Terminal,
|
||||||
formatBanner,
|
formatBanner,
|
||||||
|
|
|
@ -4916,9 +4916,7 @@ describe('traverseDependencies', function() {
|
||||||
await getOrderedDependenciesAsJSON(dgraph, root + '/index.js');
|
await getOrderedDependenciesAsJSON(dgraph, root + '/index.js');
|
||||||
throw new Error('expected `getOrderedDependenciesAsJSON` to fail');
|
throw new Error('expected `getOrderedDependenciesAsJSON` to fail');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const {
|
const {AmbiguousModuleResolutionError} = require('metro-core');
|
||||||
AmbiguousModuleResolutionError,
|
|
||||||
} = require('../../node-haste/DependencyGraph/ResolutionRequest');
|
|
||||||
if (!(error instanceof AmbiguousModuleResolutionError)) {
|
if (!(error instanceof AmbiguousModuleResolutionError)) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,9 +15,7 @@ const path = require('path');
|
||||||
const reporting = require('./reporting');
|
const reporting = require('./reporting');
|
||||||
const throttle = require('lodash.throttle');
|
const throttle = require('lodash.throttle');
|
||||||
|
|
||||||
const {
|
const {AmbiguousModuleResolutionError} = require('metro-core');
|
||||||
AmbiguousModuleResolutionError,
|
|
||||||
} = require('../node-haste/DependencyGraph/ResolutionRequest');
|
|
||||||
const {formatBanner} = require('metro-core');
|
const {formatBanner} = require('metro-core');
|
||||||
|
|
||||||
import type {
|
import type {
|
||||||
|
|
|
@ -15,9 +15,7 @@ const serializeError = require('serialize-error');
|
||||||
const {
|
const {
|
||||||
UnableToResolveError,
|
UnableToResolveError,
|
||||||
} = require('../node-haste/DependencyGraph/ModuleResolution');
|
} = require('../node-haste/DependencyGraph/ModuleResolution');
|
||||||
const {
|
const {AmbiguousModuleResolutionError} = require('metro-core');
|
||||||
AmbiguousModuleResolutionError,
|
|
||||||
} = require('../node-haste/DependencyGraph/ResolutionRequest');
|
|
||||||
|
|
||||||
export type CustomError = Error & {|
|
export type CustomError = Error & {|
|
||||||
status?: number,
|
status?: number,
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
|
||||||
|
const {AmbiguousModuleResolutionError} = require('metro-core');
|
||||||
const {DuplicateHasteCandidatesError} = require('jest-haste-map').ModuleMap;
|
const {DuplicateHasteCandidatesError} = require('jest-haste-map').ModuleMap;
|
||||||
const {formatFileCandidates, InvalidPackageError} = require('metro-resolver');
|
const {formatFileCandidates, InvalidPackageError} = require('metro-resolver');
|
||||||
|
|
||||||
|
@ -60,7 +61,6 @@ type Options<TModule, TPackage> = {|
|
||||||
class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
|
class ResolutionRequest<TModule: Moduleish, TPackage: Packageish> {
|
||||||
_immediateResolutionCache: {[key: string]: TModule, __proto__: null};
|
_immediateResolutionCache: {[key: string]: TModule, __proto__: null};
|
||||||
_options: Options<TModule, TPackage>;
|
_options: Options<TModule, TPackage>;
|
||||||
static AmbiguousModuleResolutionError: Class<AmbiguousModuleResolutionError>;
|
|
||||||
static PackageResolutionError: Class<PackageResolutionError>;
|
static PackageResolutionError: Class<PackageResolutionError>;
|
||||||
|
|
||||||
constructor(options: Options<TModule, TPackage>) {
|
constructor(options: Options<TModule, TPackage>) {
|
||||||
|
@ -123,23 +123,6 @@ function getResolutionCacheKey(modulePath, depName) {
|
||||||
return `${path.resolve(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 {
|
class PackageResolutionError extends Error {
|
||||||
originModulePath: string;
|
originModulePath: string;
|
||||||
packageError: InvalidPackageError;
|
packageError: InvalidPackageError;
|
||||||
|
@ -165,7 +148,6 @@ class PackageResolutionError extends Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolutionRequest.AmbiguousModuleResolutionError = AmbiguousModuleResolutionError;
|
|
||||||
ResolutionRequest.PackageResolutionError = PackageResolutionError;
|
ResolutionRequest.PackageResolutionError = PackageResolutionError;
|
||||||
|
|
||||||
module.exports = ResolutionRequest;
|
module.exports = ResolutionRequest;
|
||||||
|
|
Loading…
Reference in New Issue