@@ -10,7 +10,7 @@ import {absoluteFrom, AbsoluteFsPath, FileSystem, getFileSystem} from '../../../
10
10
import { runInEachFileSystem } from '../../../src/ngtsc/file_system/testing' ;
11
11
import { loadTestFiles } from '../../../test/helpers' ;
12
12
import { NgccConfiguration } from '../../src/packages/configuration' ;
13
- import { EntryPoint , getEntryPointFormat , getEntryPointInfo , INCOMPATIBLE_ENTRY_POINT , NO_ENTRY_POINT , SUPPORTED_FORMAT_PROPERTIES } from '../../src/packages/entry_point' ;
13
+ import { EntryPoint , EntryPointJsonProperty , getEntryPointFormat , getEntryPointInfo , INCOMPATIBLE_ENTRY_POINT , NO_ENTRY_POINT , SUPPORTED_FORMAT_PROPERTIES } from '../../src/packages/entry_point' ;
14
14
import { MockLogger } from '../helpers/mock_logger' ;
15
15
16
16
runInEachFileSystem ( ( ) => {
@@ -206,7 +206,7 @@ runInEachFileSystem(() => {
206
206
207
207
for ( let prop of SUPPORTED_FORMAT_PROPERTIES ) {
208
208
// Ignore the UMD format
209
- if ( prop === 'main' ) continue ;
209
+ if ( prop === 'main' || prop === 'browser' ) continue ;
210
210
// Let's give 'module' a specific path, otherwise compute it based on the property.
211
211
const typingsPath = prop === 'module' ? 'index' : `${ prop } /missing_typings` ;
212
212
@@ -425,67 +425,80 @@ runInEachFileSystem(() => {
425
425
expect ( getEntryPointFormat ( fs , entryPoint , 'module' ) ) . toBe ( 'esm5' ) ;
426
426
} ) ;
427
427
428
- it ( 'should return `esm5` for `main` if the file contains import or export statements' , ( ) => {
429
- const name = _ (
430
- '/project/node_modules/some_package/valid_entry_point/bundles/valid_entry_point/index.js' ) ;
431
- loadTestFiles ( [ { name, contents : `import * as core from '@angular/core;` } ] ) ;
432
- expect ( getEntryPointFormat ( fs , entryPoint , 'main' ) ) . toBe ( 'esm5' ) ;
428
+ ( [ 'browser' , 'main' ] as EntryPointJsonProperty [ ] ) . forEach ( browserOrMain => {
429
+ it ( 'should return `esm5` for `' + browserOrMain +
430
+ '` if the file contains import or export statements' ,
431
+ ( ) => {
432
+ const name = _ (
433
+ '/project/node_modules/some_package/valid_entry_point/bundles/valid_entry_point/index.js' ) ;
434
+ loadTestFiles ( [ { name, contents : `import * as core from '@angular/core;` } ] ) ;
435
+ expect ( getEntryPointFormat ( fs , entryPoint , browserOrMain ) ) . toBe ( 'esm5' ) ;
433
436
434
- loadTestFiles ( [ { name, contents : `import {Component} from '@angular/core;` } ] ) ;
435
- expect ( getEntryPointFormat ( fs , entryPoint , 'main' ) ) . toBe ( 'esm5' ) ;
437
+ loadTestFiles ( [ { name, contents : `import {Component} from '@angular/core;` } ] ) ;
438
+ expect ( getEntryPointFormat ( fs , entryPoint , browserOrMain ) ) . toBe ( 'esm5' ) ;
436
439
437
- loadTestFiles ( [ { name, contents : `export function foo() {}` } ] ) ;
438
- expect ( getEntryPointFormat ( fs , entryPoint , 'main' ) ) . toBe ( 'esm5' ) ;
440
+ loadTestFiles ( [ { name, contents : `export function foo() {}` } ] ) ;
441
+ expect ( getEntryPointFormat ( fs , entryPoint , browserOrMain ) ) . toBe ( 'esm5' ) ;
439
442
440
- loadTestFiles ( [ { name, contents : `export * from 'abc';` } ] ) ;
441
- expect ( getEntryPointFormat ( fs , entryPoint , 'main' ) ) . toBe ( 'esm5' ) ;
442
- } ) ;
443
+ loadTestFiles ( [ { name, contents : `export * from 'abc';` } ] ) ;
444
+ expect ( getEntryPointFormat ( fs , entryPoint , browserOrMain ) ) . toBe ( 'esm5' ) ;
445
+ } ) ;
443
446
444
- it ( 'should return `umd` for `main` if the file contains a UMD wrapper function' , ( ) => {
445
- loadTestFiles ( [ {
446
- name : _ (
447
- '/project/node_modules/some_package/valid_entry_point/bundles/valid_entry_point/index.js' ) ,
448
- contents : `
447
+ it ( 'should return `umd` for `' + browserOrMain +
448
+ '` if the file contains a UMD wrapper function' ,
449
+ ( ) => {
450
+ loadTestFiles ( [ {
451
+ name : _ (
452
+ '/project/node_modules/some_package/valid_entry_point/bundles/valid_entry_point/index.js' ) ,
453
+ contents : `
449
454
(function (global, factory) {
450
455
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
451
456
typeof define === 'function' && define.amd ? define('@angular/common', ['exports', '@angular/core'], factory) :
452
457
(global = global || self, factory((global.ng = global.ng || {}, global.ng.common = {}), global.ng.core));
453
458
}(this, function (exports, core) { 'use strict'; }));
454
459
`
455
- } ] ) ;
456
- expect ( getEntryPointFormat ( fs , entryPoint , 'main' ) ) . toBe ( 'umd' ) ;
457
- } ) ;
460
+ } ] ) ;
461
+ expect ( getEntryPointFormat ( fs , entryPoint , browserOrMain ) ) . toBe ( 'umd' ) ;
462
+ } ) ;
458
463
459
- it ( 'should return `commonjs` for `main` if the file does not contain a UMD wrapper function' , ( ) => {
460
- loadTestFiles ( [ {
461
- name : _ (
462
- '/project/node_modules/some_package/valid_entry_point/bundles/valid_entry_point/index.js' ) ,
463
- contents : `
464
+ it ( 'should return `commonjs` for `' + browserOrMain +
465
+ '` if the file does not contain a UMD wrapper function' ,
466
+ ( ) => {
467
+ loadTestFiles ( [ {
468
+ name : _ (
469
+ '/project/node_modules/some_package/valid_entry_point/bundles/valid_entry_point/index.js' ) ,
470
+ contents : `
464
471
const core = require('@angular/core);
465
472
module.exports = {};
466
473
`
467
- } ] ) ;
468
- expect ( getEntryPointFormat ( fs , entryPoint , 'main' ) ) . toBe ( 'commonjs' ) ;
469
- } ) ;
474
+ } ] ) ;
475
+ expect ( getEntryPointFormat ( fs , entryPoint , browserOrMain ) ) . toBe ( 'commonjs' ) ;
476
+ } ) ;
470
477
471
- it ( 'should resolve the format path with suitable postfixes' , ( ) => {
472
- loadTestFiles ( [ {
473
- name : _ (
474
- '/project/node_modules/some_package/valid_entry_point/bundles/valid_entry_point/index.js' ) ,
475
- contents : `
478
+ it ( 'should resolve the format path with suitable postfixes' , ( ) => {
479
+ loadTestFiles ( [ {
480
+ name : _ (
481
+ '/project/node_modules/some_package/valid_entry_point/bundles/valid_entry_point/index.js' ) ,
482
+ contents : `
476
483
(function (global, factory) {
477
484
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) :
478
485
typeof define === 'function' && define.amd ? define('@angular/common', ['exports', '@angular/core'], factory) :
479
486
(global = global || self, factory((global.ng = global.ng || {}, global.ng.common = {}), global.ng.core));
480
487
}(this, function (exports, core) { 'use strict'; }));
481
488
`
482
- } ] ) ;
489
+ } ] ) ;
490
+
491
+ entryPoint . packageJson . main = './bundles/valid_entry_point/index' ;
492
+ expect ( getEntryPointFormat ( fs , entryPoint , browserOrMain ) ) . toBe ( 'umd' ) ;
483
493
484
- entryPoint . packageJson . main = './bundles/valid_entry_point/index' ;
485
- expect ( getEntryPointFormat ( fs , entryPoint , 'main' ) ) . toBe ( 'umd' ) ;
494
+ entryPoint . packageJson . main = './bundles/valid_entry_point' ;
495
+ expect ( getEntryPointFormat ( fs , entryPoint , browserOrMain ) ) . toBe ( 'umd' ) ;
496
+ } ) ;
497
+ } ) ;
486
498
487
- entryPoint . packageJson . main = './bundles/valid_entry_point' ;
488
- expect ( getEntryPointFormat ( fs , entryPoint , 'main' ) ) . toBe ( 'umd' ) ;
499
+ it ( 'should return `undefined` if the `browser` property is not a string' , ( ) => {
500
+ entryPoint . packageJson . browser = { } as any ;
501
+ expect ( getEntryPointFormat ( fs , entryPoint , 'browser' ) ) . toBeUndefined ( ) ;
489
502
} ) ;
490
503
} ) ;
491
504
} ) ;
@@ -503,6 +516,7 @@ export function createPackageJson(
503
516
fesm5 : `./fesm5/${ packageName } .js` ,
504
517
esm5 : `./esm5/${ packageName } .js` ,
505
518
main : `./bundles/${ packageName } /index.js` ,
519
+ browser : `./bundles/${ packageName } /index.js` ,
506
520
module : './index.js' ,
507
521
} ;
508
522
if ( excludes ) {
0 commit comments