Permalink
Browse files

fix(bundler): tolerant missing main file, fix tracing on simple-line-…

…icons
  • Loading branch information...
huochunpeng committed Dec 5, 2018
1 parent b3828eb commit 9ad9eb592e274f8efa8a4f18dedbd304a96a1192
Showing with 14 additions and 10 deletions.
  1. +7 −5 lib/build/package-analyzer.js
  2. +7 −5 spec/lib/build/package-analyzer.spec.js
@@ -122,16 +122,18 @@ function determineLoaderConfig(project, description) {
let location = path.resolve(description.location);
let mainPath = Utils.nodejsLoad(location);

if (!mainPath) {
throw new Error(`The "${description.name}" package has no valid main file.`);
}

if (!description.loaderConfig) {
description.loaderConfig = {name: description.name};
}

description.loaderConfig.path = path.relative(project.paths.root, description.location).replace(/\\/g, '/');
description.loaderConfig.main = Utils.removeJsExtension(mainPath.substring(location.length + 1).replace(/\\/g, '/'));

if (mainPath) {
description.loaderConfig.main = Utils.removeJsExtension(mainPath.substring(location.length + 1).replace(/\\/g, '/'));
} else {
logger.warn(`The "${description.name}" package has no valid main file, fall back to index.js.`);
description.loaderConfig.main = 'index';
}
}

function setLocation(project, description) {
@@ -552,18 +552,20 @@ describe('The PackageAnalyzer', () => {
});
});

it('analyze() throws error when main file does not exist', done => {
it('analyze() falls back to default index.js when main file does not exist', done => {
// setup mock package.json
const fsConfig = {};
fsConfig[path.join('node_modules', 'my-package', 'package.json')] = '{ "main": "foo.js" }';
fsConfig[project.paths.root] = {};
mockfs(fsConfig);

sut.analyze('my-package')
.then(() => done.fail('should have thrown an exception'))
.catch(e => {
expect(e.message).toBe('The "my-package" package has no valid main file.');
.then(description => {
expect(description.loaderConfig.name).toBe('my-package');
expect(description.loaderConfig.path).toBe('../node_modules/my-package');
expect(description.loaderConfig.main).toBe('index');
done();
});
})
.catch(e => done.fail(e));
});
});

0 comments on commit 9ad9eb5

Please sign in to comment.