@@ -14,80 +14,157 @@ import lessTranspiler from '../../transpilers/less';
1414
1515let polyfillsLoaded = false ;
1616
17+ async function addAngularJSONPolyfills ( manager ) {
18+ const { parsed } = manager . configurations [ 'angular-config' ] ;
19+
20+ const defaultProject = parsed . defaultProject ;
21+ const project = parsed . projects [ defaultProject ] ;
22+ const build = project . architect . build ;
23+
24+ if ( build . options ) {
25+ if ( project . root && build . options . polyfill ) {
26+ const polyfillLocation = absolute (
27+ join ( project . root , build . options . polyfill )
28+ ) ;
29+ const polyfills = manager . resolveModule ( polyfillLocation , '/' ) ;
30+
31+ await manager . transpileModules ( polyfills ) ;
32+ manager . evaluateModule ( polyfills ) ;
33+ }
34+ }
35+ }
36+
37+ async function addAngularCLIPolyfills ( manager ) {
38+ const { parsed } = manager . configurations [ 'angular-cli' ] ;
39+ if ( parsed . apps && parsed . apps [ 0 ] ) {
40+ const app = parsed . apps [ 0 ] ;
41+
42+ if ( app . root && app . polyfills ) {
43+ const polyfillLocation = absolute ( join ( app . root , app . polyfills ) ) ;
44+ const polyfills = manager . resolveModule ( polyfillLocation , '/' ) ;
45+
46+ await manager . transpileModules ( polyfills ) ;
47+ manager . evaluateModule ( polyfills ) ;
48+ }
49+ }
50+ }
51+
52+ async function addAngularJSONResources ( manager ) {
53+ const { parsed } = manager . configurations [ 'angular-config' ] ;
54+
55+ const defaultProject = parsed . defaultProject ;
56+ const project = parsed . projects [ defaultProject ] ;
57+ const build = project . architect . build ;
58+
59+ if ( build . options ) {
60+ const { styles = [ ] , scripts = [ ] } = build . options ;
61+
62+ /* eslint-disable no-await-in-loop */
63+ for ( let i = 0 ; i < styles . length ; i ++ ) {
64+ const p = styles [ i ] ;
65+
66+ const finalPath = absolute ( join ( project . root , p ) ) ;
67+
68+ const tModule = await manager . resolveTranspiledModuleAsync (
69+ finalPath ,
70+ '/'
71+ ) ;
72+
73+ await tModule . transpile ( manager ) ;
74+ tModule . setIsEntry ( true ) ;
75+ tModule . evaluate ( manager ) ;
76+ }
77+
78+ const scriptTModules = await Promise . all (
79+ scripts . map ( async p => {
80+ const finalPath = absolute ( join ( project . root , p ) ) ;
81+ const tModule = await manager . resolveTranspiledModuleAsync (
82+ finalPath ,
83+ '/'
84+ ) ;
85+ tModule . setIsEntry ( true ) ;
86+ return tModule . transpile ( manager ) ;
87+ } )
88+ ) ;
89+
90+ scriptTModules . forEach ( t => {
91+ t . evaluate ( manager , { asUMD : true } ) ;
92+ } ) ;
93+ }
94+ }
95+
96+ async function addAngularCLIResources ( manager ) {
97+ const { parsed } = manager . configurations [ 'angular-cli' ] ;
98+ if ( parsed . apps && parsed . apps [ 0 ] ) {
99+ const app = parsed . apps [ 0 ] ;
100+
101+ const { styles = [ ] , scripts = [ ] } = app ;
102+
103+ /* eslint-disable no-await-in-loop */
104+ for ( let i = 0 ; i < styles . length ; i ++ ) {
105+ const p = styles [ i ] ;
106+ const finalPath = absolute ( join ( app . root || 'src' , p ) ) ;
107+
108+ const tModule = await manager . resolveTranspiledModuleAsync (
109+ finalPath ,
110+ '/'
111+ ) ;
112+
113+ await tModule . transpile ( manager ) ;
114+ tModule . setIsEntry ( true ) ;
115+ tModule . evaluate ( manager ) ;
116+ }
117+ /* eslint-enable no-await-in-loop */
118+
119+ const scriptTModules = await Promise . all (
120+ scripts . map ( async p => {
121+ const finalPath = absolute ( join ( app . root || 'src' , p ) ) ;
122+ const tModule = await manager . resolveTranspiledModuleAsync (
123+ finalPath ,
124+ '/'
125+ ) ;
126+ tModule . setIsEntry ( true ) ;
127+ return tModule . transpile ( manager ) ;
128+ } )
129+ ) ;
130+
131+ scriptTModules . forEach ( t => {
132+ t . evaluate ( manager , { asUMD : true } ) ;
133+ } ) ;
134+
135+ if ( app . environmentSource && app . environments && app . environments . dev ) {
136+ manager . preset . setAdditionalAliases ( {
137+ [ app . environmentSource ] : app . environments . dev ,
138+ } ) ;
139+ }
140+ }
141+ }
142+
17143export default function initialize ( ) {
18144 const preset = new Preset (
19145 'angular-cli' ,
20146 [ 'web.ts' , 'ts' , 'json' , 'web.tsx' , 'tsx' , 'js' ] ,
21147 { } ,
22148 {
23149 setup : async manager => {
24- const { parsed } = manager . configurations [ 'angular-cli' ] ;
25150 if ( ! polyfillsLoaded ) {
26151 const zone = manager . resolveModule ( 'zone.js' , '/' ) ;
27152 await manager . transpileModules ( zone ) ;
28153 manager . evaluateModule ( zone ) ;
29154
30- if ( parsed . apps && parsed . apps [ 0 ] ) {
31- const app = parsed . apps [ 0 ] ;
32-
33- if ( app . root && app . polyfills ) {
34- const polyfillLocation = absolute ( join ( app . root , app . polyfills ) ) ;
35- const polyfills = manager . resolveModule ( polyfillLocation , '/' ) ;
36-
37- await manager . transpileModules ( polyfills ) ;
38- manager . evaluateModule ( polyfills ) ;
39- }
155+ if ( ! manager . configurations [ 'angular-config' ] . generated ) {
156+ await addAngularJSONPolyfills ( manager ) ;
157+ } else {
158+ await addAngularCLIPolyfills ( manager ) ;
40159 }
41160
42161 polyfillsLoaded = true ;
43162 }
44163
45- if ( parsed . apps && parsed . apps [ 0 ] ) {
46- const app = parsed . apps [ 0 ] ;
47-
48- const { styles = [ ] , scripts = [ ] } = app ;
49-
50- /* eslint-disable no-await-in-loop */
51- for ( let i = 0 ; i < styles . length ; i ++ ) {
52- const p = styles [ i ] ;
53- const finalPath = absolute ( join ( app . root || 'src' , p ) ) ;
54-
55- const tModule = await manager . resolveTranspiledModuleAsync (
56- finalPath ,
57- '/'
58- ) ;
59-
60- await tModule . transpile ( manager ) ;
61- tModule . setIsEntry ( true ) ;
62- tModule . evaluate ( manager ) ;
63- }
64- /* eslint-enable no-await-in-loop */
65-
66- const scriptTModules = await Promise . all (
67- scripts . map ( async p => {
68- const finalPath = absolute ( join ( app . root || 'src' , p ) ) ;
69- const tModule = await manager . resolveTranspiledModuleAsync (
70- finalPath ,
71- '/'
72- ) ;
73- tModule . setIsEntry ( true ) ;
74- return tModule . transpile ( manager ) ;
75- } )
76- ) ;
77-
78- scriptTModules . forEach ( t => {
79- t . evaluate ( manager , { asUMD : true } ) ;
80- } ) ;
81-
82- if (
83- app . environmentSource &&
84- app . environments &&
85- app . environments . dev
86- ) {
87- manager . preset . setAdditionalAliases ( {
88- [ app . environmentSource ] : app . environments . dev ,
89- } ) ;
90- }
164+ if ( ! manager . configurations [ 'angular-config' ] . generated ) {
165+ await addAngularJSONResources ( manager ) ;
166+ } else {
167+ await addAngularCLIResources ( manager ) ;
91168 }
92169 } ,
93170 }
0 commit comments