build: resolve review comments on flat modules PR and fix more bugs (#14660)

This commit is contained in:
Jason Aden 2017-02-23 16:39:44 -08:00 committed by Igor Minar
parent 4b54c0e23f
commit c53621be8e
32 changed files with 60 additions and 200 deletions

View File

@ -1,4 +0,0 @@
{
"plugins": ["transform-es2015-modules-umd"],
"presets": ["es2015"]
}

View File

@ -54,33 +54,24 @@ for ARG in "$@"; do
done
getPackageContents() {
echo "{\"typings\": \"../typings/${2}/${2}.d.ts\", \"main\": \"../bundles/${1}-${2}.umd.js\", \"module\": \"../@angular/${1}/${2}.es5.js\", \"es2015\": \"../@angular/${1}/${2}.js\"}"
echo "{\"typings\": \"../typings/${2}/${3:-$2}.d.ts\", \"main\": \"../bundles/${1}-${2}.umd.js\", \"module\": \"../@angular/${1}/${2}.es5.js\", \"es2015\": \"../@angular/${1}/${2}.js\"}"
}
containsElement () {
local e
for e in "${@:2}"; do
[[ "$e" == "$1" ]] && return 0;
done
return 1
#######################################
# Downlevel ES2015 to ESM/ES5
# Arguments:
# param1 - Destination folder
# param2 - Input path
# param3 - Output path
# Returns:
# None
#######################################
downlevelES2015() {
echo '{"presets": [ ["es2015", { "modules": false }] ], "compact": true }' > ${1}/.babelrc
$BABELJS ${2} -o ${3}
rm -f ${1}/.babelrc
}
NON_MODULE=(
platform-browser
)
moveTypings() {
# $1 == Source copy root (/src or /testing)
# $2 == Final destination directory
rsync -a --exclude=*.js* ${1} ${2}
}
cleanTypings() {
# $1 == Source root (where index.d.ts file is, for instance)
# $2 == Source copy root (/src or /typings)
rm -f ${1}/index.*
rm -rf ${2}
}
VERSION="${VERSION_PREFIX}${VERSION_SUFFIX}"
ROUTER_VERSION="${ROUTER_VERSION_PREFIX}${VERSION_SUFFIX}"
echo "====== BUILDING: Version ${VERSION} (Router ${ROUTER_VERSION})"
@ -152,7 +143,7 @@ do
DEST_MODULE=${DESTDIR}/@angular
DEST_BUNDLES=${DESTDIR}/bundles
# ESM/ES6
# ESM/2015
JS_PATH=${DEST_MODULE}/${PACKAGE}.js
JS_PATH_ES5=${DEST_MODULE}/${PACKAGE}.es5.js
JS_TESTING_PATH=${DEST_MODULE}/${PACKAGE}/testing.js
@ -187,11 +178,15 @@ do
rm -rf ${DESTDIR}
echo "====== [${PACKAGE}]: COMPILING: ${TSC} --skipImportRename -p ${SRCDIR}/tsconfig-build.json"
# When .babelrc file exists, the dist package will have ES2015 sources, ESM/ES5, and UMD bundles. Because of a bug
# preventing the @angular/compiler package from running through this pipeline, we have to manually check for the Compiler
# package as well. The tsconfig-build.json defaults to building to the root of the package dist dir, but when
# outputting ES2015 then bundling from there, built files should go to the DEST_MODULE folder.
echo "====== [${PACKAGE}]: COMPILING: ${TSC} -p ${SRCDIR}/tsconfig-build.json"
if [[ -e ${SRCDIR}/.babelrc || ${PACKAGE} == "compiler" ]]; then
$TSC --skipImportRename -p ${SRCDIR}/tsconfig-build.json -outDir ${DEST_MODULE}
$TSC -p ${SRCDIR}/tsconfig-build.json -outDir ${DEST_MODULE}
else
$TSC --skipImportRename -p ${SRCDIR}/tsconfig-build.json
$TSC -p ${SRCDIR}/tsconfig-build.json
fi
echo "====== Move ${PACKAGE} typings"
@ -264,55 +259,54 @@ do
mv ${JS_PATH}.tmp ${JS_PATH}
if ! [[ ${PACKAGE} == 'benchpress' ]]; then
cleanTypings ${DEST_MODULE} ${DEST_MODULE}/src
rm -f ${DEST_MODULE}/index.*
rm -rf ${DEST_MODULE}/src
fi
if [[ -e ${DESTDIR}/.babelrc ]]; then
echo "====== Downleveling ${PACKAGE} to ES5/UMD"
echo "====== Downleveling ES2015 to UMD/ES5"
$BABELJS ${JS_PATH} -o ${UMD_ES5_PATH}
### Minification ###
echo "====== Minifying JavaScript"
echo "====== Minifying ES2015"
$BABILI ${JS_PATH} -o ${UMD_ES5_MIN_PATH}
echo "====== Downleveling min JavaScript to ES5/UMD"
echo "====== Downleveling minified ES2015 to UMD/ES5"
$BABELJS ${UMD_ES5_MIN_PATH} -o ${UMD_ES5_MIN_PATH}
echo "====== Minifying ${PACKAGE}"
echo "====== Minifying UMD/ES5"
$UGLIFYJS -c --screw-ie8 --comments -o ${UMD_ES5_MIN_PATH} ${UMD_ES5_MIN_PATH}
### END Minification ###
else
# For packages not running through babel, use the es5/umd config
echo "====== Rollup ${PACKAGE} index to UMD"
# For packages not running through babel, use the UMD/ES5 config
echo "====== Rollup ${PACKAGE} index to UMD/ES5"
../../../node_modules/.bin/rollup -c rollup-umd.config.js
[[ -d ${DESTDIR}/es5 ]] && rm -rf ${DESTDIR}/es5
echo "====== Minifying UMD ${PACKAGE}"
echo "====== Minifying UMD/ES5"
$UGLIFYJS -c --screw-ie8 --comments -o ${UMD_ES5_MIN_PATH} ${UMD_ES5_PATH}
fi
rm -f ${DISTDIR}/.babelrc
cp ${ROOTDIR}/.babelrc ${DEST_MODULE}/.babelrc
$BABELJS ${JS_PATH} -o ${JS_PATH_ES5}
echo "====== Downleveling ES2015 to ESM/ES5"
downlevelES2015 ${DEST_MODULE} ${JS_PATH} ${JS_PATH_ES5}
if [[ -d testing ]]; then
echo "====== Rollup ${PACKAGE} testing"
../../../node_modules/.bin/rollup -i ${DESTDIR}/testing/index.js -o ${DESTDIR}/testing.tmp.js
echo "====== Downleveling ${PACKAGE} TESTING to ES5/UMD"
echo "====== Downleveling ${PACKAGE} TESTING to UMD/ES5"
[[ -e ${SRCDIR}/.babelrc-testing ]] && cp ${SRCDIR}/.babelrc-testing ${DESTDIR}/.babelrc
$BABELJS ${DESTDIR}/testing.tmp.js -o ${UMD_TESTING_ES5_PATH}
rm -f ${DESTDIR}/.babelrc
echo "====== Move ${PACKAGE} testing typings"
rsync -a --exclude=*.js --exclude=*.js.map ${DESTDIR}/testing/ ${DESTDIR}/typings/testing
mv ${DESTDIR}/typings/testing/index.d.ts ${DESTDIR}/typings/testing/testing.d.ts
mv ${DESTDIR}/typings/testing/index.metadata.json ${DESTDIR}/typings/testing/testing.metadata.json
rm -rf ${DESTDIR}/testing
mkdir ${DESTDIR}/testing && [[ -d ${DEST_MODULE}/${PACKAGE} ]] || mkdir ${DEST_MODULE}/${PACKAGE}
getPackageContents "${PACKAGE}" "testing" > ${DESTDIR}/testing/package.json
getPackageContents "${PACKAGE}" "testing" "index" > ${DESTDIR}/testing/package.json
mv ${DESTDIR}/testing.tmp.js ${JS_TESTING_PATH}
$BABELJS ${JS_TESTING_PATH} -o ${JS_TESTING_PATH_ES5}
@ -326,7 +320,7 @@ do
rm -f ${DEST_MODULE}/static.*
../../../node_modules/.bin/rollup -i ${DESTDIR}/static/static.js -o ${DESTDIR}/static.tmp.js
echo "====== Downleveling ${PACKAGE} STATIC to ES5/UMD"
echo "====== Downleveling ${PACKAGE} STATIC to UMD/ES5"
[[ -e ${SRCDIR}/.babelrc-static ]] && cp ${SRCDIR}/.babelrc-static ${DESTDIR}/.babelrc
$BABELJS ${DESTDIR}/static.tmp.js -o ${UMD_STATIC_ES5_PATH}
rm -f ${DESTDIR}/.babelrc
@ -353,7 +347,7 @@ do
rm -f ${DEST_MODULE}/upgrade.*
../../../node_modules/.bin/rollup -i ${DESTDIR}/upgrade/upgrade.js -o ${DESTDIR}/upgrade.tmp.js
echo "====== Downleveling ${PACKAGE} UPGRADE to ES5/UMD"
echo "====== Downleveling ${PACKAGE} UPGRADE to UMD/ES5"
[[ -e ${SRCDIR}/.babelrc-upgrade ]] && cp ${SRCDIR}/.babelrc-upgrade ${DESTDIR}/.babelrc
$BABELJS ${DESTDIR}/upgrade.tmp.js -o ${UMD_UPGRADE_ES5_PATH}
rm -f ${DESTDIR}/.babelrc
@ -399,8 +393,6 @@ do
echo "====== Move ${PACKAGE} animations testing typings"
rsync -a --exclude=*.js --exclude=*.js.map ${DESTDIR}/animations/testing/ ${DESTDIR}/typings/animations/testing
mv ${DESTDIR}/typings/animations/testing/index.d.ts ${DESTDIR}/typings/animations/testing/testing.d.ts
mv ${DESTDIR}/typings/animations/testing/index.metadata.json ${DESTDIR}/typings/animations/testing/testing.metadata.json
rm -rf ${DESTDIR}/animations
@ -409,7 +401,7 @@ do
getPackageContents "${PACKAGE}" "animations" > ${DESTDIR}/animations/package.json
echo '{"typings": "../../typings/animations/testing/testing.d.ts", "main": "../../bundles/platform-browser-animations-testing.umd.js", "module": "../../@angular/platform-browser/animations/testing.es5.js", "es2015": "../../@angular/platform-browser/animations/testing.js"}' > ${DESTDIR}/animations/testing/package.json
echo '{"typings": "../../typings/animations/testing/index.d.ts", "main": "../../bundles/platform-browser-animations-testing.umd.js", "module": "../../@angular/platform-browser/animations/testing.es5.js", "es2015": "../../@angular/platform-browser/animations/testing.js"}' > ${DESTDIR}/animations/testing/package.json
mv ${DESTDIR}/animations.tmp.js ${JS_ANIMATIONS_PATH}
$BABELJS ${JS_ANIMATIONS_PATH} -o ${JS_ANIMATIONS_PATH_ES5}
@ -426,17 +418,18 @@ do
cat ${UMD_ANIMATIONS_TESTING_ES5_PATH} >> ${UMD_ANIMATIONS_TESTING_ES5_PATH}.tmp
mv ${UMD_ANIMATIONS_TESTING_ES5_PATH}.tmp ${UMD_ANIMATIONS_TESTING_ES5_PATH}
fi
for FILE in ${DEST_MODULE}/public_api*; do
rm -f ${FILE}
done
) 2>&1 | grep -v "as external dependency"
fi
(
echo "====== VERSION: Updating version references"
if [[ -e ${SRCDIR}/.babelrc ]]; then
cd ${DEST_MODULE}
else
cd ${DESTDIR}
fi
cd ${DESTDIR}
echo "====== EXECUTE: perl -p -i -e \"s/0\.0\.0\-PLACEHOLDER/${VERSION}/g\" $""(grep -ril 0\.0\.0\-PLACEHOLDER .)"
perl -p -i -e "s/0\.0\.0\-PLACEHOLDER/${VERSION}/g" $(grep -ril 0\.0\.0\-PLACEHOLDER .) < /dev/null 2> /dev/null
echo "====== EXECUTE: perl -p -i -e \"s/0\.0\.0\-ROUTERPLACEHOLDER/${ROUTER_VERSION}/g\" $""(grep -ril 0\.0\.0\-ROUTERPLACEHOLDER .)"

View File

@ -43,7 +43,7 @@ See the `package.json` of the test(s) you're debugging, to see which dist/ folde
Then run the right `tsc --watch` command to keep those dist folders up-to-date, for example:
```
$ ./node_modules/.bin/tsc -p modules/@angular/core/tsconfig-build.json --outDir dist/packages-dist/core --watch
$ ./node_modules/.bin/tsc -p modules/@angular/core/tsconfig-build.json --watch
```
Now you can run the integration test, it will re-install from the dist/ folder on each run.

View File

@ -1,5 +0,0 @@
{
"presets": [
["es2015", { "modules": false }]
]
}

View File

@ -10,5 +10,5 @@
},
"exactGlobals": true
}]],
"moduleId": "@angular/animation"
"moduleId": "@angular/animations"
}

