Skip to content

Commit d57fd0b

Browse files
alexeaglemhevery
authored andcommitted
fix(bazel): allow TS to read ambient typings (#21876)
Same fix as bazelbuild/rules_typescript@e70d7a2 This is because the CompilerOptions needs to have directoryExists undefined in order to get the google3 behavior, so we have to set the property outside the constructor. Fixes #21872 PR Close #21876
1 parent 9b280ee commit d57fd0b

File tree

4 files changed

+24
-5
lines changed

4 files changed

+24
-5
lines changed

WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ node_repositories(package_json = ["//:package.json"])
1616
git_repository(
1717
name = "build_bazel_rules_typescript",
1818
remote = "https://github.com/bazelbuild/rules_typescript.git",
19-
commit = "eb3244363e1cb265c84e723b347926f28c29aa35"
19+
commit = "d3ad16d1f105e2490859da9ad528ba4c45991d09"
2020
)
2121

2222
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")

integration/bazel/WORKSPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ node_repositories(package_json = ["//:package.json"])
1414
git_repository(
1515
name = "build_bazel_rules_typescript",
1616
remote = "https://github.com/bazelbuild/rules_typescript.git",
17-
commit = "eb3244363e1cb265c84e723b347926f28c29aa35"
17+
commit = "d3ad16d1f105e2490859da9ad528ba4c45991d09"
1818
)
1919

2020
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")

packages/bazel/test/ngc-wrapped/index_test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ describe('ngc_wrapped', () => {
1818

1919
write('some_project/index.ts', `
2020
import {Component} from '@angular/core';
21+
import {a} from 'ambient_module';
2122
console.log('works: ', Component);
2223
`);
2324

24-
writeConfig({
25+
const tsconfig = writeConfig({
2526
srcTargetPath: 'some_project',
2627
});
28+
const typesFile = path.resolve(
29+
tsconfig.compilerOptions.rootDir, tsconfig.compilerOptions.typeRoots[0], 'thing',
30+
'index.d.ts');
31+
32+
write(typesFile, `
33+
declare module "ambient_module" {
34+
declare const a = 1;
35+
}
36+
`);
2737

2838
// expect no error
2939
expect(runOneBuild()).toBe(true);

packages/bazel/test/ngc-wrapped/test_support.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface TestSupport {
2424
srcTargetPath: string,
2525
depPaths?: string[],
2626
pathMapping?: Array<{moduleName: string; path: string;}>,
27-
}): void;
27+
}): {compilerOptions: ts.CompilerOptions};
2828
read(fileName: string): string;
2929
write(fileName: string, content: string): void;
3030
writeFiles(...mockDirs: {[fileName: string]: string}[]): void;
@@ -68,11 +68,19 @@ export function setup(
6868
// -----------------
6969
// helpers
7070

71+
function mkdirp(dirname: string) {
72+
const parent = path.dirname(dirname);
73+
if (!fs.existsSync(parent)) {
74+
mkdirp(parent);
75+
}
76+
fs.mkdirSync(dirname);
77+
}
78+
7179
function write(fileName: string, content: string) {
7280
const dir = path.dirname(fileName);
7381
if (dir != '.') {
7482
const newDir = path.resolve(basePath, dir);
75-
if (!fs.existsSync(newDir)) fs.mkdirSync(newDir);
83+
if (!fs.existsSync(newDir)) mkdirp(newDir);
7684
}
7785
fs.writeFileSync(path.resolve(basePath, fileName), content, {encoding: 'utf-8'});
7886
}
@@ -126,6 +134,7 @@ export function setup(
126134
pathMapping: pathMappingObj,
127135
});
128136
write(path.resolve(basePath, tsConfigJsonPath), JSON.stringify(tsconfig, null, 2));
137+
return tsconfig;
129138
}
130139

131140
function shouldExist(fileName: string) {

0 commit comments

Comments
 (0)