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