View File

@ -1,14 +0,0 @@
{
"presets": ["es2015"],
"plugins": [["transform-es2015-modules-umd", {
"globals": {
"@angular/core": "ng.core",
"@angular/animations": "ng.animations",
"rxjs/Observable": "Rx",
"rxjs/Subject": "Rx"
},
"exactGlobals": true
}]],
"moduleId": "@angular/animation/testing"
}

View File

@ -18,7 +18,6 @@
// don't auto-discover @types/node, it results in a ///<reference in the .d.ts output
"types": []
},
"exclude": ["integrationtest"],
"files": [
"index.ts",
"../../../node_modules/@types/node/index.d.ts",

View File

@ -2,7 +2,6 @@
"extends": "./tsconfig-build",
"compilerOptions": {
"outDir": "../../../dist/packages-dist/common",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core/"],
"@angular/common": ["../../../dist/packages-dist/common"]

View File

@ -4,7 +4,6 @@
"compilerOptions": {
// Test that we rely on decorator downleveling
"emitDecoratorMetadata": false,
"outDir": "../../../dist/packages-dist/compiler",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/core/testing": ["../../../dist/packages-dist/core/testing"],

View File

@ -8,6 +8,7 @@
},
"exactGlobals": true
}]],
"moduleId": "@angular/core"
"moduleId": "@angular/core",
"compact": false
}

