fix(bazel): allow TS to read ambient typings (#21876)
Same fix as https://github.com/bazelbuild/rules_typescript/commit/e70d7a2a7c08d7031f4dd4a385a7a6aa27296948 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
This commit is contained in:
@@ -16,7 +16,7 @@ node_repositories(package_json = ["//:package.json"])
|
||||
git_repository(
|
||||
name = "build_bazel_rules_typescript",
|
||||
remote = "https://github.com/bazelbuild/rules_typescript.git",
|
||||
commit = "eb3244363e1cb265c84e723b347926f28c29aa35"
|
||||
commit = "d3ad16d1f105e2490859da9ad528ba4c45991d09"
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
|
||||
|
||||
@@ -14,7 +14,7 @@ node_repositories(package_json = ["//:package.json"])
|
||||
git_repository(
|
||||
name = "build_bazel_rules_typescript",
|
||||
remote = "https://github.com/bazelbuild/rules_typescript.git",
|
||||
commit = "eb3244363e1cb265c84e723b347926f28c29aa35"
|
||||
commit = "d3ad16d1f105e2490859da9ad528ba4c45991d09"
|
||||
)
|
||||
|
||||
load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace")
|
||||
|
||||
@@ -18,12 +18,22 @@ describe('ngc_wrapped', () => {
|
||||
|
||||
write('some_project/index.ts', `
|
||||
import {Component} from '@angular/core';
|
||||
import {a} from 'ambient_module';
|
||||
console.log('works: ', Component);
|
||||
`);
|
||||
|
||||
writeConfig({
|
||||
const tsconfig = writeConfig({
|
||||
srcTargetPath: 'some_project',
|
||||
});
|
||||
const typesFile = path.resolve(
|
||||
tsconfig.compilerOptions.rootDir, tsconfig.compilerOptions.typeRoots[0], 'thing',
|
||||
'index.d.ts');
|
||||
|
||||
write(typesFile, `
|
||||
declare module "ambient_module" {
|
||||
declare const a = 1;
|
||||
}
|
||||
`);
|
||||
|
||||
// expect no error
|
||||
expect(runOneBuild()).toBe(true);
|
||||
|
||||
@@ -24,7 +24,7 @@ export interface TestSupport {
|
||||
srcTargetPath: string,
|
||||
depPaths?: string[],
|
||||
pathMapping?: Array<{moduleName: string; path: string;}>,
|
||||
}): void;
|
||||
}): {compilerOptions: ts.CompilerOptions};
|
||||
read(fileName: string): string;
|
||||
write(fileName: string, content: string): void;
|
||||
writeFiles(...mockDirs: {[fileName: string]: string}[]): void;
|
||||
@@ -68,11 +68,19 @@ export function setup(
|
||||
// -----------------
|
||||
// helpers
|
||||
|
||||
function mkdirp(dirname: string) {
|
||||
const parent = path.dirname(dirname);
|
||||
if (!fs.existsSync(parent)) {
|
||||
mkdirp(parent);
|
||||
}
|
||||
fs.mkdirSync(dirname);
|
||||
}
|
||||
|
||||
function write(fileName: string, content: string) {
|
||||
const dir = path.dirname(fileName);
|
||||
if (dir != '.') {
|
||||
const newDir = path.resolve(basePath, dir);
|
||||
if (!fs.existsSync(newDir)) fs.mkdirSync(newDir);
|
||||
if (!fs.existsSync(newDir)) mkdirp(newDir);
|
||||
}
|
||||
fs.writeFileSync(path.resolve(basePath, fileName), content, {encoding: 'utf-8'});
|
||||
}
|
||||
@@ -126,6 +134,7 @@ export function setup(
|
||||
pathMapping: pathMappingObj,
|
||||
});
|
||||
write(path.resolve(basePath, tsConfigJsonPath), JSON.stringify(tsconfig, null, 2));
|
||||
return tsconfig;
|
||||
}
|
||||
|
||||
function shouldExist(fileName: string) {
|
||||
|
||||
Reference in New Issue
Block a user