0
Commit Graph

19 Commits

Author SHA1 Message Date
e2dcc59adf WebUI: Infer skipLibCheck=true in ts_library() when it is safe.
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.

 and  mitigate any missed type coverage from , 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}
2025-02-26 16:50:57 -08:00
c7a7248d3c WebUI: Validate all parent tsconfig files in ts_library().
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}
2025-02-25 17:46:56 -08:00
8e4694b90c WebUI: Move "/strings.m.js" path mapping outside of ts_library().
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}
2025-02-24 17:13:55 -08:00
61fe7993b9 Fix most of the remaining ESLint eqeqeq rule violations.
This is in preparation of promoting the eqeqeq rule to the top level
configuration, as opposed to only being applied to a few folders, to
better enforce the styleguide [1] and [2].

[1] https://google.github.io/styleguide/tsguide.html#equality-checks
[2] https://google.github.io/styleguide/jsguide.html#features-equality-checks

Bug: 40519637
Change-Id: I78a2704ac2a42d7f9b6d8097bf040147272f02e0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5922403
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: Ben Reich <benreich@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: Katie Dektar <katie@chromium.org>
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1367108}
2024-10-10 20:58:27 +00:00
38f86acd70 WebUI Path Mappings: Allow mapping more import types
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}
2024-03-14 22:42:50 +00:00
890a38a2a3 WebUI: Introduce new webui_path_mappings() build rule
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}
2024-03-12 01:21:41 +00:00
9d8076d4af WebUI: Add new enable_source_maps flag in ts_library().
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}
2023-02-16 00:31:11 +00:00
3dbf7df7af WebUI: Infer chrome://resources/ path_mappings from deps in ts_library.
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}
2023-02-01 00:55:17 +00:00
de62f18b4b Fix ESLint no-console violations under tools/typescript/tests.
Verified no ESLint violations are reported when running the following
git cl presubmit --files=tools/typescript/*.ts

Bug: 720034
Change-Id: Ieeaa242c3b9718b66042c1d8cde9893ee70afb24
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3945606
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1057651}
2022-10-11 20:28:04 +00:00
dfd8808526 Update copyright headers in testing/, tools/
The methodology used to generate this CL is documented in
https://crbug.com/1098010#c95.

No-Try: true
No-Presubmit: true
Bug: 1098010
Change-Id: I3a8a7b150e7bd64690534727150646081df50439
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3900697
Reviewed-by: Mark Mentovai <mark@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Commit-Queue: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1047644}
2022-09-15 20:11:09 +00:00
de25c9f9f9 [js-code-coverage] Add sourceRoot to create_js_source_maps, ts_library
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}
2022-09-07 16:20:24 +00:00
c3c3504a0c Change ts_library() to support multiple actions in the same folder
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}
2022-07-01 09:33:39 +00:00
79a5a260f6 Detect incorrect usages of TypeScript |composite| flag in ts_library.py.
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}
2022-05-12 00:02:49 +00:00
1b40fed92c Fix various @typescript-eslint/no-unused-vars ESLint rule violations.
This is in preparation of turning on this check in the top-level
src/.eslintrc.js config file.

Bug: 1300123
Change-Id: Icc949ad761e5c0a9c87a0b84d4fd186c484270b9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3484716
Reviewed-by: Jeffrey Young <cowmoo@chromium.org>
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Reviewed-by: Christopher Lam <calamity@chromium.org>
Commit-Queue: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/main@{#974539}
2022-02-24 08:15:51 +00:00
7ca45c0461 TS Library: Add manifest_excludes option
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}
2022-01-11 20:08:34 +00:00
21741cec29 WebUI: Allow overriding default tsconfig_base.json in ts_library().
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}
2021-04-30 07:09:06 +00:00
23deb6b4d6 WebUI: Better support for TypeScript definition files in ts_library().
- 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}
2021-04-13 09:30:10 +00:00
5904673b2c WebUI: Add JS-TS interoperability support in ts_library().
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}
2021-03-30 19:09:40 +00:00
920332f7fb Add ts_library() GN rule to support TypeScript in WebUI.
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}
2021-03-25 20:57:58 +00:00