Use hasteImpl in the Buck worker

Reviewed By: davidaurelio

Differential Revision: D5803422

fbshipit-source-id: de3aa40ab8ea9ec54e61173b3d6556351394089f
This commit is contained in:
Christoph Nakazawa 2017-09-13 00:03:28 -07:00 committed by Facebook Github Bot
parent 8654b558ca
commit 5422f802f5
1 changed files with 14 additions and 2 deletions

View File

@ -23,6 +23,7 @@ const path = require('path');
const {basename} = require('path');
import type {HasteImpl} from '../../node-haste/Module';
import type {
TransformedCodeFile,
TransformedSourceFile,
@ -34,11 +35,13 @@ import type {Ast} from 'babel-core';
export type TransformOptions = {|
filename: string,
hasteImpl?: HasteImpl,
polyfill?: boolean,
transformer: Transformer<*>,
variants?: TransformVariants,
|};
const NODE_MODULES = path.sep + 'node_modules' + path.sep;
const defaultTransformOptions = {
dev: true,
generateSourceMaps: true,
@ -78,14 +81,23 @@ function transformModule(
transformed[variantName] = makeResult(ast, filename, code, polyfill);
}
const annotations = docblock.parse(docblock.extract(code));
let hasteID = null;
if (filename.indexOf(NODE_MODULES) === -1) {
hasteID = docblock.parse(docblock.extract(code)).providesModule;
if (options.hasteImpl) {
if (options.hasteImpl.enforceHasteNameMatches) {
options.hasteImpl.enforceHasteNameMatches(filename, hasteID);
}
hasteID = options.hasteImpl.getHasteName(filename);
}
}
return {
details: {
assetContent: null,
code,
file: filename,
hasteID: annotations.providesModule || null,
hasteID: hasteID || null,
transformed,
type: options.polyfill ? 'script' : 'module',
},