Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add transformOptions to each graph. Update tests. #679

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/metro/src/DeltaBundler/DeltaCalculator.js
Expand Up @@ -50,6 +50,7 @@ class DeltaCalculator<T> extends EventEmitter {
dependencies: new Map(),
entryPoints,
importBundleNames: new Set(),
transformOptions: this._options.transformOptions,
};

this._dependencyGraph
Expand All @@ -72,6 +73,7 @@ class DeltaCalculator<T> extends EventEmitter {
dependencies: new Map(),
entryPoints: this._graph.entryPoints,
importBundleNames: new Set(),
transformOptions: this._options.transformOptions,
};
this._modifiedFiles = new Set();
this._deletedFiles = new Set();
Expand Down
13 changes: 13 additions & 0 deletions packages/metro/src/DeltaBundler/types.flow.js
Expand Up @@ -10,6 +10,8 @@

'use strict';

import type {JsTransformOptions} from 'metro-transform-worker';

export type MixedOutput = {|
+data: mixed,
+type: string,
Expand Down Expand Up @@ -63,10 +65,20 @@ export type Module<T = MixedOutput> = {|

export type Dependencies<T = MixedOutput> = Map<string, Module<T>>;

export type TransformInputOptions = $Diff<
JsTransformOptions,
{
inlinePlatform: boolean,
inlineRequires: boolean,
...
},
>;

export type Graph<T = MixedOutput> = {|
dependencies: Dependencies<T>,
importBundleNames: Set<string>,
+entryPoints: $ReadOnlyArray<string>,
+transformOptions: TransformInputOptions,
afoxman marked this conversation as resolved.
Show resolved Hide resolved
|};

export type TransformResult<T = MixedOutput> = $ReadOnly<{|
Expand All @@ -92,6 +104,7 @@ export type AllowOptionalDependencies =
export type Options<T = MixedOutput> = {|
+resolve: (from: string, to: string) => string,
+transform: TransformFn<T>,
+transformOptions: TransformInputOptions,
+onProgress: ?(numProcessed: number, total: number) => mixed,
+experimentalImportBundleSupport: boolean,
+shallow: boolean,
Expand Down
4 changes: 3 additions & 1 deletion packages/metro/src/IncrementalBundler.js
Expand Up @@ -23,11 +23,11 @@ const transformHelpers = require('./lib/transformHelpers');

import type {
Options as DeltaBundlerOptions,
TransformInputOptions,
Dependencies,
} from './DeltaBundler/types.flow';
import type {DeltaResult, Module, Graph} from './DeltaBundler';
import type {GraphId} from './lib/getGraphId';
import type {TransformInputOptions} from './lib/transformHelpers';
import type {ConfigT} from 'metro-config/src/configTypes.flow';

export opaque type RevisionId: string = string;
Expand Down Expand Up @@ -121,6 +121,7 @@ class IncrementalBundler {
this._config,
transformOptions,
),
transformOptions,
onProgress: otherOptions.onProgress,
experimentalImportBundleSupport: this._config.transformer
.experimentalImportBundleSupport,
Expand Down Expand Up @@ -161,6 +162,7 @@ class IncrementalBundler {
this._config,
transformOptions,
),
transformOptions,
onProgress: otherOptions.onProgress,
experimentalImportBundleSupport: this._config.transformer
.experimentalImportBundleSupport,
Expand Down
31 changes: 31 additions & 0 deletions packages/metro/src/Server/__tests__/Server-test.js
Expand Up @@ -187,6 +187,7 @@ describe('processRequest', () => {
entryPoints: ['/root/mybundle.js'],
dependencies,
importBundleNames: new Set(),
transformOptions: options.transformOptions,
};
currentGraphs.add(graph);

Expand Down Expand Up @@ -615,6 +616,16 @@ describe('processRequest', () => {
resolve: expect.any(Function),
shallow: false,
transform: expect.any(Function),
transformOptions: {
customTransformOptions: {},
dev: true,
hot: true,
minify: false,
platform: 'ios',
runtimeBytecodeVersion: null,
type: 'module',
unstable_transformProfile: 'default',
},
},
);
});
Expand All @@ -641,6 +652,16 @@ describe('processRequest', () => {
resolve: expect.any(Function),
shallow: false,
transform: expect.any(Function),
transformOptions: {
customTransformOptions: {},
dev: true,
hot: true,
minify: false,
platform: null,
runtimeBytecodeVersion: null,
type: 'module',
unstable_transformProfile: 'hermes-stable',
},
},
);
});
Expand Down Expand Up @@ -795,6 +816,16 @@ describe('processRequest', () => {
resolve: expect.any(Function),
shallow: false,
transform: expect.any(Function),
transformOptions: {
customTransformOptions: {},
dev: true,
hot: false,
minify: false,
platform: undefined,
runtimeBytecodeVersion: null,
type: 'module',
unstable_transformProfile: 'default',
},
},
);
});
Expand Down
2 changes: 1 addition & 1 deletion packages/metro/src/lib/getGraphId.js
Expand Up @@ -12,7 +12,7 @@

