mirror of https://github.com/status-im/metro.git
Make inlineRequires boolean when passed to the transformer
Reviewed By: mjesun Differential Revision: D6408081 fbshipit-source-id: 812c8e3983677f4133ef3080525859a4a70418b7
This commit is contained in:
parent
2d03a34bbc
commit
091f8560f2
|
@ -16,6 +16,7 @@ const DeltaCalculator = require('./DeltaCalculator');
|
||||||
|
|
||||||
const addParamsToDefineCall = require('../lib/addParamsToDefineCall');
|
const addParamsToDefineCall = require('../lib/addParamsToDefineCall');
|
||||||
const createModuleIdFactory = require('../lib/createModuleIdFactory');
|
const createModuleIdFactory = require('../lib/createModuleIdFactory');
|
||||||
|
const removeInlineRequiresBlacklistFromOptions = require('../lib/removeInlineRequiresBlacklistFromOptions');
|
||||||
|
|
||||||
const {EventEmitter} = require('events');
|
const {EventEmitter} = require('events');
|
||||||
|
|
||||||
|
@ -559,7 +560,9 @@ class DeltaTransformer extends EventEmitter {
|
||||||
+map: CompactRawMappings,
|
+map: CompactRawMappings,
|
||||||
+source: string,
|
+source: string,
|
||||||
}> {
|
}> {
|
||||||
return await module.read(transformOptions);
|
return await module.read(
|
||||||
|
removeInlineRequiresBlacklistFromOptions(module.path, transformOptions),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_onFileChange = () => {
|
_onFileChange = () => {
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const removeInlineRequiresBlacklistFromOptions = require('../lib/removeInlineRequiresBlacklistFromOptions');
|
||||||
|
|
||||||
import type {Options as JSTransformerOptions} from '../JSTransformer/worker';
|
import type {Options as JSTransformerOptions} from '../JSTransformer/worker';
|
||||||
import type DependencyGraph from '../node-haste/DependencyGraph';
|
import type DependencyGraph from '../node-haste/DependencyGraph';
|
||||||
|
|
||||||
|
@ -217,7 +219,7 @@ async function addDependency(
|
||||||
|
|
||||||
const shallowDeps = await dependencyGraph.getShallowDependencies(
|
const shallowDeps = await dependencyGraph.getShallowDependencies(
|
||||||
dependencyEdge.path,
|
dependencyEdge.path,
|
||||||
transformOptions,
|
removeInlineRequiresBlacklistFromOptions(module.path, transformOptions),
|
||||||
);
|
);
|
||||||
|
|
||||||
const nonNullDependencyEdge = dependencyEdge;
|
const nonNullDependencyEdge = dependencyEdge;
|
||||||
|
|
|
@ -60,7 +60,7 @@ export type TransformOptionsStrict = {|
|
||||||
+dev: boolean,
|
+dev: boolean,
|
||||||
+generateSourceMaps: boolean,
|
+generateSourceMaps: boolean,
|
||||||
+hot: boolean,
|
+hot: boolean,
|
||||||
+inlineRequires: {+blacklist: {[string]: true}} | boolean,
|
+inlineRequires: boolean,
|
||||||
+minify: boolean,
|
+minify: boolean,
|
||||||
+platform: ?string,
|
+platform: ?string,
|
||||||
+projectRoot: string,
|
+projectRoot: string,
|
||||||
|
@ -71,7 +71,7 @@ export type TransformOptions = {
|
||||||
+dev?: boolean,
|
+dev?: boolean,
|
||||||
+generateSourceMaps?: boolean,
|
+generateSourceMaps?: boolean,
|
||||||
+hot?: boolean,
|
+hot?: boolean,
|
||||||
+inlineRequires?: {+blacklist: {[string]: true}} | boolean,
|
+inlineRequires: boolean,
|
||||||
+minify: boolean,
|
+minify: boolean,
|
||||||
+platform: ?string,
|
+platform: ?string,
|
||||||
+projectRoot: string,
|
+projectRoot: string,
|
||||||
|
|
|
@ -445,7 +445,7 @@ class OptionsHasher {
|
||||||
+dev |
|
+dev |
|
||||||
(+generateSourceMaps << 1) |
|
(+generateSourceMaps << 1) |
|
||||||
(+hot << 2) |
|
(+hot << 2) |
|
||||||
(+!!inlineRequires << 3) |
|
(+inlineRequires << 3) |
|
||||||
(+enableBabelRCLookup << 4) |
|
(+enableBabelRCLookup << 4) |
|
||||||
(+minify << 5),
|
(+minify << 5),
|
||||||
]),
|
]),
|
||||||
|
@ -453,15 +453,8 @@ class OptionsHasher {
|
||||||
/* eslint-enable no-bitwise */
|
/* eslint-enable no-bitwise */
|
||||||
|
|
||||||
hash.update(JSON.stringify(platform));
|
hash.update(JSON.stringify(platform));
|
||||||
let blacklistWithLocalPaths = [];
|
hash.update(JSON.stringify(this.toLocalPath(projectRoot)));
|
||||||
if (typeof inlineRequires === 'object') {
|
|
||||||
blacklistWithLocalPaths = this.pathsToLocal(
|
|
||||||
Object.keys(inlineRequires.blacklist),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const localProjectRoot = this.toLocalPath(projectRoot);
|
|
||||||
const optionTuple = [blacklistWithLocalPaths, localProjectRoot];
|
|
||||||
hash.update(JSON.stringify(optionTuple));
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,12 +19,12 @@ Object {
|
||||||
exports[`GlobalTransformCache fetches results 1`] = `
|
exports[`GlobalTransformCache fetches results 1`] = `
|
||||||
Array [
|
Array [
|
||||||
Object {
|
Object {
|
||||||
"code": "/* code from http://globalcache.com/010a1a9e948edce805a4fa7685a1c64ce97dc035-foo.js */",
|
"code": "/* code from http://globalcache.com/c78d72e5b503433212dce49b558b0ee350b6d578-foo.js */",
|
||||||
"dependencies": Array [],
|
"dependencies": Array [],
|
||||||
"dependencyOffsets": Array [],
|
"dependencyOffsets": Array [],
|
||||||
},
|
},
|
||||||
Object {
|
Object {
|
||||||
"code": "/* code from http://globalcache.com/640a1404db77ab17a10fbae1a3b4db92634669c1-bar.js */",
|
"code": "/* code from http://globalcache.com/47637fbb61b7dfeda3a0d0a36241510b4669e4da-bar.js */",
|
||||||
"dependencies": Array [],
|
"dependencies": Array [],
|
||||||
"dependencyOffsets": Array [],
|
"dependencyOffsets": Array [],
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,57 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2016-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*
|
||||||
|
* @format
|
||||||
|
* @emails oncall+js_foundation
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const removeInlineRequiresBlacklistFromOptions = require('../removeInlineRequiresBlacklistFromOptions');
|
||||||
|
|
||||||
|
it('should not touch a transformOption object with boolean inlineRequires', () => {
|
||||||
|
const transformOptions = {
|
||||||
|
inlineRequires: false,
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(
|
||||||
|
removeInlineRequiresBlacklistFromOptions('/path', transformOptions),
|
||||||
|
).toBe(transformOptions);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change inlineRequires to true when the path is not in the blacklist', () => {
|
||||||
|
const transformOptions = {
|
||||||
|
inlineRequires: {
|
||||||
|
blacklist: {'/other': true},
|
||||||
|
},
|
||||||
|
foo: 'bar',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(
|
||||||
|
removeInlineRequiresBlacklistFromOptions('/path', transformOptions),
|
||||||
|
).toEqual({
|
||||||
|
inlineRequires: true,
|
||||||
|
foo: 'bar',
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should change inlineRequires to false when the path is in the blacklist', () => {
|
||||||
|
const transformOptions = {
|
||||||
|
inlineRequires: {
|
||||||
|
blacklist: {'/path': true},
|
||||||
|
},
|
||||||
|
foo: 'bar',
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(
|
||||||
|
removeInlineRequiresBlacklistFromOptions('/path', transformOptions),
|
||||||
|
).toEqual({
|
||||||
|
inlineRequires: false,
|
||||||
|
foo: 'bar',
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) 2015-present, Facebook, Inc.
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the BSD-style license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree. An additional grant
|
||||||
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
|
*
|
||||||
|
* @flow
|
||||||
|
* @format
|
||||||
|
*/
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
import type {Options as JSTransformerOptions} from '../JSTransformer/worker';
|
||||||
|
|
||||||
|
function removeInlineRequiresBlacklistFromOptions(
|
||||||
|
path: string,
|
||||||
|
transformOptions: JSTransformerOptions,
|
||||||
|
): JSTransformerOptions {
|
||||||
|
if (typeof transformOptions.inlineRequires === 'object') {
|
||||||
|
// $FlowIssue #23854098 - Object.assign() loses the strictness of an object in flow
|
||||||
|
return {
|
||||||
|
...transformOptions,
|
||||||
|
inlineRequires: !(path in transformOptions.inlineRequires.blacklist),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return transformOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = removeInlineRequiresBlacklistFromOptions;
|
|
@ -99,10 +99,7 @@ function buildBabelConfig(filename, options, plugins?: BabelPlugins = []) {
|
||||||
// Add extra plugins
|
// Add extra plugins
|
||||||
const extraPlugins = [externalHelpersPlugin];
|
const extraPlugins = [externalHelpersPlugin];
|
||||||
|
|
||||||
var inlineRequires = options.inlineRequires;
|
if (options.inlineRequires) {
|
||||||
var blacklist =
|
|
||||||
typeof inlineRequires === 'object' ? inlineRequires.blacklist : null;
|
|
||||||
if (inlineRequires && !(blacklist && filename in blacklist)) {
|
|
||||||
extraPlugins.push(inlineRequiresPlugin);
|
extraPlugins.push(inlineRequiresPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue