Skip to content

Commit

Permalink
added rest of changes
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanBacon committed Jun 22, 2022
1 parent 414b191 commit 53fa3f3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
26 changes: 24 additions & 2 deletions packages/metro/src/DeltaBundler/types.flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,24 @@

'use strict';

import type {RequireContextParams} from '../ModuleGraph/worker/collectDependencies';
import type {
RequireContextParams,
ContextMode,
} from '../ModuleGraph/worker/collectDependencies';
import type {PrivateState} from './graphOperations';
import type {JsTransformOptions} from 'metro-transform-worker';

import CountingSet from '../lib/CountingSet';

export type RequireContext = {
/* Should search for files recursively. Optional, default `true` when `require.context` is used */
recursive: boolean,
/* Filename filter pattern for use in `require.context`. Optional, default `.*` (any file) when `require.context` is used */
filter: RegExp,
/** Mode for resolving dynamic dependencies. Defaults to `sync` */
mode: ContextMode,
};

export type MixedOutput = {
+data: mixed,
+type: string,
Expand Down Expand Up @@ -63,6 +75,7 @@ export type Dependency = {
};

export type Module<T = MixedOutput> = {
+contextParams?: RequireContext,
+dependencies: Map<string, Dependency>,
+inverseDependencies: CountingSet<string>,
+output: $ReadOnlyArray<T>,
Expand Down Expand Up @@ -104,6 +117,12 @@ export type TransformResultWithSource<T = MixedOutput> = $ReadOnly<{
getSource: () => Buffer,
}>;

/** Transformer for generating `require.context` virtual module. */
export type TransformContextFn<T = MixedOutput> = (
string,
RequireContext,
) => Promise<TransformResultWithSource<T>>;

export type TransformFn<T = MixedOutput> = string => Promise<
TransformResultWithSource<T>,
>;
Expand All @@ -115,11 +134,14 @@ export type AllowOptionalDependencies =
| AllowOptionalDependenciesWithOptions;

export type Options<T = MixedOutput> = {
+resolve: (from: string, to: string) => string,
+resolve: (from: string, to: string, context?: ?RequireContext) => string,
+transform: TransformFn<T>,
/** Given a path and require context, return a virtual context module. */
+transformContext: TransformContextFn<T>,
+transformOptions: TransformInputOptions,
+onProgress: ?(numProcessed: number, total: number) => mixed,
+experimentalImportBundleSupport: boolean,
+unstable_allowRequireContext: boolean,
+shallow: boolean,
};

Expand Down
13 changes: 13 additions & 0 deletions packages/metro/src/IncrementalBundler.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ class IncrementalBundler {
onProgress: otherOptions.onProgress,
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
shallow: otherOptions.shallow,
});

Expand Down Expand Up @@ -160,6 +162,13 @@ class IncrementalBundler {
this._bundler,
transformOptions.platform,
),
transformContext: await transformHelpers.getTransformContextFn(
absoluteEntryFiles,
this._bundler,
this._deltaBundler,
this._config,
transformOptions,
),
transform: await transformHelpers.getTransformFn(
absoluteEntryFiles,
this._bundler,
Expand All @@ -171,6 +180,8 @@ class IncrementalBundler {
onProgress: otherOptions.onProgress,
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
shallow: otherOptions.shallow,
},
);
Expand Down Expand Up @@ -225,6 +236,8 @@ class IncrementalBundler {
shallow: otherOptions.shallow,
experimentalImportBundleSupport:
this._config.transformer.experimentalImportBundleSupport,
unstable_allowRequireContext:
this._config.transformer.unstable_allowRequireContext,
});
const revisionId = createRevisionId();
const revisionPromise = (async () => {
Expand Down

0 comments on commit 53fa3f3

Please sign in to comment.