Skip to content

Commit 10cd71a

Browse files
devversionjelbourn
authored andcommitted
build: replace setup angular snapshots script with python script
In order to be able to take advantage of Google's official bazel docker images, we no longer can use a NodeJS script for setting up the snapshot builds because NodeJS is not installed in the image. Rather we need to convert the script to a python script in order to be able to perform the package.json modification. Since this script is not intended to be executed locally, we are free to use Python for this.
1 parent 2ce5ffd commit 10cd71a

File tree

3 files changed

+74
-67
lines changed

3 files changed

+74
-67
lines changed

.circleci/config.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ jobs:
364364
- *checkout_code
365365
- *restore_cache
366366
- *yarn_download
367-
- *yarn_install
368367

369-
- run: node ./scripts/circleci/setup-angular-snapshots.js
368+
- run: python ./scripts/circleci/setup-angular-snapshots.py --tag master
369+
- *yarn_install
370370
- run: ./scripts/circleci/run-local-browser-tests.sh
371371

372372

@@ -392,7 +392,7 @@ jobs:
392392
# we use ngcc to apply the ivy switches because ngcc currently does not handle the
393393
# UMD format which is used by Bazel when running tests. UMD processing is in
394394
# progress and tracked with FW-85.
395-
- run: bazel run @nodejs//:node -- ./scripts/circleci/setup-angular-snapshots.js --tag 8.1.0-next.1-ivy-aot+82e0b4a
395+
- run: python ./scripts/circleci/setup-angular-snapshots.py --tag 8.1.0-next.1-ivy-aot+82e0b4a
396396
# Disable type checking when building with Ivy. This is necessary because
397397
# type checking is not complete yet and can incorrectly break compilation.
398398
# Issue is tracked with FW-1004.
@@ -417,7 +417,7 @@ jobs:
417417
- *setup_bazel_remote_execution
418418

419419
# Setup Angular ivy snapshots built with ngtsc.
420-
- run: bazel run @nodejs//:node -- ./scripts/circleci/setup-angular-snapshots.js --tag master-ivy-aot
420+
- run: python ./scripts/circleci/setup-angular-snapshots.py --tag master-ivy-aot
421421
# Disable type checking when building with Ivy. This is necessary because
422422
# type checking is not complete yet and can incorrectly break compilation.
423423
# Issue is tracked with FW-1004.

scripts/circleci/setup-angular-snapshots.js

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
"""
2+
Script that sets up the Angular snapshot github builds. We set up the snapshot builds by
3+
overwriting the versions in the "package.json" and taking advantage of Yarn's resolutions
4+
feature. Yarn resolutions will be used to flatten nested Angular packages because by default
5+
Yarn does not flatten any dependency. See:
6+
7+
node_modules/compiler@snapshot
8+
node_modules/compiler-cli@snapshot
9+
node_modules/[email protected]
10+
11+
Note that we cannot just use Yarn's `--flat` option because that would mean that it tries
12+
to flatten **all** dependencies and could cause unexpected results. We **only** want to
13+
explicitly flatten out all `@angular/*` dependencies. This can be achieved with resolutions.
14+
Read more here: https://yarnpkg.com/lang/en/docs/package-json/#toc-resolutions
15+
"""
16+
17+
import json
18+
import os
19+
import argparse
20+
21+
def collect_angular_deps(obj, result):
22+
for item in obj:
23+
if (item.startswith('@angular/')):
24+
result.append(item)
25+
26+
project_dir = os.path.realpath(os.path.join(os.path.dirname(__file__), '../../'))
27+
package_json_path = os.path.join(project_dir, 'package.json')
28+
29+
parser = argparse.ArgumentParser(description='Setup Angular snapshot packages')
30+
parser.add_argument('--tag', required = True)
31+
parsed_args = parser.parse_args()
32+
33+
with open(package_json_path, 'r') as package_json:
34+
data = json.load(package_json)
35+
angular_pkgs = []
36+
37+
collect_angular_deps(data['dependencies'], angular_pkgs)
38+
collect_angular_deps(data['devDependencies'], angular_pkgs)
39+
40+
if not 'resolutions' in data:
41+
data['resolutions'] = {}
42+
43+
print('Setting up snapshot builds for:')
44+
45+
for pkg in angular_pkgs:
46+
new_url = "github:angular/%s-builds#%s" % (pkg.split('/')[1], parsed_args.tag)
47+
48+
print(" %s -> %s" % (pkg, new_url))
49+
50+
# Add resolutions for each package in the format "**/{PACKAGE}" so that all
51+
# nested versions of that specific Angular package will have the same version.
52+
data['resolutions']['**/%s' % pkg] = new_url
53+
54+
# Since the resolutions only cover the version of all nested installs, we also need
55+
# to explicitly set the version for the package listed in the project "package.json".
56+
data['dependencies'][pkg] = new_url
57+
58+
# In case this dependency was previously a dev dependency, just remove it because we
59+
# re-added it as a normal dependency for simplicity.
60+
if pkg in data['devDependencies']:
61+
del data['devDependencies'][pkg]
62+
63+
new_package_json = json.dumps(data, indent = 2)
64+
65+
with open(package_json_path, 'w') as package_json_out:
66+
package_json_out.write(new_package_json)
67+
68+
print('')
69+
print('Successfully added the "resolutions" to the "package.json".')
70+
print('Please run "yarn install" in the project to update the lock file.')

0 commit comments

Comments
 (0)