Push handling of missing parent module to `resolve`
Reviewed By: jeanlauliac Differential Revision: D4863235 fbshipit-source-id: 857814cb25ee661db5e2cbdeac7175d9276044db
This commit is contained in:
parent
3bcf4acfc7
commit
eabc9cecd6
|
@ -46,7 +46,7 @@ type Async$Queue<T, C> = {
|
|||
};
|
||||
|
||||
type LoadQueue =
|
||||
Async$Queue<{id: string, parent: string}, Callback<File, Array<string>>>;
|
||||
Async$Queue<{id: string, parent: ?string}, Callback<File, Array<string>>>;
|
||||
|
||||
const createParentModule =
|
||||
() => ({file: {code: '', type: 'script', path: ''}, dependencies: []});
|
||||
|
@ -57,7 +57,6 @@ const NO_OPTIONS = {};
|
|||
exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn {
|
||||
function Graph(entryPoints, platform, options, callback = noop) {
|
||||
const {
|
||||
cwd = '',
|
||||
log = (console: any),
|
||||
optimize = false,
|
||||
skip,
|
||||
|
@ -74,7 +73,7 @@ exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn {
|
|||
memoize((file, cb) => load(file, {log, optimize}, cb)),
|
||||
), Number.MAX_SAFE_INTEGER);
|
||||
|
||||
const {collect, loadModule} = createGraphHelpers(loadQueue, cwd, skip);
|
||||
const {collect, loadModule} = createGraphHelpers(loadQueue, skip);
|
||||
|
||||
loadQueue.drain = () => {
|
||||
loadQueue.kill();
|
||||
|
@ -101,7 +100,7 @@ exports.create = function create(resolve: ResolveFn, load: LoadFn): GraphFn {
|
|||
return Graph;
|
||||
};
|
||||
|
||||
function createGraphHelpers(loadQueue, cwd, skip) {
|
||||
function createGraphHelpers(loadQueue, skip) {
|
||||
const modules = new Map([[null, createParentModule()]]);
|
||||
|
||||
function collect(
|
||||
|
@ -132,7 +131,7 @@ function createGraphHelpers(loadQueue, cwd, skip) {
|
|||
|
||||
function loadModule(id, parent, parentDepIndex) {
|
||||
loadQueue.push(
|
||||
{id, parent: parent != null ? parent : cwd},
|
||||
{id, parent},
|
||||
(error, file, dependencyIDs) =>
|
||||
onFileLoaded(error, file, dependencyIDs, id, parent, parentDepIndex),
|
||||
);
|
||||
|
|
|
@ -46,7 +46,7 @@ describe('Graph:', () => {
|
|||
const entryPoint = '/arbitrary/path';
|
||||
graph([entryPoint], anyPlatform, noOpts, () => {
|
||||
expect(resolve).toBeCalledWith(
|
||||
entryPoint, '', any(String), any(Object), any(Function));
|
||||
entryPoint, null, any(String), any(Object), any(Function));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -55,9 +55,9 @@ describe('Graph:', () => {
|
|||
const entryPoints = ['Arbitrary', '../entry.js'];
|
||||
graph(entryPoints, anyPlatform, noOpts, () => {
|
||||
expect(resolve).toBeCalledWith(
|
||||
entryPoints[0], '', any(String), any(Object), any(Function));
|
||||
entryPoints[0], null, any(String), any(Object), any(Function));
|
||||
expect(resolve).toBeCalledWith(
|
||||
entryPoints[1], '', any(String), any(Object), any(Function));
|
||||
entryPoints[1], null, any(String), any(Object), any(Function));
|
||||
done();
|
||||
});
|
||||
|
||||
|
@ -74,7 +74,7 @@ describe('Graph:', () => {
|
|||
const platform = 'any';
|
||||
graph(anyEntry, platform, noOpts, () => {
|
||||
expect(resolve).toBeCalledWith(
|
||||
any(String), '', platform, any(Object), any(Function));
|
||||
any(String), null, platform, any(Object), any(Function));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
@ -83,7 +83,7 @@ describe('Graph:', () => {
|
|||
const log = new Console();
|
||||
graph(anyEntry, anyPlatform, {log}, () => {
|
||||
expect(resolve).toBeCalledWith(
|
||||
any(String), '', any(String), objectContaining({log}), any(Function));
|
||||
any(String), null, any(String), objectContaining({log}), any(Function));
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
|
|
@ -102,7 +102,7 @@ exports.createResolveFn = function(options: ResolveOptions): ResolveFn {
|
|||
const hasteMapBuilt = hasteMap.build();
|
||||
const resolutionRequests = {};
|
||||
const filesByDirNameIndex = new FilesByDirNameIndex(hasteMap.getAllFiles());
|
||||
return (id, source: ?string, platform, _, callback) => {
|
||||
return (id, source, platform, _, callback) => {
|
||||
let resolutionRequest = resolutionRequests[platform];
|
||||
if (!resolutionRequest) {
|
||||
resolutionRequest = resolutionRequests[platform] = new ResolutionRequest({
|
||||
|
|
|
@ -40,7 +40,6 @@ export type GraphFn = (
|
|||
) => void;
|
||||
|
||||
type GraphOptions = {|
|
||||
cwd?: string,
|
||||
log?: Console,
|
||||
optimize?: boolean,
|
||||
skip?: Set<string>,
|
||||
|
@ -90,7 +89,7 @@ export type PackageData = {|
|
|||
|
||||
export type ResolveFn = (
|
||||
id: string,
|
||||
source: string,
|
||||
source: ?string,
|
||||
platform: string,
|
||||
options?: ResolveOptions,
|
||||
callback: Callback<string>,
|
||||
|
|
Loading…
Reference in New Issue