View File

@ -9,4 +9,4 @@
"exactGlobals": true
}]],
"moduleId": "@angular/core/testing"
}
}

View File

@ -2,7 +2,6 @@
"extends": "./tsconfig-build",
"compilerOptions": {
"outDir": "../../../dist/packages-dist/core",
"paths": {
"rxjs/*": ["../../../node_modules/rxjs/*"],
"@angular/core": ["../../../dist/packages-dist/core"]

View File

@ -1,10 +1,8 @@
{
"presets": ["es2015"],
"plugins": [["transform-es2015-modules-umd", {
"globals": {
"@angular/core": "ng.core",
"@angular/compiler": "ng.compiler",
"@angular/platform-browser": "ng.platformBrowser",
"@angular/http": "ng.http",
"rxjs/Observable": "Rx",

View File

@ -1,10 +1,8 @@
{
"presets": ["es2015"],
"plugins": [["transform-es2015-modules-umd", {
"globals": {
"@angular/core": "ng.core",
"@angular/compiler": "ng.compiler",
"@angular/platform-browser": "ng.platformBrowser",
"@angular/http": "ng.http",
"@angular/http/testing": "ng.http.testing",

View File

@ -1,7 +1,6 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"outDir": "../../../dist/packages-dist/http",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/http": ["../../../dist/packages-dist/http"],

View File

@ -1,7 +1,6 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"outDir": "../../../dist/packages-dist/platform-browser-dynamic",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/core/testing": ["../../../dist/packages-dist/core/testing"],

View File

@ -1,7 +1,6 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"outDir": "../../../dist/packages-dist/platform-browser",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/core/testing": ["../../../dist/packages-dist/core/testing"],

View File

@ -1,7 +1,6 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"outDir": "../../../dist/packages-dist/platform-server",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/core/testing": ["../../../dist/packages-dist/core/testing"],

View File

@ -1,7 +1,6 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"outDir": "../../../dist/packages-dist/router",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/common": ["../../../dist/packages-dist/common"],

View File

@ -1,4 +1,3 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {

View File

@ -16,9 +16,6 @@ PKGS=(
jasmine@2.4.1
webpack@2.1.0-beta.21
@angular2-material/{core,button}@2.0.0-alpha.8-1
babel-core@6.23.1
babel-loader@6.3.0
babel-preset-es2015@6.22.0
)
TMPDIR=${TMPDIR:-.}

View File

@ -30,7 +30,7 @@ export type CodegenExtension =
export function main(
project: string | VinylFile, cliOptions: CliOptions, codegen?: CodegenExtension,
options?: ts.CompilerOptions, skipImportRename?: boolean): Promise<any> {
options?: ts.CompilerOptions): Promise<any> {
try {
let projectDir = project;
// project is vinyl like file object
@ -117,7 +117,7 @@ export function main(
const tsickleCompilerHostOptions: tsickle.Options = {
googmodule: false,
untyped: true,
convertIndexImportShorthand: !skipImportRename &&
convertIndexImportShorthand:
ngOptions.target === ts.ScriptTarget.ES2015, // This covers ES6 too
};
@ -172,19 +172,13 @@ export function main(
// CLI entry point
if (require.main === module) {
let args = process.argv.slice(2);
let idx = args.indexOf('--skipImportRename');
let skipImportRename = false;
if (idx !== -1) {
args.splice(idx, 1);
skipImportRename = true;
}
const args = process.argv.slice(2);
let {options, fileNames, errors} = (ts as any).parseCommandLine(args);
check(errors);
const project = options.project || '.';
// TODO(alexeagle): command line should be TSC-compatible, remove "CliOptions" here
const cliOptions = new CliOptions(require('minimist')(args));
main(project, cliOptions, null, options, skipImportRename)
main(project, cliOptions, null, options)
.then((exitCode: any) => process.exit(exitCode))
.catch((e: any) => {
console.error(e.stack);

View File

@ -1,8 +1,7 @@
const entrypoints = [
'dist/packages-dist/core/typings/core.d.ts',
'dist/packages-dist/core/typings/testing/testing.d.ts',
'dist/packages-dist/core/typings/core.d.ts', 'dist/packages-dist/core/typings/testing/index.d.ts',
'dist/packages-dist/common/typings/common.d.ts',
'dist/packages-dist/common/typings/testing/testing.d.ts',
'dist/packages-dist/common/typings/testing/index.d.ts',
// The API surface of the compiler is currently unstable - all of the important APIs are exposed
// via @angular/core, @angular/platform-browser or @angular/platform-browser-dynamic instead.
//'dist/packages-dist/compiler/index.d.ts',
@ -10,19 +9,18 @@ const entrypoints = [
'dist/packages-dist/upgrade/typings/upgrade.d.ts',
'dist/packages-dist/upgrade/typings/static/static.d.ts',
'dist/packages-dist/platform-browser/typings/platform-browser.d.ts',
'dist/packages-dist/platform-browser/typings/testing/testing.d.ts',
'dist/packages-dist/platform-browser/typings/testing/index.d.ts',
'dist/packages-dist/platform-browser-dynamic/typings/platform-browser-dynamic.d.ts',
'dist/packages-dist/platform-browser-dynamic/typings/testing/testing.d.ts',
'dist/packages-dist/platform-browser-dynamic/typings/testing/index.d.ts',
'dist/packages-dist/platform-webworker/typings/platform-webworker.d.ts',
'dist/packages-dist/platform-webworker-dynamic/typings/platform-webworker-dynamic.d.ts',
'dist/packages-dist/platform-server/typings/platform-server.d.ts',
'dist/packages-dist/platform-server/typings/testing/testing.d.ts',
'dist/packages-dist/http/typings/http.d.ts',
'dist/packages-dist/http/typings/testing/testing.d.ts',
'dist/packages-dist/platform-server/typings/testing/index.d.ts',
'dist/packages-dist/http/typings/http.d.ts', 'dist/packages-dist/http/typings/testing/index.d.ts',
'dist/packages-dist/forms/typings/forms.d.ts', 'dist/packages-dist/router/typings/router.d.ts',
'dist/packages-dist/animations/typings/animations.d.ts',
'dist/packages-dist/platform-browser/typings/animations/animations.d.ts',
'dist/packages-dist/platform-browser/typings/animations/testing/testing.d.ts'
'dist/packages-dist/platform-browser/typings/animations/testing/index.d.ts'
];
const publicApiDir = 'tools/public_api_guard';

View File

@ -1,86 +0,0 @@
/** @experimental */
export declare function animate(timings: string | number, styles?: AnimationStyleMetadata | AnimationKeyframesSequenceMetadata): AnimationAnimateMetadata;
/** @experimental */
export declare class Animation {
constructor(input: AnimationMetadata | AnimationMetadata[]);
buildTimelines(startingStyles: StyleData | StyleData[], destinationStyles: StyleData | StyleData[]): AnimationTimelineInstruction[];
}
/** @experimental */
export interface AnimationGroupMetadata extends AnimationMetadata {
steps: AnimationMetadata[];
}
/** @experimental */
export interface AnimationKeyframesSequenceMetadata extends AnimationMetadata {
steps: AnimationStyleMetadata[];
}
/** @experimental */
export declare class AnimationModule {
}
/** @experimental */
export interface AnimationSequenceMetadata extends AnimationMetadata {
steps: AnimationMetadata[];
}
/** @experimental */
export interface AnimationStateMetadata extends AnimationMetadata {
name: string;
styles: AnimationStyleMetadata;
}
/** @experimental */
export interface AnimationStyleMetadata extends AnimationMetadata {
offset: number;
styles: StyleData[];
}
/** @experimental */
export interface AnimationTransitionMetadata extends AnimationMetadata {
animation: AnimationMetadata;
expr: string | ((fromState: string, toState: string) => boolean);
}
/** @experimental */
export declare class AnimationTrigger implements Trigger {
name: string;
states: {
[stateName: string]: StyleData;
};
transitionFactories: AnimationTransitionFactory[];
constructor(name: string, states: {
[stateName: string]: StyleData;
}, _transitionAsts: AnimationTransitionMetadata[]);
matchTransition(currentState: any, nextState: any): AnimationTransitionInstruction;
}
/** @experimental */
export declare const AUTO_STYLE = "*";
/** @experimental */
export declare function group(steps: AnimationMetadata[]): AnimationGroupMetadata;
/** @experimental */
export declare function keyframes(steps: AnimationStyleMetadata[]): AnimationKeyframesSequenceMetadata;
/** @experimental */
export declare function sequence(steps: AnimationMetadata[]): AnimationSequenceMetadata;
/** @experimental */
export declare function state(name: string, styles: AnimationStyleMetadata): AnimationStateMetadata;
/** @experimental */
export declare function style(tokens: {
[key: string]: string | number;
} | Array<{
[key: string]: string | number;
}>): AnimationStyleMetadata;
/** @experimental */
export declare function transition(stateChangeExpr: string | ((fromState: string, toState: string) => boolean), steps: AnimationMetadata | AnimationMetadata[]): AnimationTransitionMetadata;
/** @experimental */
export declare function trigger(name: string, definitions: AnimationMetadata[]): AnimationTrigger;