mirror of https://github.com/status-im/metro.git
Metro HMR: Add file parameter to getShallowDependencies()
Reviewed By: jeanlauliac Differential Revision: D5687991 fbshipit-source-id: c2db3986c6a5ec81ed1350ded92dfcf1b529c2bc
This commit is contained in:
parent
679309987b
commit
50ef3138cf
|
@ -6,6 +6,7 @@
|
|||
* 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.
|
||||
*
|
||||
* @emails oncall+javascript_tools
|
||||
* @format
|
||||
*/
|
||||
|
||||
|
@ -167,31 +168,33 @@ describe('Bundler', function() {
|
|||
|
||||
it('gets the list of dependencies from the resolver', function() {
|
||||
const entryFile = '/root/foo.js';
|
||||
return bundler.getDependencies({entryFile, recursive: true}).then(() =>
|
||||
// jest calledWith does not support jasmine.any
|
||||
expect(getDependencies.mock.calls[0].slice(0, -2)).toEqual([
|
||||
'/root/foo.js',
|
||||
{dev: true, platform: undefined, recursive: true},
|
||||
{
|
||||
preloadedModules: undefined,
|
||||
ramGroups: undefined,
|
||||
transformer: {
|
||||
dev: true,
|
||||
minify: false,
|
||||
platform: undefined,
|
||||
transform: {
|
||||
enableBabelRCLookup: true,
|
||||
return bundler
|
||||
.getDependencies({entryFile, rootEntryFile: entryFile, recursive: true})
|
||||
.then(() =>
|
||||
// jest calledWith does not support jasmine.any
|
||||
expect(getDependencies.mock.calls[0].slice(0, -2)).toEqual([
|
||||
'/root/foo.js',
|
||||
{dev: true, platform: undefined, recursive: true},
|
||||
{
|
||||
preloadedModules: undefined,
|
||||
ramGroups: undefined,
|
||||
transformer: {
|
||||
dev: true,
|
||||
generateSourceMaps: false,
|
||||
hot: false,
|
||||
inlineRequires: false,
|
||||
minify: false,
|
||||
platform: undefined,
|
||||
projectRoot: projectRoots[0],
|
||||
transform: {
|
||||
enableBabelRCLookup: true,
|
||||
dev: true,
|
||||
generateSourceMaps: false,
|
||||
hot: false,
|
||||
inlineRequires: false,
|
||||
platform: undefined,
|
||||
projectRoot: projectRoots[0],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
]),
|
||||
);
|
||||
]),
|
||||
);
|
||||
});
|
||||
|
||||
it('allows overriding the platforms array', () => {
|
||||
|
|
|
@ -481,6 +481,7 @@ class Bundler {
|
|||
if (!resolutionResponse) {
|
||||
resolutionResponse = this.getDependencies({
|
||||
entryFile,
|
||||
rootEntryFile: entryFile,
|
||||
dev,
|
||||
platform,
|
||||
hot,
|
||||
|
@ -565,6 +566,7 @@ class Bundler {
|
|||
|
||||
getShallowDependencies({
|
||||
entryFile,
|
||||
rootEntryFile,
|
||||
platform,
|
||||
dev = true,
|
||||
minify = !dev,
|
||||
|
@ -572,13 +574,14 @@ class Bundler {
|
|||
generateSourceMaps = false,
|
||||
}: {
|
||||
entryFile: string,
|
||||
+rootEntryFile: string,
|
||||
platform: ?string,
|
||||
dev?: boolean,
|
||||
minify?: boolean,
|
||||
hot?: boolean,
|
||||
generateSourceMaps?: boolean,
|
||||
}): Promise<Array<Module>> {
|
||||
return this.getTransformOptions(entryFile, {
|
||||
return this.getTransformOptions(rootEntryFile, {
|
||||
enableBabelRCLookup: this._opts.enableBabelRCLookup,
|
||||
dev,
|
||||
generateSourceMaps,
|
||||
|
@ -608,6 +611,7 @@ class Bundler {
|
|||
recursive = true,
|
||||
generateSourceMaps = false,
|
||||
isolateModuleIDs = false,
|
||||
rootEntryFile,
|
||||
onProgress,
|
||||
}: {
|
||||
entryFile: string,
|
||||
|
@ -618,10 +622,11 @@ class Bundler {
|
|||
recursive?: boolean,
|
||||
generateSourceMaps?: boolean,
|
||||
isolateModuleIDs?: boolean,
|
||||
+rootEntryFile: string,
|
||||
onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
|
||||
}): Promise<ResolutionResponse<Module, BundlingOptions>> {
|
||||
const bundlingOptions: BundlingOptions = await this.getTransformOptions(
|
||||
entryFile,
|
||||
rootEntryFile,
|
||||
{
|
||||
enableBabelRCLookup: this._opts.enableBabelRCLookup,
|
||||
dev,
|
||||
|
@ -659,6 +664,7 @@ class Bundler {
|
|||
}) {
|
||||
return this.getDependencies({
|
||||
entryFile,
|
||||
rootEntryFile: entryFile,
|
||||
dev,
|
||||
platform,
|
||||
minify,
|
||||
|
@ -864,9 +870,11 @@ class Bundler {
|
|||
|},
|
||||
): Promise<BundlingOptions> {
|
||||
const getDependencies = (entryFile: string) =>
|
||||
this.getDependencies({...options, entryFile}).then(r =>
|
||||
r.dependencies.map(d => d.path),
|
||||
);
|
||||
this.getDependencies({
|
||||
...options,
|
||||
entryFile,
|
||||
rootEntryFile: entryFile,
|
||||
}).then(r => r.dependencies.map(d => d.path));
|
||||
|
||||
const {dev, hot, platform} = options;
|
||||
const extraOptions: ExtraTransformOptions = this._getTransformOptions
|
||||
|
|
|
@ -123,6 +123,7 @@ type DependencyOptions = {|
|
|||
+minify: boolean,
|
||||
+platform: ?string,
|
||||
+recursive: boolean,
|
||||
+rootEntryFile: string,
|
||||
|};
|
||||
|
||||
type BuildInfo = {|
|
||||
|
@ -340,9 +341,10 @@ class Server {
|
|||
options.platform != null
|
||||
? options.platform
|
||||
: parsePlatformFilePath(options.entryFile, this._platforms).platform;
|
||||
const {entryFile, dev, minify, hot} = options;
|
||||
const {entryFile, dev, minify, hot, rootEntryFile} = options;
|
||||
return this._bundler.getShallowDependencies({
|
||||
entryFile,
|
||||
rootEntryFile,
|
||||
platform,
|
||||
dev,
|
||||
minify,
|
||||
|
@ -364,7 +366,7 @@ class Server {
|
|||
options.platform != null
|
||||
? options.platform
|
||||
: parsePlatformFilePath(options.entryFile, this._platforms).platform;
|
||||
const {entryFile, dev, minify, hot} = options;
|
||||
const {entryFile, dev, minify, hot, rootEntryFile} = options;
|
||||
return this._bundler.getDependencies({
|
||||
entryFile,
|
||||
platform,
|
||||
|
@ -372,6 +374,7 @@ class Server {
|
|||
minify,
|
||||
hot,
|
||||
generateSourceMaps: false,
|
||||
rootEntryFile,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -634,6 +637,7 @@ class Server {
|
|||
hot,
|
||||
minify,
|
||||
entryFile: options.entryFile,
|
||||
rootEntryFile: options.entryFile,
|
||||
recursive: false,
|
||||
}),
|
||||
Promise.all(Array.from(outdated, this.getModuleForPath, this)),
|
||||
|
|
Loading…
Reference in New Issue