Specifically:
1) Adding a new //tools/typescript/definitions:build_ts ts_library()
target which uses `skipLibCheck=false` and type checks all
definition files once.
2) Making all other ts_library() targets (specifically the ones defined
in build_webui() and webui_ts_library()) to depend on the new
target.
3) Modifying ts_library() to automatically add `skipLibCheck=true`
when
`skipLibCheck` is not specified anywhere in the inheritance chain
AND
no definition files outside of tools/typescript/definitions exist.
4) Also fixed TsLibraryTest.testEnableSourceMaps which was erroneously
passing due to a bug in _read_file() that was always reading from
the same folder, ignoring its input parameter, resulting in
comparing the expected file with itself. The actual file contains
an absolute path embedded in the generated sourcemap and therefore
the comparison needs to be relaxed to work across across machines.
#1 and #2 mitigate any missed type coverage from #3, such that any
TypeScript errors within tools/typescript/definitions/*.d.ts are still
caught during the build.
Essentially this change modifies the build such that some type
checking work that was done by the TS compiler N times (where N=number
of ts_library() targets) is only done once.
Combined with the follow-up related CL this improves TS build times by
~21.5% (43.8s -> 34.4s) on a local Linux build with
`use_remoteexec=false`. This CL alone accounts for the majority of
that improvement (~20% out of 21.5%).
Bug: 397737230
Change-Id: I14bc721e0e2a16ded0d71909d77a8e9b468f3519
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6292793
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1425476}
Previously only the last tsconfig file in the inheritance chain would be
validated (usually specified with `tsconfig_base=` or automatically
inferred when not specified). Any parent files referenced via "extends:
..." would not be validated.
This is in preparation of walking the tsconfig inheritance chain to
automatically deduce when to use `skipLibCheck=true` to improve overall
TypeScript build time performance.
Bug: 397737230
Change-Id: I0ccd5fe3758fe915e437d8bc443fcb85a85c0159
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6300796
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1424909}
ts_library() should be WebUI-agnostic as much as possible and
WebUI-specific concepts should be dealt with in higher WebUI-aware
layers like build_webui(), build_webui_tests() or webui_ts_library().
Bug: 397737230
Change-Id: I970fd62886bac82685bc36e618c4fdc5f7d5a5e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6289211
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1424245}
Instead of only allowing mapping for 2 types:
"chrome-untrusted://" + scheme-relative imports
"chrome://" + scheme-relative imports
Also allow 2 more options, useful for some build_webui() targets:
"chrome://" imports only (needed by PDF Viewer component extension)
Relative imports only (useful for targets containing code shared with
both trusted and untrusted UIs).
This is done by changing the is_untrusted boolean parameter to a
webui_context_type parameter with 4 options:
"trusted": Map trusted and scheme-relative imports (default)
"untrusted": Map untrusted and scheme-relative imports
"trusted_only": Map only trusted imports
"relative": Map only scheme-relative imports
This is in preparation for setting the |webui_host| parameter, used to
compute |webui_context_type|, in more places. This will enable
detection of imports from incorrect schemes at build time.
Bug: 328733315
Change-Id: I7e8980d1232bedcb9ea680f2720f365c3a4e66dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5370138
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1273097}
Add webui_path_mappings() gn rule that generates a json file containing
a set of path mappings corresponding to a list of dependencies. Unlike
ts_library()'s path mapping, the new rule accepts an is_untrusted
parameter so that it can only add mappings for the appropriate URL
scheme (chrome:// or chrome-untrusted://), rather than adding chrome://
mappings in all cases.
Bug: 328733315
Change-Id: Icc7c3566cdcbebfe05dbaf68eca7b7b04c8dc75e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5353398
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1271299}
1) Expose source map generation via a new dedicated enable_source_maps
flag
2) Remove inlineSourceMap, inlineSources and sourceMap from the
allowlist of tsconfig flags
3) Update all references (new_tab_page, CrOS manage_mirrorsync, CrOS
file_manager) to use the new flag
4) Update ts_library presubmit tests to test inlined source maps, since
these are the only ones actually used currently.
5) Update docs
This is part of the effort to add source maps support to build_webui()
for non-optimized builds.
Bug: 1416356
Change-Id: I49e84cbd598016488e2556288bd191c979653b25
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4252237
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1105984}
This will help eliminate missing dependencies, which often have been the
source of transient/flaky build errors.
Previously missing dependencies would go uncaught and opened the door
for flaky build errors on bots, when the order of ts_library() target
execution happened differently.
After this CL, any missing dependencies to ts_library() targets under
ui/webui/resources/ will result in a consistent build time error.
Bug: 1402829
Change-Id: I27b7859b07f2b4061d949370a6287a637aa224d9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4194970
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1099586}
When generating sourcemaps via create_js_source_maps and ts_library
the paths are relative to the directory the command is executed from.
This can lead to difficulty when merging sourcemaps as the various
steps are executed from different directories.
The sourceRoot key in tsconfig is leveraged to provide an absolute
root from where the source files reside. This enables the merging step
to remap the paths based on the new sourceRoot. This key is added when
the presence of the "inlineSourceMap" or "sourceMap" key are
identified in the tsconfig_base file.
Fixed: 1354414
Test: ./tools/typescript/ts_library_test.py
Test: ./create_js_source_maps_test.py
Change-Id: I083d274f10b96e81093c0bf78c26782a4cd9d212
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3867089
Auto-Submit: Ben Reich <benreich@chromium.org>
Reviewed-by: Tibor Goldschwendt <tiborg@chromium.org>
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Tibor Goldschwendt <tiborg@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1044005}
Change the output files to be suffixed with the action name.
Add `testonly` attribute to be accepted by ts_library() so
ts_library() marked as `testonly` don't get shipped to production
builds.
Bug: b:228405091
Change-Id: I47bdce9677ad1c19ffa39b932bc6208302b3e403
Cq-Do-Not-Cancel-Tryjobs: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3715827
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Mike Dougherty <michaeldo@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1020010}
The presence of TypeScript's `composite` flag [1] causes additional
*.d.ts output files to be produced from a ts_library() target and
and in order to properly declare such files with Ninja, need to use the
dedicated `composite` property of ts_library() instead of directly
adding such a flag in the tsconfig.json file.
Modifying ts_library.py to perform a validation step for input tsconfig
files to catch such errors.
Also making ts_library_test.py to only run with Python 3.
[1] https://www.typescriptlang.org/tsconfig#composite
Bug: None
Change-Id: I58bae4009fba5481e4e729ffd440bb8bcb37985f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3640285
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Christopher Lam <calamity@chromium.org>
Commit-Queue: Christopher Lam <calamity@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1002408}
In some cases it is useful to be able to have files be part of a
ts_library() call that shouldn't end up in the manifest that is used to
set up a grd file for serving the files at runtime. Add an option to
exclude certain files from the manifest. Also add a test for the new
option, and fix a minor issue with one of the existing ts library tests
where the check being used did not work when run with Python 3.
These new options will be used by the PDF viewer, which contains files
used by the internal plugin and Print Preview, when it is migrated to
use the TS compiler.
Bug: 1260303
Change-Id: Ib41e28edaef6f0628e1aa9599bafd7b06628c27e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3378656
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#957679}
1) Leveraging 'extends' in generated tsconfig files, instead of copying
tsconfig_base.json into the generated tsconfig.json.
This results in generating smaller tsconfig.json files. Also using
OrderedDict(), to produce a fixed order of keys which makes it easier
to read/debug such generated files.
2) Adding a new optional |tsconfig_base| attribute to ts_library() to
allow overriding the base configuration file on a per-invocation basis.
This will be leveraged in follow up CL, to relax the strictness of type
checks to facilitate JS to TS migrations.
Bug: 1189595
Change-Id: Ibf50e1cb6d59ffd372ab5d0d094f2e73baae9bae
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2859062
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#877814}
- Allow a ts_library() target to include only definitions, without
any sources.
- Add |definitions| as |inputs|, so that the GN target is re-triggered
whenever definitions change.
- Add a ts_library() definition-only target for
third_party/polymer/v3_0/components-chromium.
This is in preparation of updating the demo TypeScript WebUI page to
depend on third_party/polymer/v3_0/ elements.
Bug: 1189595
Change-Id: Ic6fd884afc402a576da31f88aece1905bb2df319
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2818000
Commit-Queue: dpapad <dpapad@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/master@{#871860}
As part of promoting usage of TypeScript in WebUI, there is a need for
new TypeScript files to refer to existing JavaScript files, especially
for shared WebUI files, for example assert.js, promise_resolver.js and
util.js
- Add a new ts_definitions() rule that generates .d.ts definition file
from an existing JS file that is annotated with JSDoc.
- Add a new |definitions| property in ts_library() for including .d.ts
files as part of the generated tsconig.json file.
- Update tests accondingly.
Bug: 1189595
Change-Id: Ibd0eefb7e37b4a696d0515e3858a3bf0024e165c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2790687
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#867712}
The new ts_library() rule does the following:
- Generates tsconfig.json file in the corresponding gen/ subfolder.
- Invokes tsc (TypeScript compiler) using the generated tsconfig.json
- Generates a manifest file to be used with generate_grd()
- Handles dependencies between different projects, where a "project"
in this context is a folder with its own tsconfig.json file.
- Supports custom URL mappings, such as chrome://resources/ URLs
- Allows passing a root_dir parameter to support cases where
preprocess_if_expr() to be run before ts_library().
Bug: 1189595
Change-Id: I613515d27e826eb76b07c68bde83844ad4d951fe
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2763769
Reviewed-by: Shik Chen <shik@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@google.com>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@google.com>
Auto-Submit: dpapad <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#866776}