Permalink
Browse files

Remove irrelevant options from cache key

Reviewed By: jeanlauliac

Differential Revision: D4938131

fbshipit-source-id: 88b686bc5ee6946297e1fd1b91d46fa618f0d9d7
  • Loading branch information...
davidaurelio authored and facebook-github-bot committed Apr 25, 2017
1 parent 291a497 commit 3e08a28987898e9082271c208fd66dd03f785eb7
@@ -54,7 +54,7 @@ function attachHMRServer({httpServer, path, packagerServer}: HMROptions) {
dependenciesModulesCache: {[mixed]: Module},
shallowDependencies: {[string]: Array<Module>},
inverseDependenciesCache: mixed,
resolutionResponse: ResolutionResponse<Module>,
resolutionResponse: ResolutionResponse<Module, *>,
}> {
return packagerServer.getDependencies({
platform: platform,
@@ -134,7 +134,7 @@ describe('Bundler', function() {
Promise.resolve({
mainModuleId: 'foo',
dependencies: modules,
transformOptions,
options: transformOptions,
getModuleId: () => 123,
getResolvedDependencyPairs: () => [],
})
@@ -272,18 +272,20 @@ describe('Bundler', function() {
'/root/foo.js',
{dev: true, platform: undefined, recursive: true},
{
dev: true,
minify: false,
platform: undefined,
transform: {
preloadedModules: undefined,
ramGroups: undefined,
transformer: {
dev: true,
generateSourceMaps: false,
hot: false,
inlineRequires: false,
minify: false,
platform: undefined,
preloadedModules: undefined,
projectRoots,
ramGroups: undefined,
transform: {
dev: true,
generateSourceMaps: false,
hot: false,
inlineRequires: false,
platform: undefined,
projectRoots,
},
},
},
])
@@ -40,13 +40,16 @@ const VERSION = require('../../package.json').version;
import type AssetServer from '../AssetServer';
import type Module, {HasteImpl} from '../node-haste/Module';
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
import type {
Options as JSTransformerOptions,
TransformOptions,
} from '../JSTransformer/worker/worker';
import type {Options as JSTransformerOptions} from '../JSTransformer/worker/worker';
import type {Reporter} from '../lib/reporting';
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
export type BundlingOptions = {|
+preloadedModules: ?{[string]: true} | false,
+ramGroups: ?Array<string>,
+transformer: JSTransformerOptions,
|};
export type ExtraTransformOptions = {|
+inlineRequires?: {+blacklist: {[string]: true}} | boolean,
+preloadedModules?: {[path: string]: true} | false,
@@ -324,12 +327,12 @@ class Bundler {
moduleSystemDeps?: Array<Module>,
onProgress?: () => void,
platform?: ?string,
resolutionResponse?: ResolutionResponse<Module>,
resolutionResponse?: ResolutionResponse<Module, BundlingOptions>,
runBeforeMainModule?: boolean,
runModule?: boolean,
unbundle?: boolean,
}) {
const onResolutionResponse = (response: ResolutionResponse<Module>) => {
const onResolutionResponse = (response: ResolutionResponse<Module, BundlingOptions>) => {
/* $FlowFixMe: looks like ResolutionResponse is monkey-patched
* with `getModuleId`. */
bundle.setMainModuleId(response.getModuleId(getMainModule(response)));
@@ -344,7 +347,7 @@ class Bundler {
const finalizeBundle = ({bundle: finalBundle, transformedModules, response, modulesByName}: {
bundle: Bundle,
transformedModules: Array<{module: Module, transformed: ModuleTransport}>,
response: ResolutionResponse<Module>,
response: ResolutionResponse<Module, BundlingOptions>,
modulesByName: {[name: string]: Module},
}) =>
this._resolverPromise.then(resolver => Promise.all(
@@ -427,7 +430,7 @@ class Bundler {
return Promise.all(
[this._resolverPromise, resolutionResponse],
).then(([resolver, response]) => {
bundle.setRamGroups(response.transformOptions.transform.ramGroups);
bundle.setRamGroups(response.options.ramGroups);
log(createActionEndEntry(transformingFilesLogEntry));
onResolutionResponse(response);
@@ -452,7 +455,7 @@ class Bundler {
bundle,
entryFilePath,
assetPlugins,
transformOptions: response.transformOptions,
options: response.options,
/* $FlowFixMe: `getModuleId` is monkey-patched */
getModuleId: (response.getModuleId: () => number),
dependencyPairs: response.getResolvedDependencyPairs(module),
@@ -495,30 +498,24 @@ class Bundler {
entryFile,
{
dev,
platform,
hot,
generateSourceMaps,
projectRoots: this._projectRoots,
},
).then(transformSpecificOptions => {
const transformOptions = {
hot,
minify,
dev,
platform,
transform: transformSpecificOptions,
};
return this._resolverPromise.then(
resolver => resolver.getShallowDependencies(entryFile, transformOptions),
);
});
projectRoots: this._projectRoots,
},
).then(bundlingOptions =>
this._resolverPromise.then(resolver =>
resolver.getShallowDependencies(entryFile, bundlingOptions.transformer),
)
);
}
getModuleForPath(entryFile: string): Promise<Module> {
return this._resolverPromise.then(resolver => resolver.getModuleForPath(entryFile));
}
getDependencies({
async getDependencies({
entryFile,
platform,
dev = true,
@@ -538,32 +535,28 @@ class Bundler {
generateSourceMaps?: boolean,
isolateModuleIDs?: boolean,
onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
}) {
return this.getTransformOptions(
}): Promise<ResolutionResponse<Module, BundlingOptions>> {
const bundlingOptions: BundlingOptions = await this.getTransformOptions(
entryFile,
{
dev,
platform,
hot,
generateSourceMaps,
minify,
projectRoots: this._projectRoots,
},
).then(transformSpecificOptions => {
const transformOptions = {
minify,
dev,
platform,
transform: transformSpecificOptions,
};
);
return this._resolverPromise.then(resolver => resolver.getDependencies(
entryFile,
{dev, platform, recursive},
transformOptions,
onProgress,
isolateModuleIDs ? createModuleIdFactory() : this._getModuleId,
));
});
const resolver = await this._resolverPromise;
const response = await resolver.getDependencies(
entryFile,
{dev, platform, recursive},
bundlingOptions,
onProgress,
isolateModuleIDs ? createModuleIdFactory() : this._getModuleId,
);
return response;
}
getOrderedDependencyPaths({entryFile, dev, platform}: {
@@ -606,21 +599,22 @@ class Bundler {
module,
bundle,
entryFilePath,
transformOptions,
options,
getModuleId,
dependencyPairs,
assetPlugins,
}: {
module: Module,
bundle: Bundle,
entryFilePath: string,
transformOptions: JSTransformerOptions,
options: BundlingOptions,
getModuleId: () => number,
dependencyPairs: Array<[mixed, {path: string}]>,
assetPlugins: Array<string>,
}): Promise<ModuleTransport> {
let moduleTransport;
const moduleId = getModuleId(module);
const transformOptions = options.transformer;
if (module.isAsset()) {
moduleTransport = this._generateAssetModule(
@@ -637,7 +631,7 @@ class Bundler {
]).then((
[name, {code, dependencies, dependencyOffsets, map, source}]
) => {
const {preloadedModules} = transformOptions.transform;
const {preloadedModules} = options;
const preloaded =
module.path === entryFilePath ||
module.isPolyfill() ||
@@ -777,10 +771,11 @@ class Bundler {
dev: boolean,
generateSourceMaps: boolean,
hot: boolean,
minify: boolean,
platform: string,
projectRoots: Array<string>,
|},
): Promise<TransformOptions> {
): Promise<BundlingOptions> {
const getDependencies = (entryFile: string) =>
this.getDependencies({...options, entryFile})
.then(r => r.dependencies.map(d => d.path));
@@ -790,13 +785,20 @@ class Bundler {
? await this._getTransformOptions(mainModuleName, {dev, hot, platform}, getDependencies)
: {};
return {
dev,
generateSourceMaps: options.generateSourceMaps,
hot,
inlineRequires: extraOptions.inlineRequires || false,
platform,
transformer: {
dev,
minify: options.minify,
platform,
transform: {
dev,
generateSourceMaps: options.generateSourceMaps,
hot,
inlineRequires: extraOptions.inlineRequires || false,
platform,
projectRoots: options.projectRoots,
}
},
preloadedModules: extraOptions.preloadedModules,
projectRoots: options.projectRoots,
ramGroups: extraOptions.ramGroups,
};
}
@@ -41,9 +41,7 @@ export type TransformOptions = {|
+hot: boolean,
+inlineRequires: {+blacklist: {[string]: true}} | boolean,
+platform: string,
+preloadedModules: ?{[string]: true} | false,
+projectRoots: Array<string>,
+ramGroups: ?Array<string>,
|};
export type Options = {|
@@ -109,7 +109,7 @@ describe('Resolver', function() {
expect(DependencyGraph.prototype.getDependencies).toBeCalledWith({
entryPath: entry,
platform,
transformOptions,
options: transformOptions,
recursive: true,
});
});
@@ -17,17 +17,18 @@ const defaults = require('../../defaults');
const pathJoin = require('path').join;
import type ResolutionResponse from '../node-haste/DependencyGraph/ResolutionResponse';
import type Module, {HasteImpl} from '../node-haste/Module';
import type Module, {HasteImpl, TransformCode} from '../node-haste/Module';
import type {SourceMap} from '../lib/SourceMap';
import type {Options as TransformOptions} from '../JSTransformer/worker/worker';
import type {Options as JSTransformerOptions} from '../JSTransformer/worker/worker';
import type {Reporter} from '../lib/reporting';
import type {TransformCode} from '../node-haste/Module';
import type {GetTransformCacheKey} from '../lib/TransformCache';
import type {GlobalTransformCache} from '../lib/GlobalTransformCache';
type MinifyCode = (filePath: string, code: string, map: SourceMap) =>
Promise<{code: string, map: SourceMap}>;
type ContainsTransformerOptions = {+transformer: JSTransformerOptions}
type Options = {|
+assetExts: Array<string>,
+blacklistRE?: RegExp,
@@ -82,7 +83,7 @@ class Resolver {
getShallowDependencies(
entryFile: string,
transformOptions: TransformOptions,
transformOptions: JSTransformerOptions,
): Promise<Array<Module>> {
return this._depGraph.getShallowDependencies(entryFile, transformOptions);
}
@@ -91,18 +92,18 @@ class Resolver {
return this._depGraph.getModuleForPath(entryFile);
}
getDependencies(
getDependencies<T: ContainsTransformerOptions>(
entryPath: string,
options: {platform: string, recursive?: boolean},
transformOptions: TransformOptions,
bundlingOptions: T,
onProgress?: ?(finishedModules: number, totalModules: number) => mixed,
getModuleId: mixed,
): Promise<ResolutionResponse<Module>> {
): Promise<ResolutionResponse<Module, T>> {
const {platform, recursive = true} = options;
return this._depGraph.getDependencies({
entryPath,
platform,
transformOptions,
options: bundlingOptions,
recursive,
onProgress,
}).then(resolutionResponse => {
@@ -146,8 +147,8 @@ class Resolver {
);
}
resolveRequires(
resolutionResponse: ResolutionResponse<Module>,
resolveRequires<T: ContainsTransformerOptions>(
resolutionResponse: ResolutionResponse<Module, T>,
module: Module,
code: string,
dependencyOffsets: Array<number> = [],
@@ -181,7 +182,7 @@ class Resolver {
).join('');
}
wrapModule({
wrapModule<T: ContainsTransformerOptions>({
resolutionResponse,
module,
name,
@@ -191,7 +192,7 @@ class Resolver {
dev = true,
minify = false,
}: {
resolutionResponse: ResolutionResponse<Module>,
resolutionResponse: ResolutionResponse<Module, T>,
module: Module,
name: string,
map: SourceMap,
@@ -309,7 +309,7 @@ class Server {
getDependencies(options: {
entryFile: string,
platform: ?string,
}): Promise<ResolutionResponse<Module>> {
}): Promise<ResolutionResponse<Module, *>> {
return Promise.resolve().then(() => {
if (!options.platform) {
options.platform = getPlatformExtension(options.entryFile);
Oops, something went wrong.

0 comments on commit 3e08a28

Please sign in to comment.