in packages/metro-transform-worker/src/index.js [498:604]
type: getBytecodeFileType(file.type),
});
}
return {
dependencies,
output,
};
}
/**
* Transforms an asset file
*/
async function transformAsset(
file: AssetFile,
context: TransformationContext,
): Promise<TransformResponse> {
const assetTransformer = require('./utils/assetTransformer');
const {assetRegistryPath, assetPlugins} = context.config;
const result = await assetTransformer.transform(
getBabelTransformArgs(file, context),
assetRegistryPath,
assetPlugins,
);
const jsFile = {
...file,
type: 'js/module/asset',
ast: result.ast,
functionMap: null,
};
return transformJS(jsFile, context);
}
/**
* Transforms a JavaScript file with Babel before processing the file with
* the generic JavaScript transformation.
*/
async function transformJSWithBabel(
file: JSFile,
context: TransformationContext,
): Promise<TransformResponse> {
const {babelTransformerPath} = context.config;
// $FlowFixMe[unsupported-syntax] dynamic require
const transformer: BabelTransformer = require(babelTransformerPath);
const transformResult = await transformer.transform(
getBabelTransformArgs(file, context),
);
const jsFile: JSFile = {
...file,
ast: transformResult.ast,
functionMap: transformResult.functionMap ?? null,
};
return await transformJS(jsFile, context);
}
async function transformJSON(
file: JSONFile,
{options, config, projectRoot}: TransformationContext,
): Promise<TransformResponse> {
let code =
config.unstable_disableModuleWrapping === true
? JsFileWrapping.jsonToCommonJS(file.code)
: JsFileWrapping.wrapJson(file.code, config.globalPrefix);
let map = [];
// TODO: When we can reuse transformJS for JSON, we should not derive `minify` separately.
const minify =
options.minify &&
options.unstable_transformProfile !== 'hermes-canary' &&
options.unstable_transformProfile !== 'hermes-stable';
if (minify) {
({map, code} = await minifyCode(
config,
projectRoot,
file.filename,
code,
file.code,
map,
));
}
let jsType: JSFileType;
if (file.type === 'asset') {
jsType = 'js/module/asset';
} else if (file.type === 'script') {
jsType = 'js/script';
} else {
jsType = 'js/module';
}
const output = [
{
data: {code, lineCount: countLines(code), map, functionMap: null},
type: jsType,
},
];
if (options.runtimeBytecodeVersion != null) {
output.push({