diff --git a/e2e/ts_library/foobar/BUILD.bazel b/e2e/ts_library/foobar/BUILD.bazel index 13a3cd3fba..39e4155e5e 100644 --- a/e2e/ts_library/foobar/BUILD.bazel +++ b/e2e/ts_library/foobar/BUILD.bazel @@ -9,7 +9,10 @@ ts_library( ts_library( name = "foo_ts_library", - srcs = ["foo.ts"], + srcs = [ + "conflict.d.ts", + "foo.ts", + ], tsconfig = ":tsconfig-foo.json", deps = [ ":types", diff --git a/e2e/ts_library/foobar/bar.ts b/e2e/ts_library/foobar/bar.ts index 12e6b90df7..09855a1564 100644 --- a/e2e/ts_library/foobar/bar.ts +++ b/e2e/ts_library/foobar/bar.ts @@ -20,6 +20,16 @@ import {a} from 'e2e_ts_library/generated_ts/foo'; // Repro for #31, should automatically discover @types/node import * as fs from 'fs'; import {cool} from 'some-lib'; +// Verify that typescript/lib/typescript.d.ts and typescript/lib/tsserverlibrary.d.ts +// are available since we must exclude all other typescript/lib/*.d.ts which are +// controlled by the compilerOptions.libs config. +// See https://github.com/bazelbuild/rules_nodejs/pull/875 for more details. import * as ts from 'typescript'; +import * as tss from 'typescript/lib/tsserverlibrary'; -import('./foo').then(({greeter}) => {console.log(Greeter, fs, cool, ts, greeter, a);}); \ No newline at end of file +import('./foo').then(({greeter}) => {console.log(Greeter, fs, cool, ts, greeter, a);}); + +const useTssType: tss.server.Project[] = []; +if (useTssType) { + console.log('foobar'); +} diff --git a/e2e/ts_library/foobar/conflict.d.ts b/e2e/ts_library/foobar/conflict.d.ts new file mode 100644 index 0000000000..ac24e9a4f8 --- /dev/null +++ b/e2e/ts_library/foobar/conflict.d.ts @@ -0,0 +1,4 @@ +// Test that we can declare an interface named Client +// which would conflict with typescript/lib/lib.webworker.d.ts if that +// lib was included but should work if that lib is not +declare class Client { id: string; } diff --git a/e2e/ts_library/package.json b/e2e/ts_library/package.json index 44db707068..f526e095ee 100644 --- a/e2e/ts_library/package.json +++ b/e2e/ts_library/package.json @@ -6,7 +6,7 @@ "@types/hammerjs": "2.0.35", "@types/jasmine": "3.3.9", "@types/node": "11.11.2", - "typescript": "^3.3.1", + "typescript": "~3.4.2", "tsickle": "0.33.1", "zone.js": "0.8.26" }, diff --git a/e2e/ts_library/yarn.lock b/e2e/ts_library/yarn.lock index 6485a793e7..db9044c0c8 100644 --- a/e2e/ts_library/yarn.lock +++ b/e2e/ts_library/yarn.lock @@ -3,14 +3,14 @@ "@bazel/jasmine@file:../../dist/npm_bazel_jasmine": - version "0.30.1-2-g5cc5c06" + version "0.32.0-4-gf2ff790" dependencies: jasmine "~3.3.1" jasmine-core "~3.3.0" v8-coverage "1.0.9" "@bazel/typescript@file:../../dist/npm_bazel_typescript": - version "0.30.1-2-g5cc5c06" + version "0.32.0-4-gf2ff790" dependencies: protobufjs "6.8.8" semver "5.6.0" @@ -829,10 +829,10 @@ tsutils@2.27.2: dependencies: tslib "^1.8.1" -typescript@^3.3.1: - version "3.3.3333" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.3.3333.tgz#171b2c5af66c59e9431199117a3bcadc66fdcfd6" - integrity sha512-JjSKsAfuHBE/fB2oZ8NxtRTk5iGcg6hkYXMnZ3Wc+b2RSqejEqTaem11mHASMnFilHrax3sLK0GDzcJrekZYLw== +typescript@~3.4.2: + version "3.4.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.4.5.tgz#2d2618d10bb566572b8d7aad5180d84257d70a99" + integrity sha512-YycBxUb49UUhdNMU5aJ7z5Ej2XGmaIBL0x34vZ82fn3hGvD+bgrMrVDpatgz2f7YxUMJxMkbWxJZeAvDxVe7Vw== uglify-js@^3.1.4: version "3.5.3" diff --git a/internal/npm_install/node_module_library.bzl b/internal/npm_install/node_module_library.bzl index e7c7677391..913fc73f29 100644 --- a/internal/npm_install/node_module_library.bzl +++ b/internal/npm_install/node_module_library.bzl @@ -35,8 +35,10 @@ def _node_module_library_impl(ctx): for f in ctx.files.srcs if f.path.endswith(".d.ts") and # exclude eg. external/npm/node_modules/protobufjs/node_modules/@types/node/index.d.ts - # these would be duplicates of the typings provided directly in another dependency - len(f.path.split("/node_modules/")) < 3 + # these would be duplicates of the typings provided directly in another dependency. + # also exclude all /node_modules/typescript/lib/lib.*.d.ts files as these are determined by + # the tsconfig "lib" attribute + len(f.path.split("/node_modules/")) < 3 and f.path.find("/node_modules/typescript/lib/lib.") == -1 ]) # transitive_declarations are all .d.ts files in srcs plus those in direct & transitive dependencies