Skip to content

Commit 066a52c

Browse files
committed
feat(typescript): use run_node helper to execute tsc
This lets it resolve plugins like ts-lit-plugin. Demonstrate this by adding a lit_plugin test under packages/typescript
1 parent 35952e5 commit 066a52c

12 files changed

Lines changed: 395 additions & 29 deletions

File tree

WORKSPACE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ install_bazel_dependencies()
101101
# With http_archive it only sees releases/download/*.tar.gz urls
102102
git_repository(
103103
name = "build_bazel_rules_typescript",
104-
commit = "5d79e42953eb8614d961ccf0e3440884e974eeb3",
104+
commit = "10a5a86885f95ab788fd841ade47b6a16e0c13d6",
105105
remote = "https://github.com/bazelbuild/rules_typescript.git",
106+
shallow_since = "1582757372 -0800",
106107
)
107108

108109
# We have a source dependency on build_bazel_rules_typescript

internal/linker/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* THIS FILE GENERATED FROM .ts; see BUILD.bazel */ /* clang-format off */var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
return new (P || (P = Promise))(function (resolve, reject) {
34
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
45
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5-
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
6+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
67
step((generator = generator.apply(thisArg, _arguments || [])).next());
78
});
89
};
@@ -493,7 +494,7 @@ Include as much of the build output as you can without disclosing anything confi
493494
exports.main = main;
494495
exports.runfiles = new Runfiles(process.env);
495496
if (require.main === module) {
496-
(() => __awaiter(this, void 0, void 0, function* () {
497+
(() => __awaiter(void 0, void 0, void 0, function* () {
497498
try {
498499
process.exitCode = yield main(process.argv.slice(2), exports.runfiles);
499500
}

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"@gregmagolan/test-a": "0.0.5",
2323
"@types/hammerjs": "2.0.35",
2424
"@types/jasmine": "~3.3.13",
25-
"@types/node": "10.12.20",
25+
"@types/node": "^12.0.0",
2626
"@types/semver": "6.2.0",
2727
"bazel_workspaces": "file:./tools/npm_packages/bazel_workspaces",
2828
"clang-format": "1.2.2",
@@ -42,6 +42,7 @@
4242
"karma-jasmine": "2.0.1",
4343
"karma-requirejs": "1.1.0",
4444
"karma-sourcemap-loader": "0.3.7",
45+
"lit-element": "^2.2.1",
4546
"minimist": "^1.2.0",
4647
"node_resolve_index": "file:./tools/npm_packages/node_resolve_index",
4748
"node_resolve_index_2": "file:./tools/npm_packages/node_resolve_index_2",
@@ -70,10 +71,11 @@
7071
"terser": "^4.4.0",
7172
"testy": "file:./tools/npm_packages/testy",
7273
"tmp": "0.1.0",
73-
"tsickle": "0.33.1",
74+
"ts-lit-plugin": "^1.1.9",
75+
"tsickle": "0.38.0",
7476
"tsutils": "2.27.2",
7577
"typeorm": "0.2.18",
76-
"typescript": "3.1.6",
78+
"typescript": "^3.7.5",
7779
"unidiff": "1.0.1",
7880
"v8-coverage": "1.0.9",
7981
"yarn": "1.22.0",

packages/typescript/src/internal/BUILD.bazel

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ load("@bazel_skylib//:bzl_library.bzl", "bzl_library")
1818

1919
package(default_visibility = ["//visibility:public"])
2020

21-
exports_files(["tsetse/tsconfig.json"])
22-
2321
bzl_library(
2422
name = "bzl",
2523
srcs = glob(

packages/typescript/src/internal/build_defs.bzl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"TypeScript compilation"
1616

17-
load("@build_bazel_rules_nodejs//:providers.bzl", "NpmPackageInfo", "js_ecma_script_module_info", "js_named_module_info", "node_modules_aspect")
17+
load("@build_bazel_rules_nodejs//:providers.bzl", "NpmPackageInfo", "js_ecma_script_module_info", "js_named_module_info", "node_modules_aspect", "run_node")
1818

1919
# pylint: disable=unused-argument
2020
# pylint: disable=missing-docstring
@@ -142,7 +142,8 @@ def _compile_action(ctx, inputs, outputs, tsconfig_file, node_opts, description
142142
arguments.append(tsconfig_file.path)
143143
mnemonic = "tsc"
144144

145-
ctx.actions.run(
145+
run_node(
146+
ctx,
146147
progress_message = "Compiling TypeScript (%s) %s" % (description, ctx.label),
147148
mnemonic = mnemonic,
148149
inputs = action_inputs,
@@ -152,7 +153,7 @@ def _compile_action(ctx, inputs, outputs, tsconfig_file, node_opts, description
152153
# See https://github.com/NixOS/nixpkgs/issues/43955#issuecomment-407546331
153154
use_default_shell_env = True,
154155
arguments = arguments,
155-
executable = ctx.executable.compiler,
156+
executable = "compiler",
156157
execution_requirements = {
157158
"supports-workers": str(int(ctx.attr.supports_workers)),
158159
},
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Copyright 2017 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
load("@npm_bazel_typescript//:index.from_src.bzl", "ts_library")
16+
17+
ts_library(
18+
name = "lit_plugin",
19+
srcs = glob(["*.ts"]),
20+
expected_diagnostics = [
21+
"""TS2322: \\[lit\\] Unknown tag "unknown-element". Did you mean 'lit-element'?""",
22+
"TS2322: \\[lit\\] Type '222' is not assignable to 'string",
23+
"TS2322: \\[lit\\] Type '333' is not assignable to 'string",
24+
"""TS2322: \\[lit\\] Type '"aaa"' is not assignable to 'number'""",
25+
"""TS2322: \\[lit\\] Type '"ccc"' is not assignable to 'number'""",
26+
"TS2322: \\[lit\\] Type '444' is not assignable to 'string",
27+
"TS2322: \\[lit\\] Type '{ field: number; }' is not assignable to '{ field: string; }'",
28+
],
29+
tsconfig = ":tsconfig.json",
30+
deps = [
31+
"@npm//lit-element",
32+
# TODO(#850): plugins["@npm//ts-lit-plugin"] instead?
33+
"@npm//ts-lit-plugin",
34+
],
35+
)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import './elements';
2+
import {html} from 'lit-element';
3+
4+
5+
const objValue = {
6+
field: 111,
7+
};
8+
console.log(html`
9+
<unknown-element></unknown-element>
10+
11+
<div .id=${222}></div>
12+
13+
<lit-element .strField=${333} .numField=${'aaa'}></lit-element>
14+
15+
<lit-element numField="bbb"></lit-element>
16+
17+
<vanilla-element .vanillaStr=${444}></vanilla-element>
18+
19+
<declared-element
20+
.declaredNumberProp=${'ccc'}
21+
.declaredObjProp=${objValue}></declared-element>
22+
`);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
export {};
3+
4+
/** An element that's only declared in a definition. */
5+
declare class DeclaredElement extends HTMLElement {
6+
declaredNumberProp: number;
7+
declaredObjProp: {field: string};
8+
}
9+
10+
declare global {
11+
interface HTMLElementTagNameMap {
12+
'declared-element': DeclaredElement;
13+
}
14+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* @fileoverview Elements used in multiple build tests.
3+
*/
4+
5+
import {customElement, LitElement} from 'lit-element';
6+
7+
8+
@customElement('lit-element')
9+
class LitElementElement extends LitElement {
10+
strField!: string;
11+
numField!: number;
12+
}
13+
14+
class VanillaElement extends HTMLElement {
15+
vanillaStr = 'hi';
16+
str!: string;
17+
}
18+
customElements.define('vanilla-element', VanillaElement);
19+
20+
declare global {
21+
interface HTMLElementTagNameMap {
22+
'lit-element': LitElementElement;
23+
'vanilla-element': VanillaElement;
24+
}
25+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"compilerOptions": {
3+
"plugins": [
4+
{
5+
"name": "ts-lit-plugin",
6+
"strict": true,
7+
"rules": {
8+
"no-unknown-tag-name": "error",
9+
"no-unclosed-tag": "error",
10+
"no-unknown-property": "error",
11+
"no-unintended-mixed-binding": "error",
12+
"no-invalid-boolean-binding": "error",
13+
"no-expressionless-property-binding": "error",
14+
"no-noncallable-event-binding": "error",
15+
"no-boolean-in-attribute-binding": "error",
16+
"no-complex-attribute-binding": "error",
17+
"no-nullable-attribute-binding": "error",
18+
"no-incompatible-type-binding": "error",
19+
"no-invalid-directive-binding": "error",
20+
"no-incompatible-property-type": "error",
21+
"no-unknown-property-converter": "error",
22+
"no-invalid-attribute-name": "error",
23+
"no-invalid-tag-name": "error",
24+
"no-unknown-attribute": "off",
25+
"no-missing-import": "off",
26+
}
27+
}
28+
]
29+
},
30+
"exclude": [
31+
"node_modules"
32+
]
33+
}

0 commit comments

Comments
 (0)