packager: worker: remove `extern` option

Reviewed By: davidaurelio

Differential Revision: D4867367

fbshipit-source-id: ebe5fa860566e87bd6d042ee41b9a7aa9c777fc6
This commit is contained in:
Jean Lauliac 2017-04-11 08:08:12 -07:00 committed by Facebook Github Bot
parent 5790a4b57f
commit 87effd2669
5 changed files with 13 additions and 64 deletions

View File

@ -140,18 +140,6 @@ describe('code transformation worker:', () => {
}
);
it('does not extract requires if files are marked as "extern"', done => {
const opts = {extern: true};
transformCode(transformer, 'filename', 'code', opts, (error, data) => {
expect(error).toBeNull();
const {dependencies, dependencyOffsets} = data.result;
expect(extractDependencies).not.toBeCalled();
expect(dependencies).toEqual([]);
expect(dependencyOffsets).toEqual([]);
done();
});
});
it('does not extract requires of JSON files', done => {
const jsonStr = '{"arbitrary":"json"}';
transformCode(transformer, 'arbitrary.json', jsonStr, {}, (error, data) => {

View File

@ -37,21 +37,20 @@ type Transformer = {
export type TransformOptions = {
+dev: boolean,
generateSourceMaps: boolean,
+generateSourceMaps: boolean,
+hot: boolean,
+inlineRequires: {+blacklist: {[string]: true}} | boolean,
platform: string,
preloadedModules?: Array<string> | false,
projectRoots: Array<string>,
ramGroups?: Array<string>,
+platform: string,
+preloadedModules?: Array<string> | false,
+projectRoots: Array<string>,
+ramGroups?: Array<string>,
} & BabelTransformOptions;
export type Options = {
+dev: boolean,
+extern?: boolean,
+minify: boolean,
platform: string,
transform: TransformOptions,
+platform: string,
+transform: TransformOptions,
};
export type Data = {
@ -119,7 +118,7 @@ function transformCode(
code = code.replace(/^#!.*/, '');
}
const depsResult = isJson || options.extern
const depsResult = isJson
? {dependencies: [], dependencyOffsets: []}
: extractDependencies(code);
@ -149,7 +148,7 @@ exports.transformAndExtractDependencies = (
) => {
/* $FlowFixMe: impossible to type a dynamic require */
const transformModule = require(transform);
transformCode(transformModule, filename, sourceCode, options || {}, callback);
transformCode(transformModule, filename, sourceCode, options, callback);
};
exports.minify = (

View File

@ -335,14 +335,14 @@ class OptionsHasher {
* cleanup will be necessary to enable rock-solid typing.
*/
hashTransformWorkerOptions(hash: crypto$Hash, options: TransformWorkerOptions): crypto$Hash {
const {dev, minify, platform, transform, extern, ...unknowns} = options;
const {dev, minify, platform, transform, ...unknowns} = options;
const unknownKeys = Object.keys(unknowns);
if (unknownKeys.length > 0) {
const message = `these worker option fields are unknown: ${JSON.stringify(unknownKeys)}`;
throw new CannotHashOptionsError(message);
}
// eslint-disable-next-line no-undef, no-bitwise
hash.update(new Buffer([+dev | +minify << 1 | +!!extern << 2]));
hash.update(new Buffer([+dev | +minify << 1]));
hash.update(JSON.stringify(platform));
return this.hashTransformOptions(hash, transform);
}

View File

@ -421,14 +421,7 @@ class Module {
_getCacheProps(transformOptions: TransformOptions, transformOptionsKey: string) {
const sourceCode = this._readSourceCode();
const moduleDocBlock = this._readDocBlock();
const getTransformCacheKey = this._getTransformCacheKey;
// Ignore requires in JSON files or generated code. An example of this
// is prebuilt files like the SourceMap library.
const extern = this.isJSON() || 'extern' in moduleDocBlock;
if (extern) {
transformOptions = {...transformOptions, extern};
}
return {
filePath: this.path,
sourceCode,

View File

@ -213,40 +213,11 @@ describe('Module', () => {
);
});
it('passes module and file contents if the file is annotated with @extern', () => {
const module = createModule({transformCode});
const customFileContents = `
/**
* @extern
*/
`;
mockIndexFile(customFileContents);
return module.read().then(() => {
expect(transformCode).toBeCalledWith(module, customFileContents, {extern: true});
});
});
it('passes the module and file contents to the transform for JSON files', () => {
mockPackageFile();
const module = createJSONModule({transformCode});
return module.read().then(() => {
expect(transformCode).toBeCalledWith(module, packageJson, {extern: true});
});
});
it('does not extend the passed options object if the file is annotated with @extern', () => {
const module = createModule({transformCode});
const customFileContents = `
/**
* @extern
*/
`;
mockIndexFile(customFileContents);
const options = {arbitrary: 'foo'};
return module.read(options).then(() => {
expect(options).not.toEqual(jasmine.objectContaining({extern: true}));
expect(transformCode)
.toBeCalledWith(module, customFileContents, {...options, extern: true});
expect(transformCode).toBeCalledWith(module, packageJson, undefined);
});
});
@ -255,9 +226,7 @@ describe('Module', () => {
const module = createJSONModule({transformCode});
const options = {arbitrary: 'foo'};
return module.read(options).then(() => {
expect(options).not.toEqual(jasmine.objectContaining({extern: true}));
expect(transformCode)
.toBeCalledWith(module, packageJson, {...options, extern: true});
expect(transformCode).toBeCalledWith(module, packageJson, options);
});
});