mirror of https://github.com/status-im/metro.git
Updates from Tue 24 Mar
- [ReactNative] Open Source PushNotifications and move Badge Number methods and permission into it | Tadeu Zagallo - [react-packager] Fix regression with transform errors | Amjad Masad - Flowify TextStylePropTypes and fix a bug with unsupported props | Marshall Roch - [ReactNative] Remove `arc build` instructions from require | Alex Kotliarskyi - Flowify Library/Utilities/ | Marshall Roch - [react-packager] Default to index.js from main if it's a dir | Amjad Masad
This commit is contained in:
parent
9a6db3d6e6
commit
074065331a
|
@ -166,6 +166,69 @@ describe('DependencyGraph', function() {
|
|||
});
|
||||
});
|
||||
|
||||
pit('should default main package to index.js', function() {
|
||||
var root = '/root';
|
||||
fs.__setMockFilesystem({
|
||||
'root': {
|
||||
'index.js': 'require("aPackage")',
|
||||
'aPackage': {
|
||||
'package.json': JSON.stringify({
|
||||
name: 'aPackage',
|
||||
}),
|
||||
'index.js': 'lol',
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var dgraph = new DependencyGraph({
|
||||
roots: [root],
|
||||
fileWatcher: fileWatcher
|
||||
});
|
||||
return dgraph.load().then(function() {
|
||||
expect(dgraph.getOrderedDependencies('/root/index.js'))
|
||||
.toEqual([
|
||||
{id: '/root/index.js', path: '/root/index.js', dependencies: ['aPackage']},
|
||||
{ id: 'aPackage/index',
|
||||
path: '/root/aPackage/index.js',
|
||||
dependencies: []
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
pit('should default use index.js if main is a dir', function() {
|
||||
var root = '/root';
|
||||
fs.__setMockFilesystem({
|
||||
'root': {
|
||||
'index.js': 'require("aPackage")',
|
||||
'aPackage': {
|
||||
'package.json': JSON.stringify({
|
||||
name: 'aPackage',
|
||||
main: 'lib',
|
||||
}),
|
||||
lib: {
|
||||
'index.js': 'lol',
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var dgraph = new DependencyGraph({
|
||||
roots: [root],
|
||||
fileWatcher: fileWatcher
|
||||
});
|
||||
return dgraph.load().then(function() {
|
||||
expect(dgraph.getOrderedDependencies('/root/index.js'))
|
||||
.toEqual([
|
||||
{id: '/root/index.js', path: '/root/index.js', dependencies: ['aPackage']},
|
||||
{ id: 'aPackage/lib/index',
|
||||
path: '/root/aPackage/lib/index.js',
|
||||
dependencies: []
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
pit('should ignore malformed packages', function() {
|
||||
var root = '/root';
|
||||
fs.__setMockFilesystem({
|
||||
|
|
|
@ -184,6 +184,12 @@ DependecyGraph.prototype.resolveDependency = function(
|
|||
var main = packageJson.main || 'index';
|
||||
modulePath = withExtJs(path.join(packageJson._root, main));
|
||||
dep = this._graph[modulePath];
|
||||
|
||||
// Some packages use just a dir and rely on an index.js inside that dir.
|
||||
if (dep == null) {
|
||||
dep = this._graph[path.join(packageJson._root, main, 'index.js')];
|
||||
}
|
||||
|
||||
if (dep == null) {
|
||||
throw new Error(
|
||||
'Cannot find package main file for package: ' + packageJson._root
|
||||
|
|
|
@ -196,7 +196,7 @@
|
|||
if (!module) {
|
||||
msg = 'Requiring unknown module "' + id + '"';
|
||||
if (__DEV__) {
|
||||
msg += '. It may not be loaded yet. Did you forget to run arc build?';
|
||||
msg += '. If you are sure the module is there, try restarting the packager.';
|
||||
}
|
||||
throw new ModuleError(msg);
|
||||
}
|
||||
|
|
|
@ -186,6 +186,7 @@ describe('processRequest', function() {
|
|||
expect(packageFunc.mock.calls.length).toBe(1);
|
||||
triggerFileChange('all','path/file.js', options.projectRoots[0]);
|
||||
jest.runAllTimers();
|
||||
jest.runAllTimers();
|
||||
})
|
||||
.then(function() {
|
||||
expect(packageFunc.mock.calls.length).toBe(2);
|
||||
|
|
|
@ -92,8 +92,10 @@ Server.prototype._rebuildPackages = function() {
|
|||
Object.keys(packages).forEach(function(key) {
|
||||
var options = getOptionsFromUrl(key);
|
||||
// Wait for a previous build (if exists) to finish.
|
||||
packages[key] = (packages[key] || q()).then(function() {
|
||||
return buildPackage(options).then(function(p) {
|
||||
packages[key] = (packages[key] || q()).finally(function() {
|
||||
// With finally promise callback we can't change the state of the promise
|
||||
// so we need to reassign the promise.
|
||||
packages[key] = buildPackage(options).then(function(p) {
|
||||
// Make a throwaway call to getSource to cache the source string.
|
||||
p.getSource({
|
||||
inlineSourceMap: options.dev,
|
||||
|
@ -102,6 +104,7 @@ Server.prototype._rebuildPackages = function() {
|
|||
return p;
|
||||
});
|
||||
});
|
||||
return packages[key];
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue