Skip to content

Commit fd701b0

Browse files
committed
build: publish tree of files rather than FESMs (angular#18541)
* Remove now unnecessary portions of build. * Add a compilePackageES5 method to build ES5 from sources * Rework all package.json and rollup config files to new format * Remove "extends" from tsconfig-build.json files and fixup compilation roots PR Close angular#18541
1 parent ee04217 commit fd701b0

File tree

160 files changed

+1066
-879
lines changed

Some content is hidden

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

160 files changed

+1066
-879
lines changed

Diff for: build.sh

+45-97
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ PACKAGES=(core
2626
benchpress)
2727

2828
NODE_PACKAGES=(compiler-cli
29-
benchpress)
29+
benchpress
30+
tsc-wrapped)
3031

3132
BUILD_ALL=true
3233
BUNDLE=true
@@ -107,76 +108,36 @@ containsElement () {
107108
return 1
108109
}
109110

110-
#######################################
111-
# Downlevel ES2015 to ESM/ES5
112-
# Arguments:
113-
# param1 - Source folder
114-
# param2 - Naming suffix to apply. Must end in ".ts" (defaults to .es5.ts)
115-
# Returns:
116-
# None
117-
#######################################
118-
downlevelES2015() {
119-
# Iterate over the files in this directory, converting to .es5.ts
120-
regex="(.+).js"
121-
for file in ${1}/*.js ; do
122-
if [[ ${file} =~ $regex ]]; then
123-
ts_file="${BASH_REMATCH[1]}${2:-".es5.ts"}"
124-
cp ${file} ${ts_file}
125-
126-
echo "====== $TSC ${ts_file} --target es5 --module es2015 --noLib --sourceMap --importHelpers"
127-
($TSC ${ts_file} --target es5 --module es2015 --noLib --sourceMap --importHelpers) > /dev/null 2>&1 || true
128-
mapSources "${BASH_REMATCH[1]}${2:-".es5.js"}"
129-
rm -f ${ts_file}
130-
fi
131-
done
132-
133-
# Recurse for sub directories
134-
for DIR in ${1}/* ; do
135-
isIgnoredDirectory ${DIR} && continue
136-
downlevelES2015 ${DIR}
137-
done
138-
}
139-
140111
#######################################
141112
# Rollup index files recursively, ignoring blacklisted directories
142113
# Arguments:
143114
# param1 - Base source folder
144115
# param2 - Destination directory
145-
# param3 - Config file
146116
# Returns:
147117
# None
148118
#######################################
149119
rollupIndex() {
150120
# Iterate over the files in this directory, rolling up each into ${2} directory
151121
local regex=".+/(.+)/index.js"
152-
if [[ "${1}/index.js" =~ $regex ]]; then
153-
in_file="${1}/index.js"
154-
out_file="${2}/${BASH_REMATCH[1]}.js"
122+
in_file="${1}/index.js"
123+
out_file="${2}/index.js"
155124

156-
echo "====== $ROLLUP -i ${in_file} -o ${out_file}"
125+
BANNER_TEXT=`cat ${LICENSE_BANNER}`
157126

158-
if [[ -f "${3}" ]]; then
159-
$ROLLUP -i ${in_file} -o ${out_file} -c ${3} --sourcemap
160-
else
161-
$ROLLUP -i ${in_file} -o ${out_file} --sourcemap
162-
fi
163-
cat ${LICENSE_BANNER} > ${out_file}.tmp
164-
cat ${out_file} >> ${out_file}.tmp
165-
mv ${out_file}.tmp ${out_file}
166-
167-
mapSources "${out_file}"
168-
169-
# Recurse for sub directories
170-
for DIR in ${1}/* ; do
171-
isIgnoredDirectory ${DIR} && continue
172-
# NOTE: We need to re-run this regex and use the new match as Bash doesn't have closures
173-
if [[ "${1}/index.js" =~ $regex ]]; then
174-
rollupIndex ${DIR} ${2}/${BASH_REMATCH[1]} "$(dirname $3)/${BASH_REMATCH[1]}/rollup.config.js"
175-
fi
176-
done
127+
if [[ -f ${in_file} ]]; then
128+
echo "=========== $ROLLUP -i ${in_file} -o ${out_file} -c ${ROOT_DIR}/rollup.config.js --sourcemap"
129+
$ROLLUP -i ${in_file} -o ${out_file} --sourcemap -f es --banner "$BANNER_TEXT" >/dev/null 2>&1
177130
fi
178-
}
179131

132+
# Recurse for sub directories
133+
for DIR in ${1}/* ; do
134+
isIgnoredDirectory ${DIR} && continue
135+
# NOTE: We need to re-run this regex and use the new match as Bash doesn't have closures
136+
if [[ "${DIR}/index.js" =~ $regex ]]; then
137+
rollupIndex ${DIR} ${2}/${BASH_REMATCH[1]}
138+
fi
139+
done
140+
}
180141

181142
#######################################
182143
# Recursively runs rollup on any entry point that has a "rollup.config.js" file
@@ -186,17 +147,11 @@ rollupIndex() {
186147
# None
187148
#######################################
188149
runRollup() {
189-
local regex="dest: ['\"](.+)['\"],*"
190150
if [[ -f "${1}/rollup.config.js" ]]; then
191151
cd ${1}
192152

193153
echo "====== $ROLLUP -c ${1}/rollup.config.js"
194-
$ROLLUP -c rollup.config.js --sourcemap
195-
196-
local dest_line=$(cat "${1}/rollup.config.js" | grep 'dest:')
197-
if [[ ${dest_line} =~ $regex ]]; then
198-
mapSources "${BASH_REMATCH[1]}"
199-
fi
154+
$ROLLUP -c rollup.config.js --sourcemap >/dev/null 2>&1
200155

201156
# Recurse for sub directories
202157
for DIR in ${1}/* ; do
@@ -241,7 +196,6 @@ minify() {
241196
if [[ "${base_file}" =~ $regex && "${base_file##*.}" != "map" ]]; then
242197
local out_file=$(dirname "${file}")/${BASH_REMATCH[1]}.min.js
243198
$UGLIFYJS -c --screw-ie8 --comments -o ${out_file} --source-map ${out_file}.map --source-map-include-sources ${file}
244-
mapSources "${out_file}"
245199
fi
246200
done
247201
}
@@ -252,19 +206,18 @@ minify() {
252206
# param1 - Source directory
253207
# param2 - Out dir
254208
# param3 - Package Name
255-
# param4 - Is child (are we recursing?)
256209
# Returns:
257210
# None
258211
#######################################
259212
compilePackage() {
260213
echo "====== [${3}]: COMPILING: ${NGC} -p ${1}/tsconfig-build.json"
261214
# For NODE_PACKAGES items (not getting rolled up)
262-
if containsElement "${PACKAGE}" "${NODE_PACKAGES[@]}"; then
215+
if containsElement "${3}" "${NODE_PACKAGES[@]}"; then
263216
$TSC -p ${1}/tsconfig-build.json
264217
else
265218
local package_name=$(basename "${2}")
266219
$NGC -p ${1}/tsconfig-build.json
267-
echo "====== Create ${1}/../${package_name}.d.ts re-export file for Closure"
220+
echo "====== Create ${1}/../${package_name}.d.ts re-export file for tsickle"
268221
echo "$(cat ${LICENSE_BANNER}) ${N} export * from './${package_name}/index'" > ${2}/../${package_name}.d.ts
269222
echo "{\"__symbolic\":\"module\",\"version\":3,\"metadata\":{},\"exports\":[{\"from\":\"./${package_name}/index\"}],\"flatModuleIndexRedirect\":true}" > ${2}/../${package_name}.metadata.json
270223
fi
@@ -274,24 +227,31 @@ compilePackage() {
274227
BASE_DIR=$(basename "${DIR}")
275228
# Skip over directories that are not nested entry points
276229
[[ -e ${DIR}/tsconfig-build.json && "${BASE_DIR}" != "integrationtest" ]] || continue
277-
compilePackage ${DIR} ${2}/${BASE_DIR} ${3} true
230+
compilePackage ${DIR} ${2}/${BASE_DIR} ${3}
278231
done
279232
}
280233

281234
#######################################
282-
# Moves typings and metadata files appropriately
235+
# Recursively compile package
283236
# Arguments:
284-
# param1 - Source of typings & metadata files
285-
# param2 - Root of destination directory
286-
# param3 - Package name (needed to correspond to name of d.ts and metadata.json files)
237+
# param1 - Source directory
238+
# param2 - Out dir
239+
# param3 - Package Name
287240
# Returns:
288241
# None
289242
#######################################
290-
moveTypings() {
291-
if [[ -f ${1}/index.d.ts && -f ${1}/index.metadata.json ]]; then
292-
mv ${1}/index.d.ts ${1}/${2}.d.ts
293-
mv ${1}/index.metadata.json ${1}/${2}.metadata.json
294-
fi
243+
compilePackageES5() {
244+
echo "====== [${3}]: COMPILING: ${NGC} -p ${1}/tsconfig-build.json --target es5 -d false --outDir ${2} --importHelpers true --sourceMap"
245+
local package_name=$(basename "${2}")
246+
$NGC -p ${1}/tsconfig-build.json --target es5 -d false --outDir ${2} --importHelpers true --sourceMap
247+
248+
for DIR in ${1}/* ; do
249+
[ -d "${DIR}" ] || continue
250+
BASE_DIR=$(basename "${DIR}")
251+
# Skip over directories that are not nested entry points
252+
[[ -e ${DIR}/tsconfig-build.json && "${BASE_DIR}" != "integrationtest" ]] || continue
253+
compilePackageES5 ${DIR} ${2} ${3}
254+
done
295255
}
296256

297257
#######################################
@@ -314,19 +274,6 @@ addNgcPackageJson() {
314274
done
315275
}
316276

317-
#######################################
318-
# This is read by NGC to be able to find the flat module index.
319-
# Arguments:
320-
# param1 - JavaScript file on which to re-map sources
321-
# Returns:
322-
# None
323-
#######################################
324-
mapSources() {
325-
if [[ -f "${1}.map" ]]; then
326-
$MAP_SOURCES -f "${1}"
327-
fi
328-
}
329-
330277
updateVersionReferences() {
331278
NPM_DIR="$1"
332279
(
@@ -343,8 +290,7 @@ echo "====== BUILDING: Version ${VERSION}"
343290
N="
344291
"
345292
TSC=`pwd`/node_modules/.bin/tsc
346-
NGC="node --max-old-space-size=3000 dist/packages-dist/tsc-wrapped/src/main"
347-
MAP_SOURCES="node `pwd`/scripts/build/map_sources.js "
293+
NGC="node --max-old-space-size=3000 `pwd`/dist/packages-dist/tsc-wrapped/src/main"
348294
UGLIFYJS=`pwd`/node_modules/.bin/uglifyjs
349295
TSCONFIG=./tools/tsconfig.json
350296
ROLLUP=`pwd`/node_modules/.bin/rollup
@@ -446,8 +392,10 @@ do
446392
SRC_DIR=${ROOT_DIR}/${PACKAGE}
447393
ROOT_OUT_DIR=${PWD}/dist/packages
448394
OUT_DIR=${ROOT_OUT_DIR}/${PACKAGE}
395+
OUT_DIR_ESM5=${ROOT_OUT_DIR}/${PACKAGE}/esm5
449396
NPM_DIR=${PWD}/dist/packages-dist/${PACKAGE}
450-
MODULES_DIR=${NPM_DIR}/@angular
397+
ESM15_DIR=${NPM_DIR}/esm15
398+
ESM5_DIR=${NPM_DIR}/esm5
451399
BUNDLES_DIR=${NPM_DIR}/bundles
452400

453401
LICENSE_BANNER=${ROOT_DIR}/license-banner.txt
@@ -466,15 +414,15 @@ do
466414

467415
echo "====== Copy ${PACKAGE} typings"
468416
rsync -a --exclude=*.js --exclude=*.js.map ${OUT_DIR}/ ${NPM_DIR}
469-
moveTypings ${NPM_DIR} ${PACKAGE}
470417

471418
(
472419
cd ${SRC_DIR}
473420
echo "====== Rollup ${PACKAGE}"
474-
rollupIndex ${OUT_DIR} ${MODULES_DIR} ${ROOT_DIR}
421+
rollupIndex ${OUT_DIR} ${ESM15_DIR} ${ROOT_DIR}
475422

476-
echo "====== Downleveling ES2015 to ESM/ES5"
477-
downlevelES2015 ${MODULES_DIR}
423+
echo "====== Produce ESM5 version"
424+
compilePackageES5 ${SRC_DIR} ${OUT_DIR_ESM5} ${PACKAGE}
425+
rollupIndex ${OUT_DIR_ESM5} ${ESM5_DIR} ${ROOT_DIR}
478426

479427
echo "====== Run rollup conversions on ${PACKAGE}"
480428
runRollup ${SRC_DIR}

Diff for: integration/hello_world__closure/closure.conf

+11-9
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,20 @@
1313
node_modules/zone.js/dist/zone_externs.js
1414

1515
--js node_modules/rxjs/**.js
16-
--process_common_js_modules
17-
--module_resolution=node
1816

19-
node_modules/@angular/core/@angular/core.js
20-
--js_module_root=node_modules/@angular/core
21-
node_modules/@angular/core/src/testability/testability.externs.js
17+
--js node_modules/@angular/core/package.json
18+
--js node_modules/@angular/core/esm15/index.js
19+
--js node_modules/@angular/core/src/testability/testability.externs.js
20+
21+
--js node_modules/@angular/common/package.json
22+
--js node_modules/@angular/common/esm15/index.js
2223

23-
node_modules/@angular/common/@angular/common.js
24-
--js_module_root=node_modules/@angular/common
24+
--js node_modules/@angular/platform-browser/package.json
25+
--js node_modules/@angular/platform-browser/esm15/index.js
2526

26-
node_modules/@angular/platform-browser/@angular/platform-browser.js
27-
--js_module_root=node_modules/@angular/platform-browser
27+
--module_resolution=node
28+
--package_json_entry_names es2015
29+
--process_common_js_modules
2830

2931
--js built/**.js
3032
--entry_point=built/src/main

Diff for: integration/hello_world__closure/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
1212
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
1313
"@angular/tsc-wrapped": "file:../../dist/packages-dist/tsc-wrapped",
14-
"google-closure-compiler": "20170409.0.0",
14+
"google-closure-compiler": "git+https://github.com/alexeagle/closure-compiler.git#packagejson.dist",
1515
"rxjs": "5.3.1",
1616
"typescript": "~2.3.1",
1717
"zone.js": "0.8.6"
@@ -29,4 +29,4 @@
2929
"preprotractor": "tsc -p e2e",
3030
"protractor": "protractor e2e/protractor.config.js"
3131
}
32-
}
32+
}

Diff for: integration/i18n/closure.conf

+8-7
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@ node_modules/zone.js/dist/zone_externs.js
1515
--js node_modules/rxjs/**.js
1616
--process_common_js_modules
1717
--module_resolution=node
18+
--package_json_entry_names es2015
1819

19-
node_modules/@angular/core/@angular/core.js
20-
--js_module_root=node_modules/@angular/core
21-
node_modules/@angular/core/src/testability/testability.externs.js
20+
--js node_modules/@angular/core/package.json
21+
--js node_modules/@angular/core/esm15/index.js
22+
--js node_modules/@angular/core/src/testability/testability.externs.js
2223

23-
node_modules/@angular/common/@angular/common.js
24-
--js_module_root=node_modules/@angular/common
24+
--js node_modules/@angular/common/package.json
25+
--js node_modules/@angular/common/esm15/index.js
2526

26-
node_modules/@angular/platform-browser/@angular/platform-browser.js
27-
--js_module_root=node_modules/@angular/platform-browser
27+
--js node_modules/@angular/platform-browser/package.json
28+
--js node_modules/@angular/platform-browser/esm15/index.js
2829

2930
--js built/**.js
3031
--entry_point=built/src/main

Diff for: integration/i18n/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser",
1212
"@angular/platform-server": "file:../../dist/packages-dist/platform-server",
1313
"@angular/tsc-wrapped": "file:../../dist/packages-dist/tsc-wrapped",
14-
"google-closure-compiler": "20170409.0.0",
14+
"google-closure-compiler": "git+https://github.com/alexeagle/closure-compiler.git#packagejson.dist",
1515
"rxjs": "5.3.1",
1616
"typescript": "~2.3.1",
1717
"zone.js": "0.8.6"

0 commit comments

Comments
 (0)