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