Skip to content

Commit 3d55b41

Browse files
gregmagolanalexeagle
authored andcommitted
fix(typescript): exclude typescript lib declarations in
...node_module_library transitive_declarations as the including /node_modules/typescript/lib/lib.*.d.ts is controlled by compilerOptions libs. Including all of the can cause typings conflicts. Test coverage also added for this that verifies that typescript/lib/typescript.d.ts and typescript/lib/tsserverlibrary.d.ts are available since we must exclude other typescript/lib/ .d.ts files which are controlled by the compilerOptions.libs config. Also verify that libs not specified such as lib.webworkder.d.ts in compileOptions.libs config are not included in the compilation unit. See #875 for more details.
1 parent 22e61f8 commit 3d55b41

6 files changed

Lines changed: 30 additions & 11 deletions

File tree

e2e/ts_library/foobar/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ ts_library(
99

1010
ts_library(
1111
name = "foo_ts_library",
12-
srcs = ["foo.ts"],
12+
srcs = [
13+
"conflict.d.ts",
14+
"foo.ts",
15+
],
1316
tsconfig = ":tsconfig-foo.json",
1417
deps = [
1518
":types",

e2e/ts_library/foobar/bar.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ import {a} from 'e2e_ts_library/generated_ts/foo';
2020
// Repro for #31, should automatically discover @types/node
2121
import * as fs from 'fs';
2222
import {cool} from 'some-lib';
23+
// Verify that typescript/lib/typescript.d.ts and typescript/lib/tsserverlibrary.d.ts
24+
// are available since we must exclude all other typescript/lib/*.d.ts which are
25+
// controlled by the compilerOptions.libs config.
26+
// See https://github.com/bazelbuild/rules_nodejs/pull/875 for more details.
2327
import * as ts from 'typescript';
28+
import * as tss from 'typescript/lib/tsserverlibrary';
2429

25-
import('./foo').then(({greeter}) => {console.log(Greeter, fs, cool, ts, greeter, a);});
30+
import('./foo').then(({greeter}) => {console.log(Greeter, fs, cool, ts, greeter, a);});
31+
32+
const useTssType: tss.server.Project[] = [];
33+
if (useTssType) {
34+
console.log('foobar');
35+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Test that we can declare an interface named Client
2+
// which would conflict with typescript/lib/lib.webworker.d.ts if that
3+
// lib was included but should work if that lib is not
4+
declare class Client { id: string; }

e2e/ts_library/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"@types/hammerjs": "2.0.35",
77
"@types/jasmine": "3.3.9",
88
"@types/node": "11.11.2",
9-
"typescript": "^3.3.1",
9+
"typescript": "~3.4.2",
1010
"tsickle": "0.33.1",
1111
"zone.js": "0.8.26"
1212
},

e2e/ts_library/yarn.lock

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33

44

55
"@bazel/jasmine@file:../../dist/npm_bazel_jasmine":
6-
version "0.30.1-2-g5cc5c06"
6+
version "0.32.0-4-gf2ff790"
77
dependencies:
88
jasmine "~3.3.1"
99
jasmine-core "~3.3.0"
1010
v8-coverage "1.0.9"
1111

1212
"@bazel/typescript@file:../../dist/npm_bazel_typescript":
13-
version "0.30.1-2-g5cc5c06"
13+
version "0.32.0-4-gf2ff790"
1414
dependencies:
1515
protobufjs "6.8.8"
1616
semver "5.6.0"
@@ -829,10 +829,10 @@ tsutils@2.27.2:
829829
dependencies:
830830
tslib "^1.8.1"
831831

832-
typescript@^3.3.1:
833-
version "3.3.3333"
834-
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.3333.tgz#171b2c5af66c59e9431199117a3bcadc66fdcfd6"
835-
integrity sha512-JjSKsAfuHBE/fB2oZ8NxtRTk5iGcg6hkYXMnZ3Wc+b2RSqejEqTaem11mHASMnFilHrax3sLK0GDzcJrekZYLw==
832+
typescript@~3.4.2:
833+
version "3.4.5"
834+
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99"
835+
integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw==
836836

837837
uglify-js@^3.1.4:
838838
version "3.5.3"

internal/npm_install/node_module_library.bzl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ def _node_module_library_impl(ctx):
3535
for f in ctx.files.srcs
3636
if f.path.endswith(".d.ts") and
3737
# exclude eg. external/npm/node_modules/protobufjs/node_modules/@types/node/index.d.ts
38-
# these would be duplicates of the typings provided directly in another dependency
39-
len(f.path.split("/node_modules/")) < 3
38+
# these would be duplicates of the typings provided directly in another dependency.
39+
# also exclude all /node_modules/typescript/lib/lib.*.d.ts files as these are determined by
40+
# the tsconfig "lib" attribute
41+
len(f.path.split("/node_modules/")) < 3 and f.path.find("/node_modules/typescript/lib/lib.") == -1
4042
])
4143

4244
# transitive_declarations are all .d.ts files in srcs plus those in direct & transitive dependencies

0 commit comments

Comments
 (0)