Permalink
Browse files

fix(package-analyzer): ignore module field for 'aurelia-' packages

  • Loading branch information...
bigopon committed Nov 6, 2018
1 parent ac889c0 commit 00de202f7ef70280a4e4478c1e97f8778584b9b8
Showing with 57 additions and 38 deletions.
  1. +1 −1 lib/build/package-analyzer.js
  2. +1 −1 package-lock.json
  3. +55 −36 spec/lib/build/package-analyzer.spec.js
@@ -138,7 +138,7 @@ function determineLoaderConfig(project, description) {
if (typeof metadata.browser === 'string') {
// use package.json browser field if possible.
metaMain = metadata.browser;
} else if (typeof metadata.module === 'string') {
} else if (typeof metadata.module === 'string' && !description.name.startsWith('aurelia-')) {
// prefer es module format over cjs, just like webpack.
// this improves compatibility with TypeScript.
metaMain = metadata.module;

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -328,44 +328,63 @@ describe('The PackageAnalyzer', () => {
.catch(e => done.fail(e));
});
it('analyze() reads package.json as package metadata, respect browser field over module/main', done => {
// setup mock package.json
const fsConfig = {};
fsConfig[path.join('node_modules/my-package', 'package.json')] = '{ "name": "my-package", "main": "index.js", "browser": "browser.js", "module": "module.js" }';
fsConfig[path.join('node_modules/my-package', 'index.js')] = 'some-content';
fsConfig[path.join('node_modules/my-package', 'browser.js')] = 'some-content';
fsConfig[project.paths.root] = {};
mockfs(fsConfig);
sut.analyze('my-package')
.then(description => {
expect(description.metadata.name).toBe('my-package');
expect(description.loaderConfig.path).toBe('../node_modules/my-package');
expect(description.loaderConfig.main).toBe('browser');
done();
})
.catch(e => done.fail(e));
describe('analyze() reads package.json as package metadata -- "browser/module/main" fields analysis', () => {
let fsConfig;
let mockFileNames = ['index.js', 'browser.js', 'module.js'];
beforeEach(function __setup__mock_package_json() {
fsConfig = {};
for (const fileName of mockFileNames) {
fsConfig[path.join('node_modules/my-package', fileName)] = 'some-content';
};
fsConfig[project.paths.root] = {};
});
it('respects browser field over module/main', done => {
fsConfig[path.join('node_modules/my-package', 'package.json')] = '{ "name": "my-package", "main": "index.js", "browser": "browser.js", "module": "module.js" }';
mockfs(fsConfig);
sut.analyze('my-package')
.then(description => {
expect(description.metadata.name).toBe('my-package');
expect(description.loaderConfig.path).toBe('../node_modules/my-package');
expect(description.loaderConfig.main).toBe('browser');
done();
})
.catch(e => done.fail(e));
});
it('respects module field over main', done => {
fsConfig[path.join('node_modules/my-package', 'package.json')] = '{ "name": "my-package", "main": "index.js", "module": "module.js"}';
mockfs(fsConfig);
sut.analyze('my-package')
.then(description => {
expect(description.metadata.name).toBe('my-package');
expect(description.loaderConfig.path).toBe('../node_modules/my-package');
expect(description.loaderConfig.main).toBe('module');
done();
})
.catch(e => done.fail(e));
});
it('respects "module" field over "main", but ignore module with "aurelia-"', done => {
fsConfig[path.join('node_modules/my-package', 'package.json')] = '{ "name": "my-package", "main": "index.js", "module": "module.js"}';
const aureliaPkg = 'aurelia-binding';
for (const fileName of mockFileNames) {
fsConfig[path.join(`node_modules/${aureliaPkg}`, fileName)] = 'export const content';
}
fsConfig[path.join(`node_modules/${aureliaPkg}`, 'package.json')] = '"name": "aurelia-binding", "main": "index.js", "module": "module.js"';
sut.analyze('aurelia-binding')
.then(description => {
expect(description.metadata.name).toBe('aurelia-binding');
expect(description.loaderConfig.path).toBe(`../node_modules/${aureliaPkg}/index.js`);
expect(description.loaderConfig.main).toBe('main');
done();
})
});
});
it('analyze() reads package.json as package metadata, respect module field over main', done => {
// setup mock package.json
const fsConfig = {};
fsConfig[path.join('node_modules/my-package', 'package.json')] = '{ "name": "my-package", "main": "index.js", "module": "module.js"}';
fsConfig[path.join('node_modules/my-package', 'index.js')] = 'some-content';
fsConfig[path.join('node_modules/my-package', 'browser.js')] = 'some-content';
fsConfig[path.join('node_modules/my-package', 'module.js')] = 'some-content';
fsConfig[project.paths.root] = {};
mockfs(fsConfig);
sut.analyze('my-package')
.then(description => {
expect(description.metadata.name).toBe('my-package');
expect(description.loaderConfig.path).toBe('../node_modules/my-package');
expect(description.loaderConfig.main).toBe('module');
done();
})
.catch(e => done.fail(e));
});
it('analyze() supports parent node_modules folder', done => {
// setup mock package.json

0 comments on commit 00de202

Please sign in to comment.