build: add source maps into NPM distribution (#15159)

Previous to 2.x there were some source maps distrubted, but they didn't go
all the way back to the TypeScript sources and they weren't available for
all JavaScript distrubted to NPM.

With this change source maps will be available for FESM distributions as
well as UMD and will go all the way back to TypeScript sources.

Fixes #15184
This commit is contained in:
Jason Aden 2017-03-16 12:55:15 -07:00 committed by Chuck Jazdzewski
parent a4076c70cc
commit 992aa17361
5 changed files with 132 additions and 113 deletions

View File

@ -115,7 +115,8 @@ downlevelES2015() {
cp ${file} ${ts_file}
echo "====== $TSC ${ts_file} --target es5 --module es2015 --noLib"
($TSC ${ts_file} --target es5 --module es2015 --noLib) > /dev/null 2>&1 || true
($TSC ${ts_file} --target es5 --module es2015 --noLib --sourceMap) > /dev/null 2>&1 || true
mapSources "${BASH_REMATCH[1]}${2:-".es5.js"}"
rm -f ${ts_file}
fi
done
@ -131,30 +132,37 @@ downlevelES2015() {
# Rollup index files recursively, ignoring blacklisted directories
# Arguments:
# param1 - Base source folder
# param2 - Source folder being rolled up (
# param2 - Naming suffix to apply. Must end in ".ts" (defaults to .es5.ts)
# param2 - Destination directory
# param3 - Config file
# Returns:
# None
#######################################
rollupIndex() {
# Iterate over the files in this directory, rolling up each into ${2} directory
regex=".+/(.+)/index.js"
local regex=".+/(.+)/index.js"
if [[ "${1}/index.js" =~ $regex ]]; then
in_file="${1}/index.js"
out_file="${2}/${BASH_REMATCH[1]}.js"
echo "====== $ROLLUP -i ${in_file} -o ${out_file}"
$ROLLUP -i ${in_file} -o ${out_file}
if [[ -f "${3}" ]]; then
$ROLLUP -i ${in_file} -o ${out_file} -c ${3} --sourcemap
else
$ROLLUP -i ${in_file} -o ${out_file} --sourcemap
fi
cat ${LICENSE_BANNER} > ${out_file}.tmp
cat ${out_file} >> ${out_file}.tmp
mv ${out_file}.tmp ${out_file}
mapSources "${out_file}"
# Recurse for sub directories
for DIR in ${1}/* ; do
isIgnoredDirectory ${DIR} && continue
# NOTE: We need to re-run this regex and use the new match as Bash doesn't have closures
if [[ "${1}/index.js" =~ $regex ]]; then
rollupIndex ${DIR} ${2}/${BASH_REMATCH[1]}
rollupIndex ${DIR} ${2}/${BASH_REMATCH[1]} "$(dirname $3)/${BASH_REMATCH[1]}/rollup.config.js"
fi
done
fi
@ -165,16 +173,21 @@ rollupIndex() {
# Recursively runs rollup on any entry point that has a "rollup.config.js" file
# Arguments:
# param1 - Base source folder containing rollup.config.js
# param2 - Package name
# Returns:
# None
#######################################
runRollup() {
if [[ "${1}/rollup.config.js" =~ $regex ]]; then
local regex="dest: ['\"](.+)['\"],*"
if [[ -f "${1}/rollup.config.js" ]]; then
cd ${1}
echo "====== $ROLLUP -c ${1}/rollup.config.js"
$ROLLUP -c rollup.config.js
$ROLLUP -c rollup.config.js --sourcemap
local dest_line=$(cat "${1}/rollup.config.js" | grep 'dest:')
if [[ ${dest_line} =~ $regex ]]; then
mapSources "${BASH_REMATCH[1]}"
fi
# Recurse for sub directories
for DIR in ${1}/* ; do
@ -193,7 +206,7 @@ runRollup() {
#######################################
addBanners() {
for file in ${1}/*; do
if [[ -f ${file} ]]; then
if [[ -f ${file} && "${file##*.}" != "map" ]]; then
cat ${LICENSE_BANNER} > ${file}.tmp
cat ${file} >> ${file}.tmp
mv ${file}.tmp ${file}
@ -216,8 +229,10 @@ minify() {
for file in "${files[@]}"; do
echo "${file}"
base_file=$( basename "${file}" )
if [[ "${base_file}" =~ $regex ]]; then
$UGLIFYJS -c --screw-ie8 --comments -o ${1}/${BASH_REMATCH[1]}.min.js ${file}
if [[ "${base_file}" =~ $regex && "${base_file##*.}" != "map" ]]; then
local out_file=$(dirname "${file}")/${BASH_REMATCH[1]}.min.js
$UGLIFYJS -c --screw-ie8 --comments -o ${out_file} --source-map ${out_file}.map --source-map-include-sources ${file}
mapSources "${out_file}"
fi
done
}
@ -288,6 +303,19 @@ addNgcPackageJson() {
done
}
#######################################
# This is read by NGC to be able to find the flat module index.
# Arguments:
# param1 - JavaScript file on which to re-map sources
# Returns:
# None
#######################################
mapSources() {
if [[ -f "${1}.map" ]]; then
$MAP_SOURCES -f "${1}"
fi
}
VERSION="${VERSION_PREFIX}${VERSION_SUFFIX}"
ROUTER_VERSION="${ROUTER_VERSION_PREFIX}${VERSION_SUFFIX}"
echo "====== BUILDING: Version ${VERSION} (Router ${ROUTER_VERSION})"
@ -296,6 +324,7 @@ N="
"
TSC=`pwd`/node_modules/.bin/tsc
NGC="node --max-old-space-size=3000 dist/tools/@angular/tsc-wrapped/src/main"
MAP_SOURCES="node `pwd`/scripts/build/map_sources.js "
UGLIFYJS=`pwd`/node_modules/.bin/uglifyjs
TSCONFIG=./tools/tsconfig.json
ROLLUP=`pwd`/node_modules/.bin/rollup
@ -411,7 +440,7 @@ do
(
cd ${SRC_DIR}
echo "====== Rollup ${PACKAGE}"
rollupIndex ${OUT_DIR} ${MODULES_DIR}
rollupIndex ${OUT_DIR} ${MODULES_DIR} ${ROOT_DIR}
echo "====== Downleveling ES2015 to ESM/ES5"
downlevelES2015 ${MODULES_DIR}

View File

@ -2591,6 +2591,10 @@
"version": "0.17.9",
"dev": true
},
"es6-promise": {
"version": "3.3.1",
"dev": true
},
"es6-symbol": {
"version": "3.0.2",
"dev": true
@ -5569,47 +5573,7 @@
},
"rollup": {
"version": "0.26.3",
"dev": true,
"dependencies": {
"ansi-regex": {
"version": "2.0.0",
"dev": true
},
"ansi-styles": {
"version": "2.2.1",
"dev": true
},
"chalk": {
"version": "1.1.3",
"dev": true
},
"has-ansi": {
"version": "2.0.0",
"dev": true
},
"source-map": {
"version": "0.1.32",
"dev": true,
"dependencies": {
"amdefine": {
"version": "1.0.1",
"dev": true
}
}
},
"source-map-support": {
"version": "0.4.0",
"dev": true
},
"strip-ansi": {
"version": "3.0.1",
"dev": true
},
"supports-color": {
"version": "2.0.0",
"dev": true
}
}
"dev": true
},
"rollup-plugin-commonjs": {
"version": "5.0.5",
@ -5640,6 +5604,24 @@
"rxjs": {
"version": "5.0.1"
},
"sander": {
"version": "0.5.1",
"dev": true,
"dependencies": {
"glob": {
"version": "7.1.1",
"dev": true
},
"graceful-fs": {
"version": "4.1.11",
"dev": true
},
"rimraf": {
"version": "2.6.1",
"dev": true
}
}
},
"sauce-connect-launcher": {
"version": "0.13.0",
"dev": true,
@ -5848,6 +5830,10 @@
}
}
},
"sorcery": {
"version": "0.10.0",
"dev": true
},
"source-list-map": {
"version": "0.1.5",
"dev": true
@ -5872,6 +5858,10 @@
}
}
},
"sourcemap-codec": {
"version": "1.3.0",
"dev": true
},
"sparkles": {
"version": "1.0.0",
"dev": true

104
npm-shrinkwrap.json generated
View File

@ -3745,6 +3745,12 @@
"resolved": "https://registry.npmjs.org/es6-module-loader/-/es6-module-loader-0.17.9.tgz",
"dev": true
},
"es6-promise": {
"version": "3.3.1",
"from": "es6-promise@>=3.1.2 <4.0.0",
"resolved": "https://registry.npmjs.org/es6-promise/-/es6-promise-3.3.1.tgz",
"dev": true
},
"es6-symbol": {
"version": "3.0.2",
"from": "es6-symbol@>=3.0.2 <3.1.0",
@ -8145,65 +8151,7 @@
"version": "0.26.3",
"from": "rollup@0.26.3",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-0.26.3.tgz",
"dev": true,
"dependencies": {
"ansi-regex": {
"version": "2.0.0",
"from": "ansi-regex@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.0.0.tgz",
"dev": true
},
"ansi-styles": {
"version": "2.2.1",
"from": "ansi-styles@>=2.2.1 <3.0.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz",
"dev": true
},
"chalk": {
"version": "1.1.3",
"from": "chalk@>=1.1.1 <2.0.0",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"dev": true
},
"has-ansi": {
"version": "2.0.0",
"from": "has-ansi@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz",
"dev": true
},
"source-map": {
"version": "0.1.32",
"from": "source-map@0.1.32",
"resolved": "https://registry.npmjs.org/source-map/-/source-map-0.1.32.tgz",
"dev": true,
"dependencies": {
"amdefine": {
"version": "1.0.1",
"from": "amdefine@>=0.0.4",
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
"dev": true
}
}
},
"source-map-support": {
"version": "0.4.0",
"from": "source-map-support@>=0.4.0 <0.5.0",
"resolved": "https://registry.npmjs.org/source-map-support/-/source-map-support-0.4.0.tgz",
"dev": true
},
"strip-ansi": {
"version": "3.0.1",
"from": "strip-ansi@>=3.0.0 <4.0.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz",
"dev": true
},
"supports-color": {
"version": "2.0.0",
"from": "supports-color@>=2.0.0 <3.0.0",
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz",
"dev": true
}
}
"dev": true
},
"rollup-plugin-commonjs": {
"version": "5.0.5",
@ -8248,6 +8196,32 @@
"from": "rxjs@5.0.1",
"resolved": "https://registry.npmjs.org/rxjs/-/rxjs-5.0.1.tgz"
},
"sander": {
"version": "0.5.1",
"from": "sander@>=0.5.0 <0.6.0",
"resolved": "https://registry.npmjs.org/sander/-/sander-0.5.1.tgz",
"dev": true,
"dependencies": {
"glob": {
"version": "7.1.1",
"from": "glob@>=7.0.5 <8.0.0",
"resolved": "https://registry.npmjs.org/glob/-/glob-7.1.1.tgz",
"dev": true
},
"graceful-fs": {
"version": "4.1.11",
"from": "graceful-fs@>=4.1.3 <5.0.0",
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz",
"dev": true
},
"rimraf": {
"version": "2.6.1",
"from": "rimraf@>=2.5.2 <3.0.0",
"resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.6.1.tgz",
"dev": true
}
}
},
"sauce-connect-launcher": {
"version": "0.13.0",
"from": "sauce-connect-launcher@>=0.13.0 <0.14.0",
@ -8550,6 +8524,12 @@
}
}
},
"sorcery": {
"version": "0.10.0",
"from": "sorcery@latest",
"resolved": "https://registry.npmjs.org/sorcery/-/sorcery-0.10.0.tgz",
"dev": true
},
"source-list-map": {
"version": "0.1.5",
"from": "source-list-map@>=0.1.0 <0.2.0",
@ -8584,6 +8564,12 @@
}
}
},
"sourcemap-codec": {
"version": "1.3.0",
"from": "sourcemap-codec@>=1.3.0 <2.0.0",
"resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.3.0.tgz",
"dev": true
},
"sparkles": {
"version": "1.0.0",
"from": "sparkles@>=1.0.0 <2.0.0",

View File

@ -85,6 +85,7 @@
"rollup-plugin-commonjs": "^5.0.5",
"selenium-webdriver": "^2.53.3",
"semver": "^5.1.0",
"sorcery": "^0.10.0",
"source-map": "^0.5.6",
"source-map-support": "^0.4.2",
"systemjs": "0.18.10",

View File

@ -0,0 +1,13 @@
var path = require('path');
var sorcery = require('sorcery');
var yargs = require('yargs');
var argv = require('yargs')
.alias('f', 'file')
.argv;
sorcery.load(argv.file).then(function(chain) {
chain.write();
});