Skip to content

Commit 9796579

Browse files
mheveryvicb
authored andcommitted
fix(packages): use ES modules for primary build (angular#11120)
1 parent 8cb1046 commit 9796579

File tree

249 files changed

+1929
-1463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+1929
-1463
lines changed

build.sh

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ TSCONFIG=./modules/tsconfig.json
5151
echo "====== (all)COMPILING: \$(npm bin)/tsc -p ${TSCONFIG} ====="
5252
# compile ts code
5353
TSC="node --max-old-space-size=3000 dist/tools/@angular/tsc-wrapped/src/main"
54+
UGLIFYJS=`pwd`/node_modules/.bin/uglifyjs
5455
$TSC -p modules/tsconfig.json
5556

5657
rm -rf ./dist/packages-dist
@@ -68,56 +69,61 @@ for PACKAGE in \
6869
upgrade \
6970
compiler-cli
7071
do
71-
SRCDIR=./modules/@angular/${PACKAGE}
72-
DESTDIR=./dist/packages-dist/${PACKAGE}
73-
UMD_ES6_PATH=${DESTDIR}/esm/${PACKAGE}.umd.js
72+
PWD=`pwd`
73+
SRCDIR=${PWD}/modules/@angular/${PACKAGE}
74+
DESTDIR=${PWD}/dist/packages-dist/${PACKAGE}
7475
UMD_ES5_PATH=${DESTDIR}/bundles/${PACKAGE}.umd.js
76+
UMD_TESTING_ES5_PATH=${DESTDIR}/bundles/${PACKAGE}-testing.umd.js
7577
UMD_ES5_MIN_PATH=${DESTDIR}/bundles/${PACKAGE}.umd.min.js
78+
LICENSE_BANNER=${PWD}/modules/@angular/license-banner.txt
7679

77-
echo "====== COMPILING: ${TSC} -p ${SRCDIR}/tsconfig-es5.json ====="
78-
$TSC -p ${SRCDIR}/tsconfig-es5.json
80+
echo "====== COMPILING: ${TSC} -p ${SRCDIR}/tsconfig.json ====="
81+
$TSC -p ${SRCDIR}/tsconfig.json
7982

8083
cp ${SRCDIR}/package.json ${DESTDIR}/
8184

85+
if [[ -e ${SRCDIR}/tsconfig-testing.json ]]; then
86+
echo "====== COMPILING TESTING: ${TSC} -p ${SRCDIR}/tsconfig-testing.json"
87+
$TSC -p ${SRCDIR}/tsconfig-testing.json
88+
fi
8289

8390
echo "====== TSC 1.8 d.ts compat for ${DESTDIR} ====="
8491
# safely strips 'readonly' specifier from d.ts files to make them compatible with tsc 1.8
8592
if [ "$(uname)" == "Darwin" ]; then
86-
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -e 's/\(^ *(static |private )*\)*readonly */\1/g'
87-
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -E 's/^( +)abstract ([[:alnum:]]+\:)/\1\2/g'
93+
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -e 's/\(^ *(static |private )*\)*readonly */\1/g'
94+
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -e 's/\/\/\/ <reference types="node" \/>//g'
95+
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i '' -E 's/^( +)abstract ([[:alnum:]]+\:)/\1\2/g'
8896
else
8997
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i -e 's/\(^ *(static |private )*\)*readonly */\1/g'
98+
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i -e 's/\/\/\/ <reference types="node" \/>//g'
9099
find ${DESTDIR} -type f -name '*.d.ts' -print0 | xargs -0 sed -i -E 's/^( +)abstract ([[:alnum:]]+\:)/\1\2/g'
91100
fi
92101

93102
if [[ ${PACKAGE} != compiler-cli ]]; then
94103

95-
echo "====== (esm)COMPILING: $TSC -p ${SRCDIR}/tsconfig-es2015.json ====="
96-
$TSC -p ${SRCDIR}/tsconfig-es2015.json
97-
98104
echo "====== BUNDLING: ${SRCDIR} ====="
99105
mkdir ${DESTDIR}/bundles
100106

101107
(
102108
cd ${SRCDIR}
103-
echo "..." # here just to have grep match something and not exit with 1
109+
echo "====== Rollup ${PACKAGE} index"
104110
../../../node_modules/.bin/rollup -c rollup.config.js
111+
cat ${LICENSE_BANNER} > ${UMD_ES5_PATH}.tmp
112+
cat ${UMD_ES5_PATH} >> ${UMD_ES5_PATH}.tmp
113+
mv ${UMD_ES5_PATH}.tmp ${UMD_ES5_PATH}
114+
$UGLIFYJS -c --screw-ie8 --comments -o ${UMD_ES5_MIN_PATH} ${UMD_ES5_PATH}
115+
116+
117+
if [[ -e rollup-testing.config.js ]]; then
118+
echo "====== Rollup ${PACKAGE} testing"
119+
../../../node_modules/.bin/rollup -c rollup-testing.config.js
120+
echo "{\"main\": \"../bundles/${PACKAGE}-testing.umd.js\"}" > ${DESTDIR}/testing/package.json
121+
cat ${LICENSE_BANNER} > ${UMD_TESTING_ES5_PATH}.tmp
122+
cat ${UMD_TESTING_ES5_PATH} >> ${UMD_TESTING_ES5_PATH}.tmp
123+
mv ${UMD_TESTING_ES5_PATH}.tmp ${UMD_TESTING_ES5_PATH}
124+
fi
105125
) 2>&1 | grep -v "as external dependency"
106126

107-
$(npm bin)/tsc \
108-
--out ${UMD_ES5_PATH} \
109-
--target es5 \
110-
--lib "es6,dom" \
111-
--allowJs \
112-
${UMD_ES6_PATH}
113-
114-
rm ${UMD_ES6_PATH}
115-
116-
cat ./modules/@angular/license-banner.txt > ${UMD_ES5_PATH}.tmp
117-
cat ${UMD_ES5_PATH} >> ${UMD_ES5_PATH}.tmp
118-
mv ${UMD_ES5_PATH}.tmp ${UMD_ES5_PATH}
119-
120-
$(npm bin)/uglifyjs -c --screw-ie8 -o ${UMD_ES5_MIN_PATH} ${UMD_ES5_PATH}
121127
fi
122128
done
123129

gulpfile.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,22 @@ gulp.task('format', () => {
3030

3131
const entrypoints = [
3232
'dist/packages-dist/core/index.d.ts',
33-
'dist/packages-dist/core/testing.d.ts',
33+
'dist/packages-dist/core/testing/index.d.ts',
3434
'dist/packages-dist/common/index.d.ts',
35-
'dist/packages-dist/common/testing.d.ts',
35+
'dist/packages-dist/common/testing/index.d.ts',
3636
// The API surface of the compiler is currently unstable - all of the important APIs are exposed
3737
// via @angular/core, @angular/platform-browser or @angular/platform-browser-dynamic instead.
3838
//'dist/packages-dist/compiler/index.d.ts',
3939
//'dist/packages-dist/compiler/testing.d.ts',
4040
'dist/packages-dist/upgrade/index.d.ts',
4141
'dist/packages-dist/platform-browser/index.d.ts',
42-
'dist/packages-dist/platform-browser/testing.d.ts',
42+
'dist/packages-dist/platform-browser/testing/index.d.ts',
4343
'dist/packages-dist/platform-browser-dynamic/index.d.ts',
44-
'dist/packages-dist/platform-browser-dynamic/testing.d.ts',
44+
'dist/packages-dist/platform-browser-dynamic/testing/index.d.ts',
4545
'dist/packages-dist/platform-server/index.d.ts',
46-
'dist/packages-dist/platform-server/testing.d.ts',
46+
'dist/packages-dist/platform-server/testing/index.d.ts',
4747
'dist/packages-dist/http/index.d.ts',
48-
'dist/packages-dist/http/testing.d.ts',
48+
'dist/packages-dist/http/testing/index.d.ts',
4949
'dist/packages-dist/forms/index.d.ts',
5050
'dist/packages-dist/router/index.d.ts'
5151
];
@@ -102,9 +102,10 @@ gulp.task('lint', ['format:enforce', 'tools:build'], () => {
102102
.pipe(tslint({
103103
tslint: require('tslint').default,
104104
configuration: tslintConfig,
105-
rulesDirectory: 'dist/tools/tslint'
105+
rulesDirectory: 'dist/tools/tslint',
106+
formatter: 'prose'
106107
}))
107-
.pipe(tslint.report('prose', {emitError: true}));
108+
.pipe(tslint.report({emitError: true}));
108109
});
109110

110111
gulp.task('tools:build', (done) => { tsc('tools/', done); });

modules/@angular/common/index.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
export * from './src/pipes';
10-
export * from './src/directives';
11-
export * from './src/location';
12-
export {NgLocalization} from './src/localization';
13-
export {CommonModule} from './src/common_module';
9+
/**
10+
* @module
11+
* @description
12+
* Entry point for all public APIs of the common package.
13+
*/
14+
export * from './src/common';
15+
16+
// This file only reexports content of the `src` folder. Keep it that way.

modules/@angular/common/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "@angular/common",
33
"version": "0.0.0-PLACEHOLDER",
44
"description": "",
5-
"main": "index.js",
6-
"jsnext:main": "esm/index.js",
5+
"main": "bundles/common.umd.js",
6+
"module": "index.js",
77
"typings": "index.d.ts",
88
"author": "angular",
99
"license": "MIT",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
export default {
3+
entry: '../../../dist/packages-dist/common/testing/index.js',
4+
dest: '../../../dist/packages-dist/common/bundles/common-testing.umd.js',
5+
format: 'umd',
6+
moduleName: 'ng.common.testing',
7+
globals: {
8+
'@angular/core': 'ng.core',
9+
'@angular/common': 'ng.common',
10+
'rxjs/Subject': 'Rx',
11+
'rxjs/observable/PromiseObservable': 'Rx', // this is wrong, but this stuff has changed in rxjs b.6 so we need to fix it when we update.
12+
'rxjs/operator/toPromise': 'Rx.Observable.prototype',
13+
'rxjs/Observable': 'Rx'
14+
}
15+
}
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
export default {
3-
entry: '../../../dist/packages-dist/common/esm/index.js',
4-
dest: '../../../dist/packages-dist/common/esm/common.umd.js',
3+
entry: '../../../dist/packages-dist/common/index.js',
4+
dest: '../../../dist/packages-dist/common/bundles/common.umd.js',
55
format: 'umd',
66
moduleName: 'ng.common',
77
globals: {
@@ -10,8 +10,5 @@ export default {
1010
'rxjs/observable/PromiseObservable': 'Rx', // this is wrong, but this stuff has changed in rxjs b.6 so we need to fix it when we update.
1111
'rxjs/operator/toPromise': 'Rx.Observable.prototype',
1212
'rxjs/Observable': 'Rx'
13-
},
14-
plugins: [
15-
// nodeResolve({ jsnext: true, main: true }),
16-
]
13+
}
1714
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './pipes';
10+
export * from './directives';
11+
export * from './location';
12+
export {NgLocalization} from './localization';
13+
export {CommonModule} from './common_module';
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../facade/src
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
/**
10+
* @module
11+
* @description
12+
* Entry point for all public APIs of the common/testing package.
13+
*/
14+
export {SpyLocation} from './location_mock';
15+
export {MockLocationStrategy} from './mock_location_strategy';

modules/@angular/common/testing/location_mock.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9+
import {Location, LocationStrategy} from '@angular/common';
910
import {EventEmitter, Injectable} from '@angular/core';
1011

11-
import {Location} from '../index';
12-
import {LocationStrategy} from '../src/location/location_strategy';
13-
1412

1513
/**
1614
* A spy for {@link Location} that allows tests to fire simulated location events.

0 commit comments

Comments
 (0)