mirror of https://github.com/status-im/metro.git
Pass hasteImplModulePath to JestHasteMap and everywhere else
Reviewed By: jeanlauliac Differential Revision: D6641294 fbshipit-source-id: 36ebec95e69fe920c6cc10addd96406521cb4b82
This commit is contained in:
parent
448c85014c
commit
1ddb0227ff
|
@ -32,7 +32,6 @@ import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDepende
|
|||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||
import type {TransformCache} from '../lib/TransformCaching';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type {HasteImpl} from '../node-haste/Module';
|
||||
import type {BabelSourceMap} from 'babel-core';
|
||||
import type {
|
||||
MetroSourceMapSegmentTuple,
|
||||
|
@ -90,7 +89,7 @@ export type Options = {|
|
|||
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
||||
+getTransformOptions?: GetTransformOptions,
|
||||
+globalTransformCache: ?GlobalTransformCache,
|
||||
+hasteImpl?: HasteImpl,
|
||||
+hasteImplModulePath?: string,
|
||||
+maxWorkers: number,
|
||||
+platforms: Array<string>,
|
||||
+polyfillModuleNames: Array<string>,
|
||||
|
@ -148,7 +147,7 @@ class Bundler {
|
|||
transformModulePath: opts.transformModulePath,
|
||||
}),
|
||||
globalTransformCache: opts.globalTransformCache,
|
||||
hasteImpl: opts.hasteImpl,
|
||||
hasteImplModulePath: opts.hasteImplModulePath,
|
||||
maxWorkers: opts.maxWorkers,
|
||||
platforms: new Set(opts.platforms),
|
||||
polyfillModuleNames: opts.polyfillModuleNames,
|
||||
|
|
|
@ -25,7 +25,6 @@ import type {PostProcessModules} from './DeltaBundler';
|
|||
import type {PostProcessModules as PostProcessModulesForBuck} from './ModuleGraph/types.flow.js';
|
||||
import type {TransformVariants} from './ModuleGraph/types.flow';
|
||||
import type {DynamicRequiresBehavior} from './ModuleGraph/worker/collectDependencies';
|
||||
import type {HasteImpl} from './node-haste/Module';
|
||||
import type {IncomingMessage, ServerResponse} from 'http';
|
||||
|
||||
type Middleware = (IncomingMessage, ServerResponse, ?() => mixed) => mixed;
|
||||
|
@ -139,11 +138,11 @@ export type ConfigT = {
|
|||
postProcessModulesForBuck: PostProcessModulesForBuck,
|
||||
|
||||
/**
|
||||
* A module that exports:
|
||||
* Path to a require-able module that exports:
|
||||
* - a `getHasteName(filePath)` method that returns `hasteName` for module at
|
||||
* `filePath`, or undefined if `filePath` is not a haste module.
|
||||
*/
|
||||
hasteImpl?: HasteImpl,
|
||||
hasteImplModulePath?: string,
|
||||
|
||||
transformVariants: () => TransformVariants,
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ import type {Ast} from 'babel-core';
|
|||
export type TransformOptions<ExtraOptions> = {|
|
||||
+asyncRequireModulePath: string,
|
||||
filename: string,
|
||||
hasteImpl?: HasteImpl,
|
||||
hasteImplModulePath?: string,
|
||||
polyfill?: boolean,
|
||||
+sourceExts: Set<string>,
|
||||
transformer: Transformer<ExtraOptions>,
|
||||
|
@ -102,11 +102,16 @@ function transformModule(
|
|||
let hasteID = null;
|
||||
if (filename.indexOf(NODE_MODULES) === -1 && !polyfill) {
|
||||
hasteID = docblock.parse(docblock.extract(sourceCode)).providesModule;
|
||||
if (options.hasteImpl) {
|
||||
if (options.hasteImpl.enforceHasteNameMatches) {
|
||||
options.hasteImpl.enforceHasteNameMatches(filename, hasteID);
|
||||
if (options.hasteImplModulePath != null) {
|
||||
// eslint-disable-next-line no-useless-call
|
||||
const HasteImpl = (require.call(
|
||||
null,
|
||||
options.hasteImplModulePath,
|
||||
): HasteImpl);
|
||||
if (HasteImpl.enforceHasteNameMatches) {
|
||||
HasteImpl.enforceHasteNameMatches(filename, hasteID);
|
||||
}
|
||||
hasteID = options.hasteImpl.getHasteName(filename);
|
||||
hasteID = HasteImpl.getHasteName(filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,6 @@ const url = require('url');
|
|||
const {getAsset} = require('../Assets');
|
||||
|
||||
import type {CustomError} from '../lib/formatBundlingError';
|
||||
import type {HasteImpl} from '../node-haste/Module';
|
||||
import type {IncomingMessage, ServerResponse} from 'http';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type {Options as DeltaBundlerOptions} from '../DeltaBundler/Serializers';
|
||||
|
@ -76,7 +75,7 @@ class Server {
|
|||
extraNodeModules: {},
|
||||
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
||||
getTransformOptions?: GetTransformOptions,
|
||||
hasteImpl?: HasteImpl,
|
||||
hasteImplModulePath?: string,
|
||||
maxWorkers: number,
|
||||
moduleFormat: string,
|
||||
platforms: Array<string>,
|
||||
|
@ -132,7 +131,7 @@ class Server {
|
|||
getPolyfills: options.getPolyfills,
|
||||
getTransformOptions: options.getTransformOptions,
|
||||
globalTransformCache: options.globalTransformCache,
|
||||
hasteImpl: options.hasteImpl,
|
||||
hasteImplModulePath: options.hasteImplModulePath,
|
||||
maxWorkers,
|
||||
moduleFormat:
|
||||
options.moduleFormat != null ? options.moduleFormat : 'haste',
|
||||
|
|
|
@ -122,7 +122,7 @@ async function runMetro({
|
|||
normalizedConfig.getModulesRunBeforeMainModule,
|
||||
getTransformOptions: normalizedConfig.getTransformOptions,
|
||||
globalTransformCache: null,
|
||||
hasteImpl: normalizedConfig.hasteImpl,
|
||||
hasteImplModulePath: normalizedConfig.hasteImplModulePath,
|
||||
maxWorkers,
|
||||
platforms: defaults.platforms.concat(platforms),
|
||||
postMinifyProcess: normalizedConfig.postMinifyProcess,
|
||||
|
|
|
@ -179,7 +179,7 @@ function toServerOptions(options: Options): ServerOptions {
|
|||
getPolyfills: options.getPolyfills,
|
||||
getTransformOptions: options.getTransformOptions,
|
||||
globalTransformCache: options.globalTransformCache,
|
||||
hasteImpl: options.hasteImpl,
|
||||
hasteImplModulePath: options.hasteImplModulePath,
|
||||
maxWorkers: options.maxWorkers,
|
||||
moduleFormat: options.moduleFormat,
|
||||
platforms: options.platforms,
|
||||
|
|
|
@ -40,7 +40,7 @@ import type {
|
|||
} from '../lib/TransformCaching';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type {ModuleMap} from './DependencyGraph/ModuleResolution';
|
||||
import type {TransformCode, HasteImpl} from './Module';
|
||||
import type {TransformCode} from './Module';
|
||||
import type Package from './Package';
|
||||
import type {HasteFS} from './types';
|
||||
|
||||
|
@ -52,7 +52,7 @@ type Options = {|
|
|||
+getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
||||
+getTransformCacheKey: GetTransformCacheKey,
|
||||
+globalTransformCache: ?GlobalTransformCache,
|
||||
+hasteImpl?: ?HasteImpl,
|
||||
+hasteImplModulePath?: string,
|
||||
+maxWorkers: number,
|
||||
+platforms: Set<string>,
|
||||
+polyfillModuleNames?: Array<string>,
|
||||
|
@ -111,6 +111,7 @@ class DependencyGraph extends EventEmitter {
|
|||
return new JestHasteMap({
|
||||
extensions: opts.sourceExts.concat(opts.assetExts),
|
||||
forceNodeFilesystemAPI: !useWatchman,
|
||||
hasteImplModulePath: opts.hasteImplModulePath,
|
||||
ignorePattern: opts.blacklistRE || / ^/,
|
||||
maxWorkers: opts.maxWorkers,
|
||||
mocksPattern: '',
|
||||
|
@ -205,7 +206,7 @@ class DependencyGraph extends EventEmitter {
|
|||
getClosestPackage: this._getClosestPackage.bind(this),
|
||||
getTransformCacheKey: _opts.getTransformCacheKey,
|
||||
globalTransformCache: _opts.globalTransformCache,
|
||||
hasteImpl: _opts.hasteImpl,
|
||||
hasteImplModulePath: _opts.hasteImplModulePath,
|
||||
resetCache: _opts.resetCache,
|
||||
transformCache: _opts.transformCache,
|
||||
reporter: _opts.reporter,
|
||||
|
|
|
@ -64,7 +64,7 @@ export type HasteImpl = {
|
|||
|
||||
export type Options = {
|
||||
globalTransformCache: ?GlobalTransformCache,
|
||||
hasteImpl: ?HasteImpl,
|
||||
hasteImplModulePath?: string,
|
||||
reporter: Reporter,
|
||||
resetCache: boolean,
|
||||
transformCache: TransformCache,
|
||||
|
@ -217,16 +217,17 @@ class Module {
|
|||
* the "@providesModule" name (ex. "foo").
|
||||
*/
|
||||
_readHasteName(): ?string {
|
||||
const hasteImpl = this._options.hasteImpl;
|
||||
if (hasteImpl == null) {
|
||||
const hasteImplModulePath = this._options.hasteImplModulePath;
|
||||
if (hasteImplModulePath == null) {
|
||||
return this._readHasteNameFromDocBlock();
|
||||
}
|
||||
const {enforceHasteNameMatches} = hasteImpl;
|
||||
if (enforceHasteNameMatches != null) {
|
||||
// eslint-disable-next-line no-useless-call
|
||||
const HasteImpl = (require.call(null, hasteImplModulePath): HasteImpl);
|
||||
if (HasteImpl.enforceHasteNameMatches != null) {
|
||||
const name = this._readHasteNameFromDocBlock();
|
||||
enforceHasteNameMatches(this.path, name || undefined);
|
||||
HasteImpl.enforceHasteNameMatches(this.path, name || undefined);
|
||||
}
|
||||
return hasteImpl.getHasteName(this.path);
|
||||
return HasteImpl.getHasteName(this.path);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,14 +26,14 @@ import type {
|
|||
} from '../lib/TransformCaching';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type DependencyGraphHelpers from './DependencyGraph/DependencyGraphHelpers';
|
||||
import type {TransformCode, HasteImpl} from './Module';
|
||||
import type {TransformCode} from './Module';
|
||||
|
||||
type GetClosestPackageFn = (filePath: string) => ?string;
|
||||
|
||||
type Options = {|
|
||||
assetDependencies: Array<string>,
|
||||
depGraphHelpers: DependencyGraphHelpers,
|
||||
hasteImpl: ?HasteImpl,
|
||||
hasteImplModulePath?: string,
|
||||
getClosestPackage: GetClosestPackageFn,
|
||||
getTransformCacheKey: GetTransformCacheKey,
|
||||
globalTransformCache: ?GlobalTransformCache,
|
||||
|
@ -183,7 +183,7 @@ class ModuleCache {
|
|||
transformCache: this._opts.transformCache,
|
||||
globalTransformCache: this._opts.globalTransformCache,
|
||||
resetCache: this._opts.resetCache,
|
||||
hasteImpl: this._opts.hasteImpl,
|
||||
hasteImplModulePath: this._opts.hasteImplModulePath,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import type {DynamicRequiresBehavior} from '../ModuleGraph/worker/collectDepende
|
|||
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
|
||||
import type {TransformCache} from '../lib/TransformCaching';
|
||||
import type {Reporter} from '../lib/reporting';
|
||||
import type {HasteImpl} from '../node-haste/Module';
|
||||
import type {
|
||||
MetroSourceMap,
|
||||
MetroSourceMapSegmentTuple,
|
||||
|
@ -82,7 +81,7 @@ export type Options = {|
|
|||
getPolyfills: ({platform: ?string}) => $ReadOnlyArray<string>,
|
||||
getTransformOptions?: GetTransformOptions,
|
||||
globalTransformCache: ?GlobalTransformCache,
|
||||
hasteImpl?: HasteImpl,
|
||||
hasteImplModulePath?: string,
|
||||
maxWorkers?: number,
|
||||
moduleFormat?: string,
|
||||
platforms?: Array<string>,
|
||||
|
|
Loading…
Reference in New Issue