const canonicalize = require('metro-core/src/canonicalize');

import type {TransformInputOptions} from './transformHelpers';
import type {TransformInputOptions} from '../DeltaBundler/types.flow';

export opaque type GraphId: string = string;

Expand Down
3 changes: 2 additions & 1 deletion packages/metro/src/lib/getPrependedScripts.js
Expand Up @@ -19,7 +19,7 @@ const {compile} = require('metro-hermes-compiler');

import type Bundler from '../Bundler';
import type DeltaBundler, {Module} from '../DeltaBundler';
import type {TransformInputOptions} from '../lib/transformHelpers';
import type {TransformInputOptions} from '../DeltaBundler/types.flow';
import type {ConfigT} from 'metro-config/src/configTypes.flow';

async function getPrependedScripts(
Expand Down Expand Up @@ -58,6 +58,7 @@ async function getPrependedScripts(
config,
transformOptions,
),
transformOptions,
onProgress: null,
experimentalImportBundleSupport:
config.transformer.experimentalImportBundleSupport,
Expand Down
11 changes: 2 additions & 9 deletions packages/metro/src/lib/transformHelpers.js
Expand Up @@ -17,18 +17,10 @@ import type {TransformOptions} from '../DeltaBundler/Worker';
import type DeltaBundler, {TransformFn} from '../DeltaBundler';
import type {ConfigT} from 'metro-config/src/configTypes.flow';
import type {Type} from 'metro-transform-worker';
import type {TransformInputOptions} from '../DeltaBundler/types.flow';

type InlineRequiresRaw = {+blockList: {[string]: true, ...}, ...} | boolean;

export type TransformInputOptions = $Diff<
TransformOptions,
{
inlinePlatform: boolean,
inlineRequires: boolean,
...
},
>;

type TransformOptionsWithRawInlines = {|
...TransformOptions,
+inlineRequires: InlineRequiresRaw,
Expand Down Expand Up @@ -72,6 +64,7 @@ async function calcTransformerOptions(
...options,
minify: false,
}),
transformOptions: options,
onProgress: null,
experimentalImportBundleSupport:
config.transformer.experimentalImportBundleSupport,
Expand Down
6 changes: 4 additions & 2 deletions packages/metro/src/shared/types.flow.js
Expand Up @@ -10,8 +10,10 @@

'use strict';

import type {Options as DeltaBundlerOptions} from '../DeltaBundler/types.flow';
import type {TransformInputOptions} from '../lib/transformHelpers';
import type {
Options as DeltaBundlerOptions,
TransformInputOptions,
} from '../DeltaBundler/types.flow';
import type {TransformProfile} from 'metro-babel-transformer';
import type {
MixedSourceMap,
Expand Down